/* App shell — login page, dashboard layout, page chrome. */

/* ── Login page ─────────────────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    padding: var(--sp-5);
}
@media (min-width: 900px) {
    .login-page {
        grid-template-columns: minmax(420px, 1fr) 1fr;
        padding: 0;
    }
}

.login-card {
    width: 100%;
    max-width: 440px;
    padding: var(--sp-7);
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--rad-lg);
    box-shadow: var(--shadow-2);
}
.login-mast {
    display: flex; align-items: baseline;
    gap: var(--sp-3);
    margin-bottom: var(--sp-7);
}
.login-mast .wordmark {
    font-family: var(--font-display);
    font-weight: 500;
    font-size: var(--t-2xl);
    letter-spacing: var(--tracking-tight);
    font-variation-settings: "SOFT" 30, "opsz" 80;
}
.login-mast .accent-dot {
    width: 8px; height: 8px;
    background: var(--accent);
    border-radius: 999px;
    margin-bottom: 4px;
}
.login-mast .subtitle {
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    color: var(--muted);
    margin-left: auto;
}
.login-headline {
    font-family: var(--font-display);
    font-size: var(--t-3xl);
    line-height: var(--lh-tight);
    letter-spacing: var(--tracking-tight);
    margin-bottom: var(--sp-2);
    font-variation-settings: "SOFT" 30, "opsz" 100;
}
.login-headline em {
    font-style: italic;
    font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
    color: var(--accent-ink);
}
.login-sub {
    color: var(--muted);
    margin-bottom: var(--sp-6);
    font-size: var(--t-sm);
    line-height: var(--lh-normal);
}
.login-form .btn { width: 100%; margin-top: var(--sp-3); }

.login-poster {
    display: none;
    background: var(--forest);
    color: var(--paper);
    padding: var(--sp-8);
    height: 100%;
    position: relative;
    overflow: hidden;
}
@media (min-width: 900px) {
    .login-poster { display: flex; flex-direction: column; justify-content: space-between; }
}
.login-poster::before {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 70% 30%, rgba(199, 127, 35, 0.25), transparent 60%);
}
.login-poster .quote {
    position: relative;
    z-index: 2;
    font-family: var(--font-display);
    font-size: var(--t-3xl);
    line-height: 1.2;
    font-variation-settings: "SOFT" 50, "opsz" 144;
    max-width: 480px;
}
.login-poster .quote em {
    font-style: italic;
    color: var(--accent-2);
    font-variation-settings: "SOFT" 100, "WONK" 1, "opsz" 144;
}
.login-poster .footer-mark {
    position: relative; z-index: 2;
    font-size: var(--t-xs);
    letter-spacing: var(--tracking-label);
    text-transform: uppercase;
    opacity: 0.6;
}
.login-poster .tower-art {
    position: absolute;
    right: var(--sp-7);
    bottom: var(--sp-7);
    width: min(360px, 55%);
    height: auto;
    z-index: 1;
    pointer-events: none;
}
.tower-art .tower-body {
    fill: rgba(245, 241, 232, 0.04);
    stroke: rgba(245, 241, 232, 0.18);
    stroke-width: 1;
}
.tower-art .windows rect {
    fill: rgba(245, 241, 232, 0.08);
}
.tower-art .windows-lit rect {
    fill: var(--accent-2);
    opacity: 0.55;
    animation: tower-window-pulse 3s ease-in-out infinite;
}
.tower-art .windows-lit rect:nth-child(2) { animation-delay: 1s; }
.tower-art .windows-lit rect:nth-child(3) { animation-delay: 2s; }

.tower-art .connectors path {
    fill: none;
    stroke: var(--accent);
    stroke-opacity: 0.4;
    stroke-width: 1;
    stroke-dasharray: 2 3;
    animation: tower-connector-flow 1.4s linear infinite;
}

.tower-art .bubble rect,
.tower-art .bubble polygon {
    fill: var(--accent);
    stroke: var(--accent);
    stroke-width: 1;
}
.tower-art .bubble {
    animation: tower-bubble-rise 5s ease-in-out infinite;
}
.tower-art .bubble-1 { opacity: 0.85; --bubble-max: 0.85; animation-delay: 0s;   }
.tower-art .bubble-2 { opacity: 0.70; --bubble-max: 0.70; animation-delay: 0.8s; }
.tower-art .bubble-3 { opacity: 0.55; --bubble-max: 0.55; animation-delay: 1.6s; }
.tower-art .bubble-4 { opacity: 0.70; --bubble-max: 0.70; animation-delay: 2.4s; }
.tower-art .bubble-5 { opacity: 0.45; --bubble-max: 0.45; animation-delay: 3.2s; }

@keyframes tower-bubble-rise {
    0%   { transform: translateY(4px);   opacity: 0; }
    25%  { opacity: var(--bubble-max, 0.7); }
    75%  { opacity: var(--bubble-max, 0.7); }
    100% { transform: translateY(-28px); opacity: 0; }
}
@keyframes tower-window-pulse {
    0%, 100% { opacity: 0.25; }
    50%      { opacity: 0.75; }
}
@keyframes tower-connector-flow {
    to { stroke-dashoffset: -5; }
}

@media (prefers-reduced-motion: reduce) {
    .tower-art .bubble,
    .tower-art .windows-lit rect,
    .tower-art .connectors path { animation: none; }
}

/* ── App shell ──────────────────────────────────────────────────────── */
.app {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas:
        "sidebar topbar"
        "sidebar main";
    min-height: 100vh;
}
@media (max-width: 900px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-areas:
            "topbar"
            "main";
    }
}

/* ── Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
    grid-area: sidebar;
    background: var(--ink);
    color: var(--paper);
    padding: var(--sp-5) var(--sp-4);
    display: flex; flex-direction: column;
    gap: var(--sp-4);
    position: sticky; top: 0;
    height: 100vh;
    /* When the brand + sections + user block exceed 100vh (short windows,
       many nav items, or with the Boss section visible) the user block
       used to escape past the dark background. Scroll inside instead. */
    overflow-y: auto;
    overscroll-behavior: contain;
}
/* Themed scrollbar so the dark sidebar doesn't get a bright OS bar. */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(245, 241, 232, 0.12);
    border-radius: 999px;
}
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(245, 241, 232, 0.22); }
@media (max-width: 900px) {
    .sidebar {
        position: fixed; inset: 0;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform var(--duration-2) var(--easing-out);
        height: 100vh;
        width: min(280px, 80vw);
    }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-3); }
}
.sidebar-brand {
    display: flex; align-items: baseline;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-3) var(--sp-3);
    border-bottom: 1px solid rgba(245, 241, 232, 0.1);
    margin-bottom: var(--sp-4);
}
.sidebar-brand .wordmark {
    font-family: var(--font-display);
    font-size: var(--t-xl);
    letter-spacing: var(--tracking-tight);
    color: var(--paper);
    font-variation-settings: "SOFT" 30, "opsz" 80;
}
.sidebar-brand .accent-dot {
    width: 6px; height: 6px;
    background: var(--accent-2);
    border-radius: 999px;
    margin-bottom: 4px;
}
.sidebar-section {
    display: flex; flex-direction: column; gap: 2px;
}
.sidebar-section .sect-label {
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    color: rgba(245, 241, 232, 0.45);
    padding: 0 var(--sp-3);
    margin-bottom: var(--sp-2);
    font-weight: 600;
}
.nav-link {
    display: flex; align-items: center;
    gap: var(--sp-3);
    padding: 9px var(--sp-3);
    border-radius: var(--rad-sm);
    color: var(--paper);
    font-size: var(--t-sm);
    font-weight: 500;
    transition: background var(--duration-1) var(--easing-out),
                color var(--duration-1) var(--easing-out);
}
.nav-link:hover {
    background: rgba(245, 241, 232, 0.06);
    text-decoration: none;
    color: var(--paper);
}
.nav-link.active {
    background: var(--accent);
    color: #fff;
}
.nav-link .nav-icon {
    width: 16px; height: 16px;
    opacity: 0.7;
    flex: 0 0 16px;
    /* Centre the inline SVG inside the 16x16 box; without this the
       SVG sits on the text baseline and looks shifted up. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}
.nav-link .nav-icon svg { display: block; }
.nav-link.active .nav-icon { opacity: 1; }

.sidebar-user {
    margin-top: auto;
    padding: var(--sp-3);
    border-top: 1px solid rgba(245, 241, 232, 0.1);
    display: flex; flex-direction: column; gap: 4px;
    /* Keep the user block at its natural height when the sidebar has to
       scroll — without this it would compress and clip the Sign-out link. */
    flex-shrink: 0;
}
.sidebar-user .name { font-weight: 600; font-size: var(--t-sm); }
.sidebar-user .email { font-size: var(--t-xs); color: rgba(245, 241, 232, 0.6); }
.sidebar-user .sign-out {
    margin-top: var(--sp-2);
    color: var(--accent-2);
    font-size: var(--t-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
    font-weight: 600;
    cursor: pointer;
}

/* ── Topbar ─────────────────────────────────────────────────────────── */
.topbar {
    grid-area: topbar;
    border-bottom: 1px solid var(--hair);
    background: var(--paper);
    display: flex; align-items: center;
    padding: 0 var(--sp-6);
    gap: var(--sp-4);
    position: sticky; top: 0; z-index: 50;
}
@media (max-width: 900px) { .topbar { padding: 0 var(--sp-4); } }

.topbar .menu-toggle {
    display: none;
    padding: var(--sp-2);
    margin-left: calc(var(--sp-2) * -1);
}
@media (max-width: 900px) { .topbar .menu-toggle { display: inline-flex; } }

.topbar .crumbs {
    display: flex; align-items: baseline;
    gap: var(--sp-3);
}
.topbar .crumbs .page-title {
    font-family: var(--font-display);
    font-size: var(--t-xl);
    font-weight: 500;
    font-variation-settings: "SOFT" 30, "opsz" 60;
}
.topbar .crumbs .page-sub {
    font-size: var(--t-xs);
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: var(--tracking-label);
}

.topbar .actions { margin-left: auto; display: flex; gap: var(--sp-3); align-items: center; }

/* Property switcher — styled native <select>. Hairline frame, monospace
 * tail for the code, accent caret on focus. */
.prop-switch {
    appearance: none;
    -webkit-appearance: none;
    font-family: var(--font-body);
    font-size: var(--t-sm);
    font-weight: 500;
    padding: 8px 36px 8px 14px;
    background-color: var(--surface);
    background-image:
        linear-gradient(45deg, transparent 50%, var(--accent) 50%),
        linear-gradient(135deg, var(--accent) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 50%,
        calc(100% - 13px) 50%;
    background-size: 5px 5px;
    background-repeat: no-repeat;
    border: 1px solid var(--hair-2);
    border-radius: var(--rad-sm);
    color: var(--ink);
    max-width: 280px;
    cursor: pointer;
    transition: border-color var(--duration-1) var(--easing-out);
}
.prop-switch:hover { border-color: var(--muted); }
.prop-switch:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
@media (max-width: 540px) {
    .prop-switch { max-width: 180px; }
}

/* ── Main ───────────────────────────────────────────────────────────── */
.main {
    grid-area: main;
    padding: var(--sp-6);
    max-width: 1400px;
    width: 100%;
    /* Without min-width:0, a wide child (data table) blows the grid track
       wider than the viewport, pushing the sidebar off-screen instead of
       letting the inner .table-wrap scroll. */
    min-width: 0;
}
@media (max-width: 900px) { .main { padding: var(--sp-5) var(--sp-4); } }

.page-section + .page-section { margin-top: var(--sp-7); }

.section-head {
    display: flex; align-items: baseline; justify-content: space-between;
    margin-bottom: var(--sp-4);
    gap: var(--sp-4);
}
.section-head h2 {
    font-family: var(--font-display);
    font-size: var(--t-2xl);
    font-weight: 500;
    font-variation-settings: "SOFT" 30, "opsz" 80;
}

.toolbar {
    display: flex; gap: var(--sp-3);
    align-items: center;
    margin-bottom: var(--sp-4);
    flex-wrap: wrap;
}
.toolbar .input { width: auto; min-width: 220px; flex: 1; max-width: 360px; }
.toolbar .select { width: auto; }

/* ── Dashboard ──────────────────────────────────────────────────────── */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--sp-4);
    margin-bottom: var(--sp-6);
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--hair);
    border-radius: var(--rad-md);
    padding: var(--sp-5);
    position: relative;
    overflow: hidden;
    transition: transform var(--duration-2) var(--easing-out),
                box-shadow var(--duration-2) var(--easing-out);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.stat-card .eyebrow { margin-bottom: var(--sp-3); }
