/* Våldskartan product styles. The House design tokens (brand-tokens.css) load
   first; everything here is built on those vars. Incident-type colors are the
   only product-local palette: a warm, editorial spread that stays legible on
   both paper and dark. */

:root {
  --vk-container: 1600px;
  --dash-h: clamp(640px, 60vh, 720px);  /* shared dashboard column height */
  --vk-sko:  #c45a4a; /* Skottlossning  */
  --vk-mord: #7c2d2d; /* Mord/dråp      */
  --vk-mdf:  #d98a5a; /* Mordförsök     */
  --vk-det:  #8a5326; /* Explosion (umber, distinct from brand gold) */
}
:root.dark {
  --vk-sko:  #e07a6a;
  --vk-mord: #c96a5a;
  --vk-mdf:  #e6a574;
  --vk-det:  #cf9b62;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}

h1, h2, h3 {
  font-family: var(--font-serif);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  margin: 0;
}
a { color: inherit; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* ---------- Header ---------- */
/* Chrome (topbar, back-link, brand, theme) comes from the shared stylesheet so
   it matches the games exactly. Only the live dot + tagline are vk-specific. */

.tagline {
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  color: var(--ink-muted);
}
/* "Live" pulse in House gold. */
.live {
  width: 9px; height: 9px;
  border-radius: var(--radius-pill);
  background: var(--gold);
  box-shadow: 0 0 0 0 var(--gold-wash);
  animation: live-pulse 2.4s var(--ease) infinite;
}
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(200,164,85,0.5); }
  70%  { box-shadow: 0 0 0 7px rgba(200,164,85,0); }
  100% { box-shadow: 0 0 0 0 rgba(200,164,85,0); }
}
@media (prefers-reduced-motion: reduce) { .live { animation: none; } }

/* ---------- Layout ---------- */

/* Wider than the House reading container: this is a map dashboard, not body
   copy, so it earns the full screen width (capped so it doesn't sprawl). */
.container { max-width: var(--vk-container); margin: 0 auto; padding: var(--space-5); }
.layout {
  display: grid;
  /* left (stats + index) · center (map, the hero) · right (latest) */
  grid-template-columns: minmax(300px, 1fr) minmax(440px, 1.7fr) minmax(280px, 1fr);
  gap: var(--space-5);
  align-items: stretch;  /* all three columns share the tallest height */
}
.col-left { order: 1; }
.col-center { order: 2; }
.col-right { order: 3; }

/* The last card in each column is a flex column so its body can fill. */
.col-center > .panel,
.col-left > .panel,
.col-right > .panel { display: flex; flex-direction: column; min-height: 0; }
.events-wrap { flex: 1; min-height: 0; overflow-y: auto; }
.events-foot {
  margin: 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
  font-size: var(--text-xs);
  color: var(--ink-faint);
  line-height: var(--leading-snug);
}

/* From tablet up: the map's height drives the row, and align-items:stretch makes
   the other two columns match it. Each column's last card fills (flex:1) so the
   index chart grows and the events list scrolls, all lining up at the bottom. */
@media (min-width: 761px) {
  .col { height: var(--dash-h); }
  .col-center > .panel,
  .col-left > .panel,
  .col-right > .panel { flex: 1; }
  .col-center .map { flex: 1; height: auto; min-height: 0; }
  .col-left .chart { flex: 1; height: auto; min-height: 200px; }
}

/* Stat summary: sits atop the right column above the index. Label, then a 2x2
   grid of compact KPIs so it reads tidily in the narrower column. */
