/* Журнал звонков. Цвет говорит, кто говорил: «я» — бирюза, собеседник — слива,
   голос не опознан — серый. Всё остальное нейтрально. */

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

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #1d2733;
  --muted: #5b6675;
  --line: #d9dfe6;
  --me: #0e7c72;
  --me-soft: #dcf0ec;
  --other: #7a3e8f;
  --other-soft: #f1e5f5;
  --unknown: #66717f;
  --unknown-soft: #e9edf1;
  --field: #808a97; /* рамка поля ввода: 3:1 к фону (граница элемента, WCAG 1.4.11) */
  --mark: #fbe39a;
  --today: #1d56c9;
  --yesterday: #8a5300;
  --family: #a8285a;
  --family-soft: #fcebf1;
  --danger: #b42318;
  --focus: #2f6feb;
  --radius: 6px;
  --font: "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --surface: #182029;
    --ink: #e4e9ee;
    --muted: #98a4b1;
    --line: #2a3441;
    --me: #45bdae;
    --me-soft: rgba(69, 189, 174, 0.15);
    --other: #c78ddc;
    --other-soft: rgba(199, 141, 220, 0.15);
    --unknown: #8d98a6;
    --field: #64707e;
    --unknown-soft: rgba(141, 152, 166, 0.16);
    --mark: rgba(240, 196, 80, 0.38);
    --today: #7ea6ff;
    --yesterday: #e2b04f;
    --family: #f08fb4;
    --family-soft: rgba(240, 143, 180, 0.12);
    --danger: #f97066;
    --focus: #6b9bff;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  /* фокус с клавиатуры и переходы к якорям не уходят под липкие шапку и плеер */
  scroll-padding-top: calc(var(--top-h, 0px) + var(--player-h, 0px) + 12px);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.55 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; text-wrap: balance; }
h1, .who, .line .text, .hit .main, .summary-panel { overflow-wrap: anywhere; }
a, button, input, select, label { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }
a { color: inherit; text-decoration-color: var(--line); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
mark { background: var(--mark); color: inherit; border-radius: 2px; padding: 0 1px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.skip {
  position: absolute; left: 16px; top: -48px; z-index: 20;
  padding: 8px 12px; border-radius: var(--radius);
  background: var(--ink); color: var(--surface);
}
.skip:focus { top: 8px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
[hidden] { display: none !important; }

/* --- шапка ------------------------------------------------------------------------- */

.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px max(16px, calc((100vw - 1120px) / 2));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; white-space: nowrap; }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 10px; border-radius: var(--radius);
  text-decoration: none; color: var(--muted);
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--bg); font-weight: 600; }
.quick-search { flex: 1; max-width: 340px; margin-left: auto; }
.logout { color: var(--muted); }

main {
  max-width: 1120px; margin: 0 auto;
  padding: 28px 16px 64px;
}
main:focus { outline: none; }

/* --- элементы управления ----------------------------------------------------------- */

