/* Curbline: road-sign blue, curb-paint yellow, asphalt gray. Barlow is a typeface
   drawn after North American highway signage, so it carries the street vernacular. */

:root {
  --bg: #eef1f3;
  --surface: #ffffff;
  --ink: #1d2328;
  --muted: #5b6670;
  --line: #d3d9de;
  --asphalt: #2b3034;
  --asphalt-ink: #e9edf0;
  --sign: #1f5aa6;
  --sign-ink: #ffffff;
  --curb: #f2c230;
  --ok: #2e7d4f;
  --ok-tint: #e3f1e8;
  --grace: #9a6b00;
  --grace-tint: #fbf1d0;
  --stop: #b3261e;
  --stop-tint: #f8e3e1;
  --stall-off: #c9d1d7;
  --plate-bg: #fbfbf8;
  --radius: 6px;
  --font: 'Barlow', system-ui, sans-serif;
  --font-sign: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #1c2125;
    --surface: #252b30;
    --ink: #e6eaed;
    --muted: #9aa5ae;
    --line: #39424a;
    --asphalt: #15191c;
    --sign: #4c86d4;
    --ok: #5cb37f;
    --ok-tint: #1f3328;
    --grace: #e0b44a;
    --grace-tint: #362d16;
    --stop: #ec6a60;
    --stop-tint: #3b2321;
    --stall-off: #3b454d;
    --plate-bg: #eceee8;
    color-scheme: dark;
  }
}
:root[data-theme='dark'] {
  --bg: #1c2125; --surface: #252b30; --ink: #e6eaed; --muted: #9aa5ae; --line: #39424a;
  --asphalt: #15191c; --sign: #4c86d4; --ok: #5cb37f; --ok-tint: #1f3328; --grace: #e0b44a;
  --grace-tint: #362d16; --stop: #ec6a60; --stop-tint: #3b2321; --stall-off: #3b454d; --plate-bg: #eceee8;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; width: 100%; max-width: 1120px; margin: 0 auto; padding: 28px 16px 48px; outline: none; }
h1, h2 { font-family: var(--font-sign); font-weight: 600; letter-spacing: 0.01em; margin: 0; }
h1 { font-size: 2.25rem; line-height: 1.1; }
h2 { font-size: 1.25rem; line-height: 1.2; }
a { color: var(--sign); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--curb); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--curb); color: #1d2328; padding: 6px 10px; z-index: 10; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- top bar: the curb ---------- */
.topbar {
  background: var(--asphalt);
  color: var(--asphalt-ink);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 16px;
  min-height: 60px;
  border-bottom: 6px solid var(--curb);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 32px; height: 32px; display: grid; place-items: center;
  background: var(--sign); color: #fff; border: 2px solid #fff; border-radius: 5px;
  font: 700 22px/1 var(--font-sign);
}
.brand-name { font: 700 1.5rem/1 var(--font-sign); letter-spacing: 0.02em; }
.tabs { display: flex; gap: 4px; flex: 1; align-self: stretch; }
.tabs a {
  color: inherit; text-decoration: none; padding: 0 12px; display: flex; align-items: center;
  font: 600 1.05rem/1 var(--font-sign); letter-spacing: 0.03em; opacity: 0.75;
  border-bottom: 4px solid transparent; margin-bottom: -6px;
}
.tabs a:hover { opacity: 1; }
.tabs a[aria-current='page'] { opacity: 1; border-bottom-color: var(--surface); }
.mode { margin: 0; font-size: 0.875rem; opacity: 0.8; }
.mode[data-mode]::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--curb); margin-right: 8px; }
.mode[data-mode='api']::before { background: #5cb37f; }

.view-head { margin-bottom: 20px; }
.sub { margin: 6px 0 0; color: var(--muted); }

/* ---------- totals ---------- */
.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 0 0 28px; }
.totals > div { background: var(--surface); padding: 14px 16px; }
.totals dt { color: var(--muted); font-size: 0.875rem; }
.totals dd { margin: 2px 0 0; font: 600 1.75rem/1.2 var(--font-sign); font-variant-numeric: tabular-nums; }
.totals small { display: block; font: 400 0.875rem/1.4 var(--font); color: var(--muted); }

