/* Статусные цвета (success / warning / error) — только для статуса проезда и камер; accent — только для
   интерактивного. Табличка номера всегда белая, как настоящая. */
@font-face {
  font-family: "RoadNumbers";
  src: url("fonts/RoadNumbers2.0.otf") format("opentype");
  font-display: block;
}

:root {
  --bg: #f1f2f4;
  --surface: #ffffff;
  --surface-alt: #e8eaee;
  --border: #dcdfe4;
  --text: #15181d;
  --muted: #5f6672;
  --faint: #9399a3;
  --accent: #2d6cff;
  --accent-dark: #e6edff;
  --success: #198a4b;
  --success-dark: #e1f4e8;
  --warning: #b07800;
  --warning-dark: #fff2d1;
  --error: #d43a2f;
  --error-dark: #fde6e4;
  --scrim: rgba(10, 12, 16, .45);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1c2027;
    --surface-alt: #262b33;
    --border: #2f353e;
    --text: #e9ecf1;
    --muted: #9aa1ad;
    --faint: #697180;
    --accent: #5b8cff;
    --accent-dark: #1d2944;
    --success: #3ccf7c;
    --success-dark: #16301f;
    --warning: #f2b330;
    --warning-dark: #3a2e12;
    --error: #ff6b60;
    --error-dark: #3a1d1b;
    --scrim: rgba(0, 0, 0, .6);
    color-scheme: dark;
  }
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
  max-width: 640px;
  margin: 0 auto;
}

.tnum { font-variant-numeric: tabular-nums; }

h2 {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 15px; font-weight: 600; margin: 24px 4px 8px;
}
h2 .count { color: var(--faint); font-weight: 400; }
h2 .more { margin-left: auto; font-size: 13px; font-weight: 400; color: var(--accent); background: none;
           border: 0; padding: 0; font-family: inherit; cursor: pointer; }

.loading { color: var(--muted); text-align: center; padding: 48px 12px; }

.empty { text-align: center; padding: 28px 16px; }
.empty .what { font-weight: 600; }
.empty .how { color: var(--muted); font-size: 13px; margin-top: 4px; }
.empty .btn { margin-top: 14px; }

.card { background: var(--surface); border-radius: 12px; overflow: hidden; }

/* ---------- госномер ---------- */

.plate {
  display: inline-flex; align-items: stretch;
  background: #fff; color: #111;
  border: 1.5px solid #111; border-radius: 4px;
  font: 17px/1 "RoadNumbers", ui-monospace, monospace;
  white-space: nowrap; flex: none;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .08);
}
.plate .pn { padding: 3px 5px 2px 6px; letter-spacing: .02em; }
.plate .pr {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-left: 1.5px solid #111; padding: 1px 4px 1px;
  font-size: 13px;
}
.plate .pr i { font: 600 5px/1 -apple-system, "Segoe UI", Roboto, Arial, sans-serif; font-style: normal;
               letter-spacing: .06em; margin-top: 1px; }
