/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #3B82F6;
    --primary-dark: #2563EB;
    --danger: #EF4444;
    --danger-bg: #FEF2F2;
    --warning: #F59E0B;
    --warning-bg: #FFFBEB;
    --success: #10B981;
    --success-bg: #F0FDF4;
    --info: #6366F1;
    --info-bg: #EEF2FF;
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-500: #6B7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
}

html { font-size: 14px; }
@media (min-width: 768px) { html { font-size: 15px; } }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Malgun Gothic', sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===== Navbar ===== */
.navbar {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav-links { display: flex; gap: 0.25rem; }

.nav-link {
    padding: 0.5rem 1rem;
    color: var(--gray-700);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: background 0.15s;
}

.nav-link:hover { background: var(--gray-100); color: var(--primary); }

/* ===== Main Content ===== */
.main-content { flex: 1; padding: 2rem 1.5rem; }

.container { max-width: 1200px; margin: 0 auto; }

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--gray-900);
}

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}

.stat-card.stat-danger { border-left-color: var(--danger); }
.stat-card.stat-warning { border-left-color: var(--warning); }
.stat-card.stat-info { border-left-color: var(--info); }

.stat-number { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-card.stat-danger .stat-number { color: var(--danger); }
.stat-card.stat-warning .stat-number { color: var(--warning); }
.stat-card.stat-info .stat-number { color: var(--info); }

.stat-label { font-size: 0.85rem; color: var(--gray-500); margin-top: 0.25rem; }

/* ===== Card ===== */
.card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-success { border-left: 4px solid var(--success); }
.card-danger { border-left: 4px solid var(--danger); background: var(--danger-bg); }
.card-warning { border-left: 4px solid var(--warning); background: var(--warning-bg); }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.card-header h2 { font-size: 1.1rem; font-weight: 600; }

.card-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; color: var(--gray-900); }
.sub-title { font-size: 0.95rem; font-weight: 600; margin: 1rem 0 0.5rem; color: var(--gray-700); }

/* ===== Table ===== */
.table-wrapper { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th {
    background: var(--gray-50);
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    border-bottom: 2px solid var(--gray-200);
    white-space: nowrap;
}

.table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    vertical-align: middle;
}

.table tbody tr:hover { background: var(--gray-50); }

.table-sm th, .table-sm td { padding: 0.5rem 0.75rem; }

.detail-text { max-width: 300px; font-size: 0.85rem; color: var(--gray-500); }

/* ===== Badge ===== */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.4;
}

.badge-success { background: var(--success-bg); color: #065F46; }
.badge-danger { background: var(--danger-bg); color: #991B1B; }
.badge-warning { background: var(--warning-bg); color: #92400E; }
.badge-info { background: var(--info-bg); color: #3730A3; }
.badge-secondary { background: var(--gray-100); color: var(--gray-700); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    gap: 0.5rem;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary { background: white; color: var(--gray-700); border-color: var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); }

.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }

.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }

/* ===== Detail ===== */
.detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.detail-header .page-title { margin-bottom: 0; }

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 0.75rem;
}

.detail-item { display: flex; flex-direction: column; gap: 0.15rem; }
.detail-label { font-size: 0.8rem; color: var(--gray-500); font-weight: 500; }
.detail-value { font-size: 0.95rem; color: var(--gray-900); }

/* ===== Filter ===== */
.filter-form {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group { display: flex; flex-direction: column; gap: 0.25rem; }
.filter-group label { font-size: 0.8rem; color: var(--gray-500); font-weight: 500; }

.input-field {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
    min-width: 200px;
}

.input-field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,0.1); }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    gap: 0.25rem;
    padding: 1rem 0 0;
    justify-content: center;
}

.page-link {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    color: var(--gray-700);
    text-decoration: none;
    font-size: 0.85rem;
}

.page-link:hover { background: var(--gray-50); }
.page-link.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ===== Agent Guide ===== */
.agent-guide { display: flex; flex-direction: column; gap: 1.5rem; }

.step {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

.step-number {
    width: 36px;
    height: 36px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.step-content h3 { font-size: 1rem; font-weight: 600; margin-bottom: 0.25rem; }
.step-content p { font-size: 0.9rem; color: var(--gray-700); margin-bottom: 0.5rem; }
.step-content ul { margin-left: 1.25rem; font-size: 0.9rem; color: var(--gray-700); }
.step-content ol { margin-left: 1.25rem; font-size: 0.9rem; color: var(--gray-700); }

.notice-box {
    background: var(--warning-bg);
    border: 1px solid #FDE68A;
    border-left: 4px solid var(--warning);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-top: 0.75rem;
    font-size: 0.9rem;
}
.notice-box strong { display: block; margin-bottom: 0.5rem; color: #92400E; }
.notice-box p { color: var(--gray-700); margin-bottom: 0.5rem; }
.notice-box ol { margin-left: 1.25rem; color: var(--gray-700); }
.notice-box ol li { margin-bottom: 0.25rem; }

.code-block {
    background: var(--gray-900);
    color: #E5E7EB;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-family: 'Cascadia Code', 'Consolas', monospace;
    font-size: 0.85rem;
    overflow-x: auto;
}

.text-muted { color: var(--gray-500); font-size: 0.85rem; }

code {
    background: var(--gray-100);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
    color: var(--danger);
}

/* ===== Login ===== */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
    padding: 2rem;
}

.login-card {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2.5rem;
    width: 100%;
    max-width: 400px;
}

.login-title { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: 0.25rem; }
.login-subtitle { text-align: center; color: var(--gray-500); font-size: 0.9rem; margin-bottom: 1.5rem; }

.login-field { margin-bottom: 1rem; }
.login-field label { display: block; font-size: 0.85rem; font-weight: 500; color: var(--gray-700); margin-bottom: 0.25rem; }

.btn-block { width: 100%; margin-top: 0.5rem; }

.login-error {
    background: var(--danger-bg);
    color: #991B1B;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    border-left: 3px solid var(--danger);
}

.login-success {
    background: var(--success-bg);
    color: #065F46;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    border-left: 3px solid var(--success);
}

.login-back { text-align: center; margin-top: 1rem; }
.login-back a { color: var(--gray-500); font-size: 0.85rem; text-decoration: none; }
.login-back a:hover { color: var(--primary); }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-box {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 2rem;
    width: 100%;
    max-width: 460px;
}

.modal-box h3 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }

.modal-box textarea { resize: vertical; }

.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ===== Token Form ===== */
.token-form { display: flex; gap: 0.5rem; align-items: center; }
.token-form .input-field { flex: 1; max-width: 300px; letter-spacing: 2px; font-weight: 600; }

.saved-tokens { margin-top: 0.5rem; }

/* ===== Nav Auth ===== */
.nav-logout { display: flex; align-items: center; gap: 0.5rem; }
.nav-user { font-size: 0.85rem; color: var(--gray-500); }

/* ===== Footer ===== */
.footer {
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: 1rem 1.5rem;
    text-align: center;
    font-size: 0.85rem;
    color: var(--gray-500);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .nav-container { flex-direction: column; gap: 0.5rem; padding: 0.5rem 0; }
    .navbar { height: auto; padding: 0.5rem 1rem; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .detail-grid { grid-template-columns: 1fr; }
    .filter-form { flex-direction: column; }
    .input-field { min-width: unset; width: 100%; }
}
