/* Power Tech GPS — shared styles.
   Mobile-first: the Optimus UI being unusable on a phone is a founding reason for this
   project, so every layout rule here starts at phone width and widens from there. */

:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #21252e;
  --line: #2c313c;
  --text: #e8ebf0;
  --muted: #98a1b0;
  --accent: #3b82f6;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 10px;
  /* Respected by the map panel so it never sits under an iPhone's home indicator. */
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Stops iOS Safari bouncing the whole page when you drag on the map. */
  overscroll-behavior: none;
}

a { color: var(--accent); }

/* ---------------------------------------------------------------- app shell */

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh; /* dvh, not vh: vh is wrong while mobile browser chrome is showing */
}

header.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

header.bar .brand {
  font-weight: 600;
  letter-spacing: 0.2px;
  margin-right: auto;
  font-size: 15px;
}

nav.tabs { display: flex; gap: 4px; }

nav.tabs a {
  padding: 6px 11px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}
nav.tabs a:hover { background: var(--panel-2); color: var(--text); }
nav.tabs a.active { background: var(--accent); color: #fff; }

main { flex: 1 1 auto; position: relative; min-height: 0; }

/* ---------------------------------------------------------------- map */

#map { position: absolute; inset: 0; background: #11141a; }

/* Truck filter. On a phone it is a bottom sheet that slides up, because a side panel
   would eat half a small screen; from 720px it becomes a floating side panel. */
#filter {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 55%;
  background: var(--panel);
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(calc(100% - 46px));
  transition: transform 0.22s ease;
  padding-bottom: var(--safe-b);
  z-index: 5;
}
#filter.open { transform: translateY(0); }

#filter .handle {
  height: 46px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  cursor: pointer;
  user-select: none;
  flex: 0 0 auto;
}
#filter .handle strong { font-size: 14px; }
#filter .handle .count { color: var(--muted); font-size: 13px; margin-left: auto; }

#filter .body { overflow-y: auto; padding: 4px 10px 12px; }

.truck-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.truck-row:hover { background: var(--panel-2); }
.truck-row.off { opacity: 0.4; }

.swatch {
  width: 14px; height: 14px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 2px solid rgba(255,255,255,0.75);
}

.truck-row .name { font-weight: 500; }
.truck-row .meta { margin-left: auto; color: var(--muted); font-size: 12px; text-align: right; }
.truck-row .meta .stale { color: #f59e0b; }

.filter-actions {
  display: flex; gap: 8px; padding: 6px 8px 0;
}
.filter-actions button {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  font-size: 13px;
  cursor: pointer;
}
.filter-actions button:hover { border-color: var(--accent); }

/* ---------------------------------------------------------------- map markers

   Drawn as HTML through a custom OverlayView rather than Google's AdvancedMarkerElement,
   which would require a cloud-configured Map ID -- one more thing to set up in Google
   Cloud, and one more thing to break. HTML markers also give us real CSS animation for
   the sonar pulse, which a canvas marker icon cannot do. */

.truck-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  /* none on the wrapper so its empty box never swallows a map drag; the dot and label
     opt back in below. */
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.truck-dot, .truck-label { pointer-events: auto; cursor: pointer; }

/* Muted by focus mode. Kept clickable on purpose -- tapping a dimmed truck should move
   focus to it rather than requiring a trip back through empty map first. */
.truck-marker.muted { opacity: 0.22; }
/* A dozen sonar rings pulsing behind the truck you are actually reading defeats the
   point of focusing. */
.truck-marker.muted .truck-dot::after { animation: none; opacity: 0; }

.truck-dot {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.6);
  position: relative;
  z-index: 2;
}

/* Invisible touch target. The dot is 15px, well under the ~44px a fingertip needs, so
   without this the focus tap is a game of chance on a phone. */
.truck-dot::before {
  content: "";
  position: absolute;
  inset: -14px;
  border-radius: 50%;
}

/* The sonar ping. Sized from the dot and coloured by an inline custom property so each
   truck pulses in its own colour. */
