/* Контраст тексту ≥ 7:1 (WCAG AAA) у світлій і темній темах. Розміри в rem — поважають налаштування шрифту браузера. */
:root {
  --bg: #ffffff;
  --surface: #f3f5f9;
  --surface-2: #e6ebf3;
  --text: #111418;
  --muted: #3b4350;          /* 9.6:1 на білому */
  --border: #6b7585;         /* 4.8:1 — для меж полів (≥3:1) */
  --border-soft: #c9d1dd;
  --link: #0a3a9e;           /* 10:1 */
  --link-visited: #5a2a8a;
  --primary: #0a3a9e;
  --primary-text: #ffffff;
  --focus: #111418;
  --focus-halo: #ffd400;
  --tag-bg: #e6ebf3;
  --ok: #0d5c2e;
  --no: #8a1c1c;
  --partial: #7a4a00;
  --notice-bg: #fff6d6;
  --notice-border: #7a4a00;
  --success-bg: #e3f4e8;
  --error-bg: #fde8e8;
  --bar: #9fb4dc;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #181d24;
    --surface-2: #222a34;
    --text: #f2f4f7;
    --muted: #c3cad4;
    --border: #8b95a5;
    --border-soft: #394350;
    --link: #9cc3ff;
    --link-visited: #d3b3ff;
    --primary: #9cc3ff;
    --primary-text: #0b1220;
    --focus: #ffd400;
    --focus-halo: #0f1216;
    --tag-bg: #222a34;
    --ok: #86e0a5;
    --no: #ffaaaa;
    --partial: #ffd58a;
    --notice-bg: #2b2410;
    --notice-border: #ffd58a;
    --success-bg: #11281a;
    --error-bg: #2e1414;
    --bar: #3d5a8c;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
/* hidden має перемагати display з класів (напр., .btn { display: inline-flex }) */
[hidden] { display: none !important; }

html { font-size: 112.5%; /* 18px при стандартних 16px */ -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.wrap { max-width: 72rem; margin: 0 auto; padding: 0 1rem; }

h1, h2, h3, h4 { line-height: 1.25; margin: 1.6em 0 0.5em; }
h1 { font-size: 2rem; margin-top: 1rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
p, ul, ol, dl { margin: 0 0 1em; }

a { color: var(--link); text-decoration-thickness: 0.08em; text-underline-offset: 0.18em; }
a:visited { color: var(--link-visited); }
a:hover { text-decoration-thickness: 0.18em; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px var(--focus-halo);
  border-radius: 2px;
}
main:focus, [tabindex="-1"]:focus { outline: none; box-shadow: none; }
[tabindex="-1"]:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; }

.visually-hidden {
  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: 1rem; top: -10rem; z-index: 10;
  background: var(--primary); color: var(--primary-text); padding: 0.75rem 1rem; font-weight: 700;
}
.skip-link:focus { top: 1rem; }
.skip-link:visited { color: var(--primary-text); }

/* ---- Шапка ---- */
.site-header { background: var(--surface); border-bottom: 1px solid var(--border-soft); }
.header-inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 2rem; padding-top: 0.75rem; padding-bottom: 0.75rem; }
.brand { display: flex; align-items: center; gap: 0.75rem; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.05rem; line-height: 1.25; }
.brand:visited { color: var(--text); }
.brand-sub { display: block; font-weight: 400; color: var(--muted); font-size: 0.9rem; }
.brand-mark { flex: none; width: 2.5rem; height: 2.5rem; }
.nav-list { list-style: none; display: flex; flex-wrap: wrap; gap: 0.25rem; margin: 0; padding: 0; }
.nav-list a {
  display: inline-flex; align-items: center; min-height: 2.75rem; padding: 0.25rem 0.75rem;
  color: var(--text); text-decoration: none; border-radius: 0.375rem; font-weight: 600;
}
.nav-list a:visited { color: var(--text); }
.nav-list a:hover { background: var(--surface-2); text-decoration: underline; }
.nav-list a[aria-current="page"] { background: var(--surface-2); box-shadow: inset 0 -3px 0 var(--primary); }

main { display: block; padding-bottom: 3rem; }
.lead { font-size: 1.1rem; max-width: 50rem; }
.hint { color: var(--muted); font-size: 0.95rem; }
.prose { max-width: 50rem; }

/* ---- Форми ---- */
.filters { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 0.75rem; padding: 0.25rem 1.25rem 1.25rem; margin: 1.5rem 0; }
.filters h2 { margin-top: 0.75rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem 1.5rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1rem; }
.field .hint { margin: 0; }
label, legend, summary { font-weight: 600; }
input[type="search"], input[type="text"], input[type="file"], select {
  font: inherit; color: var(--text); background: var(--bg);
  min-height: 2.9rem; padding: 0.5rem 0.75rem; width: 100%;
  border: 2px solid var(--border); border-radius: 0.375rem;
}
select { appearance: auto; }
fieldset { border: 1px solid var(--border-soft); border-radius: 0.5rem; padding: 0.5rem 1rem 0.75rem; margin: 0; min-width: 0; }
legend { padding: 0 0.35rem; }
.fieldsets { display: grid; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); gap: 1rem; margin-top: 1rem; }
.check { display: flex; align-items: flex-start; gap: 0.6rem; min-height: 2.75rem; padding: 0.3rem 0; }
.check input { flex: none; width: 1.35rem; height: 1.35rem; margin: 0.2rem 0 0; accent-color: var(--primary); }
.check label { font-weight: 400; cursor: pointer; }
.more-filters { margin: 0.25rem 0 1rem; }
.more-filters > summary, details > summary {
  cursor: pointer; min-height: 2.75rem; display: flex; align-items: center; gap: 0.5rem;
  padding: 0.25rem 0; color: var(--link);
}
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; display: inline-block; transition: transform 0.15s; color: var(--text); }
details[open] > summary::before { transform: rotate(90deg); }
details > summary:hover { text-decoration: underline; }

.actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 2.9rem;
  padding: 0.5rem 1.25rem; border-radius: 0.5rem; font: inherit; font-weight: 700;
  text-decoration: none; cursor: pointer; border: 2px solid var(--primary);
}
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-primary:hover { text-decoration: underline; }
.btn-secondary, .btn-secondary:visited { background: var(--bg); color: var(--primary); }
.btn-secondary:hover { background: var(--surface-2); }

/* ---- Результати ---- */
.results h2 { scroll-margin-top: 1rem; }
#results-area[aria-busy="true"] { opacity: 0.6; transition: opacity 0.15s; }
.region-title { border-bottom: 2px solid var(--border-soft); padding-bottom: 0.3rem; }
.region-title .count { color: var(--muted); font-weight: 400; }
.org-card {
  border: 1px solid var(--border-soft); border-left: 4px solid var(--primary);
  border-radius: 0.5rem; padding: 0.25rem 1.25rem 0.5rem; margin: 0 0 1rem; background: var(--bg);
}
.org-card-muted { border-left-color: var(--border); }
.org-title { margin: 0.75rem 0 0.4rem; font-size: 1.2rem; }
.org-meta { display: flex; flex-wrap: wrap; gap: 0.4rem 0.75rem; align-items: center; color: var(--muted); }
.tag { display: inline-block; background: var(--tag-bg); color: var(--text); border-radius: 0.3rem; padding: 0.05rem 0.5rem; font-size: 0.9rem; }
.label { font-weight: 700; }
.org-facts { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem 1.25rem; }
.org-facts li::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.org-phones a { white-space: nowrap; }
.inactive { margin-top: 2.5rem; }

/* ---- Сторінка організації ---- */
.back-link { margin: 1rem 0 0; }
.back-link a::before { content: "← "; }
.contacts { font-size: 1.05rem; }
.contacts a[href^="tel:"] { white-space: nowrap; font-weight: 600; }
.levels { display: grid; gap: 0; border-top: 1px solid var(--border-soft); max-width: 50rem; }
.dl-row { display: grid; grid-template-columns: minmax(10rem, 18rem) 1fr; gap: 0.25rem 1.5rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border-soft); }
.dl-row dt { font-weight: 700; }
.dl-row dd { margin: 0; }
.level-icon { display: inline-block; width: 1.4em; font-weight: 700; }
.level-yes .level-icon::before { content: "✓"; color: var(--ok); }
.level-no .level-icon::before { content: "✗"; color: var(--no); }
.level-partial .level-icon::before { content: "◐"; color: var(--partial); }
.level-unknown .level-icon::before { content: "?"; color: var(--muted); }
@media (max-width: 36rem) { .dl-row { grid-template-columns: 1fr; } }

.notice { background: var(--notice-bg); border-left: 4px solid var(--notice-border); padding: 0.75rem 1rem; border-radius: 0.375rem; }
.notice-success { background: var(--success-bg); border-left-color: var(--ok); }
.notice-error { background: var(--error-bg); border-left-color: var(--no); }
.notice h2 { margin-top: 0.25rem; }

