/* Кольорові схеми. Кожна схема — це лише набір змінних; решта стилів їх використовує.
   Типова — «Синя» (:root). */
[data-scheme="night"] {
  --bg: #0d1117;
  --bg-glow: #142030;
  --panel: rgba(22, 28, 38, 0.72);
  --panel-line: rgba(255, 255, 255, 0.07);
  --text: #e8edf3;
  --muted: #8b96a5;
  --calm: #1f5a43;
  --water: #3f7fb0; /* Дніпро й водосховища */
  --yellow: #f2c230;
  --yellow-deep: #8a6a12; /* жовта тривога, що триває добу й довше */
  --red: #e5383b;
  --red-deep: #7d1f24; /* колір тривоги, що триває добу й довше */
  --nodata: #2a313c;
  --raion-line: #0d1117;
  --oblast-line: rgba(255, 255, 255, 0.75); /* білі тонкі межі областей */
  --country-line: #ffffff; /* білий контур країни */
  --glow: 0.55;
}

[data-scheme="day"] {
  --raion-border: #eef1f4; /* на світлому фоні межі районів — світлі проміжки */
  --bg: #eef1f4;
  --bg-glow: #ffffff;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-line: rgba(15, 23, 42, 0.08);
  --text: #111827;
  --muted: #5b6573;
  --calm: #9fd3ae;
  --water: #6fa8dc; /* Дніпро й водосховища */
  --yellow: #f4bb1f;
  --yellow-deep: #a8780c; /* жовта тривога, що триває добу й довше */
  --red: #dc2f2f;
  --red-deep: #8e2222; /* колір тривоги, що триває добу й довше */
  --nodata: #cfd5dc;
  --raion-line: #eef1f4;
  --oblast-line: rgba(17, 24, 39, 0.38);
  --country-line: rgba(17, 24, 39, 0.6);
  --glow: 0.25;
}

[data-scheme="neon"] {
  --bg: #05050a;
  --bg-glow: #12082a;
  --panel: rgba(14, 10, 28, 0.74);
  --panel-line: rgba(180, 140, 255, 0.14);
  --text: #f3eeff;
  --muted: #9a8fbf;
  --calm: #10322b;
  --water: #3b4fc4; /* Дніпро й водосховища */
  --yellow: #ffe14d;
  --yellow-deep: #8c7a1a; /* жовта тривога, що триває добу й довше */
  --red: #ff2d55;
  --red-deep: #7a1430; /* колір тривоги, що триває добу й довше */
  --nodata: #1b1730;
  --raion-line: #05050a;
  --oblast-line: rgba(255, 255, 255, 0.75); /* білі тонкі межі областей */
  --country-line: #ffffff; /* білий контур країни */
  --glow: 1;
}

/* Синя: спокійні райони сині, тривоги приглушені — бордовий і гірчичний на темно-синьому. */
:root:not([data-scheme]),
[data-scheme="blue"] {
  --bg: #010e28;
  --bg-glow: #06204a;
  --panel: rgba(17, 27, 50, 0.86);
  --panel-line: rgba(120, 160, 220, 0.14);
  --text: #e6edf6;
  --muted: #a2a7b0;
  --calm: #0068a6;
  --water: #5b93d1; /* Дніпро й водосховища */
  --yellow: #c8901e;
  --yellow-deep: #6e5418; /* жовта тривога, що триває добу й довше */
  --red: #8e3747;
  --red-deep: #3e2531; /* колір тривоги, що триває добу й довше */
  --nodata: #2b3446;
  --raion-line: #0a3d6e;
  --oblast-line: rgba(255, 255, 255, 0.75); /* білі тонкі межі областей */
  --country-line: #ffffff; /* білий контур країни */
  --glow: 0.18;
}

