/* Всё оформление — здесь. Встроенных стилей нет: CSP их запрещает (style-src 'self'). */

:root {
  --bg: #f4f5f4;
  --surface: #ffffff;
  --surface-2: #f0f2f1;
  --border: #dfe3e1;
  --border-strong: #c7cdca;
  --text: #17201e;
  --text-2: #56625e;
  --text-3: #87928e;
  --accent: #0f6e6a;
  --accent-hover: #0b5a57;
  --accent-soft: #e2f1ef;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fdf1d8;
  --mark: #ffe58a;

  /* Два голоса разговора. Цвета держатся одни и те же в метках, на шкале и в расшифровке. */
  --remote: #2f5fb3;
  --remote-soft: #e6eefb;
  --local: #1d7a4a;
  --local-soft: #e3f3ea;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(20, 30, 28, .06), 0 2px 8px rgba(20, 30, 28, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111615;
    --surface: #182020;
    --surface-2: #1f2828;
    --border: #2a3534;
    --border-strong: #3a4746;
    --text: #e6ecea;
    --text-2: #a4b0ad;
    --text-3: #75827f;
    --accent: #3fb3aa;
    --accent-hover: #5cc6be;
    --accent-soft: #173432;
    --danger: #f08a80;
    --danger-soft: #3a1f1c;
    --warn: #e8b44c;
    --warn-soft: #3a2e14;
    --mark: #6b5510;
    --remote: #7aa5f0;
    --remote-soft: #1c2940;
    --local: #62c793;
    --local-soft: #173127;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
code, pre { font-family: var(--mono); font-size: 12.5px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------ кнопки и поля */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 16px; height: 16px; fill: currentColor; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06201e; } }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-icon { width: 34px; padding: 0; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12.5px; color: var(--text-2); }

input[type="text"], input[type="search"], input[type="password"], input[type="date"], input:not([type]), select {
  height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface);
  min-width: 0;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.form-error { margin: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger); font-size: 13px; }

/* ------------------------------------------------------------------ вход */

.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; gap: 14px;
  padding: 28px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.login-sub { margin: -8px 0 6px; color: var(--text-2); }

/* ------------------------------------------------------------------ каркас */

.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 26px; height: 26px; padding: 5px; border-radius: 7px; background: var(--accent); fill: #fff; }
.brand-lg { font-size: 20px; }
.brand-lg .brand-mark { width: 32px; height: 32px; padding: 6px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a { padding: 6px 10px; border-radius: var(--radius-sm); color: var(--text-2); }
.topnav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.topnav a.active { color: var(--text); background: var(--surface-2); font-weight: 550; }
.whoami { display: flex; align-items: center; gap: 8px; }
.whoami-name { color: var(--text-2); font-size: 13px; }

.view { max-width: 1080px; margin: 0 auto; padding: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 9px 16px; border-radius: 8px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 13px;
}

.muted { color: var(--text-2); }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
.empty { padding: 48px 20px; text-align: center; color: var(--text-2); }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ------------------------------------------------------------------ список звонков */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.search { position: relative; flex: 1 1 280px; }
.search input { width: 100%; padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 9px; width: 16px; height: 16px; fill: var(--text-3); pointer-events: none; }

.segmented { display: inline-flex; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); }
.segmented button { height: 28px; padding: 0 12px; border: 0; border-radius: 4px; background: transparent; color: var(--text-2); cursor: pointer; }
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 550; }
.segmented button:disabled { opacity: .4; cursor: default; }
.segmented button:disabled:hover { color: var(--text-2); }

.dates { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); }
.dates input { width: 142px; }