.stat-card .display-num { margin-bottom: var(--sp-2); }
.stat-card .stat-sub { font-size: var(--t-sm); color: var(--muted); }
.stat-card .corner {
    position: absolute;
    top: -1px; right: -1px;
    width: 80px; height: 80px;
    background: var(--accent-soft);
    border-bottom-left-radius: var(--rad-lg);
    opacity: 0.4;
    z-index: 0;
}
.stat-card > * { position: relative; z-index: 1; }

.staggered > * { animation: fade-up var(--duration-3) var(--easing-out) both; }
.staggered > *:nth-child(1) { animation-delay: 30ms; }
.staggered > *:nth-child(2) { animation-delay: 90ms; }
.staggered > *:nth-child(3) { animation-delay: 150ms; }
.staggered > *:nth-child(4) { animation-delay: 210ms; }
.staggered > *:nth-child(5) { animation-delay: 270ms; }

@keyframes fade-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Hide on mobile */
.hide-mobile { }
@media (max-width: 900px) { .hide-mobile { display: none; } }

/* Backdrop for mobile sidebar */
.sidebar-scrim {
    display: none;
    position: fixed; inset: 0;
    background: rgba(26, 22, 18, 0.4);
    z-index: 89;
}
.sidebar-scrim.open { display: block; }
