:root {
  --bg: #07111c;
  --panel: #0e1c2b;
  --panel-2: #071421;
  --line: #1e3a52;
  --text: #e8f1f8;
  --muted: #8aa0b5;
  --accent: #3dd6c6;
  --accent-2: #41e0cf;
  --warn: #f59e0b;
  --danger: #ef4444;
  --ok: #34d399;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #12324a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

header.topbar {
  border-bottom: 1px solid var(--line);
  background: rgba(7, 17, 28, .82);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
}
/* Меню занимает середину, учётная запись прижимается вправо. */
.topbar-inner nav.main { margin-right: auto; }

.brand { font-weight: 800; letter-spacing: .04em; font-size: 17px; color: var(--text); }
.brand span { color: var(--accent); }

nav.main { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
nav.main a {
  padding: 8px 13px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}
nav.main a:hover { background: #12283c; color: var(--text); text-decoration: none; }
nav.main a.active { background: #123a3a; color: var(--accent); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 28px 20px 72px; }

h1 { margin: 0 0 6px; font-size: 27px; letter-spacing: .02em; }
h2 { margin: 0 0 14px; font-size: 19px; }
h3 { margin: 18px 0 10px; font-size: 15px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
/* Ширину подзаголовка не ограничиваем: колонка страницы и так 1240 px, а
   жёсткая мера в 78ch рвала на две строки текст, которому хватало одной. */
.sub { color: var(--muted); margin: 0 0 20px; line-height: 1.55; }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  margin-bottom: 20px;
}
.card.tight { padding: 16px 18px; }

.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }

/* --------------------------------------------------------------- обзор */

.wrap.wide { max-width: 1600px; }

/* Полоса ключевых чисел под заголовком. */
.kpi {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
}
.kpi-item span { display: block; font-size: 12px; color: var(--muted); letter-spacing: .04em; text-transform: uppercase; }
.kpi-item b { display: block; font-size: 26px; margin-top: 6px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-item small { display: block; font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi-item.accent b { color: var(--accent); }

/* Кладка колонками: карточки сохраняют свою высоту и подтягиваются вплотную
   друг к другу. В grid ряд равен самой высокой карточке, и под короткими
   оставались пустые провалы — здесь их нет. */
/* Сетка, а не кладка колонками: у карточек одного ряда должна совпадать
   высота, а `columns` растит каждую по своему содержимому. Строки тянутся
   по самой высокой карточке ряда. */
.board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}
.board > .card {
  margin: 0;
  /* Колонка внутри карточки: содержимое остаётся сверху, а сама карточка
     занимает всю высоту ряда. */
  display: flex;
  flex-direction: column;
}
.board > .card > :last-child { margin-bottom: 0; }

/* Широкая карточка живёт вне сетки — на всю ширину. */
.board-wide { margin-bottom: 16px; }

@media (max-width: 1200px) { .board { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px)  { .board { grid-template-columns: minmax(0, 1fr); } }

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

/* Учётная запись и выход — в правой части шапки. */
.session { display: flex; align-items: center; gap: 10px; margin: 0; }
.session .who { font-size: 12.5px; color: var(--muted); white-space: nowrap; }

/* ------------------------------------------------------------- страница входа */

/* Карточка по центру экрана, без шапки: на странице входа вести из меню
   всё равно некуда, а пустая полоса сверху ломает композицию. */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
}
.auth-shell .messages { width: 100%; max-width: 420px; }

.auth-card {
  width: 100%;
  max-width: 420px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(20, 44, 66, .92), rgba(14, 28, 43, .96));
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}

.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.auth-logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  color: #062a28;
  background: linear-gradient(180deg, var(--accent-2), #1fb8aa);
  flex: 0 0 auto;
}
.auth-logo svg { width: 24px; height: 24px; }
.auth-title { font-size: 18px; font-weight: 700; letter-spacing: .02em; }
.auth-title span { color: var(--accent); }
.auth-caption { font-size: 12px; color: var(--muted); margin-top: 2px; }

.auth-heading { font-size: 21px; margin: 0 0 20px; }
.auth-msg { margin-bottom: 18px; }

.auth-card .field { margin-bottom: 16px; }
.auth-card input[type=text],
.auth-card input[type=password] { padding: 12px 14px; font-size: 15px; }
.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61, 214, 198, .18);
}

.auth-submit { width: 100%; padding: 13px 20px; font-size: 15px; margin-top: 4px; }

/* Автозаполнение браузера подменяет фон на белый и рвёт тёмную тему.
   Перекрыть его можно только внутренней тенью — background оно игнорирует. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-box-shadow: 0 0 0 1000px var(--panel-2) inset;
  -webkit-text-fill-color: var(--text);
  caret-color: var(--text);
  transition: background-color 5000s ease-in-out 0s;
}

button.ghost.danger, .btn.ghost.danger { color: #fca5a5; border-color: #7f1d1d; background: transparent; }
.card-head a { font-size: 13px; font-weight: 600; }

/* ------------------------------------------------------------- формы */

/* Ровная сетка полей: подписи на одной линии, поля одной ширины —
   в отличие от flex-строк, где высокий элемент перекашивает весь ряд. */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px 16px;
  align-items: start;
}
.form-grid .field { min-width: 0; }
.form-grid .field.wide { grid-column: span 2; }

