/* dawum-summary – Gestaltung.
 *
 * Farbrollen sind als Custom Properties definiert und einmal je Farbschema
 * gesetzt: einmal per Systemeinstellung, einmal per Umschalter am Kopf.
 */

:root {
  color-scheme: light;

  --surface: #fcfcfb;
  --plane: #f9f9f7;
  --surface-sunken: #f2f1ec;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #2a78d6;
  --up: #006300;
  --down: #c0392b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 8px 24px -16px rgba(11, 11, 11, 0.25);
  --ghost: rgba(11, 11, 11, 0.05);

  --radius: 12px;
  --radius-sm: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface: #1a1a19;
    --plane: #0d0d0d;
    --surface-sunken: #131312;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.20);
    --accent: #3987e5;
    --up: #0ca30c;
    --down: #e66767;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -16px rgba(0, 0, 0, 0.8);
    --ghost: rgba(255, 255, 255, 0.07);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface: #1a1a19;
  --plane: #0d0d0d;
  --surface-sunken: #131312;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.20);
  --accent: #3987e5;
  --up: #0ca30c;
  --down: #e66767;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px -16px rgba(0, 0, 0, 0.8);
  --ghost: rgba(255, 255, 255, 0.07);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

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

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 19px; }
h2 { font-size: 16px; }
p { margin: 0; }

.wrap { max-width: 1220px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--text-muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ Kopf */

.site-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.head-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
  flex-wrap: wrap;
}

.brand .sub { color: var(--text-secondary); font-size: 13px; margin-top: 2px; }
.head-actions { display: flex; align-items: center; gap: 10px; }

/* ------------------------------------------------------- Formularelemente */

.field { display: inline-flex; align-items: center; gap: 8px; }
.field-label { font-size: 12px; color: var(--text-muted); }

select, input[type="date"] {
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
}
select:focus-visible, input:focus-visible, button:focus-visible, summary:focus-visible,
svg:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.12s ease;
}
.btn:hover { background: var(--ghost); }
.btn-icon { width: 34px; padding: 7px 0; text-align: center; font-size: 15px; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-secondary); }
.btn-quiet:hover { background: var(--ghost); }
.btn-block { display: block; width: 100%; margin-top: 10px; }

.segmented {
  display: inline-flex;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
}
.seg {
  font: inherit;
  font-size: 13px;
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.seg:hover { background: var(--ghost); }
.seg.is-active {
  background: var(--surface);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.check .muted { margin-left: auto; font-variant-numeric: tabular-nums; }

input[type="range"] { accent-color: var(--accent); width: 130px; }

/* ------------------------------------------------------------- Filterzeile */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 22px;
  padding: 16px 0 18px;
}
.filter { display: flex; align-items: center; gap: 8px; }
.filter-label { font-size: 12px; color: var(--text-muted); }
.custom-range { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.custom-range[hidden] { display: none; }

.dropdown { position: relative; }
.dropdown summary { list-style: none; user-select: none; }
.dropdown summary::-webkit-details-marker { display: none; }
.dropdown summary::after { content: " ▾"; color: var(--text-muted); }
.dropdown-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
  display: grid;
  gap: 2px;
}
.dropdown-panel .check { padding: 5px 8px; border-radius: 6px; }
.dropdown-panel .check:hover { background: var(--ghost); }

/* ------------------------------------------------------------------ Karten */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px 20px;
  margin-bottom: 18px;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-sub { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.notice { text-align: center; padding: 48px 20px; }

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
@media (max-width: 940px) {
  /* minmax(0, …) statt 1fr: sonst erzwingen die Tabellen mit ihrem
   * Mindestmaß eine Spalte breiter als der Bildschirm. */
  .split { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------------------ Kennzahlen */

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(184px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px 12px;
  display: grid;
  gap: 2px;
}
.tile-head { display: flex; align-items: center; gap: 7px; min-width: 0; }
.tile-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile-value { font-size: 32px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.tile-spark { height: 30px; margin: 2px 0 4px; }
.tile-foot { display: flex; align-items: baseline; gap: 6px; font-size: 12px; }
.delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.is-up { color: var(--up); }
.delta.is-down { color: var(--down); }
.delta.is-flat { color: var(--text-muted); }

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

/* ------------------------------------------------------ Wahltermin-Zeile */

.stamp {
  display: inline-block;
  margin-left: 8px;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.election-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin: 0 0 16px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
}
.election-strip strong { color: var(--text-primary); font-weight: 650; }

/* ---------------------------------------------------------- Sitzverteilung */

.seats-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 20px;
  align-items: center;
}
@media (max-width: 780px) {
  .seats-layout { grid-template-columns: minmax(0, 1fr); }
}
.hemi-total {
  font-size: 26px;
  font-weight: 650;
  font-family: var(--font);
}
.fineprint {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-muted);
  max-width: 90ch;
}

/* ---------------------------------------------------------------- Legende */

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; }
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-secondary);
}
.legend-rect { width: 12px; height: 12px; border-radius: 3px; }
.legend-line { width: 16px; height: 3px; border-radius: 2px; }

