:root {
  color-scheme: light;

  /* NAAN brand palette */
  --brand-main:      #584f87;   /* main brand purple */
  --brand-blue-1:     #E1F0FB;
  --brand-blue-2:     #EBF5FC;
  --brand-blue-3:     #ABD5F4;
  --brand-off-white:  #F8F8F8;
  --brand-grey:       #C6CED4;
  --brand-grey-mid:   #7C7C8C;
  --brand-dark:       #333333;

  /* Darkened companion to --brand-grey-mid, for secondary text only. The brand grey
     itself only reaches 4.1:1 against white, which fails WCAG 1.4.3 (4.5:1) at the
     12-13px sizes it was being used at; this reaches 5.2:1 while staying the same
     hue. --brand-grey-mid is still used as-is for non-text purposes, where no
     contrast minimum applies. */
  --brand-grey-text:  #6B6B7A;

  --surface-page:   #ffffff;
  --surface-card:   #ffffff;
  --text-primary:   var(--brand-dark);
  --text-secondary: var(--brand-grey-text);
  --text-muted:     var(--brand-grey-text);
  --border:         var(--brand-grey);
  --gridline:       var(--brand-blue-1);
  --focus-ring:     var(--brand-main);

  /* Map status colours - one hue (brand purple) for NAAN coverage, a deeper
     brand-derived blue for non-member provision, brand off-white for none.
     These variables are also what the legend swatches use directly; the
     map itself (app.js) keeps its own copy since Leaflet can't read CSS
     custom properties, so keep the two in sync if either changes. */
  --status-full:        var(--brand-main);
  --status-partial:     #ACA7C3;
  --status-non-member:  #7AB5E0;
  --status-none:        var(--brand-off-white);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text-primary);
  background: var(--surface-page);
}

.naan-map-root {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;   /* avoids the mobile browser-chrome gap where supported */
  min-height: 480px;
  overflow: hidden;
}

/* Header */
.header-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  z-index: 1100;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--surface-card);
  border-bottom: 1px solid var(--border);
}
.header-bar img {
  height: 34px;
  width: auto;
  display: block;
}
.header-bar .header-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

#map {
  position: absolute;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--surface-page);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  overflow: hidden;
  white-space: nowrap;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

/* Lets keyboard users jump past the 189 focusable map areas in one keystroke
   (WCAG 2.4.1). Hidden until focused. */
.skip-map-link {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 1200;
  transform: translateY(-200%);
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #ffffff;
  background: var(--brand-main);
  border-radius: 6px;
  text-decoration: underline;
}
.skip-map-link:focus {
  transform: translateY(0);
  outline: 3px solid var(--brand-dark);
  outline-offset: 2px;
}

/* Search box */
.search-box {
  position: absolute;
  top: 68px;
  left: 12px;
  /* Above Leaflet's own controls (.leaflet-top is z-index 1000), which otherwise
     tie on z-index and win on source order, painting the zoom buttons over the
     left-hand end of the search field. The zoom control is also moved clear of the
     search box further down - see the Leaflet overrides section. */
  z-index: 1050;
  width: min(300px, calc(100% - 24px));
}
.search-box input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-card);
  color: var(--text-primary);
  box-shadow: 0 1px 4px rgba(51,51,51,0.12);
}
.search-box input::placeholder {
  color: var(--text-secondary);
  opacity: 1;
}
.search-box input:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}
.search-results {
  margin-top: 4px;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(51,51,51,0.18);
}
.search-option {
  padding: 8px 12px;
  font-size: 14px;
  color: var(--text-primary);
  cursor: pointer;
}
/* The keyboard-highlighted option needs to be identifiable by more than a pale
   background tint, which is why there is a left bar as well as the fill. */
.search-option:hover,
.search-option[aria-selected="true"] {
  background: var(--brand-blue-1);
  box-shadow: inset 3px 0 0 var(--brand-main);
}

