/* App layout and components. Theme tokens and primitives are in theme.css. */

:root[data-mode="dark"] { color-scheme: dark; }

h1, h2 { font-weight: normal; }

:focus-visible {
  outline: 2px solid var(--brand-ink);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Full height column: the update bar, when there is one, then the map. */
body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

#app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.map {
  position: absolute;
  inset: 0;
  /* Leaflet's panes use z-index 400 to 700. Isolating the map keeps them
     inside it, under the floating panels. */
  z-index: 0;
  isolation: isolate;
}

/* Leaflet's stylesheet paints the container grey and sets its own font. */
.map.leaflet-container {
  background: transparent;
  font: inherit;
}

/* Tiles slightly see-through, so the brand tint of the page shows in the
   street map too and it follows the swatch as well as the mode. */
.leaflet-tile-pane {
  opacity: 0.85;
  transition: filter 0.25s ease;
}

/* OSM has one tile style. Dark mode inverts it, turning hues back round so
   water stays blue and parks green, and dims it under the network. */
:root[data-mode="dark"] .leaflet-tile-pane {
  filter: invert(1) hue-rotate(180deg) brightness(0.85) contrast(0.85);
}

/* Floating panels over the map, in the standard 720px column. */
.overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px;
  padding-top: max(14px, env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.overlay > * { pointer-events: auto; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 10px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 7px;
}
.brand-name {
  font-size: 1.2rem;
  color: var(--brand-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Search and line toggles. */
.controls {
  position: relative;
  padding: 8px;
}

.controls-row {
  display: flex;
  gap: 8px;
}

.search {
  flex: 1 1 auto;
  min-width: 0;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 4px 0 12px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
}
.search-field:focus-within {
  outline: 2px solid var(--brand-ink);
  outline-offset: 1px;
}
.search-icon {
  display: inline-flex;
  color: var(--muted-strong);
}
.search-icon svg { width: 18px; height: 18px; }

.search-field input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--ink);
  /* 16px stops iOS zooming the page on focus. */
  font-size: 1rem;
  outline: none;
}
.search-field input::placeholder {
  color: var(--muted-strong);
  opacity: 1;
}
.search-field input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-field .icon-btn.small { flex-shrink: 0; }
.search-field .icon-btn.hidden { display: none; }

.lines-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 42px;
  padding: 0 12px;
  border-radius: 14px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.9rem;
  transition: background 0.15s ease, color 0.15s ease;
}
.lines-toggle svg { width: 18px; height: 18px; }
.lines-count {
  font-size: 0.78rem;
  color: var(--muted-strong);
}
.lines-chev {
  display: inline-flex;
  transition: transform 0.2s ease;
}
.lines-chev svg { width: 16px; height: 16px; }
.lines-toggle[aria-expanded="true"] {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.lines-toggle[aria-expanded="true"] .lines-count { color: var(--on-brand); }
.lines-toggle[aria-expanded="true"] .lines-chev { transform: rotate(180deg); }

/* Dropdowns under the controls card: search results and the line list. */
.dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: min(55vh, 440px);
  overflow-y: auto;
  padding: 8px;
  background: var(--surface-strong);
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.2s ease, visibility 0s linear 0s;
}
.dropdown.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-6px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
}

.results {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 12px;
  text-align: left;
  transition: background 0.15s ease;
}
.result:hover,
.result:focus-visible {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}
.result-codes {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  flex-shrink: 0;
  width: 108px;
}
.result-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.result-name {
  font-size: 0.95rem;
  color: var(--ink);
}
.result-alt {
  font-size: 0.8rem;
  color: var(--muted-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-empty {
  padding: 10px;
  font-size: 0.9rem;
  color: var(--muted-strong);
}

.line-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 6px;
}
.line-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--muted-strong);
  font-size: 0.88rem;
  text-align: left;
  transition: color 0.15s ease, background 0.15s ease;
}
.line-chip[aria-pressed="true"] { color: var(--ink); }

/* Filled when the line is showing, hollow when it is not, so the state
   does not rest on text colour alone. */
.line-swatch {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 3px solid var(--line);
  background: transparent;
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--ink) 60%, transparent);
  transition: background 0.15s ease;
}
.line-chip[aria-pressed="true"] .line-swatch { background: var(--line); }

