/* ---------- Tokens ---------- */
:root {
    --shell-bg: #f4f7f5;
    --surface: #ffffff;
    --border: #dfe7e3;
    --text: #17211e;
    --muted: #5d6e68;
    --link: #0f6b5c;

    --side-bg: #143d36;
    --side-text: #c4d9d1;
    --side-text-strong: #ffffff;
    --side-hover: rgba(255, 255, 255, .07);
    --side-active: rgba(255, 255, 255, .12);
    --side-line: rgba(255, 255, 255, .14);
    --accent: #f2a900;           /* marigold */

    --sidebar-w: 268px;
    --topbar-h: 62px;
    --font-ui: "Figtree", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-brand: "Fraunces", Georgia, "Times New Roman", serif;
}

[data-bs-theme="dark"] {
    --shell-bg: #0d1412;
    --surface: #151f1c;
    --border: #25332e;
    --text: #e4eeea;
    --muted: #8fa49c;
    --link: #5fd0bb;

    --side-bg: #0a2420;
    --side-text: #9db8af;
}

/* ---------- Base ---------- */
body {
    font-family: var(--font-ui);
    background: var(--shell-bg);
    color: var(--text);
}

.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--side-bg);
    color: var(--side-text);
    z-index: 1040;
    transition: transform .25s ease;
}

.sidebar-brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    border-bottom: 1px solid var(--side-line);
}

.brand-word {
    font-family: var(--font-brand);
    font-weight: 600;
    font-size: 1.45rem;
    letter-spacing: -.01em;
    color: var(--side-text-strong);
}

.brand-dot { color: var(--accent); }

.side-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .2rem;
}

.nav-row {
    position: relative;
    display: flex;
    align-items: center;
    gap: .8rem;
    width: 100%;
    padding: .62rem .85rem;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--side-text);
    font: inherit;
    font-weight: 500;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s, color .15s;
}

.nav-row:hover { background: var(--side-hover); color: var(--side-text-strong); }

.nav-row.active,
.nav-group.has-active > .nav-row {
    background: var(--side-active);
    color: var(--side-text-strong);
}

/* marigold rail marks where you are */
.nav-row.active::before,
.nav-group.has-active > .nav-row::before {
    content: "";
    position: absolute;
    left: -.75rem;
    top: 18%;
    bottom: 18%;
    width: 4px;
    border-radius: 0 4px 4px 0;
    background: var(--accent);
}

.nav-icon { font-size: 1.1rem; width: 1.3rem; text-align: center; flex: none; }
.nav-label { flex: 1; min-width: 0; }
.nav-external { font-size: .72rem; opacity: .6; }
.nav-chevron { font-size: .72rem; transition: transform .2s; }
.nav-group.open > .nav-row .nav-chevron { transform: rotate(180deg); }

/* collapsible group, animated height */
.nav-sub {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows .22s ease;
}
.nav-group.open > .nav-sub { grid-template-rows: 1fr; }

.nav-sub-inner {
    overflow: hidden;
    margin-left: 1.65rem;
    padding-left: .7rem;
    border-left: 1px solid var(--side-line);
    visibility: hidden;
    transition: visibility .22s;
}
.nav-group.open > .nav-sub > .nav-sub-inner { visibility: visible; }

.nav-sub-link {
    display: flex;
    align-items: center;
    gap: .7rem;
    margin: .15rem 0;
    padding: .5rem .7rem;
    border-radius: 8px;
    color: var(--side-text);
    font-size: .94rem;
    text-decoration: none;
    transition: background-color .15s, color .15s;
}
.nav-sub-link:hover { background: var(--side-hover); color: var(--side-text-strong); }
.nav-sub-link.active { background: var(--side-active); color: var(--side-text-strong); font-weight: 600; }
.nav-sub-link .nav-icon { font-size: 1rem; }

.nav-skeleton {
    height: 40px;
    border-radius: 10px;
    background: var(--side-hover);
    animation: nav-pulse 1.2s ease-in-out infinite;
}
@keyframes nav-pulse { 50% { opacity: .45; } }

/* ---------- Main column ---------- */
.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: 0 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar-spacer { flex: 1; }

.app-content {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem;
}

.app-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .875rem;
}
.app-footer a { color: var(--link); text-decoration: none; }
.app-footer a:hover { text-decoration: underline; }

/* ---------- Topbar controls ---------- */
.icon-btn {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: background-color .15s, color .15s;
}
.icon-btn:hover { background: var(--shell-bg); color: var(--text); }
.menu-toggle { display: none; }

.login-link {
    padding: .45rem .9rem;
    border-radius: 10px;
    background: var(--side-bg);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
}

.user-menu { position: relative; margin-left: .25rem; }

.user-btn {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .3rem .6rem .3rem .3rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: border-color .15s;
}
.user-btn:hover { border-color: var(--muted); }
.user-btn img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.user-caret { font-size: .7rem; color: var(--muted); }

.user-backdrop { position: fixed; inset: 0; z-index: 1050; }

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + .5rem);
    z-index: 1051;
    min-width: 240px;
    padding: .4rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, .14);
}
.user-dropdown-head {
    display: flex;
    flex-direction: column;
    gap: .1rem;
    padding: .6rem .7rem .7rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: .3rem;
}
.user-dropdown-head span { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    width: 100%;
    padding: .55rem .7rem;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}
.user-dropdown-item:hover { background: var(--shell-bg); }

/* ---------- Focus ---------- */
.nav-row:focus-visible,
.nav-sub-link:focus-visible,
.icon-btn:focus-visible,
.user-btn:focus-visible,
.user-dropdown-item:focus-visible,
.login-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---------- Login layout ---------- */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background: var(--side-bg);
}
.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2.25rem 2rem;
    border-radius: 16px;
    background: var(--surface);
    color: var(--text);
    text-align: center;
}
.login-brand {
    margin-bottom: 1.5rem;
    font-family: var(--font-brand);
    font-weight: 600;
    font-size: 1.8rem;
    letter-spacing: -.01em;
}
.login-brand .brand-dot { color: var(--accent); }

/* ---------- Small screens: sidebar becomes a drawer ---------- */
.sidebar-backdrop { display: none; }

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    .sidebar-open .app-sidebar { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
    .sidebar-open .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1035;
        background: rgba(8, 18, 15, .5);
    }
    .app-main { margin-left: 0; }
    .menu-toggle { display: inline-grid; }
    .user-name, .user-caret { display: none; }
    .user-btn { padding: .25rem; }
    .app-topbar { padding: 0 1rem; }
    .app-content { padding: 1.25rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    .app-sidebar, .nav-sub, .nav-chevron, .nav-skeleton { transition: none; animation: none; }
}

/* Login page */
.login-sub { color: var(--bs-secondary-color); text-align: center; margin: .5rem 0 1rem; }
.login-google { display: flex; justify-content: center; min-height: 44px; }
