/*
 * ukrainakriget.se — base stylesheet.
 *
 * Hand-written rather than Tailwind-generated for now: the surface is small,
 * and a build step that must run before the site renders at all is a poor
 * trade this early. The class names are already utility-shaped, so moving to
 * Tailwind later is mechanical.
 *
 * Colour policy: the palette is deliberately sober. This is a site about a
 * war, and figures about dead people should not be presented in the visual
 * language of a growth dashboard. Blue and yellow appear only as a thin
 * accent, never as chart fills.
 */

:root {
  color-scheme: light dark;

  --bg: #fbfbf9;
  --bg-raised: #ffffff;
  --bg-sunken: #f2f2ee;
  --border: #dedcd5;
  --border-strong: #c4c1b6;

  --text: #16150f;
  --text-muted: #56544a;
  --text-faint: #7d7a6e;

  --accent: #0057b7;      /* Ukrainian blue, used sparingly */
  --accent-warm: #b58900; /* muted gold; the flag yellow is too loud for data */
  --danger: #8f2f1d;
  --stale: #8a5a00;
  --stale-bg: #fdf3dc;

  --radius: 10px;
  --shadow: 0 1px 2px rgb(20 18 10 / 6%), 0 4px 16px rgb(20 18 10 / 4%);

  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;

  --measure: 68ch;
  --container: 72rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14140f;
    --bg-raised: #1c1c16;
    --bg-sunken: #100f0b;
    --border: #302f26;
    --border-strong: #4a483b;

    --text: #f2f1e8;
    --text-muted: #b3b0a2;
    --text-faint: #8a877a;

    --accent: #6ba4e8;
    --accent-warm: #d9b23d;
    --danger: #e07a63;
    --stale: #e0b352;
    --stale-bg: #2e2612;

    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 24%);
  }
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: 1.25rem;
}

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

h1, h2, h3 {
  line-height: 1.2;
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--bg-raised);
  padding: 0.75rem 1rem;
  z-index: 100;
}
.skip-link:focus { left: 0; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: saturate(1.4) blur(6px);
}

.header-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.75rem 1.5rem;
  padding-block: 0.85rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 650;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 2px;
  /* The flag, abstracted to a small mark rather than a decorative banner. */
  background: linear-gradient(to bottom, var(--accent) 50%, var(--accent-warm) 50%);
}

.brand-tld { color: var(--text-faint); font-weight: 400; }

.site-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.1rem;
  font-size: 0.925rem;
  margin-right: auto;
}

.site-nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding-block: 0.15rem;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover { color: var(--text); }
.site-nav a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

.header-updated {
  margin: 0;
  font-size: 0.825rem;
  color: var(--text-faint);
}

/* ---------- content ---------- */

.hero { padding-block: 2.5rem 1.5rem; }
.hero h1 { font-size: clamp(1.75rem, 4vw, 2.6rem); margin: 0 0 0.75rem; }
.lede {
  font-size: 1.125rem;
  color: var(--text-muted);
  max-width: var(--measure);
  margin: 0 0 1rem;
}

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-block: 1.5rem;
}

.panel-head { margin-bottom: 1.25rem; }
.panel-head h2 { margin: 0 0 0.4rem; font-size: 1.25rem; }
.panel-note {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: var(--measure);
}

/* ---------- KPI tiles ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.kpi {
  background: var(--bg-raised);
  padding: 1rem 1.1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  /* The left rule encodes how much the figure can be relied on. */
  border-left: 3px solid transparent;
}

