/* Aktivitätsauswertung – dunkles, ruhiges Dashboard.
   Statusfarben (gut / Warnung / Befreiung / kritisch) erscheinen immer zusammen mit Symbol und Beschriftung.
   Keine Inline-Styles (CSP style-src 'self'); Positionen setzt nur das Skript über CSSOM. */

:root {
  color-scheme: dark;
  --bg: #0b0d11;
  --surface-1: #11141a;
  --surface-2: #161a21;
  --surface-3: #1c212a;
  --surface-4: #252b36;
  --row-hover: #171c24;
  --row-active: #1f2632;
  --line: rgba(148, 163, 184, 0.13);
  --line-strong: rgba(148, 163, 184, 0.26);
  --text: #e8ecf2;
  --text-2: #b1b9c6;
  --text-3: #808a99;

  --accent: #5b9dff;
  --accent-strong: #3f86f2;
  --accent-bg: rgba(91, 157, 255, 0.14);
  --focus: #8ab8ff;

  --good: #39c07a;
  --good-fg: #74dca3;
  --good-bg: rgba(57, 192, 122, 0.13);
  --warn: #f0b43c;
  --warn-fg: #f6ca6c;
  --warn-bg: rgba(240, 180, 60, 0.13);
  --exempt: #f28a52;
  --exempt-fg: #f8aa7c;
  --exempt-bg: rgba(242, 138, 82, 0.14);
  --bad: #f2555a;
  --bad-fg: #ff8d90;
  --bad-bg: rgba(242, 85, 90, 0.14);
  --judge: #a78bfa;
  --judge-bg: rgba(167, 139, 250, 0.14);
  --vip: #e9c46a;
  --permanent: #8fb2e6;
  --permanent-bg: rgba(143, 178, 230, 0.14);
  --archive: #a78bfa;

  /* Gruppenfarben der Tabellenköpfe (zurückhaltend, nur als Akzentlinie und Punkt). */
  --g-person: #94a3b8;
  --g-status: #e58aa9;
  --g-weekly: #5b9dff;
  --g-checks: #3cc4b4;
  --g-lifetime: #a78bfa;
  --g-join: #94a3b8;

  --radius-s: 6px;
  --radius: 10px;
  --radius-l: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 2px 8px rgba(0, 0, 0, 0.35);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", "SF Mono", ui-monospace, Consolas, monospace;
  --col-rank: 70px;
  --col-id: 86px;
  --col-name: 184px;
  --head-1: 36px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 16px; height: 16px; flex: none; vertical-align: -3px; }
