/* Parking ANPR - веб-интерфейс (этап 11.2).
   Телефон и компьютер, светлая и тёмная тема (по настройке устройства).
   Цвет решения тот же, что на экране будки: зелёный - открыто,
   жёлтый - решает охрана, красный - запрет или сбой. */

:root {
  --bg: #f2f4f6;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --ink: #16202a;
  --ink-2: #4a5763;
  --ink-3: #6b7783;
  --line: #dde2e7;
  --accent: #1d5fa8;
  --accent-ink: #ffffff;
  --accent-bg: #e2edf9;
  --ok: #1f7a45;
  --ok-bg: #e3f3e9;
  --warn: #8a5b00;
  --warn-bg: #fbf0d5;
  --bad: #b3261e;
  --bad-bg: #fbe3e1;
  --info: #56626d;
  --info-bg: #eceff2;
  --focus: #1d5fa8;
  --shadow: 0 1px 2px rgba(22, 32, 42, 0.06), 0 2px 10px rgba(22, 32, 42, 0.05);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151b;
    --surface: #17202a;
    --surface-2: #1c2631;
    --ink: #e6ebef;
    --ink-2: #b1bcc6;
    --ink-3: #8c98a3;
    --line: #2a3540;
    --accent: #6aa7ea;
    --accent-ink: #0f151b;
    --accent-bg: #16283d;
    --ok: #6cc990;
    --ok-bg: #15301f;
    --warn: #e7b54f;
    --warn-bg: #3a2c0f;
    --bad: #f08a82;
    --bad-bg: #3d1715;
    --info: #a8b3bd;
    --info-bg: #232d37;
    --focus: #8cbcf0;
    --shadow: none;
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--font);
  min-height: 100vh;
}

a { color: var(--accent); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0; }

.loading { padding: 40px 16px; text-align: center; color: var(--ink-3); }

/* --- верхняя строка и разделы --- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
}

.nav { display: flex; gap: 4px; flex: 1; }
.nav a, .tabs a {
  color: var(--ink-2);
  text-decoration: none;
  border-radius: 8px;
  font-weight: 500;
}
.nav a { padding: 8px 12px; }
.nav a[aria-current="page"] { background: var(--accent-bg); color: var(--accent); }
.nav a:hover { color: var(--ink); }

.who {
  margin-left: auto;
  color: var(--ink-2);
  text-decoration: none;
  font-size: 14px;
  text-align: right;
  line-height: 1.25;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.who small { display: block; color: var(--ink-3); }

.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: none;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1;
  padding: 10px 4px 12px;
  text-align: center;
  font-size: 13px;
}
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; }

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

@media (max-width: 720px) {
  .bar { padding: 8px 16px; }
  .nav { display: none; }
  .tabs { display: flex; }
  .view { padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); }
  .who { max-width: 60vw; }
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: 600 16px/1.2 var(--font);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { width: 100%; min-height: 60px; font-size: 19px; border-radius: 12px; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 6px 4px; min-height: 0; font-weight: 500; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }

.field { display: grid; gap: 6px; }
.field > span { font-weight: 600; font-size: 14px; color: var(--ink-2); }
.field .hint { font-size: 13px; color: var(--ink-3); }

input[type="text"], input[type="password"], input[type="search"], input[type="date"], select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: 16px/1.3 var(--font);
}
input::placeholder { color: var(--ink-3); }
input.code {
  font: 600 28px/1.2 var(--mono);
  letter-spacing: 0.3em;
  text-align: center;
  max-width: 260px;
}

.form { display: grid; gap: 16px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.error { color: var(--bad); font-weight: 500; min-height: 1.45em; }
.muted { color: var(--ink-3); }
.small-text { font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font: 14px var(--font);
  cursor: pointer;
}
.chips button[aria-pressed="true"] { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; flex-wrap: wrap; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; padding: 10px 14px; font-size: 15px; color: var(--ink-2); background: var(--surface); }
.seg label + label span { border-left: 1px solid var(--line); }
.seg input:checked + span { background: var(--accent-bg); color: var(--accent); font-weight: 600; }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: -2px; }

/* --- карточки --- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card > h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.center-card { max-width: 440px; margin: 6vh auto 0; }
.center-card h1 { margin-bottom: 6px; }
.center-card .lead { color: var(--ink-2); margin-bottom: 20px; }
.center-card.wide { max-width: 560px; }
.narrow { max-width: 560px; }
.mt { margin-top: 10px; }
.mb { margin-bottom: 14px; }

.grid { display: grid; gap: 16px; }
.lanes { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dash-bottom { display: grid; gap: 16px; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); align-items: start; }
@media (max-width: 860px) {
  .lanes, .dash-bottom { grid-template-columns: minmax(0, 1fr); }
}

/* --- состояние и цвета --- */

