:root,
[data-theme="dark"] {
    --sg-bg: #0f172a;
    --sg-bg-elevated: #1a2740;
    --sg-surface: #1a2740;
    --sg-surface-2: color-mix(in srgb, var(--sg-surface) 86%, white);
    --sg-border: color-mix(in srgb, var(--sg-accent) 22%, transparent);
    --sg-text: #f8fafc;
    --sg-muted: #94a3b8;
    --sg-primary: #1e4976;
    --sg-accent: #7dd3fc;
    --sg-danger: #f87171;
    --sg-success: #34d399;
    --sg-radius: 24px;
    --sg-shadow: 0 24px 60px rgba(2, 8, 23, 0.35);
}

[data-theme="light"] {
    --sg-text: #0f172a;
    --sg-muted: #475569;
    --sg-border: color-mix(in srgb, var(--sg-primary) 16%, transparent);
    --sg-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    background: var(--sg-bg);
    color: var(--sg-text);
    font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
}

h1, h2, h3 {
    margin: 0;
    font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
    letter-spacing: -0.03em;
    font-weight: 700;
}

p { margin: 0; }

a { color: inherit; text-decoration: none; }

button, input, select {
    font: inherit;
}

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--sg-accent);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.muted { color: var(--sg-muted); }

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px 1fr;
    background:
        radial-gradient(circle at 12% 8%, color-mix(in srgb, var(--sg-primary) 42%, transparent), transparent 34%),
        radial-gradient(circle at 88% 92%, color-mix(in srgb, var(--sg-accent) 16%, transparent), transparent 30%),
        var(--sg-bg);
}

.sidebar {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 1.4rem 1.1rem;
    border-right: 1px solid var(--sg-border);
    background: color-mix(in srgb, var(--sg-surface) 55%, transparent);
    backdrop-filter: blur(22px);
}

.brand {
    display: flex;
    gap: 0.85rem;
    align-items: center;
    padding: 0.3rem 0.4rem 1.2rem;
}

.brand img {
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--sg-accent);
}

.brand strong { display: block; font-size: 0.95rem; }
.brand span { color: var(--sg-muted); font-size: 0.75rem; }

.side-nav { display: grid; gap: 0.25rem; }

.nav-label {
    margin: 1.15rem 0 0.35rem;
    padding: 0 0.7rem;
    color: var(--sg-muted);
    font-size: 0.7rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.side-nav a,
.nav-soon {
    padding: 0.7rem 0.8rem;
    border-radius: 14px;
    color: var(--sg-text);
}

.side-nav a.active {
    background: color-mix(in srgb, var(--sg-accent) 18%, transparent);
    box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--sg-accent) 40%, transparent);
}

.nav-soon {
    color: color-mix(in srgb, var(--sg-muted) 80%, transparent);
}

.side-foot {
    margin-top: auto;
    padding-top: 1rem;
}

.nav-user {
    margin-bottom: 0.7rem;
    color: var(--sg-muted);
    font-size: 0.8rem;
    word-break: break-all;
}

.workspace { min-width: 0; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    padding: 1.4rem 1.8rem 0.4rem;
}

.topbar-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.topbar-meta { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }

.menu-toggle,
.menu-close {
    display: none;
    border: 0;
    background: var(--sg-surface-2);
    box-shadow: inset 0 0 0 1px var(--sg-border);
    color: var(--sg-text);
    cursor: pointer;
}

.menu-toggle {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    padding: 0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.menu-toggle span {
    display: block;
    width: 16px;
    height: 2px;
    border-radius: 2px;
    background: var(--sg-text);
}

.menu-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    place-items: center;
    z-index: 2;
}

.nav-backdrop { display: none; }

.page {
    padding: 1.2rem 1.8rem 2.4rem;
    display: grid;
    gap: 1rem;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
}

.chip, .btn-ghost, .btn-gold, .segment button {
    border: 0;
    border-radius: 999px;
    padding: 0.55rem 0.9rem;
}

.chip {
    background: var(--sg-surface-2);
    box-shadow: inset 0 0 0 1px var(--sg-border);
    font-size: 0.78rem;
}

.chip.gold {
    color: #041018;
    background: var(--sg-accent);
}

.btn-gold {
    color: #041018;
    background: var(--sg-accent);
    font-weight: 700;
    cursor: pointer;
}

.btn-ghost {
    display: inline-flex;
    justify-content: center;
    background: transparent;
    box-shadow: inset 0 0 0 1px var(--sg-border);
    color: var(--sg-text);
    cursor: pointer;
}

.kpi-grid, .stat-grid, .preset-grid {
    display: grid;
    gap: 0.9rem;
}

.kpi-grid { grid-template-columns: repeat(4, 1fr); }
.stat-grid { grid-template-columns: repeat(4, 1fr); }
.preset-grid { grid-template-columns: repeat(4, 1fr); }
.preset-grid.themes-10 { grid-template-columns: repeat(5, 1fr); }