.text-btn {
  margin-top: 8px;
  padding: 6px 4px;
  font-size: 0.85rem;
  color: var(--brand-ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Station code badge, in the line's own colour. */
.code-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 0.78rem;
  line-height: 1.4;
  letter-spacing: 0.02em;
  background: var(--line, var(--surface-strong));
  color: var(--line-ink, var(--ink));
  white-space: nowrap;
}

/* Station markers. The marker element is the dot; the tag hangs off it, so
   the dot, not the whole label, sits on the station's coordinate. */
.stn {
  width: 12px;
  height: 12px;
}
.stn-interchange {
  width: 16px;
  height: 16px;
}
.stn-hidden { display: none; }

.stn-dot {
  position: absolute;
  inset: 0;
  padding: 0;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--ink);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stn-interchange .stn-dot { border-width: 3px; }

/* Zoomed out, a phone shows the whole network in about 300px. */
[data-small-dots] .stn-dot {
  inset: 2px;
  border-width: 1.5px;
}
[data-small-dots] .stn-interchange .stn-dot {
  inset: 3px;
  border-width: 2px;
}
/* A finger sized target around a 12px dot. */
.stn-dot::before {
  content: "";
  position: absolute;
  inset: -10px;
  border-radius: 50%;
}
.stn-dot:hover { transform: scale(1.25); }

/* Raised above its neighbours by setZIndexOffset in js/map.js; Leaflet
   sets marker z-index inline, so CSS cannot. */
.stn-selected .stn-dot {
  transform: scale(1.35);
  box-shadow: 0 0 0 3px var(--brand-ink);
}

.stn-tag {
  position: absolute;
  left: calc(100% + 6px);
  top: 50%;
  transform: translateY(-50%);
  display: none;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  pointer-events: none;
}
.stn-codes {
  display: flex;
  gap: 2px;
}
.stn-name {
  display: none;
  font-size: 0.82rem;
  color: var(--ink);
  /* A halo in the page colour keeps names readable where they cross a line. */
  text-shadow:
    0 0 2px var(--bg),
    0 0 3px var(--bg),
    0 0 5px var(--bg);
}

[data-tier="1"] .stn-tag,
[data-tier="2"] .stn-tag,
.stn-selected .stn-tag { display: flex; }

/* The selected label sits on its own pill, above any neighbour it overlaps. */
.stn-selected .stn-tag {
  padding: 3px 10px 3px 4px;
  border-radius: 999px;
  background: var(--surface-strong);
  border: 1px solid var(--surface-border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
[data-tier="2"] .stn-name,
.stn-selected .stn-name { display: inline; }

/* Zoom and fit. */
.map-controls {
  position: absolute;
  right: 14px;
  top: 50%;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transform: translateY(-50%);
}
.map-controls .icon-btn { box-shadow: var(--shadow); }
/* .icon-btn's display would otherwise beat the hidden attribute. */
.map-controls .icon-btn[hidden] { display: none; }

/* Station detail card. */
.detail {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 12;
  max-width: 692px;
  margin: 0 auto;
  padding: 16px 18px 18px;
  background: var(--surface-strong);
  display: flex;
  flex-direction: column;
  gap: 12px;
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0s;
}
.detail.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
}
.detail:focus { outline: none; }
.detail:focus-visible { outline: 2px solid var(--brand-ink); }

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.detail-head h2 {
  font-size: 1.4rem;
  color: var(--brand-ink);
}
.detail-names {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.detail-alt {
  font-size: 1.05rem;
  color: var(--ink);
}
.detail-lines {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.detail-line {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.92rem;
}
.detail-line .code-badge {
  min-width: 52px;
  justify-content: center;
}

/* Data credit, bottom left. */
.map-credit {
  position: absolute;
  left: 8px;
  bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 4;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 0.72rem;
  color: var(--muted);
}

.map-error {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 6;
  width: min(360px, calc(100% - 28px));
  padding: 16px 18px;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--error);
}
.map-error.hidden { display: none; }

/* About modal. */
.about {
  display: flex;
  flex-direction: column;
  gap: 10px;
  font-size: 0.9rem;
  line-height: 1.5;
}
.about-list {
  padding-left: 1.2em;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.about-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}
.footer-heart {
  display: inline-flex;
  width: 15px;
  height: 15px;
  /* Fixed meaning: reads as a heart whatever the brand colour. */
  color: #34c759;
}
.footer-heart svg { width: 100%; height: 100%; }

/* Buttons. */
.btn {
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}
.btn-primary {
  background: var(--brand-fill);
  color: var(--on-brand);
}
.btn-primary:hover { background: var(--brand-fill-strong); }
.btn-quiet {
  color: var(--ink);
  border: 1px solid var(--surface-border);
}

/* Update bar, per update-bar-spec.md. Quieter than the header, full width,
   tinted enough to read as a notice. */
.update-notice {
  flex: none;
  background: color-mix(in srgb, var(--brand-ink) 12%, var(--bg));
  border-bottom: 1px solid var(--surface-border);
  color: var(--ink);
  font-size: 0.875rem;
}
.update-notice-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 720px;
  margin: 0 auto;
  padding: 0.5rem 1rem;
  /* Under the notch on a phone, where the bar is the topmost thing on screen. */
  padding-top: max(0.5rem, env(safe-area-inset-top));
}
.update-notice p { flex: 1 1 auto; min-width: 0; }
.update-notice .btn {
  flex: none;
  padding: 6px 12px;
}

@media (max-width: 480px) {
  .overlay {
    padding: 10px;
    padding-top: max(10px, env(safe-area-inset-top));
    gap: 8px;
  }
  .topbar { padding: 8px 8px 8px 12px; }
  .brand-name { font-size: 1.05rem; }
  .topbar-actions { gap: 6px; }
  .lines-count { display: none; }
  .map-controls { right: 10px; }
  .detail {
    left: 10px;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
  }
  .result-codes { width: 86px; }
  .update-notice-inner { flex-wrap: wrap; }
  .update-notice p { flex-basis: 100%; }
}
