/* ==========================================================================
   Theme tokens + app shell. Dark by default — a light theme can be added
   later by redefining these variables under another selector.
   ========================================================================== */
:root {
    color-scheme: dark;

    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1e222b;
    --surface-3: #262b36;
    --border: #2a2f3a;
    --border-strong: #3a4150;

    --text: #e6e8ee;
    --text-muted: #9aa3b2;
    --text-faint: #6b7385;

    --accent: #22d3ee;
    --accent-hover: #67e8f9;
    --accent-soft: rgba(34, 211, 238, 0.12);
    --accent-ring: rgba(34, 211, 238, 0.35);
    --on-accent: #041318;

    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.13);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.13);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.13);
    --info: #818cf8;
    --info-soft: rgba(129, 140, 248, 0.14);

    --radius: 10px;
    --radius-sm: 7px;
    --radius-lg: 14px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.22);
    --shadow-lg: 0 20px 50px rgba(0, 0, 0, 0.5);

    --sidebar-w: 244px;
    --sidebar-w-collapsed: 72px;
    --topbar-h: 62px;

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Consolas, monospace;
}

html, body { background: var(--bg); }
body {
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    font-feature-settings: 'cv11', 'ss01';
}
a { text-decoration: none; }
::selection { background: var(--accent-soft); color: var(--accent-hover); }
.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }

/* ---------- Shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: var(--sidebar-w);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #141720 0%, #11141a 100%);
    border-right: 1px solid var(--border);
    transition: width .2s ease;
    z-index: 40;
}
.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--topbar-h);
    padding: 0 18px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    overflow: hidden;
}
.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent) 0%, #818cf8 100%);
    color: var(--on-accent);
    box-shadow: 0 4px 16px rgba(34, 211, 238, 0.25);
}
.brand-mark .icon { width: 19px; height: 19px; }
.brand-text { display: flex; flex-direction: column; font-weight: 700; font-size: 15px; letter-spacing: -0.01em; line-height: 1.2; }
.brand-text small { font-weight: 500; font-size: 11.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; max-width: 160px; }

.nav { flex: 1; overflow-y: auto; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-section {
    margin: 18px 10px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
    white-space: nowrap;
}
.nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); }
.nav-link.active::before {
    content: '';
    position: absolute;
    left: -10px;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--accent);
}
.nav-badge {
    margin-left: auto;
    min-width: 20px;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--warning-soft);
    color: var(--warning);
    font-size: 11.5px;
    font-weight: 600;
    text-align: center;
}
.sidebar-collapse {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px;
    padding: 9px 12px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-faint);
    white-space: nowrap;
}
.sidebar-collapse:hover { background: var(--surface-2); color: var(--text); }
.sidebar-collapse .icon { transition: transform .2s; }

/* Collapsed (desktop) */
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-section { display: none; }
body.sidebar-collapsed .nav-link, body.sidebar-collapsed .sidebar-collapse { justify-content: center; padding: 10px; }
body.sidebar-collapsed .nav-badge { position: absolute; top: 2px; right: 2px; min-width: 0; padding: 0 5px; font-size: 10px; }
body.sidebar-collapsed .sidebar-collapse .icon { transform: rotate(180deg); }
body.sidebar-collapsed .brand { justify-content: center; padding: 0; }

.sidebar-backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 16px;
    height: var(--topbar-h);
    padding: 0 28px;
    background: rgba(15, 17, 21, 0.82);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar .menu-btn { display: none; }
.global-search {
    position: relative;
    flex: 1;
    max-width: 520px;
    display: flex;
    align-items: center;
}
.global-search > .icon { position: absolute; left: 12px; color: var(--text-faint); pointer-events: none; width: 16px; height: 16px; }
.global-search input[type=search] {
    width: 100%;
    height: 38px;
    padding: 0 40px 0 38px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}
.global-search input[type=search]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.global-search kbd {
    position: absolute;
    right: 10px;
    padding: 1px 7px;
    border: 1px solid var(--border-strong);
    border-radius: 5px;
    font: 500 11px var(--mono);
    color: var(--text-faint);
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.user-menu { position: relative; }
.user-menu summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 4px 4px;
    border-radius: 999px;
    cursor: pointer;
    list-style: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: var(--surface-2); }
.avatar {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #334155, #1e293b);
    border: 1px solid var(--border-strong);
    font-weight: 600;
    font-size: 13px;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-meta strong { font-size: 13px; font-weight: 600; }
.user-meta small { font-size: 11.5px; color: var(--text-muted); }
.user-menu .menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 190px;
    padding: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}
.user-menu .menu a, .user-menu .menu button {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    background: none;
    color: var(--text);
    text-align: left;
}
.user-menu .menu a:hover, .user-menu .menu button:hover { background: var(--surface-3); }
.user-menu .menu .icon { width: 16px; height: 16px; color: var(--text-muted); }

.content { flex: 1; width: 100%; max-width: 1480px; margin: 0 auto; padding: 28px; }

/* ---------- Responsive shell ---------- */
@media (max-width: 960px) {
    .sidebar {
        position: fixed;
        left: 0;
        transform: translateX(-100%);
        transition: transform .22s ease;
        width: var(--sidebar-w) !important;
        box-shadow: var(--shadow-lg);
    }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 35; }
    body.sidebar-collapsed .brand-text, body.sidebar-collapsed .nav-label, body.sidebar-collapsed .nav-section { display: revert; }
    body.sidebar-collapsed .nav-link { justify-content: flex-start; padding: 9px 12px; }
    body.sidebar-collapsed .brand { justify-content: flex-start; padding: 0 18px; }
    .sidebar-collapse { display: none; }
    .topbar .menu-btn { display: inline-grid; }
    .topbar { padding: 0 16px; gap: 10px; }
    .content { padding: 20px 16px; }
    .global-search kbd { display: none; }
}
@media (max-width: 640px) {
    .hide-sm { display: none !important; }
}
