:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2026;
  --muted: #69707c;
  --line: #e3e6ea;
  --accent: #0b63ce;
  --hover: #eef3fb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --panel: #181c21;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --line: #2a3038;
    --accent: #5aa2ff;
    --hover: #212834;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  display: grid;
  grid-template-columns: 340px 1fr;
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

#panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
}
#panel header { padding: 14px 16px 0; border-bottom: 1px solid var(--line); }
/* test mode (/api/config testMode): strip above the logo, public/tester.js */
.test-banner {
  margin: -14px -16px 12px; padding: 5px 16px;
  background: #e4e5e7; color: #4a4f57; font-size: 12px; font-weight: 600; text-align: center; letter-spacing: 0.02em;
}
@media (prefers-color-scheme: dark) { .test-banner { background: #2a2e34; color: #b4bac3; } }
h1 { margin: 0 0 10px; font-size: 18px; }

/* logo in the style of acércame (assets/img/logo.acercame.png): blue "a",
   grey "m", geometric sans (Jost ~ Futura, same single-storey "a") */
:root { --logo-a: #0082cd; --logo-m: #aaa9a7; }
@media (prefers-color-scheme: dark) { :root { --logo-a: #2a9be0; --logo-m: #8f8e8c; } }
.logo {
  display: flex; align-items: flex-end; gap: 8px;
  font-family: Jost, "Century Gothic", Futura, sans-serif;
  font-weight: 400; line-height: 1; user-select: none;
}
.logo .a { color: var(--logo-a); }
.logo .m { color: var(--logo-m); }
.logo .mono { font-size: 44px; font-weight: 600; letter-spacing: -0.07em; margin-bottom: -4px; }
.logo .mono .m { margin-left: -0.06em; }
.logo .word { font-size: 17px; letter-spacing: -0.01em; padding-bottom: 1px; }
/* viewer: the bus icon (public/icon.svg) replaces the "am" monogram */
.logo .bus { display: block; margin: -2px -2px -2px -4px; }
.logo:has(.bus) { align-items: center; gap: 6px; }
.logo:has(.bus) .word { font-size: 22px; padding-bottom: 0; }

/* service notices (/api/warnings) */
.title-row { display: flex; align-items: flex-start; justify-content: space-between; }
.icon-row { display: flex; gap: 2px; margin: -4px -6px 0 0; }
.icon-btn {
  position: relative; padding: 4px 6px; border: 0; border-radius: 6px;
  background: none; color: var(--muted); cursor: pointer;
}
.icon-btn:hover, .icon-btn[aria-expanded="true"] { background: var(--hover); }
#info-btn[aria-expanded="true"] { color: var(--accent); }
#locate-btn[aria-pressed="true"] { color: #1a73e8; }
#locate-btn.waiting svg { animation: meter-pulse 0.8s ease-in-out infinite alternate; }
.toast {
  position: fixed; left: 50%; bottom: 72px; z-index: 1000; transform: translateX(-50%);
  max-width: calc(100vw - 32px); padding: 8px 14px; border-radius: 8px;
  background: #1c2026; color: #fff; font-size: 13px; box-shadow: 0 4px 16px rgb(0 0 0 / 0.3);
}
.bell.on { color: #d97706; }
.badge {
  position: absolute; top: 0; right: 0; min-width: 16px; padding: 0 4px; border-radius: 8px;
  background: #dc2626; color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center;
}
.alerts { margin: 0 0 10px; padding: 8px 12px; border: 1px solid var(--line); border-left: 3px solid #d97706; border-radius: 8px; background: var(--bg); max-height: 40vh; overflow: auto; }
.alerts .alert { margin: 0 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.alerts pre.alert { font-size: 12px; }
.alerts .alert:last-child { margin-bottom: 0; }
.info { margin: 0 0 10px; padding: 8px 12px; border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; background: var(--bg); max-height: 50vh; overflow: auto; font-size: 13px; }
.info h2 { margin: 2px 0 6px; }
.info p { margin: 8px 0 0; }
.info .note { padding: 6px 8px; border-radius: 6px; background: var(--hover); }
.info a { color: var(--accent); }
.fares { width: 100%; border-collapse: collapse; }
.fares td { padding: 3px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.fares td:nth-child(2) { padding: 3px 6px; color: var(--muted); font-size: 12px; }
.fares td:last-child { text-align: right; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stop-alert { margin: 6px 0 0; padding: 4px 6px; border-left: 3px solid #d97706; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; }
h2 { margin: 6px 0 10px; font-size: 15px; }

/* scoreboard */
.scoreboard { margin: 0 0 10px; padding: 10px 12px 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.score-row { display: flex; gap: 16px; }
.score { display: flex; align-items: baseline; gap: 6px; }
.score strong { font-size: 26px; line-height: 1; font-variant-numeric: tabular-nums; }
.score span { color: var(--muted); font-size: 12px; }
.scoreboard .chips { margin-top: 8px; gap: 4px; }
.score-chip { cursor: pointer; }
.score-chip.off { background: none; color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.score-chip sup { font-size: 9px; margin-left: 1px; }

.tabs { display: flex; gap: 4px; }
.tabs button {
  flex: 1; padding: 8px; border: 0; background: none; color: var(--muted);
  font: inherit; cursor: pointer; border-bottom: 2px solid transparent;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.tab { flex: 1; overflow-y: auto; padding: 8px 8px 16px; }
#stop-search {
  width: 100%; padding: 8px 10px; margin: 4px 0 8px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit;
}

.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 6px; cursor: pointer;
}
.list li:hover, .list li.active { background: var(--hover); }
ol.stops { counter-reset: n; }
ol.stops li::before { counter-increment: n; content: counter(n); min-width: 1.6em; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }

.chip {
  display: inline-block; min-width: 34px; padding: 2px 6px; border-radius: 4px;
  color: #fff; font-weight: 700; font-size: 12px; text-align: center; white-space: nowrap;
}
.chip.small { min-width: 0; padding: 0 5px; font-size: 11px; font-weight: 600; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.ref { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }

.link { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 4px 0; }

#status { padding: 8px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

#map { height: 100%; }

/* popup */
.popup h3 { margin: 0 0 2px; font-size: 14px; }
.popup button {
  margin-top: 8px; padding: 5px 10px; border: 1px solid var(--accent); border-radius: 5px;
  background: none; color: var(--accent); font: inherit; cursor: pointer;
}
.popup .arrivals { margin-top: 8px; max-height: 220px; overflow-y: auto; }
/* refresh meter: last update (left) -> next update (right) */
.meter { margin: 8px 0 2px; --m: var(--accent); }
.popup .meter { --m: #0b63ce; } /* Leaflet popups stay white in dark mode */
.meter-track { position: relative; height: 4px; margin: 5px 5px; border-radius: 2px; background: rgba(127, 127, 127, 0.25); }
.meter-fill { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: 2px; background: var(--m); opacity: 0.35; }
.meter-dot {
  position: absolute; top: 50%; left: 0; width: 10px; height: 10px; margin: -5px 0 0 -5px;
  border-radius: 50%; background: var(--m); box-shadow: 0 0 0 2px #fff;
}
.meter-fill, .meter-dot { transition: width 1s linear, left 1s linear; }
.meter.no-anim .meter-fill, .meter.no-anim .meter-dot { transition: none; }
.meter-labels {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}
.popup .meter-labels { color: #666; }
.meter.loading .meter-dot { left: 100% !important; animation: meter-pulse 0.8s ease-in-out infinite alternate; }
.meter.loading .meter-fill { width: 100% !important; }
@keyframes meter-pulse { from { opacity: 1; } to { opacity: 0.3; } }
@media (prefers-reduced-motion: reduce) {
  .meter-fill, .meter-dot { transition: none; }
  .meter.loading .meter-dot { animation: none; }
}
.arrival-list { list-style: none; margin: 0; padding: 0; }
.arrival-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0; border-top: 1px solid #ddd; font-size: 12px;
}
.arrival-list li.invalid { opacity: 0.5; }
.arrival-list .eta { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* estimated buses */
.buses { margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.buses p { margin: 4px 8px; }
.buses .eta { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.bus-icon { background: none; border: 0; }
.bus-marker { position: relative; width: 60px; height: 60px; }
/* White disc with a line-coloured rim: reads on satellite, streets and dark tiles alike. */
.bus-ring {
  position: absolute; inset: 11px; display: grid; place-items: center; border-radius: 50%;
  background: #fff; border: 3px solid var(--c);
  box-shadow: 0 0 0 1.5px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.6);
}
/* Waiting at the terminus: dashed rim, calmer arrow. */
.bus-marker.waiting .bus-ring { border-style: dashed; }
.bus-marker.waiting .bus-arrow { opacity: 0.55; }
.bus-van {
  position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible;
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
/* Direction arrow: line colour, white halo, then a dark halo, so it survives any background. */
.bus-arrow { position: absolute; inset: 0; pointer-events: none; }
.bus-arrow::before {
  content: ""; position: absolute; left: 50%; top: -4px; transform: translateX(-50%);
  border-style: solid; border-color: transparent; border-width: 0 10px 16px;
  border-bottom-color: var(--c);
  filter: drop-shadow(0 0 1.5px #fff) drop-shadow(0 0 1px #fff) drop-shadow(0 0 2px rgba(0, 0, 0, 0.9));
}
.bus-code {
  position: absolute; right: 0; bottom: 4px; padding: 1px 5px; border-radius: 4px;
  background: var(--c); color: #fff; font: 700 11px/1.3 system-ui, sans-serif;
  border: 1.5px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* Mobile: header, map, tabs, then the list running to the bottom edge (iOS
   Safari's floating URL pill sits over the list, which scrolls past it). #panel and its
   header dissolve (display: contents) so their children sit in the body grid. */
@media (max-width: 700px) {
  body {
    height: 100dvh;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto auto auto minmax(160px, 1fr) auto auto minmax(0, 1.15fr);
    grid-template-areas: "banner" "title" "alerts" "info" "score" "map" "tabs" "status" "content";
    background: var(--panel);
  }
  /* iOS Safari: dvh stops above the floating URL pill and the gap below shows
     as a white band; lvh runs the list behind the pill (its 64px padding lets
     the last rows scroll clear). -webkit-touch-callout = iOS WebKit only. */
  @supports (-webkit-touch-callout: none) {
    body { height: 100lvh; }
    html, body { overscroll-behavior: none; }
  }
  #panel, #panel header { display: contents; }
  /* only the map pinch-zooms (Leaflet sets its own touch-action); the rest just
     scrolls. iOS also needs the viewport meta and the gesturestart guard in app.js */
  html, body { touch-action: pan-x pan-y; }
  .test-banner { grid-area: banner; margin: 0; padding: 3px 12px; font-size: 11px; }
  .title-row { grid-area: title; padding: 6px 12px 4px; }
  .logo .bus { width: 32px; height: 32px; }
  .logo:has(.bus) .word { font-size: 19px; }
  .icon-row { margin: 0 -6px 0 0; }
  .alerts, .info { margin: 0 12px 6px; max-height: 30dvh; }
  .alerts { grid-area: alerts; }
  .info { grid-area: info; }
  #map { grid-area: map; height: auto; min-height: 0; }
  .tab { grid-area: content; min-height: 0; padding-bottom: calc(env(safe-area-inset-bottom) + 64px); }
  #status { grid-area: status; padding: 3px 12px; font-size: 11px; }
  #status.loaded { display: none; }

  /* compact scoreboard: one line of numbers, one scrollable line of chips */
  .scoreboard { grid-area: score; margin: 0 12px 6px; padding: 5px 10px; display: flex; align-items: center; gap: 10px; }
  .score-row { gap: 10px; flex: none; }
  .score { gap: 4px; }
  .score strong { font-size: 17px; }
  .score span { font-size: 11px; }
  .scoreboard .chips { margin-top: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; min-width: 0; }
  .scoreboard .chips::-webkit-scrollbar { display: none; }
  .score-chip { flex: none; }
  .score-chip.off { display: none; }
  .leaflet-popup-content { margin: 10px 12px; }
  .popup .arrivals { max-height: 22dvh; }
  .leaflet-control-attribution { font-size: 9px; line-height: 1.3; }

  /* tab bar under the map */
  .tabs { grid-area: tabs; gap: 0; border-bottom: 1px solid var(--line); background: var(--panel); }
  .tabs button { padding: 6px 4px; }
}

/* Cómo llegar */
.rp-field { padding: 8px; border-bottom: 1px solid var(--line); }
.rp-label { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 600; }
.rp-pin {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  color: #fff; font: 700 12px/1 system-ui, sans-serif; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.rp-icon { background: none; border: 0; }
.rp-buttons { display: flex; flex-wrap: wrap; gap: 4px; }
.rp-buttons button {
  flex: 1; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; white-space: nowrap;
  background: var(--bg); color: var(--text); font: inherit; font-size: 12px; cursor: pointer;
}
.rp-buttons button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.rp-value { margin-top: 6px; font-size: 13px; }
.rp-actions { display: flex; justify-content: space-between; padding: 4px 8px; }
.rp-results p { margin: 8px; }
.rp-mode-icon { font-size: 20px; }
.rp-modes .eta { font-variant-numeric: tabular-nums; white-space: nowrap; }
.rp-time { text-align: right; white-space: nowrap; }
.rp-lines { display: flex; align-items: center; gap: 3px; }
.list li.rp-bus { align-items: flex-start; }
.rp-legs { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.list .rp-legs li { display: list-item; margin: 3px 0; padding: 0; background: none; }
.popup-actions { display: flex; flex-wrap: wrap; gap: 6px; }
/* stop popup: "Parada N" and its line chips on one row; the three buttons on one row */
.popup-meta { align-items: center; gap: 4px; }
.popup-meta .ref { margin-right: 4px; }
.popup .popup-actions button { flex: 1; margin-top: 8px; padding: 5px 6px; font-size: 12px; white-space: nowrap; }
/* map modes */
.leaflet-container.pick-map, .pick-map .leaflet-interactive { cursor: crosshair; }
.route-mode path.route-line { stroke-opacity: 0.3; }
.pick-stop path.route-line, .pick-map path.route-line { stroke-opacity: 0.12; }
.pick-stop path.stop-marker { stroke: #1a73e8; stroke-width: 4; }
.pick-stop .bus-icon, .pick-map .bus-icon { opacity: 0.3; pointer-events: none; }
.rp-follow { margin-top: 6px; }
.list li.rp-bus.idle { opacity: 0.55; background: repeating-linear-gradient(135deg, transparent 0 6px, var(--hover) 6px 12px); }
.list li.rp-bus.idle.active { opacity: 0.8; }

/* test mode: contact-name modal (public/tester.js) */
.tester {
  width: min(380px, calc(100vw - 32px)); padding: 20px; border: 0; border-radius: 10px;
  background: var(--panel); color: var(--text); box-shadow: 0 12px 40px rgb(0 0 0 / 0.3);
}
.tester::backdrop { background: rgb(0 0 0 / 0.45); }
.tester h2 { margin: 0 0 8px; font-size: 17px; color: var(--logo-a); }
.tester p { margin: 0 0 12px; }
.tester input {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit;
}
.tester input:focus { outline: 2px solid var(--logo-a); outline-offset: -1px; }
.tester-error { margin: 8px 0 0 !important; color: #c62828; font-size: 13px; }
.tester button {
  margin-top: 14px; width: 100%; padding: 9px; border: 0; border-radius: 6px;
  background: var(--logo-a); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.tester button:disabled { opacity: 0.6; cursor: wait; }

/* "¿Qué es esto?" full-page modal */
.about {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0;
  border: 0; background: var(--panel); color: var(--text); overflow-y: auto;
}
.about::backdrop { background: var(--panel); }
.about-inner { position: relative; max-width: 680px; margin: 0 auto; padding: 32px 20px 48px; font-size: 15px; line-height: 1.6; }
.about-close { position: absolute; top: 20px; right: 12px; }
.about h1 { margin: 0 44px 12px 0; font: 600 30px/1.2 Jost, "Century Gothic", Futura, sans-serif; color: var(--logo-a); }
.about h2 { margin: 28px 0 6px; font-size: 17px; }
.about p { margin: 0 0 12px; }
.about .lead { font-size: 17px; }
.about a { color: var(--accent); }

/* star button: "Valorar Arrímame" (public/feedback.js), inside the .about shell */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.rate hr { margin: 32px 0 20px; border: 0; border-top: 1px solid var(--line); }
.fb-form { display: flex; flex-direction: column; }
.fb-form > label { margin: 14px 0 4px; font-weight: 600; font-size: 14px; }
.fb-form input[type="text"], .fb-form textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--text); font: inherit; resize: vertical;
}
.fb-form textarea { min-height: 140px; }
.fb-form input:focus, .fb-form textarea:focus { outline: 2px solid var(--logo-a); outline-offset: -1px; }
.fb-form button {
  align-self: flex-start; margin-top: 14px; padding: 9px 28px; border: 0; border-radius: 6px;
  background: var(--logo-a); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.fb-form button:disabled { opacity: 0.6; cursor: wait; }
.fb-msg { margin: 10px 0 0 !important; font-size: 14px; }
.fb-msg.error { color: #c62828; }
.fb-msg.ok { color: #2e7d32; }
@media (prefers-color-scheme: dark) { .fb-msg.error { color: #ff8a80; } .fb-msg.ok { color: #81c784; } }
/* 5 radios in reverse order: a checked/hovered star lights itself and the ones before it */
.stars { margin: 0; padding: 0; border: 0; }
.stars legend { margin-bottom: 4px; padding: 0; font-weight: 600; font-size: 14px; }
.star-row { display: flex; flex-direction: row-reverse; justify-content: flex-end; gap: 2px; }
.star-row input { position: absolute; opacity: 0; pointer-events: none; }
.star-row label { font-size: 38px; line-height: 1; color: var(--line); cursor: pointer; transition: color 0.1s; }
.star-row input:checked ~ label { color: #f5a623; }
.star-row:hover input ~ label { color: var(--line); }
.star-row:hover label:hover, .star-row:hover label:hover ~ label { color: #f5a623; }
.star-row input:focus-visible + label { outline: 2px solid var(--logo-a); outline-offset: 2px; border-radius: 4px; }
.low-nudge { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; border-left: 3px solid #f5a623; background: var(--hover); font-size: 14px; }
.low-nudge p { margin: 0 0 4px !important; }
.fb-form .low-nudge button { margin-top: 6px; padding: 7px 16px; }
.fb-form.flash { animation: fb-flash 1.6s ease-out; border-radius: 8px; }
@keyframes fb-flash { from { box-shadow: 0 0 0 4px #f5a623; } to { box-shadow: 0 0 0 4px transparent; } }
