@font-face {
  font-family: "Onest";
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/onest-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Onest";
  font-weight: 100 900;
  font-display: swap;
  src: url("/static/fonts/onest-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --font: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  --radius-sm: 6px;
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #1d1b16;
  --muted: #6b675e;
  --border: #e2ded4;
  --accent: #0f6b5c;
  --on-accent: #ffffff;
  --good: #1f8a5b;
  --warn: #b7791f;
  --bad: #c2412d;
  --neutral: #8a8f98;
  --on-status: #ffffff;
  --shadow: 0 1px 2px rgba(29, 27, 22, 0.06);
}
:root[data-theme="dark"] {
  --bg: #14130f;
  --surface: #1c1b16;
  --surface-2: #26241d;
  --text: #ece9e1;
  --muted: #9a958a;
  --border: #33312a;
  --accent: #3fb8a0;
  --on-accent: #0b1512;
  --good: #4cc38a;
  --warn: #e0b04a;
  --bad: #ef7a67;
  --neutral: #7c8089;
  --on-status: #10100d;
  --shadow: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14130f;
    --surface: #1c1b16;
    --surface-2: #26241d;
    --text: #ece9e1;
    --muted: #9a958a;
    --border: #33312a;
    --accent: #3fb8a0;
    --on-accent: #0b1512;
    --good: #4cc38a;
    --warn: #e0b04a;
    --bad: #ef7a67;
    --neutral: #7c8089;
    --on-status: #10100d;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; font-variant-numeric: tabular-nums; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 0.7rem; }
.card h2:first-child { margin-top: 0; }

/* shell */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.2rem; padding: 1.2rem 1rem; background: var(--surface); border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { padding: 0.5rem 0.7rem; border-radius: var(--radius-sm); color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.theme-toggle { margin-top: auto; }
.main { min-width: 0; }
.page { padding: 1.6rem 2rem 3rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.8rem 1.2rem; margin-bottom: 1.2rem; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; padding: 0.7rem 1rem; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .theme-toggle { margin-top: 0; margin-left: auto; }
  .page { padding: 1rem; }
}

/* surfaces */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.2rem 1.4rem; margin-bottom: 1.2rem; box-shadow: var(--shadow); }
.error { color: var(--bad); }
.muted { color: var(--muted); }

/* forms */
input, select, button { font: inherit; }
input[type="text"], input[type="password"], input[type="datetime-local"], select, input[type="file"] {
  width: 100%; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text);
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { padding: 0.5rem 0.9rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); cursor: pointer; }
button:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.small { padding: 0.25rem 0.6rem; font-size: 0.85rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; }
.field > span { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.field.actions { justify-content: flex-end; }
.upload-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.9rem 1rem; align-items: end; }
.upload-form .wide { grid-column: 1 / -1; }
.inline-form { display: flex; gap: 0.7rem; align-items: end; }
.inline-form.compact { align-items: center; }
form.inline { display: inline; margin: 0; }

/* tables */
table, .table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.55rem 0.7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tr.stage th { background: var(--surface-2); color: var(--text); text-transform: none; letter-spacing: 0; font-size: 0.95rem; }
tr.stage.missed th { background: color-mix(in srgb, var(--bad) 16%, var(--surface)); }

/* status + badges */
.status, .badge { display: inline-block; padding: 0.1rem 0.6rem; border-radius: 999px; font-size: 0.8rem; font-weight: 600; background: var(--neutral); color: var(--on-status); }
.status.done, .badge.good { background: var(--good); }
.status.failed, .badge.bad { background: var(--bad); }
.status.queued { background: var(--neutral); }
.status.preprocessing, .status.transcribing, .status.scoring, .badge.warn { background: var(--warn); }
.badge.neutral { background: var(--neutral); }
.tag { background: var(--surface-2); padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.8rem; margin-right: 0.25rem; display: inline-block; }

/* score */
.scorebox { display: flex; gap: 1.5rem; align-items: center; background: var(--surface); border: 1px solid var(--border); padding: 1rem 1.2rem; border-radius: var(--radius); margin: 1rem 0; }
.score { font-size: 3rem; font-weight: 700; min-width: 5.5rem; text-align: center; border-radius: var(--radius); padding: 0.4rem; color: var(--on-status); background: var(--neutral); }
.score.good { background: var(--good); } .score.warn { background: var(--warn); } .score.bad { background: var(--bad); }
.banner { background: var(--bad); color: var(--on-status); padding: 0.8rem 1rem; border-radius: var(--radius); margin: 1rem 0; font-weight: 600; }
.quote { font-style: italic; }
.reason { color: var(--muted); font-size: 0.9rem; }

/* transcript */
.turns-head { display: flex; gap: 0.8rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.6rem; }
.turns-head form { margin: 0; }
.turn { padding: 0.5rem 0.8rem; margin: 0.35rem 0; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--neutral); max-width: 85%; }
.turn.operator { border-left-color: var(--accent); }
.turn.patient { border-left-color: var(--good); margin-left: auto; }
.turn-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.15rem; }
.rolebtn { border: 0; background: transparent; padding: 0; font-size: 0.8rem; font-weight: 600; color: var(--text); }
.transcript { white-space: pre-wrap; background: var(--surface); padding: 1rem; border-radius: var(--radius); line-height: 1.5; }