.icon-warning { color: var(--warn); }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
b, strong { font-weight: 650; }
.num, .tnum { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ Kopfbereich */

.appbar {
  display: flex;
  align-items: center;
  gap: 12px 20px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border-radius: 10px;
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid rgba(91, 157, 255, 0.3);
}
.brand-mark .icon { width: 20px; height: 20px; }
.brand h1 { font-size: 17px; line-height: 1.2; }
.brand-unit { margin: 0; color: var(--text-3); font-size: 12.5px; }
.appbar-end { margin-left: auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.refresh {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px;
  font-size: 12.5px; color: var(--text-2);
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-2);
  max-width: 100%;
}
.refresh-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.refresh-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.12); }
.refresh[data-state="ok"] .refresh-dot { background: var(--good); box-shadow: 0 0 0 3px var(--good-bg); }
.refresh[data-state="refreshing"] .refresh-dot { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); animation: pulse 1.2s ease-in-out infinite; }
.refresh[data-state="stale"] .refresh-dot,
.refresh[data-state="restored"] .refresh-dot { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-bg); }
.refresh[data-state="error"] .refresh-dot,
.refresh[data-state="offline"] .refresh-dot { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.refresh[data-state="archive"] .refresh-dot { background: var(--archive); box-shadow: 0 0 0 3px var(--judge-bg); }
@keyframes pulse { 50% { opacity: 0.35; } }

.edit-state {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 10px;
  font-size: 12.5px; color: var(--text-2);
  border-radius: 999px; background: var(--accent-bg);
}
.edit-state b { color: var(--text); }

/* ------------------------------------------------------------ Steuerleiste: Woche, Suche, Aktionen */

.controls {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px 16px;
  padding: 12px 20px 10px;
}
.week-block { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.week-nav { display: flex; align-items: center; gap: 6px; min-width: 0; }
.week-select {
  position: relative; display: inline-flex; align-items: center;
}
.week-select select {
  appearance: none;
  height: 36px; padding: 0 36px 0 38px;
  min-width: 270px; max-width: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.week-select select:hover { background: var(--surface-3); }
.week-select select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.week-select .icon { position: absolute; pointer-events: none; color: var(--text-3); }
.week-select .icon-cal { left: 12px; }
.week-select .icon-chev { right: 12px; width: 14px; height: 14px; }
.week-badge {
  display: inline-flex; align-items: center; gap: 5px;
  height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.week-badge-current { background: var(--good-bg); color: var(--good-fg); }
.week-badge-archive { background: var(--judge-bg); color: #c4b2ff; }
.period { color: var(--text-3); font-size: 12.5px; min-width: 0; padding-left: 2px; }
.period b { color: var(--text-2); font-weight: 600; }

.controls-end { margin-left: auto; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.search {
  display: inline-flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px;
  width: 280px; max-width: 100%;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface-1); color: var(--text-3);
}
.search:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(138, 184, 255, 0.18); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font: inherit; outline: none; }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { filter: invert(0.7); }

/* ------------------------------------------------------------ Übersicht / Filter */

.summary {
  display: flex; align-items: center; gap: 8px;
  padding: 0 20px 12px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  height: 32px; padding: 0 12px 0 10px; flex: none;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface-1); color: var(--text-2);
  font: inherit; font-size: 12.5px; cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s;
}
.chip:hover { background: var(--surface-2); border-color: var(--line-strong); }
.chip[aria-pressed="true"] { background: var(--accent-bg); border-color: rgba(91, 157, 255, 0.55); color: var(--text); }
.chip-count { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.chip .icon { width: 14px; height: 14px; }
.chip-good .icon { color: var(--good); }
.chip-bad .icon { color: var(--bad); }
.chip-exempt .icon { color: var(--exempt); }
.chip-warn .icon { color: var(--warn); }
.chip-muted .icon { color: var(--text-3); }
.chip:disabled { cursor: default; opacity: 0.55; }
.summary-count { margin-left: auto; padding-left: 8px; color: var(--text-3); font-size: 12.5px; white-space: nowrap; }

/* ------------------------------------------------------------ Schaltflächen */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface-3); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background-color 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--surface-4); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-outline { background: transparent; }
.btn-primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-primary:hover { background: #3577dd; }
.btn-danger { background: transparent; border-color: rgba(242, 85, 90, 0.5); color: var(--bad-fg); }
.btn-danger:hover { background: var(--bad-bg); }
.btn-small { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn .badge-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
  display: inline-grid; place-items: center;
  background: var(--warn-bg); color: var(--warn-fg); font-size: 11.5px; font-weight: 700;
}
.btn-warn .icon { color: var(--warn); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; flex: none;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface-1); color: var(--text-2);
  cursor: pointer;
}
.icon-btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.icon-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.icon-btn-plain { border-color: transparent; background: transparent; }

/* ------------------------------------------------------------ Hinweisleisten */

.banners { display: flex; flex-direction: column; gap: 8px; padding: 0 20px; }
.banners:empty { display: none; }
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-1); color: var(--text-2);
  font-size: 13px;
}
.banner .icon { margin-top: 1px; }
.banner b { color: var(--text); }
.banner[data-level="warn"] { border-color: rgba(240, 180, 60, 0.4); background: linear-gradient(0deg, var(--warn-bg), var(--warn-bg)), var(--surface-1); }
.banner[data-level="warn"] .icon { color: var(--warn); }
.banner[data-level="error"] { border-color: rgba(242, 85, 90, 0.45); background: linear-gradient(0deg, var(--bad-bg), var(--bad-bg)), var(--surface-1); }
.banner[data-level="error"] .icon { color: var(--bad); }
.banner[data-level="info"] .icon { color: var(--accent); }
.banner[data-level="archive"] { border-color: rgba(167, 139, 250, 0.4); background: linear-gradient(0deg, var(--judge-bg), var(--judge-bg)), var(--surface-1); }
.banner[data-level="archive"] .icon { color: var(--archive); }