.kpi, .stat, .panel, .stage-card, .preset, .auth-card, .glass-card {
    background: color-mix(in srgb, var(--sg-surface) 62%, transparent);
    border: 1px solid var(--sg-border);
    border-radius: var(--sg-radius);
    box-shadow: var(--sg-shadow);
    backdrop-filter: blur(18px);
}

.kpi, .stat { padding: 1.1rem 1.15rem; }
.kpi span, .stat span { color: var(--sg-muted); font-size: 0.8rem; }
.kpi strong, .stat strong { display: block; margin: 0.45rem 0 0.3rem; font-size: 1.7rem; }
.kpi em { font-style: normal; color: var(--sg-muted); font-size: 0.78rem; }
.kpi.gold { background: linear-gradient(180deg, color-mix(in srgb, var(--sg-accent) 16%, var(--sg-surface)), var(--sg-surface)); }
.up { color: var(--sg-success) !important; }

.split {
    display: grid;
    grid-template-columns: 1.4fr 0.8fr;
    gap: 1rem;
}

.panel { padding: 1.15rem 1.2rem; }
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.9rem;
}

.data {
    width: 100%;
    border-collapse: collapse;
}

.data th, .data td {
    padding: 0.7rem 0.4rem;
    text-align: left;
    border-bottom: 1px solid var(--sg-border);
}

.data th { color: var(--sg-muted); font-size: 0.75rem; font-weight: 600; }

.activity { margin: 0; padding-left: 1.1rem; display: grid; gap: 0.55rem; color: var(--sg-muted); }

.profit-row {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
}

.profit-row strong { font-size: 1.6rem; }

.segment {
    display: flex;
    gap: 0.3rem;
    padding: 0.25rem;
    background: var(--sg-surface);
    border-radius: 999px;
    border: 1px solid var(--sg-border);
}

.segment button {
    background: transparent;
    color: var(--sg-muted);
    cursor: pointer;
}

.segment button.on {
    color: #041018;
    background: var(--sg-accent);
}

.timeline { display: grid; gap: 0.75rem; }

.stage-card {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 0.8rem;
    padding: 1rem;
}

.stage-index {
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: color-mix(in srgb, var(--sg-primary) 70%, black);
    color: #f6f0dc;
    font-weight: 700;
}

.doc-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.form-grid.single { grid-template-columns: 1fr; }

label {
    display: grid;
    gap: 0.4rem;
    color: var(--sg-muted);
    font-size: 0.82rem;
}

input, select {
    width: 100%;
    padding: 0.8rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--sg-border);
    background: var(--sg-bg-elevated);
    color: var(--sg-text);
}

input[type="color"] { height: 48px; padding: 0.25rem; }

.actions { display: flex; align-items: center; gap: 0.8rem; }
.ok { color: var(--sg-success); }
.form-error { color: var(--sg-danger); }

.preset {
    text-align: left;
    padding: 1rem;
    cursor: pointer;
    color: var(--sg-text);
}

.preset.on { box-shadow: inset 0 0 0 1px var(--sg-accent); }
.swatch {
    display: block;
    height: 42px;
    border-radius: 12px;
    margin-bottom: 0.75rem;
    background: linear-gradient(135deg, var(--a), var(--b));
}

.preset em { color: var(--sg-muted); font-style: normal; font-size: 0.78rem; }

.swatch.wide { height: 56px; }

.custom-swatch {
    background:
        conic-gradient(from 180deg, #7dd3fc, #c4b5fd, #fca5a5, #e0c36a, #7dd3fc);
}

.theme-preview {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 1.4rem;
    padding: 1.6rem;
    align-items: center;
}

.theme-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-top: 1rem;
}

.theme-pills span {
    padding: 0.35rem 0.7rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--sg-bg) 55%, transparent);
    border: 1px solid var(--sg-border);
    font-size: 0.78rem;
}

.mini-dash {
    position: relative;
    padding: 1.1rem;
    border-radius: 22px;
    background: color-mix(in srgb, var(--sg-bg) 45%, transparent);
    border: 1px solid var(--sg-border);
}

.mini-dash strong { display: block; margin: 0.3rem 0 0.8rem; }

.live-dot {
    position: absolute;
    top: 0.9rem;
    right: 0.9rem;
    font-size: 0.72rem;
    color: var(--sg-success);
}

.mini-bars {
    display: flex;
    align-items: end;
    gap: 0.45rem;
    height: 72px;
    margin-bottom: 0.8rem;
}

.mini-bars i {
    flex: 1;
    display: block;
    border-radius: 8px 8px 0 0;
    background: linear-gradient(180deg, var(--sg-accent), var(--sg-primary));
}

