/* ============================================================================
   ClimRisk UA — stylesheet
   ========================================================================== */
:root {
  --c-blue: #0b57a4;
  --c-blue-dark: #083358;
  --c-blue-light: #e3f0fb;
  --c-yellow: #ffd500;
  --c-bg: #f2f5f9;
  --c-card: #ffffff;
  --c-text: #1c2b3a;
  --c-text-dim: #5a6b7d;
  --c-border: #dde5ee;
  --c-red: #c62828;
  --c-green: #2e7d32;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 42, 67, 0.1), 0 4px 14px rgba(16, 42, 67, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--c-text);
  background: var(--c-bg);
}

/* ---------------------------------------------------------------- layout */
body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: linear-gradient(120deg, var(--c-blue-dark), var(--c-blue) 70%, #1273c4);
  color: #fff;
  border-bottom: 4px solid var(--c-yellow);
  flex-shrink: 0;
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { width: 42px; height: 42px; flex-shrink: 0; }
.brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
  line-height: 1.1;
  white-space: nowrap;
}
.ua-badge {
  background: var(--c-yellow);
  color: var(--c-blue-dark);
  border-radius: 6px;
  padding: 0 6px;
  font-size: 0.85em;
  vertical-align: 2px;
}
.brand-text p { margin: 2px 0 0; font-size: 0.8rem; opacity: 0.85; white-space: nowrap; }

header nav { display: flex; gap: 8px; flex-shrink: 0; }

/* --------------------------------------------------------------- buttons */
.btn {
  font: inherit;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  padding: 8px 14px;
  font-weight: 600;
  transition: filter 0.15s, background 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn.solid { background: var(--c-yellow); color: var(--c-blue-dark); }
.btn.solid:hover { filter: brightness(1.05); }
.btn.ghost {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
}
.btn.ghost:hover { background: rgba(255, 255, 255, 0.22); }
.btn.wide { width: 100%; }
.btn.icon {
  background: transparent;
  color: var(--c-text-dim);
  font-size: 1.4rem;
  line-height: 1;
  padding: 4px 10px;
}
.btn.icon:hover { color: var(--c-text); background: var(--c-blue-light); }

/* -------------------------------------------------------------- controls */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 14px;
  padding: 12px 20px;
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
}

.ctl { display: flex; flex-direction: column; gap: 5px; }
.ctl label, .ctl-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-dim);
}

#indicator {
  font: inherit;
  font-weight: 600;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--c-border);
  background: var(--c-card);
  color: var(--c-text);
  min-width: 290px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
#indicator:focus { outline: 2px solid var(--c-blue); outline-offset: 1px; }

.seg {
  display: flex;
  background: var(--c-card);
  border: 1px solid var(--c-border);
  border-radius: 11px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.seg button {
  font: inherit;
  border: none;
  background: transparent;
  padding: 6px 12px;
  cursor: pointer;
  color: var(--c-text-dim);
  border-right: 1px solid var(--c-border);
  line-height: 1.25;
  transition: background 0.15s;
}
.seg button:last-child { border-right: none; }
.seg button b { display: block; font-size: 0.88rem; }
.seg button span { display: block; font-size: 0.66rem; opacity: 0.75; }
.seg button:hover { background: var(--c-blue-light); }
.seg button.active {
  background: var(--c-blue);
  color: #fff;
}
.seg button.active span { opacity: 0.9; }
.seg.disabled { opacity: 0.45; pointer-events: none; }

/* ------------------------------------------------------------------ main */
main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 420px;
  min-height: 0;
}

.map-wrap { position: relative; min-height: 0; }

#map {
  position: absolute;
  inset: 0;
  background: #dce6ef;
}

/* map overlay cards */
.map-card {
  position: absolute;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(4px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 14px;
  z-index: 600;
  pointer-events: none;
}

#legend { left: 12px; bottom: 22px; min-width: 240px; }
.legend-title { font-size: 0.78rem; font-weight: 700; margin-bottom: 6px; }
.legend-bar {
  height: 12px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}
.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--c-text-dim);
  margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

#hovercard { right: 12px; top: 12px; text-align: right; min-width: 180px; }
#hovercard strong { font-size: 0.88rem; }
#hc-value { font-size: 1.15rem; font-weight: 700; color: var(--c-blue-dark); margin-top: 2px; }
#hc-sub { font-size: 0.72rem; color: var(--c-text-dim); margin-top: 1px; }

