:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #677085; --line: #e2e5eb;
  --accent: #2f5bd3; --accent-ink: #ffffff; --hover: #eef2fb;
  --good: #1f8a4c; --good-bg: #e6f4ec; --bad: #c3352b; --bad-bg: #fbe9e7; --imp: #b7791f; --imp-bg: #fdf3e1;
  --active: #fff7d1; --mgr: #2f5bd3; --cli: #6b4fbb;
  --radius: 8px; --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 16px rgba(20,30,50,.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --panel: #1a1e26; --text: #e6e9ef; --muted: #9aa3b5; --line: #2b313d;
    --accent: #6d8ff0; --accent-ink: #0d1220; --hover: #232a38;
    --good: #5cc98a; --good-bg: #173326; --bad: #ef7a70; --bad-bg: #3a1c1a; --imp: #e5b35a; --imp-bg: #3a2d14;
    --active: #3a3517; --mgr: #8aa6f5; --cli: #b7a3f0; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --panel: #1a1e26; --text: #e6e9ef; --muted: #9aa3b5; --line: #2b313d;
  --accent: #6d8ff0; --accent-ink: #0d1220; --hover: #232a38;
  --good: #5cc98a; --good-bg: #173326; --bad: #ef7a70; --bad-bg: #3a1c1a; --imp: #e5b35a; --imp-bg: #3a2d14;
  --active: #3a3517; --mgr: #8aa6f5; --cli: #b7a3f0; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.05); }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
textarea { width: 100%; resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 650; color: var(--text); }
.top nav { display: flex; gap: 4px; }
.top nav a { padding: 4px 10px; border-radius: 6px; color: var(--muted); }
.top nav a.on { color: var(--text); background: var(--hover); text-decoration: none; }
main { max-width: 1400px; margin: 0 auto; padding: 16px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.login { max-width: 360px; margin: 10vh auto; padding: 24px; display: grid; gap: 12px; }
.login h1 { margin: 0 0 4px; font-size: 20px; }
.login label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login input { width: 100%; padding: 9px 10px; }
.err { color: var(--bad); min-height: 1.2em; font-size: 13px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; padding: 12px; margin-bottom: 12px; }
.filters label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.filters input[type=number] { width: 90px; }
.stats { display: flex; gap: 16px; margin: 0 0 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.stats b { color: var(--text); }
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--hover); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.b-S { background: var(--good-bg); color: var(--good); border-color: transparent; }
.b-F { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.b-P { background: var(--imp-bg); color: var(--imp); border-color: transparent; }
.b-done { background: var(--good-bg); color: var(--good); border-color: transparent; }
.b-skip { color: var(--muted); }

.callhead { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; padding: 12px 14px; margin-bottom: 12px; }
.callhead .meta { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.seg-ctl { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg-ctl button { border: 0; border-radius: 0; border-right: 1px solid var(--line); }
.seg-ctl button:last-child { border-right: 0; }
.seg-ctl button.on { background: var(--accent); color: var(--accent-ink); }
.player { position: sticky; top: 49px; z-index: 10; padding: 8px 12px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.player audio { width: 100%; height: 36px; }
.player .speed { min-width: 56px; }
.player label { white-space: nowrap; }

.callgrid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 12px; align-items: start; }
@media (max-width: 960px) { .callgrid { grid-template-columns: 1fr; } }
.transcript { padding: 6px 0; }
.seg { display: grid; grid-template-columns: 56px 92px 1fr 28px; gap: 8px; padding: 6px 12px; border-left: 3px solid transparent; align-items: start; }
.seg:hover { background: var(--hover); }
.seg.active { background: var(--active); }
.seg.picked { outline: 2px dashed var(--accent); outline-offset: -2px; }
.seg.a-good { border-left-color: var(--good); }
.seg.a-bad { border-left-color: var(--bad); }
.seg.a-improve { border-left-color: var(--imp); }
.seg .t { color: var(--muted); font-variant-numeric: tabular-nums; border: 0; background: none; padding: 0; text-align: left; }
.seg .t:hover { color: var(--accent); background: none; }
.seg .who { font-size: 12px; font-weight: 600; color: var(--muted); padding-top: 1px; }
.seg .who.mgr { color: var(--mgr); }
.seg .who.cli { color: var(--cli); }
.seg .txt { white-space: pre-wrap; word-break: break-word; }
.seg .add { visibility: hidden; border: 0; padding: 0 4px; color: var(--muted); }
.seg:hover .add, .seg .add:focus { visibility: visible; }
@media (hover: none) { .seg .add { visibility: visible; } }
.selbtn { position: absolute; z-index: 30; box-shadow: var(--shadow); }

.side { display: grid; gap: 12px; position: sticky; top: 110px; max-height: calc(100vh - 124px); overflow: auto; }
@media (max-width: 960px) { .side { position: static; max-height: none; } }
.panel { padding: 12px; }
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.form { display: grid; gap: 8px; }
.form .quote { font-style: italic; color: var(--muted); max-height: 90px; overflow: auto; border-left: 3px solid var(--line); padding-left: 8px; }
.verdicts { display: flex; gap: 6px; flex-wrap: wrap; }
.verdicts button.on.v-good { background: var(--good-bg); color: var(--good); border-color: var(--good); }
.verdicts button.on.v-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad); }
.verdicts button.on.v-improve { background: var(--imp-bg); color: var(--imp); border-color: var(--imp); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ann { border: 1px solid var(--line); border-left-width: 4px; border-radius: 6px; padding: 8px 10px; display: grid; gap: 4px; cursor: pointer; }
.ann:hover { background: var(--hover); }
.ann.v-good { border-left-color: var(--good); }
.ann.v-bad { border-left-color: var(--bad); }
.ann.v-improve { border-left-color: var(--imp); }
.ann .q { font-style: italic; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ann .h { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: 12px; }
.ann .h .badge { white-space: normal; }
.ann .better { border-top: 1px dashed var(--line); padding-top: 4px; }
.ann .tools { display: flex; gap: 4px; justify-content: flex-end; }
.ann .tools button { padding: 2px 8px; font-size: 12px; }
.anns { display: grid; gap: 8px; }

.settings { display: grid; gap: 12px; max-width: 900px; }
.settings textarea { min-height: 220px; font-family: ui-monospace, Menlo, monospace; }
.audit td { font-size: 12px; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: .95; }
kbd { border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 12px; }

@media (max-width: 640px) {
  main { padding: 10px; }
  .top { flex-wrap: wrap; gap: 6px 10px; padding: 8px 10px; }
  .top .brand, #who { display: none; }
  .seg { grid-template-columns: 52px 1fr 28px; grid-template-areas: "t who add" "txt txt txt"; row-gap: 2px; }
  .seg .t { grid-area: t; } .seg .who { grid-area: who; } .seg .txt { grid-area: txt; } .seg .add { grid-area: add; }
  .callhead { padding: 10px; }
  .filters label { flex: 1 1 140px; }
  .filters select, .filters input { width: 100%; }
  .player { top: 0; position: static; }
}