/* --------------------------------------------------------------- Diagramm */

.chart { position: relative; min-height: 120px; }
.chart-flat { min-height: 0; }
.chart-svg { display: block; overflow: visible; }
.chart-tick { font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-endlabel { font-size: 11px; font-family: var(--font); }
.chart-marker { font-size: 10.5px; font-family: var(--font); }
.chart-endvalue { font-size: 12px; font-weight: 650; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-inlabel { font-size: 12px; font-weight: 600; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-empty {
  padding: 48px 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}
.spark { display: block; overflow: visible; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  min-width: 168px;
  max-width: calc(100vw - 48px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  padding: 9px 11px;
  font-size: 12px;
  z-index: 10;
}
.tt-head { font-weight: 650; font-size: 12px; }
.tt-sub { color: var(--text-muted); font-size: 11px; margin-bottom: 6px; }
.tt-rows { display: grid; gap: 3px; }
.tt-row { display: grid; grid-template-columns: 14px auto 1fr; align-items: baseline; gap: 7px; }
.tt-key { width: 14px; height: 3px; border-radius: 2px; align-self: center; }
.tt-row strong { font-variant-numeric: tabular-nums; font-size: 12.5px; }
.tt-name { color: var(--text-secondary); }

/* ----------------------------------------------------------- Gruppeneditor */

.preset-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.preset-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 0 0;
  min-height: 1.2em;
}

.editor { display: grid; gap: 10px; margin-top: 14px; }
.group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px 12px;
  background: var(--surface-sunken);
}
.group-head { display: flex; align-items: center; gap: 8px; }
.group-name {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 6px;
  min-width: 0;
  flex: 1 1 auto;
}
.group-name:hover { border-color: var(--border-strong); }
.group-name:focus { background: var(--surface); border-color: var(--accent); outline: none; }
.group-sum {
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  white-space: nowrap;
}
.icon-btn {
  font: inherit;
  font-size: 17px;
  line-height: 1;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--ghost); color: var(--text-primary); }

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  padding: 0;
  flex: 0 0 auto;
}
.swatch.is-active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.swatch-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin: 4px 0; }
.swatch-grid .swatch { width: 26px; height: 26px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  min-height: 34px;
  padding: 4px;
  border-radius: 6px;
  border: 1px dashed transparent;
}
.chips.is-over { border-color: var(--accent); background: var(--ghost); }
.chips-empty { font-size: 12px; color: var(--text-muted); padding: 5px 4px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12.5px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 4px 10px 4px 8px;
  cursor: grab;
}
.chip:hover { border-color: var(--accent); }
.chip.is-dragging { opacity: 0.4; }

.pool { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.pool-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.pool-head .count { font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- Popover */

.popover {
  position: absolute;
  z-index: 60;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
}
.popover-title {
  font-size: 11px;
  color: var(--text-muted);
  padding: 2px 6px 6px;
}
.popover-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  font: inherit;
  font-size: 13px;
  color: var(--text-primary);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
}
.popover-row:hover { background: var(--ghost); }
.popover-note {
  font-size: 11px;
  color: var(--text-muted);
  margin: 6px 6px 2px;
  max-width: 210px;
}

/* --------------------------------------------------------------- Tabellen */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0 10px 8px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 7px 10px 7px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--ghost); }
.table td:first-child { display: table-cell; }
.table td .dot { display: inline-block; vertical-align: -1px; margin-right: 7px; }
.table .num { font-variant-numeric: tabular-nums; }
.table .num.is-up { color: var(--up); }
.table .num.is-down { color: var(--down); }
.table-compact td, .table-compact th { padding-right: 14px; }

