/*
 * Wiki.JE contrast audit layer
 *
 * Loaded after shared and page-specific styles so older templates cannot
 * reintroduce light-only or dark-only text/surface pairs.
 */

/* One outer rail for both Blade shells and every full-width page family. */
:root {
  --jw-content-max:1180px;
  --jw-page-gutter:clamp(16px,4vw,32px);
  --jw-success-ink:#147a45;
  --jw-warning-ink:#8a4b00;
  --jw-danger-ink:#b42336;
}
body:not(.map-mode) > #main {
  width:min(var(--jw-content-max),calc(100% - (2 * var(--jw-page-gutter))))!important;
  max-width:var(--jw-content-max)!important;
  margin-inline:auto!important;
  padding-inline:0!important;
}
body:not(.map-mode) > #main > :is(.design-lab,.home-today-layout,.island-atlas,.parish-guide,.wx,.travel,.airport-page,.flight-page,.whats-on) {
  width:100%!important;
  max-width:none!important;
  margin-inline:0!important;
}
body:not(.map-mode) > #main > :is(.article,.project-page) {
  width:100%!important;
  max-width:none!important;
  margin-inline:0!important;
  padding-inline:0!important;
}
:is(.masthead,.header-inner,.footer,.site-footer) {
  max-width:var(--jw-content-max)!important;
}
.header-inner,
.footer,
.site-footer {
  width:min(var(--jw-content-max),calc(100% - (2 * var(--jw-page-gutter))))!important;
  margin-inline:auto!important;
}

/* Reset and update controls are deliberately available in both shells. */
.footer-cache-reset {
  display:inline-flex!important;
  align-items:center;
  justify-content:center;
  min-height:40px;
  margin:.55rem 0;
  padding:.55rem .85rem;
  border:1px solid var(--lg-separator)!important;
  border-radius:var(--lg-pill)!important;
  background:var(--lg-surface-2)!important;
  color:var(--lg-accent)!important;
  font:600 13px/1 var(--lg-font)!important;
  cursor:pointer;
}
.footer-cache-reset:disabled { opacity:.68; cursor:wait; }
.footer-cache-reset-link {
  display:inline-flex;
  align-items:center;
  min-height:40px;
  margin:.55rem 0;
  padding:.55rem .85rem;
  border:1px solid var(--lg-danger)!important;
  border-radius:var(--lg-pill)!important;
  color:var(--lg-danger)!important;
  font:600 13px/1 var(--lg-font)!important;
  text-decoration:none!important;
}
.footer-cache-reset-link:hover,
.footer-cache-reset-link:focus-visible {
  background:rgb(var(--lg-danger-rgb,255 59 48) / .12)!important;
}

