/* Выходы на воду: мобильная вёрстка первой (одна колонка, поля по 16 px), светлая и тёмная темы по настройке системы. */

:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #17202b;
  --muted: #566274;
  --border: #d5dbe3;
  --accent: #0a62c0;
  --on-accent: #ffffff;
  --danger: #b3261e;
  --alert-bg: #fdecea;
  --warn-bg: #fff2cc;
  --warn-text: #5c4300;
  --wait-bg: #e8f0fb;
  --radius: 12px;
  --gap: 16px;
  /* графики отчёта (report.js читает эти переменные): категории в постоянном порядке, нейтральный серый,
     сетка и оси приглушены, серые полосы — нет фикса GPS или до тары на воде */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-neutral: #8f959c;
  --chart-grid: #e8ebef;
  --chart-axis: #b9c1cb;
  --chart-shade: rgba(110, 120, 132, 0.16);
  --chart-band: rgba(42, 120, 214, 0.12);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151b;
    --surface: #1a212a;
    --text: #e6eaef;
    --muted: #9ba7b6;
    --border: #2d3743;
    --accent: #6aaeff;
    --on-accent: #07121f;
    --danger: #ff8f86;
    --alert-bg: #3a1f1d;
    --warn-bg: #3d3210;
    --warn-text: #f3d98a;
    --wait-bg: #1d2a3b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-neutral: #7d848c;
    --chart-grid: #26303b;
    --chart-axis: #46525f;
    --chart-shade: rgba(150, 160, 172, 0.18);
    --chart-band: rgba(57, 135, 229, 0.18);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow-wrap: anywhere;
}

[hidden] { display: none !important; }

a { color: var(--accent); }

h1 { margin: 0 0 8px; font-size: 1.5rem; line-height: 1.25; }
h2 { margin: 0; font-size: 1.05rem; line-height: 1.3; }

/* шапка и основная колонка */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px var(--gap);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; color: var(--text); text-decoration: none; }
.session { display: flex; align-items: center; gap: 12px; margin: 0; min-width: 0; }
.who { color: var(--muted); min-width: 0; }

main { max-width: 760px; margin: 0 auto; padding: var(--gap); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--gap); }
.narrow { max-width: 420px; margin: 8px auto 0; }

