/* ==================================================================
   WABbase shared dark theme
   Loaded on every page from layout.html, after page stylesheets.
   Targets WCAG 2.1 Level AA. Fonts are bundled in ../fonts (IBM Plex, SIL OFL).
   ================================================================== */
@font-face { font-family: "IBM Plex Sans"; src: url("../fonts/plex-sans-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Sans"; src: url("../fonts/plex-sans-600.woff2") format("woff2"); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: "IBM Plex Mono"; src: url("../fonts/plex-mono-400.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }

:root {
  --bg: #0f1318;
  --surface: #171c23;
  --surface-2: #1f262f;
  --surface-3: #28303b;
  --text: #e6ebf0;
  --muted: #9aa5b3;            /* 5.3:1 or better on every surface */
  --border: #262e39;
  --border-strong: #36404d;
  --control-border: #7a8696;   /* 3:1 or better on every surface (WCAG 1.4.11) */
  --accent: #6cb6e0;           /* water blue, tuned for dark backgrounds */
  --accent-strong: #8fcaeb;
  --accent-contrast: #0a1218;
  --ok: #57b78a;
  --danger: #e8776f;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-2: 0 10px 28px rgba(0, 0, 0, 0.5);
  --font-body: "IBM Plex Sans", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --nav-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }

html { background: var(--bg); color-scheme: dark; font-size: 16px; }  /* skeleton.css sets 62.5%; restore so rem sizes are correct */

html body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5 { font-family: var(--font-body); color: var(--text); letter-spacing: -0.01em; margin: 0 0 0.5em; line-height: 1.25; }
h1 { font-size: 1.75rem; font-weight: 600; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1.05rem; font-weight: 600; }
p { margin: 0 0 0.9em; }

a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }
a:hover { color: var(--text); }

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* ---------- Header ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow: visible;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 34px; height: 34px; border-radius: 50%; background: #fff; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-title { font-size: 17px; font-weight: 600; color: var(--text); }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.05em; text-transform: uppercase; }

.nav-links { display: flex; gap: 6px; list-style: none; margin: 0 0 0 auto; padding: 0; }
.navbar nav { margin-left: auto; }
.nav-links li { margin: 0; }
.navbar .nav-links a {
  float: none;
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
}
.navbar .nav-links a:hover { background: var(--surface-2); border-color: var(--control-border); color: var(--text); }
.navbar .nav-links a[aria-current="page"] {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}

/* ---------- Main ---------- */
#content { display: block; }
#content:focus { outline: none; }

/* ---------- Buttons ---------- */
.btn,
button.btn,
#downloaddata,
#downloadshp,
#clear,
#cleartable,
#dl {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  height: auto;
  margin: 0;
  padding: 7px 16px;
  font: 600 13.5px/1.2 var(--font-body);
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
  background: var(--surface-3);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: normal;
  transition: background-color 0.15s, border-color 0.15s;
}
.btn:hover,
#downloadshp:hover, #clear:hover, #cleartable:hover { background: color-mix(in srgb, var(--accent) 14%, var(--surface-3)); color: var(--text); border-color: var(--accent); }
.btn-primary,
#downloaddata,
#dl {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}
.btn-primary:hover, #downloaddata:hover, #dl:hover { background: var(--accent-strong); border-color: var(--accent-strong); color: var(--accent-contrast); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.btn-col { display: flex; flex-direction: column; align-items: stretch; gap: 8px; margin-top: 16px; }

/* ---------- Form fields ---------- */
input[type="text"], input[list], input:not([type]), select {
  width: 100%;
  min-height: 38px;
  padding: 7px 10px;
  font: 400 14px var(--font-body);
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  box-shadow: none;
}
input[list]:focus, input:not([type]):focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
label { display: block; margin: 0 0 6px; font-size: 13.5px; font-weight: 600; color: var(--text); }
.field { margin-bottom: 12px; text-align: left; }
.hint { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); text-align: left; }
.empty-note { margin: 12px 0; font-size: 13.5px; color: var(--muted); font-style: italic; text-align: left; }

/* ---------- Tab sets (radio inputs + labels) ---------- */
.tab-fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.tab-radio,
.tabset > input[type="radio"],
.tab-fieldset > input[type="radio"] {
  position: absolute !important;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
  pointer-events: none;
}
.tab-radio + label,
input.tab-radio + label {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  margin: 0 4px 0 0;
  padding: 6px 14px;
  position: static;
  top: auto;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.tab-radio + label:hover { color: var(--text); background: var(--surface-2); }
.tab-radio:checked + label {
  color: var(--accent-contrast);
  background: var(--accent);
  border-color: var(--accent);
}
.tab-radio:focus-visible + label { outline: 3px solid var(--accent); outline-offset: 2px; }
.tab-radio ~ .tab { display: none; margin-top: 12px; padding: 14px 0 0; border-top: 1px solid var(--border); }
#tab1:checked ~ .tab.content1,
#tab2:checked ~ .tab.content2,
#tab3:checked ~ .tab.content3,
#tab4:checked ~ .tab.content4 { display: block; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border-strong);
}
tbody tr:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* key/value tables */
.mtable { width: 100%; margin: 0; }
.mtable th[scope="row"], .nobh {
  width: 46%;
  padding: 8px 12px 8px 0;
  white-space: normal;
  background: transparent;
  border-radius: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  position: static;
}
.mtable td { font-family: var(--font-mono); font-size: 13.5px; overflow-wrap: anywhere; }
.nob { border: 0; border-bottom: 1px solid var(--border) !important; }

