:root {
  --bg: #0f1216; --panel: #171b21; --line: #262c35; --fg: #e8ecf1; --muted: #8a94a3;
  --track: #3a414c; --track-edge: #6b7482; --track-off: #353c47;
  --green: #3ac47d; --purple: #b56be8; --red: #ff4d4d; --warn: #f2b233;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f3f5f8; --panel: #ffffff; --line: #dde2e8; --fg: #14181d; --muted: #66707d;
    --track: #c9cfd7; --track-edge: #8a939e; --track-off: #dde1e7;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font: 14px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif; }
header { display: flex; align-items: center; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { font-weight: 800; font-size: 18px; letter-spacing: .3px; }
.brand span { font-weight: 400; color: var(--muted); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand picture, .logo picture { display: block; line-height: 0; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.link { color: var(--fg); text-decoration: none; border: 1px solid var(--line); padding: 4px 10px; border-radius: 6px; }
.clock { font-variant-numeric: tabular-nums; font-weight: 600; }
.conn { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.conn.on { background: rgba(58, 196, 125, .15); color: var(--green); }
.conn.off { background: rgba(255, 77, 77, .15); color: var(--red); }
.alarm-bar { background: var(--red); color: #fff; font-weight: 700; padding: 4px 12px; border-radius: 6px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

.box { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 12px; padding: 12px; height: calc(100% - 52px); }
.map-wrap { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; min-height: 360px; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-btn { position: absolute; left: 12px; top: 12px; z-index: 2; background: rgba(10,12,16,.7); color: #fff; border: 1px solid rgba(255,255,255,.2);
  border-radius: 6px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
.map-btn:hover { background: rgba(10,12,16,.9); }
.note { position: absolute; left: 12px; bottom: 8px; right: 12px; font-size: 11px; color: var(--muted); }
.side { display: flex; flex-direction: column; gap: 12px; overflow: auto; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
td.car { font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
tr.stale td { opacity: .5; }
tr.flash td { animation: flash 1s 3; }
@keyframes flash { 50% { background: rgba(255, 255, 255, .06); } }
.green { color: var(--green); } .purple { color: var(--purple); font-weight: 700; } .red { color: var(--red); }
.warn { color: var(--warn); } .crit { color: #fff; background: var(--red); padding: 0 6px; border-radius: 4px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.badge { font-size: 10px; background: var(--line); color: var(--muted); padding: 1px 6px; border-radius: 4px; font-weight: 500; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--c); border-radius: 10px; padding: 10px; }
.card.alarm { border-color: var(--red); box-shadow: 0 0 0 1px var(--red); }
.card-h { font-weight: 700; margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-h .dev { font-weight: 400; font-size: 11px; margin-left: 6px; }
.big { display: flex; align-items: baseline; gap: 6px; margin-bottom: 6px; }
.big b { font-size: 28px; font-variant-numeric: tabular-nums; }
.big b.gear { margin-left: auto; }
.big small { color: var(--muted); }
.row { display: flex; justify-content: space-between; padding: 2px 0; }
.row b { font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: var(--line); border-radius: 3px; margin: 6px 0; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--green); transition: width .3s; }
.mode { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-bottom: 4px; }
.mode.rec { background: rgba(255, 77, 77, .15); color: var(--red); }
.mode.standby { background: var(--line); color: var(--muted); }
.row.pin { align-items: center; gap: 6px; margin-top: 4px; padding-top: 6px; border-top: 1px dashed var(--line); }
.row.pin span { flex: 1; color: var(--muted); }
.meta-edit { background: none; border: 1px solid var(--line); color: var(--fg); border-radius: 4px; cursor: pointer; padding: 0 6px; font-size: 11px; }
.msg-show { background: none; border: 1px solid var(--line); color: var(--fg); border-radius: 4px; cursor: pointer; padding: 0 6px; font-size: 12px; }
.row.msg { font-size: 12px; margin-top: 4px; gap: 6px; }
.row.msg span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.msg.wait b, .row.msg.late b { color: var(--warn); } .row.msg.ok b { color: var(--green); }
.row.msg.no b { color: #fff; background: var(--red); padding: 0 6px; border-radius: 4px; animation: pulse 1s infinite; }
.bcast-btn { background: none; cursor: pointer; font: inherit; }
.ask-red { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 8px; background: var(--red); color: #fff; font-weight: 800; font-size: 15px; cursor: pointer; }
.ask-red:hover { filter: brightness(1.1); }
.poll { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.poll-h { display: flex; align-items: center; gap: 8px; font-weight: 700; }
.poll-h.bad { color: var(--red); }
.poll-h button { margin-left: auto; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; }
.poll-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--line); }
.chip.ok { background: rgba(58, 196, 125, .18); color: var(--green); }
.chip.no { background: var(--red); color: #fff; font-weight: 700; animation: pulse 1s infinite; }
.chip.late { background: rgba(242, 178, 51, .18); color: var(--warn); }
.msg-modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; }
.msg-modal[hidden] { display: none; }
.msg-card { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px 20px; width: min(520px, 92vw); }
.msg-h { font-size: 18px; font-weight: 700; margin: 0 40px 4px 0; }
.msg-tpl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0; }
.msg-tpl button, .msg-form button { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-weight: 700; cursor: pointer; }
.msg-tpl button:hover, .msg-form button:hover { border-color: var(--fg); }
.msg-form { display: flex; gap: 8px; align-items: center; }
.msg-form input { flex: 1; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: inherit; text-transform: uppercase; }
.err-text { color: var(--red); font-size: 13px; min-height: 18px; margin-top: 6px; }
.row.pin b { font-size: 16px; letter-spacing: 1px; }
.qr-show { background: none; border: 1px solid var(--line); color: var(--fg); border-radius: 4px; cursor: pointer; padding: 0 6px; font-size: 11px; font-weight: 700; }
.qr-modal { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; cursor: pointer; }
.qr-modal[hidden] { display: none; }  /* display:flex иначе перебивает атрибут hidden */
.qr-card { position: relative; background: #fff; color: #111; border-radius: 18px; padding: 24px 28px; text-align: center; max-width: 92vw; }
.qr-card img { display: block; width: min(70vh, 80vw); height: auto; margin: 12px auto; }
.qr-close { position: absolute; top: 8px; right: 10px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: #eee; color: #333; font-size: 20px; cursor: pointer; }
.qr-close:hover { background: #ddd; }
.qr-car { font-size: 28px; font-weight: 800; }
.qr-sub { color: #555; font-size: 16px; } .qr-sub b { color: #111; letter-spacing: 2px; font-size: 20px; }
.alarm-text { margin-top: 6px; color: var(--red); font-weight: 700; }

/* архив */
.archive { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 12px; padding: 12px; }
.archive .list { max-height: calc(100vh - 90px); overflow: auto; }
.archive tr.sel td { background: rgba(58, 142, 232, .15); }
.archive tbody tr { cursor: pointer; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.charts canvas { width: 100%; height: 260px; display: block; }
.legend span { margin-right: 14px; }

@media (max-width: 900px) {
  .box, .archive { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 60vh; }
  header { flex-wrap: wrap; }
}

select { background: var(--panel); color: var(--fg); border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font: inherit; }


/* видео с машины */
.video-box { position: absolute; right: 12px; bottom: 28px; width: min(46%, 560px); background: #000; border-radius: 10px; overflow: hidden; box-shadow: 0 6px 24px rgba(0,0,0,.45); }
.video-frame { position: relative; container-type: inline-size; }
.video-box video { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #000; }
/* Наложение: 5 зон по углам и в центре снизу, у каждой фиксированный размер — цифры не двигают соседей.
   Размеры в cqw: всё масштабируется вместе с окном видео (врезка или большой экран). */
.hud { position: absolute; inset: 0; pointer-events: none; color: #fff; font-size: 2.1cqw;
  font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.hp { position: absolute; background: rgba(10,12,16,.72); border-radius: 1cqw; padding: 1cqw 1.6cqw; line-height: 1.15; }
.hud small { color: #b8bec7; font-size: 1.9cqw; }
.hud b { font-weight: 700; }
.hud-tl { left: 1.6cqw; top: 1.6cqw; display: flex; align-items: center; gap: 1.4cqw; font-size: 2.5cqw; font-weight: 600; pointer-events: auto; }
.hud-tl .live { background: #e24b4a; border-radius: .5cqw; padding: .1cqw 1cqw; font-size: 1.8cqw; }
.hud-tl button { background: none; border: 0; color: #b8bec7; font-size: 2.6cqw; cursor: pointer; padding: 0 0 0 .6cqw; }
.hud-tl button:hover { color: #fff; }
.hud-tr { right: 1.6cqw; top: 1.6cqw; text-align: right; }
.secs { display: flex; gap: .6cqw; margin-top: .8cqw; justify-content: flex-end; }
.secs i { width: 5.5cqw; height: 1cqw; border-radius: .3cqw; background: #5f5e5a; }
.secs i.green { background: #4ade80; } .secs i.purple { background: #a78bfa; } .secs i.yellow { background: #facc15; }
.secs i.cur { outline: .3cqw solid #fff; outline-offset: .2cqw; }
.hud-bl { left: 1.6cqw; bottom: 1.6cqw; width: 21cqw; white-space: nowrap; }
.spd { display: flex; align-items: baseline; gap: .8cqw; }
.spd b { font-size: 6cqw; width: 3ch; text-align: right; line-height: 1; }
.spd .gear { font-size: 3.4cqw; width: auto; margin-left: auto; color: #facc15; }
.rpm { height: .9cqw; background: #444441; border-radius: .3cqw; margin: .8cqw 0 .4cqw; overflow: hidden; }
.rpm i { display: block; height: 100%; width: 0; background: #ef9f27; transition: width .2s linear; }
.rpm i.red { background: #ef4444; }
.hud-bc { left: 50%; bottom: 1.6cqw; transform: translateX(-50%); width: 22cqw; text-align: center; }
.hud-bc b { display: block; font-size: 5cqw; line-height: 1.05; }
.delta { display: inline-block; min-width: 9cqw; margin-top: .4cqw; padding: 0 1.2cqw; border-radius: .5cqw; font-size: 2.6cqw; font-weight: 700; }
.delta.green { background: #3b6d11; } .delta.red { background: #a32d2d; } .delta:empty { visibility: hidden; }
.hud-br { right: 1.6cqw; bottom: 1.6cqw; width: 19cqw; }
.hud-br div { display: flex; justify-content: space-between; align-items: baseline; }
/* крупное видео: делит панель с картой — видео сверху, схема трассы ниже, ничего не перекрывается */
.map-wrap.split { display: flex; flex-direction: column; }
.map-wrap.split .video-box { position: relative; inset: auto; flex: none; align-self: center; width: calc(100% - 24px);
  max-width: calc((100vh - 52px - 24px) * 0.6 * 16 / 9); margin-top: 12px; }
.map-wrap.split #map { position: relative; inset: auto; flex: 1; min-height: 0; }
/* маленькое окно: только главное — скорость, время круга, дельта, секторы */
@container (max-width: 400px) {
  .hud { font-size: 11px; }
  .hud small { font-size: 10px; }
  .hud-br, #hudRpm, .hud-tr small, .hud-tl .live { display: none; }
  .hud-tl { font-size: 11px; }
  .hud-tl button { font-size: 13px; }
  .hud-bl { width: auto; } .spd b { font-size: 22px; } .spd .gear { font-size: 14px; }
  .hud-bc { width: auto; min-width: 70px; } .hud-bc b { font-size: 18px; } .delta { font-size: 11px; min-width: 40px; }
  .secs i { width: 18px; height: 4px; }
}
.hud-br .warn { color: #facc15; } .hud-br .crit { color: #ff6b6b; }
.video-state { position: absolute; left: 0; right: 0; top: 50%; text-align: center; color: #ddd; font-size: 13px; pointer-events: none; }
.card.has-video { cursor: pointer; }
.card.watching { box-shadow: 0 0 0 2px var(--c); }
.cam { margin-left: 6px; font-size: 13px; }