/* "Only show areas where you can volunteer" toggle, sitting under the search box. */
.map-filter {
  position: absolute;
  top: 113px;
  left: 12px;
  z-index: 1050;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: min(300px, calc(100% - 24px));
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.3;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(51,51,51,0.12);
}
.map-filter input {
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--brand-main);
}
.map-filter label {
  cursor: pointer;
  color: var(--text-primary);
}
.map-filter input:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Legend */
.legend {
  position: absolute;
  /* Clear of the attribution along the bottom. At narrower desktop widths the licence
     acknowledgement wraps to three lines, and once it shifts left to clear the drawer
     it runs underneath the legend, so 16px was not enough room. */
  bottom: 60px;
  left: 12px;
  z-index: 1000;
  background: var(--surface-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  box-shadow: 0 1px 4px rgba(51,51,51,0.12);
  max-width: 240px;
}
.legend-title {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 2px 0;
}
.legend-note {
  margin: 8px 0 0;
  padding-top: 6px;
  border-top: 1px solid var(--gridline);
  font-size: 11px;
  line-height: 1.4;
}
.legend-swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  border: 1px solid var(--brand-grey-mid);
}
.legend-swatch[data-status="full"] { background: var(--status-full); }
.legend-swatch[data-status="partial"] { background: var(--status-partial); }
.legend-swatch[data-status="non-member"] { background: var(--status-non-member); }
.legend-swatch[data-status="none"] { background: var(--status-none); }
.legend-swatch[data-status="filtered-out"] { background: #ffffff; }

/* Only meaningful while the volunteering filter is on, so it stays out of the way the
   rest of the time rather than describing something nobody can see. */
.legend-row-filtered { display: none; }
.naan-map-root.filtering-volunteering .legend-row-filtered { display: flex; }

/* Detail panel */
.panel {
  position: absolute;
  top: 56px;
  right: 0;
  bottom: 0;
  z-index: 1000;
  width: min(380px, 100%);
  background: var(--surface-card);
  border-left: 1px solid var(--border);
  box-shadow: -2px 0 10px rgba(51,51,51,0.10);
  overflow-y: auto;
  /* Closed by default at every width; app.js opens it on load where there is room
     for it beside the map. Until November 2026 these two rules lived only inside the
     640px media query, so on a desktop the drawer could never be dismissed and the
     close button appeared to do nothing.
     visibility is toggled as well as the transform so that a closed drawer leaves
     the tab order and the accessibility tree, rather than sitting just off-screen
     where a keyboard user could still tab into it. */
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.2s ease, visibility 0s linear 0.2s;
}
.panel.panel-visible {
  transform: translateX(0);
  visibility: visible;
  transition: transform 0.2s ease, visibility 0s;
}
.panel:focus { outline: none; }
.panel-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.panel-close:hover { background: var(--brand-blue-2); }
.panel-close:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.panel-content {
  padding: 44px 20px 24px;
}
.panel-intro {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 19px;
  color: var(--brand-main);
}
/* The heading is focused programmatically when an area is opened, so that screen
   readers announce the new area. Only show a ring when the user is actually
   navigating by keyboard. */
.panel h2:focus { outline: none; }
.panel h2:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
  border-radius: 2px;
}
.panel-police {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0 0 16px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
  margin: 0 0 14px;
}
.status-badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.status-badge[data-status="full"]        { color: var(--brand-main);     background: var(--brand-blue-2); }
.status-badge[data-status="partial"]     { color: var(--brand-main);     background: var(--brand-blue-1); }
.status-badge[data-status="non-member"]  { color: var(--brand-dark);     background: var(--brand-blue-1); }
.status-badge[data-status="none"]        { color: var(--text-secondary); background: var(--brand-off-white); }

.group-section {
  border-top: 1px solid var(--gridline);
  padding: 14px 0;
}
.group-section:first-of-type { border-top: none; }
.group-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.scheme-card {
  margin-bottom: 12px;
  font-size: 14px;
  line-height: 1.5;
}
.scheme-card:last-child { margin-bottom: 0; }
.scheme-name {
  font-weight: 600;
  margin: 0 0 2px;
}
.scheme-meta {
  color: var(--text-secondary);
  font-size: 13px;
}
.scheme-meta a {
  color: var(--text-primary);
  text-decoration: underline;
}
.scheme-meta a:hover { color: var(--brand-main); }
.scheme-meta a:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

.member-yes, .member-no, .member-unknown {
  font-weight: 600;
  color: var(--text-primary);
}
.member-yes::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 4px;
  background: var(--brand-main);
}
.no-provider {
  color: var(--text-muted);
  font-size: 14px;
  font-style: italic;
}

/* Data caveat and "tell us about a change" address, under the introduction and under
   every area's details. Set apart by a rule so it reads as a note about the data
   rather than as part of the provision itself. */
