/* Almuñécar Bus Reach — tokens, layout, components.
   Light is the default; [data-theme=dark] swaps the tokens. */

:root {
  color-scheme: light;
  --bg: #f2f2f0;
  --surface: #ffffff;
  --surface-2: #f7f7f5;
  --ink: #1b1c1e;
  --ink-2: #5f6368;
  --ink-3: #898781;
  --line: #e2e2de;
  --line-2: #cfcfca;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --route: #eb6834;
  --warn: #b45309;
  --warn-bg: #fff4e5;
  --band-0: #6da7ec; --band-1: #3987e5; --band-2: #256abf; --band-3: #184f95; --band-4: #0d366b;
  --sign-bg: #14171c; --sign-ink: #ffb547; --sign-ring: #2b2f36;
  --shadow: 0 8px 28px rgba(20, 23, 28, .14), 0 1px 2px rgba(20, 23, 28, .08);
  --radius: 14px;
  --fs-0: 11px; --fs-1: 12px; --fs-2: 13px; --fs-3: 14.5px; --fs-4: 17px; --fs-5: 22px;
  --peek: calc(112px + env(safe-area-inset-bottom, 0px));
  --rail: 400px;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141517;
  --surface: #1d1f23;
  --surface-2: #24272c;
  --ink: #ececea;
  --ink-2: #a3a7ae;
  --ink-3: #7d8087;
  --line: #2f3238;
  --line-2: #3d4149;
  --accent: #6da7ec;
  --accent-ink: #0d1117;
  --route: #f08a5d;
  --warn: #f5b063;
  --warn-bg: #2e2416;
  --band-0: #9ec5f4; --band-1: #6da7ec; --band-2: #3987e5; --band-3: #256abf; --band-4: #184f95;
  --sign-bg: #0b0d10; --sign-ink: #ffb547; --sign-ring: #30343b;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  position: fixed; inset: 0; overflow: hidden;
  overscroll-behavior: none; touch-action: manipulation;
  background: var(--bg); color: var(--ink);
  font: var(--fs-3)/1.4 -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
}
h1, h2, h3, p { margin: 0; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: var(--accent); }
.t { font-variant-numeric: tabular-nums; }
.tag { display: inline-block; font-size: var(--fs-0); color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; padding: 0 6px; margin-left: 4px; vertical-align: 1px; }
.warn { color: var(--warn); }
.link { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.hint { font-size: var(--fs-1); color: var(--ink-3); margin: 6px 0; }
.empty { color: var(--ink-3); padding: 16px; text-align: center; }

.app { position: absolute; inset: 0; height: 100vh; height: 100dvh; }
.map { position: absolute; inset: 0; background: var(--bg); }
.map .maplibregl-ctrl-attrib { font-size: var(--fs-0); }
.map .maplibregl-ctrl-top-right { top: 12px; right: 12px; }
.maplibregl-popup.tip .maplibregl-popup-content {
  background: var(--surface); color: var(--ink); border-radius: 10px; padding: 8px 10px; box-shadow: var(--shadow);
  font-size: var(--fs-2); line-height: 1.3; pointer-events: none;
}
.maplibregl-popup.tip .maplibregl-popup-content strong { display: block; }
.maplibregl-popup.tip .maplibregl-popup-content span { color: var(--ink-2); }
.maplibregl-popup.tip .maplibregl-popup-tip { border-top-color: var(--surface); border-bottom-color: var(--surface); }

/* ---- panel (shared) -------------------------------------------------- */
.panel { background: var(--surface); color: var(--ink); }
/* A selected place turns the panel into its card; everything else waits behind "All destinations". */
.panel.has-detail > :is(.controls, .legend, .list, .urban), .panel.has-detail .summary { display: none; }
.panel.has-detail .panel__head { padding-bottom: 0; }
.panel.has-detail .panel__head h1 { font-size: var(--fs-3); color: var(--ink-2); }
.panel.has-detail .panel__head h1 span { color: var(--ink-3); }
.panel__head { padding: 18px 18px 8px; }
.panel__head h1 { font-size: var(--fs-5); font-weight: 700; letter-spacing: -.01em; }
.panel__head h1 span { color: var(--ink-2); font-weight: 500; }
.summary { margin-top: 6px; font-size: var(--fs-2); color: var(--ink-2); }
.summary strong { color: var(--ink); }

.controls { padding: 6px 18px 12px; border-bottom: 1px solid var(--line); }
.ctl { margin-top: 10px; }
.ctl--row { display: flex; gap: 14px; flex-wrap: wrap; align-items: flex-end; }
.ctl__label { font-size: var(--fs-0); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips--tight { gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 6px 11px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); font-size: var(--fs-2); line-height: 1.2; color: var(--ink);
  min-height: 32px;
}
.chip:disabled { opacity: .4; cursor: default; }
.chip.is-on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip__badge { font-size: var(--fs-0); margin-left: 5px; color: var(--warn); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.chip.is-on .chip__badge { color: inherit; opacity: .85; }
.chip--date { position: relative; overflow: hidden; }
.chip--date input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-2); border-radius: 999px; padding: 0 12px; min-height: 32px; background: var(--surface); position: relative; }
.pill select {
  font: inherit; font-variant-numeric: tabular-nums; border: 0; background: transparent; color: var(--ink);
  padding: 4px 18px 4px 0; appearance: none; -webkit-appearance: none; cursor: pointer; min-height: 30px;
}
.pill::after { content: ""; position: absolute; right: 12px; top: 50%; width: 6px; height: 6px; border-right: 1.5px solid var(--ink-2); border-bottom: 1.5px solid var(--ink-2); transform: translateY(-70%) rotate(45deg); pointer-events: none; }
.pill.is-now { border-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; }
.seg__btn { padding: 6px 10px; font-size: var(--fs-2); color: var(--ink-2); min-height: 32px; }
.seg__btn + .seg__btn { border-left: 1px solid var(--line-2); }
.seg__btn.is-on { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-1); color: var(--ink-2); cursor: pointer; min-height: 32px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { width: 34px; height: 20px; border-radius: 999px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch__track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(14px); }