.hint { margin: 0 0 12px; color: var(--muted); }
.form + .hint { margin-top: 16px; }
.small { font-size: 0.875rem; margin: -4px 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

.alert { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; background: var(--alert-bg); color: var(--danger); }

/* формы */
.form label { display: block; margin: 0 0 4px; font-weight: 600; }
.form input {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0 0 12px;
  padding: 8px 12px;
  font: inherit;               /* 16 px: iOS не приближает страницу при фокусе */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* кнопки */
.btn, .link {
  font: inherit;
  cursor: pointer;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
}
.btn.primary { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn:focus-visible, .link:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.form .btn { width: 100%; }
.link { padding: 8px 0; color: var(--accent); background: none; border: 0; }

/* загрузка */
.upload { margin-bottom: var(--gap); }
.upload .btn { width: 100%; }
progress { display: block; width: 100%; height: 12px; margin: 12px 0 4px; accent-color: var(--accent); }

/* карточки выходов */
.cards { display: grid; gap: 12px; }
.card { padding: var(--gap); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-title a { color: var(--text); text-decoration: none; }
.card-title a:hover { text-decoration: underline; }
.when { margin: 2px 0 8px; color: var(--muted); font-size: 0.9375rem; }
.note { margin-left: 6px; padding: 1px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 0.8125rem; }

.status { margin: 0 0 8px; padding: 8px 12px; border-radius: 8px; }
.status-wait { background: var(--wait-bg); }
.status-error { background: var(--alert-bg); color: var(--danger); }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; margin: 0 0 8px; }
.stats div { min-width: 0; }
.stats dt { color: var(--muted); font-size: 0.8125rem; }
.stats dd { margin: 0; font-weight: 600; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); font-size: 0.875rem; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.badge.info { background: var(--wait-bg); color: var(--accent); text-decoration: none; }
a.badge.info:hover { text-decoration: underline; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.actions form { margin: 0; }
.actions .btn { flex: 1 1 auto; }

/* шире телефона */
@media (min-width: 600px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .upload .btn { width: auto; }
  .actions .btn { flex: 0 0 auto; }
}

/* ---- отчёт по выходу (report.html, report.js) ---- */
main.wide { max-width: 1120px; }
.report > * { max-width: 760px; }                 /* текст и таблицы — узкой колонкой, графики шире */
.report > .tab-panel, .report > .tabs { max-width: none; }   /* полоса вкладок закрывает графики под собой во всю ширину */
.tab-panel > :not(.detail) { max-width: 760px; }

.report-head { margin-bottom: 12px; }
.report-head h1 { margin: 0; }
.back { display: inline-block; margin-bottom: 4px; padding: 6px 0; text-decoration: none; }
.report-head .when { margin: 2px 0 0; }

.report-actions { margin: 0 0 12px; }
.share-panel { margin: 0 0 var(--gap); }
.share-panel h2 { margin-bottom: 6px; }
.share-panel form { margin: 0; }
.copy-row { display: flex; gap: 8px; margin: 0 0 12px; min-width: 0; }
.copy-row input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.copy-row .btn { flex: 0 0 auto; }
.copy-msg { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* переключатель источника «Устройство | Текущий алгоритм» (отчёт и раздел администратора): две равные половины */
.segmented {
  display: flex;
  gap: 3px;
  max-width: 440px;
  margin: 0 0 12px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.segmented a {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 44px;
  padding: 4px 10px;
  color: var(--text);
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  border-radius: 9px;
}
.segmented a[aria-current="page"] { color: var(--on-accent); background: var(--accent); }
.segmented a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg-state { display: block; color: var(--muted); font-size: 0.8125rem; font-weight: 400; }
.segmented a[aria-current="page"] .seg-state { color: inherit; }

/* форма запроса разбора текущим алгоритмом */
.replay-panel { margin: 0 0 var(--gap); }
.replay-panel h2 { margin-bottom: 6px; }
.replay-form { margin: 0; }
.replay-form fieldset { min-width: 0; margin: 0 0 12px; padding: 0; border: 0; }
.replay-form legend, .replay-form > label { display: block; margin: 0 0 4px; padding: 0; font-weight: 600; }
.replay-form .radio {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin: 0 0 6px;
  padding: 0 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.replay-form .radio:has(input:checked) { border-color: var(--accent); }
.replay-form .radio input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.replay-form input[type="text"] {
  display: block;
  width: 100%;
  min-height: 44px;
  margin: 0 0 4px;
  padding: 8px 12px;
  font: inherit;               /* 16 px: iOS не приближает страницу при фокусе */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.replay-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.replay-form .btn { width: 100%; }

/* подпись источника отчёта разбора текущим алгоритмом — на каждой вкладке, чтобы его не спутать с устройством */
.source-line { margin: 0 0 12px; padding: 8px 12px; background: var(--wait-bg); border-left: 4px solid var(--accent); border-radius: 8px; font-size: 0.9375rem; }
.source-line p { margin: 0; }
.source-line .note.old { margin-left: 4px; }
.source-line .note.old a { color: inherit; }
.source-line .src-note { margin-top: 4px; font-weight: 600; }

/* вкладки: без скрипта список вкладок скрыт и все разделы идут подряд */
.tabs {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  gap: 4px;
  margin: 0 calc(-1 * var(--gap)) 12px;
  padding: 8px var(--gap);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0 8px;
  font: inherit;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tab-panel { margin-bottom: 24px; }
.tab-panel:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.tabs-on .panel-title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* плитки */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 0 12px; }
.tile { min-width: 0; padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.tile dt { color: var(--muted); font-size: 0.8125rem; }
.tile dd { margin: 0; }
.tile .v { font-size: 1.375rem; font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .v.missing, .metrics .missing { color: var(--muted); font-size: 0.9375rem; font-weight: 400; }
.tile .sub { color: var(--muted); font-size: 0.8125rem; }

/* таблицы показателей: подпись слева, значение справа */
.metrics {
  width: 100%;
  margin: 0 0 12px;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}
.metrics caption { padding: 4px 0 6px; text-align: left; color: var(--muted); font-size: 0.875rem; font-weight: 600; }
/* break-word, а не anywhere (как у body): колонка не уже самого длинного слова, слова не рвутся посередине */
.metrics th, .metrics td { padding: 8px 12px; text-align: left; vertical-align: top; border-top: 1px solid var(--border); overflow-wrap: break-word; }
.metrics tr:first-child th, .metrics tr:first-child td { border-top: 0; }
.metrics th { width: 46%; font-weight: 400; color: var(--muted); }
.metrics td .v { font-weight: 600; }
.metrics .sub { display: block; color: var(--muted); font-size: 0.8125rem; }
.metrics .alert-row .v, .metrics .alert-row .sub { color: var(--danger); }
.missing-note { margin: 0 0 12px; padding: 10px 12px; border: 1px dashed var(--border); border-radius: var(--radius); color: var(--muted); }
.fine { margin: 0 0 12px; color: var(--muted); font-size: 0.8125rem; }

.code-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; min-width: 0; }
.code-row code {
  flex: 1 1 260px;                                /* на телефоне строка целиком, кнопка под ней */
  min-width: 0;
  padding: 10px 12px;
  overflow-x: auto;
  white-space: pre;
  overflow-wrap: normal;
  font: 0.875rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.code-row .btn { flex: 0 0 auto; }

/* «Подробно»: графики одной колонкой, на широком экране — двумя */
.btn.more { width: 100%; margin: 4px 0 12px; }
.detail { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.detail-status { margin: 0; color: var(--muted); }
.viz { margin: 0; min-width: 0; padding: 12px 12px 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.viz figcaption { margin: 0 0 6px; }
.viz-title { display: block; font-weight: 600; }
.viz-cap { display: block; color: var(--muted); font-size: 0.8125rem; }
.chart { width: 100%; height: 280px; }
.chart.tall { height: 400px; }
.chart.map { height: 320px; border-radius: 8px; overflow: hidden; isolation: isolate; }  /* слои Leaflet (z-index до 1000) не лезут поверх вкладок */
.chart.empty { height: auto; padding: 16px 0; color: var(--muted); }
.viz-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 8px 0 0; color: var(--muted); font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.viz-legend .sw { display: inline-block; width: 18px; height: 6px; margin-right: 4px; border-radius: 3px; vertical-align: middle; }
.leaflet-container { font: inherit; }

@media (min-width: 600px) {
  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .btn.more { width: auto; }
  .replay-form fieldset { display: flex; flex-wrap: wrap; gap: 8px; }
  .replay-form .radio { flex: 1 1 0; margin: 0; }
  .replay-form .btn { width: auto; }
  .tabs { margin-left: 0; margin-right: 0; padding-left: 0; padding-right: 0; }
  .tab { flex: 0 0 auto; padding: 0 20px; }
}
@media (min-width: 768px) {
  .chart { height: 320px; }
  .chart.tall { height: 440px; }
  .chart.map { height: 420px; }
}
@media (min-width: 1000px) {
  .detail { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-flow: row dense; }  /* карта во всю ширину не оставляет дыр */
  .detail .viz:has(.map) { grid-column: 1 / -1; }
}

/* ---- раздел администратора (admin.html, admin_outings.html, admin.js) ---- */
h3 { margin: 0; font-size: 1.05rem; line-height: 1.3; }
.adminlink { padding: 8px 0; }
.block { margin: 0 0 var(--gap); }
.block > h2 { margin-bottom: 8px; }

.subnav { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 12px; }
.subnav a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
}
.subnav a[aria-current="page"] { color: var(--on-accent); background: var(--accent); border-color: var(--accent); }

.stats.summary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0 0 var(--gap);
  padding: 12px var(--gap);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.note.off { color: var(--danger); border-color: var(--danger); }
.note.old { margin-left: 0; color: var(--warn-text); background: var(--warn-bg); border-color: transparent; }
.hint.none { margin: 12px 0 0; }

.invite-list { display: grid; gap: 8px; margin: 12px 0 0; padding: 0; list-style: none; }
.invite-list li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.invite-list form { margin: 0; }

.filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; }
.filter label { flex: 0 0 100%; font-weight: 600; }
.filter select {
  flex: 1 1 200px;
  min-width: 0;
  min-height: 44px;
  padding: 8px 12px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
}

/* таблица выходов: прокручивается внутри рамки, страница не шире экрана */
.table-wrap { max-width: 100%; margin: 0 0 12px; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table-wrap:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; font-variant-numeric: tabular-nums; }
.admin-table th, .admin-table td { padding: 8px 10px; text-align: left; vertical-align: top; white-space: nowrap; overflow-wrap: normal; border-top: 1px solid var(--border); }
.admin-table thead th { border-top: 0; color: var(--muted); font-size: 0.8125rem; font-weight: 600; }
.admin-table .num { text-align: right; }
.admin-table .sub { display: block; color: var(--muted); font-size: 0.8125rem; }
.admin-table .sub.err { min-width: 14rem; color: var(--danger); white-space: normal; }
.admin-table tfoot th, .admin-table tfoot td { border-top: 2px solid var(--border); font-weight: 600; }
.admin-table a { color: var(--accent); }
.card h3.card-title { margin-bottom: 8px; }
