/*
 * In-car styling.
 *
 * Tuned for a Tesla centre screen: bright cabin, glare, gloved hands, and a
 * driver or passenger glancing rather than reading. Hence the large hit targets
 * (44px floor, 56px for anything consequential), heavy weights, and a dark
 * palette that matches Tesla's own UI so the app does not flash white.
 */

:root {
  --bg: #16181c;
  --surface: #22262d;
  --surface-2: #2c313a;
  --line: #3a4049;
  --text: #f2f4f7;
  --muted: #9aa4b2;

  --todo: #f5a524;       /* amber  - to collect */
  --done: #2fbf71;       /* green  - collected */
  --absent: #e8833a;     /* orange - not in field */
  --danger: #ef4444;
  --accent: #4c8dff;

  --radius: 12px;
  --tap: 56px;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over the display rules below. Without this,
   `display: flex/grid` on a specific id beats the user-agent [hidden] rule and
   hidden panels stay on screen. */
[hidden] { display: none !important; }


html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 500 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  /* The car screen is a touch surface; text selection only gets in the way. */
  -webkit-user-select: none;
  user-select: none;
}

.screen { position: fixed; inset: 0; }
.muted { color: var(--muted); }
.pad { padding: 1rem; }
.error { color: var(--danger); min-height: 1.4em; margin: .5rem 0 0; }

