:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f0eee9;
  --border: #e2dfd8;
  --text: #1b1a18;
  --text-2: #52514e;
  --text-3: #77756f;
  --brand: #5b2333;
  --brand-ink: #ffffff;
  --accent: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #b9b6ad;
  --good: #16794a;
  --warn: #9a5b00;
  --bad: #b3261e;
  --good-bg: #e6f4ec;
  --warn-bg: #fdf1dc;
  --bad-bg: #fbe9e7;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #34332f;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9a988f;
    --brand: #8c3a50;
    --accent: #5a9cec;
    --series-1: #3987e5;
    --series-2: #5c5a54;
    --good: #5cc98f;
    --warn: #e5a73c;
    --bad: #f07a70;
    --good-bg: #183324;
    --warn-bg: #3a2c12;
    --bad-bg: #3d1b18;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #34332f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #9a988f; --brand: #8c3a50; --accent: #5a9cec;
  --series-1: #3987e5; --series-2: #5c5a54; --good: #5cc98f; --warn: #e5a73c; --bad: #f07a70;
  --good-bg: #183324; --warn-bg: #3a2c12; --bad-bg: #3d1b18;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; }
.muted { color: var(--text-3); }
.small { font-size: .85rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Kopfzeile */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 1rem;
  background: var(--brand); color: var(--brand-ink); padding: 0 16px; min-height: 52px;
}
.brand { color: #fff; font-weight: 700; white-space: nowrap; }
.brand span { font-weight: 400; opacity: .8; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #fff; opacity: .82; padding: 15px 10px; white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a:hover { opacity: 1; text-decoration: none; }
.nav a.on { opacity: 1; border-bottom-color: #fff; font-weight: 600; }
.badge { display: inline-block; min-width: 1.3em; padding: 0 .35em; border-radius: 9px; background: #fff; color: var(--brand); font-size: .75rem; text-align: center; }
.logout button { color: #fff; opacity: .8; }

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.foot { text-align: center; color: var(--text-3); font-size: .8rem; padding: 0 16px 24px; }

.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.pagehead p { margin: 0; color: var(--text-2); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stack > * + * { margin-top: 16px; }

/* Kennzahlen */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; color: var(--text); display: block; }
a.kpi:hover { text-decoration: none; border-color: var(--text-3); }
.kpi .label { color: var(--text-2); font-size: .82rem; }
.kpi .value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: .8rem; color: var(--text-3); }
.up { color: var(--good); } .down { color: var(--bad); }

/* Tabellen */
.tablewrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .78rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .02em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; gap: .75rem; justify-content: space-between; align-items: baseline; }
.list li:last-child { border-bottom: 0; }

/* Formulare */
label { display: block; font-size: .85rem; color: var(--text-2); }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 80px; resize: vertical; }
.form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form .full { grid-column: 1 / -1; }
.inline { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline > * { flex: 1 1 160px; }
.inline > .btn, .inline > button { flex: 0 0 auto; }
.check { display: flex; align-items: center; gap: 6px; }
.check input { width: auto; margin: 0; }
.btn {
  display: inline-block; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--text-3); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: .85rem; font-weight: 500; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
form.inl { display: inline; }

.flash { background: var(--good-bg); color: var(--text); border: 1px solid var(--good); padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }
.error { background: var(--bad-bg); border: 1px solid var(--bad); padding: 10px 14px; border-radius: 8px; }
.note { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; color: var(--text-2); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs a { padding: 5px 12px; border-radius: 16px; background: var(--surface-2); color: var(--text-2); font-size: .9rem; }
.tabs a.on { background: var(--text); color: var(--surface); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 12px; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dl.facts dt { color: var(--text-3); font-size: .85rem; }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }
details > summary { cursor: pointer; color: var(--accent); }

/* Diagramm */
.chart { width: 100%; height: auto; display: block; }
.chart .gl { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: var(--text-3); stroke-width: 1; }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .hit { fill: transparent; }
.chart .bar-g:hover .hit { fill: var(--surface-2); }
.legend { display: flex; gap: 16px; font-size: .85rem; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Pipeline */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.col h3 { margin: 0 0 8px; display: flex; justify-content: space-between; }
.opp { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; }
.opp summary { list-style: none; }
.opp summary::-webkit-details-marker { display: none; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; display: grid; gap: 12px; }
.login h1 { color: var(--brand); }
.login h1 span { font-weight: 400; color: var(--text-2); }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 0 1rem; padding-top: 8px; }
  .brand { order: 1; }
  .logout { order: 2; margin-left: auto; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -16px; padding: 0 8px; }
  .nav a { padding: 10px 10px 12px; }
  h1 { font-size: 1.25rem; }
  .hide-sm { display: none; }
  .kpi .value { font-size: 1.25rem; }
}
