/* Color tokens — see ../docs for the data-viz method these follow.
   Light values first; dark values are redefined twice so both the OS
   setting and the manual toggle (#theme-toggle -> [data-theme]) win. */
:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface:         #fcfcfb;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --series-1:        #2a78d6;
  --series-1-wash:   rgba(42, 120, 214, 0.10);
  --status-good:     #0ca30c;
  --status-good-text:#006300;
  --status-critical: #d03b3b;
  --badge-covid-bg:  #fdeee9;
  --badge-covid-fg:  #9a3412;
  --badge-est-bg:    #f0efec;
  --badge-est-fg:    #52514e;
  /* Sequential (one hue) heatmap ramp for the regional map/bar chart — safe
     by construction for every vision type, varying only in lightness. */
  --heat-low:        #cde2fb;
  --heat-high:       #0d366b;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:            #0d0d0d;
    --surface:         #1a1a19;
    --text-primary:    #ffffff;
    --text-secondary:  #c3c2b7;
    --text-muted:      #898781;
    --grid:            #2c2c2a;
    --axis:            #383835;
    --border:          rgba(255, 255, 255, 0.10);
    --series-1:        #3987e5;
    --series-1-wash:   rgba(57, 135, 229, 0.10);
    --status-good:     #0ca30c;
    --status-good-text:#0ca30c;
    --status-critical: #e66767;
    --badge-covid-bg:  #3a241a;
    --badge-covid-fg:  #f0b090;
    --badge-est-bg:    #2c2c2a;
    --badge-est-fg:    #c3c2b7;
    --heat-low:        #1e3a5f;
    --heat-high:       #6fb1f0;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:            #0d0d0d;
  --surface:         #1a1a19;
  --text-primary:    #ffffff;
  --text-secondary:  #c3c2b7;
  --text-muted:      #898781;
  --grid:            #2c2c2a;
  --axis:            #383835;
  --border:          rgba(255, 255, 255, 0.10);
  --series-1:        #3987e5;
  --series-1-wash:   rgba(57, 135, 229, 0.10);
  --status-good:     #0ca30c;
  --status-good-text:#0ca30c;
  --status-critical: #e66767;
  --badge-covid-bg:  #3a241a;
  --badge-covid-fg:  #f0b090;
  --badge-est-bg:    #2c2c2a;
  --badge-est-fg:    #c3c2b7;
  --heat-low:        #1e3a5f;
  --heat-high:       #6fb1f0;
}

* { box-sizing: border-box; }

/* The hidden attribute must win over any component's own display rule
   (e.g. .scope-controls { display: flex } used to keep the region selects
   visible under the "Milli göstəricilər" tab). */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.muted { color: var(--text-secondary); font-size: 0.9rem; margin: 4px 0 0; }

/* Header */
/* One size for the wordmark and the page title, so they read as a pair. */
:root { --head-size: 1.5rem; --topbar-h: 62px; }
html { scroll-padding-top: calc(var(--topbar-h) + 8px); } /* in-page jumps stop below the fixed bar */

/* Fixed top bar: logo + name, centred with empty sides. Opaque and above the
   content (z-index), so scrolling text never runs into it. */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  padding: 8px 16px;
  background: var(--page);
  border-bottom: 1px solid var(--border);
}
/* Brand lockup (mark + wordmark). The mark takes the chart blue via
   currentColor, so it follows light/dark like the data does. */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--series-1);
  text-decoration: none;
}
.brand__mark { display: block; flex: none; width: 40px; height: 40px; }
.brand__name { font-size: var(--head-size); font-weight: 700; line-height: 1.2; letter-spacing: 0.01em; color: var(--text-primary); }
.brand:focus-visible { outline: 2px solid var(--series-1); outline-offset: 3px; border-radius: 6px; }

/* Page-load intro: the mark's line is drawn like an ECG trace. Flat line,
   then each rise-and-fall (P bump + dip, then the tall spike) with a short
   pause after it, and finally the quick climb of the growth arrow to the end
   dot. Segment ends on the 100-unit path: 9.74 / 34.76 / 80.98 / 100. Runs on
   every load only (nothing is stored); users who asked for less motion get
   the finished logo at once. */