/* Фиксированные четыре колонки: поля укладываются в ровные ряды без
   пустого хвоста, который оставляет auto-fit при нечётном количестве. */
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1000px) {
  .form-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .form-grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
  .form-grid .field.wide { grid-column: span 1; }
}

/* Подвал формы: пояснение слева, действие справа, на одной линии. */
.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
/* Пояснение занимает остаток строки и сжимается само: без flex-basis оно
   распирает ряд по своей длине и сталкивает кнопку на вторую строку. */
.form-actions .spacer {
  flex: 1 1 260px;
  min-width: 0;
  margin-right: auto;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* Подвал с полями: подпись, компактные поля и кнопка садятся на одну линию.
   По центру их равнять нельзя — у поля сверху ещё подпись, и кнопка уезжает. */
.form-actions.with-fields { align-items: flex-end; }

/* Флажок с подписью в одну строку: иначе он висит отдельно от своего текста
   и ломает ровный ряд полей. */
.switch { display: flex; align-items: center; gap: 8px; margin: 0; padding: 10px 0; }
.switch input[type=checkbox] { width: auto; margin: 0; flex: 0 0 auto; }
.switch span { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.form-actions .field.compact { flex: 0 0 auto; width: 165px; min-width: 0; }
.form-actions .field.compact label { white-space: nowrap; }

@media (max-width: 700px) {
  .form-actions.with-fields { align-items: stretch; }
  .form-actions .field.compact { flex: 1 1 140px; width: auto; }
  .form-actions.with-fields button { width: 100%; }
}

/* Компактные чекбоксы вместо длинного столбца — не растягивают ряд. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color .15s, background .15s;
}
.chips label:hover { border-color: #2c5a7a; }
.chips label:has(input:checked) { border-color: var(--accent); background: #0d2b2c; }
.chips input { margin: 0; }
.chips .count { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Разделитель внутри карточки между двумя формами. */
.form-block + .form-block { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.form-block h3 { margin-top: 0; margin-bottom: 12px; }

form { display: grid; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 14px; align-items: end; }

/* Ряд, который обязан уместиться в одну строку вместе с кнопкой: поля
   сжимаются по мере надобности вместо того, чтобы сталкивать кнопку вниз.
   Пропорции задаются классами — иначе длинный select забирает всю ширину. */
.row.single-line { flex-wrap: nowrap; }
.row.single-line .field { min-width: 0; flex: 1 1 0; }
.row.single-line .field.grow { flex: 2 1 0; }
.row.single-line .field.tight { flex: 0 1 130px; }
.row.single-line button { flex: 0 0 auto; }

@media (max-width: 900px) {
  .row.single-line { flex-wrap: wrap; }
  .row.single-line .field { flex: 1 1 180px; }
  .row.single-line .field.tight { flex: 1 1 130px; }
}
.field { display: flex; flex-direction: column; min-width: 170px; flex: 1 1 auto; }
label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }

/* Пароль и почта — такие же поля: без них браузер рисует свой белый фон,
   и на тёмной теме поле выпадает из оформления. */
input[type=file], input[type=text], input[type=password], input[type=email],
input[type=number], select, textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid #1d6f6a; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }

button, .btn {
  background: linear-gradient(180deg, var(--accent-2), #1fb8aa);
  border: 0;
  color: #042226;
  font-weight: 700;
  font-size: 14px;
  padding: 11px 20px;
  border-radius: 10px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-block;
}
button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
button.ghost, .btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
}
button.danger, .btn.danger { background: linear-gradient(180deg, #f87171, #dc2626); color: #fff; }
button.small, .btn.small { padding: 7px 13px; font-size: 13px; }
button:disabled { opacity: .4; cursor: not-allowed; filter: none; }

.messages { display: grid; gap: 10px; margin-bottom: 20px; }
.msg { padding: 12px 15px; border-radius: 10px; font-size: 14px; border: 1px solid; }
.msg.error { color: #fecaca; background: #3b1218; border-color: #7f1d1d; }
.msg.success { color: #bbf7d0; background: #0d2f22; border-color: #166534; }
.msg.info, .msg.warning { color: #fde68a; background: #35270a; border-color: #854d0e; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 14px; }
figure { margin: 0; }
figure img { width: 100%; border-radius: 12px; border: 1px solid var(--line); display: block; background: #000; }
figcaption { font-size: 13px; color: var(--muted); margin-top: 8px; }
img.wide { width: 100%; border-radius: 12px; border: 1px solid var(--line); background: #fff; }

/* ---------------------------------------------------------- галерея результатов */

/* Крупнее обычной .grid: результаты анализа — то, что смотрят внимательно,
   а не служебный список, поэтому карточки заметно больше. */
.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}
.gallery figure {
  cursor: zoom-in;
  transition: transform .15s ease;
}
.gallery figure:hover { transform: translateY(-2px); }
.gallery figure img {
  aspect-ratio: 4 / 3;
  object-fit: contain;
  background: #000;
}
.gallery figure figcaption { display: flex; align-items: center; gap: 6px; }
.gallery figure figcaption::after {
  content: "⤢";
  margin-left: auto;
  opacity: .5;
  font-size: 12px;
}

/* Лайтбокс: увеличенный просмотр по клику, с переключением между картинками. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(4, 10, 17, .94);
  backdrop-filter: blur(4px);
  padding: 32px 16px;
}
.lightbox.on { display: flex; }
.lightbox img {
  max-width: min(1400px, 92vw);
  max-height: 72vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.lightbox-caption { color: var(--text); font-size: 14.5px; text-align: center; max-width: 70ch; }
.lightbox-counter { color: var(--muted); font-size: 12.5px; }
.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-nav:disabled { opacity: .25; cursor: default; }
.lightbox-nav.prev { left: 18px; }
.lightbox-nav.next { right: 18px; }
@media (max-width: 640px) {
  .lightbox-nav { width: 38px; height: 38px; }
  .lightbox-nav.prev { left: 6px; }
  .lightbox-nav.next { right: 6px; }
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 10px; }
.stat {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 12.5px;
  color: var(--muted);
}
.stat b { display: block; font-size: 19px; color: var(--text); margin-top: 4px; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.ok { background: #134e4a; color: #99f6e4; }
.badge.no { background: #3f2a0a; color: #fde68a; }
.badge.err { background: #45161c; color: #fecaca; }
.badge.run { background: #16324e; color: #93c5fd; }
.badge.idle { background: #1f2937; color: #cbd5e1; }

/* Широкая таблица прокручивается внутри своей карточки, а не тянет за собой
   всю страницу: горизонтальный скролл body ломает вёрстку на узких экранах. */
.card { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th, table td { min-width: 0; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Дата и время не должны разрываться посередине. */
td.mono { white-space: nowrap; }
td.mono a { white-space: normal; }

/* Протокол анализа: тот же моноширинный блок, что и логи, но выше и светлее —
   его читают целиком, а не проглядывают хвост. */
.log.report {
  max-height: none;
  color: var(--text);
  font-size: 13px;
  line-height: 1.65;
  user-select: text;
}

.log {
  background: #040d16;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  font-family: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  color: #b9d4e6;
  white-space: pre-wrap;
  max-height: 420px;
  overflow: auto;
}

.progress { height: 10px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: linear-gradient(90deg, #1fb8aa, var(--accent-2)); transition: width .4s; }

.legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 0; padding: 0; }
.legend span { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.note { font-size: 12.5px; color: var(--muted); margin-top: 14px; line-height: 1.5; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--muted); word-break: break-all; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.pairs { max-height: 260px; overflow: auto; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.inline-form { display: inline; }

/* ---------------------------------------------------------- индикатор загрузки */

.loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 22px;
  background: rgba(7, 17, 28, .82);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity .25s ease;
}
.loader.on { display: flex; opacity: 1; }

/* Пульсирующее сердце: задача про эхокардиографию, и ритм тут уместнее спиннера. */
.loader-heart {
  width: 62px;
  height: 62px;
  color: var(--accent);
  animation: heartbeat 1.15s ease-in-out infinite;
  filter: drop-shadow(0 0 14px rgba(61, 214, 198, .45));
}
.loader-heart svg { width: 100%; height: 100%; display: block; }

@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  14%      { transform: scale(1.16); }
  28%      { transform: scale(1); }
  42%      { transform: scale(1.1); }
  60%      { transform: scale(1); }
}

/* Линия ЭКГ под сердцем — та же метафора, что и в кадре аппарата. */
.loader-ecg { width: 240px; height: 42px; overflow: hidden; }
.loader-ecg path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 320;
  animation: trace 1.6s linear infinite;
}
@keyframes trace {
  from { stroke-dashoffset: 320; }
  to   { stroke-dashoffset: -320; }
}

.loader-text { color: var(--text); font-size: 15px; font-weight: 600; letter-spacing: .01em; }
.loader-hint { color: var(--muted); font-size: 13px; margin-top: -14px; max-width: 46ch; text-align: center; line-height: 1.5; }

@media (prefers-reduced-motion: reduce) {
  .loader-heart, .loader-ecg path { animation-duration: 3s; }
}

/* Кнопка, ожидающая ответа сервера */
button.busy { opacity: .65; cursor: progress; }