input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="search"], input[type="password"], input[type="date"],
input[type="number"], select, textarea {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--field);
  border-radius: var(--radius);
}
input:not([type="checkbox"]), select { height: 40px; }
textarea { resize: vertical; min-height: 96px; }
.button, button.button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--field); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.button:hover { border-color: var(--muted); }
.button.primary { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.button.primary:hover { opacity: 0.9; }
.button:disabled { opacity: 0.5; cursor: default; }
.link-button {
  border: 0; background: none; padding: 0; cursor: pointer;
  text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: 3px;
}
.link-button:hover { text-decoration-color: currentColor; color: var(--ink); }
.field { display: grid; gap: 4px; }
.field > span { font-size: 0.875rem; color: var(--muted); }
.check { display: flex; gap: 10px; align-items: flex-start; }
.check input { margin-top: 5px; width: 18px; height: 18px; accent-color: var(--me); }

.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: end;
  margin: 20px 0 8px;
}
.filters .field { min-width: 140px; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: baseline; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.empty { padding: 48px 0; color: var(--muted); }
.empty p + * { margin-top: 12px; }
.loading { color: var(--muted); padding: 24px 0; }
.error { color: var(--danger); }
.more { margin-top: 20px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 20px; }
.pager span { font-variant-numeric: tabular-nums; }

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

.calls { list-style: none; margin: 0; padding: 0; }
.day + .day { margin-top: 12px; }
/* Заголовок дня прилипает под шапкой: в длинном дне видно, какой это день */
.day-head {
  position: sticky; top: var(--top-h, 0px); z-index: 2;
  padding: 14px 0 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
  color: var(--muted);
}
/* Давность дня: сегодня ярче, вчера спокойнее, дальше приглушено; точка дублирует цвет формой */
.day-head::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px;
  border-radius: 50%; background: currentColor; vertical-align: 0.1em;
}
.day-head[data-age="today"] { color: var(--today); }
.day-head[data-age="yesterday"] { color: var(--yesterday); }
.day-head[data-age="past"]::before { background: transparent; box-shadow: inset 0 0 0 1.5px currentColor; }
.call-row {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  gap: 4px 20px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.call-row .when { color: var(--muted); font-size: 0.9375rem; }
.call-row .when b { display: block; color: var(--ink); font-weight: 600; }
.call-row .who { font-weight: 600; text-decoration: none; }
.call-row .who:hover { text-decoration: underline; }
/* Семья: тон фона и полоса слева; строка выступает за колонку, чтобы текст остался на месте */
.call-row.family {
  margin-inline: -12px; padding-inline: 12px;
  background: var(--family-soft);
  box-shadow: inset 3px 0 var(--family);
}
.table tr.family td { background: var(--family-soft); }
.table tr.family td:first-child { box-shadow: inset 3px 0 var(--family); padding-left: 10px; }
.family-badge {
  margin-left: 8px; padding: 1px 7px; border-radius: 999px;
  font-size: 0.8125rem; font-weight: 500; color: var(--family);
  box-shadow: inset 0 0 0 1px currentColor; white-space: nowrap;
}
.call-row .summary {
  color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  max-width: 72ch;
}
.call-row .side { text-align: right; color: var(--muted); font-size: 0.9375rem; }
.dir { font-size: 0.875rem; color: var(--muted); margin-left: 8px; font-weight: 400; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 0.8125rem; background: var(--unknown-soft); color: var(--muted);
}
.badge.failed { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { font-size: 0.8125rem; color: var(--muted); }
/* отдельно стоящие ссылки — цель не меньше 24 px (WCAG 2.2, 2.5.8) */
.tags a.tag, .hit .meta a { display: inline-block; padding-block: 2px; }
.result-head h2 a { display: inline-block; padding-block: 3px; }

/* --- страница звонка --------------------------------------------------------------- */

.call-head h1 { margin-bottom: 4px; }
.call-head h1 a, .result-head a { text-decoration: none; }
.call-head h1 a:hover, .result-head a:hover { text-decoration: underline; }
.call-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--muted); }
.call-meta .phone { color: var(--ink); }

/* Плеер с полосой разговора прилипает под шапкой: длинный разговор листается, плеер на месте.
   --top-h и --player-h выставляет JS (высота шапки и плеера). */
.player {
  position: sticky; top: var(--top-h, 0px); z-index: 5;
  margin: 16px 0 0; padding: 12px 0 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.player audio { width: 100%; height: 40px; }
.player .note { margin-top: 8px; }

/* Полоса разговора: две дорожки по всей длительности — кто когда говорил. Клик — перемотка. */
.lanes {
  position: relative;
  height: 46px;
  margin-top: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  cursor: pointer;
  touch-action: manipulation;
}
.lane-bar {
  position: absolute; height: 14px; border-radius: 3px; min-width: 2px;
}
.lane-bar.me { top: 7px; background: var(--me); }
.lane-bar.other { top: 23px; background: var(--other); }
.lane-bar.unknown { top: 15px; background: var(--unknown); }
.lane-bar.hit { box-shadow: 0 0 0 2px var(--mark); }
.playhead {
  position: absolute; top: -4px; bottom: -4px; width: 2px;
  background: var(--ink); border-radius: 1px; pointer-events: none;
  transform: translateX(-1px);
}
.lanes-legend { display: flex; gap: 16px; margin-top: 6px; font-size: 0.8125rem; color: var(--muted); }
.lanes-legend span::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  margin-right: 6px; vertical-align: -1px; background: currentColor;
}
.lanes-legend .me { color: var(--me); }
.lanes-legend .other { color: var(--other); }

.call-body {
  display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 40px;
  margin-top: 20px; align-items: start;
}
.summary-panel {
  position: sticky; top: calc(var(--top-h, 0px) + var(--player-h, 0px) + 16px);
  max-height: calc(100vh - var(--top-h, 0px) - var(--player-h, 0px) - 32px); overflow-y: auto;
  display: grid; gap: 18px; align-content: start;
}
.summary-panel ul { margin: 6px 0 0; padding-left: 18px; }
.summary-panel li + li { margin-top: 4px; }
.summary-panel .version { font-size: 0.8125rem; color: var(--muted); }