.summary-bar {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4) var(--space-5);
}
.sumbar-label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-muted); }
.sumbar-label em { font-style: normal; font-weight: 400; color: var(--ink-faint); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.kpi {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
}
.kpi-top { display: flex; align-items: center; gap: var(--space-2); }
.kpi .dot { box-shadow: none; }
.kpi b {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.kpi-label { font-size: var(--text-sm); color: var(--ink-muted); }
.kpi .stat-delta { margin: 0; font-size: var(--text-xs); }
.kpi.is-off { opacity: 0.4; }
.col { display: flex; flex-direction: column; gap: var(--space-5); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}
.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.panel-head--sub { margin-top: var(--space-5); }
.panel-head h2 { font-size: var(--text-lg); }
.panel-head h3 { font-size: var(--text-md); font-weight: 700; }
.hint { font-size: var(--text-xs); color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; }

/* ---------- Period select ---------- */

.period { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--text-sm); color: var(--ink-muted); }
.period select {
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  padding: 6px 30px 6px 12px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6a66' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.period select:hover { border-color: var(--ink-faint); }

/* ---------- Map ---------- */

.map {
  width: 100%;
  height: clamp(440px, 66vh, 660px);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-sunken);
  overflow: hidden;
}
.leaflet-container { font-family: var(--font-sans); background: var(--surface-sunken); }

/* Brand the Leaflet popups/tooltips to match panels. */
.leaflet-popup-content-wrapper, .leaflet-tooltip {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
}
.leaflet-popup-tip { background: var(--surface); border: 1px solid var(--line); }
.leaflet-tooltip { padding: 6px 10px; }
.leaflet-tooltip::before { display: none; }
.leaflet-popup-content a, .leaflet-tooltip a { color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.vk-pop { display: flex; flex-direction: column; gap: 2px; }
.vk-pop b { font-size: var(--text-sm); }
.vk-pop-place { color: var(--ink-muted); }
.vk-pop-time { color: var(--ink-faint); font-variant-numeric: tabular-nums; margin-bottom: 2px; }
/* Source link: match the events-list "Polisen" link (gold-deep, no underline). */
.vk-pop-src { display: inline-flex; align-items: center; gap: var(--space-1); margin-top: var(--space-1); color: var(--gold-deep); font-weight: 600; text-decoration: none; }
.vk-pop-src:hover { text-decoration: underline; text-underline-offset: 2px; }
.vk-pop-ext { flex: none; }
.leaflet-bar a {
  background: var(--surface); color: var(--ink); border-color: var(--line);
}
.leaflet-bar a:hover { background: var(--surface-sunken); }
.leaflet-control-attribution {
  background: rgba(255,255,255,0.7); color: var(--ink-faint); font-size: 10px;
}
:root.dark .leaflet-control-attribution { background: rgba(28,29,34,0.7); }

/* ---------- Legend ---------- */

.legend {
  list-style: none;
  display: flex; flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: var(--space-3) 0 0;
  padding: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
}
.legend li { display: inline-flex; align-items: center; gap: var(--space-2); }
.dot { width: 11px; height: 11px; border-radius: var(--radius-pill); flex-shrink: 0; box-shadow: inset 0 0 0 2px rgba(255,255,255,0.7); }
.dot-sko  { background: var(--vk-sko); }
.dot-mord { background: var(--vk-mord); }
.dot-mdf  { background: var(--vk-mdf); }
.dot-det  { background: var(--vk-det); }

/* ---------- Stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-3);
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  padding: var(--space-3) var(--space-2);
  background: var(--surface-sunken);
  border-radius: var(--radius);
}
.stat-dot { width: 8px; height: 8px; border-radius: var(--radius-pill); margin-bottom: 4px; }
.stat-num {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-2xl);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.02em;
}
.stat-label { font-size: var(--text-xs); color: var(--ink-muted); }

/* ---------- Source / notes ---------- */

.source, .note {
  margin: 0;
  font-size: var(--text-sm);
  color: var(--ink-muted);
  line-height: var(--leading-body);
}
.note { margin-top: var(--space-4); }

/* Disclaimer demoted to a quiet page footer. */
.page-foot {
  margin-top: var(--space-6);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
  font-size: var(--text-xs);
  color: var(--ink-faint);
  line-height: var(--leading-body);
}

/* ---------- Index headline ---------- */

.index-now { display: flex; align-items: baseline; gap: var(--space-2); }
.index-value {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--danger);
  letter-spacing: -0.02em;
}
.index-date { font-size: var(--text-sm); color: var(--ink-faint); }
.chart { width: 100%; height: 300px; }

/* ---------- Events table ---------- */

.events { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.events th {
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  padding: 0 var(--space-2) var(--space-2);
  border-bottom: 1px solid var(--line);
}
.events td {
  padding: var(--space-3) var(--space-2);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.events td:first-child, .events th:first-child { padding-left: 0; }
.events td:last-child, .events th:last-child { padding-right: 0; }
.events tbody tr:last-child td { border-bottom: none; }
.events tbody tr:hover { background: var(--surface-sunken); }
.events .type-cell { display: inline-flex; align-items: center; gap: var(--space-2); white-space: nowrap; }
.events .type-cell .dot { box-shadow: none; }
.events .when { font-variant-numeric: tabular-nums; color: var(--ink-muted); white-space: nowrap; }
.events .col-link, .events td.col-link { text-align: right; }
.events .col-link a { color: var(--gold-deep); font-weight: 600; }

/* ---------- Updated stamp ---------- */

.updated { color: var(--ink-faint); }

/* ---------- Legend (now toggle buttons) ---------- */

.legend-btn {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font: inherit; font-size: var(--text-sm);
  color: var(--ink-muted);
  background: none; border: 0; padding: 2px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}
.legend-btn:hover { color: var(--ink); }
.legend-btn.is-off { opacity: 0.4; text-decoration: line-through; }

/* ---------- Stat delta chips + toggled-off cards ---------- */

.stat { position: relative; }
.stat-delta {
  margin-top: 4px;
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--ink-faint);
  letter-spacing: 0.01em;
}
.stat-delta.is-up { color: var(--danger); }
.stat-delta.is-down { color: var(--positive); }
.stat.is-off { opacity: 0.4; }
.stats-foot {
  margin: var(--space-3) 0 0;
  font-size: var(--text-xs);
  color: var(--ink-faint);
}

/* ---------- Index read line ---------- */

/* Tighter top on the index box: title hugs the top, less gap before the chart. */
.col-left > .panel { padding-top: var(--space-4); }
.col-left > .panel > .panel-head { margin-bottom: var(--space-2); align-items: flex-start; }
.index-value { line-height: 1; }
.index-title { line-height: 1.1; }
.index-title { display: flex; align-items: center; gap: var(--space-2); }
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-pill);
  background: none;
  color: var(--ink-faint);
  cursor: help;
  transition: color var(--dur-fast) var(--ease);
}
.info-btn:hover { color: var(--ink-muted); }

