:root {
  --bg: #f4f5f7; --card: #fff; --text: #1c1f24; --muted: #667085; --line: #e2e5ea;
  --accent: #2563eb; --ok: #15803d; --bad: #b42318; --warn: #b54708;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --card: #1b1e24; --text: #e7e9ec; --muted: #98a2b3; --line: #2c313a; --accent: #5b8cff;
          --ok: #4ade80; --bad: #f97066; --warn: #fdb022; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--card);
         border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; }
nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
nav a { padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
nav a.active { background: var(--accent); color: #fff; }
nav a.soon { color: var(--muted); cursor: default; }
.who { color: var(--muted); font-size: 13px; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
input, select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
                background: var(--bg); color: var(--text); width: 100%; }
input[type=checkbox] { width: auto; }
button { font: inherit; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line);
         background: var(--card); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.link { border: none; background: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 200px; }
.cam { border-top: 1px solid var(--line); padding: 12px 0; }
.cam:first-of-type { border-top: none; }
.result { font-size: 13px; margin-top: 6px; }
.ok { color: var(--ok); } .bad { color: var(--bad); } .warn { color: var(--warn); } .muted { color: var(--muted); }
.snap { max-width: 320px; width: 100%; border-radius: 6px; margin-top: 8px; display: block; cursor: zoom-in; }
#viewer { padding: 0; border: none; border-radius: 10px; background: var(--card); color: var(--text);
          width: min(96vw, 1280px); max-width: 96vw; max-height: 96vh; }
#viewer::backdrop { background: rgba(0, 0, 0, .75); }
.viewer-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 8px 8px 14px; }
#viewer-close { font-size: 20px; line-height: 1; padding: 8px 14px; }
#viewer-img { display: block; width: 100%; max-height: calc(96vh - 56px); object-fit: contain; background: #000;
              aspect-ratio: 16 / 9; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid currentColor; }
.actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; display: flex; gap: 8px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); font-size: 14px; }
.center { max-width: 360px; margin: 10vh auto; }
.note { font-size: 13px; color: var(--muted); margin: 4px 0 12px; }
.gatebtn { font-size: 18px; padding: 14px 20px; width: 100%; margin-top: 12px; }
#toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text);
         color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 10; max-width: 90vw; }
