/*
 * The look comes from the road: a highway-sign green, a route-blue line, and one very
 * large number, the speed, set in Barlow, a face drawn from highway signage.
 * Status always carries words and a shape, never colour alone.
 */
@font-face { font-family: "Barlow"; font-weight: 400; font-display: swap; src: url("/fonts/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 500; font-display: swap; src: url("/fonts/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-weight: 600; font-display: swap; src: url("/fonts/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 600; font-display: swap; src: url("/fonts/barlow-condensed-latin-600-normal.woff2") format("woff2"); }

:root {
  color-scheme: light;
  --ink: #12211b;
  --ink-2: #4a5a54;
  --line: #dde3df;
  --edge: #7f8d87;
  --surface: #ffffff;
  --wash: #f2f5f3;
  --sign: #0b5d45;
  --sign-dark: #084534;
  --route: #1e5bd6;

  --ok: #0c6b43;
  --ok-wash: #e3f4eb;
  --warn: #7a5200;
  --warn-wash: #fff2d1;
  --warn-mark: #e9a100;
  --bad: #ad231c;
  --bad-wash: #fde9e7;
  --off: #47535c;
  --off-wash: #e9edef;

  --panel-w: 372px;
  --target: 44px;
  --radius-panel: 14px;
  --radius-control: 8px;
  --shadow: 0 1px 2px rgb(18 33 27 / 0.2), 0 6px 20px rgb(18 33 27 / 0.14);
  font-family: "Barlow", "Noto Sans Tamil", system-ui, -apple-system, "Segoe UI", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; color: var(--ink); background: var(--wash); line-height: 1.4; }
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--route); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.muted { color: var(--ink-2); }

/* Map --------------------------------------------------------------------- */
.map { position: fixed; inset: 0; background: #e8ece9; }

.vehicle { width: 48px; height: 48px; filter: drop-shadow(0 2px 3px rgb(18 33 27 / 0.45)); }
.vehicle svg { display: block; }
.vehicle__disc { fill: var(--sign); stroke: #fff; stroke-width: 3; }
.vehicle__arrow { fill: #fff; }
.vehicle[data-level="warn"] .vehicle__disc { fill: #a56f00; }
.vehicle[data-level="bad"] .vehicle__disc { fill: var(--bad); }
.vehicle[data-level="off"] .vehicle__disc { fill: var(--off); }

.other-vehicle {
  min-height: 32px;
  padding: 0 10px;
  background: var(--surface);
  border: 2px solid var(--off);
  border-radius: 16px;
  box-shadow: var(--shadow);
  font-size: 0.875rem;
  font-weight: 600;
}
.other-vehicle[data-level="ok"] { border-color: var(--ok); }
.other-vehicle[data-level="warn"] { border-color: var(--warn-mark); }
.other-vehicle[data-level="bad"] { border-color: var(--bad); }

.map-buttons { position: fixed; top: 12px; right: 12px; z-index: 5; display: flex; gap: 8px; }
.map-button {
  min-height: var(--target);
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow);
  font-weight: 600;
}
.map-button:hover { background: var(--wash); }
.map-button[aria-pressed="true"] { background: var(--sign); border-color: var(--sign); color: #fff; }

.map-warning {
  position: fixed;
  top: 68px;
  right: 12px;
  z-index: 5;
  max-width: 320px;
  padding: 8px 12px;
  background: var(--warn-wash);
  border-radius: var(--radius-control);
  box-shadow: var(--shadow);
  color: var(--warn);
  font-size: 0.875rem;
}

/* Panel ------------------------------------------------------------------- */
.panel {
  position: fixed;
  top: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 6;
  display: flex;
  flex-direction: column;
  width: var(--panel-w);
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow);
}
.panel__grip { display: none; }
.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px 8px 16px;
}
.vehicle-select {
  flex: 1;
  min-width: 0;
  min-height: var(--target);
  padding: 0 8px;
  background: var(--wash);
  border: 1px solid var(--edge);
  border-radius: var(--radius-control);
  font-weight: 600;
}
.text-button {
  min-height: var(--target);
  padding: 0 6px;
  background: none;
  border: 0;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.panel__more { display: flex; flex-direction: column; flex: 1; padding: 0 16px 12px; }
.panel__note { margin-top: auto; padding-top: 16px; color: var(--ink-2); font-size: 0.8125rem; }

.page-offline {
  margin: 0 16px 8px;
  padding: 8px 12px;
  background: var(--off-wash);
  border-radius: var(--radius-control);
  font-size: 0.875rem;
}

/* The status reason is what this page exists to say. */
.status {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 10px;
  margin: 0 16px;
  padding: 12px;
  border-radius: 10px;
  background: var(--off-wash);
}
.status h1 { font-size: 1.125rem; font-weight: 600; line-height: 1.25; }
.status p { font-size: 0.9375rem; }
.status .text-button { min-height: 32px; padding: 0; font-weight: 500; }
.status__mark { width: 16px; height: 16px; margin-top: 4px; background: var(--off); border-radius: 50%; }
.status__notice { margin-top: 8px; padding-top: 8px; border-top: 1px solid rgb(18 33 27 / 0.18); font-weight: 500; }

.status[data-level="ok"] { background: var(--ok-wash); }
.status[data-level="ok"] .status__mark { background: var(--ok); }
.status[data-level="warn"] { background: var(--warn-wash); }
.status[data-level="warn"] .status__mark { background: var(--warn-mark); border-radius: 2px; transform: rotate(45deg) scale(0.9); }
.status[data-level="bad"] { background: var(--bad-wash); }
.status[data-level="bad"] .status__mark { background: var(--bad); border-radius: 2px; }
.status[data-level="off"] .status__mark { background: transparent; border: 3px solid var(--off); }

.speed { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 10px 16px 12px; }
.speed__figure { display: flex; align-items: baseline; gap: 6px; }
.speed output {
  font-family: "Barlow Condensed", "Barlow", sans-serif;
  font-size: 6rem;
  font-weight: 600;
  line-height: 0.92;
  letter-spacing: -0.01em;
}
.speed__figure span { color: var(--ink-2); font-size: 1.125rem; font-weight: 500; }
.speed__figure { min-height: 88px; }
.speed[data-fresh="false"] output { color: var(--edge); font-family: "Barlow", sans-serif; font-size: 3.25rem; font-weight: 400; }

.facts { display: grid; gap: 2px; min-width: 130px; font-size: 0.875rem; }
.facts div { display: flex; justify-content: space-between; gap: 10px; }
.facts dt { color: var(--ink-2); }
.facts dd { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.tabs { display: flex; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1;
  min-height: var(--target);
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--ink-2);
  font-weight: 600;
}
.tabs button[aria-selected="true"] { border-bottom-color: var(--sign); color: var(--ink); }

.panel h2 { margin: 16px 0 6px; font-size: 0.9375rem; font-weight: 600; }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.summary dt { color: var(--ink-2); font-size: 0.8125rem; }
.summary dd {
  font-family: "Barlow Condensed", "Barlow", sans-serif;
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.15;
}

.timeline { display: flex; flex-direction: column; font-size: 0.9375rem; }
.timeline li {
  position: relative;
  display: grid;
  grid-template-columns: 4.6rem minmax(0, 1fr);
  gap: 8px;
  padding: 5px 0 5px 14px;
}
.timeline li::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 0;
  width: 8px;
  height: 8px;
  background: var(--off);
  border-radius: 50%;
}
.timeline li[data-level="ok"]::before { background: var(--ok); }
.timeline li[data-level="warn"]::before { background: var(--warn-mark); }
.timeline li[data-level="bad"]::before { background: var(--bad); }
.timeline li.muted { padding-left: 0; display: block; }
.timeline li.muted::before { display: none; }
.timeline time { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* History ------------------------------------------------------------------- */
.date-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-weight: 500; }
.date-row input {
  flex: 1;
  min-height: var(--target);
  padding: 0 8px;
  background: var(--wash);
  border: 1px solid var(--edge);
  border-radius: var(--radius-control);
}
.day-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  min-height: 36px;
  padding: 0 12px;
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: 18px;
  font-size: 0.875rem;
  font-weight: 500;
}
.chip:hover { border-color: var(--edge); }

.replay { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 10px; margin-top: 14px; }
.round-button {
  min-width: 72px;
  min-height: var(--target);
  background: var(--sign);
  border: 0;
  border-radius: var(--radius-control);
  color: #fff;
  font-weight: 600;
}
.round-button:hover { background: var(--sign-dark); }
.replay__track input { display: block; width: 100%; height: 28px; margin: 0; accent-color: var(--route); }
.replay__now { font-size: 0.875rem; color: var(--ink-2); }
.replay__now strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.replay select {
  min-height: var(--target);
  padding: 0 4px;
  background: var(--wash);
  border: 1px solid var(--edge);
  border-radius: var(--radius-control);
}

.stops button {
  width: 100%;
  min-height: var(--target);
  padding: 0;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
.stops button:hover { color: var(--route); }

/* Phone: the panel is a bottom sheet, and the map keeps the top of the screen. */
@media (max-width: 760px) {
  .panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: auto;
    max-height: 78dvh;
    border-radius: var(--radius-panel) var(--radius-panel) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel__grip {
    display: block;
    flex: none;
    width: 100%;
    height: 24px;
    padding: 0;
    background: none;
    border: 0;
  }
  .panel__grip::before {
    content: "";
    display: block;
    width: 44px;
    height: 5px;
    margin: 0 auto;
    background: var(--edge);
    border-radius: 3px;
  }
  .panel__head { padding: 0 12px 6px 16px; }
  .panel__more { display: none; }
  .panel.is-open .panel__more { display: flex; }
  .speed { padding-block: 6px 10px; }
  .speed__figure { min-height: 66px; }
  .speed output { font-size: 4.5rem; }
  .speed[data-fresh="false"] output { font-size: 2.5rem; }
  .status { padding: 10px 12px; }
  .status p { font-size: 0.875rem; }
  /* The map credit sits in the top-left corner on a phone. Keep the buttons clear of it. */
  .map-buttons { top: 48px; }
  .map-warning { top: 104px; left: 12px; right: 12px; max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Sign in: a highway sign ------------------------------------------------------ */
.login-page {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: 16px;
  overflow: auto;
  background: var(--wash);
}
.sign { width: 100%; max-width: 400px; padding: 8px; background: var(--sign); border-radius: 18px; box-shadow: var(--shadow); }
.sign__border { padding: 24px; border: 3px solid #fff; border-radius: 12px; color: #fff; }
.sign h1 {
  margin-bottom: 20px;
  font-family: "Barlow Condensed", "Barlow", sans-serif;
  font-size: 2.75rem;
  font-weight: 600;
  line-height: 1;
}
.sign label { display: block; margin: 12px 0 4px; font-weight: 500; }
.sign input {
  width: 100%;
  min-height: var(--target);
  padding: 0 12px;
  background: #fff;
  border: 0;
  border-radius: var(--radius-control);
  color: var(--ink);
}
.sign button {
  width: 100%;
  min-height: var(--target);
  margin-top: 20px;
  background: #fff;
  border: 0;
  border-radius: var(--radius-control);
  color: var(--sign-dark);
  font-weight: 600;
}
.sign button:disabled { opacity: 0.7; }
.sign :focus-visible { outline-color: #fff; }
.sign__error { padding: 8px 12px; background: var(--bad-wash); border-radius: var(--radius-control); color: var(--bad); font-weight: 500; }