.summary { display: flex; flex-wrap: wrap; gap: 6px 10px; justify-content: space-between; align-items: center; margin: 0 2px 8px; font-size: 13px; color: var(--text-2); }
.summary-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.calls { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.call-row {
  display: grid;
  /* minmax(0, …) обязателен: иначе длинная строка расшифровки в nowrap раздвинет страницу вбок */
  grid-template-columns: 34px minmax(140px, 200px) 48px 52px minmax(0, 1fr);
  align-items: center; gap: 14px;
  padding: 11px 16px; border-top: 1px solid var(--border);
  color: var(--text);
}
.call-row:first-child { border-top: 0; }
.call-row:hover { background: var(--surface-2); text-decoration: none; }

.dir { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; }
.dir svg { width: 16px; height: 16px; fill: currentColor; }
.dir-in { background: var(--remote-soft); color: var(--remote); }
.dir-out { background: var(--local-soft); color: var(--local); }
.dir-missed { background: var(--danger-soft); color: var(--danger); }

.num { font-weight: 600; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num small { display: block; font-weight: 400; font-size: 12px; color: var(--text-3); }
.when { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.dur { color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; }
.preview { min-width: 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview .who { font-weight: 550; margin-right: 4px; }
.preview .who.remote { color: var(--remote); }
.preview .who.local { color: var(--local); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.day-sep { padding: 7px 16px; background: var(--surface-2); border-top: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .03em; }
.day-sep:first-child { border-top: 0; }

.pager { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 16px; color: var(--text-2); }

@media (max-width: 760px) {
  .topbar { gap: 12px; padding: 0 12px; }
  .whoami-name { display: none; }
  .view { padding: 12px; }
  .dates { width: 100%; }
  .dates input { flex: 1; width: auto; }
  .call-row { grid-template-columns: 34px minmax(0, 1fr) auto; row-gap: 2px; padding: 10px 12px; }
  .call-row .dir { grid-row: span 2; }
  .call-row .when { grid-column: 3; grid-row: 1; font-size: 12px; }
  .call-row .dur { grid-column: 3; grid-row: 2; font-size: 12px; }
  .call-row .num { grid-column: 2; grid-row: 1; }
  .call-row .preview { grid-column: 2; grid-row: 2; font-size: 13px; }
}

/* ------------------------------------------------------------------ карточка звонка */

.back { display: inline-flex; align-items: center; gap: 4px; margin-bottom: 12px; color: var(--text-2); }
.back svg { width: 16px; height: 16px; fill: currentColor; }

.call-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  padding: 18px 20px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0;
}
.call-head .dir { width: 40px; height: 40px; }
.call-head .dir svg { width: 20px; height: 20px; }
.call-title { flex: 1; min-width: 200px; }
.call-title h1 { margin: 0; font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.call-meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--text-2); font-size: 13px; }
.call-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* плеер */
.player {
  position: sticky; top: 56px; z-index: 5;
  padding: 14px 20px 16px; background: var(--surface);
  border: 1px solid var(--border); border-top: 0; border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}
.player-row { display: flex; align-items: center; gap: 12px; }
.play {
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: 50%; background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center;
}
@media (prefers-color-scheme: dark) { .play { color: #06201e; } }
.play:hover { background: var(--accent-hover); }
.play:disabled { opacity: .5; cursor: default; }
.play svg { width: 20px; height: 20px; fill: currentColor; }
.time { font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 13px; min-width: 92px; }

.timeline { position: relative; flex: 1; height: 34px; cursor: pointer; touch-action: none; }
.lane { position: absolute; left: 0; right: 0; height: 7px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.lane-remote { top: 6px; }
.lane-local { top: 21px; }
.seg { position: absolute; top: 0; bottom: 0; border-radius: 3px; }
.lane-remote .seg { background: var(--remote); opacity: .45; }
.lane-local .seg { background: var(--local); opacity: .45; }
.seg.active { opacity: 1; }
.progress { position: absolute; top: 0; bottom: 0; left: 0; width: 0; border-right: 2px solid var(--text); pointer-events: none; }
.progress::after { content: ""; position: absolute; right: -6px; top: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--text); }
.hover-time { position: absolute; top: -22px; padding: 1px 6px; border-radius: 4px; background: var(--text); color: var(--bg); font-size: 11px; transform: translateX(-50%); pointer-events: none; white-space: nowrap; }

.player-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.player-tools .spacer { flex: 1; }
.legend { display: inline-flex; gap: 12px; font-size: 12.5px; color: var(--text-2); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend .l-remote::before { background: var(--remote); }
.legend .l-local::before { background: var(--local); }
.player-note { font-size: 12.5px; color: var(--text-3); }
.player-note:empty { display: none; }

/* ------------------------------------------------------------------ сообщения */

.msgs { display: flex; flex-direction: column; gap: 8px; }
.msg {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.msg-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.msg-from { font-weight: 600; overflow-wrap: anywhere; }
.msg-time { color: var(--text-3); font-size: 12.5px; margin-left: auto; white-space: nowrap; }
.msg-text { color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }

/* расшифровка */
.transcript-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 10px; margin: 22px 2px 6px; }
.transcript-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.transcript-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.follow { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); cursor: pointer; }

/* с какими параметрами получен текст */
.transcript-info { display: flex; flex-wrap: wrap; margin: 0 2px 12px; font-size: 12.5px; color: var(--text-3); }
.transcript-info span + span::before { content: "·"; margin: 0 7px; }

.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-2); margin-bottom: 12px; }
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-job { display: flex; align-items: flex-start; gap: 10px; background: var(--accent-soft); color: var(--accent); }
.notice-job small { display: block; margin-top: 2px; font-size: 12.5px; color: var(--text-2); }
.spinner {
  flex: none; width: 14px; height: 14px; margin-top: 3px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* окно выбора языка */
.dlg {
  width: min(460px, calc(100vw - 32px)); padding: 20px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.dlg::backdrop { background: rgba(10, 16, 15, .45); }
.dlg h3 { margin: 0 0 6px; font-size: 16px; }
.dlg p { margin: 0 0 14px; color: var(--text-2); }
.choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.choice {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer;
}
.choice:hover { background: var(--surface-2); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin: 3px 0 0; accent-color: var(--accent); }
.choice strong { display: block; font-weight: 600; }
.choice small { display: block; color: var(--text-2); font-size: 12.5px; }
.dlg-error { color: var(--danger); font-size: 13px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; }

.transcript { display: flex; flex-direction: column; gap: 6px; }
.line {
  display: grid; grid-template-columns: 58px 1fr; gap: 10px;
  max-width: 82%; padding: 8px 12px; border-radius: 12px;
  border: 1px solid transparent; cursor: pointer;
  scroll-margin-top: 220px; scroll-margin-bottom: 40px;
}
.line.remote { align-self: flex-start; background: var(--remote-soft); border-top-left-radius: 4px; }
.line.local { align-self: flex-end; background: var(--local-soft); border-top-right-radius: 4px; }
.line:hover { border-color: var(--border-strong); }
.line.active { border-color: currentColor; box-shadow: 0 0 0 1px currentColor; }
.line.remote.active { color: var(--remote); }
.line.local.active { color: var(--local); }
.line-ts { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--text-3); padding-top: 1px; }
.line-body { color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.line-who { display: block; font-size: 12px; font-weight: 600; }
.line.remote .line-who { color: var(--remote); }
.line.local .line-who { color: var(--local); }

@media (max-width: 760px) {
  .call-head { padding: 14px; }
  .player { padding: 12px 14px 14px; }
  .player-row { flex-wrap: wrap; row-gap: 8px; }
  .timeline { order: 10; flex-basis: 100%; }
  .time { min-width: 0; margin-left: auto; }
  .player-note { flex-basis: 100%; }
  .legend { display: none; }
  .line { max-width: 94%; grid-template-columns: 1fr; gap: 0; }
  /* точка в начале перенесённой строки выглядит опечаткой — на узком экране по параметру в строке */
  .transcript-info { flex-direction: column; gap: 1px; }
  .transcript-info span + span::before { content: none; }
  .line-ts { order: 2; }
}

/* ------------------------------------------------------------------ API */

.doc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 26px; }
.doc h1 { margin: 0 0 6px; font-size: 20px; }
.doc h2 { margin: 26px 0 8px; font-size: 15px; }
.doc p { margin: 6px 0; color: var(--text-2); max-width: 760px; }
.doc pre { margin: 8px 0; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow-x: auto; }
.doc code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.doc pre code { background: none; padding: 0; }
.endpoints { width: 100%; border-collapse: collapse; margin: 8px 0; }
.endpoints-wrap { overflow-x: auto; }
.endpoints td { padding: 8px 10px; border-top: 1px solid var(--border); vertical-align: top; }
.endpoints tr:first-child td { border-top: 0; }
.endpoints td:first-child { white-space: nowrap; }
@media (max-width: 760px) {
  .doc { padding: 16px; }
  .endpoints td { display: block; border-top: 0; padding: 2px 0; }
  .endpoints tr { display: block; padding: 8px 0; border-top: 1px solid var(--border); }
  .endpoints tr:first-child { border-top: 0; }
}
.method { display: inline-block; min-width: 42px; font-family: var(--mono); font-size: 11.5px; font-weight: 700; color: var(--accent); }