main { flex: 1; min-height: 0; padding: 12px 20px 20px; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ Tabelle */

.table-wrap {
  position: relative;
  flex: 1; min-height: 260px;
  overflow: auto;
  border: 1px solid var(--line); border-radius: var(--radius-l);
  background: var(--surface-1);
  overscroll-behavior: contain;
  scrollbar-color: var(--surface-4) transparent;
  scrollbar-width: thin;
}
.table-wrap[data-loading="true"] .grid tbody { opacity: 0.45; transition: opacity 0.15s; }

.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; font-size: 13px; }
.grid th, .grid td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: middle; white-space: nowrap;
  background: var(--surface-1);
}

.grid thead th { position: sticky; z-index: 3; background: var(--surface-2); font-weight: 600; color: var(--text-2); }
.grid thead tr.groups th {
  top: 0; height: var(--head-1); padding: 0 12px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-2);
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 2px 0 var(--group-color, transparent);
}
.grid thead tr.groups th[data-group="person"] { --group-color: var(--g-person); }
.grid thead tr.groups th[data-group="status"] { --group-color: var(--g-status); }
.grid thead tr.groups th[data-group="weekly"] { --group-color: var(--g-weekly); }
.grid thead tr.groups th[data-group="checks"] { --group-color: var(--g-checks); }
.grid thead tr.groups th[data-group="lifetime"] { --group-color: var(--g-lifetime); }
.grid thead tr.groups th[data-group="join"] { --group-color: var(--g-join); }
.group-label { display: inline-flex; align-items: center; gap: 8px; position: sticky; left: calc(var(--col-rank) + var(--col-id) + var(--col-name) + 12px); }
.grid thead tr.groups th[data-group="person"] .group-label { position: static; }
.group-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--group-color); flex: none; }
.group-unit {
  text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 11px;
  padding: 1px 7px; border-radius: 999px;
  background: var(--surface-4); color: var(--text-2);
}
.grid thead tr.cols th { top: var(--head-1); padding: 0; font-size: 12px; border-bottom: 1px solid var(--line-strong); }

.sort-btn {
  display: inline-flex; align-items: center; gap: 5px;
  width: 100%; padding: 9px 12px;
  border: 0; background: transparent; color: inherit;
  font: inherit; text-align: left; cursor: pointer;
}
.grid th.num .sort-btn { justify-content: flex-end; }
.sort-btn:hover { color: var(--text); background: var(--surface-3); }
.sort-btn .icon { width: 12px; height: 12px; opacity: 0.3; }
.sort-btn:hover .icon { opacity: 0.7; }
th[aria-sort] .sort-btn { color: var(--text); }
th[aria-sort] .sort-btn .icon { opacity: 1; color: var(--accent); }

/* Gruppentrenner */
.grid .g-start { border-left: 1px solid var(--line-strong); }

/* Feste Identitätsspalten */
.grid .c-rank { position: sticky; left: 0; z-index: 2; width: var(--col-rank); min-width: var(--col-rank); max-width: var(--col-rank); }
.grid .c-id { position: sticky; left: var(--col-rank); z-index: 2; width: var(--col-id); min-width: var(--col-id); max-width: var(--col-id); }
.grid .c-name {
  position: sticky; left: calc(var(--col-rank) + var(--col-id)); z-index: 2;
  width: var(--col-name); min-width: var(--col-name); max-width: var(--col-name);
  overflow: hidden; text-overflow: ellipsis;
  box-shadow: 1px 0 0 var(--line-strong), 10px 0 14px -10px rgba(0, 0, 0, 0.7);
}
.grid thead .c-rank, .grid thead .c-id, .grid thead .c-name { z-index: 4; }
.grid thead th[data-group="person"] { position: sticky; left: 0; z-index: 5; box-shadow: inset 0 2px 0 var(--group-color), 1px 0 0 var(--line-strong); }

.grid tbody tr:hover td { background: var(--row-hover); }
.grid tbody td:focus { background: var(--row-active); }
.grid tbody td:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 0; }
.grid tbody tr:last-child td { border-bottom: 0; }
/* Letzte Zeile einer Ranggruppe (SGT+ | LCPL–FCPL | PFC–SFC | PVT und darunter) */
.grid tbody tr.rank-break td { border-bottom: 2px solid var(--line-strong); }

