:root {
  color-scheme: light;
  --bg: #f4f5f3;
  --surface: #fcfcfb;
  --surface-2: #eeefec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6c6b67;
  --border: #dcdcd7;
  --accent: #1c5cab;
  --accent-text: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --grid: #e4e4df;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --warn-bg: #fff4dd;
  --warn-text: #7a4b00;
  --crit-bg: #fdecec;
  --crit-text: #8f2323;
  --info-bg: #e8f0fb;
  --info-text: #184f95;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #9c9b93;
    --border: #34342f;
    --accent: #5598e7;
    --accent-text: #0b0b0b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --grid: #2c2c29;
    --warn-bg: #3a2c12;
    --warn-text: #f5c96a;
    --crit-bg: #3b1a1c;
    --crit-text: #f2a3a4;
    --info-bg: #17263b;
    --info-text: #9ec5f4;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --text: #f0efec; --text-2: #c3c2b7; --muted: #9c9b93;
  --border: #34342f; --accent: #5598e7; --accent-text: #0b0b0b; --series-1: #3987e5; --series-2: #d95926; --grid: #2c2c29;
  --warn-bg: #3a2c12; --warn-text: #f5c96a; --crit-bg: #3b1a1c; --crit-text: #f2a3a4; --info-bg: #17263b; --info-text: #9ec5f4;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); font-weight: 500; }
button.small { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: .55; cursor: wait; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; min-width: 0; }
textarea { width: 100%; min-height: 64px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--crit-text); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 14px; margin: 18px 0 8px; color: var(--text-2); }
.mono { font-family: var(--mono); font-size: 12px; }

.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.login-card { width: min(400px, 100%); display: grid; gap: 8px; padding: 26px; }

.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { font-weight: 700; font-size: 18px; white-space: nowrap; }
.tag { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin-left: 6px; }
.tag-warn { background: var(--warn-bg); color: var(--warn-text); }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; min-width: 0; }
.nav a { padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.nav a.active { background: var(--surface-2); color: var(--text); }
.user { display: flex; gap: 8px; align-items: center; font-size: 13px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: end; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.filters label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.filters select, .filters input { max-width: 170px; }

.view { padding: 16px; max-width: 1400px; margin: 0 auto; }
.banner { margin: 12px 16px 0; padding: 10px 14px; border-radius: 10px; font-size: 14px; display: flex; gap: 8px; align-items: flex-start; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); }
.banner.info { background: var(--info-bg); color: var(--info-text); }
.banner.crit { background: var(--crit-bg); color: var(--crit-text); }
.meta-line { font-size: 13px; color: var(--muted); margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 4px 14px; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.ind { display: grid; gap: 4px; align-content: start; }
.ind .label { font-size: 13px; color: var(--text-2); font-weight: 600; }
.ind .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.ind .value.unknown { font-size: 17px; color: var(--muted); font-weight: 600; }
.ind .sub { font-size: 12px; color: var(--muted); }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-2); background: var(--surface-2); white-space: nowrap; }
.badge.partial { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }
.badge.unknown { background: var(--surface-2); color: var(--muted); }
.badge.small-sample { background: var(--info-bg); color: var(--info-text); border-color: transparent; }
.delta { font-size: 12px; color: var(--text-2); }
details.formula { font-size: 12px; color: var(--text-2); }
details.formula summary { cursor: pointer; color: var(--accent); }
details.formula dl { margin: 6px 0 0; display: grid; gap: 2px; }
details.formula dt { font-weight: 700; }
details.formula dd { margin: 0 0 4px; }

.chart-card h3 { margin-top: 0; }
.bars { display: grid; gap: 6px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.bar-row .bl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.bar-track { height: 14px; position: relative; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-fill.s2 { background: var(--series-2); }
.bar-row .bv { font-variant-numeric: tabular-nums; color: var(--text); min-width: 3ch; text-align: right; }
.bar-row:hover .bar-fill { filter: brightness(1.12); }
.cols { display: flex; align-items: flex-end; gap: 2px; height: 140px; border-bottom: 1px solid var(--grid); position: relative; }
.col { flex: 1; min-width: 2px; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; cursor: default; }
.col span { display: block; background: var(--series-1); border-radius: 4px 4px 0 0; min-height: 0; }
.col.s2 span { background: var(--series-2); }
.col.missing span { background: repeating-linear-gradient(45deg, var(--muted) 0 2px, transparent 2px 5px); min-height: 6px; }
.col:hover span { filter: brightness(1.15); }
.cols-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.chart-foot { font-size: 12px; color: var(--muted); margin-top: 8px; }
details.table-view summary { font-size: 12px; cursor: pointer; color: var(--accent); margin-top: 6px; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 6px; max-width: 260px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-2); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 8px; font-size: 13px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin: 8px 0; }
.toolbar label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }

.status { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 12px; }
.status::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.status.high::before, .status.critical::before { background: var(--critical); }
.status.medium::before, .status.serious::before { background: var(--serious); }
.status.warning::before { background: var(--warning); }
.status.good::before { background: var(--good); }

.alerts { display: grid; gap: 8px; }
.alert { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.alert .ic { grid-row: span 2; font-size: 16px; }
.alert .t { font-weight: 700; }
.alert .e { font-size: 13px; color: var(--text-2); }

.state { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--border); border-radius: 12px; }
.state.err { color: var(--crit-text); border-color: var(--critical); }
.drawer { margin-top: 12px; }
.form-grid { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; }
.form-grid label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.timeline { display: grid; gap: 6px; }
.tl { display: grid; grid-template-columns: 120px 1fr; gap: 10px; font-size: 13px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.tl .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.tl .what b { font-weight: 700; }
.pill { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--text-2); margin-right: 4px; }