/* ------------------------------------------------------------------ leaflet tweaks */
.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution {
  font-size: 0.62rem;
  background: rgba(255, 255, 255, 0.8) !important;
}

/* --------------------------------------------------------------- sidebar */
#sidebar {
  background: var(--c-card);
  border-left: 1px solid var(--c-border);
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#empty-state {
  margin: auto;
  text-align: center;
  padding: 30px 18px;
  color: var(--c-text-dim);
}
#empty-state svg { width: 64px; height: 64px; margin-bottom: 10px; }
#empty-state h2 { font-size: 1.1rem; color: var(--c-text); margin: 0 0 8px; }
#empty-state p { font-size: 0.86rem; line-height: 1.5; margin: 0; }

.oblast-head { position: relative; padding-right: 30px; }
.oblast-head h2 { margin: 0; font-size: 1.25rem; line-height: 1.25; }
.oblast-head p { margin: 2px 0 8px; color: var(--c-text-dim); font-size: 0.9rem; }
#close-detail { position: absolute; top: -4px; right: -8px; }

.chip {
  display: inline-block;
  background: var(--c-blue-light);
  color: var(--c-blue);
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 3px 10px;
}

.stat-row {
  display: grid;
  grid-template-columns: 1.1fr 1.2fr 1fr;
  gap: 8px;
}
.stat {
  background: var(--c-bg);
  border-radius: 10px;
  padding: 10px;
  text-align: center;
}
.stat-val {
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--c-blue-dark);
  font-variant-numeric: tabular-nums;
}
.stat-val.small { font-size: 0.95rem; }
.stat small { color: var(--c-text-dim); font-size: 0.66rem; }

.chart-block h3, .table-block h3 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--c-text-dim);
}
.chart-box {
  position: relative;
  height: 230px;
  background: var(--c-card);
}

/* ------------------------------------------------------------------ table */
#ind-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
#ind-table th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-text-dim);
  padding: 4px 6px;
  border-bottom: 2px solid var(--c-border);
}
#ind-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#ind-table th.num, #ind-table td.num { text-align: right; }
#ind-table tbody tr { cursor: pointer; transition: background 0.1s; }
#ind-table tbody tr:hover { background: var(--c-blue-light); }
#ind-table tbody tr.current { background: var(--c-blue-light); }
.delta-up { color: var(--c-red); font-weight: 700; }
.delta-down { color: var(--c-green); font-weight: 700; }
.delta-zero { color: var(--c-text-dim); }

/* ------------------------------------------------------------------ footer */
footer {
  flex-shrink: 0;
  background: var(--c-blue-dark);
  color: #cfe3f5;
  padding: 8px 20px;
  font-size: 0.7rem;
  line-height: 1.45;
}
footer p { margin: 2px 0; }
footer .credits { opacity: 0.7; }

/* ------------------------------------------------------------------ dialog */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: 680px;
  width: min(92vw, 680px);
  max-height: 84vh;
  box-shadow: 0 20px 60px rgba(8, 51, 88, 0.35);
}
dialog::backdrop { background: rgba(8, 32, 55, 0.55); }
.dialog-inner {
  padding: 26px 30px;
  overflow-y: auto;
  max-height: 84vh;
  position: relative;
}
.dialog-inner h2 { margin: 0 0 14px; color: var(--c-blue-dark); }
.dialog-inner h3 {
  margin: 18px 0 6px;
  font-size: 0.95rem;
  color: var(--c-blue);
}
.dialog-inner p, .dialog-inner li { font-size: 0.88rem; line-height: 1.55; }
.dialog-inner .warn {
  background: #fff8e1;
  border-left: 4px solid #f9a825;
  padding: 10px 14px;
  border-radius: 6px;
}
.dialog-close { position: absolute; top: 10px; right: 10px; }

/* ------------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  main { grid-template-columns: 1fr 360px; }
  #indicator { min-width: 220px; }
}

@media (max-width: 880px) {
  body { overflow: auto; height: auto; min-height: 100vh; }
  .controls { padding: 10px 12px; gap: 10px; }
  #indicator { min-width: 0; width: 100%; }
  .ctl { width: 100%; }
  .seg { width: 100%; }
  .seg button { flex: 1; }
  main { grid-template-columns: 1fr; }
  .map-wrap { height: 60vh; min-height: 380px; }
  #sidebar { border-left: none; border-top: 1px solid var(--c-border); }
  .brand-text p { display: none; }
  header { flex-wrap: wrap; }
}
