/**
 * BK ClinicQ: clinic discovery (Issue 32).
 *
 * The list a patient sees first, on the patient layout. Mobile-first: one column, 44px targets,
 * nothing that needs a hover. Tokens only (every colour is a var(--token) from site.css), which
 * tests/unit/platform/test_ui_shell.py holds this file to.
 *
 * Two rules shape it beyond the layout:
 *
 *   - A sector is never told by colour alone. The badge's word, its shape (a square or a diamond)
 *     and its border (solid or dashed) all differ, so it reads the same in greyscale.
 *   - Open and closed are words first. The weight and colour of the text only repeat what it says.
 */

.discover { --stack-gap: var(--space-5); }

/* ── Messages ───────────────────────────────────────────────── */

.discover .msg { margin-top: var(--space-3); font-size: var(--step--1); }
.discover .msg[hidden] { display: none; }
.discover .msg-muted { color: var(--muted); }
.discover .msg-error {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--danger-ink);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--ink);
}

/* ── The location prompt and the suburb search ───────────────── */

.discover-locate .btn { margin-top: var(--space-2); }

.area-label { display: block; font-weight: 600; margin-bottom: var(--space-2); }
.area-row { display: flex; gap: var(--space-2); }
.area-input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}
.area-input:focus-visible,
.segmented-input:focus-visible + .segmented-option,
.area-suggestion:focus-visible,
.discover a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px var(--focus-ring);
}
.area-hint { margin-top: var(--space-2); font-size: var(--step--1); color: var(--muted); }

.area-suggestions-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.area-suggestion {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-2);
  min-height: var(--tap);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
}
.area-suggestion:hover { border-color: var(--brand); }
.area-suggestion-name { font-weight: 600; }
.area-suggestion-alias { color: var(--muted); }
.area-suggestion-where { flex-basis: 100%; font-size: var(--step--1); color: var(--muted); }

.discover-restart { margin-top: var(--space-4); font-size: var(--step--1); }
/* Links inside a sentence are underlined, so they are links without relying on colour. */
.discover-restart a,
.discover-attribution a { color: var(--brand-deep); text-decoration: underline; text-underline-offset: .15em; }

/* ── Filters ────────────────────────────────────────────────── */

.discover-results > * + * { margin-top: var(--space-4); }
.discover-results h2 { font-size: var(--step-2); }

.discover-filters { display: grid; gap: var(--space-3); }

/* The filters as one compact row (Issue 257): the Filters button with its count, then List or Map.
   The groups themselves are in the Filters sheet, so the first clinic starts near the top of a
   phone's screen. */
.filter-bar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.filter-button { gap: var(--space-2); }
.filter-button::-webkit-details-marker { display: none; }
.filter-button { list-style: none; }
.filter-button .icon { width: 1.15rem; height: 1.15rem; }
.filter-button .bar-badge { position: static; }
.view-toggle { flex: 0 1 11rem; }
.discover-filters .sheet-body { display: grid; gap: var(--space-4); }
/* Without JavaScript the sheet opens in place, under the bar, as a card. */
.discover-filters .sheet:not([data-sheet-ready])[open] { flex-basis: 100%; }
.discover-filters .sheet:not([data-sheet-ready])[open] > .sheet-panel {
  margin-top: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
}
.filter-bar:has(.sheet:not([data-sheet-ready])[open]) { flex-wrap: wrap; }

/* A filter in use, as a chip that removes itself: its words, and a cross that says so. */
.filter-chips { display: flex; flex-wrap: wrap; gap: var(--space-2); list-style: none; margin: 0; padding: 0; }
.filter-chips[hidden] { display: none; }
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 2rem;
  padding: 0 var(--space-2) 0 var(--space-3);
  border: 1px solid var(--brand);
  border-radius: var(--radius-pill);
  background: var(--brand-soft);
  color: var(--brand-deep);
  font-size: var(--step--1);
  font-weight: 600;
}
.filter-chip:hover { background: var(--brand-tint); }
.filter-chip-x { width: 1rem; height: 1rem; }

/* A segmented control built from real radio buttons: arrow keys move between the options of a
   group, and a browser without scripts submits them with the form. The legend is visible and sits
   above its group, so "Within" and "Sort by" are read before their options. */