/* ---------- lots: each one drawn as a row of painted stalls ---------- */
.lots { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.lot { display: grid; grid-template-columns: 48px 1fr auto; gap: 16px; align-items: center; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.lot-sign {
  width: 48px; height: 48px; display: grid; place-items: center;
  background: var(--sign); color: var(--sign-ink); border-radius: 5px; box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 3px var(--sign);
  font: 700 1.6rem/1 var(--font-sign);
}
.lot-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.lot-count { margin: 0; color: var(--muted); font-size: 0.9375rem; }
.lot-count strong { color: var(--ink); font-weight: 600; }
.lot-meta { margin: 6px 0 0; color: var(--muted); font-size: 0.875rem; }
.lot-pct { margin: 0; font: 600 2rem/1 var(--font-sign); font-variant-numeric: tabular-nums; min-width: 3.2ch; text-align: right; }
.stalls { display: grid; grid-template-columns: repeat(48, 1fr); gap: 2px; margin-top: 10px; height: 28px; border-bottom: 3px solid var(--curb); padding-bottom: 2px; }
.stalls i { background: transparent; border-left: 2px solid var(--stall-off); }
.stalls i:last-child { border-right: 2px solid var(--stall-off); }
.stalls i.on { background: var(--sign); border-left-color: var(--sign); border-radius: 2px 2px 0 0; }
.stalls[data-level='busy'] i.on { background: var(--grace); border-left-color: var(--grace); }
.stalls[data-level='full'] i.on { background: var(--stop); border-left-color: var(--stop); }

/* ---------- forms and buttons ---------- */
.field { display: grid; gap: 4px; font-size: 0.875rem; color: var(--muted); }
.field input, .field select, .field textarea {
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 10px; font-size: 1rem; min-width: 0;
}
.field.compact input, .field.compact select { padding: 6px 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius); padding: 8px 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--sign); border-color: var(--sign); color: #fff; }
.btn.stop { background: var(--stop); border-color: var(--stop); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 0.875rem; }

/* ---------- enforcement ---------- */
.enf-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.check-form .lot-select { max-width: 380px; }
.check-form { display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.plate-input { display: block; width: fit-content; max-width: 100%; position: relative; }
.plate-input-label { position: absolute; top: 6px; left: 0; right: 0; text-align: center; font: 600 0.75rem/1 var(--font-sign); letter-spacing: 0.2em; color: var(--sign); }
.plate-input input {
  width: 280px; max-width: 100%; height: 108px; padding: 18px 12px 6px; text-align: center;
  font: 700 3rem/1 var(--font-sign); letter-spacing: 0.08em; text-transform: uppercase;
  background: var(--plate-bg); color: #1d2328; border: 3px solid #1d2328; border-radius: 12px;
  box-shadow: inset 0 0 0 4px var(--plate-bg), inset 0 0 0 5px #9aa5ae;
}
.plate-input input::placeholder { color: #b7bfc5; }

.result:empty { display: none; }
.result { margin-top: 16px; }
.verdict { display: grid; grid-template-columns: auto 1fr; gap: 20px; background: var(--surface); border: 1px solid var(--line); border-left: 8px solid var(--muted); border-radius: var(--radius); padding: 18px; }
.verdict[data-result='valid'] { border-left-color: var(--ok); }
.verdict[data-result='grace'] { border-left-color: var(--curb); }
.verdict[data-result='violation'] { border-left-color: var(--stop); }
.verdict-body p { margin: 0 0 8px; }
.verdict-head { font: 700 1.75rem/1.1 var(--font-sign); }
.verdict[data-result='valid'] .verdict-head { color: var(--ok); }
.verdict[data-result='grace'] .verdict-head { color: var(--grace); }
.verdict[data-result='violation'] .verdict-head { color: var(--stop); }
.flag { background: var(--stop-tint); color: var(--stop); padding: 8px 10px; border-radius: var(--radius); font-weight: 600; }
.cite, .pay { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; margin-top: 12px; }

.plate {
  width: 214px; height: 96px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--plate-bg); color: #1d2328; border: 3px solid #1d2328; border-radius: 10px;
  box-shadow: inset 0 0 0 3px var(--plate-bg), inset 0 0 0 4px #9aa5ae;
}
.plate-top { font: 600 0.75rem/1 var(--font-sign); letter-spacing: 0.12em; color: var(--sign); max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plate-num { font: 700 2.1rem/1.05 var(--font-sign); letter-spacing: 0.04em; }
.mini-plate {
  display: inline-block; font: 600 0.95rem/1 var(--font-sign); letter-spacing: 0.06em; padding: 4px 6px;
  background: var(--plate-bg); color: #1d2328; border: 1.5px solid #1d2328; border-radius: 4px; white-space: nowrap;
}

.feed { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 0 6px; }
.feed h2 { padding: 0 16px 10px; border-bottom: 1px solid var(--line); }
.reads { list-style: none; margin: 0; padding: 0; max-height: 560px; overflow: auto; }
.reads li { border-bottom: 1px solid var(--line); }
.reads li:last-child { border-bottom: 0; }
.read {
  width: 100%; text-align: left; background: none; border: 0; padding: 10px 16px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 0 8px;
}
.read:hover { background: var(--bg); }
.read-plate { font: 600 1.1rem/1.2 var(--font-sign); letter-spacing: 0.06em; }
.read-where { grid-column: 1; color: var(--muted); font-size: 0.8125rem; }
.read-result { grid-row: 1 / span 2; grid-column: 2; align-self: center; font-size: 0.8125rem; font-weight: 600; }
.reads li[data-result='valid'] .read-result { color: var(--ok); }
.reads li[data-result='grace'] .read-result { color: var(--grace); }
.reads li[data-result='violation'] .read-result { color: var(--stop); }
.empty { color: var(--muted); padding: 16px; }

/* ---------- tables ---------- */
.filters { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); padding: 0; margin: 0; overflow: hidden; background: var(--surface); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; padding: 6px 12px; font-weight: 600; font-size: 0.9375rem; border-right: 1px solid var(--line); }
.seg label:last-child span { border-right: 0; }
.seg input:checked + span { background: var(--asphalt); color: var(--asphalt-ink); }
.seg input:focus-visible + span { outline: 3px solid var(--curb); outline-offset: -3px; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.grid { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
.grid th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.8125rem; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tr:last-child td { border-bottom: 0; }
.grid .nowrap { white-space: nowrap; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid .actions { white-space: nowrap; text-align: right; }
.grid .actions .btn + .btn { margin-left: 4px; }
.note { color: var(--muted); font-size: 0.8125rem; }
.status { font-size: 0.8125rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); white-space: nowrap; }
.status[data-status='open'] { background: var(--stop-tint); color: var(--stop); }
.status[data-status='appealed'] { background: var(--grace-tint); color: var(--grace); }
.status[data-status='paid'], .status[data-status='active'] { background: var(--ok-tint); color: var(--ok); }

.permit-form {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; align-items: end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 20px;
}
.zones { border: 0; padding: 0; margin: 0; }
.zones legend { padding: 0; margin-bottom: 4px; }
.zones div { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span { display: grid; place-items: center; width: 36px; height: 36px; border: 1px solid var(--line); border-radius: 5px; font: 700 1.1rem/1 var(--font-sign); color: var(--ink); }
.chip input:checked + span { background: var(--sign); border-color: var(--sign); color: #fff; }
.chip input:focus-visible + span { outline: 3px solid var(--curb); outline-offset: 2px; }

/* ---------- dialog, toast, footer ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(20 24 28 / 0.5); }
dialog h2 { margin-bottom: 6px; }
dialog p { margin: 0 0 12px; color: var(--muted); }
dialog textarea { width: 100%; resize: vertical; }
dialog .row { margin-top: 14px; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 140%); opacity: 0;
  background: var(--asphalt); color: var(--asphalt-ink); padding: 10px 16px; border-radius: var(--radius);
  border-left: 6px solid #5cb37f; transition: transform 0.2s ease, opacity 0.2s ease; max-width: calc(100vw - 32px); z-index: 20;
}
.toast[data-tone='bad'] { border-left-color: var(--stop); }
.toast.show { transform: translate(-50%, 0); opacity: 1; }
.load-error { background: var(--stop-tint); color: var(--stop); padding: 12px; border-radius: var(--radius); }
.foot { color: var(--muted); font-size: 0.875rem; text-align: center; padding: 20px 16px 28px; }
.foot p { margin: 0; }

@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

@media (max-width: 860px) {
  .totals { grid-template-columns: repeat(2, 1fr); }
  .enf-grid { grid-template-columns: 1fr; }
  .permit-form { grid-template-columns: 1fr 1fr; }
  .mode { width: 100%; padding-bottom: 8px; margin-top: -4px; }
  .tabs { order: 3; width: 100%; flex: none; overflow-x: auto; min-height: 44px; }
  .topbar { gap: 8px 16px; padding-top: 10px; }
}
@media (max-width: 540px) {
  h1 { font-size: 1.9rem; }
  .lot { grid-template-columns: 40px 1fr; }
  .lot-sign { width: 40px; height: 40px; font-size: 1.35rem; }
  .lot-pct { grid-column: 2; text-align: left; font-size: 1.4rem; margin-top: -6px; }
  .stalls { grid-template-columns: repeat(48, 1fr); gap: 1px; height: 22px; }
  .stalls i { border-left-width: 1px; }
  .verdict { grid-template-columns: 1fr; }
  .permit-form { grid-template-columns: 1fr; }
  .plate-input input { width: 100%; font-size: 2.5rem; }
  .tabs a { padding: 0 8px; font-size: 1rem; }
  .tabs { gap: 0; }
}