.transcript-tools { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.transcript-tools input { max-width: 280px; }
.transcript { list-style: none; margin: 0; padding: 0; max-width: 72ch; }
.line {
  scroll-margin-top: calc(var(--top-h, 0px) + var(--player-h, 0px) + 12px);
  scroll-margin-bottom: 24px;
  display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 2px 12px;
  padding: 8px 10px 8px 0;
  border-left: 3px solid transparent;
  padding-left: 10px;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.line.me { border-left-color: var(--me); }
.line.other { border-left-color: var(--other); }
.line.unknown { border-left-color: var(--unknown); }
.line.active.me { background: var(--me-soft); }
.line.active.other { background: var(--other-soft); }
.line.active.unknown { background: var(--unknown-soft); }
.line.target { outline: 2px solid var(--mark); }
.line .t {
  grid-row: span 2; border: 0; background: none; padding: 0; cursor: pointer;
  min-height: 24px; min-width: 40px; /* WCAG 2.2: цель не меньше 24×24 */
  color: var(--muted); font-size: 0.875rem; text-align: left; align-self: start; padding-top: 2px;
}
.line .t:hover { color: var(--ink); text-decoration: underline; }
.line .speaker { font-size: 0.8125rem; font-weight: 600; }
.line.me .speaker { color: var(--me); }
.line.other .speaker { color: var(--other); }
.line.unknown .speaker { color: var(--unknown); }
.line.dim { opacity: 0.35; }

/* --- поиск ------------------------------------------------------------------------- */

.search-form { display: flex; gap: 10px; margin-top: 16px; }
.search-form input { font-size: 1.125rem; }
.results { list-style: none; margin: 16px 0 0; padding: 0; }
.result { padding: 18px 0; border-bottom: 1px solid var(--line); }
.result-head h2 { font-size: 1rem; }
.result-head { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.hits { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 10px; }
.hit { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: 2px 12px; max-width: 80ch; }
.play {
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--field); background: var(--surface); cursor: pointer;
  display: grid; place-items: center; color: var(--ink);
}
.play svg { width: 14px; height: 14px; fill: currentColor; }
.play.playing { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.hit .ctx { font-size: 0.875rem; color: var(--muted); }
.hit .main { border-left: 3px solid var(--unknown); padding-left: 10px; }
.hit .main.me { border-color: var(--me); }
.hit .main.other { border-color: var(--other); }
.hit .meta { font-size: 0.8125rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 0 12px; }
.summary-hit { margin-top: 10px; max-width: 80ch; }

/* --- контакты, настройки ----------------------------------------------------------- */

.table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.table th, .table td { text-align: left; padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); }
.table th { font-weight: 500; color: var(--muted); font-size: 0.875rem; }
.table td.num { text-align: right; }

.columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 40px; }
.section { margin-top: 32px; }
.section > h2 { margin-bottom: 12px; }
.stack { display: grid; gap: 16px; max-width: 560px; }
.counters { display: flex; flex-wrap: wrap; gap: 28px; margin-top: 8px; }
.counter b { display: block; font-size: 1.5rem; font-weight: 650; }
.counter span { color: var(--muted); font-size: 0.875rem; }

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

.login {
  max-width: 360px; margin: 12vh auto 0;
  display: grid; gap: 16px;
}
.login h1 { font-size: 1.5rem; }
.login .button { justify-content: center; }
.login .lanes-mark { display: grid; gap: 6px; margin-bottom: 8px; }
.login .lanes-mark i { display: block; height: 10px; border-radius: 3px; }
.login .lanes-mark i:nth-child(1) { width: 46%; background: var(--me); }
.login .lanes-mark i:nth-child(2) { width: 62%; margin-left: 30%; background: var(--other); }

/* --- уведомления ------------------------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px);
  max-width: calc(100vw - 32px);
  padding: 10px 16px; border-radius: var(--radius);
  background: var(--ink); color: var(--surface);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }

/* сенсорный экран: цели касания 44 px (рекомендация iOS/Android) */
@media (pointer: coarse) {
  .button, .play { min-height: 44px; }
  .play { width: 44px; height: 44px; }
  .line .t { min-height: 44px; }
  .nav a { padding: 11px 12px; }
  .link-button { padding: 10px 0; }
  .hit { grid-template-columns: 48px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}

/* --- телефон ----------------------------------------------------------------------- */

@media (max-width: 860px) {
  .call-body { grid-template-columns: 1fr; gap: 28px; }
  .summary-panel { position: static; order: -1; }
  .columns { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  /* на телефоне прилипает только плеер: шапка в три строки заняла бы пол-экрана */
  .top { position: static; flex-wrap: wrap; gap: 8px 16px; }
  .brand { order: 1; }
  .logout { order: 2; margin-left: auto; }
  .quick-search { order: 3; flex-basis: 100%; max-width: none; margin-left: 0; }
  .nav { order: 4; width: 100%; overflow-x: auto; }
  main { padding-top: 20px; }
  h1 { font-size: 1.4rem; }
  .call-row { grid-template-columns: minmax(0, 1fr) auto; }
  .call-row .when { grid-column: 1 / -1; }
  .filters .field { min-width: calc(50% - 6px); flex: 1; }
}