.kpi-label {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.kpi-value {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.kpi-number {
  font-size: 1.7rem;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.kpi-delta {
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  color: var(--danger);
  font-weight: 550;
}

.kpi-meta {
  margin: 0;
  font-size: 0.775rem;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Trust encoding. Claims are visually quieter than verified counts, because
   they deserve less confidence, and the design should say so before the
   caption does. */
.trust-strong { border-left-color: var(--accent); }
.trust-medium { border-left-color: var(--accent-warm); }
.trust-claim  { border-left-color: var(--border-strong); }
.trust-weak   { border-left-color: transparent; }

.trust-pill {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-left-width: 3px;
  white-space: nowrap;
}

.badge {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 650;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
}

.badge-stale {
  color: var(--stale);
  background: var(--stale-bg);
  border: 1px solid color-mix(in srgb, var(--stale) 35%, transparent);
}

/* ---------- charts ---------- */

.chart { margin: 0; }
.chart-canvas {
  width: 100%;
  height: clamp(240px, 42vw, 420px);
}
.chart-caption {
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-top: 0.5rem;
}

/* ---------- tables ---------- */

.table-scroll {
  overflow-x: auto;
  /* Wide tables scroll inside their own container; the page body never
     scrolls horizontally. */
  margin-inline: -0.5rem;
  padding-inline: 0.5rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table caption {
  text-align: left;
  padding-bottom: 0.75rem;
  color: var(--text-muted);
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table thead th {
  font-size: 0.775rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  border-bottom-color: var(--border-strong);
  white-space: nowrap;
}

.data-table tbody tr:hover { background: var(--bg-sunken); }

.data-table td:not(.license-cell) { font-variant-numeric: tabular-nums; }
.license-cell { color: var(--text-muted); font-size: 0.825rem; max-width: 22rem; }

.source-note {
  display: block;
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-faint);
  max-width: 30rem;
  margin-top: 0.25rem;
}

.definition-list dt {
  font-weight: 620;
  margin-top: 1rem;
}
.definition-list dd {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  max-width: var(--measure);
}

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 4rem;
  padding-block: 2.5rem 3rem;
  background: var(--bg-sunken);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.footer-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: 2rem;
}

.site-footer h2 { font-size: 0.95rem; margin: 0 0 0.5rem; color: var(--text); }
.site-footer p { margin: 0 0 0.75rem; max-width: 42ch; }

.footer-legal {
  margin-top: 2rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.825rem;
  color: var(--text-faint);
}

code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--bg-sunken);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  border: 1px solid var(--border);
}

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

/* ---------- news ---------- */

.news-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.news-item {
  padding-block: 1.1rem;
  border-bottom: 1px solid var(--border);
}
.news-item:first-child { padding-top: 0; }
.news-item:last-child { border-bottom: none; padding-bottom: 0; }

.news-title {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 0.35rem;
  line-height: 1.35;
}
.news-title a { color: var(--text); text-decoration: none; }
.news-title a:hover { color: var(--accent); text-decoration: underline; }

.news-summary {
  margin: 0 0 0.4rem;
  color: var(--text-muted);
  font-size: 0.925rem;
  max-width: var(--measure);
}

.news-meta {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-faint);
}

.news-source {
  font-weight: 600;
  color: var(--text-muted);
}

.news-dupes {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.05rem 0.45rem;
}

.source-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.source-chips li {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
}

.chip-count {
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  color: var(--text);
}

.chart-readout {
  margin: 0 0 0.25rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  min-height: 1.4em;
}

/* ---------- claim vs confirmed ---------- */

.reading-guide {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
}

.guide-item {
  border-left: 3px solid var(--border-strong);
  padding: 0.1rem 0 0.1rem 0.9rem;
}
.guide-item h3 { margin: 0 0 0.3rem; font-size: 0.95rem; }
.guide-item p { margin: 0; font-size: 0.9rem; color: var(--text-muted); }

.comparison-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.comparison-table td.claimed { color: var(--text-muted); }
.comparison-table td.confirmed { font-weight: 620; }

.bar-cell { min-width: 9rem; width: 22%; }

.bar {
  position: relative;
  height: 1.4rem;
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  align-items: center;
}

/* The bar is an inline SVG, not a styled div: its width has to vary per row,
   and a div width would be an inline style, which the site's CSP forbids. The
   filled part is what is documented; the empty remainder is the honest subject
   of the page. */
.bar-track {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.bar-fill {
  fill: color-mix(in srgb, var(--accent) 55%, transparent);
}

.bar-label {
  position: relative;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
  padding-left: 0.5rem;
  color: var(--text);
}

.callout {
  border-left: 4px solid var(--accent-warm);
}
.callout h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.callout p { margin: 0; color: var(--text-muted); max-width: var(--measure); }

/* The reader's own country, marked so it can be found without hunting. */
.row-highlight {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.row-highlight th[scope="row"] { font-weight: 700; }

/* ---------- map ----------
 *
 * The SVG is generated server-side with no styling attributes, so the whole
 * appearance lives here and inherits the theme tokens. That is the main reason
 * for hand-rolling the map: light/dark works with no JavaScript.
 */

.mapfig { margin: 0; }

.warmap {
  width: 100%;
  height: auto;
  display: block;
  background: var(--bg-sunken);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* Administrative outline: present for orientation, never competing with the
   data drawn on top of it. */
.map-oblasts path {
  fill: var(--bg-raised);
  stroke: var(--border-strong);
  stroke-width: 0.6;
  stroke-linejoin: round;
}

.map-frontline path {
  stroke-width: 0.4;
  stroke-linejoin: round;
}

/* Occupied territory carries the strongest colour on the page. Everything else
   on this site is deliberately muted so that this reads first. */
.layer-occupied {
  fill: color-mix(in srgb, var(--danger) 62%, transparent);
  stroke: var(--danger);
}

/* Territory held since 2014 is drawn in the same hue but flatter: it is
   occupied, but it is not what changed this week. */
.layer-crimea_2014,
.layer-ordlo_2014 {
  fill: color-mix(in srgb, var(--danger) 32%, transparent);
  stroke: color-mix(in srgb, var(--danger) 55%, transparent);
}

/* The grey zone is hatched rather than solid, because "nobody is in firm
   control here" should not look like a fact of the same kind as the others. */
.layer-unknown {
  fill: color-mix(in srgb, var(--text-faint) 30%, transparent);
  stroke: color-mix(in srgb, var(--text-faint) 50%, transparent);
}

.map-losses circle {
  fill: var(--text);
  fill-opacity: 0.55;
  stroke: var(--bg-raised);
  stroke-width: 0.5;
}
.map-losses circle:hover { fill-opacity: 1; }
.loss-Ukraine { fill: var(--accent); }

.map-legend {
  list-style: none;
  margin: 0.9rem 0 0.5rem;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.map-legend li { display: inline-flex; align-items: center; gap: 0.45rem; }

.swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  flex: none;
}
.swatch-occupied { background: color-mix(in srgb, var(--danger) 62%, transparent); }
.swatch-2014     { background: color-mix(in srgb, var(--danger) 32%, transparent); }
.swatch-unknown  { background: color-mix(in srgb, var(--text-faint) 30%, transparent); }
.swatch-loss     { background: var(--text); border-radius: 50%; opacity: 0.55; }

.map-meta {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-faint);
  max-width: var(--measure);
}

/* ---------- server-rendered charts ----------
 *
 * The SVG arrives complete from the server; these rules are its entire
 * appearance, which is what makes light/dark work without any JavaScript.
 * preserveAspectRatio="none" lets the chart stretch to the panel width, so
 * stroke widths are set in the geometry rather than scaled with it.
 */

/* Uniform scaling, height derived from the viewBox aspect ratio.
 *
 * The obvious alternative — preserveAspectRatio="none" with a fixed CSS height —
 * stretches the geometry to fill the box, and stretches every text label with
 * it. Axis numbers then render subtly squashed or smeared depending on the
 * viewport width, which is exactly the kind of thing that makes a chart look
 * cheap without it being obvious why. */
.chart-svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.chart-grid line {
  stroke: currentColor;
  stroke-opacity: 0.12;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart-ylabels text,
.chart-xlabels text {
  font-size: 11px;
  fill: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.chart-area {
  fill: var(--accent);
  fill-opacity: 0.1;
  stroke: none;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round;
  /* Without this the line thins and thickens as the chart stretches. */
  vector-effect: non-scaling-stroke;
}

.chart-guide {
  stroke: var(--text-faint);
  stroke-dasharray: 3 3;
  vector-effect: non-scaling-stroke;
}

.chart-marker { fill: var(--accent); }

/* Zero is a reference, not one gridline among several. */
.chart-baseline {
  stroke: var(--text-faint);
  stroke-opacity: 0.45;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.chart-last-dot { fill: var(--accent); }

/* The latest value, stated rather than left to be read off an axis. The halo
   (paint-order + stroke) keeps it legible where it crosses the line or the
   area fill. */
.chart-last-label {
  fill: var(--text);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  paint-order: stroke;
  stroke: var(--bg-raised);
  stroke-width: 3;
  stroke-linejoin: round;
}

.chart-svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.footer-version {
  display: inline-block;
  margin-left: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-faint);
  opacity: 0.7;
}

/* A single line of context above a table or chart, where a panel of prose used
   to sit. The data is the point; this is the minimum needed not to misread it. */
.key-note {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: var(--measure);
  padding-left: 0.75rem;
  border-left: 2px solid var(--border-strong);
}
.key-note strong { color: var(--text); font-weight: 620; }

.footer-lead { margin: 0 0 0.5rem; max-width: 60ch; }

/* Panel heading with an action on the right (e.g. "all news"). */
.panel-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.panel-more {
  font-size: 0.85rem;
  white-space: nowrap;
}

/* The front page shows headlines only — no summaries — so the list stays
   scannable next to the figures above it. */
.news-list-compact .news-item { padding-block: 0.7rem; }
.news-list-compact .news-title { font-size: 0.975rem; margin-bottom: 0.2rem; }