.grid td.num, .grid th.num { text-align: right; }
.grid td.num { font-variant-numeric: tabular-nums; }
.grid td.c-total { background: var(--surface-2); }
.grid tbody tr:hover td.c-total { background: var(--row-hover); }
.grid td.has-detail { cursor: pointer; }
.grid td.has-detail:hover .cell-main,
.grid td.has-detail:hover .num-value { text-decoration: underline dotted var(--text-3); text-underline-offset: 3px; }

.cell { display: flex; align-items: center; gap: 7px; }
.grid td.num .cell { justify-content: flex-end; }
.cell-stack { display: flex; flex-direction: column; gap: 2px; line-height: 1.25; min-width: 0; }
.cell-main { color: var(--text); }
.cell-sub { color: var(--text-3); font-size: 11.5px; }
.muted { color: var(--text-3); }
.zero { color: var(--text-3); opacity: 0.75; }
.strong { font-weight: 700; }

.name-text { overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.rank-prefix {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 42px; height: 22px; padding: 0 7px;
  border-radius: 5px; border: 1px solid var(--line-strong);
  background: var(--surface-3); color: var(--text);
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.03em;
}
.rank-prefix.muted { color: var(--text-3); border-style: dashed; }
.id-text { font-family: var(--mono); font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Symbol- und Statuskennzeichen */
.state { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 6px; flex: none; }
.state .icon { width: 14px; height: 14px; vertical-align: 0; }
.state-good { color: var(--good); background: var(--good-bg); }
.state-exempt { color: var(--exempt); background: var(--exempt-bg); }
.state-bad { color: var(--bad); background: var(--bad-bg); }
.state-warn { color: var(--warn); background: var(--warn-bg); }
.state-muted { color: var(--text-3); background: rgba(148, 163, 184, 0.1); }
.state-judge { color: var(--judge); background: var(--judge-bg); }
.state-vip { color: var(--vip); background: rgba(233, 196, 106, 0.14); }
.state-permanent { color: var(--permanent); background: var(--permanent-bg); }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px 0 7px;
  border-radius: 999px; border: 1px solid transparent;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pill .icon { width: 13px; height: 13px; }
.pill-good { background: var(--good-bg); color: var(--good-fg); border-color: rgba(57, 192, 122, 0.25); }
.pill-exempt { background: var(--exempt-bg); color: var(--exempt-fg); border-color: rgba(242, 138, 82, 0.28); }
.pill-bad { background: var(--bad-bg); color: var(--bad-fg); border-color: rgba(242, 85, 90, 0.3); }
.pill-warn { background: var(--warn-bg); color: var(--warn-fg); border-color: rgba(240, 180, 60, 0.28); }
.pill-muted { background: rgba(148, 163, 184, 0.09); color: var(--text-2); border-color: var(--line); }
.pill-permanent { background: var(--permanent-bg); color: var(--permanent); border-color: rgba(143, 178, 230, 0.28); }
.pill-judge { background: var(--judge-bg); color: #c4b2ff; border-color: rgba(167, 139, 250, 0.3); }
.pill-vip { background: rgba(233, 196, 106, 0.13); color: var(--vip); border-color: rgba(233, 196, 106, 0.3); }
.pill-archive { background: var(--judge-bg); color: #c4b2ff; border-color: rgba(167, 139, 250, 0.3); }

.flag { color: var(--warn); display: inline-flex; flex: none; }
.flag .icon { width: 13px; height: 13px; }
.mark { display: inline-flex; flex: none; color: var(--text-3); }
.mark .icon { width: 13px; height: 13px; }
.mark-identity { color: var(--accent); }

.empty { padding: 48px 16px; text-align: center; color: var(--text-2); display: grid; justify-items: center; gap: 10px; }
.empty .icon { width: 28px; height: 28px; color: var(--text-3); }

/* Platzhalterzeilen beim ersten Laden */
.skeleton td { height: 44px; }
.skeleton .bar { display: block; height: 10px; border-radius: 5px; background: linear-gradient(90deg, var(--surface-3), var(--surface-4), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite; }
.skeleton .bar-s { width: 36px; }
.skeleton .bar-m { width: 64px; }
.skeleton .bar-l { width: 120px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

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

.popover {
  position: fixed; z-index: 50;
  width: max-content; max-width: min(440px, calc(100vw - 16px)); max-height: min(72vh, 600px);
  overflow: auto;
  padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.popover[data-pinned="true"] { border-color: rgba(138, 184, 255, 0.6); }
.popover-close {
  position: absolute; top: 10px; right: 10px;
  width: 28px; height: 28px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-2); cursor: pointer;
  display: grid; place-items: center;
}
.popover-close:hover { background: var(--surface-4); color: var(--text); }
.popover-body { padding: 14px 16px 16px; }
.pop-kicker {
  margin: 0 36px 2px 0; color: var(--text-3);
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.02em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.popover h3 { font-size: 14.5px; margin: 0 36px 10px 0; line-height: 1.3; }
.popover h4 {
  margin: 14px 0 6px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--text-3); font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em;
}
.popover p { margin: 6px 0; color: var(--text-2); }
.popover ul { margin: 6px 0; padding-left: 18px; color: var(--text-2); }
.popover li { margin: 3px 0; }
.popover .lead { display: flex; align-items: center; gap: 8px; color: var(--text); }
.popover .kv { display: grid; grid-template-columns: auto 1fr; gap: 5px 16px; margin: 8px 0; }
.popover .kv dt { color: var(--text-3); }
.popover .kv dd { margin: 0; font-variant-numeric: tabular-nums; color: var(--text); }
.popover table { border-collapse: collapse; width: 100%; font-size: 12px; margin: 8px 0; }
.popover th, .popover td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.popover thead th { color: var(--text-3); font-weight: 600; background: var(--surface-3); }
.popover thead th:first-child { border-top-left-radius: 6px; }
.popover thead th:last-child { border-top-right-radius: 6px; }
.popover td.num, .popover th.num { text-align: right; font-variant-numeric: tabular-nums; }
.popover tr.total td { font-weight: 700; color: var(--text); border-bottom: 0; }
.popover .note { font-size: 12px; color: var(--text-3); }
.popover .callout-line { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: var(--surface-3); margin: 8px 0; color: var(--text-2); }
.popover .callout-line .icon { margin-top: 1px; }
.popover .actions { margin-top: 12px; display: flex; gap: 8px; }
.alias-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.alias { display: inline-flex; gap: 6px; align-items: center; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); color: var(--text-2); font-size: 12px; }
.alias .id-text { font-size: 12px; }

/* ------------------------------------------------------------ Dialoge */

.dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius-l);
  background: var(--surface-1); color: var(--text);
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(5, 7, 10, 0.72); backdrop-filter: blur(2px); }
.dialog-narrow { width: min(400px, calc(100vw - 24px)); }
.dialog-wide { width: min(1000px, calc(100vw - 24px)); }
.dialog form { display: flex; flex-direction: column; gap: 14px; }
.dialog-narrow form { padding: 22px 24px; }
.dialog h2 { font-size: 17px; }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 18px 14px 24px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 2; background: var(--surface-1);
}
.dialog-head p { margin: 2px 0 0; color: var(--text-3); font-size: 12.5px; }
.dialog-body { padding: 18px 24px 24px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.dialog h3 { font-size: 14px; margin: 24px 0 10px; }
.dialog h3:first-child { margin-top: 0; }
.section { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); margin-top: 16px; }
.section > h3:first-child { margin-top: 0; }

.hint { margin: 0; color: var(--text-2); font-size: 13px; }
.callout {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius);
  background: var(--accent-bg); border: 1px solid rgba(91, 157, 255, 0.3);
  color: var(--text-2); font-size: 13px;
}
.callout .icon { color: var(--accent); margin-top: 1px; }
.dialog-body > .callout { margin-bottom: 14px; }
.dialog-body > p.hint { margin-bottom: 12px; }
.callout b { color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 550; color: var(--text-2); }
.field input, .field select, .field textarea, .num-input {
  height: 38px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--bg); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 400;
}
.field textarea { height: auto; min-height: 64px; padding: 8px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .num-input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px rgba(138, 184, 255, 0.18); }
.num-input { width: 78px; height: 34px; padding: 0 8px; text-align: right; font-variant-numeric: tabular-nums; }
.num-input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-bg); }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.field-grow { flex: 1; min-width: 200px; }
.form-error { margin: 0; color: var(--bad-fg); font-size: 13px; }
.form-ok { margin: 0; color: var(--good-fg); font-size: 13px; }