pre { white-space: pre-wrap; font-size: 12px; margin: 6px 0 0; }
.tablewrap { overflow-x: auto; }
.shot { color: var(--accent); cursor: zoom-in; font-size: 13px; }
.thumb { height: 36px; max-width: 160px; border-radius: 4px; display: block; background: #000; }
#jf > label { min-width: 140px; }
.pill.ok, .pill.bad, .pill.warn, .pill.muted { white-space: nowrap; }
/* status page: live camera frames with the latest recognition under each */
.camgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-bottom: 16px; }
.camgrid .card { margin-bottom: 0; }
.camcard { padding: 12px; }
.camhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.camhead .note { margin: 0; }
.camimg { position: relative; aspect-ratio: 16 / 9; background: #000; border-radius: 6px; overflow: hidden; }
.camimg img { width: 100%; height: 100%; object-fit: contain; display: block; cursor: zoom-in; }
.camimg .nolive-text { display: none; position: absolute; inset: 0; align-items: center; justify-content: center;
                       color: #98a2b3; font-size: 13px; text-align: center; padding: 12px; }
.camimg.nolive img { visibility: hidden; }
.camimg.nolive .nolive-text { display: flex; }
.caminfo { margin-top: 8px; min-height: 64px; }
.caminfo .note { margin: 4px 0; }
.fresh { border-left: 4px solid currentColor; padding: 4px 10px; }
.fresh > div:not(.bigplate) { color: var(--text); }
.bigplate { font-size: 24px; font-weight: 700; letter-spacing: 1px; }
tr.dim td { opacity: .6; }/* plate base */
#plate-dlg { padding: 0; border: none; border-radius: 10px; background: var(--card); color: var(--text); width: min(96vw, 720px); }
#plate-dlg::backdrop { background: rgba(0, 0, 0, .6); }
.pf-body { padding: 0 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.pf-body .actions { position: static; background: none; }
.rights { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 13px; color: var(--muted); }
.right { display: inline-block; font-size: 11px; padding: 1px 4px; margin-right: 2px; border-radius: 4px; border: 1px solid currentColor; }
.right.on { color: var(--ok); } .right.off { color: var(--muted); opacity: .45; text-decoration: line-through; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
.nowrap { white-space: nowrap; }
button.small { font-size: 12px; }
#pl-bar > label { min-width: 160px; }
/* ---------------------------------------------------------------- phones and small tablets */
.m-only { display: none; }
@media (max-width: 700px) {
  :root { font-size: 15px; }
  header { padding: 6px 10px; gap: 4px 10px; }
  .brand { font-size: 15px; }
  .who { margin-left: auto; font-size: 12px; }
  /* all tabs visible at once: 3 per row (admin: 2 rows, guard: 1 row), nothing to scroll sideways */
  nav { order: 3; flex: 1 0 100%; display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
  nav::-webkit-scrollbar { display: none; }
  nav a { white-space: nowrap; padding: 8px 4px; text-align: center; font-size: 15px; background: var(--bg); }
  nav a.active { background: var(--accent); }
  main { padding: 10px; }
  h1 { font-size: 18px; margin: 2px 0 10px; }
  h2 { font-size: 15px; }
  .card { padding: 12px; margin-bottom: 10px; border-radius: 8px; }
  input, select, textarea { font-size: 16px; }  /* iOS does not zoom into fields of 16 px and more */
  button { min-height: 40px; }
  button.link { min-height: 0; }
  .row > label { min-width: 100%; }
  #jf > label, #pl-bar > label { min-width: calc(50% - 4px); flex: 1 1 calc(50% - 4px); }
  #jf > button, #pl-bar > button { flex: 1 1 100%; }
  .grid, .camgrid { grid-template-columns: 1fr; gap: 10px; }
  .gatebtn { min-height: 52px; }
  .caminfo { min-height: 0; }
  .bigplate { font-size: 22px; }
  .m-only { display: inline; }
  th, td { padding: 6px 4px; }
  .tablewrap { margin: 0 -4px; }

  /* journal / latest recognitions: one card per event */
  table:has(tr.ev) thead, table:has(tr.pl) thead, table.users tr.hdr { display: none; }
  tr.ev { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  tr.ev td { border: none; padding: 1px 0; }
  tr.ev .e-time, tr.ev .e-cam { font-size: 12px; color: var(--muted); }
  tr.ev .e-conf { display: none; }  /* the card shows it next to the decision instead (.conf) */
  tr.ev .conf { font-size: 13px; color: var(--muted); margin-left: 6px; white-space: nowrap; }
  tr.ev .e-shot { grid-column: 2; grid-row: 1 / span 4; align-self: center; }
  tr.ev .e-shot .thumb { height: 44px; max-width: 120px; }

  /* plate base and search results: flowing cards */
  tr.pl, tr.hit { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  tr.pl td, tr.hit td { border: none; padding: 0; }
  tr.pl td:empty { display: none; }
  tr.pl .p-plate { font-size: 16px; }
  tr.pl .p-term { margin-left: auto; font-size: 13px; }
  tr.pl .p-grp, tr.pl .p-owner, tr.pl .p-car, tr.pl .p-note { font-size: 13px; color: var(--muted); }
  tr.pl .p-rights { flex-basis: 100%; }
  tr.hit td:nth-child(2), tr.hit td:nth-child(3) { font-size: 13px; color: var(--muted); }

  /* users: a block per user */
  table.users tr { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.users td { border: none; padding: 0; }
  table.users td[data-l]::before { content: attr(data-l); display: block; font-size: 12px; color: var(--muted); }
  table.users .u-login { flex-basis: 100%; }
  table.users .u-pw { flex-basis: 100%; display: flex; gap: 8px; }

  /* dialogs take the whole screen */
  #plate-dlg, #viewer { width: 100vw; max-width: 100vw; max-height: 100dvh; margin: 0; border-radius: 0; }
  #plate-dlg { height: 100dvh; }
  #viewer-img { max-height: calc(100dvh - 56px); }
  .rights { gap: 4px 12px; }
}
@media (max-width: 700px) { .actions:has(#jm) { position: static; } }
details.card > summary { cursor: pointer; }
details.card[open] > summary { margin-bottom: 10px; }
@media (max-width: 700px) { tr.pl .p-rights { order: 2; } tr.pl .p-term { order: 1; } }

/* server load meters: categorical slots 1-3 of the validated default palette, fixed order */
:root { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; }
@media (prefers-color-scheme: dark) { :root { --s1: #3987e5; --s2: #d95926; --s3: #199e70; } }
.srv-row { margin-bottom: 10px; }
.srv-k { font-size: 13px; color: var(--muted); }
.srv-v { margin: 2px 0 4px; }
.meter { display: flex; gap: 2px; height: 12px; border-radius: 4px; overflow: hidden; }
.meter .seg { border-radius: 4px; min-width: 3px; }
.meter .seg.s1 { background: var(--s1); } .meter .seg.s2 { background: var(--s2); } .meter .seg.s3 { background: var(--s3); }
.meter .seg.free { flex: 1 1 0; background: var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 2px 0 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.legend i.s1 { background: var(--s1); } .legend i.s2 { background: var(--s2); } .legend i.s3 { background: var(--s3); }
.legend i.sfree { background: var(--line); }
table.toplist td, table.toplist th { padding: 4px 6px; font-size: 13px; }
td.num, th.num { text-align: right; white-space: nowrap; }
/* no sideways scrolling and no double-tap zoom on phones */
html, body { overflow-x: hidden; max-width: 100%; }
html, body { touch-action: pan-x pan-y; }
body { -webkit-text-size-adjust: 100%; }
.note.later { color: var(--warn); margin: 2px 0; }
