:root {
    color-scheme: light dark;
    --bg: #faf7f4;
    --surface: #ffffff;
    --surface-2: #f3eee9;
    --text: #2a2024;
    --muted: #7a6e72;
    --line: #e8e0da;
    --accent: #7b2d4f;
    --accent-hover: #64223f;
    --accent-soft: #f6e8ee;
    --accent-text: #ffffff;
    --danger: #a3302a;
    --danger-bg: #fbeceb;
    --ok: #2f6b4f;
    --ok-bg: #e5f2ea;
    --warn: #8a5a12;
    --warn-bg: #fbf0dc;
    --side-bg: #2b1b23;
    --side-text: #f4eaef;
    --side-muted: #b9a4ae;
    --side-hover: rgba(255, 255, 255, .07);
    --side-line: rgba(255, 255, 255, .1);
    --shadow: 0 1px 2px rgba(43, 27, 35, .05), 0 8px 24px rgba(43, 27, 35, .08);
    --font: "Inter", "Segoe UI", system-ui, sans-serif;
    --font-display: "Fraunces", Georgia, serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171214;
        --surface: #211a1d;
        --surface-2: #2c2327;
        --text: #f2eaee;
        --muted: #ad9fa5;
        --line: #3a2f34;
        --accent: #e59bbb;
        --accent-hover: #f0b5ce;
        --accent-soft: #3d2430;
        --accent-text: #2b0f1c;
        --danger: #f2a7a2;
        --danger-bg: #3e2220;
        --ok: #9fd8b8;
        --ok-bg: #1d3528;
        --warn: #f0c983;
        --warn-bg: #3a2d16;
        --side-bg: #120d10;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.6 var(--font);
    -webkit-font-smoothing: antialiased;
}

#app { height: 100%; }
h1 { font: 600 1.75rem/1.2 var(--font-display); letter-spacing: -.01em; margin: 0 0 .35rem; }
a { color: var(--accent); }
.muted { color: var(--muted); }

button, input, select, textarea { font: inherit; color: inherit; }

button {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .5rem .95rem;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}

button:hover:not(:disabled) { border-color: var(--muted); }

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
}

button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.link {
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent);
    text-align: left;
}

button.link:hover { text-decoration: underline; }

input, select, textarea {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .6rem .75rem;
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.brand { display: flex; align-items: center; gap: .6rem; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #a8476f, #5c1f3b);
    color: #fff;
    font: 600 1.2rem/1 var(--font-display);
}

.brand-name { font: 600 1.15rem/1.1 var(--font-display); }
.brand-sub { display: block; font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; opacity: .7; }

/* Sign in */

.login-page {
    min-height: 100%;
    display: grid;
    place-items: center;
    padding: 16px;
    background:
        radial-gradient(60rem 40rem at 10% -10%, var(--accent-soft), transparent 60%),
        radial-gradient(50rem 30rem at 110% 110%, var(--surface-2), transparent 60%),
        var(--bg);
}

.login-card {
    width: min(400px, 100%);
    display: grid;
    gap: 1rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.login-card .brand { margin-bottom: .5rem; }
.login-card h1 { font-size: 1.5rem; margin: 0; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: .3rem; font-size: .9rem; font-weight: 600; }
.login-card button.primary { padding: .7rem; margin-top: .25rem; }
.form-error { color: var(--danger); background: var(--danger-bg); border-radius: 10px; padding: .5rem .75rem; margin: 0; }

/* Chat shell */

.shell { height: 100dvh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }

.sidebar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
    padding: 1.1rem .9rem;
    background: var(--side-bg);
    color: var(--side-text);
}

.sidebar .brand { padding: 0 .3rem; }
.sidebar button.primary { background: #fff; border-color: #fff; color: #5c1f3b; }
.sidebar button.primary:hover:not(:disabled) { background: #f6e8ee; border-color: #f6e8ee; }

.history-label {
    margin: .25rem .4rem 0;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--side-muted);
}

.history { flex: 1; min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 2px; }

.history-item {
    background: none;
    border: 0;
    border-radius: 8px;
    color: var(--side-muted);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: .5rem .6rem;
}

.history-item:hover { background: var(--side-hover); color: var(--side-text); }
.history-item.active { background: rgba(255, 255, 255, .12); color: var(--side-text); }

.account { display: grid; gap: .6rem; padding: .9rem .3rem 0; border-top: 1px solid var(--side-line); }
.account-person { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.account-person div { display: grid; min-width: 0; line-height: 1.3; }
.account-person strong, .account-person span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-person span { font-size: .82rem; color: var(--side-muted); }

.avatar {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    background: #a8476f;
    color: #fff;
    font-weight: 600;
    font-size: .9rem;
}

.account-links { display: flex; gap: 1rem; font-size: .88rem; }
.account-links a, .account-links button.link { color: var(--side-muted); text-decoration: none; }
.account-links a:hover, .account-links button.link:hover { color: var(--side-text); text-decoration: underline; }

.chips { display: flex; flex-wrap: wrap; gap: .3rem; }

.chip {
    font-size: .76rem;
    font-weight: 500;
    padding: .1rem .55rem;
    border-radius: 99px;
    background: var(--surface-2);
}

.sidebar .chip { background: var(--side-hover); color: var(--side-text); }
.chip.allow { background: var(--ok-bg); color: var(--ok); }
.chip.deny { background: var(--danger-bg); color: var(--danger); }
.chip.flag { background: var(--warn-bg); color: var(--warn); }

.chat { display: flex; flex-direction: column; min-height: 0; }

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    padding: 2rem max(16px, calc((100% - 800px) / 2));
}

.empty { margin: auto; text-align: center; display: grid; justify-items: center; gap: .4rem; padding: 1rem 0; }
.empty .brand-mark { width: 52px; height: 52px; font-size: 1.7rem; border-radius: 14px; margin-bottom: .6rem; }
.empty p { margin: 0 0 1rem; }

.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; width: min(560px, 100%); }

.suggestions button {
    text-align: left;
    padding: .75rem .9rem;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(43, 27, 35, .04);
}

.suggestions button:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); }
.suggestions small { display: block; color: var(--muted); font-size: .76rem; margin-bottom: .1rem; }

