/* «Автовахта»: крупно, контрастно, удобно с телефона. Две темы — светлая и тёмная; «как в системе» выбирает
   по настройке устройства. Все цвета — переменные: тёмная тема переопределяет только их. */
:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1d2228; --muted: #5d6875; --line: #d9dee4;
  --header: #182330; --header-text: #ffffff; --input: #ffffff; --th: #f7f8fa; --hover: #eef4ff;
  --accent: #1f6feb; --accent-dark: #1858c0; --accent-text: #ffffff; --focus: #9cc3ff;
  --green: #17732f; --green-bg: #d8f3df; --red: #b4231a; --red-bg: #fde1de;
  --gray: #4c5763; --gray-bg: #e6e9ee; --warn: #7a4f00; --warn-bg: #fff2cc;
  --blocked: #ffffff; --blocked-bg: #30343a;
  --flash: #0f5323; --flash-bg: #d8f3df; --err: #b4231a; --err-bg: #fff6f5;
  --plate-bg: #ffffff; --plate-text: #111111; --plate-line: #222222;
  --shadow: 0 1px 2px rgba(0,0,0,.05); --backdrop: rgba(0,0,0,.7);
  --radius: 10px;
  color-scheme: light;
}
/* Тёмная: графит, мягкий светлый текст, яркие читаемые метки */
:root[data-theme="dark"] {
  --bg: #1b2027; --card: #242a32; --text: #e4e8ec; --muted: #9ba6b2; --line: #363e48;
  --header: #12161b; --header-text: #e9edf1; --input: #1e242b; --th: #2a313a; --hover: #2c3846;
  --accent: #4d8ef7; --accent-dark: #3a7be6; --accent-text: #ffffff; --focus: #2f5d9e;
  --green: #6fdc8c; --green-bg: #1d3a27; --red: #ff8a80; --red-bg: #47211f;
  --gray: #c3cbd4; --gray-bg: #353d47; --warn: #f2c862; --warn-bg: #3b3115;
  --blocked: #f1f1f1; --blocked-bg: #0d0f12;
  --flash: #a6ecb9; --flash-bg: #1d3a27; --err: #ff9a91; --err-bg: #2f1f20;
  --plate-bg: #f4f4ef; --plate-text: #111111; --plate-line: #cfd3d8;
  --shadow: none; --backdrop: rgba(0,0,0,.8);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #1b2027; --card: #242a32; --text: #e4e8ec; --muted: #9ba6b2; --line: #363e48;
    --header: #12161b; --header-text: #e9edf1; --input: #1e242b; --th: #2a313a; --hover: #2c3846;
    --accent: #4d8ef7; --accent-dark: #3a7be6; --accent-text: #ffffff; --focus: #2f5d9e;
    --green: #6fdc8c; --green-bg: #1d3a27; --red: #ff8a80; --red-bg: #47211f;
    --gray: #c3cbd4; --gray-bg: #353d47; --warn: #f2c862; --warn-bg: #3b3115;
    --blocked: #f1f1f1; --blocked-bg: #0d0f12;
    --flash: #a6ecb9; --flash-bg: #1d3a27; --err: #ff9a91; --err-bg: #2f1f20;
    --plate-bg: #f4f4ef; --plate-text: #111111; --plate-line: #cfd3d8;
    --shadow: none; --backdrop: rgba(0,0,0,.8);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: .2em 0 .6em; }
h2 { font-size: 1.2rem; margin: 1.2em 0 .5em; }
h3 { font-size: 1.05rem; }

/* шапка */
.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 8px 16px;
  background: var(--header); color: var(--header-text); position: sticky; top: 0; z-index: 10; }
.top a { color: var(--header-text); text-decoration: none; }
.brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1 1 auto; scrollbar-width: none; }
.nav a { padding: 8px 12px; border-radius: 8px; white-space: nowrap; opacity: .85; }
.nav a.active, .nav a:hover { background: rgba(255,255,255,.14); opacity: 1; }
.me { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
/* не помещается в строку: «Автовахта» и кнопки пользователя — сверху, меню — строкой ниже на всю ширину */
@media (max-width: 1500px) {
  .top .brand { order: 1; }
  .top .me { order: 2; margin-left: auto; }
  .top .nav { order: 3; flex-basis: 100%; }
}
.page { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* переключатель темы */
.theme-menu { position: relative; }
.theme-menu summary { list-style: none; cursor: pointer; font-size: 1.25rem; width: 40px; height: 40px;
  display: grid; place-items: center; border-radius: 50%; border: 1px solid rgba(255,255,255,.35); }
.theme-menu summary::-webkit-details-marker { display: none; }
.theme-menu .menu { position: absolute; right: 0; top: 46px; background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; min-width: 210px; z-index: 20;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); display: grid; gap: 2px; }
.theme-menu .menu button { all: unset; cursor: pointer; padding: 10px 12px; border-radius: 8px; display: flex; gap: 10px; }
.theme-menu .menu button:hover, .theme-menu .menu button[aria-checked="true"] { background: var(--hover); }
.theme-menu .menu button[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); }
.login-theme { position: fixed; right: 12px; top: 12px; }
.login-theme summary { border-color: var(--line); color: var(--text); }

/* кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  padding: 8px 18px; border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--accent-dark); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn.ghost { background: transparent; color: inherit; border: 1px solid currentColor; }
.btn.light { background: var(--gray-bg); color: var(--text); }
.btn.light:hover { background: var(--line); }
.btn.danger { background: var(--red-bg); color: var(--red); border: 1px solid var(--red); }
.btn.danger:hover { background: var(--red); color: #fff; }
.btn.ok { background: #1f8a3c; color: #fff; }
.btn.ok:hover { background: #18722f; }
.btn.big { min-height: 56px; font-size: 1.1rem; }
.inline { display: inline; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 12px 0; align-items: center; }

/* карточки и сообщения */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  margin-bottom: 16px; box-shadow: var(--shadow); }
.flash { background: var(--flash-bg); color: var(--flash); border-radius: var(--radius); padding: 12px 16px;
  margin-bottom: 16px; font-weight: 600; }
.alert { border-radius: var(--radius); padding: 12px 16px; margin: 10px 0; }
.alert.error { background: var(--red-bg); color: var(--red); font-weight: 600; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.ok { background: var(--green-bg); color: var(--green); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.ok-text { color: var(--green); }

/* формы */
form.stack, .stack { display: grid; gap: 14px; max-width: 640px; }
.field { display: grid; gap: 4px; align-content: start; }
.field .label { font-weight: 600; }
.req { color: var(--red); }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: 46px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: var(--input); color: var(--text); }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); border-color: var(--accent); }
.hint { color: var(--muted); font-size: .88rem; }
.hint.rec { color: var(--text); opacity: .85; }
.err { color: var(--err); font-weight: 600; font-size: .92rem; }
.has-error input, .has-error select { border-color: var(--red); background: var(--err-bg); }
.check { display: flex; gap: 10px; align-items: center; min-height: 40px; }
.check input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.radio-row { display: flex; flex-wrap: wrap; gap: 10px; }
.radio-row label { display: flex; gap: 8px; align-items: center; padding: 10px 14px; border: 2px solid var(--line);
  border-radius: var(--radius); cursor: pointer; font-weight: 600; background: var(--input); }
.radio-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.radio-row label:has(input:checked) { border-color: var(--accent); background: var(--hover); }
.plate-input { font-size: 1.4rem !important; letter-spacing: .06em; text-transform: uppercase; font-weight: 700; }
.plate-hint { min-height: 1.6em; font-weight: 600; }
.plate-hint.ok { color: var(--green); }
.plate-hint.bad { color: var(--red); }
details > summary { cursor: pointer; }

/* раздел формы с заголовком (например, «Telegram-бот» в форме пользователя) */
fieldset.section { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; margin: 0;
  display: grid; gap: 14px; max-width: 640px; }
fieldset.section legend { font-weight: 700; font-size: 1.05rem; padding: 0 6px; }