.plate.police, .plate.diplomatic { color: #fff; }
.plate.police { background: #1f4fa3; }
.plate.diplomatic { background: #b3261e; }
.plate.police .pr, .plate.diplomatic .pr { border-left-color: #fff; }
.plate.lg { font-size: 40px; border-width: 2.5px; border-radius: 7px; }
.plate.lg .pn { padding: 6px 10px 4px 12px; }
.plate.lg .pr { border-left-width: 2.5px; padding: 2px 8px; font-size: 30px; }
.plate.lg .pr i { font-size: 10px; margin-top: 2px; }

/* ---------- статусы ---------- */

.st { font-size: 13px; font-weight: 600; white-space: nowrap; }
.st.in { color: var(--success); }
.st.out { color: var(--error); }
.st.unknown { color: var(--warning); }
.st.unread { color: var(--muted); }
.noplate {
  display: inline-block; padding: 3px 8px; border: 1.5px dashed var(--faint); border-radius: 6px;
  color: var(--muted); font-size: 13px;
}
.last .noplate { margin-top: 14px; font-size: 15px; padding: 8px 12px; }

.chip-st {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 4px; white-space: nowrap;
}
.chip-st.in { background: var(--success-dark); color: var(--success); }
.chip-st.out { background: var(--error-dark); color: var(--error); }
.chip-st.unknown { background: var(--warning-dark); color: var(--warning); }
.chip-st.unread { background: var(--surface-alt); color: var(--muted); }
.chip-st.new { background: var(--success-dark); color: var(--success); }
.chip-st.update { background: var(--warning-dark); color: var(--warning); }
.chip-st.same { background: var(--surface-alt); color: var(--faint); }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot.on { background: var(--success); box-shadow: 0 0 0 4px var(--success-dark); }
.dot.off { background: var(--error); box-shadow: 0 0 0 4px var(--error-dark); }
.dot.idle { background: var(--faint); }

/* ---------- последний проезд ---------- */

.last { position: relative; background: var(--surface); border-radius: 12px; overflow: hidden; }
.last::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--faint); z-index: 1; }
.last.in::before { background: var(--success); }
.last.out::before { background: var(--error); }
.last.unknown::before { background: var(--warning); }
.last.unread::before { background: var(--muted); }
.last.tap { cursor: pointer; }
.last .photo { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: #000; cursor: pointer; }
.last .info { padding: 14px 16px 16px 20px; }
.last .top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.last .time { font-size: 28px; font-weight: 600; line-height: 1; }
.last .who { font-size: 20px; font-weight: 600; margin-top: 14px; }
.last .who.anon { color: var(--warning); }
.last .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.last .plate { margin-top: 14px; }

.stat { display: flex; gap: 8px; margin-top: 8px; }
.stat > div { flex: 1; background: var(--surface); border-radius: 12px; padding: 12px 14px; }
.stat b { display: block; font-size: 28px; line-height: 1.1; font-weight: 600; }
.stat span { color: var(--muted); font-size: 13px; }

/* ---------- строки ---------- */

.row {
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
}
.row + .row::after {
  content: ""; position: absolute; left: 14px; right: 0; top: 0; border-top: 1px solid var(--border);
}
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .title.anon { color: var(--warning); font-weight: 600; }
.row .sub { color: var(--muted); font-size: 13px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .side { text-align: right; white-space: nowrap; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row .side .t { font-size: 15px; font-weight: 600; }
.row .chev { color: var(--faint); font-size: 20px; }
.row.tap { cursor: pointer; }
.row.tap:active { background: var(--surface-alt); }

.thumb { width: 72px; height: 48px; border-radius: 8px; object-fit: cover; flex: none; background: var(--surface-alt); }
.thumb.in { box-shadow: 0 0 0 2px var(--success); }
.thumb.out { box-shadow: 0 0 0 2px var(--error); }

.banner { display: flex; gap: 10px; border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; font-size: 13px; }
.banner b { display: block; font-size: 15px; margin-bottom: 2px; }
.banner.warn { background: var(--warning-dark); color: var(--text); }
.banner.warn b { color: var(--warning); }

/* ---------- формы и кнопки ---------- */

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.toolbar input { flex: 1; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.chip {
  border: 0; border-radius: 8px; padding: 8px 12px; font: inherit; font-size: 13px;
  background: var(--surface); color: var(--text); white-space: nowrap; cursor: pointer;
}
.chip.active { background: var(--accent); color: #fff; font-weight: 600; }

input, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 11px 12px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dark); }
.sheet input, .sheet select { background: var(--bg); }

label { display: block; font-size: 13px; color: var(--muted); margin: 16px 2px 6px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 4px 0; }
.hint code { font-size: 12px; }

button.btn {
  font: inherit; font-weight: 600;
  border: 0; border-radius: 8px; padding: 12px 16px;
  background: var(--accent); color: #fff; cursor: pointer;
}
button.btn.secondary { background: var(--surface); color: var(--accent); box-shadow: inset 0 0 0 1px var(--border); }
.sheet button.btn.secondary { background: transparent; }
button.btn.danger { background: transparent; color: var(--error); box-shadow: inset 0 0 0 1px var(--error); }
button.btn.wide { width: 100%; margin-top: 12px; }
button.btn:disabled { opacity: .45; }
button.icon {
  border: 0; background: var(--accent); color: #fff; width: 44px; height: 44px; border-radius: 8px;
  font-size: 24px; line-height: 1; flex: none; cursor: pointer;
}

.actions { display: flex; gap: 8px; margin-bottom: 12px; }
.actions .btn { flex: 1; }

.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 3px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px;
  padding: 9px 4px; border-radius: 6px; cursor: pointer;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); font-weight: 600; }

.daynav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daynav input { flex: 1; text-align: center; }
.daynav button { flex: none; width: 44px; height: 44px; border: 0; border-radius: 8px;
                 background: var(--surface); color: var(--text); font-size: 20px; cursor: pointer; }
.daynav button:disabled { color: var(--faint); }

.frame { margin-top: 12px; border-radius: 8px; overflow: hidden; background: var(--bg); }
.frame img { width: 100%; display: block; }
.frame .msg { padding: 12px 14px; font-size: 13px; }
.frame .msg.ok { color: var(--success); font-weight: 600; }
.frame .msg.err { color: var(--error); }

.summary { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; }

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

nav#tabs {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; background: var(--surface);
  box-shadow: 0 -1px 0 var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
nav#tabs button {
  flex: 1; border: 0; background: transparent; color: var(--faint);
  font: inherit; font-size: 11px; padding: 8px 0 9px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
nav#tabs button svg { width: 24px; height: 24px; }
nav#tabs button.active { color: var(--accent); font-weight: 600; }

.sheet { position: fixed; inset: 0; background: var(--scrim); display: flex; align-items: flex-end; z-index: 10; }
.sheet-body {
  background: var(--surface); width: 100%; max-width: 640px; margin: 0 auto;
  border-radius: 12px 12px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto;
}
.sheet-body h3 { margin: 0 0 4px; font-size: 20px; }
.sheet-body h2 { margin-left: 0; }
.sheet-body .card { background: var(--bg); }
.sheet-actions { display: flex; gap: 8px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }

.viewer { position: fixed; inset: 0; background: #000; z-index: 20; overflow: hidden; touch-action: none; }
.viewer img { position: absolute; left: 0; top: 0; transform-origin: 0 0; user-select: none; -webkit-user-select: none; }
.viewer-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px; z-index: 1;
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(0, 0, 0, .55); color: #fff;
  font-size: 18px; line-height: 40px; text-align: center; cursor: pointer;
}

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); border-radius: 8px; padding: 12px 14px;
  z-index: 30; text-align: center; font-size: 13px; max-width: 608px; margin: 0 auto;
}

.fatal { text-align: center; padding: 64px 16px; }
.fatal .what { font-size: 20px; font-weight: 600; }
.fatal .how { color: var(--muted); margin-top: 6px; }

.row .line { display: flex; align-items: center; gap: 8px; margin-top: 6px; min-width: 0; }
.row .side .cam { color: var(--faint); font-size: 11px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- разбор проездов ---------- */

.st.void { color: var(--faint); }
.row.void .title, .row.void .plate { opacity: .5; }
.when { padding: 10px 14px 0; font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; }
.when + .row::after { display: none; }

button.banner { width: 100%; border: 0; text-align: left; font: inherit; font-size: 13px; align-items: center; }
.banner .chev { margin-left: auto; color: var(--warning); font-size: 20px; }
.banner.tap { cursor: pointer; }

nav#tabs button { position: relative; }
nav#tabs .badge {
  position: absolute; top: 4px; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--warning); color: var(--surface); font-size: 11px; font-weight: 700; line-height: 18px;
}

.sheet-body .meta { color: var(--muted); font-size: 13px; }
.evphoto { display: block; width: 100%; border-radius: 8px; margin-top: 12px; background: #000; cursor: pointer; }
.alert {
  margin-top: 10px; padding: 10px 12px; border-radius: 8px;
  background: var(--warning-dark); color: var(--text); font-size: 13px;
}
.alert::before { content: "⚠ "; color: var(--warning); font-weight: 700; }
label.check { display: flex; gap: 10px; align-items: center; margin-top: 10px; color: var(--text); }
label.check input { width: auto; margin: 0; }
.pair { display: flex; gap: 8px; }
.pair input { min-width: 0; }
.pair #year { flex: 0 0 88px; }
.row .sub.warn { color: var(--warning); white-space: normal; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.quick .chip { display: inline-flex; align-items: center; gap: 8px; background: var(--bg); }
