:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --border: #e2e5ec;
  --text: #161a23;
  --muted: #5d6576;
  --faint: #8b93a3;
  --accent: #2f4bd8;
  --accent-soft: #e8ecfd;
  --accent-text: #ffffff;
  --danger: #c3362b;
  --danger-soft: #fdecea;
  --ok: #1d7f4e;
  --ok-soft: #e3f5ec;
  --warn: #9a6200;
  --warn-soft: #fff3d9;
  --agent: #2f4bd8;
  --agent-soft: #e8ecfd;
  --customer: #b4478a;
  --customer-soft: #fbe9f3;
  --other: #0f7c80;
  --other-soft: #e0f4f4;
  --mark: #ffe28a;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaf0;
    --muted: #a1a8b8;
    --faint: #6f7788;
    --accent: #6f86ff;
    --accent-soft: #232b4d;
    --accent-text: #0b0d12;
    --danger: #ff7b70;
    --danger-soft: #3a1f1d;
    --ok: #53c98d;
    --ok-soft: #173327;
    --warn: #f0b74a;
    --warn-soft: #3a2e14;
    --agent: #8196ff;
    --agent-soft: #232b4d;
    --customer: #e98cc3;
    --customer-soft: #3a2031;
    --other: #5fd0d4;
    --other-soft: #173536;
    --mark: #6b5a17;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 620; }
h3 { font-size: 13px; font-weight: 620; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.stack { display: grid; gap: 12px; }
.hidden { display: none !important; }

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 0 24px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 680; font-size: 15px; text-decoration: none; color: var(--text); }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 2px; }
.nav a {
  padding: 6px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 520;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.banner {
  padding: 8px 24px; background: var(--warn-soft); color: var(--warn); font-size: 13px; border-bottom: 1px solid var(--border);
}

main { max-width: 1320px; margin: 0 auto; padding: 24px; }

/* ── Controls ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 540; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.icon { width: 30px; height: 30px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
.btn.icon:hover { background: var(--surface-2); color: var(--text); }
.btn.icon.on { color: var(--accent); }
.btn.icon svg { width: 16px; height: 16px; }

input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  min-width: 0;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus, [contenteditable]:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: grid; gap: 4px; font-size: 12.5px; font-weight: 560; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { color: var(--text); font-weight: 400; font-size: 14px; }
label.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; line-height: 1.45; }
label.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex: none; }
input[type=range] { accent-color: var(--accent); width: 100%; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 10px; }
.card-body { padding: 0 16px 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px;
  font-size: 12px; font-weight: 560; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.spin { width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Login ───────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { width: min(380px, 100%); padding: 28px; display: grid; gap: 16px; }
.login .brand { font-size: 18px; }
.error-text { color: var(--danger); font-size: 13px; }

/* ── Calls list ──────────────────────────────────────────── */
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 28px; display: grid; gap: 12px; justify-items: center; text-align: center; margin-bottom: 24px;
  transition: border-color .15s, background .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-size: 15px; font-weight: 600; }
