:root {
    color-scheme: light;
    --shell-bg: #f8fafc;
    --shell-card: #ffffff;
    --shell-card-soft: #fbfdff;
    --shell-text: #1e293b;
    --shell-heading: #0f172a;
    --shell-muted: #64748b;
    --shell-faint: #94a3b8;
    --shell-primary: #2563eb;
    --shell-primary-soft: #eff6ff;
    --shell-border: rgba(226, 232, 240, .92);
    --shell-border-strong: #d8e0ea;
    --shell-success: #059669;
    --shell-danger: #e11d48;
    --shell-warning: #d97706;
    --shell-shadow: 0 8px 24px rgba(15, 23, 42, .055);
    --shell-shadow-hover: 0 12px 30px rgba(15, 23, 42, .085);
    --sidebar-width: 256px;
    --sidebar-collapsed-width: 68px;
    --topbar-height: 64px;
}

html.theme-dark {
    color-scheme: dark;
    --shell-bg: #020617;
    --shell-card: #0f172a;
    --shell-card-soft: #111c31;
    --shell-text: #e2e8f0;
    --shell-heading: #f8fafc;
    --shell-muted: #94a3b8;
    --shell-faint: #64748b;
    --shell-primary: #60a5fa;
    --shell-primary-soft: rgba(30, 64, 175, .24);
    --shell-border: rgba(51, 65, 85, .78);
    --shell-border-strong: #334155;
    --shell-shadow: 0 10px 28px rgba(0, 0, 0, .22);
    --shell-shadow-hover: 0 14px 34px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html, body, form { min-height: 100%; margin: 0; }
html { background: var(--shell-bg); }
body {
    min-width: 320px;
    overflow-x: hidden;
    color: var(--shell-text);
    background: var(--shell-bg);
    font-family: Inter, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    transition: color .2s ease, background-color .2s ease;
}

button, input, select, textarea { font: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
.sr-only {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Sidebar */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1200;
    width: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: #475569;
    background: rgba(255, 255, 255, .98);
    border-right: 1px solid var(--shell-border);
    box-shadow: 5px 0 18px rgba(15, 23, 42, .025);
    transition: width .24s ease, transform .24s ease, background-color .2s ease;
    overflow: hidden;
}

.theme-dark .sidebar {
    color: #94a3b8;
    background: rgba(2, 6, 23, .98);
    box-shadow: 8px 0 25px rgba(0, 0, 0, .22);
}

.sidebar-header {
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--shell-border);
}

.brand {
    min-width: 0;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 15px;
    text-decoration: none;
}

.brand-logo {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #4f46e5 58%, #7c3aed);
    box-shadow: 0 8px 18px rgba(37, 99, 235, .22);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: -.02em;
}

.brand-copy {
    min-width: 0;
    display: block;
    transition: opacity .2s ease;
}

.brand-copy strong {
    display: block;
    overflow: hidden;
    color: var(--shell-heading);
    font-size: 13px;
    font-weight: 750;
    letter-spacing: -.01em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy > span {
    display: block;
    margin-top: 1px;
    overflow: hidden;
    color: var(--shell-faint);
    font-size: 9px;
    font-weight: 550;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-close {
    display: none;
    width: 35px;
    height: 35px;
    margin-right: 10px;
    place-items: center;
    border: 1px solid var(--shell-border);
    border-radius: 9px;
    color: var(--shell-muted);
    background: var(--shell-card-soft);
    cursor: pointer;
}

.sidebar-search {
    position: relative;
    padding: 12px 12px 5px;
}

.sidebar-search > i {
    position: absolute;
    left: 25px;
    top: 24px;
    z-index: 1;
    color: var(--shell-faint);
    font-size: 11px;
    pointer-events: none;
}

.sidebar-search input {
    width: 100%;
    height: 38px;
    padding: 0 47px 0 35px;
    border: 1px solid var(--shell-border);
    border-radius: 9px;
    outline: none;
    color: var(--shell-text);
    background: var(--shell-bg);
    font-size: 11px;
    transition: border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.sidebar-search input::placeholder { color: var(--shell-faint); }
.sidebar-search input:focus {
    border-color: #93c5fd;
    background: var(--shell-card);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .09);
}

.sidebar-search kbd {
    position: absolute;
    right: 22px;
    top: 21px;
    min-width: 32px;
    padding: 2px 4px;
    border: 1px solid var(--shell-border-strong);
    border-radius: 5px;
    color: var(--shell-faint);
    background: var(--shell-card);
    font: 600 8px/1.2 "JetBrains Mono", monospace;
    text-align: center;
}

.menu-scroll {
    min-height: 0;
    flex: 1;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 4px 8px 16px;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, .36) transparent;
}

.menu-scroll::-webkit-scrollbar { width: 5px; }
.menu-scroll::-webkit-scrollbar-thumb {
    border-radius: 10px;
    background: rgba(148, 163, 184, .30);
}

.menu-title {
    margin: 14px 11px 7px;
    color: var(--shell-faint);
    font-size: 8px;
    font-weight: 750;
    letter-spacing: .16em;
    text-transform: uppercase;
}

.nav-group { margin: 2px 0; }

.nav-link,
.nav-group-button {
    position: relative;
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 11px;
    margin: 2px 0;
    padding: 9px 11px;
    border: 0;
    border-left: 3px solid transparent;
    border-radius: 8px;
    color: var(--shell-muted);
    background: transparent;
    font-size: 11.5px;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: color .16s ease, background .16s ease, border-color .16s ease, transform .16s ease;
}

.nav-link > i,
.nav-group-button > i:first-child {
    width: 20px;
    flex: 0 0 20px;
    text-align: center;
    font-size: 13px;
}

.nav-link > span,
.nav-group-button > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-link:hover,
.nav-group-button:hover {
    color: var(--shell-heading);
    background: rgba(241, 245, 249, .90);
}

.theme-dark .nav-link:hover,
.theme-dark .nav-group-button:hover {
    background: rgba(15, 23, 42, .92);
}

.nav-link:focus-visible,
.nav-group-button:focus-visible,
.sidebar-toggle:focus-visible,
.sidebar-close:focus-visible,
.sidebar-collapse:focus-visible,
.top-action:focus-visible,
.guest-theme:focus-visible,
.user-chip:focus-visible {
    outline: 3px solid rgba(96, 165, 250, .34);
    outline-offset: 2px;
}

.nav-link.active {
    color: #2563eb;
    border-left-color: #2563eb;
    background: #eff6ff;
    font-weight: 700;
}

.theme-dark .nav-link.active {
    color: #60a5fa;
    border-left-color: #3b82f6;
    background: rgba(30, 58, 138, .30);
}

.nav-group-button .chevron {
    width: auto;
    margin-left: auto;
    color: var(--shell-faint);
    font-size: 9px;
    transition: transform .2s ease;
}

.nav-group.open .chevron { transform: rotate(180deg); }
.nav-children { display: none; padding: 2px 0 4px 15px; }
.nav-group.open .nav-children { display: block; }
.nav-children .nav-link { min-height: 38px; font-size: 10.8px; }

.menu-no-result {
    display: grid;
    place-items: center;
    gap: 7px;
    padding: 30px 12px;
    color: var(--shell-faint);
    font-size: 11px;
    text-align: center;
}

.menu-no-result i { font-size: 20px; }

.sidebar-footer {
    padding: 10px 9px;
    border-top: 1px solid var(--shell-border);
}

.sidebar-user-card {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 51px;
    padding: 7px 8px;
    border: 1px solid var(--shell-border);
    border-radius: 10px;
    background: var(--shell-card-soft);
}

.avatar {
    width: 34px;
    height: 34px;
    flex: 0 0 34px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #7c3aed);
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
}

.sidebar-user-copy { min-width: 0; }

.sidebar-user-copy strong {
    display: block;
    max-width: 160px;
    overflow: hidden;
    color: var(--shell-heading);
    font-size: 10.5px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user-copy > span {
    display: block;
    max-width: 160px;
    margin-top: 1px;
    overflow: hidden;
    color: var(--shell-faint);
    font-size: 8.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-collapse {
    width: 100%;
    min-height: 36px;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 7px;
    padding: 7px 10px;
    border: 0;
    border-radius: 8px;
    color: var(--shell-muted);
    background: transparent;
    font-size: 10px;
    font-weight: 650;
    cursor: pointer;
    text-align: left;
}

.sidebar-collapse:hover {
    color: var(--shell-heading);
    background: var(--shell-bg);
}

.sidebar-collapse i {
    width: 18px;
    transition: transform .24s ease;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 1150;
    display: none;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(15, 23, 42, .52);
    backdrop-filter: blur(2px);
    cursor: pointer;
}

/* Main application shell */
.main-shell {
    min-width: 0;
    min-height: 100vh;
    margin-left: var(--sidebar-width);
    background: var(--shell-bg);
    transition: margin-left .24s ease, background-color .2s ease;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    min-height: var(--topbar-height);
    padding: 0 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    border-bottom: 1px solid var(--shell-border);
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.theme-dark .topbar { background: rgba(2, 6, 23, .80); }

.topbar-left {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-toggle {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    display: grid;
    place-items: center;
    border: 1px solid var(--shell-border);
    border-radius: 8px;
    color: var(--shell-muted);
    background: var(--shell-card);
    cursor: pointer;
    transition: color .16s ease, background .16s ease, border-color .16s ease;
}

.sidebar-toggle:hover {
    color: var(--shell-primary);
    border-color: #bfdbfe;
    background: var(--shell-primary-soft);
}

.page-heading { min-width: 0; }

.page-heading h1 {
    margin: 0;
    overflow: hidden;
    color: var(--shell-heading);
    font-size: clamp(15px, 1.6vw, 17px);
    font-weight: 750;
    letter-spacing: -.018em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-heading p {
    margin: 1px 0 0;
    color: var(--shell-faint);
    font-size: 8.5px;
    font-weight: 550;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    border: 1px solid #bbf7d0;
    border-radius: 999px;
    color: #047857;
    background: #ecfdf5;
    font-size: 9px;
    font-weight: 750;
}

.theme-dark .sync-pill {
    border-color: rgba(6, 95, 70, .60);
    color: #34d399;
    background: rgba(6, 78, 59, .22);
}

.sync-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 0 4px rgba(16, 185, 129, .10);
    animation: syncPulse 1.8s ease-in-out infinite;
}

@keyframes syncPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .42; }
}

.top-action,
.guest-theme {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--shell-border);
    border-radius: 8px;
    color: var(--shell-muted);
    background: var(--shell-card);
    text-decoration: none;
    cursor: pointer;
    transition: color .16s ease, background .16s ease, border-color .16s ease, transform .16s ease;
}

.top-action:hover,
.guest-theme:hover {
    color: var(--shell-primary);
    border-color: #bfdbfe;
    background: var(--shell-primary-soft);
    transform: translateY(-1px);
}

.top-action.danger:hover {
    color: #be123c;
    border-color: #fecdd3;
    background: #fff1f2;
}

.theme-dark .top-action.danger:hover {
    color: #fb7185;
    border-color: rgba(159, 18, 57, .65);
    background: rgba(76, 5, 25, .34);
}

.theme-sun { display: none; }
.theme-dark .theme-moon { display: none; }
.theme-dark .theme-sun { display: inline-block; }

.user-chip {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 9px 3px 4px;
    border: 1px solid var(--shell-border);
    border-radius: 999px;
    background: var(--shell-card);
    text-decoration: none;
    transition: border-color .16s ease, box-shadow .16s ease;
}

.user-chip:hover {
    border-color: var(--shell-border-strong);
    box-shadow: var(--shell-shadow);
}

.user-chip .avatar {
    width: 29px;
    height: 29px;
    flex-basis: 29px;
    font-size: 8px;
}

.user-chip-copy { min-width: 0; }

.user-chip-copy strong {
    display: block;
    max-width: 125px;
    overflow: hidden;
    color: var(--shell-heading);
    font-size: 9.5px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-chip-copy > span {
    display: block;
    max-width: 125px;
    margin-top: 0;
    overflow: hidden;
    color: var(--shell-faint);
    font-size: 7.5px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-content {
    width: 100%;
    min-width: 0;
    padding: 22px;
}

.page-content > * { max-width: 100%; }

.shell-card {
    border: 1px solid var(--shell-border);
    border-radius: 14px;
    background: var(--shell-card);
    box-shadow: var(--shell-shadow);
}

/* Desktop collapsed state */
@media (min-width: 1025px) {
    .sidebar.is-collapsed { width: var(--sidebar-collapsed-width); }
    .main-shell.sidebar-is-collapsed { margin-left: var(--sidebar-collapsed-width); }

    .sidebar.is-collapsed .brand {
        justify-content: center;
        padding-inline: 10px;
    }

    .sidebar.is-collapsed .brand-copy,
    .sidebar.is-collapsed .sidebar-search,
    .sidebar.is-collapsed .menu-title,
    .sidebar.is-collapsed .nav-link > span,
    .sidebar.is-collapsed .nav-group-button > span,
    .sidebar.is-collapsed .nav-group-button .chevron,
    .sidebar.is-collapsed .sidebar-user-copy,
    .sidebar.is-collapsed .sidebar-collapse > span {
        display: none;
    }

    .sidebar.is-collapsed .menu-scroll { padding-inline: 7px; }

    .sidebar.is-collapsed .nav-link,
    .sidebar.is-collapsed .nav-group-button {
        justify-content: center;
        gap: 0;
        padding-inline: 7px;
        border-left-color: transparent;
    }

    .sidebar.is-collapsed .nav-link.active {
        border-left-color: transparent;
        box-shadow: inset 0 0 0 1px rgba(37, 99, 235, .12);
    }

    .sidebar.is-collapsed .nav-link > i,
    .sidebar.is-collapsed .nav-group-button > i:first-child {
        width: 24px;
        flex-basis: 24px;
        font-size: 14px;
    }

    .sidebar.is-collapsed .nav-children { padding-left: 0; }
    .sidebar.is-collapsed .sidebar-user-card { justify-content: center; padding-inline: 5px; }
    .sidebar.is-collapsed .sidebar-collapse { justify-content: center; padding-inline: 6px; }
    .sidebar.is-collapsed .sidebar-collapse i { transform: rotate(180deg); }
}

/* Guest pages */
.guest-shell {
    min-height: 100vh;
    color: var(--shell-text);
    background: var(--shell-bg);
}

.guest-topbar {
    min-height: 64px;
    padding: 0 4vw;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid var(--shell-border);
    background: rgba(255, 255, 255, .86);
    backdrop-filter: blur(16px);
}

.theme-dark .guest-topbar { background: rgba(2, 6, 23, .84); }

.guest-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    color: var(--shell-heading);
    font-size: 12.5px;
    font-weight: 750;
    text-decoration: none;
}

.guest-brand .brand-logo {
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    border-radius: 9px;
    font-size: 10px;
}

.guest-nav {
    display: flex;
    align-items: center;
    gap: 5px;
}

.guest-nav a {
    padding: 8px 11px;
    border-radius: 8px;
    color: var(--shell-muted);
    font-size: 10.5px;
    font-weight: 650;
    text-decoration: none;
}

.guest-nav a:hover {
    color: var(--shell-primary);
    background: var(--shell-primary-soft);
}

.guest-nav .login-link {
    color: #fff;
    background: #2563eb;
    box-shadow: 0 6px 14px rgba(37, 99, 235, .18);
}

.guest-nav .login-link:hover {
    color: #fff;
    background: #1d4ed8;
}

.guest-content { padding: 0; }

/* Shared notices */
.validation-summary,
.app-alert {
    margin-bottom: 13px;
    padding: 11px 13px;
    border-radius: 9px;
    font-size: 11px;
}

.validation-summary {
    border: 1px solid #fecaca;
    color: #991b1b;
    background: #fef2f2;
}

.app-alert.success {
    color: #166534;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
}

.app-alert.error {
    color: #991b1b;
    background: #fef2f2;
    border: 1px solid #fecaca;
}

.app-alert.info {
    color: #1e40af;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
}

@media (max-width: 1024px) {
    .sidebar {
        width: min(88vw, 290px);
        transform: translateX(-105%);
        box-shadow: 18px 0 45px rgba(15, 23, 42, .22);
    }

    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: grid; }
    .sidebar-collapse { display: none; }
    .sidebar-overlay.is-visible { display: block; }
    body.sidebar-drawer-open { overflow: hidden; }

    .main-shell,
    .main-shell.sidebar-is-collapsed { margin-left: 0; }

    .topbar { padding: 0 14px; }
    .page-content { padding: 17px; }
}

@media (max-width: 700px) {
    .sync-pill,
    .user-chip-copy { display: none; }

    .user-chip {
        padding: 3px;
        border-radius: 9px;
    }
}

@media (max-width: 560px) {
    :root { --topbar-height: 60px; }

    .topbar {
        min-height: 60px;
        gap: 7px;
    }

    .top-actions { gap: 5px; }
    .top-action { width: 33px; height: 33px; }
    .sidebar-toggle { width: 34px; height: 34px; }

    .page-heading p { display: none; }
    .page-heading h1 { font-size: 14px; }
    .page-content { padding: 12px; }

    .guest-topbar {
        min-height: 62px;
        padding: 9px 12px;
        flex-wrap: wrap;
    }

    .guest-nav {
        width: 100%;
        overflow-x: auto;
        padding-bottom: 2px;
    }

    .guest-nav a { white-space: nowrap; }
}