/* ---------- ArcGIS widgets: dark overrides ---------- */
.esri-view { background: var(--bg); }
.esri-widget,
.esri-widget--button,
.esri-widget--panel,
.esri-expand__content,
.esri-search,
.esri-search__container,
.esri-search__input,
.esri-search__sources-button,
.esri-search__submit-button,
.esri-menu,
.esri-menu__list-item,
.esri-search__suggestions-menu,
.esri-legend,
.esri-layer-list,
.esri-layer-list__item,
.esri-basemap-gallery,
.esri-basemap-gallery__item,
.esri-attribution,
.esri-popup__main-container,
.esri-popup__header,
.esri-popup__footer,
.esri-feature-table,
.esri-grid,
.esri-features__footer {
  background-color: var(--surface) !important;
  color: var(--text) !important;
  font-family: var(--font-body);
}
.esri-widget--button { border-bottom: 1px solid var(--border); }
.esri-widget--button:hover,
.esri-search__submit-button:hover,
.esri-search__sources-button:hover,
.esri-menu__list-item:hover,
.esri-menu__list-item--active,
.esri-basemap-gallery__item:hover { background-color: var(--surface-3) !important; color: var(--text) !important; }
.esri-basemap-gallery__item--selected { border-left-color: var(--accent) !important; background-color: var(--surface-2) !important; }
.esri-basemap-gallery__item-title { color: var(--text) !important; }
.esri-ui-corner .esri-component { box-shadow: var(--shadow-2); border-radius: var(--radius-sm); }
.esri-search__input { border: 0; }
.esri-search__input::placeholder { color: var(--muted); }
.esri-menu { border: 1px solid var(--border-strong); }
.esri-legend__service-label, .esri-legend__layer-caption, .esri-legend__layer-cell--info,
.esri-layer-list__item-title { color: var(--text) !important; }
.esri-layer-list__item { border-bottom-color: var(--border) !important; }
.esri-layer-list__item-toggle, .esri-layer-list__item-actions-menu-item { color: var(--muted) !important; }
.esri-attribution { background-color: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--muted) !important; }
.esri-attribution a { color: var(--muted); }
.esri-icon-non-visible::before { content: "\e610" !important; }
.esri-icon-visible::before { content: "\e611" !important; }

/* ArcGIS sign-in and other dialogs */
.esri-identity-modal__dialog,
.esri-identity-modal .esri-modal__dialog,
.esri-identity-modal .esri-identity-form,
.esri-modal__dialog,
.esri-modal__content { background: var(--surface) !important; color: var(--text) !important; }
.esri-identity-form__label,
.esri-identity-form h2, .esri-modal__dialog h2, .esri-identity-modal__title { color: var(--text) !important; }
.esri-identity-modal__close-button { color: var(--text) !important; background: transparent !important; }
.esri-identity-form__group input,
.esri-identity-form input { background: var(--bg) !important; color: var(--text) !important; border: 1px solid var(--control-border) !important; }
.esri-button {
  min-height: 36px;
  color: var(--accent-contrast) !important;
  background: var(--accent) !important;
  border: 1px solid var(--accent) !important;
}
.esri-button--secondary {
  color: var(--text) !important;
  background: var(--surface-3) !important;
  border-color: var(--control-border) !important;
}
.esri-modal__close-button, .esri-identity-modal .esri-modal__close-button { color: var(--text) !important; }

/* ==================================================================
   Accessibility
   ================================================================== */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -80px;
  z-index: 1000;
  padding: 10px 16px;
  font-weight: 600;
  color: var(--accent-contrast);
  background: var(--accent);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.skip-link:focus { top: 10px; color: var(--accent-contrast); outline: 3px solid var(--text); outline-offset: 2px; }

a:focus-visible,
button:focus-visible,
input:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible,
.esri-widget--button:focus,
.esri-search__input:focus {
  outline: 3px solid var(--accent) !important;
  outline-offset: 2px;
}
#map:focus-visible { outline-offset: -3px !important; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--surface); }
*::-webkit-scrollbar-track { background: transparent; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .btn, .tab-radio + label, input, .navbar .nav-links a { border: 1px solid CanvasText; }
  .tab-radio:checked + label, .navbar .nav-links a[aria-current="page"] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
}

@media (max-width: 640px) {
  .navbar { gap: 10px; padding: 0 10px; }
  .brand-sub { display: none; }
  .navbar .nav-links a { padding: 6px 9px; font-size: 13px; }
}

@media print {
  html body { background: #fff; color: #000; }
  .navbar, .skip-link, #map, .esri-ui { display: none !important; }
  th, td, h1, h2, h3, p, li { color: #000 !important; background: #fff !important; }
}