.segmented { margin: 0; padding: 0; border: 0; min-width: 0; }
.segmented-legend { margin-bottom: var(--space-1); padding: 0; font-size: var(--step--1); color: var(--muted); }
.segmented-options { display: grid; }
.segmented-input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-option {
  display: grid; place-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-1);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--ink);
  text-align: center;
  cursor: pointer;
}
.segmented-2 { grid-template-columns: repeat(2, 1fr); }
.segmented-3 { grid-template-columns: repeat(3, 1fr); }
.segmented-4 { grid-template-columns: repeat(4, 1fr); }
.segmented-5 { grid-template-columns: repeat(5, 1fr); }
.segmented-option + .segmented-input + .segmented-option { border-left: 0; }
.segmented-options .segmented-input:first-of-type + .segmented-option { border-radius: var(--radius) 0 0 var(--radius); }
.segmented-options .segmented-option:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.segmented-input:checked + .segmented-option {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: .25em;
}

/* ── Results ────────────────────────────────────────────────── */

.results-loading { display: none; }
.results-loading.htmx-request { display: block; }
.results.htmx-request { opacity: .5; }

.results-summary { font-weight: 600; }
.results-note { margin-top: var(--space-1); font-size: var(--step--1); color: var(--muted); }

.results-error h3 { font-size: var(--step-1); }
.results-error p { margin-top: var(--space-2); color: var(--muted); }
.results-error .btn { margin-top: var(--space-3); }

.clinic-list { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-3); }

.clinic-card {
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.clinic-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.clinic-card-name { font-size: var(--step-1); line-height: 1.3; overflow-wrap: anywhere; }
.clinic-card-name a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--line); text-underline-offset: .2em; }
.clinic-card-name a:hover { text-decoration-color: var(--brand); }
.clinic-card-address { margin-top: var(--space-1); font-size: var(--step--1); color: var(--muted); }

.clinic-facts { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); margin: var(--space-3) 0 0; }
.clinic-fact { min-width: 0; }
.clinic-fact-wide { grid-column: 1 / -1; }
.clinic-fact dt { font-size: var(--step--2); text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.clinic-fact dd { margin: 0; overflow-wrap: anywhere; }

.open-state.is-open { font-weight: 600; color: var(--brand-deep); }
/* Closing soon is a warning: said in its own words first ("Closing soon · closes 16:00"), then drawn
   in the warning tone, so the colour is never the only sign (Issue 257). */
.open-state.is-closing-soon { font-weight: 600; color: var(--warn-ink); }
.open-state.is-closed { color: var(--ink); }

.clinic-list-more { list-style: none; }

/* The sector badge: a word, a shape and a border style, so colour is never the only difference. */
.sector-badge {
  flex: none;
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .15rem .55rem;
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-pill);
  font-size: var(--step--1);
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
}
.sector-badge-icon { width: .75rem; height: .75rem; }
.sector-badge-square { border-style: solid; }
.sector-badge-square .sector-badge-icon { fill: currentColor; }
.sector-badge-diamond { border-style: dashed; }
.sector-badge-diamond .sector-badge-icon { fill: none; stroke: currentColor; stroke-width: 1.6; }

.discover-attribution { font-size: var(--step--2); color: var(--muted); text-align: center; }

/* ── The clinic detail page (Issue 35) ──────────────────────── */

.clinic-detail { overflow-wrap: anywhere; }

/* The head (Issue 260), the same on every tab: a back arrow, the name and the badge on one row, then
   the open state and Join the queue. Compact, so each panel's first line is on the first screen. */
.clinic-head { display: grid; gap: var(--space-3); }
.clinic-head-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: var(--space-2) var(--space-3); }
.clinic-back {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  margin-left: calc(-1 * var(--space-2));
  border-radius: 50%;
  color: var(--ink);
}
.clinic-back:hover { background: var(--bg-soft); color: var(--brand-deep); }
.clinic-name { align-self: center; font-size: var(--step-2); line-height: 1.2; }
.clinic-head-top .sector-badge { align-self: center; }
.clinic-address { color: var(--muted); }

.clinic-live { display: grid; gap: var(--space-3); }
.clinic-open { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--space-3); }
.clinic-open-state { font-size: var(--step-1); font-weight: 600; }
.clinic-open-state.is-open { color: var(--brand-deep); }
.clinic-open-today { color: var(--muted); }
.clinic-join .btn:disabled { opacity: 1; background: var(--bg-soft); color: var(--muted); border-color: var(--line); }
.clinic-join-reason { margin-top: var(--space-2); font-size: var(--step--1); color: var(--ink); }

