/* Terrorkartan product styles. The House design tokens (brand-tokens.css) load
   first; everything here is built on those vars. Attack-type colors are the only
   product-local palette: a warm, editorial spread legible on paper and dark.
   Sibling of Våldskartan; shares its dashboard structure. */

:root {
  --tk-container: 1600px;
  --dash-h: clamp(640px, 60vh, 720px);  /* shared dashboard column height */
  --tk-bomb:    #8a5326; /* Bombdåd (umber, distinct from brand gold) */
  --tk-shoot:   #c45a4a; /* Skjutning */
  --tk-vehicle: #7c2d2d; /* Fordonsattack */
  --tk-stab:    #d98a5a; /* Knivdåd */
  --tk-arson:   #c0693a; /* Anlagd brand */
  --tk-other:   #8a857c; /* Övrigt (neutral) */
}
:root.dark {
  --tk-bomb:    #cf9b62;
  --tk-shoot:   #e07a6a;
  --tk-vehicle: #c96a5a;
  --tk-stab:    #e6a574;
  --tk-arson:   #dc8a5c;
  --tk-other:   #a29c92;
}

* { 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 ---------- */

.tagline {
  margin: 0 0 var(--space-4);
  font-size: var(--text-sm);
  color: var(--ink-muted);
}
.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 ---------- */

.container { max-width: var(--tk-container); margin: 0 auto; padding: var(--space-5); }
.layout {
  display: grid;
  /* left (stats + chart) · 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;
}
.col-left { order: 1; }
.col-center { order: 2; }
.col-right { order: 3; }

.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; }

@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: three big numbers, above the trend chart. */
.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: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
.kpi {
  min-width: 0;              /* let the track shrink below the number's width */
  container-type: inline-size; /* size the number to THIS card, not the viewport */
  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-2);
}
.kpi b {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: clamp(15px, 26cqi, 30px);  /* scales to card width; fits 5 digits */
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  color: var(--ink);
  white-space: nowrap;
}
.kpi-label { font-size: var(--text-sm); color: var(--ink-muted); }
.kpi .stat-delta { margin: 0; font-size: var(--text-xs); }
.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 h2 { font-size: var(--text-lg); }
.panel-head h3 { font-size: var(--text-md); font-weight: 700; }

/* ---------- 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); }

.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-popup-content a { color: var(--ink); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.tk-pop { display: flex; flex-direction: column; gap: 2px; min-width: 200px; }
.tk-pop b { font-size: var(--text-sm); }
.tk-pop-place { color: var(--ink-muted); }
.tk-pop-time { color: var(--ink-faint); font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.tk-pop-toll {
  display: flex; gap: var(--space-4);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: var(--text-sm); color: var(--ink-muted);
}
.tk-pop-toll b { font-variant-numeric: tabular-nums; color: var(--ink); }
.tk-pop-perp { margin-top: var(--space-2); color: var(--ink); }
.tk-pop-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: var(--space-2); }
.tk-tag {
  font-size: var(--text-xs);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  border: 1px solid var(--line);
  color: var(--ink-muted);
}
.tk-tag.tk-attrib { font-variant-caps: small-caps; letter-spacing: 0.02em; }
.tk-motive-islamist  { border-color: color-mix(in srgb, var(--tk-shoot) 45%, transparent); color: var(--tk-shoot); }
.tk-motive-far-right { border-color: color-mix(in srgb, var(--tk-bomb) 50%, transparent); color: var(--tk-bomb); }
.tk-pop-src { display: inline-flex; align-items: center; gap: var(--space-1); margin-top: var(--space-2); color: var(--gold-deep); font-weight: 600; text-decoration: none; }
.tk-pop-src:hover { text-decoration: underline; text-underline-offset: 2px; }
.tk-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-bombing  { background: var(--tk-bomb); }
.dot-shooting { background: var(--tk-shoot); }
.dot-vehicle  { background: var(--tk-vehicle); }
.dot-stabbing { background: var(--tk-stab); }
.dot-arson    { background: var(--tk-arson); }
.dot-other    { background: var(--tk-other); }

.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; }
.legend-note { font-size: var(--text-xs); color: var(--ink-faint); }

/* ---------- Stat delta chips ---------- */

.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); }

/* ---------- Trend chart 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-label { font-size: var(--text-sm); color: var(--ink-faint); }
.chart { width: 100%; height: 300px; }
.col-left > .panel { padding-top: var(--space-4); }
.col-left > .panel > .panel-head { margin-bottom: var(--space-2); align-items: flex-start; }

/* ---------- 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 tbody tr[data-id] { cursor: pointer; }
.events tbody tr[data-id]:focus-visible { outline: 2px solid var(--gold); outline-offset: -2px; }
.events-empty { color: var(--ink-faint); text-align: center; padding: var(--space-5) 0; }

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

.updated { color: var(--ink-faint); }
.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);
}
.page-foot a { color: var(--gold-deep); }

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

@media (max-width: 1180px) {
  .layout { grid-template-columns: 1fr 1fr; }
  .col-center { order: -1; grid-column: 1 / -1; }
  .map { height: clamp(420px, 56vh, 600px); }
}
@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); }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---------- Thumbnail mode (?thumb) ---------- */
/* Map-only view at the og:image size; used by tools/gen-thumbs.sh to render
   /shared/thumbs/terrorkartan.png. Never seen 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; }