@media (max-width: 640px) {
  .nav { order: 3; flex-basis: 100%; }
  .view { padding: 12px; }
  .filters select, .filters input { max-width: 140px; }
  .ind .value { font-size: 22px; }
  .tl { grid-template-columns: 1fr; gap: 2px; }
  .bar-row { grid-template-columns: minmax(70px, 42%) 1fr auto; }
}
/* Internal conversational QA; dynamic content is always textContent. */
.sac-comparison { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.sac-comparison pre, #sac-evidence, #sac-messages p, #sac-feedback-history p { white-space: pre-wrap; overflow-wrap: anywhere; }
#sac-profile { width: 100%; min-height: 12rem; font-family: monospace; }
#sac-current textarea { width: 100%; min-height: 5rem; }
@media (max-width: 720px) { .sac-comparison { grid-template-columns: 1fr; } }
/* Daily-use SAC workspace: cases, conversation, response review. */
.sac-qa { margin: 0; background: #11151b; color: #e6edf4; }
.sac-qa h1, .sac-qa h2, .sac-qa h3 { margin: 0 0 .6rem; }
.sac-header, .sac-account { padding: .8rem 1.2rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; border-bottom: 1px solid #2c3541; }
.sac-header h1 { font-size: 1.25rem; }.sac-header p { margin: .2rem 0; color: #9dacbd; font-size: .85rem; }
.sac-layout { display: grid; grid-template-columns: 260px minmax(360px, 1fr) 310px; min-height: calc(100vh - 150px); }
.sac-list, .sac-comments { padding: 1rem; background: #161c25; overflow-wrap: anywhere; }
.sac-list { border-right: 1px solid #2c3541; }.sac-comments { border-left: 1px solid #2c3541; }
.sac-qa label { display: block; margin: .6rem 0; }.sac-qa input:not([type=checkbox]), .sac-qa select, .sac-qa textarea { max-width: 100%; width: 100%; box-sizing: border-box; }
.sac-heading, .sac-toolbar, .sac-send-row, .sac-date-range, .sac-review-actions, .sac-pagination { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.sac-heading h2 { font-size: 1.1rem; }.sac-heading h3 { font-size: .95rem; }.sac-qa button { cursor: pointer; border-radius: .5rem; }.sac-qa button:disabled { opacity: .5; cursor: default; }
#sac-cases { display: grid; gap: .5rem; margin: 1rem 0; }#sac-cases button { padding: .7rem; text-align: left; background: #202b39; color: #dbe7f4; border: 1px solid #344457; font-size: .83rem; }
.sac-chat { padding: 0; min-width: 0; }#sac-empty { padding: 3rem; color: #a9b7c8; }.sac-chat-heading { padding: 1rem 1.4rem; border-bottom: 1px solid #2c3541; }.sac-chat-heading h2 { font-size: 1.15rem; }.sac-chat-heading p { font-size: .8rem; color: #a9b7c8; }
#sac-messages { display: flex; flex-direction: column; gap: 1rem; padding: 1.5rem; height: min(53vh, 650px); overflow-y: auto; }
.sac-bubble { max-width: 92%; padding: .8rem 1rem; border-radius: .8rem; background: #202b39; white-space: pre-wrap; overflow-wrap: anywhere; }.sac-bubble.client { align-self: flex-end; background: #193a38; }.sac-bubble.reply { align-self: flex-start; }.sac-bubble p { margin: .2rem 0 .6rem; }.sac-bubble small { color: #afbed0; }.sac-bubble button { font-size: .78rem; }
#sac-turn { padding: 1rem 1.4rem; border-top: 1px solid #2c3541; }#sac-turn textarea { min-height: 85px; resize: vertical; }.sac-send-row span { color: #9dacbd; font-size: .75rem; }
.sac-comments h2 { font-size: 1rem; }.sac-comments form { border-top: 1px solid #344050; margin-top: 1rem; padding-top: 1rem; }.sac-comments textarea { min-height: 65px; }.sac-comments p { font-size: .83rem; }.sac-comments pre { white-space: pre-wrap; max-height: 260px; overflow: auto; font-size: .75rem; }
.sac-qa dialog { color: #e6edf4; background: #18202b; border: 1px solid #435066; border-radius: 1rem; padding: 1.5rem; width: min(680px, calc(100vw - 40px)); max-height: 85vh; overflow: auto; }.sac-qa dialog::backdrop { background: #000a; }
.sac-order-editor { border: 1px solid #3b485b; padding: .8rem; margin: .8rem 0; border-radius: .6rem; }.sac-product-editor { display: flex; gap: .5rem; align-items: center; }.sac-product-editor input[type=number] { width: 75px; }
.sac-compare { padding: 1rem 1.4rem; }.sac-comparison { grid-template-columns: 1fr 1fr; font-size: .8rem; }.sac-comparison section { min-width: 0; border: 1px solid #344050; padding: .6rem; }.sac-comparison pre { max-height: 180px; overflow: auto; }
#sac-status { padding: .6rem 1.2rem; color: #adcfec; }.sac-qa summary { cursor: pointer; padding: .6rem 0; }
@media(max-width:1100px) { .sac-layout { grid-template-columns: 220px minmax(300px,1fr); }.sac-comments { grid-column: 1 / -1; border-top: 1px solid #2c3541; } }
@media(max-width:700px) { .sac-layout { display: block; }.sac-list { border-bottom: 1px solid #2c3541; }.sac-toolbar { flex-wrap: wrap; }.sac-comparison { grid-template-columns: 1fr; } }
.sac-date-range label { flex: 1; min-width: 0; }.sac-date-range input { min-width: 0; font-size: .8rem; }
#sac-cases button { white-space: pre-line; width: 100%; }