.banner {
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 600;
  border: 1px solid transparent;
}
.k-ok, .k-allow { --k: var(--ok); --k-bg: var(--ok-bg); }
.k-warn { --k: var(--warn); --k-bg: var(--warn-bg); }
.k-bad, .k-deny, .k-fault { --k: var(--bad); --k-bg: var(--bad-bg); }
.k-reading { --k: var(--accent); --k-bg: var(--accent-bg); }
.k-stale, .k-info { --k: var(--info); --k-bg: var(--info-bg); }
.banner[class*="k-"] { background: var(--k-bg); color: var(--k); border-color: color-mix(in srgb, var(--k) 25%, transparent); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--k, var(--info)); flex: none; }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--k-bg, var(--info-bg));
  color: var(--k, var(--info));
}

.lane-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.lane-head .sub { color: var(--ink-3); font-size: 14px; }
.lane-video { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); margin-bottom: 12px; }

.decision {
  border-left: 5px solid var(--k, var(--info));
  background: var(--k-bg, var(--info-bg));
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 6px;
}
.decision .d-title { font-weight: 700; font-size: 18px; color: var(--k, var(--ink)); }
.decision .d-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.decision .d-reason { font-weight: 600; }
.decision .d-note, .decision .d-meta { font-size: 14px; color: var(--ink-2); }
.decision.empty { --k: var(--line); background: var(--surface-2); color: var(--ink-3); font-weight: 500; }

.alert { margin-top: 10px; }

/* --- номерной знак --- */

.plate {
  display: inline-flex;
  align-items: stretch;
  border: 2px solid #111;
  border-radius: 5px;
  background: #fff;
  color: #111;
  font: 700 18px/1 var(--mono);
  overflow: hidden;
  white-space: nowrap;
}
.plate .pl-main { padding: 4px 8px; display: flex; gap: 3px; align-items: baseline; }
.plate .pl-l { font-size: 15px; }
.plate .pl-reg { border-left: 2px solid #111; padding: 2px 6px; display: grid; justify-items: center; font-size: 13px; }
.plate .pl-reg i { font: 600 8px/1 var(--font); font-style: normal; letter-spacing: 0.05em; }
.plate.small { font-size: 14px; border-width: 1.5px; }
.plate.small .pl-main { padding: 2px 6px; }
.plate.small .pl-l { font-size: 12px; }
.plate.small .pl-reg { font-size: 11px; padding: 1px 4px; border-left-width: 1.5px; }
.plate.small .pl-reg i { display: none; }

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

.list { display: grid; }
.row {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr) auto;
  gap: 4px 12px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row .t { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 14px; }
.row .t small { display: block; color: var(--ink-3); font-size: 12px; }
.row .main { display: grid; gap: 3px; min-width: 0; }
.row .line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row .line2 { color: var(--ink-2); font-size: 14px; overflow-wrap: anywhere; }
.row .line3 { color: var(--ink-3); font-size: 13px; overflow-wrap: anywhere; }
.row .side { color: var(--ink-3); font-size: 13px; text-align: right; }

.presence-count { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.presence-count b { font-size: 36px; line-height: 1; font-variant-numeric: tabular-nums; }

.sys-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.sys-row:first-child { border-top: 0; }
.sys-row .label { flex: 1; color: var(--ink-2); }
.sys-row .value { font-weight: 600; color: var(--k, var(--ink)); }

.updated { text-align: center; font-size: 13px; color: var(--ink-3); padding: 8px 0; }
.updated.stale { color: var(--bad); font-weight: 600; }

.filters { display: grid; gap: 12px; margin-bottom: 16px; }
.filters .inline { display: flex; gap: 10px; flex-wrap: wrap; }
.filters .inline > * { flex: 1 1 180px; }
.more { display: flex; justify-content: center; padding-top: 12px; }

/* --- настройка кода --- */

.steps { display: grid; gap: 18px; counter-reset: step; }
.step { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; }
.step::before {
  counter-increment: step;
  content: counter(step);
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 700;
}
.step > div { display: grid; gap: 10px; }
.qr { width: 220px; max-width: 100%; background: #fff; padding: 8px; border-radius: 8px; border: 1px solid var(--line); }
.qr svg { display: block; width: 100%; height: auto; }
.secret { font: 600 18px/1.4 var(--mono); letter-spacing: 0.06em; word-spacing: 0.3em; overflow-wrap: anywhere; }

/* --- окно открытия --- */

.sheet {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
}
.sheet::backdrop { background: rgba(10, 16, 22, 0.55); }
.sheet form { padding: 20px; display: grid; gap: 16px; }
.sheet .sheet-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
@media (max-width: 720px) {
  .sheet { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; max-height: 92vh; }
  .sheet form { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(560px, calc(100vw - 24px));
  padding: 12px 18px;
  border-radius: 10px;
  font-weight: 600;
  background: var(--k-bg, var(--surface));
  color: var(--k, var(--ink));
  border: 1px solid color-mix(in srgb, var(--k, var(--ink)) 30%, transparent);
  box-shadow: 0 6px 24px rgba(10, 16, 22, 0.18);
}
@media (max-width: 720px) {
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

.profile-grid { display: grid; gap: 8px 16px; grid-template-columns: max-content minmax(0, 1fr); margin-bottom: 18px; }
.profile-grid dt { color: var(--ink-3); }
.profile-grid dd { margin: 0; font-weight: 600; }

@media (prefers-reduced-motion: no-preference) {
  .toast { transition: opacity 0.2s; }
}
