:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --text: #1c1c1a;
  --muted: #6a6963;
  --line: #e1dfd7;
  --accent: #0f6e66;
  --accent-hover: #0b5a53;
  --accent-ink: #ffffff;
  --accent-soft: #e2f0ee;
  --danger: #b42318;
  --ok-bg: #e5f3e8;
  --ok-ink: #1d6a34;
  --warn-bg: #fdf3dc;
  --warn-ink: #7a5a0c;
  --s1: #c8452a;
  --s2: #e0892b;
  --s3: #c9b33a;
  --s4: #6aa56c;
  --s5: #2f8a4c;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --surface: #1f1f1c;
    --surface-2: #2a2a26;
    --text: #ecebe6;
    --muted: #a09f97;
    --line: #34332e;
    --accent: #3fb3a6;
    --accent-hover: #5cc4b8;
    --accent-ink: #0b1f1d;
    --accent-soft: #1b3330;
    --danger: #f07a6b;
    --ok-bg: #1c3323;
    --ok-ink: #8fd3a3;
    --warn-bg: #3a2f12;
    --warn-ink: #f0d48a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; font-weight: 650; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; margin-top: 1.4em; }
p { margin: 0 0 0.9em; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.error { color: var(--danger); margin: 0.6em 0 0; }
.empty { color: var(--muted); padding: 1.5em 0; text-align: center; }
[hidden] { display: none !important; }

kbd {
  font: 600 0.72rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  padding: 0.2em 0.4em;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
}

/* ---------- layout */

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0.75rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { display: flex; align-items: center; gap: 0.55rem; font-weight: 700; color: var(--text); text-decoration: none; }
.logo {
  width: 22px; height: 22px; border-radius: 6px; background: var(--accent);
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3a8 8 0 0 0-8 8v5a3 3 0 0 0 3 3h1v-7H6v-1a6 6 0 0 1 12 0v1h-2v7h1a3 3 0 0 0 3-3v-5a8 8 0 0 0-8-8Z'/%3E%3C/svg%3E") center / 20px no-repeat;
}
.who { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.3rem 0.8rem; font-size: 0.9rem; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 1.5rem 1rem 6rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.4rem;
  margin-bottom: 1rem;
}
.narrow { max-width: 420px; margin: 3rem auto; }

.row { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.two > .card { margin-bottom: 0; }
.two + .card, .tiles + .card { margin-top: 1rem; }

.page-head {
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end;
  gap: 1rem; margin-bottom: 1rem;
}
.page-head h1 { margin-bottom: 0.2em; }
.page-head p { margin: 0; }
.back { display: inline-block; font-size: 0.88rem; text-decoration: none; margin-bottom: 0.4rem; }

/* ---------- controls */

button, .button {
  font: inherit; font-weight: 550;
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  padding: 0.55em 1.05em;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button:focus-visible, .button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.link { border: 0; background: none; padding: 0; color: var(--accent); font-weight: 500; }

label { display: block; font-weight: 550; font-size: 0.9rem; margin: 1rem 0 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 0.35rem;
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 0.55em 0.7em;
}
textarea { resize: vertical; }
.row select { width: auto; flex: 1 1 260px; margin: 0; }

.login h1 { margin-bottom: 0.3em; }
.login button { width: 100%; margin-top: 1.2rem; }

.badge {
  display: inline-block; font-size: 0.75rem; font-weight: 600; white-space: nowrap;
  padding: 0.15em 0.6em; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 0.8rem 1rem; border-radius: 10px; margin-bottom: 1rem;
}
.banner.success { background: var(--ok-bg); color: var(--ok-ink); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- home */

.hero { padding: 1.6rem 1.6rem 1.4rem; }
.hero p { max-width: 62ch; }
.hero > p.small:last-child { margin: 0.9rem 0 0; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.75rem; font-weight: 650; color: var(--accent); margin-bottom: 0.4em; }

.progress-line { display: flex; flex-wrap: wrap; align-items: center; gap: 0.8rem; margin: 0.6rem 0; }
.progress-track { flex: 0 1 280px; height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* ---------- tables */

.table-wrap { overflow-x: auto; margin: 0 -0.4rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th {
  text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; padding: 0.5rem 0.4rem; border-bottom: 1px solid var(--line);
}
td { padding: 0.65rem 0.4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.clickable a { font-weight: 600; text-decoration: none; }
.note-cell, .summary { white-space: pre-wrap; }
.note-cell { min-width: 16rem; }
.summary-cell { color: var(--muted); max-width: 32rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.avg { display: flex; align-items: center; gap: 0.6rem; min-width: 9rem; }
.avg .bar-track { flex: 1; }

/* ---------- review */

.review-grid { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 1rem; align-items: start; }
.review-grid > .card { margin-bottom: 0; }

.progress-box { text-align: right; font-size: 0.92rem; }
.dots { display: flex; gap: 5px; justify-content: flex-end; margin-bottom: 0.35rem; }
.dot { width: 14px; height: 14px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--line); }
.dot.on { background: var(--accent); border-color: var(--accent); }

.call-time { font-size: 1.35rem; margin-bottom: 0.2em; }
.call-time::first-letter { text-transform: uppercase; }
.meta { word-break: break-all; }

.player { background: var(--surface-2); border-radius: 10px; padding: 0.9rem; margin: 1rem 0 0.4rem; }
.player audio { width: 100%; display: block; }
.player-tools { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; align-items: center; }
.spacer { flex: 1; }
.chip { padding: 0.3em 0.7em; font-size: 0.85rem; border-radius: 999px; font-variant-numeric: tabular-nums; }
.chip.selected { background: var(--text); color: var(--surface); border-color: var(--text); }

.outcomes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; }
.choice { justify-content: space-between; text-align: left; padding: 0.75em 0.9em; }
.choice-main { grid-column: 1 / -1; font-size: 1.02rem; }
.choice.selected { background: var(--accent-soft); border-color: var(--accent); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }

.scores { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0.5rem; }
.score { flex-direction: column; gap: 0.1rem; padding: 0.7em 0.3em; }
.score strong { font-size: 1.35rem; line-height: 1.1; }
.score span { font-size: 0.78rem; font-weight: 500; color: var(--muted); }
.score.selected { color: #fff; }
.score.selected span { color: rgb(255 255 255 / 0.9); }
.score-1.selected { background: var(--s1); border-color: var(--s1); }
.score-2.selected { background: var(--s2); border-color: var(--s2); }
.score-3.selected { background: var(--s3); border-color: var(--s3); }
.score-4.selected { background: var(--s4); border-color: var(--s4); }
.score-5.selected { background: var(--s5); border-color: var(--s5); }

.note { margin-top: 1.4rem; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-top: 1.2rem; }
.actions .keys { flex: 1 1 280px; margin: 0; }
.actions .primary { padding: 0.7em 1.4em; }

.history h2 { display: flex; justify-content: space-between; }
.history ol { list-style: none; margin: 0; padding: 0; max-height: 70vh; overflow-y: auto; }
.history li a {
  display: flex; justify-content: space-between; gap: 0.5rem; align-items: center;
  padding: 0.5rem 0.55rem; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 0.86rem;
}
.history li a:hover { background: var(--surface-2); }
.history li a.current { background: var(--accent-soft); }
.h-time { color: var(--muted); white-space: nowrap; }
.h-out { text-align: right; display: flex; align-items: center; gap: 0.35rem; }

.score-pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.6em; height: 1.6em; padding: 0 0.35em; border-radius: 6px;
  font-weight: 700; font-size: 0.82rem; color: #fff;
}
.score-pill.score-1 { background: var(--s1); }
.score-pill.score-2 { background: var(--s2); }
.score-pill.score-3 { background: var(--s3); }
.score-pill.score-4 { background: var(--s4); }
.score-pill.score-5 { background: var(--s5); }

/* ---------- overview */

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.tile-label { display: block; font-size: 0.8rem; color: var(--muted); font-weight: 550; }
.tile-value { display: block; font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 0.15rem; }
.tile-value small { font-size: 0.9rem; font-weight: 500; color: var(--muted); }

.bar-row { display: grid; grid-template-columns: 11rem 1fr 2.5rem; gap: 0.7rem; align-items: center; padding: 0.3rem 0; font-size: 0.9rem; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--muted); }
.bar-fill.accent { background: var(--accent); }
.bar-fill.score-bg-1 { background: var(--s1); }
.bar-fill.score-bg-2 { background: var(--s2); }
.bar-fill.score-bg-3 { background: var(--s3); }
.bar-fill.score-bg-4 { background: var(--s4); }
.bar-fill.score-bg-5 { background: var(--s5); }
.bar-count { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary h2 { display: inline; }
details summary::before { content: '▸ '; color: var(--muted); }
details[open] summary::before { content: '▾ '; }
details[open] summary { margin-bottom: 0.6rem; }

.play { width: 2.1rem; height: 2.1rem; padding: 0; border-radius: 50%; font-size: 0.8rem; }

.player-bar {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
  width: min(720px, calc(100% - 2rem));
  display: flex; align-items: center; gap: 0.8rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.15); padding: 0.6rem 0.9rem;
}
.player-bar audio { flex: 1; min-width: 0; }

/* ---------- responsive */

@media (max-width: 900px) {
  .review-grid { grid-template-columns: 1fr; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
  .progress-box { text-align: left; }
  .dots { justify-content: flex-start; }
}

@media (max-width: 560px) {
  .outcomes { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .scores { grid-template-columns: repeat(5, minmax(3rem, 1fr)); gap: 0.3rem; }
  .score span { display: none; }
  .bar-row { grid-template-columns: 7.5rem 1fr 2rem; }
  .card { padding: 1rem; }
  .player-bar { flex-wrap: wrap; }
}
