/*
 * One stylesheet, no framework, no web fonts.
 *
 * Two rules here are product rules, not taste:
 *   * colour is never the only channel — every shaded/sunny marker has a word
 *     next to it, so the palette below is a reinforcement and not the message;
 *   * the attribution bar is always visible and never collapses.
 */
:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --surface-2: #eeeeec;
  --text: #1b1b1d;
  --text-dim: #5c5c63;
  --line: #d8d8d4;
  --accent: #1b5e43;
  --shaded: #1b5e43;
  --sunny: #c77a12;
  --comparison: #8a8a8e;
  --error-bg: #fdecec;
  --error-text: #8a1c1c;
  /* The position dot. Deliberately NOT the shaded/sunny palette: the dot is
     not a claim about sun, and reusing those hues would read as one. */
  --position: #2f6fe0;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131316;
    --surface: #1d1d21;
    --surface-2: #26262b;
    --text: #ececed;
    --text-dim: #a3a3ab;
    --line: #35353b;
    --accent: #6fcfa3;
    --shaded: #6fcfa3;
    --sunny: #ffc46b;
    --comparison: #8a8a8e;
    --error-bg: #3a1d1d;
    --error-text: #ffb4ab;
    --position: #7aa7ff;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.app { max-width: 720px; margin: 0 auto; padding-bottom: 84px; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .6em; }
small, .caption { font-size: .8rem; color: var(--text-dim); }

