/* Layout: full-bleed map with a floating panel (bottom sheet on phones, left card on desktop). */

/* ---- Design tokens ---- */
:root {
  --bg: #eeeeee;
  --panel: #ffffff;
  --fg: #000000;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --accent: #000000;
  --accent-fg: #ffffff;
  --ok: #05a357;
  --danger: #d4380d;
  --blue: #276ef1;
  --grip: #bdbdbd;
  --shadow: 0 4px 16px rgba(0, 0, 0, .16);
  --display: "DM Sans", system-ui, sans-serif;
  --body: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --panel: #1c1c1c;
    --fg: #ffffff;
    --muted: #a3a3a3;
    --line: #333333;
    --accent: #ffffff;
    --accent-fg: #000000;
    --ok: #3ddc84;
    --danger: #ff8a65;
    --grip: #666666;
    --shadow: 0 4px 16px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

/* ---- Base ---- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }   /* no pull-to-refresh over the map */
body { background: var(--bg); color: var(--fg); font: 15px/1.45 var(--body); }
#map { position: fixed; inset: 0; z-index: 0; background: #eeeeee; }
h1 { font: 700 28px/1.1 var(--display); margin: 0 0 6px; letter-spacing: -.02em; }
h2 { font: 700 20px/1.2 var(--display); margin: 0; letter-spacing: -.01em; }
.sub { margin: 0; color: var(--muted); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; }
.label, legend {
  font: 500 12px var(--body); text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); padding: 0; margin: 0 0 8px;
}

/* ---- Panel ---- */
.panel {
  position: fixed; z-index: 10;
  left: 16px; top: 16px; width: min(380px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: var(--shadow);
}
.panel-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px; }
.grabber { display: none; }   /* phones only, see the media query at the bottom */
[data-view] { display: flex; flex-direction: column; gap: 16px; }
.head { display: flex; align-items: center; gap: 12px; }