/* ---- Таблиці ---- */
.table-wrap { overflow-x: auto; margin: 1rem 0; max-width: 100%; }
.data-table { border-collapse: collapse; width: 100%; min-width: 28rem; }
.data-table caption { text-align: left; font-weight: 700; font-size: 1.1rem; padding: 0.5rem 0; }
.data-table th, .data-table td { overflow-wrap: normal; hyphens: auto; border-bottom: 1px solid var(--border-soft); padding: 0.55rem 0.75rem; text-align: left; vertical-align: top; }
.data-table thead th { background: var(--surface-2); border-bottom: 2px solid var(--border); }
.data-table tbody th { font-weight: 600; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.chart-table td.num { position: relative; min-width: 12rem; }
.chart-table .bar { position: absolute; left: 0.5rem; top: 50%; transform: translateY(-50%); height: 1.1rem; width: calc((100% - 5rem) * var(--w) / 100); background: var(--bar); border-radius: 0.2rem; }

/* ---- Дослідження ---- */
.toc { background: var(--surface); border-radius: 0.75rem; padding: 0.25rem 1.25rem 0.75rem; max-width: 50rem; }
.toc h2 { margin-top: 0.75rem; }
.toc li { margin: 0.3rem 0; }
blockquote { margin: 1rem 0; padding: 0.5rem 1.25rem; border-left: 4px solid var(--primary); background: var(--surface); font-style: italic; border-radius: 0 0.375rem 0.375rem 0; }
blockquote p { margin: 0.4rem 0; }
.callout { font-size: 1.15rem; background: var(--surface); padding: 1rem 1.25rem; border-radius: 0.5rem; }
.conclusions li { margin-bottom: 0.9rem; }
.plain-dl dt { font-weight: 700; margin-top: 0.5rem; }
.plain-dl dd { margin: 0 0 0.5rem 0; }
address { font-style: normal; line-height: 1.9; margin-bottom: 1rem; }

/* ---- Жива карта областей ---- */
:root {
  --map-0: #eceff3; --map-1: #c7d5ee; --map-2: #92addf; --map-3: #4f78c4; --map-4: #1d4596;
  --map-lbl-light: #111418; --map-lbl-dark: #ffffff; --map-edge: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root {
    --map-0: #2a313b; --map-1: #2c4470; --map-2: #3a63a8; --map-3: #5d8ddb; --map-4: #a8c9ff;
    --map-lbl-light: #f2f4f7; --map-lbl-dark: #0b1220; --map-edge: #0f1216;
  }
}
.region-map { max-width: 56rem; margin: 1.5rem 0 0.5rem; }
.region-map-svg { display: block; width: 100%; height: auto; }
.region-map-svg path { stroke: var(--map-edge); stroke-width: 1.2; stroke-linejoin: round; }
.region-map-svg .shade-0 { fill: var(--map-0); }
.region-map-svg .shade-1 { fill: var(--map-1); }
.region-map-svg .shade-2 { fill: var(--map-2); }
.region-map-svg .shade-3 { fill: var(--map-3); }
.region-map-svg .shade-4 { fill: var(--map-4); }
.region-link { cursor: pointer; }
.region-link:hover path { stroke: var(--text); stroke-width: 3; }
.region-link:hover { filter: brightness(1.08); }
.labels { pointer-events: none; }
.labels .label-link { pointer-events: auto; }
.hit { fill: transparent; }
.label-link:hover .lbl-out { text-decoration: underline; }
.lbl { font: 700 22px system-ui, sans-serif; text-anchor: middle; dominant-baseline: central;
       fill: var(--map-lbl-light); paint-order: stroke; stroke: var(--map-0); stroke-width: 4px; stroke-linejoin: round; }
.lbl-0 { fill: var(--muted); font-weight: 400; }
.lbl-1 { stroke: var(--map-1); }
.lbl-2 { stroke: var(--map-2); }
.lbl-3, .lbl-4 { fill: var(--map-lbl-dark); stroke: var(--map-3); }
.lbl-4 { stroke: var(--map-4); }
.lbl.lbl-out { fill: var(--text); stroke: var(--bg); }
.leader { stroke: var(--text); stroke-width: 1.5; }
.leader-dot { fill: var(--text); }
.map-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 1rem; font-size: 0.95rem; margin-top: 0.5rem; }
.legend-title { font-weight: 700; }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { width: 1.4rem; height: 1rem; border-radius: 0.2rem; border: 1px solid var(--border); }
.swatch.shade-0 { background: var(--map-0); } .swatch.shade-1 { background: var(--map-1); }
.swatch.shade-2 { background: var(--map-2); } .swatch.shade-3 { background: var(--map-3); }
.swatch.shade-4 { background: var(--map-4); }
.map-hint { margin-bottom: 1.5rem; }
/* SVG масштабується разом з екраном, тож розмір підписів (в одиницях SVG) підбираємо сходинками,
   щоб на екрані цифри лишалися приблизно 15–22px на будь-якій ширині. */
@media (max-width: 56rem) { .lbl { font-size: 26px; stroke-width: 5px; } }
@media (max-width: 40rem) {
  .lbl { font-size: 36px; stroke-width: 6px; }
  .region-map-svg path { stroke-width: 2; }
  .hit { r: 44px; }
}
@media (max-width: 30rem) { .lbl { font-size: 46px; stroke-width: 7px; } }
@media (max-width: 25rem) { .lbl { font-size: 52px; } }
@media (forced-colors: active) {
  .region-map-svg path { stroke: CanvasText; }
  .lbl { fill: CanvasText; stroke: Canvas; }
}

/* ---- Підвал ---- */
.site-footer { background: var(--surface); border-top: 1px solid var(--border-soft); padding: 1.5rem 0 1rem; color: var(--text); font-size: 0.95rem; }

@media (max-width: 40rem) {
  html { font-size: 106.25%; }
  h1 { font-size: 1.6rem; }
  .filters { padding: 0.25rem 0.9rem 1rem; }
  .org-card { padding: 0.25rem 0.9rem 0.5rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

@media (forced-colors: active) {
  .org-card, .filters, fieldset { border: 1px solid CanvasText; }
  .chart-table .bar { display: none; }
}

@media print {
  .site-header nav, .filters, .skip-link, .site-footer { display: none; }
  .org-card { break-inside: avoid; }
}