button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 10px 14px; min-height: 44px;
}
.btn:hover { background: var(--surface-2); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn--primary { color: #10231c; } }
.btn--primary:disabled { opacity: .45; cursor: not-allowed; }
.btn--ghost { background: transparent; border-color: transparent; text-decoration: underline; padding: 6px 4px; min-height: 0; }
.btn:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; flex: 1; }
.topbar .btn { padding: 8px 10px; min-height: 40px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 12px 14px;
}
.row { display: flex; gap: 8px; align-items: center; }
.row--wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.field {
  display: flex; align-items: center; gap: 8px; width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); padding: 10px 12px; min-height: 46px; text-align: left;
}
.field__label { font-size: .75rem; color: var(--text-dim); display: block; }
.field__value { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field__value--empty { color: var(--text-dim); }

input[type="text"], input[type="search"], input[type="datetime-local"], select {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type="range"] { width: 100%; accent-color: var(--accent); }
.slider-ends { display: flex; justify-content: space-between; }

#map { height: 340px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.map-wrap { position: relative; margin: 12px 14px; }

/* ======================================================================
 * The map screen.
 *
 * The map is the screen, not a panel inside a form. Before this it was a
 * 340 px box below a tall planner card: on a 390x844 phone it began at
 * y = 580 and most of it was under the fold, which is what the owner meant
 * by "mechanics, not a navigator". Everything else now floats ON the map.
 *
 * `--sheet-h` and `--attrib-h` are measured in `app.js` after each render
 * and written onto `#app`, because the sheet's height depends on its
 * contents (a result is taller than an empty planner) and the credit bar
 * wraps to a different number of lines in each language. The same two
 * numbers are the insets `fitBounds` is padded with, so what the camera
 * thinks is covered and what is actually covered cannot drift apart.
 * ====================================================================== */
.app--map {
  position: fixed; inset: 0; max-width: none; margin: 0; padding: 0; overflow: hidden;
}
.map-screen { position: absolute; inset: 0; }
.app--map .map-wrap { position: absolute; inset: 0; margin: 0; }
.app--map #map { position: absolute; inset: 0; height: 100%; border: 0; border-radius: 0; }

/* ======================================================================
 * THE SEARCH SURFACE HIDES THE MAP. THIS IS A LEGAL RULE, NOT A STYLE.
 *
 * EEA Service Specific Terms §B.15.1 bars everything in a Places response
 * except latitude, longitude and place_id from being displayed "on, next to,
 * or in a manner that is visually associated with any map" — and the defined
 * term "With any Map" says "including a Google Map", so drawing a Google
 * basemap buys no relief. Our layout is a full-bleed map with floating panels,
 * so a suggestion list that floated would violate it by construction.
 *
 * The real guarantee is structural and lives in `js/app.js:render`: on the
 * search screen the map node is never appended to the document. This block is
 * the belt to that brace — an opaque, full-height ground, so that no future
 * layout change can leave a strip of map visible beside or behind the list.
 * ====================================================================== */
.app--search {
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
}

/* EEA SST §A.4.3: "Routing provided by Lightshadow", shown whenever a Google
   basemap is under our route, before navigation begins. Small, but it must be
   legible — "clearly display" is the wording — so it is not dimmed the way a
   caption is. */
.credit-routing {
  margin: 0 0 6px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
}

/* Overlays keep to a readable column on a wide screen; the map does not.
   The wrapper does the positioning and the inset, the child carries the
   background — otherwise the card's own padding would eat the inset and the
   card would sit flush against the edges of the phone. */
.overlay-col {
  position: absolute; left: 0; right: 0; margin: 0 auto;
  max-width: 580px; padding: 0 10px; pointer-events: none; z-index: 10;
}
.overlay-col > * { pointer-events: auto; }
.overlay-top { top: max(8px, env(safe-area-inset-top)); }

.float {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 2px 14px rgba(0, 0, 0, .18);
}
@media (prefers-color-scheme: dark) { .float { box-shadow: 0 2px 14px rgba(0, 0, 0, .5); } }

/* ---- the two endpoint rows, the primary flow ---- */
.top-card { padding: 6px; display: flex; gap: 6px; }
.top-card__fields { flex: 1; min-width: 0; }
.top-card__side { display: flex; flex-direction: column; gap: 4px; }

.field-line {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; border-radius: 10px;
  padding: 8px 8px; min-height: 44px; text-align: left; color: inherit;
}
.field-line:hover { background: var(--surface-2); }
.field-line + .field-line { border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
.field-line__text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.field-line__text--empty { color: var(--text-dim); }
.field-line__pin { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.field-line__pin--origin { background: var(--position); }
.field-line__pin--dest { background: var(--accent); }
.field-line__clear { border: 0; background: none; padding: 8px; color: var(--text-dim); min-height: 40px; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 12px; font-size: 1.05rem; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn--on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .icon-btn--on { color: #10231c; } }
.icon-btn--busy { color: var(--text-dim); }

/* ---- the control stacks, thumb-sized, on the right ---- */
.map-stack {
  position: absolute; right: max(10px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 8px; z-index: 12;
}
.map-stack .icon-btn { box-shadow: 0 2px 10px rgba(0, 0, 0, .2); width: 46px; height: 46px; }
.map-stack--lower { bottom: calc(var(--sheet-h, 170px) + var(--attrib-h, 56px) + 14px); }
/* A short screen — a small phone, or any phone in landscape — has no room for
   46 px targets between the endpoint card and the sheet. 40 px is still above
   the 40 px minimum every touch guideline gives. */
@media (max-height: 680px) {
  .map-stack { gap: 6px; }
  .map-stack .icon-btn { width: 40px; height: 40px; }
}

/* ---- the bottom sheet ---- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: var(--attrib-h, 56px);
  margin: 0 auto; max-width: 580px; z-index: 11;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0; box-shadow: 0 -2px 16px rgba(0, 0, 0, .18);
  max-height: 72vh; overflow-y: auto; overscroll-behavior: contain;
  padding: 4px 14px 14px;
}
/**
 * The resting sheet may never take more than two fifths of the screen.
 *
 * On a 320x568 phone it grew to 409 px of 568 and left the planned route in a
 * 100 px strip — measured in Chrome on 2026-09-14, and exactly the complaint
 * this work exists to answer, reintroduced from the other direction. The
 * expanded sheet is allowed to be tall, because expanding it is the user
 * asking to read rather than to look at the map.
 */
.sheet--peek { max-height: 46vh; }
/**
 * On a short screen the answer has to fit inside that cap WITHOUT scrolling,
 * because the two buttons are the point of the peek and a primary action below
 * the fold is a primary action nobody presses. The headline comes down until
 * the estimate pill sits on its line rather than wrapping under it, which is
 * what was costing the height.
 *
 * The qualifying sentence is NOT dropped to make room. A share-in-shade figure
 * without "clear sky, clouds are not modelled" beside it is the one thing this
 * sheet may never show.
 */
@media (max-height: 680px) {
  /* `.sheet__answer .headline` further down this file has the same specificity
     and would win on order, so the selector has to be longer, not just later. */
  .sheet--peek .sheet__answer .headline { font-size: 1.5rem; }
  .sheet--peek .caption { margin-bottom: .3em; }
  .sheet--peek .card { margin: 6px 0; }
}
@media (prefers-color-scheme: dark) { .sheet { box-shadow: 0 -2px 16px rgba(0, 0, 0, .5); } }
.sheet__handle {
  display: block; width: 100%; border: 0; background: none; padding: 6px 0 8px;
  min-height: 0; cursor: pointer;
}
.sheet__grip {
  display: block; width: 40px; height: 4px; margin: 0 auto;
  border-radius: 999px; background: var(--line);
}
.sheet .card { margin: 10px 0; border: 0; padding: 0; background: none; }
.sheet h2 { margin-top: 4px; }
.sheet__answer { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sheet__answer .headline { font-size: 1.75rem; }
.sheet__row { display: flex; gap: 8px; align-items: center; }
.sheet__row .btn { flex: 1; }
/* The one thing the sheet is for, at thumb width. */
.sheet__cta { width: 100%; margin-top: 4px; }

/* ---- the position dot's own readout ---- */
.pos-pill {
  position: absolute; left: max(10px, env(safe-area-inset-left));
  bottom: calc(var(--sheet-h, 170px) + var(--attrib-h, 56px) + 14px);
  z-index: 12; font-size: .72rem; color: var(--text-dim);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px;
}
.pos-pill[hidden] { display: none; }

/* The out-of-coverage offer. Deliberately the same card as everything else on
   the map: it is an offer, not an alarm, so it gets no warning colour. */
.coverage-hint { display: grid; gap: 6px; }
.coverage-hint .row { align-items: center; }
.coverage-hint p { margin: 0; }

.loc-note { display: flex; gap: 8px; align-items: flex-start; }
.loc-note p { margin: 0; }

/* Permanently visible, never collapsing (D13). */
.attribution {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: block; width: 100%; text-align: left;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 0; border-top: 1px solid var(--line);
  padding: 6px 12px; font-size: .68rem; line-height: 1.35; color: var(--text-dim);
}
/**
 * THE CREDITS WRAP. THEY ARE NEVER TRUNCATED. THIS IS A LICENCE RULE.
 *
 * This line used to read `white-space: nowrap; text-overflow: ellipsis`, and on
 * a 320 px screen it produced — measured in Chrome on 2026-09-14, screenshot in
 * `docs/superpowers/evidence/` — "...CC-B...", "...datos obtenidos el 11/0..."
 * and "...Data from OpenStreet...". Three of the four credits were cut.
 *
 * A credit that has been shortened to an ellipsis has not been given:
 *
 *   * IGN's CC BY 4.0 requires the attribution to be retained in a "reasonable
 *     manner"; half a licence name is not the licence name.
 *   * Catastro is NOT CC-BY. The ACCESS DATE is part of the mandatory credit
 *     (Resolución de 23 de marzo de 2011, clause 12), and the date was the
 *     first thing the ellipsis ate — "el 11/0..." is not a date, and a wrong
 *     date is worse than a visibly absent one.
 *   * The OSMF guidelines want the credit legible to anyone who views the map
 *     WITHOUT having to interact with it, which also rules out solving this by
 *     hiding the bar behind a disclosure control.
 *
 * The cost is that the bar no longer has a predictable height. That is handled
 * rather than tolerated: `publishInsets()` in `app.js` measures the real box
 * after every render AND through a ResizeObserver, so `--attrib-h` below always
 * describes the bar that is actually on screen. `overflow-wrap` is the
 * last-resort break for a single token longer than the screen, so nothing can
 * spill sideways out of the viewport instead of wrapping.
 */
.attribution__line { display: block; overflow-wrap: break-word; }
/**
 * One credit must not read as the tail of the one above it.
 *
 * While every credit was a single line, the line break was the separator. Now
 * that they wrap, four credits can be seven lines, and "…4.0 scne.es" sitting
 * directly above "Dirección General del Catastro…" invites reading them as one
 * sentence — which would attribute the Catastro data to IGN's CC BY licence.
 * Two pixels is enough to keep them apart and costs 6 px of map.
 */
.attribution__line + .attribution__line { margin-top: 2px; }

.notice { border-radius: var(--radius); padding: 10px 12px; margin: 10px 0; background: var(--surface-2); }
.notice--error { background: var(--error-bg); color: var(--error-text); }
.notice--stale { border: 1px dashed var(--line); }

.headline { font-size: 2rem; font-weight: 650; line-height: 1.1; }
.pill {
  display: inline-block; font-size: .72rem; padding: 2px 8px;
  border: 1px solid var(--line); border-radius: 999px; color: var(--text-dim); vertical-align: middle;
}

.caveats { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.caveats__title { font-size: .78rem; font-weight: 600; color: var(--text-dim); margin: 0 0 6px; }
.caveats__list { margin: 0; padding-left: 1.1em; }
.caveats__list li { font-size: .8rem; color: var(--text-dim); margin-bottom: 4px; }

.segments { list-style: none; margin: 8px 0 0; padding: 0; }
.segments li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: .85rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.dot--shaded { background: var(--shaded); }
.dot--sunny { background: var(--sunny); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; color: var(--text-dim); }
.legend span { display: flex; align-items: center; gap: 6px; }

.results { list-style: none; margin: 0; padding: 0; }
.results li { border-bottom: 1px solid var(--line); }
.results button { width: 100%; text-align: left; background: none; border: 0; padding: 12px 4px; }
.results strong { display: block; }


.spinner {
  width: 16px; height: 16px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; flex: none;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.switch { display: flex; align-items: center; gap: 10px; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