/* Okabe–Ito: кольори, які розрізняють люди з порушеннями кольоросприйняття. */
[data-scheme="contrast"] {
  --bg: #101418;
  --bg-glow: #18202a;
  --panel: rgba(24, 30, 38, 0.78);
  --panel-line: rgba(255, 255, 255, 0.1);
  --text: #ffffff;
  --muted: #a3adba;
  --calm: #009e73;
  --water: #56b4e9; /* Дніпро й водосховища */
  --yellow: #f0e442;
  --yellow-deep: #8c8526; /* жовта тривога, що триває добу й довше */
  --red: #d55e00;
  --red-deep: #7a3600; /* колір тривоги, що триває добу й довше */
  --nodata: #39424e;
  --raion-line: #101418;
  --oblast-line: rgba(255, 255, 255, 0.75); /* білі тонкі межі областей */
  --country-line: #ffffff; /* білий контур країни */
  --glow: 0.4;
}

/* Інші типи загроз — однакові для всіх схем. */
:root {
  --artillery: #ff7b00; /* артобстріл */
  --urban: #9c8a63;     /* вуличні бої */
  --chemical: #9bc53d;  /* хімічна */
  --nuclear: #22c3d6;   /* радіаційна */
  --raion-border: rgba(205, 215, 230, 0.38); /* світло-сірі межі районів (темні схеми) */
}

/* Бірюзова: спокійні райони бірюзово-сині, свіжа ракетна — цегляно-червона, давня — темно-бордова.
   Блок стоїть після загального :root і має вищу специфічність (html[...]), бо перевизначає
   ще й --artillery та --raion-border, які задані для всіх схем. */
