:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ef;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;   /* verfuegbar */
  --series-2: #eb6834;   /* unterwegs */
  --series-3: #1baf7a;   /* einbehalten */
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-ink: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --good-ink: #0ca30c;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 24px 64px; }

/* ---------- Kopf ---------- */
header.top {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
h1 { font-size: 22px; font-weight: 650; margin: 0 0 2px; letter-spacing: -0.01em; }
.meta { color: var(--ink-2); font-size: 13px; }
.meta .sep { color: var(--muted); margin: 0 6px; }
.actions { display: flex; align-items: center; gap: 10px; }
button.refresh {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
button.refresh:hover { filter: brightness(1.08); }
button.refresh:disabled { opacity: .7; cursor: progress; }
button.refresh svg { width: 16px; height: 16px; }
button.refresh.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Karten und Abschnitte ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
section { margin-top: 28px; }
section > h2 { font-size: 15px; font-weight: 650; margin: 0 0 4px; }
section > .sub { color: var(--ink-2); font-size: 13px; margin: 0 0 12px; }

/* ---------- Kennzahlen ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { padding: 16px 18px; }
.kpi .label { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 13px; font-weight: 550; }
.kpi .swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.kpi .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 6px 0 8px; white-space: nowrap; }
.kpi .split { display: grid; gap: 2px; font-size: 12.5px; color: var(--ink-2); }
.kpi .split div { display: flex; justify-content: space-between; gap: 8px; }
.kpi .split span:last-child { font-variant-numeric: tabular-nums; color: var(--ink); }
.kpi.total { background: var(--surface-2); }

/* ---------- Status-Leiste ---------- */
.statusbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
  font-size: 12.5px; color: var(--ink); text-decoration: none;
}
.chip:hover { background: var(--surface-2); }
.dot { width: 16px; height: 16px; border-radius: 50%; display: inline-grid; place-items: center;
  font-size: 10px; font-weight: 800; color: #fff; flex: none; }
.dot.ok { background: var(--good); }
.dot.partial { background: var(--warning); color: #0b0b0b; }
.dot.error { background: var(--critical); }
.dot.not_configured { background: transparent; border: 1.5px dashed var(--muted); color: var(--muted); }

/* ---------- Tabellen ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 14px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--muted); font-weight: 550; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr.sum td { font-weight: 650; border-top: 1px solid var(--muted); }
td.muted, .muted { color: var(--muted); }
td.strong { font-weight: 650; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 5px;
  background: var(--surface-2); color: var(--ink-2); }
.when { font-weight: 600; }
tr.arrived td { color: var(--ink-2); }
tr.arrived td.num { text-decoration: line-through; text-decoration-color: var(--muted); }
tr.arrived td.num.muted { text-decoration: none; }
.urgent { display: inline-flex; align-items: center; gap: 6px; font-weight: 650; color: var(--critical); }
section .sub a { color: var(--accent); }
.status-inline { display: inline-flex; align-items: center; gap: 5px; margin-left: 8px; font-weight: 500; font-size: 12px; color: var(--ink-2); }

/* ---------- Verteilung (gestapelte Balken) ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12.5px; color: var(--ink-2); margin: 0 0 10px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸ "; }
details[open] > summary::before { content: "▾ "; }
.bars { padding: 10px 16px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 130px; align-items: center; gap: 14px; padding: 7px 0; }
.bar-row .name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .total { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.track { display: flex; gap: 2px; height: 16px; align-items: stretch; }
.seg { height: 100%; min-width: 3px; cursor: default; }
.seg:last-child { border-radius: 0 4px 4px 0; }
.seg.s1 { background: var(--series-1); }
.seg.s2 { background: var(--series-2); }
.seg.s3 { background: var(--series-3); }
.track.empty { background: repeating-linear-gradient(135deg, var(--grid) 0 2px, transparent 2px 6px); border-radius: 4px; }
.tooltip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--ink); color: var(--page);
  padding: 7px 10px; border-radius: 7px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.18);
  font-variant-numeric: tabular-nums; display: none;
}

/* ---------- Kontokarten ---------- */
.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 12px; }
.acc { padding: 14px 16px; scroll-margin-top: 16px; }
.acc header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.acc h3 { font-size: 15px; margin: 0; display: flex; align-items: center; gap: 8px; }
.acc .status { font-size: 12px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.acc table { font-size: 13px; }
.acc th, .acc td { padding: 6px 8px; }
.acc .facts { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; font-size: 12.5px; margin-top: 10px; }
.acc .facts dt { color: var(--muted); }
.acc .facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.msg { font-size: 12.5px; border-radius: 7px; padding: 8px 10px; margin-top: 8px; }
.msg.error { background: color-mix(in srgb, var(--critical) 12%, transparent); }
.msg.note { background: var(--surface-2); color: var(--ink-2); }
.msg.idle { background: var(--surface-2); color: var(--ink-2); }

/* ---------- Zustaende ---------- */
.banner { padding: 14px 16px; margin-top: 16px; font-size: 13.5px; }
.banner.error { border-color: var(--critical); }
.loading { color: var(--ink-2); padding: 40px 0; text-align: center; }
.empty { color: var(--muted); padding: 14px 16px; font-size: 13px; }
footer { margin-top: 36px; color: var(--muted); font-size: 12px; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .wrap { padding: 16px 16px 48px; }
  .kpis { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 100px 1fr 96px; gap: 8px; }
  .accounts { grid-template-columns: 1fr; }
}

/* ---------- Heute zu tun ---------- */
.todo { padding: 10px 14px; margin-bottom: 14px; }
.todo-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 650; font-size: 14px; margin-bottom: 2px; }
.todo-head .muted { font-weight: 400; font-size: 12px; }
.todo-row { display: flex; align-items: flex-start; gap: 10px; padding: 7px 4px; border-radius: 6px; color: var(--ink); text-decoration: none; font-size: 13.5px; }
.todo-row:hover { background: var(--surface-2); }
.todo-text { flex: 1; min-width: 0; }
.todo-sub { display: block; color: var(--ink-2); font-size: 12px; margin-top: 1px; }
.todo-when { font-size: 12px; font-weight: 600; white-space: nowrap; }
.todo-when.red { color: var(--critical); }
.tdot { width: 9px; height: 9px; border-radius: 50%; flex: none; margin-top: 5px; }
.tdot.red { background: var(--critical); }
.tdot.yellow { background: var(--warning); }
.tdot.green { background: var(--good); margin-top: 4px; }
.todo-more { background: none; border: 0; color: var(--accent); font: inherit; font-size: 12.5px; cursor: pointer; padding: 4px 4px 2px 23px; }
.todo-ok { display: flex; gap: 10px; align-items: flex-start; font-size: 12.5px; color: var(--ink-2); border-top: 1px solid var(--grid); margin-top: 6px; padding: 8px 4px 2px; }

/* ---------- Vergleich in den Kacheln ---------- */
.compare-bar { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-bottom: 8px; font-size: 12.5px; flex-wrap: wrap; }
.cmp-seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg-btn { background: none; border: 0; border-left: 1px solid var(--border); color: var(--ink-2); font: inherit; font-size: 12.5px; padding: 5px 10px; cursor: pointer; }
.seg-btn:first-child { border-left: 0; }
.seg-btn:hover { background: var(--surface-2); }
.seg-btn.on { background: var(--accent); color: var(--accent-ink); }
.kpi .label { justify-content: flex-start; }
.kpi .trend { display: flex; align-items: center; gap: 8px; margin: 6px 0 10px; cursor: default; }
.kpi .trend-cap { flex: none; min-width: 44px; font-size: 10.5px; color: var(--muted); }
.kpi .trend-line { position: relative; flex: 1; height: 26px; }
.kpi .trend-line svg { display: block; width: 100%; height: 100%; overflow: visible; }
.kpi .trend-line polyline { fill: none; stroke: var(--ink-2); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.kpi .trend-line .spark-area { fill: var(--ink-2); opacity: 0.08; }
.kpi .trend-dot { position: absolute; right: -3px; width: 6px; height: 6px; border-radius: 50%; background: var(--ink); transform: translateY(-50%); }
.kpi .value { margin-bottom: 2px; }
.delta { font-size: 12.5px; margin-bottom: 8px; font-variant-numeric: tabular-nums; }
.delta.good { color: var(--good-ink); }
.delta.bad { color: var(--critical); }
.delta.flat { color: var(--ink-2); }
.delta .muted { font-weight: 400; }
@media (max-width: 560px) {
  .compare-bar .muted { display: none; }
  .cmp-seg { width: 100%; }
  .seg-btn { flex: 1 1 0; padding: 5px 4px; font-size: 12px; line-height: 1.25; }
}

/* Freigabe-Rechner */
.rel-calc { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 16px; border-bottom: 1px solid var(--grid); }
.rel-calc label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); }
.rel-calc input[type="date"] { font: inherit; font-size: 13px; color: var(--ink); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 4px 8px; }
.rel-result { margin-left: auto; font-size: 13px; color: var(--ink-2); }
.rel-result b { color: var(--ink); font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.rel-chart { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin: 0 16px; padding-top: 16px; border-bottom: 1px solid var(--grid); }
.rel-col { flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; background: none; border: 0; padding: 0; cursor: pointer; border-radius: 4px 4px 0 0; }
.rel-col:hover { background: var(--surface-2); }
.rel-bar { display: block; width: 100%; max-width: 34px; background: var(--series-3); border-radius: 4px 4px 0 0; }
.rel-col.later .rel-bar { opacity: 0.3; }
.rel-axis { display: flex; gap: 6px; margin: 0 16px; padding: 6px 0 12px; }
.rel-axis span { flex: 1 1 0; text-align: center; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; }
.rel-undated { border-top: 1px solid var(--grid); padding: 10px 16px 12px; }
.rel-undated h3 { font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.rel-undated-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; padding: 3px 0; }
.rel-undated-row .num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
@media (max-width: 560px) {
  .rel-result { margin-left: 0; }
  .rel-chart, .rel-axis { gap: 3px; }
  .rel-axis span:nth-child(even) { visibility: hidden; }
  .rel-undated-row { flex-direction: column; gap: 0; }
  .rel-undated-row .num { text-align: left; }
}

/* Anmeldung und Einrichtung */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; box-sizing: border-box; }
.auth-card { width: 100%; max-width: 380px; padding: 24px; display: flex; flex-direction: column; gap: 12px; box-sizing: border-box; }
.auth-card.wide { max-width: 480px; }
.auth-card h1 { font-size: 20px; margin: 0; }
.auth-card h2 { font-size: 14px; margin: 10px 0 0; }
.auth-card p { margin: 0; font-size: 13.5px; color: var(--ink-2); line-height: 1.45; }
.auth-card .sub { margin: 0 0 4px; }
.auth-card .small { font-size: 12.5px; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
.auth-card input { font: inherit; font-size: 15px; color: var(--ink); background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; }
.auth-card input:focus { outline: 2px solid var(--accent); outline-offset: 0; }
.auth-card button.refresh { justify-content: center; margin-top: 6px; padding: 10px 14px; }
.auth-card code { font-size: 12.5px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.auth-card a { color: var(--accent); }
.auth-error { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--ink); border: 1px solid color-mix(in srgb, var(--critical) 40%, transparent); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.qr { align-self: center; background: #fff; padding: 10px; border-radius: 8px; line-height: 0; }
.qr img, .qr canvas { display: block; }
.qr.qr-missing { background: none; line-height: 1.4; font-size: 13px; color: var(--ink-2); padding: 0; }
a.logout { font-size: 13px; color: var(--ink-2); text-decoration: none; }
a.logout:hover { color: var(--ink); text-decoration: underline; }