/* значки: тонкая линия, цвет — от текста; размер — от шрифта */
.icon { width: 1.2em; height: 1.2em; vertical-align: -0.22em; flex: none; }
.brand .logo { width: 1.5em; height: 1.5em; vertical-align: -0.35em; color: #6ea8ff; }
.login-title .logo { width: 1.3em; height: 1.3em; color: var(--accent); }
.me-link { display: inline-flex; gap: 6px; align-items: center; }
.theme-menu summary .icon { width: 22px; height: 22px; }
.theme-menu .menu button { align-items: center; }
.alert .icon, .plate-hint .icon, .tag .icon { margin-right: 2px; }
.btn.is-sending { opacity: .65; cursor: progress; }

/* данные для входа — один раз после создания/сброса */
.creds { font: 600 1.05rem/1.6 "Consolas", "DejaVu Sans Mono", monospace; background: var(--gray-bg); color: var(--text);
  border-radius: var(--radius); padding: 14px 16px; white-space: pre-wrap; word-break: break-word; margin: 0 0 12px; user-select: all; }

/* генератор пароля и правила */
.pw-pair { display: grid; gap: 14px; }
.pw-gen { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pw-out { display: inline-flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pw-text { font: 700 1.25rem/1.2 "Consolas", "DejaVu Sans Mono", monospace; letter-spacing: .08em; padding: 6px 12px;
  border-radius: 8px; background: var(--gray-bg); color: var(--text); user-select: all; }
.pw-rules { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: .88rem; }
.pw-rules li { color: var(--muted); }
.pw-rules li::before { content: "✗ "; color: var(--red); font-weight: 700; }
.pw-rules li.ok { color: var(--green); }
.pw-rules li.ok::before { content: "✓ "; color: var(--green); }

/* поле пароля с «глазом» */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 52px; }
.pw-wrap .eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 44px; height: 38px;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer;
  display: grid; place-items: center; }
.pw-wrap .eye .icon { width: 22px; height: 22px; }
.pw-wrap .eye:hover { background: var(--gray-bg); color: var(--text); }

/* сетки фильтров и настроек */
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px 14px; align-items: start; }
.filter-grid.two { grid-template-columns: 2fr 1fr; max-width: 640px; }
.filter-grid .hint { font-size: .8rem; }
.filter-buttons { display: flex; gap: 10px; align-items: end; grid-column: 1 / -1; }
.filters-toggle > summary { list-style: none; margin-bottom: 10px; width: max-content; }
.filters-toggle > summary::-webkit-details-marker { display: none; }
@media (min-width: 721px) { .filters-toggle > summary { display: none; } }   /* на ПК фильтры всегда раскрыты */
.filter-grid .wide { grid-column: span 2; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: end; }
/* настройки: слева разделы, справа строки «описание | поле», кнопка сохранения прилипает к низу экрана */
html { scroll-behavior: smooth; }
/* выделение текущего раздела — только цветом текста и фоном: та же толщина шрифта и те же отступы, ничего не прыгает */
.settings-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; align-items: start; }
.settings-nav { position: sticky; top: calc(var(--hdr, 64px) + 12px); display: grid; gap: 2px; }
.settings-nav a { padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; font-weight: 400;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-nav a:hover { background: var(--hover); }
.settings-nav a.current { background: var(--hover); color: var(--accent); }
.settings-section { scroll-margin-top: calc(var(--hdr, 64px) + 12px); }
.settings-section h2 { margin-top: 0; }
.srow { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 8px 28px; padding: 14px 10px;
  border-top: 1px solid var(--line); align-items: start; border-radius: 6px; }
.settings-section h2 + .srow { border-top: 0; }
.srow .stext { display: grid; gap: 3px; }
.srow .sctl { padding-top: 2px; }
.srow.changed { background: var(--warn-bg); box-shadow: inset 4px 0 0 var(--warn); }
.srow.has-error { background: var(--err-bg); box-shadow: inset 4px 0 0 var(--red); }
.readonly-info { display: grid; gap: 4px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; }
.switch { display: flex; gap: 10px; align-items: center; min-height: 46px; cursor: pointer; }
.switch input { width: 24px; height: 24px; accent-color: var(--accent); }
.savebar { position: sticky; bottom: 0; z-index: 5; display: flex; justify-content: flex-end; align-items: center; gap: 16px;
  padding: 12px 16px; margin: 0 0 16px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 -6px 18px rgba(0,0,0,.12); }
.savebar-note { color: var(--muted); }
.savebar.dirty .savebar-note { color: var(--warn); font-weight: 700; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); }
table.list th, table.list td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { font-size: .85rem; color: var(--muted); font-weight: 600; background: var(--th); }
table.list tr.blocked td { opacity: .6; }
.diff td { font-size: .88rem; padding: 2px 8px 2px 0; border: 0; }