.brand__line {
  stroke-dasharray: 100 100;
  animation: ecg-trace 2.2s linear both;
}
.brand__dot {
  transform-box: fill-box;
  transform-origin: center;
  animation: ecg-dot 0.32s ease-out 1.9s both;
}
@keyframes ecg-trace {
  0%     { stroke-dashoffset: 100;   opacity: 0; }
  0.5%   { stroke-dashoffset: 100;   opacity: 1; }
  13.6%  { stroke-dashoffset: 90.26; }                          /* flat baseline */
  31.8%  { stroke-dashoffset: 65.24; }                          /* bump + dip */
  43.2%  { stroke-dashoffset: 65.24; }                          /* pause */
  68.2%  { stroke-dashoffset: 19.02; }                          /* tall spike + back down */
  79.5%  { stroke-dashoffset: 19.02; animation-timing-function: ease-in; } /* pause */
  87.7%  { stroke-dashoffset: 0; }                              /* fast climb to the end */
  100%   { stroke-dashoffset: 0; }
}
@keyframes ecg-dot {
  0%   { transform: scale(0); }
  60%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  .brand__line, .brand__dot { animation: none; }
}

.site-header {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px 8px;
}
/* Title and the language / theme buttons share one row. */
.site-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.site-header h1 { margin: 0; font-size: var(--head-size); line-height: 1.25; min-width: 0; }
.site-header .subtitle { margin: 6px 0 0; color: var(--text-secondary); font-size: 0.95rem; }
#theme-toggle {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 1.1rem;
  cursor: pointer;
}
#theme-toggle:hover { background: var(--page); }

/* Header controls (language + theme) stay together in the top-right corner,
   also on phones: the title shrinks/wraps instead. */
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* AZ / EN: two small circles. Light mode = white fill, black ring; dark mode
   = dark fill, white ring (both follow --surface / --text-primary). The
   current language is the inverted, filled circle. */
.lang-switch { display: flex; gap: 4px; }
.lang-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1.5px solid var(--text-primary);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  padding: 0;
}
.lang-btn:hover { background: var(--page); }
.lang-btn[aria-pressed="true"] {
  background: var(--text-primary);
  color: var(--surface);
  cursor: default;
}
.lang-btn:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

/* Set by the inline head script while a saved non-default language loads
   (i18n.js removes it), so the Azerbaijani fallback text never flashes. */
.i18n-pending body { visibility: hidden; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card h2 { margin: 0 0 4px; font-size: 1.15rem; }

/* KPI row */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.kpi-tile__label { margin: 0; font-size: 0.85rem; color: var(--text-secondary); }
.kpi-tile__value {
  margin: 6px 0 0;
  font-size: 1.9rem;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
}
.kpi-tile__unit { font-size: 0.8rem; color: var(--text-muted); font-weight: 400; }
.kpi-tile__delta {
  margin: 8px 0 0;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.kpi-tile__delta[data-dir="up"], .delta[data-dir="up"]     { color: var(--status-critical); }
.kpi-tile__delta[data-dir="down"], .delta[data-dir="down"] { color: var(--status-good-text); }
.kpi-tile__delta[data-dir="flat"], .delta[data-dir="flat"] { color: var(--text-muted); }
.delta { font-weight: 600; white-space: nowrap; }
.kpi-tile__count { margin: 4px 0 0; font-size: 0.8rem; color: var(--text-muted); }

/* Chart card */
.chart-card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.select-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#region-year-select, .scope-controls select {
  font: inherit;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
}
.chart-wrap { position: relative; height: 340px; }
.chart-wrap--bar { height: 420px; margin-top: 16px; }
.table-jump {
  display: inline-block;
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--series-1);
}