.truck-dot::after {
  content: "";
  position: absolute;
  inset: -2.5px;
  border-radius: 50%;
  border: 2px solid var(--pulse, #fff);
  animation: sonar 2.1s ease-out infinite;
}

@keyframes sonar {
  0%   { transform: scale(1);   opacity: 0.85; }
  70%  { transform: scale(3.4); opacity: 0; }
  100% { transform: scale(3.4); opacity: 0; }
}

/* Motion is decorative here; a dozen of these pulsing is exactly the kind of thing that
   triggers vestibular discomfort, and the dot is still perfectly readable without it. */
@media (prefers-reduced-motion: reduce) {
  .truck-dot::after { animation: none; opacity: 0.5; }
}

.truck-label {
  margin-top: 3px;
  background: rgba(15,17,21,0.88);
  color: #fff;
  font-size: 11.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  white-space: nowrap;
  border: 1px solid rgba(255,255,255,0.16);
}

.truck-label .mph { color: var(--muted); font-weight: 400; }

/* Stop markers */
.stop-marker {
  position: absolute;
  transform: translate(-50%, -50%);
  pointer-events: auto;
  cursor: pointer;
}
.stop-pin {
  width: 12px; height: 12px;
  border-radius: 3px;
  background: #fff;
  border: 3px solid var(--pin, #888);
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

/* Automatic duration chip. Hidden until the map container gains .zoom-detail, because
   at city zoom a dozen of these overlap into an unreadable pile. Offset to the right of
   the pin so it does not cover the spot the pin is marking. */
.stop-duration {
  display: none;
  position: absolute;
  left: 15px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  color: #111;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 5px;
  white-space: nowrap;
  border: 1.5px solid var(--pin, #888);
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
  pointer-events: none;
}
#map.zoom-detail .stop-duration { display: block; }

/* Hover / tap detail. Sits above the pin so it never covers the chip. */
.stop-bubble {
  position: absolute;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: rgba(15,17,21,0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 11.5px;
  line-height: 1.5;
  white-space: nowrap;
  display: none;
  z-index: 10;
  box-shadow: 0 3px 12px rgba(0,0,0,0.5);
}
.stop-marker:hover .stop-bubble,
.stop-marker.show .stop-bubble { display: block; }

/* Muted stops drop out of the pointer layer entirely -- a dimmed stop from another
   truck should not steal a hover from the one being read. */
.stop-marker { transition: opacity 0.18s ease; }
.stop-marker.muted { opacity: 0.18; pointer-events: none; }
.stop-bubble .t { font-weight: 700; }
.stop-bubble .eng { color: var(--muted); }

/* ---------------------------------------------------------------- forms, login */

.center-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
}

.card h1 { margin: 0 0 4px; font-size: 19px; }
.card p.sub { margin: 0 0 18px; color: var(--muted); font-size: 13.5px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

input[type=email], input[type=text], input[type=date] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--text);
  padding: 11px 12px;
  /* 16px minimum: anything smaller makes iOS Safari zoom the page on focus. */
  font-size: 16px;
}
input:focus { outline: none; border-color: var(--accent); }

input.code {
  letter-spacing: 7px;
  text-align: center;
  font-size: 22px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

button.primary {
  width: 100%;
  margin-top: 14px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 9px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.55; cursor: default; }

.msg { margin-top: 12px; font-size: 13.5px; min-height: 18px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

.linkish {
  background: none; border: 0; color: var(--accent);
  font-size: 13px; cursor: pointer; padding: 0; margin-top: 12px;
}

/* ---------------------------------------------------------------- tables / settings */

.page { padding: 16px; max-width: 900px; margin: 0 auto; overflow-y: auto; height: 100%; }
.page h2 { font-size: 17px; margin: 0 0 4px; }
.page p.hint { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.setting-row .orig { color: var(--muted); font-size: 12px; }
.setting-row input[type=text] { flex: 1 1 150px; min-width: 130px; font-size: 15px; padding: 8px 10px; }
.setting-row input[type=color] {
  width: 42px; height: 34px; padding: 0;
  background: none; border: 1px solid var(--line); border-radius: 7px; cursor: pointer;
}
.setting-row button {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; cursor: pointer; font-size: 13px;
}
.setting-row button.save { background: var(--accent); border-color: var(--accent); color: #fff; }

.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.toolbar input[type=date] { width: auto; }

.empty { color: var(--muted); padding: 24px; text-align: center; }