/* метки */
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; font-weight: 700; white-space: nowrap; }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.red { background: var(--red-bg); color: var(--red); }
.tag.unknown { background: var(--gray-bg); color: var(--gray); }
.tag.blocked { background: var(--blocked-bg); color: var(--blocked); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.plate { font-family: "Consolas", "DejaVu Sans Mono", monospace; font-weight: 700; font-size: 1.15rem; color: var(--plate-text);
  border: 2px solid var(--plate-line); border-radius: 6px; padding: 0 6px; background: var(--plate-bg); white-space: nowrap; }

/* статус камер */
.cameras { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.cam { display: flex; gap: 8px; align-items: center; padding: 8px 14px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--line); font-weight: 600; }
.dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; background: var(--muted); }
.cam.on .dot { background: #2da44e; box-shadow: 0 0 0 3px var(--green-bg); }
.cam.off { border-color: var(--red); background: var(--red-bg); color: var(--red); }
.cam.off .dot { background: var(--red); }
.cam.disabled { opacity: .7; }

/* живое видео */
.video-block { margin-bottom: 16px; }
.video-toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.seg { display: inline-flex; gap: 0; }
.seg .btn { border-radius: 0; }
.seg .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.seg .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.seg .btn.active { background: var(--accent); color: var(--accent-text); }
.video-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.vwin { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  cursor: zoom-in; }
/* окно — в пропорции настоящего кадра камеры (2592×1520); дополнительный поток 704×576 — это тот же кадр,
   сжатый по ширине, поэтому растягиваем на всё окно (fill), а не вписываем с полосами */
.vwin .vbox { position: relative; aspect-ratio: 2592 / 1520; background: #0b0d10; }
.vwin video, .vwin .vsnap { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; background: #0b0d10; }
.vwin .vmsg { position: absolute; left: 8px; bottom: 8px; right: 8px; padding: 6px 10px; border-radius: 6px;
  background: rgba(0,0,0,.65); color: #fff; font-size: .9rem; width: max-content; max-width: calc(100% - 16px); }
.vwin figcaption { padding: 8px 12px; font-weight: 700; }
.vwin:fullscreen { border: 0; border-radius: 0; background: #000; display: grid; }
.vwin:fullscreen { place-items: center; }
.vwin:fullscreen .vbox { width: min(100vw, calc(100vh * 2592 / 1520)); }
.vwin:fullscreen figcaption { position: absolute; top: 10px; left: 14px; color: #fff; text-shadow: 0 1px 3px #000; }

/* лента */
.feed { display: grid; gap: 10px; }
.pass { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; background: var(--card);
  border: 1px solid var(--line); border-left: 8px solid var(--gray-bg); border-radius: var(--radius); padding: 10px; }
.pass.green { border-left-color: #2da44e; }
.pass.red { border-left-color: #e5534b; }
.pass.blocked { border-left-color: var(--blocked-bg); }
.pass.fresh { animation: fresh 3s ease-out; }
@keyframes fresh { from { background: var(--warn-bg); } to { background: var(--card); } }
.pass .shots { display: flex; gap: 8px; align-items: center; }
.pass .shots img { border-radius: 6px; cursor: zoom-in; background: var(--gray-bg); display: block; }
.pass .full { width: 160px; height: 90px; object-fit: cover; }
.pass .crop { width: 150px; height: 46px; object-fit: contain; }
.pass .main { display: grid; gap: 4px; }
.pass .line1 { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.pass .who { font-weight: 600; }
.pass .meta { color: var(--muted); font-size: .9rem; }
.pass .side { text-align: right; display: grid; gap: 4px; justify-items: end; }
.pass .time { font-size: 1.3rem; font-weight: 700; }
.noshot { display: grid; place-items: center; background: var(--gray-bg); border-radius: 6px; color: var(--muted);
  font-size: .8rem; text-align: center; padding: 4px; }
.noshot.full { width: 160px; height: 90px; }
.noshot.crop { width: 150px; height: 46px; }

/* фото проезда крупно */
.shots-big { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.shots-big figure { margin: 0; display: grid; gap: 6px; }
.shots-big img { width: 100%; border-radius: 8px; cursor: zoom-in; background: var(--gray-bg); }
.shots-big figcaption { color: var(--muted); font-size: .88rem; }
.shots-big .noshot { min-height: 120px; }

/* всплывающее окно с фото */
.photo-dialog { border: 0; border-radius: var(--radius); padding: 10px; max-width: 96vw; max-height: 96vh;
  background: var(--card); color: var(--text); }
.photo-dialog img { max-width: 92vw; max-height: 82vh; display: block; margin-bottom: 8px; }
.photo-dialog::backdrop { background: var(--backdrop); }

.pager { display: flex; gap: 12px; align-items: center; margin: 14px 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.code { font: 700 2rem/1.2 "Consolas", monospace; letter-spacing: .2em; background: var(--gray-bg); padding: 10px 18px;
  border-radius: var(--radius); display: inline-block; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 4px 16px; }
.login-box { max-width: 420px; margin: 8vh auto; }

@media (max-width: 900px) {
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-layout { grid-template-columns: 1fr; }
  .settings-nav { display: none; }                              /* на телефоне и узком экране — без списка разделов */
  .srow { grid-template-columns: 1fr; gap: 8px; }               /* столбиком: описание, под ним поле */
}
@media (max-width: 720px) {
  body { font-size: 16px; }
  .page { padding: 10px; }
  .pass { grid-template-columns: 1fr; }
  .pass .shots { flex-direction: column; align-items: stretch; }        /* фото — одно под другим */
  .pass .full, .pass .noshot.full { width: 100%; height: auto; aspect-ratio: 16 / 9; }
  .pass .crop, .pass .noshot.crop { width: 100%; height: 64px; }
  .pass .side { text-align: left; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-items: start; }
  .shots-big { grid-template-columns: 1fr; }
  .video-grid { grid-template-columns: 1fr; }                   /* видео — одно под другим */
  .filter-grid, .filter-grid.two { grid-template-columns: 1fr; }
  .filter-grid .wide { grid-column: auto; }
  .me .who-name { display: none; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  table.list.responsive thead { display: none; }
  table.list.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.list.responsive td { display: block; border: 0; padding: 4px 10px; }
}