/* tables: horizontal scroll on narrow screens, aligned columns across stage tables */
.table-wrap { overflow-x: auto; }
table.checklist { table-layout: fixed; min-width: 640px; }
table.checklist .c-id { width: 3.4rem; }
table.checklist .c-verdict { width: 9.5rem; }
table.checklist .c-evidence { width: 38%; }
input[type="file"]::file-selector-button { margin-right: 0.8rem; padding: 0.35rem 0.8rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }

/* dashboard */
.period { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.period input[type="date"] { width: auto; padding: 0.3rem 0.5rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.segmented a { padding: 0.3rem 0.8rem; color: var(--muted); font-weight: 500; background: var(--surface); }
.segmented a:hover { text-decoration: none; background: var(--surface-2); }
.segmented a.on { background: var(--accent); color: var(--on-accent); }
.crumb { margin: 0 0 0.4rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.kpi { margin: 0; }
.kpi-label { font-size: 0.8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 2.6rem; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; }
.kpi-value small { font-size: 1rem; font-weight: 500; color: var(--muted); }
.delta { font-size: 0.85rem; color: var(--muted); }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); }
.sub { font-size: 0.82rem; color: var(--muted); }
.bad-text { color: var(--bad); }
.stack { display: flex; height: 8px; margin: 0.7rem 0 0.35rem; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.stack i.good { background: var(--good); } .stack i.bad { background: var(--bad); }
.legend { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 0.35rem; flex-wrap: wrap; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--neutral); }
.dot.good { background: var(--good); } .dot.bad { background: var(--bad); } .dot.accent { background: var(--accent); }
.dot.prev { background: transparent; border: 2px dashed var(--muted); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.card-head h2 { margin: 0 0 0.6rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.2rem; }
.grid-2 > .card { margin: 0 0 1.2rem; }
.empty { text-align: center; padding: 2.5rem 1rem; }

.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.prev { stroke: var(--muted); stroke-width: 1.6; stroke-dasharray: 4 3; opacity: 0.75; }
.chart .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 1.5; }

.loss { margin-bottom: 0.9rem; }
.loss-head { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.92rem; }
.loss-head .pts { font-weight: 700; color: var(--bad); white-space: nowrap; }
.bar { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin: 0.25rem 0 0.15rem; }
.bar i { display: block; height: 100%; border-radius: 999px; background: var(--bad); }
.bar i.requirement { background: var(--warn); }
.bar i.ok { background: var(--good); } .bar i.mid { background: var(--warn); } .bar i.low { background: var(--bad); }

.chip { display: inline-block; min-width: 2.2rem; text-align: center; padding: 0.05rem 0.5rem; border-radius: 999px; font-weight: 700; color: var(--on-status); background: var(--neutral); }
.chip.good { background: var(--good); } .chip.warn { background: var(--warn); } .chip.bad { background: var(--bad); }
.stars { --fill: 0%; font-size: 0.95rem; letter-spacing: 1px; background: linear-gradient(90deg, var(--warn) var(--fill), var(--border) var(--fill)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stagebar { display: flex; gap: 2px; width: 100%; min-width: 110px; max-width: 220px; height: 10px; }
.sb-seg { display: block; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.sb-seg i { display: block; height: 100%; background: var(--accent); }
.nowrap { white-space: nowrap; }
td .sub { margin-top: 0.1rem; }
td.summary { max-width: 26rem; color: var(--muted); font-size: 0.9rem; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.danger:hover { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.notice { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); padding: 0.6rem 0.9rem; border-radius: var(--radius-sm); }
.field.grow { flex: 1; }
.actions-row { display: flex; gap: 0.7rem; flex-wrap: wrap; align-items: center; }
.player { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.player audio { flex: 1; min-width: 240px; }
a.ts { font-variant-numeric: tabular-nums; }

/* side panel */
.drawer { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
.drawer.open { pointer-events: auto; }
.drawer-overlay { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.38); opacity: 0; transition: opacity 0.2s ease; }
.drawer.open .drawer-overlay { opacity: 1; }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); border-left: 1px solid var(--border); padding: 1.3rem 1.4rem 2rem; overflow-y: auto; transform: translateX(100%); transition: transform 0.24s ease; }
.drawer.open .drawer-panel { transform: none; }
.drawer-close { position: absolute; top: 0.6rem; right: 0.8rem; border: 0; background: transparent; font-size: 1.6rem; line-height: 1; color: var(--muted); padding: 0.2rem 0.5rem; }
body.no-scroll { overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; margin-right: 1.8rem; }
.panel-head h2 { margin: 0 0 0.2rem; font-size: 1.15rem; word-break: break-all; }
.panel-score { display: flex; gap: 1rem; align-items: center; margin: 1rem 0; }
.panel-score .score { font-size: 2.2rem; min-width: 4rem; padding: 0.2rem; }
.stagewide { margin: 0.4rem 0; } .stagewide .stagebar { max-width: none; }
.drawer audio { width: 100%; margin: 0.4rem 0 0.8rem; }
.drawer h3 { font-size: 0.95rem; margin: 1.1rem 0 0.4rem; }
.drawer details { border-top: 1px solid var(--border); padding: 0.6rem 0; }
.drawer summary { cursor: pointer; font-weight: 600; }
.losses, .mini-items { list-style: none; margin: 0; padding: 0; }
.losses li, .mini-items li { padding: 0.25rem 0; font-size: 0.9rem; }
.losses .pts { color: var(--bad); font-weight: 700; margin-right: 0.3rem; }
.mini-stage { margin-top: 0.7rem; }
.turns.compact .turn { max-width: 100%; margin: 0.3rem 0; }
.panel-danger { margin-top: 1.5rem; }

@media (max-width: 800px) {
  .period { width: 100%; }
  .period input[type="date"] { flex: 1; min-width: 0; }
  .kpi-value { font-size: 2.2rem; }
}

/* manual review */
tr.row.needs-review > td { background: color-mix(in srgb, var(--warn) 11%, var(--surface)); }
tr.row.manual > td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.review-bar { display: flex; gap: 0.6rem 1.4rem; flex-wrap: wrap; align-items: center; margin: 1.2rem 0 0.4rem; }
.filter { cursor: pointer; }
.only-review tr.row:not(.needs-review) { display: none; }
.reviewer-note { margin-top: 0.3rem; padding: 0.35rem 0.6rem; border-left: 3px solid var(--accent); background: var(--surface-2); border-radius: var(--radius-sm); font-size: 0.9rem; }
details.adjust { margin-top: 0.4rem; }
details.adjust summary { cursor: pointer; color: var(--accent); font-size: 0.85rem; font-weight: 600; }
details.adjust form { margin-top: 0.5rem; display: grid; gap: 0.5rem; }
.verdicts { display: flex; gap: 1rem; flex-wrap: wrap; }
.verdicts label { display: inline-flex; align-items: center; gap: 0.3rem; cursor: pointer; }
textarea { width: 100%; padding: 0.5rem 0.65rem; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg); color: var(--text); font: inherit; resize: vertical; }
textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
tr.row { scroll-margin-top: 5rem; }

/* transcript: readable spacing between turns */
.turns { display: flex; flex-direction: column; gap: 1rem; margin-top: 0.8rem; }
.turn { margin: 0; padding: 0.85rem 1.1rem; line-height: 1.65; max-width: min(80%, 56rem); }
.turn-meta { margin-bottom: 0.4rem; font-size: 0.82rem; }
.turns.compact { gap: 0.7rem; }
.turns.compact .turn { padding: 0.6rem 0.8rem; max-width: 100%; }
@media (max-width: 800px) { .turn { max-width: 94%; } }

.badge, .status { white-space: nowrap; }
table.checklist .c-verdict { width: 11.5rem; }
.turns:not(.compact) { max-width: 60rem; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.login { width: 100%; max-width: 380px; margin: 0; padding: 1.8rem 1.8rem 2rem; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 0.6rem; font-weight: 700; }
.login h1 { text-align: center; margin: 0.9rem 0 1.3rem; }
.login .error { text-align: center; margin: 0 0 1rem; }
.login-form { display: grid; gap: 1.1rem; }
.btn.block { width: 100%; padding: 0.7rem 1rem; }