/* ---- legend ------------------------------------------------------------ */
.legend { padding: 10px 18px; border-bottom: 1px solid var(--line); font-size: var(--fs-1); color: var(--ink-2); }
.legend__title { font-size: var(--fs-0); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 6px; }
.legend__bands { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.legend__band { display: inline-flex; align-items: center; gap: 5px; }
.legend__band i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 2px var(--line-2); }
.legend__glyphs { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; }
.legend__glyphs span { display: inline-flex; align-items: center; gap: 5px; }
.g { width: 11px; height: 11px; border-radius: 50%; display: inline-block; background: var(--band-2); box-shadow: 0 0 0 1.5px var(--surface); }
.g--xfer { box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 3px var(--band-2); }
.g--stranded { background: transparent; border: 2px solid var(--band-2); }
.g--approx { background: transparent; border: 2px dotted var(--band-2); }

/* ---- list -------------------------------------------------------------- */
.list { padding: 4px 0 8px; }
.row {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; align-items: center;
  width: 100%; text-align: left; padding: 9px 18px; border-bottom: 1px solid var(--line);
}
.row--in { padding-left: 34px; background: var(--surface-2); }
.row:hover, .row.is-hover { background: var(--surface-2); }
.row.is-selected { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.row--group .row__name { font-weight: 600; }
.row--group.is-open { border-bottom-color: transparent; }
.row__main { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row__name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__meta { font-size: var(--fs-1); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row__dur { font-size: var(--fs-2); color: var(--ink); font-weight: 600; }
.dot { width: 12px; height: 12px; border-radius: 50%; justify-self: center; background: var(--band-2); box-shadow: 0 0 0 2px var(--surface); }
.dot.band-0 { background: var(--band-0); } .dot.band-1 { background: var(--band-1); } .dot.band-2 { background: var(--band-2); }
.dot.band-3 { background: var(--band-3); } .dot.band-4 { background: var(--band-4); }
.dot.is-xfer { box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px currentColor; }
.dot.band-0.is-xfer { color: var(--band-0); } .dot.band-1.is-xfer { color: var(--band-1); } .dot.band-2.is-xfer { color: var(--band-2); }
.dot.band-3.is-xfer { color: var(--band-3); } .dot.band-4.is-xfer { color: var(--band-4); }
.dot.is-stranded { background: transparent !important; border: 2px solid; }
.dot.band-0.is-stranded { border-color: var(--band-0); } .dot.band-1.is-stranded { border-color: var(--band-1); }
.dot.band-2.is-stranded { border-color: var(--band-2); } .dot.band-3.is-stranded { border-color: var(--band-3); } .dot.band-4.is-stranded { border-color: var(--band-4); }

/* ---- detail ------------------------------------------------------------ */
.detail { padding: 12px 18px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.back { color: var(--accent); font-size: var(--fs-2); margin-bottom: 8px; display: inline-block; }
.detail h2 { font-size: var(--fs-4); font-weight: 700; letter-spacing: -.01em; }
.detail h3 { font-size: var(--fs-0); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin: 18px 0 6px; }
.detail__sub { font-size: var(--fs-2); color: var(--ink-2); margin: 2px 0 12px; }
.detail__note { font-size: var(--fs-1); color: var(--ink-3); margin: -6px 0 12px; }
.headsign-block { margin: 10px 0; }
.headsign-label { font-size: var(--fs-0); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 6px; }
.headsign {
  display: inline-block; max-width: 100%; background: var(--sign-bg); color: var(--sign-ink);
  font-weight: 700; font-size: var(--fs-5); line-height: 1.1; letter-spacing: .05em; text-transform: uppercase;
  padding: 12px 16px; border-radius: 10px; box-shadow: inset 0 0 0 1px var(--sign-ring), 0 1px 2px rgba(0,0,0,.3);
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
}
.headsign span { text-shadow: 0 0 10px rgba(255, 181, 71, .35); }
.headsign-note { font-size: var(--fs-1); color: var(--warn); margin-top: 6px; }
.leg__caveat { display: block; font-size: var(--fs-1); color: var(--warn); margin-top: 4px; }
/* Abono Único chips: green = valid, grey = not, amber = only on listed corridors / unknown */
.abono { font-size: var(--fs-1); white-space: nowrap; }
.abono--yes { color: #1f7a3a; font-weight: 600; }
.abono--no { color: var(--ink-3, #8a8a86); }
.abono--some, .abono--unknown { color: var(--warn); }
.detail__abono { margin: 6px 0 10px; font-size: var(--fs-2); }
.abono--journey-yes { color: #1f7a3a; }
.abono--journey-partial, .abono--journey-some, .abono--journey-unknown { color: var(--warn); }
.abono--journey-no { color: var(--ink-2); }
[data-theme="dark"] .abono--yes, [data-theme="dark"] .abono--journey-yes { color: #6fcf8a; }
.jt td.abono { text-align: center; font-weight: 700; }
.leg { font-size: var(--fs-2); color: var(--ink-2); margin-top: 8px; line-height: 1.5; }
.leg strong { color: var(--ink); font-weight: 600; }
.leg__arrow { color: var(--ink-3); margin: 0 4px; }
.leg__meta { display: block; font-size: var(--fs-1); color: var(--ink-3); }
.change { margin: 12px 0; padding: 8px 10px; border-left: 3px solid var(--route); background: var(--surface-2); font-size: var(--fs-2); color: var(--ink-2); border-radius: 0 8px 8px 0; }
.change__title { display: block; color: var(--ink); font-weight: 600; }
.change__walk { display: block; color: var(--ink-2); margin: 2px 0; }
.change__walk strong { color: var(--ink); font-weight: 600; }
.gap { display: inline-block; margin-left: 6px; font-size: var(--fs-0); font-weight: 700; letter-spacing: .06em; padding: 1px 6px; border-radius: 4px; }
.gap--tight { background: var(--warn-bg); color: var(--warn); }
.gap--ok { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line-2); }
.gap--comfortable { background: color-mix(in srgb, var(--band-1) 18%, var(--surface)); color: var(--accent); }
.gap--none { background: var(--warn-bg); color: var(--warn); }
.home { margin-top: 16px; padding-top: 4px; border-top: 1px dashed var(--line-2); }
.home__dwell { margin-top: 8px; font-size: var(--fs-2); color: var(--ink-2); }
.home__dwell strong { color: var(--ink); }
.routes { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.route button { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); font-size: var(--fs-2); line-height: 1.35; }
.route button:hover { border-color: var(--line-2); }
.route.is-on button { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.route__desc { color: var(--ink-2); }
.route__desc strong { color: var(--ink); font-weight: 600; }
.route__desc b { font-weight: 700; color: var(--ink); }
.route__times { font-size: var(--fs-1); color: var(--ink); font-weight: 600; word-spacing: 1px; }
.jt { width: 100%; border-collapse: collapse; font-size: var(--fs-1); }
.jt th { text-align: left; font-weight: 600; color: var(--ink-3); padding: 4px 6px 4px 0; border-bottom: 1px solid var(--line); font-size: var(--fs-0); text-transform: uppercase; letter-spacing: .06em; }
.jt td { padding: 5px 6px 5px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.jt td.t { white-space: nowrap; }
.jt tr.is-pick { cursor: pointer; }
.jt tr.is-pick:hover { background: var(--surface-2); }
.jt tr.is-active td { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.sign { display: inline-block; padding: 1px 6px; border-radius: 4px; background: var(--sign-bg); color: #f3f3f0; font-size: var(--fs-0); letter-spacing: .03em; text-transform: uppercase; }
.sign.is-misleading { color: var(--sign-ink); }
.sign__then { font-size: var(--fs-0); color: var(--ink-3); margin: 0 4px; }

/* ---- town buses --------------------------------------------------------- */
.urban { padding: 4px 18px 12px; border-bottom: 1px solid var(--line); }
.section-toggle { display: flex; justify-content: space-between; width: 100%; padding: 10px 0; font-weight: 600; }
.section-toggle__hint { color: var(--accent); font-weight: 500; font-size: var(--fs-2); }
.banner { padding: 8px 10px; border-radius: 8px; font-size: var(--fs-2); margin: 6px 0; }
.banner--warn { background: var(--warn-bg); color: var(--warn); }
.ub { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin: 8px 0; font-size: var(--fs-2); }
.ub summary { cursor: pointer; display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.ub__from { color: var(--ink-3); font-weight: 400; font-size: var(--fs-1); }
.ub__sched { margin-top: 8px; }
.ub__tag { font-size: var(--fs-0); text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); }
.ub__times { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.ub__times span { background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }
.ub__note, .ub__alert { font-size: var(--fs-1); color: var(--warn); margin-top: 4px; }
.ub__times .is-off { opacity: .4; text-decoration: line-through; }
.ub__none { color: var(--ink-3); margin-top: 6px; }
.ub__stops { margin-top: 8px; font-size: var(--fs-1); color: var(--ink-2); line-height: 1.5; }

/* ---- footer ------------------------------------------------------------- */
.footer { padding: 12px 18px calc(18px + env(safe-area-inset-bottom, 0px)); font-size: var(--fs-1); color: var(--ink-3); line-height: 1.5; }
.footer p { margin: 4px 0; }
.footer__warn { color: var(--warn); font-weight: 500; }
.limits summary { cursor: pointer; color: var(--ink-2); }
.limits ul { margin: 4px 0 0; padding-left: 18px; }

/* ---- toast / no-gl --------------------------------------------------------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow);
  font-size: var(--fs-2); display: flex; gap: 12px; align-items: center; z-index: 50; max-width: min(92vw, 520px);
}
.toast--warn { background: var(--warn); color: #fff; }
.toast__btn { font-weight: 700; text-decoration: underline; text-underline-offset: 2px; white-space: nowrap; }
.nogl { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; color: var(--ink-2); background: var(--bg); }

/* ---- desktop: floating rail ---------------------------------------------- */
@media (min-width: 900px) {
  .sheet {
    position: absolute; top: 12px; left: 12px; bottom: 12px; width: var(--rail); z-index: 5;
    overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
    scrollbar-width: thin;
  }
  .sheet__spacer, .snap, .sheet__handle { display: none; }
  .panel { min-height: 100%; border-radius: var(--radius); }
  .map .maplibregl-ctrl-bottom-right { right: 0; }
}

/* ---- mobile: bottom sheet ---------------------------------------------------- */
@media (max-width: 899px) {
  :root { --fs-3: 15px; }
  .sheet {
    position: fixed; inset: 0; z-index: 10; overflow-y: scroll; scroll-snap-type: y mandatory;
    overscroll-behavior: contain; pointer-events: none; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .sheet::-webkit-scrollbar { display: none; }
  .sheet__spacer { height: calc(100vh - var(--peek)); height: calc(100dvh - var(--peek)); }
  .snap { position: absolute; left: 0; width: 1px; height: 1px; scroll-snap-align: start; }
  .snap--peek { top: 0; }
  .snap--half { top: calc(50vh - var(--peek)); top: calc(50dvh - var(--peek)); }
  .snap--full { top: calc(100vh - var(--peek) - env(safe-area-inset-top, 0px)); top: calc(100dvh - var(--peek) - env(safe-area-inset-top, 0px)); }
  .panel {
    pointer-events: auto; height: 100vh; height: 100dvh;
    border-radius: 18px 18px 0 0; box-shadow: 0 -4px 24px rgba(0, 0, 0, .18);
    padding-bottom: env(safe-area-inset-bottom, 0px); overflow: hidden;
  }
  .sheet.is-full .panel { overflow-y: auto; border-radius: 0; padding-top: env(safe-area-inset-top, 0px); }
  /* the grip: a 36x5 bar drawn inside a finger-sized box; the box and the
     title take the hand-driven drag (see sheet.js), so no native scroll may
     start on them */
  .sheet__handle { width: 88px; height: 24px; margin: 0 auto; display: flex; align-items: center; justify-content: center;
    touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
  .sheet__handle::after { content: ''; width: 36px; height: 5px; border-radius: 3px; background: var(--line-2); }
  .panel__head { padding-top: 0; }
  .panel__head h1 { font-size: 19px; touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
  .row { padding: 11px 16px; }
  .controls, .legend, .detail, .urban, .footer { padding-left: 16px; padding-right: 16px; }
  .map .maplibregl-ctrl-top-right { display: none; }
  .map .maplibregl-ctrl-bottom-right { bottom: calc(var(--peek) - 4px); }
  .toast { bottom: calc(var(--peek) + 12px); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