.turn { display: flex; gap: .75rem; align-items: flex-start; }
.turn.user { justify-content: flex-end; }
.turn .avatar { width: 30px; height: 30px; margin-top: .1rem; border-radius: 9px; background: linear-gradient(135deg, #a8476f, #5c1f3b); font: 600 .95rem/1 var(--font-display); }

.bubble { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.turn.assistant .bubble { flex: 1; padding-top: .15rem; }

.bubble.user {
    max-width: 80%;
    white-space: pre-wrap;
    background: var(--accent);
    color: var(--accent-text);
    border-radius: 16px 16px 4px 16px;
    padding: .6rem .95rem;
}

.bubble.blocked {
    background: var(--danger-bg);
    color: var(--danger);
    border-radius: 12px;
    padding: .7rem .95rem;
}

.bubble table { display: block; overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
.bubble th { background: var(--surface-2); }
.bubble code { background: var(--surface-2); border-radius: 5px; padding: .05rem .3rem; font-size: .9em; }
.bubble pre code { background: none; padding: 0; }

table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: .55rem .75rem; text-align: left; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: .8rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
td.center { text-align: center; }
td.nowrap { white-space: nowrap; }
td.detail { max-width: 380px; overflow-wrap: anywhere; }

pre { overflow-x: auto; background: var(--surface-2); border-radius: 10px; padding: .75rem; }

.status { display: flex; align-items: center; gap: .5rem; color: var(--muted); margin: 0 0 0 2.6rem; font-size: .9rem; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse { 50% { opacity: .25; transform: scale(.7); } }

.composer { padding: .5rem max(16px, calc((100% - 800px) / 2)) 1.25rem; }

.composer-box {
    display: flex;
    align-items: flex-end;
    gap: .5rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: .45rem .45rem .45rem .9rem;
    box-shadow: var(--shadow);
    transition: border-color .15s;
}

.composer-box:focus-within { border-color: var(--accent); }

.composer textarea {
    flex: 1;
    min-width: 0;
    resize: none;
    border: 0;
    background: none;
    padding: .45rem 0;
    box-shadow: none;
}

.composer button { border-radius: 12px; padding: .55rem 1.1rem; }
.composer-note { margin: .5rem 0 0; text-align: center; font-size: .76rem; color: var(--muted); }

/* Modules */

.modules { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 3px; background: var(--side-hover); border-radius: 11px; }

.modules a {
    padding: .45rem .5rem;
    border-radius: 8px;
    color: var(--side-muted);
    font-size: .88rem;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
}

.modules a:hover { color: var(--side-text); }
.modules a.active { background: rgba(255, 255, 255, .14); color: var(--side-text); }
.schedule-dot { display: inline-block; width: 7px; height: 7px; margin-right: .45rem; border-radius: 50%; background: #e59bbb; vertical-align: middle; }

/* Analytics */

.report-page { min-height: 0; overflow-y: auto; padding: 2rem max(16px, calc((100% - 1040px) / 2)); }
.report-page > .status { margin-left: 0; }

.report-new { display: grid; justify-items: center; gap: .5rem; max-width: 640px; margin: 8vh auto 0; text-align: center; }
.report-new .brand-mark { width: 52px; height: 52px; font-size: 1.7rem; border-radius: 14px; margin-bottom: .5rem; }
.report-new > p { margin: 0 0 .75rem; }
.report-new .composer-box { width: 100%; text-align: left; }
.report-new .composer-box textarea { flex: 1; min-width: 0; resize: none; border: 0; background: none; padding: .45rem 0; box-shadow: none; }
.report-new .composer-box button { border-radius: 12px; padding: .55rem 1.1rem; }
.report-new .status { margin: .5rem 0 0; }
.report-new .suggestions { margin-top: 1rem; }

.report-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.report-head h1 { margin: 0; }
.report-head p { margin: .2rem 0 0; }
.report-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem; }
.schedule { display: grid; gap: .15rem; font-size: .76rem; font-weight: 600; color: var(--muted); }
.schedule select { padding: .45rem .6rem; font-size: .9rem; font-weight: 400; color: var(--text); }
.report-meta { margin: .75rem 0 0; font-size: .85rem; }
.report-summary { max-width: 70ch; margin: 1rem 0 0; }
.report-page .form-error { margin-top: .75rem; }

.blocks { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-top: 1.5rem; }

.block {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1rem 1.1rem;
    box-shadow: 0 1px 2px rgba(43, 27, 35, .04);
}

.block h3 { margin: 0 0 .6rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.block p { margin: 0; }
.block-bar, .block-line { grid-column: span 2; }
.block-table { grid-column: 1 / -1; }
.block .table-wrap { box-shadow: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.kpi-value { font: 600 clamp(1.3rem, 2.3vw, 2rem)/1.15 var(--font-display); letter-spacing: -.01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 34%) minmax(0, 1fr) auto; align-items: center; gap: .6rem; font-size: .85rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; }
.bar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; background: var(--accent); }
.bar-row:hover .bar-fill { background: var(--accent-hover); }
.bar-value { font-variant-numeric: tabular-nums; color: var(--muted); }

.line-chart { display: block; width: 100%; height: auto; overflow: visible; }
.line-chart polyline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.line-chart circle { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.line-chart circle:hover { r: 6; }
.line-chart .grid { stroke: var(--line); stroke-dasharray: 3 4; }
.line-chart .axis { stroke: var(--line); }
.line-chart .tick { fill: var(--muted); font-size: 17px; }

.report-sql { margin-top: 1.5rem; font-size: .9rem; }
.report-sql summary { cursor: pointer; color: var(--muted); }
.report-sql pre { white-space: pre-wrap; font-size: .82rem; }

@media (max-width: 900px) {
    .blocks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .block-bar, .block-line { grid-column: 1 / -1; }
}

/* Governance */

.admin { max-width: 1080px; margin: 0 auto; padding: 2rem 16px; }
.admin-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.tabs { display: flex; gap: .25rem; margin: 1.25rem 0; padding: .25rem; background: var(--surface-2); border-radius: 12px; overflow-x: auto; width: fit-content; max-width: 100%; }

.tabs button {
    background: none;
    border: 0;
    border-radius: 9px;
    color: var(--muted);
    white-space: nowrap;
}

.tabs button:hover:not(:disabled) { color: var(--text); }
.tabs button.active { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(43, 27, 35, .12); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 1px 2px rgba(43, 27, 35, .04); }
.table-wrap th { background: var(--surface-2); }
.table-wrap tbody tr:hover { background: color-mix(in srgb, var(--surface-2) 50%, transparent); }
.filter { width: min(320px, 100%); margin-bottom: .75rem; }
.search { display: flex; gap: .5rem; margin-bottom: .75rem; }
.search input { flex: 1; min-width: 0; max-width: 320px; }
input[type="checkbox"] { accent-color: var(--accent); width: 1rem; height: 1rem; }

@media (max-width: 720px) {
    .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
    .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; padding: .75rem 16px; }
    .history, .history-label, .account .chips, .account-person div { display: none; }
    .modules { order: 3; width: 100%; }
    .report-page { padding-top: 1.25rem; }
    .account { display: flex; align-items: center; padding: 0; border-top: 0; }
    .messages { padding-top: 1.25rem; }
    .suggestions { grid-template-columns: minmax(0, 1fr); }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    inset: auto 0 0 0;
    padding: .6rem 1rem;
    background: var(--danger-bg);
    color: var(--danger);
}

#blazor-error-ui .dismiss { float: right; cursor: pointer; }

.loading-progress { display: block; width: 80px; height: 80px; margin: 30vh auto 1rem; }
.loading-progress circle { fill: none; stroke: var(--line); stroke-width: .6rem; }
.loading-progress circle:last-child {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
}

.loading-progress-text { text-align: center; color: var(--muted); }
.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Loading"); }
