/* ── Tokens (KVF brand colors) ───────────────────────────────────────────────── */
:root {
  --bg:      #f0f2f5;
  --card:    #ffffff;
  --text:    #1a1a1a;
  --muted:   #6b7280;
  --border:  #dde2e8;
  --accent:  #1a1a2e;   /* KVF dark (near black) */
  --accent2: #c8102e;   /* KVF red accent        */
  --accentl: #f0f0f5;   /* KVF light tint        */
  --font:    -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --radius:  10px;
  --shadow:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
}

/* ── Full-viewport shell ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); font-size: 14px; color: var(--text);
       background: var(--bg); display: flex; flex-direction: column; }
a { text-decoration: none; color: inherit; }

/* ── Header ─────────────────────────────────────────────────────────────────── */
.site-header {
  flex-shrink: 0;
  height: 52px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.header-logo  { height: 30px; width: auto; display: block; }
.header-divider { width: 1px; height: 28px; background: rgba(255,255,255,.25); flex-shrink: 0; }
.header-title { font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.header-progress { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.hp-text         { font-size: 11px; font-weight: 600; opacity: .85; }
.hp-track        { height: 4px; background: rgba(255,255,255,.25); border-radius: 2px; overflow: hidden; }
#progress-fill   { height: 100%; background: #60d394; border-radius: 2px; width: 0%; transition: width .5s ease; }
#last-update     { font-size: 11px; opacity: .65; margin-left: auto; white-space: nowrap; }

/* ── App shell ───────────────────────────────────────────────────────────────── */
#app { flex: 1; display: flex; overflow: hidden; min-height: 0; }

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
#sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Top nav (Úrslit / Samanteljing / Forsøgn) */
.nav-top-list       { flex-shrink: 0; }
.nav-top-list .nav-item a {
  display: block;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  border-left: 3px solid transparent;
  transition: background .12s, border-color .12s;
}
.nav-top-list .nav-item a:hover    { background: var(--accentl); }
.nav-top-list .nav-item.active a   { background: var(--accentl); border-left-color: var(--accent); }

/* Station list */
.nav-sep   { height: 1px; background: var(--border); }
.nav-label { padding: 7px 14px 3px; font-size: 10px; font-weight: 700;
             text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }

/* 2-column grid — fits stations without scroll */
.nav-stations {
  flex: 1;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  list-style: none;
}
.nav-stations .nav-item a {
  display: block;
  padding: 4px 6px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 2px solid transparent;
  transition: background .1s, color .1s;
}
.nav-stations .nav-item a:hover      { background: var(--accentl); color: var(--accent); }
.nav-stations .nav-item.active a     { background: var(--accentl); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.nav-stations .nav-item.has-data > a { color: var(--text); font-weight: 600; }

/* ── Main content ────────────────────────────────────────────────────────────── */
#valcontent { flex: 1; overflow-y: auto; min-width: 0; padding: 14px; background: var(--bg); }

/* ── Feed grid — auto-fit fills the row ──────────────────────────────────────── */
.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 10px;
}

/* ── Feed card ───────────────────────────────────────────────────────────────── */
.ps-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.ps-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 12px 4px;
  gap: 6px;
}
.ps-name  { font-size: 15px; font-weight: 700; }
.ps-time  { font-size: 12px; color: var(--muted); flex-shrink: 0; font-variant-numeric: tabular-nums; }

.ps-card-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px 8px;
  flex-wrap: wrap;
}
.turnout-chip {
  font-size: 12px; padding: 2px 8px; border-radius: 12px;
  background: #f3f4f6; border: 1px solid var(--border); color: var(--muted);
}
.winner-chip {
  font-size: 12px; padding: 2px 9px; border-radius: 12px;
  color: #fff; font-weight: 600;
}
.new-badge {
  display: inline-block; margin-left: 7px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  background: #22c55e; color: #fff; padding: 1px 5px; border-radius: 4px; vertical-align: middle;
}

/* ── Party bars ──────────────────────────────────────────────────────────────── */
.party-bars { display: flex; flex-direction: column; }
.party-row {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 12px;
  border-top: 1px solid rgba(0,0,0,.04);
}
.party-badge {
  width: 20px; height: 20px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 11px; flex-shrink: 0;
}
.party-badge.lg { width: 26px; height: 26px; font-size: 13px; border-radius: 5px; }
.party-label { flex: 0 0 120px; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-wrap { flex: 1; height: 9px; background: rgba(0,0,0,.07); border-radius: 4px; overflow: hidden; }
.bar-wrap.lg { height: 12px; }
.bar  { height: 100%; border-radius: 4px; transition: width .4s ease; }
.party-pct { flex: 0 0 42px; text-align: right; font-size: 13px; font-weight: 700;
             font-variant-numeric: tabular-nums; }

/* ── Detail view ─────────────────────────────────────────────────────────────── */
.detail-view {}

.detail-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.detail-title { font-size: 20px; font-weight: 700; margin-bottom: 3px; }
.detail-sub   { font-size: 13px; color: var(--muted); }
.pdf-link {
  font-size: 13px; font-weight: 600; color: var(--accent);
  padding: 6px 14px; border: 1.5px solid var(--accent);
  border-radius: 6px; white-space: nowrap; flex-shrink: 0;
  transition: background .12s, color .12s;
}
.pdf-link:hover { background: var(--accent); color: #fff; }

/* Detail bars */
.detail-bars { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow); }
.detail-party-block { border-bottom: 1px solid rgba(0,0,0,.05); }
.detail-party-block:last-child { border-bottom: none; }
.detail-party-row {
  display: flex; align-items: center; gap: 10px; padding: 7px 14px;
}
.detail-party-mandates {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 3px 14px 4px 14px;
}
.detail-party-winners {
  padding: 3px 14px 6px 14px; font-size: 12px; color: #555;
}
.detail-party-name  { flex: 0 0 160px; font-size: 14px; }
.detail-party-pct   { flex: 0 0 50px; text-align: right; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.detail-party-votes { flex: 0 0 44px; text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.detail-bars-hdr { display: flex; align-items: center; gap: 10px; padding: 3px 14px; border-bottom: 1px solid var(--border); }
.detail-bars-hdr .dbh-spacer { flex: 1; }
.detail-col-hdr  { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; font-weight: 600; text-align: right; }
.detail-col-old  { flex: 0 0 44px; }
.detail-col-diff { flex: 0 0 44px; }
.detail-old-pct  { flex: 0 0 44px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.detail-diff     { flex: 0 0 44px; text-align: right; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.detail-diff.pos { color: #2a9d5c; }
.detail-diff.neg { color: #c0392b; }
.mandates-wrap      { display: flex; flex-wrap: wrap; gap: 4px; }
.mandate-chip       { font-size: 11px; padding: 2px 8px; border-radius: 10px; color: #fff; font-weight: 600; }
.mandate-votes      { margin-left: 5px; opacity: .75; font-weight: 400; }

/* Candidate grid */
.cand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
}
.cand-block { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.cand-header {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  color: #fff; font-size: 13px; font-weight: 700;
}
.cand-header-badge {
  width: 20px; height: 20px; border-radius: 4px; background: rgba(0,0,0,.22);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; color: #fff; flex-shrink: 0;
}
.cand-row {
  display: flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-top: 1px solid rgba(0,0,0,.05); font-size: 12px;
}
.cand-nr    { width: 18px; text-align: right; color: var(--muted); font-size: 11px; flex-shrink: 0; }
.cand-name  { flex: 1; }
.cand-name.italic { font-style: italic; color: var(--muted); }
.cand-votes { width: 34px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.cand-row.elected .cand-name { font-weight: 700; }
.cand-row.list-row { opacity: .8; }

/* ── Styled HTML (psempty / prognosis) ───────────────────────────────────────── */
.styled-html {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  font-size: 14px;
}
.styled-html table { width: 100%; border-collapse: collapse; font-family: var(--font); font-size: 13px; }
.styled-html td, .styled-html th { padding: 5px 8px; vertical-align: middle; }
.styled-html .tabheader td { font-size: 13px; color: var(--muted); }
.styled-html h2.topheader  { font-size: 18px; font-weight: 700; color: var(--text); }
.styled-html .tabtop { border-top: 2px solid var(--accent); margin-top: 8px; }
.styled-html .tabtop .header td { background: var(--accent); color: #fff; font-weight: 600; padding: 6px 8px; }
.styled-html .headerparty td { padding: 5px 8px; }
.styled-html .c1 { width: 5%; text-align: center; }
.styled-html .c2 { width: 38%; }
.styled-html .c3, .styled-html .c4,
.styled-html .c5, .styled-html .c6,
.styled-html .c7 { text-align: right; }
.styled-html h3  { font-size: 15px; color: var(--muted); text-align: center; margin-top: 24px; }

/* ── Card highlight (scroll-to animation) ────────────────────────────────────── */
@keyframes cardPulse {
  0%   { box-shadow: 0 0 0 0 rgba(0,102,204,.5); }
  50%  { box-shadow: 0 0 0 6px rgba(0,102,204,.2); }
  100% { box-shadow: 0 0 0 0 rgba(0,102,204,0); }
}
.card-highlight {
  outline: 2px solid var(--accent2);
  animation: cardPulse 1.8s ease forwards;
}

/* ── Prognosis extras ────────────────────────────────────────────────────────── */
.prog-label { font-size: 12px; font-weight: 600; color: var(--muted); align-self: center; }
.prog-note  { margin-top: 10px; font-size: 13px; color: var(--muted); font-style: italic; padding: 8px 4px; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.empty-state { text-align: center; color: var(--muted); padding: 60px 20px; font-size: 16px; }

/* ── Mobile ──────────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  html, body { overflow: auto; height: auto; }
  #app       { flex-direction: column; height: auto; overflow: visible; }

  #sidebar {
    width: 100%; overflow: visible;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .nav-top-list { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px; }
  .nav-top-list .nav-item a { padding: 6px 12px; border-radius: 20px; border-left: none; font-size: 13px; }
  .nav-top-list .nav-item.active a { border-left: none; }

  /* Compact pill list for stations on mobile */
  .nav-stations {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    overflow: visible;
    padding: 0 8px 8px;
  }
  .nav-stations .nav-item a { border-radius: 12px; border-left: none; padding: 3px 8px; }
  .nav-stations .nav-item.active a { border-left: none; }

  #valcontent { overflow: visible; padding: 10px; }
  .feed-grid  { grid-template-columns: 1fr; }
  .cand-grid  { grid-template-columns: 1fr 1fr; }
  .detail-party-name { flex: 0 0 120px; font-size: 13px; }
  .detail-title { font-size: 17px; }
  .detail-bars { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.detail-bars-hdr, .detail-party-row { min-width: 600px; }
}
