/* ==========================================================================
   Base & Reset
   ========================================================================== */
:root {
    --bg:            #FAFAF9;
    --surface:       #FFFFFF;
    --surface-2:     #F5F5F4;
    --border:        #E7E5E4;
    --border-strong: #D6D3D1;
    --text:          #1C1917;
    --text-2:        #44403C;
    --muted:         #78716C;
    --faint:         #A8A29E;

    --accent:        #4F46E5;
    --accent-hover:  #4338CA;
    --accent-soft:   #EEF2FF;
    --accent-fg:     #3730A3;

    --success:       #16A34A;
    --success-soft:  #ECFDF5;
    --danger:        #DC2626;
    --danger-soft:   #FEF2F2;
    --warning:       #CA8A04;
    --warning-soft:  #FEFCE8;

    --radius:        10px;
    --radius-sm:     8px;
    --radius-full:   999px;

    --shadow-xs: 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-sm: 0 1px 3px rgba(28, 25, 23, 0.06), 0 1px 2px rgba(28, 25, 23, 0.04);
    --shadow-lg: 0 12px 24px -8px rgba(28, 25, 23, 0.10), 0 4px 8px -4px rgba(28, 25, 23, 0.05);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    --sidebar-w: 240px;
    --topbar-h:  60px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

/* ==========================================================================
   Layout
   ========================================================================== */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 100vh;
}

/* Mobile Overlay */
.overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(28, 25, 23, 0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}
.overlay.open { display: block; }

/* Sidebar */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    padding: 16px 12px;
    z-index: 100;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 20px; }
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.nav-section { margin-top: 8px; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); font-weight: 600; padding: 0 10px 8px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--text-2); font-size: 14px; font-weight: 500; transition: background 120ms ease, color 120ms ease; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-fg); }
.nav-item svg { color: var(--faint); flex-shrink: 0; }
.nav-item.active svg { color: var(--accent); }
.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-fg); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 500; line-height: 1.2; }
.user-role { font-size: 11px; color: var(--muted); line-height: 1.2; }

/* Main Column */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar-h); padding: 0 32px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 10; }
.topbar-title { font-size: 15px; font-weight: 600; color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.content { padding: 32px; max-width: 1200px; width: 100%; margin: 0 auto; flex: 1; }
.page-header { margin-bottom: 28px; }
.page-header h1 { font-size: 22px; }
.page-header p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* ==========================================================================
   Components
   ========================================================================== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-xs); }
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 14px; font-weight: 600; }
.card-body { padding: 22px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-xs); }
.stat-label { font-size: 12px; font-weight: 500; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; margin-top: 2px; line-height: 1.1; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; line-height: 1; border: 1px solid transparent; transition: background 120ms ease, border-color 120ms ease, color 120ms ease; white-space: nowrap; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #FEE2E2; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--radius-full); font-size: 12px; font-weight: 500; line-height: 1.6; }
.badge-dot { width: 5px; height: 5px; border-radius: 50%; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-success .badge-dot { background: var(--success); }
.badge-muted { background: var(--surface-2); color: var(--muted); }
.badge-muted .badge-dot { background: var(--faint); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-warn .badge-dot { background: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.table-responsive { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th { text-align: left; font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); padding: 10px 22px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table tbody td { padding: 14px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #FCFCFB; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); outline: none; transition: border-color 120ms ease, box-shadow 120ms ease; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.alert { padding: 12px 16px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: flex; align-items: flex-start; gap: 8px; }
.alert-ok   { background: var(--success-soft); color: #065F46; border: 1px solid #D1FAE5; }
.alert-err  { background: var(--danger-soft);  color: #991B1B; border: 1px solid #FECACA; }
.alert-info { background: var(--accent-soft);  color: var(--accent-fg); border: 1px solid #C7D2FE; }

/* Utilities */
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-4 { margin-top: 16px; } .mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--muted); } .text-sm { font-size: 13px; }
.mono { font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   Skeleton Loaders
   ========================================================================== */
.skeleton { background: #E7E5E4; background: linear-gradient(90deg, #F5F5F4 25%, #E7E5E4 50%, #F5F5F4 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite linear; border-radius: 4px; color: transparent !important; }
.skeleton-text { height: 16px; width: 100%; margin-bottom: 8px; display: inline-block; }
.skeleton-title { height: 24px; width: 50%; margin-bottom: 12px; display: inline-block; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.btn-loading { opacity: 0.7; pointer-events: none; cursor: wait; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: #fff; animation: spin 1s ease-in-out infinite; margin-right: 6px; vertical-align: middle; }
.btn-secondary .spinner { border-color: rgba(0,0,0,0.1); border-top-color: #1C1917; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Mobile Responsiveness
   ========================================================================== */
@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
    }
    .menu-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        padding: 8px;
        margin-left: -8px;
        border-radius: 8px;
        color: var(--text-2);
    }
    .menu-toggle:hover {
        background: var(--surface-2);
    }
    .sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        bottom: 0;
        width: 280px;
        z-index: 100;
        transition: left 0.3s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.1);
    }
    .sidebar.open {
        left: 0;
    }
    .topbar {
        padding: 0 16px;
    }
    .content {
        padding: 16px;
    }
    .stat-grid {
        grid-template-columns: 1fr;
    }
    .page-header.flex {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

/* ==========================================================================
   Network Analytics (GSC Style)
   ========================================================================== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-xs);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.kpi-card span { font-size: 13px; font-weight: 500; color: var(--muted); }
.kpi-card strong { font-size: 28px; font-weight: 600; letter-spacing: -0.03em; line-height: 1.1; }
.kpi-card small { font-size: 12px; color: var(--faint); }

.analytics-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow-xs);
}
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
}
.category-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

@media (max-width: 768px) {
    .category-grid { grid-template-columns: 1fr; }
    .kpi-grid { grid-template-columns: 1fr 1fr; }
}