html[data-scheme="teal"],
[data-scheme="teal"] {
  --bg: #0b1124;
  --bg-glow: #23435a;
  --panel: rgba(14, 26, 40, 0.86);
  --panel-line: rgba(120, 190, 220, 0.16);
  --text: #f2f5f8;
  --muted: #9aaab8;
  --calm: #015e74;
  --water: #3aa6cc; /* Дніпро й водосховища */
  --yellow: #be8e00;
  --yellow-deep: #6f5300; /* жовта тривога, що триває добу й довше */
  --red: #be3c35;
  --red-deep: #860601; /* колір тривоги, що триває добу й довше */
  --nodata: #24303d;
  --raion-line: #071420;
  --raion-border: rgba(225, 240, 245, 0.32);
  --oblast-line: rgba(255, 255, 255, 0.8); /* білі тонкі межі областей */
  --country-line: #ffffff; /* білий контур країни */
  --artillery: #a25e27;
  --glow: 0.3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "SF Pro Display", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body { transition: background 0.4s ease; }

/* Прозорий фон для OBS: ?transparent */
html.transparent, html.transparent body { background: transparent; }
html.transparent .app { background: none; }

.app {
  position: relative;
  height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr 300px;
  grid-template-rows: auto 1fr auto;
  gap: 12px 24px;
  padding: 28px 36px;
  background: radial-gradient(ellipse 70% 60% at 50% 45%, var(--bg-glow), transparent 70%);
}

/* ---------- шапка ---------- */

.top {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

h1 {
  margin: 0;
  font-size: clamp(22px, 2.3vw, 40px);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: clamp(12px, 0.95vw, 16px);
}

.clock {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-right: 0;
}

.clock-time {
  font-size: clamp(22px, 2.3vw, 40px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.clock-date { color: var(--muted); font-size: clamp(12px, 0.95vw, 16px); }

/* ---------- карта ---------- */

.stage {
  grid-column: 1 / -1;
  grid-row: 2;
  position: relative;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map { width: 100%; height: 100%; overflow: visible; }

.raion {
  fill: var(--calm);
  stroke: var(--raion-border);
  stroke-width: 0.5;
  stroke-linejoin: round;
  transition: fill 0.7s ease;
}

.raion.yellow { fill: var(--yellow); }
.raion.red { fill: var(--red); }
.raion.artillery { fill: var(--artillery); }
.raion.urban { fill: var(--urban); }
.raion.chemical { fill: var(--chemical); }
.raion.nuclear { fill: var(--nuclear); }
.raion.nodata { fill: var(--nodata); }

.raion.flash { animation: flash 1.4s ease-out; }

@keyframes flash {
  0% { filter: brightness(1.9); }
  100% { filter: brightness(1); }
}

.raion:hover { filter: brightness(1.18); }

.oblasts path {
  fill: none;
  stroke: var(--oblast-line);
  stroke-width: 0.6;
  stroke-linejoin: round;
  pointer-events: none;
}

.country {
  fill: none;
  stroke: var(--country-line);
  stroke-width: 1.3;
  stroke-linejoin: round;
  pointer-events: none;
}

/* Дніпро з водосховищами. Напівпрозорі, щоб під ними було видно колір району. */
.water { pointer-events: none; }
.water .river {
  fill: none;
  stroke: var(--water);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.85;
}
.water .lakes {
  fill: var(--water);
  stroke: var(--water);
  stroke-width: 0.8;
  stroke-linejoin: round;
  opacity: 0.85;
}

/* Світіння червоних і жовтих районів. */
.glow path { pointer-events: none; }
.glow .red { fill: var(--red); }
.glow .yellow { fill: var(--yellow); }
.glow .artillery { fill: var(--artillery); }
.glow .urban { fill: var(--urban); }
.glow .chemical { fill: var(--chemical); }
.glow .nuclear { fill: var(--nuclear); }
.glow { opacity: var(--glow); filter: url(#blur); }

.glow .red { animation: pulse 2.8s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* Громада з тривогою — напівпрозорий колір поверх району (як на alerts.in.ua) і контур. */
.hromadas path { stroke-linejoin: round; }
.hromada-fill { stroke: none; opacity: 0.5; transition: fill 0.7s ease; }
.hromada-fill.red { fill: var(--red); }
.hromada-fill.yellow { fill: var(--yellow); }
.hromada-fill.artillery { fill: var(--artillery); }
.hromada-fill.urban { fill: var(--urban); }
.hromada-fill.chemical { fill: var(--chemical); }
.hromada-fill.nuclear { fill: var(--nuclear); }
.hromada-outline {
  fill: transparent; /* щоб підказка спрацьовувала по всій площі громади */
  stroke: var(--text);
  stroke-opacity: 0.55;
  stroke-width: 0.7;
}
.hromada-outline:hover { fill: rgba(255, 255, 255, 0.12); }

.city {
  stroke: var(--raion-line);
  stroke-width: 1.4;
  transition: fill 0.7s ease;
}
.city.red { fill: var(--red); }
.city.yellow { fill: var(--yellow); }
.city.artillery { fill: var(--artillery); }
.city.urban { fill: var(--urban); }
.city.chemical { fill: var(--chemical); }
.city.nuclear { fill: var(--nuclear); }

/* Підписи областей: обведення кольором фону, щоб читалось на будь-якій заливці. */
.oblast-labels { pointer-events: none; }

.oblast-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  fill: var(--text);
  paint-order: stroke;
  stroke: var(--raion-line);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.oblast-label.city { font-size: 8.5px; font-weight: 500; opacity: 0.9; }

/* Назви районів і міст, де зараз тривога. */
.raion-labels { pointer-events: none; }
.raion-label {
  font-size: 6.4px;
  font-weight: 600;
  fill: #fff;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.55);
  stroke-width: 1.8px;
  stroke-linejoin: round;
}
.raion-label.small { font-size: 5.2px; stroke-width: 1.5px; }

/* Тривалість тривоги під назвою області. */
.oblast-duration {
  font-size: 9px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  fill: var(--text);
  opacity: 0.85;
  paint-order: stroke;
  stroke: var(--raion-line);
  stroke-width: 2.6px;
  stroke-linejoin: round;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px);
  font-size: 14px;
  line-height: 1.35;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 14px));
}
.tooltip b { display: block; font-size: 15px; }
.tooltip span { display: block; color: var(--muted); }

.loading {
  position: absolute;
  color: var(--muted);
  font-size: 18px;
}

/* ---------- панелі ---------- */

.legend, .feed {
  position: relative;
  z-index: 2;
  align-self: end;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 18px;
  padding: 18px 20px;
  backdrop-filter: blur(12px);
}

.legend { grid-column: 1; grid-row: 2; }

.legend-row {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 7px 0;
  font-size: clamp(14px, 1vw, 18px);
}

.swatch { width: 18px; height: 18px; border-radius: 6px; }
.legend-row[hidden] { display: none; }
[data-level="red"] .swatch { background: var(--red); box-shadow: 0 0 14px var(--red); }
[data-level="yellow"] .swatch { background: var(--yellow); box-shadow: 0 0 14px var(--yellow); }
[data-level="artillery"] .swatch { background: var(--artillery); box-shadow: 0 0 14px var(--artillery); }
[data-level="urban"] .swatch { background: var(--urban); box-shadow: 0 0 14px var(--urban); }
[data-level="chemical"] .swatch { background: var(--chemical); box-shadow: 0 0 14px var(--chemical); }
[data-level="nuclear"] .swatch { background: var(--nuclear); box-shadow: 0 0 14px var(--nuclear); }
[data-level="green"] .swatch { background: var(--calm); }

.legend-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: clamp(16px, 1.25vw, 22px);
}

.legend-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nodata-chip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--nodata);
  border: 1px solid var(--panel-line);
}

.feed { grid-column: 3; grid-row: 2; }

.feed h2 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.feed ol { list-style: none; margin: 0; padding: 0; }

.feed li {
  display: grid;
  grid-template-columns: 44px 10px 1fr;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
  font-size: 14px;
  border-top: 1px solid var(--panel-line);
  animation: slide-in 0.5s ease;
}
.feed li:first-child { border-top: 0; }

.feed time { color: var(--muted); font-variant-numeric: tabular-nums; }

.feed .pip { width: 10px; height: 10px; border-radius: 50%; align-self: center; }
.feed .pip.red { background: var(--red); }
.feed .pip.yellow { background: var(--yellow); }
.feed .pip.artillery { background: var(--artillery); }
.feed .pip.urban { background: var(--urban); }
.feed .pip.chemical { background: var(--chemical); }
.feed .pip.nuclear { background: var(--nuclear); }
.feed .pip.green { background: var(--calm); }

.feed .place { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.feed .place small { color: var(--muted); }

.feed .empty { color: var(--muted); grid-template-columns: 1fr; }

@keyframes slide-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: none; }
}

/* ---------- низ ---------- */

.bottom {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.status { display: flex; align-items: center; gap: 8px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live .dot { background: #34d399; box-shadow: 0 0 8px #34d399; animation: pulse 2s infinite; }
.status.error .dot { background: var(--red); }

.check { font-variant-numeric: tabular-nums; }

/* ---------- перемикач схем ---------- */

.schemes {
  position: absolute;
  top: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 5px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  backdrop-filter: blur(12px);
}

.schemes button {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: 999px;
  padding: 7px 14px 7px 9px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
.schemes button:hover { color: var(--text); }
.schemes button[aria-pressed="true"] { background: var(--panel-line); color: var(--text); }

.schemes .chips { display: flex; }
.schemes .chips i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-left: -4px;
  border: 1.5px solid var(--bg);
}
.schemes .chips i:first-child { margin-left: 0; }

/* ---------- режим OBS: ?obs ---------- */

.obs .schemes { display: none; }
.obs, .obs * { cursor: none !important; }
.obs .tooltip { display: none !important; }

/* ---------- вузькі екрани ---------- */

@media (max-width: 1100px) {
  html, body { overflow: auto; }
  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: none;
    padding: 16px;
  }
  .top, .stage, .legend, .feed, .bottom, .schemes { grid-column: 1; grid-row: auto; }
  .stage { height: 66vw; min-height: 240px; }
  .schemes { position: static; transform: none; justify-self: start; flex-wrap: wrap; border-radius: 18px; order: 1; }
  .top { order: 0; }
  .stage { order: 2; }
  .legend { order: 3; }
  .feed { order: 4; }
  .bottom { order: 5; }
  .schemes button span.name { display: none; }
  .bottom { flex-direction: column; align-items: flex-start; gap: 6px; }
}