/* -------------------------------------------------------------- buttons -- */
.btn {
  min-height: var(--tap);
  padding: 0 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:active { filter: brightness(1.25); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-collected { background: var(--done); border-color: var(--done); color: #06281a; }
.btn-notinfield { background: var(--absent); border-color: var(--absent); color: #2b1405; }
.btn-ghost { background: transparent; }

/* -------------------------------------------------------------- pairing -- */
#pair { display: grid; place-items: center; background: var(--bg); padding: 1rem; }
.pair-box { width: min(30rem, 100%); text-align: center; }
.pair-box h1 { font-size: 1.75rem; margin: 0 0 .5rem; letter-spacing: .01em; }
#pair-code {
  width: 100%;
  margin: 1.5rem 0 1rem;
  padding: 1rem;
  font: 700 2.5rem/1 ui-monospace, Menlo, monospace;
  letter-spacing: .35em;
  text-align: center;
  text-transform: uppercase;
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
}
#pair-code:focus { outline: none; border-color: var(--accent); }
#pair-submit { width: 100%; }

/* ------------------------------------------------------------ statusbar -- */
#statusbar {
  position: absolute; inset: 0 0 auto 0; z-index: 3;
  display: flex; align-items: center; gap: .75rem;
  padding: .5rem .75rem;
  background: linear-gradient(var(--bg) 65%, transparent);
}
.veh-name { font-weight: 700; margin-right: auto; }
.stat { font-variant-numeric: tabular-nums; font-size: .95rem; }
.pill {
  padding: .2rem .6rem; border-radius: 999px; font-weight: 700;
  background: var(--surface-2); font-size: .95rem;
}
.pill.underway { background: var(--surface-2); color: var(--text); }
.pill.parked { background: var(--done); color: #06281a; }
#statusbar .btn { min-height: 40px; padding: 0 .9rem; font-size: .9rem; }

/* ------------------------------------------------------------------ map -- */
#map { position: absolute; inset: 0; }
.maplibregl-ctrl-attrib { font-size: 10px; }

/* Vehicle and structure markers are DOM elements so they scale crisply and
   take touch events without a canvas hit-test. */
.marker {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid #0e1013; cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.marker.TO_COLLECT { background: var(--todo); }
.marker.COLLECTED { background: var(--done); }
.marker.NOT_IN_FIELD { background: var(--absent); }
.marker-vehicle {
  width: 0; height: 0;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 26px solid var(--accent);
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.8));
}

/* ---------------------------------------------------------------- sheet -- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 58%;
  display: flex; flex-direction: column;
  transition: transform .18s ease-out;
}
.sheet.collapsed { transform: translateY(calc(100% - var(--tap))); }
.sheet-handle {
  min-height: var(--tap);
  display: flex; align-items: center; gap: .6rem;
  width: 100%; padding: 0 1rem;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
}
.badge {
  margin-left: auto; padding: .15rem .6rem; border-radius: 999px;
  background: var(--accent); color: #fff; font-size: .9rem;
}
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.filter-row {
  display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem; border-bottom: 1px solid var(--line);
}
.chk { display: flex; align-items: center; gap: .5rem; }
.chk input { width: 22px; height: 22px; }
.select {
  margin-left: auto; min-height: 40px; padding: 0 .5rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; font: inherit;
}

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: .85rem;
  min-height: var(--tap); padding: .5rem 1rem;
  border-bottom: 1px solid var(--line); cursor: pointer;
}
.list li:active { background: var(--surface-2); }
.dot { width: 14px; height: 14px; border-radius: 50%; flex: none; }
.dot.TO_COLLECT { background: var(--todo); }
.dot.COLLECTED { background: var(--done); }
.dot.NOT_IN_FIELD { background: var(--absent); }
.li-main { flex: 1; min-width: 0; }
.li-id { font-weight: 700; }
.li-sub { font-size: .88rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-dist { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--muted); }

/* ----------------------------------------------------------- inspection -- */
.detail {
  position: absolute; inset: 0; z-index: 6;
  background: rgba(0,0,0,.6);
  display: grid; place-items: end center;
  padding: 1rem;
}
.detail-card {
  position: relative;
  width: min(46rem, 100%); max-height: 92%;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.detail-close {
  position: absolute; top: .5rem; right: .5rem;
  width: 44px; height: 44px;
  background: none; border: 0; color: var(--muted);
  font-size: 2rem; line-height: 1; cursor: pointer;
}
.detail-card h2 { margin: 0 1.5rem .75rem 0; font-size: 1.35rem; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: 0 0 1rem; font-size: .95rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; }

#d-form { border: 0; padding: 0; margin: 0; }
#d-form:disabled { opacity: .45; }
.field { display: block; margin-bottom: .9rem; }
.field span { display: block; margin-bottom: .3rem; color: var(--muted); font-size: .9rem; }
.field input, .field textarea {
  width: 100%; padding: .75rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  font: inherit; -webkit-user-select: text; user-select: text;
}
.field input { min-height: var(--tap); }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.actions .btn { flex: 1 1 10rem; }

/* ---------------------------------------------------------------- toast -- */
.toast {
  position: absolute; left: 50%; bottom: 5rem; z-index: 8;
  transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: .85rem 1.25rem; border-radius: var(--radius);
  font-weight: 600; box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

/* ------------------------------------------------------------- offline -- */
.pill.queued { background: var(--todo); color: #2b1405; }

.offline-banner {
  position: absolute; top: 3.25rem; left: .75rem; right: .75rem; z-index: 5;
  background: var(--absent); color: #2b1405;
  padding: .7rem 1rem; border-radius: var(--radius);
  font-weight: 600; box-shadow: 0 3px 12px rgba(0,0,0,.5);
}
.offline-banner span { font-weight: 500; display: block; font-size: .92rem; }

.pending-notice {
  background: var(--todo); color: #2b1405;
  padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
  font-weight: 600;
}

/* A queued outcome is shown as a ring rather than a fill, so the crew can tell
   at a glance what has actually reached the office from what has not. */
.dot.pending, .marker.pending {
  background: transparent;
  border: 3px solid var(--todo);
  box-sizing: border-box;
}
.li-queued { font-size: .8rem; color: var(--todo); font-weight: 700; }

/* GPS source indicator. Present only when the browser is actually supplying a
   fix, so its absence is itself information. */
.pill.gps { background: var(--done); color: #06281a; }
.pill.gps.denied { background: var(--absent); color: #2b1405; }

/* ------------------------------------------------------- offline maps -- */
.region-list { list-style: none; margin: 0 0 1rem; padding: 0; }
.region-list li {
  display: flex; align-items: center; gap: 1rem;
  padding: .85rem 0; border-bottom: 1px solid var(--line);
}
.region-main { flex: 1; min-width: 0; }
.region-name { font-weight: 700; }
.region-sub { font-size: .88rem; color: var(--muted); }
.region-list .btn { min-height: 44px; padding: 0 .9rem; flex: none; }
.region-here {
  display: inline-block; margin-left: .5rem; padding: .1rem .5rem;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: .75rem; font-weight: 700; vertical-align: middle;
}
.progress {
  height: 6px; border-radius: 3px; background: var(--surface-2);
  overflow: hidden; margin-top: .4rem;
}
.progress > span { display: block; height: 100%; background: var(--accent); width: 0; }
.pill.mapsrc { background: var(--surface-2); color: var(--muted); }
.pill.mapsrc.offline { background: var(--done); color: #06281a; }