.dropzone .row { width: min(560px, 100%); }
.dropzone input[type=text] { flex: 1; }
.progress { width: min(560px, 100%); height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.steps-explainer { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.steps-explainer .card { padding: 14px 16px; }
.steps-explainer .n { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; margin-bottom: 8px; }
.steps-explainer p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }

table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; font-weight: 600; color: var(--faint); padding: 10px 16px; border-bottom: 1px solid var(--border); }
table.list td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr.link { cursor: pointer; }
table.list tbody tr.link:hover { background: var(--surface-2); }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* ── Project ─────────────────────────────────────────────── */
.project-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.project-head .name {
  font-size: 22px; font-weight: 650; border: 1px solid transparent; background: transparent; height: 38px; padding: 0 8px; margin-left: -8px;
  min-width: 200px; flex: 0 1 520px;
}
.project-head .name:hover { border-color: var(--border); }
.stepper { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.stepper .step { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; font-weight: 560; color: var(--muted); }
.stepper .step .n { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-size: 11px; font-weight: 700; }
.stepper .step.done { color: var(--ok); }
.stepper .step.done .n { background: var(--ok-soft); }
.stepper .step.current { color: var(--accent); border-color: var(--accent); }
.stepper .step.current .n { background: var(--accent); color: var(--accent-text); }

.player-bar {
  position: sticky; top: 56px; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.player-bar .scrub { flex: 1; }
.player-bar .time { min-width: 96px; text-align: right; }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.sidebar { display: grid; gap: 16px; position: sticky; top: 124px; max-height: calc(100vh - 140px); overflow: auto; padding-bottom: 8px; }

.toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar input { width: 160px; }

.transcript { padding: 6px 0; }
.line {
  display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 10px; align-items: start;
  padding: 8px 12px; border-left: 3px solid transparent;
}
.line:hover { background: var(--surface-2); }
.line.playing { background: var(--accent-soft); }
.line.removed .text { text-decoration: line-through; color: var(--faint); }
.line.removed { opacity: .7; }
.line.edited { border-left-color: var(--warn); }
.line .who { display: grid; gap: 2px; }
.line .who select {
  height: 24px; padding: 0 6px; border-radius: 6px; font-size: 12px; font-weight: 620; border: 0; width: 100%;
}
.line .who .t { font-size: 11.5px; color: var(--faint); padding-left: 6px; font-variant-numeric: tabular-nums; }
.role-agent { background: var(--agent-soft); color: var(--agent); }
.role-customer { background: var(--customer-soft); color: var(--customer); }
.role-other { background: var(--other-soft); color: var(--other); }
.line .text { padding: 2px 6px; border-radius: 6px; min-height: 24px; white-space: pre-wrap; word-break: break-word; line-height: 1.55; }
.line .text:hover { background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }
.line .text mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }
.line .orig { font-size: 12px; color: var(--faint); padding: 2px 6px 0; }
.line .orig s { text-decoration-color: var(--faint); }
.line .actions { display: flex; gap: 0; opacity: .35; transition: opacity .12s; }
.line:hover .actions, .line:focus-within .actions { opacity: 1; }

.speaker-card { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.speaker-card .row input { flex: 1; }
.speaker-card select { width: 100%; }
.speaker-chip { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px; font-weight: 640; }

.finding { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.finding:last-child { border-bottom: 0; }
.finding .row input { flex: 1; height: 30px; }

.render-item { display: grid; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.render-item:last-child { border-bottom: 0; }
.render-item audio { width: 100%; height: 36px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.option { display: grid; gap: 6px; }
.option .hint { font-size: 12px; color: var(--faint); }

/* ── Voices ──────────────────────────────────────────────── */
.voice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.voice { padding: 16px; display: grid; gap: 12px; }
.voice .consent { font-size: 12.5px; background: var(--surface-2); border-radius: 8px; padding: 8px 10px; color: var(--muted); }
.voice .sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.voice .sliders label { display: grid; gap: 2px; font-size: 12px; color: var(--muted); }
.voice .test { display: flex; gap: 8px; }
.voice .test input { flex: 1; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgb(10 12 18 / 55%); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 12px; box-shadow: 0 20px 50px rgb(0 0 0 / 30%); padding: 22px; display: grid; gap: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.notice { font-size: 12.5px; padding: 10px 12px; border-radius: 8px; background: var(--accent-soft); color: var(--text); line-height: 1.5; }
.notice.warn { background: var(--warn-soft); }

#toasts { position: fixed; bottom: 16px; right: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); max-width: 380px; }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 1000px) {
  .workspace { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; }
  .steps-explainer { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  main { padding: 16px; }
  .topbar { padding: 0 16px; gap: 10px; }
  .topbar .who-am-i { display: none; }
  .line { grid-template-columns: 1fr; }
  .line .actions { opacity: 1; }
  .steps-explainer { grid-template-columns: 1fr; }
  .voice-grid { grid-template-columns: 1fr; }
  table.list .hide-sm { display: none; }
}