/* ---- Location row ---- */
.locrow { display: flex; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 12px; }
.locrow .grow { flex: 1; min-width: 0; }
.locrow small { display: block; color: var(--muted); font: 400 12px var(--mono); margin-top: 2px; overflow-wrap: anywhere; }
.status { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.status[data-state="ok"] .dot { background: var(--ok); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 25%, transparent); }
.status[data-state="busy"] .dot { background: #d99a1c; animation: pulse 1s infinite alternate; }
.status[data-state="error"] { color: var(--danger); }
.status[data-state="error"] .dot { background: var(--danger); }
@keyframes pulse { to { opacity: .3; } }

/* ---- Form ---- */
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.chip span { display: inline-block; padding: 9px 14px; border-radius: 999px; background: var(--bg); font-size: 14px; font-weight: 500; }
.chip input:checked + span { background: var(--accent); color: var(--accent-fg); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; }
input[type="tel"], select, textarea {
  font: 400 15px var(--body); color: var(--fg); background: var(--bg);
  border: 1px solid transparent; border-radius: 10px; padding: 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 64px; }
.error { color: var(--danger); font-size: 13px; margin: 0; }
.error:empty { display: none; }

/* ---- Buttons ---- */
button, .btn {
  font: 500 14px var(--body); cursor: pointer; border-radius: 999px; padding: 11px 18px;
  border: 1px solid transparent; background: var(--bg); color: var(--fg);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
}
button:hover, .btn:hover { filter: brightness(.94); }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.wide { width: 100%; padding: 14px 18px; font-size: 15px; }
button.ghost { background: transparent; padding: 8px 4px; color: var(--muted); }

/* ---- Mechanic cards ---- */
.cards { display: flex; flex-direction: column; gap: 10px; list-style: none; margin: 0; padding: 0; }
.card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.cards .card { cursor: pointer; }
.cards .card:hover { background: var(--bg); }
.cards .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.card.plain { gap: 6px; align-items: flex-start; }
.sticky-bar {
  position: sticky; bottom: -20px; margin: 0 -20px -20px; padding: 12px 20px 20px;
  background: var(--panel); border-top: 1px solid var(--line);
}
button:disabled { opacity: .45; cursor: default; }
.card-top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.card h3 { margin: 0; font: 700 16px/1.25 var(--display); }
.meta { color: var(--muted); font-size: 13px; margin: 0; }
.eta { text-align: right; flex: none; }
.eta b { display: block; font: 700 20px/1 var(--display); }
.eta span { color: var(--muted); font-size: 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--bg); }
.tag.strong { background: var(--accent); color: var(--accent-fg); }
.tag.warn { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.empty { color: var(--muted); margin: 0; padding: 8px 0; }

/* ---- Tracking ---- */
.big { font: 700 36px/1.05 var(--display); letter-spacing: -.02em; margin: 2px 0 6px; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.steps li::before { content: ""; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.steps li.done { color: var(--fg); }
.steps li.done::before { background: var(--accent); border-color: var(--accent); }
.steps li.now { color: var(--fg); font-weight: 500; }
.steps li.now::before { border-color: var(--accent); }

/* ---- Map markers ---- */
.me-pin {
  width: 20px; height: 20px; border-radius: 50%; background: var(--blue); border: 3px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.35), 0 0 0 0 rgba(39,110,241,.45);
  animation: ring 2s infinite;
}
@keyframes ring {
  70%  { box-shadow: 0 1px 4px rgba(0,0,0,.35), 0 0 0 18px rgba(39,110,241,0); }
  100% { box-shadow: 0 1px 4px rgba(0,0,0,.35), 0 0 0 0 rgba(39,110,241,0); }
}
.mech-pin {
  width: 30px; height: 30px; border-radius: 10px; background: #000; color: #fff;
  display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35);
}
.mech-pin svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mech-pin.is-van { background: #fff; color: #000; border: 2px solid #000; border-radius: 50%; }
.mech-pin { cursor: pointer; }
.mech-pin.is-selected { background: var(--blue); color: #fff; border-color: #fff; box-shadow: 0 0 0 5px rgba(39,110,241,.35), 0 2px 6px rgba(0,0,0,.35); }
.mech-pin.is-active { background: var(--ok); color: #fff; border-color: #fff; box-shadow: 0 0 0 5px rgba(5,163,87,.35), 0 2px 6px rgba(0,0,0,.35); }
@media (prefers-reduced-motion: reduce) { .me-pin, .dot { animation: none !important; } }

/* ---- MapLibre controls ---- */
.maplibregl-ctrl-group { background: var(--panel) !important; border: 1px solid var(--line); box-shadow: none !important; }
.maplibregl-ctrl-group button { border: 0; border-radius: 0; padding: 0; }
@media (prefers-color-scheme: dark) {
  .maplibregl-ctrl-group button .maplibregl-ctrl-icon { filter: invert(1); }
}

/* ---- Phones: panel becomes a bottom sheet ---- */
@media (max-width: 640px) {
  .panel {
    left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 72dvh;
    border-radius: 18px 18px 0 0;
    transition: height .25s ease;
  }
  .panel.is-dragging { transition: none; }
  .panel-body {
    padding: 4px max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  }
  .panel.is-collapsed .panel-body { visibility: hidden; }

  /* The handle: drag it or tap it to slide the panel down and see the map */
  .grabber {
    display: flex; flex-direction: column; align-items: center; gap: 8px; flex: none;
    padding: 14px 16px 10px; cursor: grab;
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  }
  .grabber, .grabber * { touch-action: none; }
  .grabber:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 18px 18px 0 0; }
  .grip { width: 48px; height: 5px; border-radius: 3px; background: var(--grip); }
  .peek { display: none; max-width: 100%; font: 700 15px/1.2 var(--display); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .panel.is-collapsed .peek { display: block; }
  @media (prefers-reduced-motion: reduce) { .panel { transition: none; } }
  .sticky-bar {
    bottom: calc(-1 * max(16px, env(safe-area-inset-bottom, 0px)));
    margin: 0 -16px calc(-1 * max(16px, env(safe-area-inset-bottom, 0px)));
    padding: 12px 16px max(16px, env(safe-area-inset-bottom, 0px));
  }
}