.clinic-panel h2 { font-size: var(--step-2); }
.clinic-panel h2:focus { outline: none; }
.clinic-panel h2:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
/* One panel at a time once clinic-tabs.js runs; with no script all four show in order. */
.clinic-panel[hidden] { display: none; }
.clinic-payment { margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--line-soft); }
.clinic-payment h3 { font-size: var(--step-1); }
.clinic-queues-total { margin-top: var(--space-1); font-weight: 600; }
.queue-rows { list-style: none; margin: var(--space-3) 0 0; padding: 0; display: grid; gap: var(--space-2); }
.queue-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-1);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.queue-row-name { font-weight: 600; }
.queue-row-figure { font-size: var(--step--1); }
.queue-row-wait { color: var(--muted); }
.queue-row-tag {
  display: inline-block;
  padding: 0 .4rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  font-size: var(--step--2);
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.clinic-updated { margin-top: var(--space-2); font-size: var(--step--2); color: var(--muted); }

.clinic-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.clinic-actions .btn { flex: 1 1 10rem; }
.clinic-hint { margin-top: var(--space-3); font-size: var(--step--1); color: var(--muted); }

.hours-list { display: grid; gap: var(--space-1); margin: 0; }
.hours-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 var(--space-3); padding: var(--space-1) 0; border-bottom: 1px solid var(--line-soft); }
.hours-row dd { margin: 0; }
.hours-row.is-today { font-weight: 600; }
.hours-today { font-weight: 400; color: var(--muted); }

.service-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.service-name { font-weight: 600; }
.service-description { font-size: var(--step--1); color: var(--muted); }

@media (max-width: 22rem) {
  .clinic-facts { grid-template-columns: 1fr; }
}


/* ── Payment and medical aid (Issue 37) ─────────────────────── */

.payment-filter { margin: 0; padding: var(--space-3); border: 1px dashed var(--line); border-radius: var(--radius); }
.payment-notice { display: block; margin-top: var(--space-1); font-size: var(--step--1); color: var(--muted); }
.payment-notice-strong { margin: 0 0 var(--space-3); padding: var(--space-2) var(--space-3); border-left: 3px solid var(--warn-ink); background: var(--warn-bg); color: var(--ink); }
.check-row { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin-top: var(--space-2); }
.check-option { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--tap); cursor: pointer; }
.check-option input { width: 1.5rem; height: 1.5rem; flex: none; accent-color: var(--brand); }
.scheme-picker { margin-top: var(--space-2); }
.scheme-picker summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; font-weight: 600; }
.scheme-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr)); gap: var(--space-1) var(--space-3); }
.payment-lines { margin: 0; padding-left: 1.1rem; display: grid; gap: var(--space-1); }
.stale-tag {
  display: inline-block;
  margin-top: var(--space-2);
  padding: 0 .45rem;
  border: 1px solid var(--warn-ink);
  border-radius: var(--radius-pill);
  font-size: var(--step--2);
  font-weight: 600;
  color: var(--warn-ink);
  background: var(--warn-bg);
}
.scheme-picker summary:focus-visible,
.check-option input:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }


/* ── The map (Issue 33) ─────────────────────────────────────── */

/* In map view the cards stay in the page, because the map is drawn from them, but only the map and
   the preview are shown. A tile failure removes .is-map and the list comes back. */
.discover-results.is-map #results .clinic-list,
.discover-results.is-map .results-summary + .results-note { display: none; }

.discover-map[hidden] { display: none; }
.map-canvas {
  height: min(60vh, 26rem);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  overflow: hidden;
}
.map-canvas .leaflet-control-attribution { font-size: var(--step--2); }
.map-canvas .leaflet-control-attribution a { color: var(--brand-deep); text-decoration: underline; }

.map-legend { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); font-size: var(--step--1); }
.map-legend li { display: inline-flex; align-items: center; gap: var(--space-1); }
.map-legend-icon svg { width: .9rem; height: .9rem; display: block; }
.map-status, .map-note { margin-top: var(--space-2); font-size: var(--step--1); color: var(--muted); }

/* A pin: a shape (square or diamond) in the sector's colour with a light outline, so it reads on any
   tile and in greyscale. The origin is a ring, not a pin. */
.map-pin { background: transparent; border: 0; }
.map-pin svg { width: 100%; height: 100%; display: block; overflow: visible; }
.map-pin-square { color: var(--brand); }
.map-pin-diamond { color: var(--warn-ink); }
.map-pin-square svg, .map-pin-diamond svg { fill: currentColor; stroke: var(--surface); stroke-width: 1.4; }
.map-pin-origin { color: var(--ink); }
.map-pin-origin svg { fill: var(--surface); stroke: currentColor; stroke-width: 2.4; }
.map-pin:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; border-radius: 2px; }

.map-cluster {
  display: grid; place-items: center;
  border: 2px solid var(--surface);
  border-radius: 50%;
  background: var(--ink);
  color: var(--surface);
  font-weight: 700;
  font-size: var(--step--1);
}
.map-cluster:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* A clinic's name on its pin (Issue 258): part of the pin's own icon, centred above it, a solid label
   with a border rather than text on the tiles, so it reads on any map in both themes. The full name is
   the pin's title and the preview's; this one is cut at 28 characters and never wider than the cell
   discover-map.js clusters by (LABEL_CELL). */
