:root {
  --bg: #16191d;
  --panel: #1e2227;
  --panel-2: #252a31;
  --border: #30363d;
  --text: #e6e9ec;
  --muted: #9aa4ae;
  --accent: #7fd1c4;
  --accent-bg: rgba(127, 209, 196, 0.12);
  --accent-border: rgba(127, 209, 196, 0.55);
  --warn: #f7c948;
  --pothole: #ff5a5f;
  --longitudinal: #ffb703;
  --transverse: #4cc9f0;
  --alligator: #c77dff;
  --radius: 3px;
  --font: "Segoe UI", Inter, Roboto, Arial, sans-serif;
  --mono: Consolas, "Cascadia Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 14px;
  cursor: pointer;
}

button:hover { border-color: var(--accent-border); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.active { background: var(--accent-bg); border-color: var(--accent-border); color: var(--accent); }
button.primary { background: var(--accent); color: #0f1a18; border-color: var(--accent); font-weight: 600; }

.app {
  display: grid;
  grid-template-rows: 64px 40px 1fr 36px;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.logo {
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 1px;
  background: var(--panel-2);
}

.brand h1 {
  margin: 0;
  font-size: 15px;
  letter-spacing: 3px;
  font-weight: 600;
}

.brand p { margin: 0; color: var(--muted); font-size: 13px; }

.muni { margin-left: 18px; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.muni select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; }

.steps { margin-left: auto; display: flex; gap: 8px; }
.steps button { display: flex; gap: 8px; align-items: center; }

.subbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 13px;
}

.subbar strong { color: var(--text); font-weight: 500; }
/* What to click on the open screen, after its name (HINT in app.js) */
.subbar .hint { margin-left: 12px; color: var(--accent); }
/* The note on the right gives way to the hint when the bar is short of
   room: it is cut short with "..." (hovering shows the whole note) */
#sub-left { flex-shrink: 0; }
#sub-right { min-width: 0; margin-left: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { display: grid; min-height: 0; }

.screen { display: none; min-height: 0; }
.screen.active { display: grid; grid-template-columns: 290px 1fr 340px; min-height: 0; height: 100%; }

.side, .detail {
  background: var(--panel);
  overflow: auto;
  padding: 14px;
  min-height: 0;
}

.side { border-right: 1px solid var(--border); }
.detail { border-left: 1px solid var(--border); }

.center { position: relative; min-width: 0; min-height: 0; overflow: auto; padding: 14px; }
.center.flush { padding: 0; overflow: hidden; }

h2 {
  margin: 0 0 10px 0;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

h2 .count { color: var(--muted); font-weight: 400; font-family: var(--mono); font-size: 12px; }
h3 { margin: 14px 0 6px 0; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }

.list { display: flex; flex-direction: column; gap: 6px; }

.item {
  text-align: left;
  display: grid;
  grid-template-columns: 1fr auto;     /* the name and details, then a value */
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  background: transparent;
}

.item .label { font-weight: 500; }
.item .sub { color: var(--muted); font-size: 12px; }
.item .value { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.note { color: var(--muted); font-size: 12px; margin-top: 12px; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; text-align: right; font-weight: 500; }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
}

.tag.accent { color: var(--accent); border-color: var(--accent-border); background: var(--accent-bg); }
.tag.warn { color: var(--warn); border-color: rgba(247, 201, 72, 0.5); }

.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.viewport {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
}

/* The picture is as large as the column and the window height allow, at
   its own 4:3 shape. The width is set on the box around it, so the space
   is kept while each picture loads. */
.viewport { width: min(100%, calc((100vh - 290px) * 4 / 3)); }
.viewport img { display: block; width: 100%; height: auto; transition: opacity 140ms ease-out; }
.center.dashcam { text-align: center; }
.center.dashcam .player { text-align: left; }

#boxes { position: absolute; left: 0; top: 0; right: 0; bottom: 0; pointer-events: none; }

.leaflet-container { background: #0f1215; font: 12px var(--font); }
.leaflet-tile-pane { filter: brightness(0.62) saturate(0.55); }
.leaflet-container .leaflet-control-attribution { background: rgba(14, 17, 20, 0.8); color: var(--muted); }
.leaflet-container .leaflet-control-attribution a { color: var(--accent); }

.box {
  position: absolute;
  border: 3px solid;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6);
}

.box span {
  position: absolute;
  left: -3px;
  top: -24px;
  padding: 1px 6px;
  font: 600 12px/18px var(--font);
  color: #0f1113;
  border-radius: 3px;
  white-space: nowrap;
}

.chip {
  position: absolute;
  padding: 6px 10px;
  background: rgba(14, 17, 20, 0.82);
  border-radius: 2px;
  font: 13px/1.3 var(--mono);
  color: var(--text);
}

.chip.tl { left: 12px; top: 12px; }
.chip.tr { right: 12px; top: 12px; }
.chip.bl { left: 12px; bottom: 12px; }
.chip.br { right: 12px; bottom: 12px; }
.chip.faded { background: rgba(214, 40, 40, 0.88); }

.player { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.player input[type=range] { flex: 1; min-width: 200px; accent-color: var(--accent); }

.counters { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; font-size: 13px; }
.counters .n { font-family: var(--mono); text-align: right; }

#map, #crew-map { width: 100%; height: 100%; background: #0f1215; }
#crew-map { height: 280px; border-radius: var(--radius); border: 1px solid var(--border); }

.legend { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.legend-title { margin-top: 6px; font-weight: 600; }
.swatch { display: inline-block; width: 22px; height: 6px; border-radius: 3px; margin-right: 8px; vertical-align: middle; }
.swatch.thin { height: 3px; }
.kv a, .note a, .record a { color: var(--accent); text-decoration: none; }
.kv a:hover, .note a:hover, .record a:hover { text-decoration: underline; }
.record { border-top: 1px solid var(--border); padding: 8px 0; font-size: 13px; }
.record p { margin: 4px 0; }
.record-head { display: flex; gap: 8px; align-items: center; }
.record .sub { color: var(--muted); font-size: 12px; }
#history-detail h4, #block-detail h4 { margin: 0 0 8px 0; font-size: 14px; }
.swatch.dashed { background: repeating-linear-gradient(90deg, #7a8794 0 5px, transparent 5px 9px); }

.map-overlay {
  position: absolute;
  z-index: 800;
  background: rgba(14, 17, 20, 0.86);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 8px 12px;
  font-size: 13px;
}

.map-overlay.tr { right: 12px; top: 12px; }
.map-overlay.bl { left: 12px; bottom: 12px; }

.vehicle-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
}

.vehicle-icon div {
  width: 0;
  height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-bottom: 22px solid var(--accent);
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.9));
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; }
td.num, th.num { text-align: right; font-family: var(--mono); }
tr.selectable { cursor: pointer; }
tr.selectable:hover td { background: rgba(255, 255, 255, 0.03); }
tr.selectable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tr.selected td { background: var(--accent-bg); }

.bars { display: grid; grid-template-columns: 220px 1fr 60px; gap: 8px 12px; align-items: center; font-size: 13px; margin-top: 14px; }
.bar { height: 12px; background: transparent; border: 1px solid var(--border); border-left: 2px solid var(--muted); overflow: hidden; }
.bar div { height: 100%; }

.axis { display: flex; justify-content: space-between; font: 11px var(--mono); color: var(--muted); border-top: 1px solid var(--border); padding-top: 4px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.card h2 { margin-bottom: 8px; }

.board { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-top: 14px; }
.day { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.day h4 { margin: 0 0 8px 0; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }
.job { font-size: 12px; padding: 6px 8px; border-radius: 2px; background: var(--panel-2); margin-bottom: 6px; border-left: 3px solid var(--accent); }
.job.crack { border-left-color: var(--longitudinal); }
.job .idx { font-family: var(--mono); color: var(--muted); }

.statusbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
}

.statusbar span { overflow: hidden; text-overflow: ellipsis; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--accent-border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  display: none;
  z-index: 2000;
}

.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

[hidden] { display: none !important; }
.frame-empty { display: flex; align-items: center; justify-content: center; width: 640px; max-width: 100%; height: 360px; padding: 24px; color: var(--muted); font-size: 14px; }
.map-overlay.mid { left: 50%; top: 50%; transform: translate(-50%, -50%); }
td.empty { color: var(--muted); }
.bars .note { grid-column: 1 / -1; margin-top: 0; }
#status-right.error { color: var(--warn); }

/* ---------------------------------------------------------------------------
   WEBSITE ADDITIONS (Peoria trial page)
   - The dashboard stays hidden until app.js has filled it in.
   - The logo square shows the Itsgraded sign.
   - The municipality is fixed to Peoria, so it shows as text.
   - Phones: smaller labels on the dashcam picture.
   - Narrower windows (tablets and phones): the three columns stack, the
     maps get a fixed height and the page scrolls. The website's frame
     grows to the full height (assets/js/peoria-trial.js), so nothing here
     may depend on the window height.
   --------------------------------------------------------------------------- */
/* Hidden until app.js has filled every screen (it adds .ready), so the
   page never shows a half-filled dashboard that then jumps */
.app:not(.ready) { visibility: hidden; }
.logo { padding: 0; overflow: hidden; }
.logo img { display: block; width: 30px; height: 30px; }
.muni strong { color: var(--text); font-weight: 500; }

@media (max-width: 1100px) {
  html, body { height: auto; }
  .app { display: block; height: auto; }
  .topbar { flex-wrap: wrap; padding: 10px 14px; }
  .muni { margin-left: 0; }
  .steps { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .subbar { flex-wrap: wrap; gap: 4px 12px; padding: 8px 14px; }
  /* narrower screens: the bar's words wrap onto more lines instead */
  #sub-left { flex-shrink: 1; }
  #sub-right { margin-left: 0; white-space: normal; }
  /* min-width: 0 keeps each screen to the window's width; without it a
     wide table (Material reports, Repair coordinator) stretched the whole
     screen and the page scrolled sideways on phones */
  .screen.active { display: flex; flex-direction: column; height: auto; min-width: 0; }
  /* A table wider than the window scrolls sideways inside its own card */
  .card { min-width: 0; overflow-x: auto; }
  .side, .detail { border: 0; border-bottom: 1px solid var(--border); overflow: visible; }
  .center { overflow: visible; }
  .center.flush { height: 460px; }   /* a fixed height: the website grows the frame to fit, so screen-relative heights would keep growing */
  .viewport { width: 100%; }
  .board { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .statusbar { flex-wrap: wrap; gap: 4px 12px; height: auto; padding: 8px 14px; }
}

/* Phones: the dashcam picture is narrow, so the corner labels shrink and
   the position and source labels step aside (both are in the Selected
   frame list under the picture). Box labels shrink too. The bar charts
   (Material reports) get a narrower label column, so each bar and the
   scale under it keep room. */
@media (max-width: 700px) {
  .chip { padding: 3px 6px; font-size: 10px; }
  .chip.tl { left: 6px; top: 6px; }
  .chip.br { right: 6px; bottom: 6px; }
  .chip.tr, .chip.bl { display: none; }
  .box { border-width: 2px; }
  .box span { top: -17px; padding: 0 4px; font-size: 10px; line-height: 15px; }
  .bars { grid-template-columns: minmax(0, 34%) minmax(0, 1fr) 34px; gap: 8px 10px; }
  .axis { gap: 6px; }
}
