/* Farben als Tokens; hell ist Standard, dunkel per Systemeinstellung oder Umschalter (data-theme) */
:root {
  color-scheme: light;
  --bg: #F4F5F7; --surface: #FFFFFF; --ink: #111418; --ink2: #3A424D; --muted: #5B6470;
  --line: #E3E6EA; --line2: #EEF0F2; --input: #D5D9DF;
  --accent: #2448C9; --accent-ink: #1A3599; --accent-bg: #E8EDFC; --accent-soft: #F4F6FD;
  --good: #0E6A41; --good-bg: #E6F4EC; --bad: #A32015; --bad-bg: #FDECEA;
  --warn: #9A4A06; --warn-bg: #FFF4E5; --warn-dot: #E07B12; --ok-dot: #12A150;
  --bar-soft: #C5D1F6; --pending: #8FA5EA; --radius: 12px;
  --on-ink: #FFFFFF; --ink-hover: #2A2F36; --hover: #ECEEF2; --btn-hover-line: #AEB5BF;
  --note-bg: #F0F3FD; --note-line: #D6DEFA; --panel-bg: #F7F9FE; --drop-bg: #FAFBFC; --drop-line: #C5CBD3;
  --dot-bad: #C4320A; --dot-grey: #9AA1AB; --warn-line: #F3C98B;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0F1216; --surface: #171B21; --ink: #E8EBEF; --ink2: #C3C9D1; --muted: #8E97A3;
    --line: #2A3038; --line2: #222830; --input: #39414B;
    --accent: #7B97F5; --accent-ink: #A9BCFA; --accent-bg: #1E2A4D; --accent-soft: #19213A;
    --good: #5DD39A; --good-bg: #133626; --bad: #F48A7E; --bad-bg: #3D1A17;
    --warn: #F5B66A; --warn-bg: #3A2710; --warn-dot: #E8902F; --ok-dot: #2FBF6E;
    --bar-soft: #34437A; --pending: #5D74C2;
    --on-ink: #0F1216; --ink-hover: #FFFFFF; --hover: #222830; --btn-hover-line: #56606C;
    --note-bg: #19213A; --note-line: #2C3A66; --panel-bg: #19202E; --drop-bg: #141920; --drop-line: #3A424D;
    --dot-bad: #E5573A; --dot-grey: #6B7480; --warn-line: #7A5420;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1216; --surface: #171B21; --ink: #E8EBEF; --ink2: #C3C9D1; --muted: #8E97A3;
  --line: #2A3038; --line2: #222830; --input: #39414B;
  --accent: #7B97F5; --accent-ink: #A9BCFA; --accent-bg: #1E2A4D; --accent-soft: #19213A;
  --good: #5DD39A; --good-bg: #133626; --bad: #F48A7E; --bad-bg: #3D1A17;
  --warn: #F5B66A; --warn-bg: #3A2710; --warn-dot: #E8902F; --ok-dot: #2FBF6E;
  --bar-soft: #34437A; --pending: #5D74C2;
  --on-ink: #0F1216; --ink-hover: #FFFFFF; --hover: #222830; --btn-hover-line: #56606C;
  --note-bg: #19213A; --note-line: #2C3A66; --panel-bg: #19202E; --drop-bg: #141920; --drop-line: #3A424D;
  --dot-bad: #E5573A; --dot-grey: #6B7480; --warn-line: #7A5420;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; }
a { color: var(--accent); } a:hover { color: var(--accent-ink); }
button, input, select { font-family: inherit; font-size: 14px; }
[hidden] { display: none !important; }
h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
h3 { margin: 0; font-size: 15px; font-weight: 600; }
.muted { color: var(--muted); } .small { font-size: 12px; } .center { text-align: center; }
.num { font-variant-numeric: tabular-nums; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.error { color: var(--bad); font-weight: 600; min-height: 1em; margin: 0; }

/* Layout */
.app { min-height: 100vh; display: flex; flex-wrap: wrap; }
.side { flex: 1 1 228px; background: var(--surface); border-right: 1px solid var(--line); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; }
.brand { padding: 4px 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.brand-name { font-weight: 700; font-size: 16px; }
.side-shop { padding: 0 12px 16px; }
.side-shop select { font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; padding: 9px 12px; border-radius: 8px; color: var(--ink2);
  text-decoration: none; min-height: 40px; }
.nav a:hover { background: var(--hover); color: var(--ink); }
.nav a.on { background: var(--accent-bg); color: var(--accent-ink); font-weight: 600; }
.side-user { margin-top: auto; padding: 16px 12px 0; display: flex; flex-wrap: wrap; gap: 6px; justify-content: space-between; align-items: center;
  gap: 8px; border-top: 1px solid var(--line2); }
.main { flex: 999 1 560px; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px;
  max-width: 1440px; outline: none; }
@media (max-width: 820px) {
  .side { border-right: none; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .side-user { margin-top: 8px; }
  .main { padding: 20px 16px 40px; }
}

/* Header */
.page-head { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-end; justify-content: space-between; }
.page-title { display: flex; flex-direction: column; gap: 6px; }
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { min-height: 40px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--input); background: var(--surface);
  color: var(--ink2); font-weight: 500; cursor: pointer; font-size: 13px; }
.pill[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink2); min-height: 40px; padding: 0 12px;
  border: 1px solid var(--input); border-radius: 8px; background: var(--surface); cursor: pointer; }
.check input { margin: 0; width: 16px; height: 16px; }
.custom-range { display: flex; gap: 6px; align-items: center; }
.custom-range input { min-height: 40px; padding: 6px 10px; border: 1px solid var(--input); border-radius: 8px; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card.table-card { padding: 16px 6px 6px; }
.card.table-card > h2, .card.table-card > .card-head, .card.table-card > p { margin-left: 12px; margin-right: 12px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.grid { display: grid; gap: 14px; }
.g-kpi { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.g-2 { grid-template-columns: repeat(auto-fit, minmax(480px, 1fr)); }
.g-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g-pl { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
@media (max-width: 1100px) { .g-pl { grid-template-columns: 1fr; } }
@media (max-width: 560px) { .g-2, .g-3 { grid-template-columns: 1fr; } }
.kpi { padding: 16px 18px; gap: 8px; }
.kpi-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.badge { font-size: 11px; font-weight: 600; border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.b-grey { background: var(--line2); color: var(--ink2); } .b-warn { background: var(--warn-bg); color: var(--warn); }
.b-good { background: var(--good-bg); color: var(--good); } .b-bad { background: var(--bad-bg); color: var(--bad); }
.b-blue { background: var(--accent-bg); color: var(--accent-ink); }
.delta { font-weight: 600; border-radius: 6px; padding: 2px 6px; font-variant-numeric: tabular-nums; }
.d-good { background: var(--good-bg); color: var(--good); } .d-bad { background: var(--bad-bg); color: var(--bad); }
.strip { display: flex; flex-wrap: wrap; gap: 8px 18px; align-items: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; }
.strip-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.src { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.dot-ok { background: var(--ok-dot); } .dot-warn { background: var(--warn-dot); } .dot-bad { background: var(--dot-bad); }
.dot-grey { background: var(--dot-grey); }
.note { margin: 0; font-size: 13px; color: var(--accent-ink); background: var(--note-bg); border: 1px solid var(--note-line);
  border-radius: 10px; padding: 10px 14px; }
.est-note { margin-left: auto; font-size: 13px; color: var(--warn); background: var(--warn-bg); border-radius: 999px; padding: 4px 10px; }

/* Chart */
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink2); }
.legend span { display: flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-wrap { overflow-x: auto; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 210px; min-width: 520px; border-bottom: 1px solid var(--input);
  padding: 0 2px; }
.chart-col { flex: 1 1 0; min-width: 0; display: flex; align-items: flex-end; justify-content: center; gap: 1px; height: 100%; }
.bar { flex: 1 1 0; border-radius: 3px 3px 0 0; min-height: 1px; }
.bar-rev { background: var(--bar-soft); } .bar-prof { background: var(--accent); } .bar-est { background: var(--warn-dot); }
.bar-neg { background: var(--bad); }
.chart-labels { display: flex; gap: 4px; min-width: 520px; padding: 6px 2px 0; }
.chart-labels span { flex: 1 1 0; min-width: 0; font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; }
.hbar { height: 8px; background: var(--line2); border-radius: 999px; overflow: hidden; }
.hbar > div { height: 100%; background: var(--accent); border-radius: 999px; }
.cost-row { display: flex; flex-direction: column; gap: 5px; }
.cost-row-top { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.stack { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--line2); }

/* Tables */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line2); white-space: nowrap; font-variant-numeric: tabular-nums;
  vertical-align: middle; }
th.r, td.r { text-align: right; }
td.wrap { white-space: normal; min-width: 220px; }
table.compact th, table.compact td { padding: 9px 8px; font-size: 13px; }
.kv .num, .kv b { white-space: nowrap; }
tr.sel { background: var(--accent-soft); }
tr.total { background: var(--accent-soft); font-weight: 700; }
tr.sub td { font-weight: 700; }
td.ded { padding-left: 24px; color: var(--ink2); }
.empty { padding: 16px 12px; color: var(--muted); }

/* Forms & buttons */
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 500; color: var(--ink2); }
.fld input, .fld select, .inp { min-height: 40px; padding: 8px 12px; border: 1px solid var(--input); border-radius: 8px;
  background: var(--surface); color: var(--ink); width: 100%; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.btn { min-height: 38px; padding: 6px 14px; border-radius: 8px; border: 1px solid var(--input); background: var(--surface);
  color: var(--ink2); font-weight: 500; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { border-color: var(--btn-hover-line); }
.btn-dark { background: var(--ink); color: var(--on-ink); border-color: var(--ink); font-weight: 600; }
.btn-dark:hover { background: var(--ink-hover); }
.btn-red { background: var(--bad); color: var(--on-ink); border-color: var(--bad); font-weight: 600; }
.btn-danger { color: var(--bad); }
.btn-wide { width: 100%; min-height: 46px; font-size: 15px; }
.btn-link { border: none; background: transparent; color: var(--accent); cursor: pointer; padding: 6px 0; }
.btn-row { display: flex; flex-wrap: wrap; gap: 6px; }
.order-link { border: none; background: transparent; padding: 4px 0; font-weight: 600; color: var(--accent);
  cursor: pointer; text-decoration: underline; }
.panel { border: 1px solid var(--note-line); background: var(--panel-bg); border-radius: var(--radius); padding: 16px; display: flex;
  flex-direction: column; gap: 12px; margin: 0 12px 12px; }
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 140px;
  border: 2px dashed var(--drop-line); border-radius: var(--radius); background: var(--drop-bg); padding: 20px; text-align: center; }
.split { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-start; }
.split > .main-col { flex: 999 1 640px; min-width: 0; }
.split > .side-col { flex: 1 1 290px; min-width: 0; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line2); }
.kv:last-child { border-bottom: none; }
.mini-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.mini-grid .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.secret { font-family: ui-monospace, monospace; background: var(--line2); padding: 8px 10px; border-radius: 8px;
  word-break: break-all; font-size: 13px; }
.loading { color: var(--muted); padding: 40px 0; }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 40px 16px; }
.login-box { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 20px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.login-brand .brand-name { font-size: 22px; }
.login-card { padding: 28px; gap: 16px; }
.login-card > div { display: flex; flex-direction: column; gap: 16px; }
.login-card h1 { font-size: 20px; }
.code-input { font-size: 18px !important; letter-spacing: 0.2em; text-align: center; }

.viewer [data-write] { display: none !important; }
.sr { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
details > summary { padding: 4px 0 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--on-ink);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s;
  max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; }
.toast.err { background: var(--bad); }

/* Zeitraum als kompakte Auswahl */
.range-select { min-height: 40px; padding: 8px 32px 8px 12px; border: 1px solid var(--input); border-radius: 8px;
  background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; }
.custom-range input { background: var(--surface); color: var(--ink); }
.theme-btn { margin-top: 6px; }