/* ---------- Clickable event rows ---------- */

.events tbody tr[data-link] { cursor: pointer; }
.events tbody tr[data-link]:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.events-empty { color: var(--ink-faint); text-align: center; padding: var(--space-5) 0; }

/* ---------- Thumbnail mode (?thumb) ---------- */
/* Map-only view at the og:image size; everything else is hidden and the map
   fills the frame. Used by the headless thumbnail render, never in normal use. */
.thumb #sitenav, .thumb .topbar, .thumb .tagline, .thumb .col-left, .thumb .col-right,
.thumb .legend, .thumb .panel-head, .thumb .page-foot { display: none !important; }
.thumb .container { max-width: none; padding: 0; margin: 0; }
.thumb .layout { display: block; }
.thumb .col-center > .panel, .thumb .panel { border: 0; border-radius: 0; box-shadow: none; padding: 0; background: none; }
.thumb .map { height: 100vh !important; border: 0; border-radius: 0; }
.thumb .leaflet-control-container { display: none !important; }

/* ---------- Responsive ---------- */

/* Two columns: map (center) on top spanning full width, stats + latest below. */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .col-center { order: -1; grid-column: 1 / -1; }
  .map { height: clamp(420px, 56vh, 600px); }
}
/* Single column: map first, then stats + index, then latest. */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .map { height: clamp(380px, 56vh, 540px); }
}
@media (max-width: 560px) {
  .container { padding: var(--space-4); }
  .panel { padding: var(--space-4); }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .events .col-link { display: none; }
}