/* Legacy surfaces which can otherwise inherit the wrong colour from body. */
:is(.parish-section,.knowledge-banner,.article-top,.jw-toc,.home-tools,.directory-filters) {
  background:var(--lg-surface-2)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
:is(.parish-section,.knowledge-banner,.article-top,.jw-toc,.home-tools,.directory-filters) :is(h1,h2,h3,h4,strong,dt,dd,label) {
  color:var(--lg-label)!important;
}
:is(.parish-section,.knowledge-banner,.article-top,.jw-toc,.home-tools,.directory-filters) :is(p,small,.small,.muted) {
  color:var(--lg-secondary)!important;
}
.parish-grid a {
  background:var(--lg-surface)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
.parish-grid .icon,
.source-list .icon { color:var(--lg-secondary)!important; }
.knowledge-banner .button,
.parish-section .button { color:#fff!important; }

/* The original homepage hero used light editorial copy on a dark green
   panel. The 5.x shell turns the panel into an adaptive surface. */
.hero {
  background:var(--lg-surface-2)!important;
  color:var(--lg-label)!important;
  border:1px solid var(--lg-separator)!important;
}
.hero :is(.hero-kicker,.hero-copy>p,.hero-suggestions) {
  color:var(--lg-secondary)!important;
}
.hero-suggestions a {
  background:var(--lg-surface)!important;
  border-color:var(--lg-separator)!important;
  color:var(--lg-accent)!important;
}
.hero h1 em { color:var(--lg-accent)!important; }
.hero-search {
  background:var(--lg-surface-2)!important;
  border-color:var(--lg-separator)!important;
  color:var(--lg-label)!important;
}
.hero-search input,
.hero-search input::placeholder { color:var(--lg-label)!important; }
.hero-search input::placeholder { opacity:.62; }
.hero-search button { background:var(--lg-accent)!important; color:#fff!important; }
.card-tag,
.scene-label {
  background:var(--lg-surface-2)!important;
  color:var(--lg-label)!important;
  border:1px solid var(--lg-separator)!important;
}
.save-button {
  background:var(--lg-elevated)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
.save-button[aria-pressed="true"] { color:var(--lg-accent)!important; }
.saved-count { background:var(--lg-nav-selected)!important; color:var(--lg-accent)!important; }

/* Route-specific sheets are injected after the shared glass stylesheet, so
   their old light-only panels need a final adaptive pass here. */
:is(.empty-state,.research-callout,.visit-card,.sidebar-note,.about-card,
    .status-pill,.feature-ledger,.feature-ledger details,.notice) {
  background:var(--lg-surface)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
:is(.empty-state,.research-callout,.visit-card,.sidebar-note,.about-card,
    .status-pill,.feature-ledger,.feature-ledger details,.notice) :is(h1,h2,h3,h4,strong,dt,dd,summary,label) {
  color:var(--lg-label)!important;
}
:is(.empty-state,.research-callout,.visit-card,.sidebar-note,.about-card,
    .status-pill,.feature-ledger,.feature-ledger details,.notice) :is(p,small,.small,.muted) {
  color:var(--lg-secondary)!important;
}
.about-card>p:not(.eyebrow) { color:var(--lg-secondary)!important; }
.draft-banner {
  background:color-mix(in srgb,var(--lg-warning) 14%,var(--lg-surface-2))!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-warning)!important;
}
.reviewed-banner {
  background:color-mix(in srgb,var(--lg-success) 14%,var(--lg-surface-2))!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-success)!important;
}
.notice.error {
  background:color-mix(in srgb,var(--lg-danger) 14%,var(--lg-surface-2))!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-danger)!important;
}
.atlas-chart text { fill:var(--lg-label)!important; stroke:var(--lg-surface)!important; }

/* Reading surfaces and article copy. */
.article-text,
.article-section .lead,
.prose :is(p,li),
.jw-toc,
.jw-toc strong,
.article-top { color:var(--lg-label)!important; }
.article-section .lead,
.article-text { color:var(--lg-secondary)!important; }
.jw-toc a,
.article-top a { color:var(--lg-accent)!important; }
.jw-command-list :is(a,button):is(:hover,.selected,[aria-selected="true"]) {
  background:rgb(var(--lg-accent-rgb) / .14)!important;
  color:var(--lg-label)!important;
}
.jw-connection {
  background:var(--lg-elevated)!important;
  color:var(--lg-label)!important;
  border:1px solid var(--lg-separator)!important;
}
.jw-connection.online {
  background:var(--lg-success)!important;
  color:#071b0d!important;
  border-color:transparent!important;
}
.correction-box {
  background:var(--lg-surface)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
.correction-box :is(p,label) { color:var(--lg-secondary)!important; }

/* Small legacy strips and icon-only actions also need an adaptive foreground. */
.island-strip { color:var(--lg-secondary)!important; border-color:var(--lg-separator)!important; }
.island-strip strong { color:var(--lg-label)!important; }
.island-strip :is(.icon,a) { color:var(--lg-accent)!important; }

/* The interface laboratory contains intentional visual swatches, but its
   text-bearing panels must still follow the selected appearance. */
.lab-hero {
  background:linear-gradient(155deg,var(--lg-surface) 0 62%,var(--lg-surface-2))!important;
  color:var(--lg-label)!important;
}
.lab-rich-backdrop {
  background:linear-gradient(135deg,
    color-mix(in srgb,var(--lg-accent) 20%,var(--lg-surface-2)),
    color-mix(in srgb,var(--lg-warning) 14%,var(--lg-surface-2)))!important;
  color:var(--lg-label)!important;
}

/* Airport and travel status surfaces keep semantic meaning without relying
   on a light-only pastel background. */
:is(.airport-board,.airport-overview,.airport-route-tools,.flight-detail-card,
    .airport-guide details,.destination-card,.airport-card-grid article,
    .flight-advice-grid article,.airport-overview-card,.airport-route-grid a) {
  background:var(--lg-surface)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
:is(.airport-tabs,.airport-dates,.flight-advice-grid article,.flight-status,
    .flight-detail-status) {
  background:var(--lg-surface-2)!important;
  color:var(--lg-label)!important;
}
:is(.airport-card-number,.destination-count) { color:var(--lg-accent)!important; }
:is(.flight-status.complete,.flight-detail-status.complete) {
  background:color-mix(in srgb,var(--lg-success) 20%,var(--lg-surface-2))!important;
  color:var(--jw-success-ink)!important;
}
:is(.flight-status.warning,.flight-detail-status.warning) {
  background:color-mix(in srgb,var(--lg-warning) 20%,var(--lg-surface-2))!important;
  color:var(--jw-warning-ink)!important;
}
:is(.flight-status.danger,.flight-detail-status.danger) {
  background:color-mix(in srgb,var(--lg-danger) 20%,var(--lg-surface-2))!important;
  color:var(--jw-danger-ink)!important;
}
:is(.airport-alert,.airport-alert.warning,.airport-alert.danger) {
  background:color-mix(in srgb,var(--lg-accent) 14%,var(--lg-surface-2))!important;
  color:var(--lg-label)!important;
}
:is(.airport-alert.warning,.airport-alert.danger) { border-left-color:var(--lg-warning)!important; }

/* Leaflet ships with opaque white controls and its own text colours. */
:is(.leaflet-popup-content-wrapper,.leaflet-popup-tip,
    .leaflet-control-layers,.leaflet-bar a,.leaflet-container .leaflet-control-attribution,
    .leaflet-control-scale-line) {
  background:var(--lg-elevated)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
.leaflet-popup-content,
.leaflet-popup-content p,
.leaflet-popup-content a,
.leaflet-container a.leaflet-popup-close-button,
.leaflet-bar a { color:var(--lg-label)!important; }
.leaflet-popup-content a { color:var(--lg-accent)!important; }
.leaflet-bar a:is(:hover,:focus),
.leaflet-container a.leaflet-popup-close-button:is(:hover,:focus) {
  background:var(--lg-surface-2)!important;
  color:var(--lg-accent)!important;
}

/* 5.2 route sweep: these older editorial components still carried their
   original light palette after the shared glass layer was introduced. Keep
   the semantic meaning, but make both the surface and its copy adaptive. */
:is(.empty,.empty-state,.airport-empty,.parish-stats div,.parish-discoveries,
    .parish-today>div,.parish-agenda section,.parish-explore,.parish-shelves section,
    .travel-board,.travel-map-card,.travel-options article,.wx-card,.wx-observations,
    .project-page section) {
  background:var(--lg-surface)!important;
  color:var(--lg-label)!important;
  border-color:var(--lg-separator)!important;
}
:is(.empty,.empty-state,.airport-empty,.parish-stats div,.parish-discoveries,
    .parish-today>div,.parish-agenda section,.parish-explore,.parish-shelves section,
    .travel-board,.travel-map-card,.travel-options article,.wx-card,.wx-observations,
    .project-page section) :is(h1,h2,h3,h4,h5,strong,dt,dd,summary,label) {
  color:var(--lg-label)!important;
}
:is(.empty,.empty-state,.airport-empty,.parish-stats div,.parish-discoveries,
    .parish-today>div,.parish-agenda section,.parish-explore,.parish-shelves section,
    .travel-board,.travel-map-card,.travel-options article,.wx-card,.wx-observations,
    .project-page section) :is(p,li,small,.small,.muted) {
  color:var(--lg-secondary)!important;
}
.parish-discovery-columns>div,
#weather-days button[aria-pressed="true"],
.wx-daylight,
#weather-trend {
  background:var(--lg-surface-2)!important;
  color:var(--lg-label)!important;
}
.opening.open { color:var(--jw-success-ink)!important; }
.opening.closed { color:var(--lg-accent)!important; }
.source-list .icon { color:var(--lg-secondary)!important; }
.prose :is(p,li) { color:var(--lg-secondary)!important; }

/* Interaction quality: keep taps, focus, overflow and motion predictable on
   touch screens and narrow Safari viewports. */
:where(button,a,input,select,textarea,summary) {
  -webkit-tap-highlight-color:transparent;
  touch-action:manipulation;
}
:where(button,a) { overflow-wrap:anywhere; }
:where(.cards,.grid,.lab-grid,.airport-card-grid,.airport-route-grid,
    .destination-grid,.parish-shelves,.parish-discovery-columns,
    .travel-grid,.travel-options,.wx-layout,.wx-overview) > * { min-width:0; }
:is(.airport-table-wrap,.lab-table-wrap,.jw-table-scroll,#weather-hours,
    .map-filter-panel,.lg-sheet-body) { max-width:100%; overscroll-behavior:contain; }
:where(.footer-links,.actions,.airport-jumps,.travel-links,.flight-actions) {
  min-width:0;
}

@media (hover:none), (pointer:coarse) {
  :is(.destination-card,.airport-route-grid a,.airport-card-grid article,
      .card,.place-card,.category-card,.news-list>a,.tool-grid>a,
      .guide-card,.travel-options>article):hover {
    transform:none!important;
    box-shadow:var(--lg-shadow-none,0 1px 2px rgb(0 0 0 / .035))!important;
  }
}

@media (max-width:600px) {
  /* The laboratory and island atlas should feel compact rather than forcing
     a large desktop composition into a phone viewport. */
  .lab-hero { min-height:0!important; }
  .lab-hero h1 { font-size:clamp(42px,12vw,58px)!important; letter-spacing:-2px!important; }
  .atlas-chart text { font-size:clamp(36px,12vw,60px)!important; stroke-width:8px!important; }
  .footer-links {
    display:grid!important;
    grid-template-columns:1fr;
    gap:8px!important;
    align-items:stretch!important;
  }
  .footer-links>a,
  .footer-links>button,
  .footer-cache-reset-link,
  .footer-cache-reset {
    width:100%;
    justify-content:flex-start;
    text-align:left;
  }
  :is(.airport-jumps,.travel-links,.flight-actions) > a,
  :is(.actions,.airport-tool-links) > button,
  :is(.actions,.airport-tool-links) > a { min-height:44px; }
}

@media (prefers-reduced-motion:reduce), html[data-motion="reduce"] {
  *,*::before,*::after {
    animation-duration:.001ms!important;
    animation-iteration-count:1!important;
    scroll-behavior:auto!important;
    transition-duration:.001ms!important;
  }
  ::view-transition-old(root),::view-transition-new(root),
  ::view-transition-group(*) { animation:none!important; }
}

@media (max-width:600px) {
  /* Prevent page families from adding a second, narrower mobile rail. */
  body:not(.map-mode)>#main>:is(.project-page,.parish-guide,.wx,.travel,
      .airport-page,.flight-page,.home-today-layout,.island-atlas) {
    width:100%!important;
    max-width:none!important;
  }
  .jw-breadcrumbs,.breadcrumbs { width:100%!important; }
}

/* Explicit dark and system-dark preferences share the same adaptive rules. */
@media (prefers-color-scheme:dark) {
  :root:not([data-theme="light"]) {
    --jw-success-ink:#63e685;
    --jw-warning-ink:#ffd166;
    --jw-danger-ink:#ff7b73;
  }
  html:not([data-theme="light"]) :is(.parish-section,.knowledge-banner,.article-top,.jw-toc,.lab-hero,.lab-rich-backdrop) {
    color:var(--lg-label)!important;
  }
}

html[data-theme="dark"] {
  --jw-success-ink:#63e685;
  --jw-warning-ink:#ffd166;
  --jw-danger-ink:#ff7b73;
}

@media (forced-colors:active) {
  .footer-cache-reset {
    background:ButtonFace!important;
    color:ButtonText!important;
    border-color:ButtonText!important;
  }
  :is(.parish-section,.knowledge-banner,.article-top,.jw-toc,.lab-hero,
      .airport-board,.airport-overview,.airport-route-tools,.flight-detail-card,
      .leaflet-popup-content-wrapper,.leaflet-popup-tip) {
    background:Canvas!important;
    color:CanvasText!important;
    border-color:CanvasText!important;
  }
  :is(.parish-section,.knowledge-banner,.article-top,.jw-toc,.lab-hero,
      .airport-board,.airport-overview,.airport-route-tools,.flight-detail-card,
      .leaflet-popup-content-wrapper,.leaflet-popup-tip) * { color:inherit!important; }
  a { color:LinkText!important; }
}
