/* ==========================================================================
   Application shell — sidebar, topbar and page canvas.
   Shared by the admin panel and the agency workspace so both stay in step.
   ========================================================================== */

/* ── Boot & auth ───────────────────────────────────────────────────────── */

.boot {
    position: fixed;
    inset: 0;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: var(--sp-5);
    background: var(--bg-canvas);
    z-index: 500;
}
.boot-mark { opacity: .9; }

.auth-screen {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: var(--sp-6);
    background:
        radial-gradient(900px 480px at 50% -12%, rgba(109, 124, 255, .16), transparent 62%),
        var(--bg-canvas);
}

.auth-card {
    width: min(400px, 100%);
    display: flex;
    flex-direction: column;
    gap: var(--sp-5);
    padding: var(--sp-8) var(--sp-6);
    background: var(--bg-surface);
    border: 1px solid var(--line);
    border-radius: var(--r-xl);
    box-shadow: var(--shadow-lg);
}

.auth-brand { display: flex; align-items: center; gap: var(--sp-3); }
.auth-brand-name { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 800; color: var(--ink-strong); }
.auth-brand-sub { font-size: var(--text-sm); color: var(--ink-muted); }

/* ── Shell ─────────────────────────────────────────────────────────────── */

.shell {
    display: grid;
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    min-height: 100dvh;
    background: var(--bg-canvas);
}

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

/* ── Sidebar ───────────────────────────────────────────────────────────── */

.sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
    border-right: 1px solid var(--line);
    position: sticky;
    top: 0;
    height: 100dvh;
    z-index: 60;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-h);
    padding: 0 var(--sp-4);
    border-bottom: 1px solid var(--line);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    font-family: var(--font-display);
    font-weight: 800;
    font-size: var(--text-lg);
    color: var(--ink-strong);
    letter-spacing: -.02em;
}
.sidebar-brand:hover { color: var(--ink-strong); }

.sidebar-close { display: none; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--sp-4) var(--sp-3);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-group-label {
    padding: var(--sp-4) var(--sp-3) var(--sp-2);
    font-size: var(--text-2xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-faint);
}
.nav-group-label:first-child { padding-top: 0; }

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: 8px var(--sp-3);
    border-radius: var(--r-md);
    color: var(--ink-muted);
    font-size: var(--text-md);
    font-weight: 500;
    transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
    position: relative;
}
.nav-link:hover { background: var(--bg-raised); color: var(--ink-strong); }
.nav-link.is-active { background: var(--brand-soft); color: var(--brand); }
.nav-link.is-active::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 18px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
}
.nav-link svg { width: 17px; height: 17px; flex: none; }
.nav-link .badge { margin-left: auto; }

.sidebar-foot { padding: var(--sp-3); border-top: 1px solid var(--line); }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    padding: var(--sp-2) var(--sp-3);
    border: 0;
    border-radius: var(--r-md);
    background: transparent;
    text-align: left;
    transition: background var(--dur-fast) var(--ease);
}
.sidebar-user:hover { background: var(--bg-raised); }
.sidebar-user-info { display: flex; flex-direction: column; min-width: 0; }
.sidebar-user-name { font-size: var(--text-sm); font-weight: 600; color: var(--ink-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: var(--text-xs); color: var(--ink-faint); }

.sidebar-scrim { display: none; }

/* ── Topbar ────────────────────────────────────────────────────────────── */

.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    height: var(--topbar-h);
    padding: 0 var(--sp-5);
    background: color-mix(in srgb, var(--bg-canvas) 88%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.topbar-title {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--ink-strong);
}

.sidebar-toggle { display: none; }

/* ── Page ──────────────────────────────────────────────────────────────── */

.page {
    flex: 1;
    padding: var(--sp-6) var(--sp-5) var(--sp-16);
    max-width: 1500px;
    width: 100%;
    margin-inline: auto;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--sp-4);
    flex-wrap: wrap;
    margin-bottom: var(--sp-5);
}
.page-head h1 { font-size: var(--text-2xl); }
.page-head p { color: var(--ink-muted); font-size: var(--text-sm); margin: 4px 0 0; }

.toolbar {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
    margin-bottom: var(--sp-4);
}
.toolbar .input-group { min-width: 240px; flex: 1 1 240px; max-width: 380px; }
.toolbar .select { width: auto; min-width: 150px; }

/* ── Charts ────────────────────────────────────────────────────────────── */

.chart {
    width: 100%;
    height: 220px;
    display: block;
}
.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--sp-3);
    margin-top: var(--sp-3);
    font-size: var(--text-xs);
    color: var(--ink-muted);
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* ── Detail layout ─────────────────────────────────────────────────────── */

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: var(--sp-5);
    align-items: start;
}

.kv { display: grid; grid-template-columns: minmax(120px, auto) minmax(0, 1fr); gap: var(--sp-2) var(--sp-4); font-size: var(--text-md); }
.kv dt { color: var(--ink-muted); }
.kv dd { margin: 0; color: var(--ink-strong); word-break: break-word; }

.timeline { display: flex; flex-direction: column; gap: var(--sp-3); }
.timeline-item { display: flex; gap: var(--sp-3); font-size: var(--text-sm); }
.timeline-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--brand);
    margin-top: 6px;
    flex: none;
    box-shadow: 0 0 0 3px var(--brand-soft);
}

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 1180px) {
    .detail-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 980px) {
    .shell { grid-template-columns: minmax(0, 1fr); }

    .sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: min(280px, 84vw);
        transform: translateX(-102%);
        transition: transform var(--dur-slow) var(--ease);
        box-shadow: var(--shadow-lg);
    }
    .shell.nav-open .sidebar { transform: none; }
    .shell.nav-open .sidebar-scrim {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 55;
        background: var(--bg-overlay);
    }

    .sidebar-close, .sidebar-toggle { display: inline-flex; }
    .page { padding: var(--sp-5) var(--sp-4) var(--sp-16); }
    .topbar { padding: 0 var(--sp-4); }
}