.data-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.data-table th, .data-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.data-table th { color: var(--text-3); font-weight: 600; font-size: 12px; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tr.total td { font-weight: 700; color: var(--text); border-top: 1px solid var(--line-strong); }
.data-table tr.disabled td { color: var(--text-3); }
.scroll-x { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.scroll-x .data-table tr:last-child td { border-bottom: 0; }
.setup-scroll { max-height: 52vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }

.history { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.history li { padding: 9px 0; border-bottom: 1px solid var(--line); color: var(--text-2); }
.history li:last-child { border-bottom: 0; }
.history li b { color: var(--text); }
.history .meta { color: var(--text-3); font-size: 12px; }

.prose p, .prose li { color: var(--text-2); }
.prose h3 { margin: 22px 0 8px; }
.prose ul { padding-left: 18px; }
.legend-list { list-style: none; padding: 0 !important; display: grid; gap: 8px; }
.legend-list li { display: flex; align-items: center; gap: 10px; margin: 0; }

.issue-list { list-style: none; margin: 0; padding: 0; }
.issue-list li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--text-2); }
.issue-list li:last-child { border-bottom: 0; }
.issue-list li .icon { margin-top: 2px; }
.issue-persons { color: var(--text-3); font-size: 12px; margin-top: 2px; }

/* Identitäten */
.review { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); padding: 14px 16px; }
.review + .review { margin-top: 12px; }
.review-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }
.review-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.review-meta { color: var(--text-3); font-size: 12px; }
.choice-list { display: grid; gap: 8px; margin: 12px 0; }
.choice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-1); cursor: pointer;
}
.choice:hover { border-color: var(--line-strong); }
.choice:has(input:checked) { border-color: rgba(91, 157, 255, 0.6); background: var(--accent-bg); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice-text { display: grid; gap: 2px; }
.choice-sub { color: var(--text-3); font-size: 12px; }

.noscript { padding: 16px; }

/* ------------------------------------------------------------ Bildschirmgrößen */

@media (max-width: 1100px) {
  .controls-end { margin-left: 0; width: 100%; }
  .search { flex: 1 1 240px; width: auto; }
}

@media (max-width: 760px) {
  .appbar { padding: 10px 16px; }
  .appbar-end { margin-left: 0; width: 100%; flex-wrap: nowrap; }
  .refresh { flex: 1 1 auto; min-width: 0; }
  .edit-state { display: none; }
  .controls { padding: 10px 16px 8px; }
  .week-block, .week-nav { width: 100%; }
  .week-select { flex: 1; min-width: 0; }
  .week-select select { min-width: 0; width: 100%; padding-left: 12px; font-size: 13px; }
  .week-select .icon-cal, .week-badge { display: none; }
  .summary { padding: 0 16px 10px; }
  .summary-count { display: none; }
  .banners { padding: 0 16px; }
  main { padding: 8px 16px 16px; }
  .grid th, .grid td { padding: 7px 10px; }
  /* Nur der Name bleibt fixiert, damit genug Platz für die Werte bleibt. */
  .grid .c-rank, .grid .c-id { position: static; }
  .grid thead tr.cols th.c-rank, .grid thead tr.cols th.c-id { position: sticky; left: auto; }
  .grid .c-name { left: 0; width: 132px; min-width: 132px; max-width: 132px; }
  .grid thead th[data-group="person"] { position: sticky; left: auto; }
  .group-label { left: 142px; }
  .dialog-body { padding: 16px; }
  .dialog-head { padding: 14px 14px 12px 16px; }
}

/* Details als Blatt am unteren Rand auf kleinen Bildschirmen */
@media (max-width: 640px) {
  .popover {
    left: 0 !important; right: 0; top: auto !important; bottom: 0;
    width: 100%; max-width: none; max-height: 72vh;
    border-radius: var(--radius-l) var(--radius-l) 0 0;
    border-bottom: 0;
  }
  .popover::before { content: ""; display: block; width: 40px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--surface-4); }
}

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

@media (forced-colors: active) {
  .state, .flag, .pill, .chip, .rank-prefix { forced-color-adjust: auto; border: 1px solid CanvasText; }
  .refresh-dot, .group-dot { border: 1px solid CanvasText; }
}