.minibar {
  display: inline-block;
  height: 6px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 8px;
  opacity: 0.85;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  cursor: pointer;
}
.tag:hover { border-color: var(--accent); color: var(--text-primary); }
.tag.is-none { color: var(--text-muted); font-style: italic; }

/* ------------------------------------------------------------------- Fuß */

.site-foot {
  border-top: 1px solid var(--border);
  margin-top: 28px;
  padding: 22px 0 40px;
  font-size: 12.5px;
  color: var(--text-secondary);
}
.foot-inner { display: grid; gap: 8px; }
.foot-inner .muted { max-width: 78ch; }

/* ------------------------------------------------------------------ Mobil
 *
 * Grundsatz: nichts schrumpfen, bis es unlesbar wird, sondern umbrechen. Die
 * Filterzeile wird zur Filterspalte, breite Tabellen scrollen in sich selbst,
 * und quer über die Seite scrollt nie etwas.
 */

@media (max-width: 720px) {
  .wrap { padding: 0 14px; }
  .card { padding: 16px 14px; margin-bottom: 14px; }
  .brand h1 { font-size: 17px; }

  /* Kopf: Titel oben, Bedienelemente darunter in einer eigenen Zeile. */
  .head-inner { flex-direction: column; align-items: stretch; gap: 10px; }
  .head-actions { gap: 8px; }
  .head-actions .field { flex: 1 1 auto; min-width: 0; }
  .head-actions select { width: 100%; }
  .head-actions .btn { white-space: nowrap; flex: 0 0 auto; }
  .stamp { margin-left: 0; margin-top: 4px; display: block; width: fit-content; }

  /* Filter: Beschriftung über das Bedienelement statt daneben. Der Regler
   * behält seinen Wert auf derselben Zeile – zwei Zeilen für „Glättung: 10“
   * wären verschenkt. */
  .filters { gap: 12px; padding: 14px 0 16px; }
  .filter {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 5px 10px;
    width: 100%;
  }
  .filter > .filter-label,
  .filter > .segmented,
  .filter > .dropdown,
  .filter > .custom-range { grid-column: 1 / -1; }
  .filter > output { grid-column: 2; white-space: nowrap; }
  .filter:last-child { display: flex; align-items: center; }
  .segmented { width: 100%; justify-content: space-between; }
  .seg { flex: 1 1 auto; text-align: center; white-space: nowrap; padding: 7px 6px; }
  input[type="range"] { width: 100%; }
  .filter .dropdown, .filter .dropdown .btn { width: 100%; text-align: left; }
  .dropdown-panel { min-width: 0; width: 100%; }
  .custom-range { flex-wrap: wrap; }
  .custom-range input { flex: 1 1 130px; }

  /* Zwei Kacheln nebeneinander – fünf einspaltige Blöcke sind zu viel Weg. */
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px 12px 10px; }
  .tile-value { font-size: 25px; }
  .tile-spark { height: 26px; }
  .tile-foot { flex-wrap: wrap; gap: 2px 6px; }

  /* Der Balken hinter dem Wert ist Zierde; ohne ihn passt die Spalte mit der
   * Veränderung noch auf den Bildschirm, und die ist eine Information. */
  .minibar { display: none; }

  .card-head { gap: 10px; margin-bottom: 12px; }
  .legend { gap: 4px 12px; }
  .fineprint { max-width: none; }
  .preset-row { gap: 8px; }
  .preset-row .field { flex: 1 1 100%; }
  .preset-row select { flex: 1 1 auto; min-width: 0; }
}

@media (max-width: 430px) {
  .table th, .table td { padding-right: 8px; }
  .tile-value { font-size: 23px; }
  .election-strip { padding: 9px 11px; }
}

@media print {
  .site-head, .filters, .preset-row, .pool, #export, #poll-more { display: none !important; }
  .card { break-inside: avoid; box-shadow: none; }
}
