:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f7f8fa;
    --text: #16191d;
    --muted: #68727f;
    --border: #e2e6eb;
    --accent: #2457c5;
    --accent-hover: #1d4aa8;
    --accent-soft: #e8eefc;
    --accent-text: #ffffff;
    --ok: #1f7a3f;
    --ok-soft: #e3f3e8;
    --warn-bg: #fff4d6;
    --warn-text: #6b4b00;
    --error-bg: #fde8e8;
    --error-text: #8a1c1c;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e1116;
        --surface: #161a20;
        --surface-2: #1c2129;
        --text: #e7eaee;
        --muted: #98a3b1;
        --border: #2a313b;
        --accent: #7ea6ff;
        --accent-hover: #9bb9ff;
        --accent-soft: #1d2a45;
        --accent-text: #0e1116;
        --ok: #6fd391;
        --ok-soft: #173223;
        --warn-bg: #3a2f0f;
        --warn-text: #ffd97a;
        --error-bg: #3b1515;
        --error-text: #ff9c9c;
        --shadow: none;
    }
}

:root[data-theme="dark"] {
    --bg: #0e1116;
    --surface: #161a20;
    --surface-2: #1c2129;
    --text: #e7eaee;
    --muted: #98a3b1;
    --border: #2a313b;
    --accent: #7ea6ff;
    --accent-hover: #9bb9ff;
    --accent-soft: #1d2a45;
    --accent-text: #0e1116;
    --ok: #6fd391;
    --ok-soft: #173223;
    --warn-bg: #3a2f0f;
    --warn-text: #ffd97a;
    --error-bg: #3b1515;
    --error-text: #ff9c9c;
    --shadow: none;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1:focus { outline: none; }
h1 { font-size: 1.5rem; margin: 0 0 0.35rem; letter-spacing: -0.015em; font-weight: 700; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; font-weight: 650; }
h3 { font-size: 0.9rem; margin: 1rem 0 0.4rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.88em; }
pre { font-family: var(--mono); font-size: 0.82rem; white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

/* ---- app shell ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1040px; margin: 0 auto; padding: 0 1rem; height: 56px; display: flex; align-items: center; gap: 2rem; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-text); font-size: 0.95rem; font-weight: 800; }
.nav { display: flex; gap: 0.25rem; margin-left: auto; }
.nav a { color: var(--muted); text-decoration: none; padding: 0.4rem 0.75rem; border-radius: 8px; font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }

.page { max-width: 1040px; margin: 0 auto; padding: 1.75rem 1rem 4rem; }
.logout { display: inline-flex; align-items: center; gap: 0.5rem; margin-left: 0.75rem; padding-left: 0.75rem; border-left: 1px solid var(--border); }
.login-page { max-width: 440px; padding-top: 4rem; }
.login-panel label { display: block; margin: 0.9rem 0 0.3rem; font-weight: 600; }
.login-panel input.query { width: 100%; }

/* ---- hero / search ---- */
.hero { margin-bottom: 1.25rem; }
.hero.compact h1 { font-size: 1.3rem; }
.lead { color: var(--muted); margin: 0 0 1.1rem; max-width: 64ch; }

.search { display: flex; gap: 0.5rem; }
input.query, textarea {
    flex: 1;
    min-width: 0;
    width: 100%;
    font: inherit;
    font-size: 1rem;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}
input.query:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; line-height: 1.5; }

button {
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    padding: 0.7rem 1.15rem;
    border: 1px solid var(--accent);
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.12s, border-color 0.12s;
}
button:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button:disabled { opacity: 0.45; cursor: default; }
button.secondary { background: transparent; color: var(--accent); }
button.secondary:hover:not(:disabled) { background: var(--accent-soft); }
button.danger { border-color: var(--error-text); color: var(--error-text); }
button.danger:hover:not(:disabled) { background: var(--error-bg); border-color: var(--error-text); }

.examples { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin-top: 0.75rem; color: var(--muted); font-size: 0.85rem; }
button.chip {
    padding: 0.2rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 999px;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
button.chip:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.row { display: flex; gap: 0.5rem; }
.row.end { justify-content: flex-end; margin-top: 0.5rem; }
.notice, .alert { margin: 0.75rem 0; padding: 0.7rem 1rem; border-radius: 10px; }
.notice { background: var(--warn-bg); color: var(--warn-text); }
.notice a { color: inherit; font-weight: 600; }
.alert { background: var(--error-bg); color: var(--error-text); }
.hint { color: var(--muted); margin: 0.4rem 0 0; font-size: 0.85rem; }

/* ---- panels ---- */
.panel {
    margin-top: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.panel.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }
.panel.empty p { margin: 0; }
.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1.1rem;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.panel-title { font-weight: 650; display: flex; align-items: center; gap: 0.5rem; }
.panel-body { padding: 1rem 1.1rem; }
.stats { display: flex; gap: 1rem; color: var(--muted); font-size: 0.83rem; font-variant-numeric: tabular-nums; }

.dot { display: inline-block; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

/* ---- badges ---- */
.badge {
    display: inline-block;
    padding: 0.12rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 650;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
    white-space: nowrap;
}
.badge.ok, .badge.status-finished { background: var(--ok-soft); color: var(--ok); border-color: transparent; text-transform: none; }
.badge.warn, .badge.status-running { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; text-transform: none; }
.badge.status-failed, .badge.status-cancelled, .badge.status-interrupted { background: var(--error-bg); color: var(--error-text); border-color: transparent; text-transform: none; }
.badge-websearch, .badge-webfetch { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge-websearchresults { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-completed { background: var(--ok); color: #fff; border-color: transparent; }
.badge-warning { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }

/* ---- timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0.25rem 0; }
.timeline-empty { padding: 1rem 1.1rem; color: var(--muted); }
.step {
    display: grid;
    grid-template-columns: 4.4rem 6rem 1fr;
    gap: 0.6rem;
    align-items: start;
    padding: 0.5rem 1.1rem;
    border-top: 1px solid var(--border);
    font-size: 0.92rem;
}
.step:first-child { border-top: none; }
.step time { color: var(--muted); font-family: var(--mono); font-size: 0.76rem; padding-top: 0.25rem; }
.step .badge { width: 100%; text-align: center; margin-top: 0.1rem; }
.step-body { min-width: 0; }
.step-title { overflow-wrap: anywhere; }
.step-websearch .step-title, .step-webfetch .step-title { font-family: var(--mono); font-size: 0.85rem; }
.step-thinking .step-title, .step-assistanttext .step-title { color: var(--muted); font-style: italic; }
.step-status .step-title { color: var(--muted); font-size: 0.86rem; }
.step-warning .step-title { color: var(--warn-text); }
.step-completed .step-title { font-weight: 600; }

.chips { list-style: none; margin: 0.35rem 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.chips a {
    display: inline-block;
    max-width: 100%;
    padding: 0.12rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.8rem;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chips a:hover { border-color: var(--accent); color: var(--accent); }

.step-details { margin-top: 0.3rem; }
.step-details summary { cursor: pointer; color: var(--muted); font-size: 0.8rem; user-select: none; }
.step-details pre, .block pre {
    margin: 0.3rem 0 0;
    padding: 0.55rem 0.7rem;
    background: var(--surface-2);
    border-radius: 8px;
    max-height: 22rem;
    overflow: auto;
}

/* ---- report ---- */
.report { padding: 1.1rem 1.4rem; }
.report .meta, .run-header .meta { display: flex; flex-wrap: wrap; gap: 0.4rem 1.25rem; color: var(--muted); font-size: 0.85rem; margin-bottom: 0.75rem; }
.report .meta strong, .run-header .meta strong { color: var(--text); font-weight: 600; }
.live-report { border-style: dashed; }
.markdown > :first-child { margin-top: 0; }
.markdown table { border-collapse: collapse; width: 100%; margin: 0.5rem 0 1rem; font-size: 0.92rem; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 0.45rem 0.6rem; text-align: left; vertical-align: top; }
.markdown th { background: var(--surface-2); }
.markdown h1 { font-size: 1.3rem; }
.markdown h2 { font-size: 1.05rem; margin-top: 1.25rem; }
.markdown pre { background: var(--surface-2); padding: 0.6rem 0.8rem; border-radius: 8px; overflow-x: auto; }

.health-banner { background: var(--error-bg); color: var(--error-text); border-bottom: 1px solid var(--error-text); }
.health-item { max-width: 1040px; margin: 0 auto; padding: 0.55rem 1rem; display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: baseline; font-weight: 500; }
.health-item.health-unavailable { color: var(--warn-text); }
.health-banner:has(.health-unavailable):not(:has(.health-authfailed, .health-quotaexceeded)) { background: var(--warn-bg); border-color: var(--warn-text); }
.health-item a { color: inherit; font-weight: 700; }
.health-msg { font-weight: 400; opacity: 0.9; overflow-wrap: anywhere; }
.health-when { font-weight: 400; opacity: 0.8; font-size: 0.85rem; }
.badge.health-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; text-transform: none; }
.badge.health-authfailed, .badge.health-quotaexceeded { background: var(--error-bg); color: var(--error-text); border-color: transparent; text-transform: none; }
.badge.health-unavailable { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; text-transform: none; }
.sources-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.sources-table th, .sources-table td { text-align: left; padding: 0.55rem 1rem; border-top: 1px solid var(--border); vertical-align: top; }
.sources-table thead th { border-top: none; background: var(--surface-2); color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; }

.question-banner { background: var(--accent); color: var(--accent-text); }
.question-banner a { display: block; max-width: 1040px; margin: 0 auto; padding: 0.5rem 1rem; color: inherit; text-decoration: none; font-weight: 600; }
.question-banner a:hover { text-decoration: underline; }
.question-banner .dot { background: var(--accent-text); margin-right: 0.4rem; }

/* ---- run page / question ---- */
.now { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.75rem; padding: 0.55rem 0.8rem; background: var(--accent-soft); border-radius: 8px; }
.now .badge { text-transform: uppercase; }
.now-title { overflow-wrap: anywhere; font-weight: 500; }
button.link { background: none; border: none; padding: 0; color: var(--accent); font: inherit; font-size: inherit; font-weight: 500; cursor: pointer; }
button.link:hover { text-decoration: underline; }
.run-actions { display: flex; align-items: center; gap: 0.6rem; }
.button-link { display: inline-block; padding: 0.45rem 0.9rem; border: 1px solid var(--border); border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 600; font-size: 0.9rem; }
.button-link:hover { border-color: var(--accent); color: var(--accent); }
.question { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.question-text { font-size: 1.05rem; font-weight: 600; margin: 0 0 0.75rem; }
.options { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.75rem; }
.options .chip { font-size: 0.95rem; padding: 0.45rem 0.9rem; }
.search-form .search { margin-bottom: 0.5rem; }
.context-wrap summary { cursor: pointer; color: var(--muted); font-size: 0.85rem; user-select: none; }
.context-wrap textarea { margin-top: 0.5rem; }
.timeline-wrap > summary { list-style: none; cursor: pointer; }
.timeline-wrap > summary::-webkit-details-marker { display: none; }
.as-summary { display: flex; }
.timeline-wrap:not([open]) > .as-summary { border-bottom: none; }
.step-question .step-title { font-weight: 600; color: var(--accent); }
.badge-question { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.badge-answer { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* ---- dossier ---- */
.dossier-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1.5rem; flex-wrap: wrap; }
.dossier-kicker { display: flex; gap: 0.4rem; margin-bottom: 0.4rem; }
.dossier-name { font-size: 1.7rem; margin: 0; }
.badge.type { background: var(--accent-soft); color: var(--accent); border-color: transparent; text-transform: none; }
.badge.conf-high { background: var(--ok-soft); color: var(--ok); border-color: transparent; text-transform: none; }
.badge.conf-medium { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; text-transform: none; }
.badge.conf-low { background: var(--error-bg); color: var(--error-text); border-color: transparent; text-transform: none; }
.figures { display: flex; gap: 1.25rem; margin: 0; }
.figures div { text-align: center; }
.figures dt { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.figures dd { margin: 0; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.dossier-summary { font-size: 1.02rem; margin: 0.9rem 0 0; max-width: 72ch; }
.dossier-section { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border); }
.dossier-section h2 { margin-bottom: 0.6rem; }
.dossier-section.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.facts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem 1.5rem; }
.fact-group h3 { margin: 0 0 0.3rem; }
.fact-group dl { margin: 0; }
.fact { display: grid; grid-template-columns: 9rem 1fr; gap: 0.5rem; padding: 0.35rem 0; border-top: 1px dashed var(--border); }
.fact:first-child { border-top: none; }
.fact dt { color: var(--muted); font-size: 0.85rem; padding-top: 0.1rem; }
.fact dd { margin: 0; min-width: 0; }
.fact-value { font-weight: 600; overflow-wrap: anywhere; }
.fact.conf-low .fact-value { font-weight: 500; color: var(--muted); }
.fact-meta { display: inline-flex; flex-wrap: wrap; gap: 0.4rem; margin-left: 0.3rem; color: var(--muted); font-size: 0.78rem; }
.ref { color: var(--accent); text-decoration: none; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: 0.35rem 0; border-top: 1px dashed var(--border); }
ul.plain li:first-child { border-top: none; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; font-weight: 400; }
.map { height: 320px; margin-top: 1rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface-2); }
.chrono { list-style: none; margin: 0; padding: 0; }
.chrono li { display: grid; grid-template-columns: 6.5rem 1fr; gap: 0.6rem; padding: 0.3rem 0; border-top: 1px dashed var(--border); }
.chrono li:first-child { border-top: none; }
.chrono time { color: var(--muted); font-variant-numeric: tabular-nums; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; }
.gallery figure { margin: 0; }
.gallery img { width: 100%; height: 120px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.gallery figcaption { font-size: 0.78rem; color: var(--muted); margin-top: 0.25rem; }
.sources { margin: 0; padding-left: 1.4rem; }
.sources li { padding: 0.3rem 0; }
.sources .src-url { color: var(--muted); font-size: 0.8rem; margin-left: 0.4rem; }
.narrative summary { cursor: pointer; font-weight: 650; }
.narrative article { margin-top: 0.75rem; }

/* ---- journal ---- */
.crumbs { color: var(--muted); font-size: 0.85rem; margin-bottom: 0.5rem; display: flex; gap: 0.4rem; }
.runs { list-style: none; margin: 0; padding: 0; }
.run-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.1rem;
    border-top: 1px solid var(--border);
    color: inherit;
    text-decoration: none;
}
.runs li:first-child .run-row { border-top: none; }
.run-row:hover { background: var(--surface-2); }
.run-main { min-width: 0; flex: 1; }
.run-query { font-weight: 600; overflow-wrap: anywhere; }
.run-meta { display: flex; flex-wrap: wrap; gap: 0.3rem 1rem; color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.run-header { padding: 1.1rem 1.4rem; }
.run-header-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 0.4rem; }
.run-header h1 { margin: 0; }

.feedback-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.feedback-list li { padding: 0.6rem 0.8rem; background: var(--surface-2); border-radius: 8px; margin-bottom: 0.4rem; }
.feedback-list time { display: block; color: var(--muted); font-size: 0.78rem; }
.feedback-list p { margin: 0.15rem 0 0; white-space: pre-wrap; }

.rounds { padding: 0.5rem 1.1rem 1rem; }
.round { border: 1px solid var(--border); border-radius: 10px; margin-top: 0.6rem; }
.round > summary { display: flex; align-items: center; gap: 0.75rem; padding: 0.6rem 0.9rem; cursor: pointer; font-weight: 600; user-select: none; }
.round > summary .stats { margin-left: auto; font-weight: 400; }
.round[open] > summary { border-bottom: 1px solid var(--border); }
.round h3 { padding: 0 0.9rem; }
.blocks { list-style: none; margin: 0; padding: 0.5rem 0.9rem; }
.block { display: grid; grid-template-columns: 9.5rem 1fr; gap: 0.6rem; padding: 0.4rem 0; border-top: 1px dashed var(--border); align-items: start; }
.block:first-child { border-top: none; }
.block .badge { width: 100%; text-align: center; }
.block-body { min-width: 0; overflow-wrap: anywhere; }
.block-error .badge { background: var(--error-bg); color: var(--error-text); }
pre.muted { color: var(--muted); }

/* ---- settings ---- */
.settings { padding: 0; }
.settings .status { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin: 0.5rem 0 1rem; }
.settings .actions { margin-top: 0.75rem; flex-wrap: wrap; }
.secret-title { font-size: 1.05rem; margin: 0 0 0.25rem; }

.legal { margin-top: 2.5rem; color: var(--muted); font-size: 0.8rem; }

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

@media (max-width: 720px) {
    .dossier-section.two-col { grid-template-columns: 1fr; }
    .fact { grid-template-columns: 1fr; gap: 0.1rem; }
}

@media (max-width: 640px) {
    .topbar-inner { gap: 1rem; }
    .nav a { padding: 0.4rem 0.5rem; }
    .step { grid-template-columns: 1fr; gap: 0.15rem; }
    .step .badge, .block .badge { width: auto; }
    .block { grid-template-columns: 1fr; }
    .panel-head { flex-direction: column; align-items: flex-start; }
    .search { flex-direction: column; }
}