.panel-disclaimer {
  margin: 18px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--gridline);
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.panel-disclaimer a {
  color: var(--brand-main);
  text-decoration: underline;
}
.panel-disclaimer a:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Leaflet overrides */
.leaflet-container {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--surface-page);
}
.area-tooltip {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

/* Leaflet puts the zoom control at the top left, which is exactly where the search
   box sits. Push it down so the two no longer share the same space - previously the
   zoom-out button and the left-hand end of the search field overlapped, and which
   one you actually clicked depended on paint order. */
/* Clear of both the search box and the volunteering toggle stacked beneath it. */
.leaflet-top .leaflet-control-zoom {
  margin-top: 118px;
}

/* Each area is given tabindex="0" and role="button" by app.js. Browsers do not
   draw a usable default focus ring on SVG paths, so this supplies one; app.js also
   thickens the area's own outline on focus, which is what actually shows through on
   browsers that ignore outline on SVG. */
.leaflet-interactive:focus {
  outline: 3px solid var(--brand-dark);
  outline-offset: 2px;
}
.leaflet-interactive:focus:not(:focus-visible) {
  outline: none;
}

/* The boundary licence acknowledgement lives here (see BOUNDARY_ATTRIBUTION in
   app.js), so it needs to stay readable rather than being the usual near-invisible
   map credit. */
.leaflet-control-attribution {
  font-size: 11px;
  line-height: 1.4;
  max-width: min(420px, 60vw);
  background: rgba(255,255,255,0.92);
  color: var(--text-primary);
}

/* Leaflet puts the attribution bottom right, which is exactly where the details
   drawer sits, so the drawer used to cover it completely. That is not just untidy:
   the attribution carries the ONS boundary licence acknowledgement, which the Open
   Government Licence requires to be shown. Shift it clear while the drawer is open,
   and let it slide back when the drawer is closed. */
.leaflet-bottom.leaflet-right {
  transition: right 0.2s ease;
}
.naan-map-root.drawer-open .leaflet-bottom.leaflet-right {
  right: min(380px, 100%);
}
.leaflet-control-attribution a { color: var(--brand-main); }

.leaflet-bar a:focus-visible,
.leaflet-control-attribution a:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

@media (max-width: 640px) {
  .panel { width: 100%; }

  /* On a phone the drawer covers the whole map, so it behaves like a full screen
     view rather than a side panel. The search box and the volunteering toggle sit
     above it on z-index, and the legend ties on z-index but comes later in the
     source, so all three were painting straight over the area's details and making
     them unreadable. None of them is any use while the drawer is covering the map,
     so take them out of the way until it is closed.

     display:none rather than hiding them visually, so they also leave the tab order:
     a control a keyboard user can reach but cannot see is worse than one that is
     plainly gone. They come straight back when the drawer closes. */
  .naan-map-root.drawer-open .search-box,
  .naan-map-root.drawer-open .map-filter,
  .naan-map-root.drawer-open .legend { display: none; }
  /* Full width here, so shifting the attribution out from under the drawer would push
     it off the screen entirely. An open drawer covers the map on a phone anyway. */
  .naan-map-root.drawer-open .leaflet-bottom.leaflet-right { right: 0; }
  /* Narrow screens make the attribution wrap to three full-width lines across the
     bottom of the map, which the legend used to sit on top of. Lift the legend clear
     of it rather than shrinking the licence text to the point of illegibility. */
  .legend { max-width: 180px; font-size: 11px; }
  .legend-note { display: none; }
  /* Bigger tap target on a phone, where the panel covers the whole screen and this is
     the only way out of it. */
  .panel-close { width: 44px; height: 44px; }
  /* Keep the h1 for screen readers even though there is no room to show it. */
  .header-bar .header-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    white-space: nowrap;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
  }
  .leaflet-control-attribution { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .panel.panel-visible { transition: none; }
  .leaflet-bottom.leaflet-right { transition: none; }
  .skip-map-link { transition: none; }
}

/* Windows high contrast / forced colours: the status fills are replaced by the OS
   palette, so make sure borders and focus rings still resolve to something visible. */
@media (forced-colors: active) {
  .legend-swatch { border: 1px solid CanvasText; forced-color-adjust: none; }
  .skip-map-link:focus,
  .search-box input:focus-visible,
  .panel-close:focus-visible,
  .leaflet-interactive:focus { outline-color: Highlight; }
}