/* Regional section */
.regional-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0;
}
.tab-group { display: flex; gap: 6px; }
.tab-btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-secondary);
  cursor: pointer;
}
.tab-btn[aria-selected="true"] {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #ffffff;
  font-weight: 600;
}
.map-wrap { position: relative; }
/* Vertical scrolling stays native; horizontal gestures reach the swipe handler (region-map.js, initSwipe). */
#region-map { touch-action: pan-y; }
#region-map { width: 100%; height: auto; display: block; max-height: 480px; }
.region-shape { cursor: pointer; outline: none; transition: fill-opacity 0.1s; }
.region-shape:focus, .region-shape:hover, .region-shape.is-active {
  stroke: var(--text-primary);
  stroke-width: 2;
  fill-opacity: 0.85;
}
.region-tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.85rem;
  box-shadow: 0 2px 8px var(--border);
  white-space: nowrap;
}
.scale-legend {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0 4px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.scale-legend__bar {
  flex: 1;
  max-width: 240px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  position: relative;
}
/* Downward arrow sitting on top of the bar (not inside it), pointing at the
   selected district's value -- see renderScaleLegend(). */
.scale-legend__marker {
  position: absolute;
  bottom: calc(100% + 2px);
  width: 0;
  height: 0;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 8px solid var(--text-primary);
}
.region-nav-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 10px 0 0;
}
.region-stepper { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.region-stepper .muted { margin: 0; font-variant-numeric: tabular-nums; }
.step-btn {
  font: inherit;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
}
.step-btn:hover { border-color: var(--series-1); }
.breadcrumb {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}
.breadcrumb a { color: var(--series-1); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb strong { color: var(--text-primary); }

/* Table scope (Milli / Region cascade) */
.table-scope-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 12px 0 4px;
}
.scope-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 12px 0 8px; }
.national-result { max-width: 360px; }
.national-result--table { max-width: 720px; }
.national-result--table .kpi-tile__label { margin-bottom: 6px; }
.all-years-note { margin: 0; }
.all-years-note__value {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  color: var(--text-primary);
}
.trend-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}
.trend-controls .scope-controls { margin: 0; }

.about p { margin: 8px 0 0; color: var(--text-secondary); font-size: 0.95rem; max-width: 70ch; }

/* Table */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
.data-table th {
  cursor: pointer;
  user-select: none;
  color: var(--text-secondary);
  font-weight: 600;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.data-table th:hover { color: var(--text-primary); }
.data-table th[aria-sort="ascending"]::after  { content: " \25B2"; }
.data-table th[aria-sort="descending"]::after { content: " \25BC"; }
.data-table td[data-type="num"], .data-table th[data-type="num"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  margin-left: 4px;
}
.badge-covid { background: var(--badge-covid-bg); color: var(--badge-covid-fg); }
.badge-est   { background: var(--badge-est-bg);   color: var(--badge-est-fg); }

/* Methodology */
.methodology dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 12px 0; }
.methodology dt { color: var(--text-secondary); font-size: 0.85rem; }
.methodology dd { margin: 0; }
.methodology details { margin-top: 12px; font-size: 0.9rem; }
.methodology summary { cursor: pointer; color: var(--text-secondary); }
.methodology ul { margin: 8px 0 0; padding-left: 20px; }

/* Error state */
.error-card button {
  font: inherit;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  cursor: pointer;
}

footer {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px 32px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

@media (max-width: 560px) {
  :root { --head-size: 1.25rem; --topbar-h: 56px; }
  .brand__mark { width: 34px; height: 34px; }
  .topbar { padding: 8px 12px; }
  .chart-wrap { height: 280px; }
  .chart-wrap--bar { height: 380px; }
  .regional-controls { align-items: stretch; }
}

/* Vahid is the same on every row, so it has no data-key and isn't sortable. */
.data-table th:not([data-key]) { cursor: default; }
.data-table th:not([data-key]):hover { color: var(--text-secondary); }

/* Dəyişim is left-aligned so every arrow starts on the same line; tabular
   digits keep the percentages lined up after it. */
.data-table td.delta-cell, .data-table th[data-key="delta"] {
  text-align: left;
  font-variant-numeric: tabular-nums;
}