.map-pin .map-label {
  position: absolute;
  bottom: calc(100% + .25rem);
  left: 50%;
  transform: translateX(-50%);
  max-width: 12.5rem;
  padding: .125rem .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-card);
  font: 600 var(--step--2) / 1.35 var(--font);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

/* The map's frame holds the Full screen button over its top-right corner. It is its own stacking
   context: Leaflet gives its panes and controls z-indexes of 400 to 1000, which would otherwise paint
   the map over the page's fixed bottom bar (Issue 255). */
.map-frame { position: relative; isolation: isolate; }
.map-fullscreen {
  position: absolute;
  top: var(--space-2);
  right: var(--space-2);
  z-index: 800;
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-card);
  cursor: pointer;
}
.map-fullscreen[hidden] { display: none; }
.map-fullscreen svg { width: 1.25rem; height: 1.25rem; }
.map-fullscreen-exit, .is-full .map-fullscreen-enter { display: none; }
.is-full .map-fullscreen-exit { display: block; }

/* Full screen: the whole section fills the screen, the map takes what the legend and the preview leave.
   The Fullscreen API gives :fullscreen; where the browser has none (Safari on iPhone), .is-full fixes
   the section over the page and its bottom bar, and the page behind it stops scrolling. */
.discover-map.is-full {
  display: flex;
  flex-direction: column;
  padding: var(--space-2);
  padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
  background: var(--bg);
}
.discover-map.is-full:not(:fullscreen) { position: fixed; inset: 0; z-index: 40; margin: 0; }
.discover-map.is-full .map-frame { flex: 1; min-height: 0; }
.discover-map.is-full .map-canvas { height: 100%; }
.discover-map.is-full .map-preview { max-height: 45vh; overflow: auto; }
html.map-is-full, html.map-is-full body { overflow: hidden; }

.map-preview { margin-top: var(--space-3); }
.map-preview .clinic-card { list-style: none; }
.map-preview-close { margin-top: var(--space-2); }

.map-fallback[hidden] { display: none; }
/* View queue, then Directions (Issue 259): side by side down to 320 px, stacked below it, each a 44 px
   target. The padding is tighter than a page button's so both fit a 320 px card. */
.clinic-card-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-3); }
.clinic-card-actions .btn { flex: 1 1 6.5rem; min-height: var(--tap); padding-inline: var(--space-3); white-space: nowrap; }
@media (max-width: 19.99rem) { .clinic-card-actions .btn { flex-basis: 100%; } }

/* ── Join now | Book a time (Issue 261) ─────────────────────── */

/* The head the join and booking pages share: the back arrow and the clinic's name (the clinic page's
   own head row), then a segmented control of two links. The shown page's option is filled and
   underlined, so it is marked by more than colour. */
.clinic-action-head { display: grid; gap: var(--space-3); }
.action-toggle { display: grid; grid-template-columns: 1fr 1fr; }
.action-toggle-option {
  display: grid;
  place-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-2);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: var(--step--1);
  font-weight: 500;
  text-align: center;
}
.action-toggle-option:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.action-toggle-option:last-child { border-left: 0; border-radius: 0 var(--radius) var(--radius) 0; }
.action-toggle-option:hover { color: var(--brand-deep); }
.action-toggle-option[aria-current="page"] {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: .25em;
}

/* ── Joining a queue (Issue 200) ────────────────────────────── */

.join .check-option { display: flex; overflow-wrap: anywhere; }
.join-queue { align-items: flex-start; padding-block: var(--space-2); }
.join-queue input { margin-top: .1rem; }
.join-queue-text { display: grid; gap: .1rem; min-width: 0; }
.join-queue-name { font-weight: 600; }
.join-queue-figures { font-size: var(--step--1); color: var(--muted); }
.join-reason { resize: vertical; }
/* The notifications question is a full sentence: read as text, not as a bold label. */
.join-choices legend { font-weight: 400; }
.join-step h2:focus { outline: none; }
.join-step h2:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ── Booking a time (Issue 81) ───────────────────────────────── */
.book-times { display: grid; gap: .5rem; margin: .75rem 0; }
.book-reference { font-size: 1.1rem; }
.book-list { list-style: none; padding: 0; margin: 0; display: grid; gap: .75rem; }
.book-item { display: grid; gap: .35rem; padding-block: .5rem; border-top: 1px solid var(--line); }
.book-item:first-child { border-top: 0; }
.book-item-when { font-weight: 600; margin: 0; }

/* Who this visit is for (Issue 84): the picker, and the panel that adds somebody. */
.who-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.who-add {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line-soft);
}