.mini-kpis {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.4rem;
    color: var(--sg-muted);
    font-size: 0.72rem;
}

.agency-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 1.2rem;
    align-items: center;
}

.logo-preview img {
    width: 132px;
    height: 132px;
    object-fit: cover;
    border-radius: 50%;
    box-shadow: 0 0 0 1px var(--sg-accent);
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 2rem;
    background:
        radial-gradient(circle at 20% 20%, color-mix(in srgb, var(--sg-primary) 35%, transparent), transparent 30%),
        radial-gradient(circle at 80% 80%, color-mix(in srgb, var(--sg-accent) 18%, transparent), transparent 28%),
        var(--sg-bg);
}

.auth-shell {
    width: min(980px, 100%);
    display: grid;
    grid-template-columns: 1.05fr 0.95fr;
    overflow: hidden;
    border-radius: 28px;
    border: 1px solid var(--sg-border);
    background: color-mix(in srgb, var(--sg-surface) 90%, transparent);
    box-shadow: var(--sg-shadow);
}

.auth-hero {
    padding: 2.4rem 2rem;
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--sg-primary) 42%, transparent), transparent),
        color-mix(in srgb, var(--sg-bg) 88%, black);
}

.auth-logo {
    width: 96px;
    height: 96px;
    object-fit: cover;
    border-radius: 50%;
    margin-bottom: 1.4rem;
}

.auth-hero h1 { font-size: 2.3rem; margin-bottom: 0.7rem; }
.auth-lead { color: #c9d0c8; max-width: 26rem; }
.auth-card { padding: 2.2rem 2rem; }
.auth-card h2 { margin-bottom: 0.35rem; }
.auth-form { display: grid; gap: 0.9rem; margin-top: 1.2rem; }
.check { display: flex; align-items: center; gap: 0.55rem; }
.check input { width: auto; }

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
    margin-bottom: 1rem;
}

.filters input, .filters select {
    flex: 1;
    min-width: 180px;
}

.link { color: var(--sg-accent); font-weight: 600; }
.link:hover { text-decoration: underline; }

.empty {
    padding: 1.4rem 0.2rem;
    color: var(--sg-muted);
}

.row-actions { text-align: right; }
.row-actions a { color: var(--sg-muted); }

.user-row-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.4rem;
    align-items: center;
}

.perm-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem 1rem;
    padding: 0.4rem 0 0.2rem;
}

.badge {
    display: inline-flex;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: var(--sg-surface-2);
    font-size: 0.75rem;
}

.badge.ok, .badge.approved { color: var(--sg-success); }
.badge.off, .badge.cancelled, .badge.closed, .badge.rejected { color: var(--sg-muted); }
.badge.draft, .badge.pending { color: var(--sg-accent); }

.span-2 { grid-column: span 2; }

textarea {
    width: 100%;
    padding: 0.8rem 0.85rem;
    border-radius: 12px;
    border: 1px solid var(--sg-border);
    background: var(--sg-bg-elevated);
    color: var(--sg-text);
    resize: vertical;
}

.repeat-row, .repeat-stack {
    display: grid;
    gap: 0.6rem;
    margin-bottom: 0.7rem;
}

.repeat-row {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    align-items: center;
}

.kv {
    list-style: none;
    margin: 0.8rem 0 0;
    padding: 0;
    display: grid;
    gap: 0.65rem;
}

.kv li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--sg-border);
    padding-bottom: 0.45rem;
}

.kv span { color: var(--sg-muted); }

label.check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.8rem 1rem;
    background: #b32121;
    color: white;
    z-index: 1000;
}

#blazor-error-ui.show { display: block; }

@media (max-width: 980px) {
    .app-shell, .auth-shell, .split, .kpi-grid, .stat-grid, .preset-grid, .preset-grid.themes-10, .form-grid, .agency-grid, .theme-preview {
        grid-template-columns: 1fr;
    }

    .menu-toggle { display: inline-flex; }
    .menu-close { display: grid; }

    .nav-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(2, 8, 23, 0.55);
        z-index: 30;
    }

    .app-shell.nav-open .nav-backdrop { display: block; }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(300px, 88vw);
        height: 100vh;
        z-index: 40;
        display: flex;
        transform: translateX(-110%);
        transition: transform 0.2s ease;
        background: var(--sg-surface);
        overflow-y: auto;
        box-shadow: var(--sg-shadow);
    }

    .app-shell.nav-open .sidebar { transform: translateX(0); }
    .app-shell.nav-open { overflow: hidden; }
    .brand { padding-right: 2.4rem; }

    .page, .topbar { padding-left: 1rem; padding-right: 1rem; }
    .toolbar { flex-wrap: wrap; align-items: start; }
    .segment { flex-wrap: wrap; overflow-x: auto; }
    .panel { overflow-x: auto; }
}
