/* WDTEC Promo – Admin-Oberfläche
   Farben als Variablen: hier zentral anpassen. Dunkelmodus folgt dem System. */

:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #7d7b75;
  --line: #e4e3dc;
  --line-strong: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: rgba(42, 120, 214, 0.1);
  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --warn-ink: #8a5a00;
  --bad: #d03b3b;
  --bad-ink: #b02a2a;
  --neutral: #898781;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0f0f0e;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f6f6f3;
    --ink-2: #c3c2b7;
    --muted: #8f8d86;
    --line: #2c2c2a;
    --line-strong: #444440;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --good-ink: #3fc23f;
    --warn-ink: #fab219;
    --bad-ink: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
.os-icon { display: inline-flex; vertical-align: -4px; margin-right: 6px; color: var(--ink-2); }
.os-icon svg { width: 18px; height: 18px; }
.muted { color: var(--muted); }
.ink-2 { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 12px; background: var(--surface); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: 0.02em;
}
.brand-name { font-weight: 650; line-height: 1.15; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav a {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 8px;
  color: var(--ink-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--accent-wash); color: var(--accent-ink); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav a { position: relative; }
.nav-dot { width: 10px; height: 10px; border-radius: 50%; margin-left: auto; flex: none; background: var(--neutral); box-shadow: 0 0 0 2px var(--surface); }
.nav-dot.ok { background: var(--good); }
.nav-dot.warn { background: #f08c00; }
.nav-dot.alarm { background: var(--bad); animation: dot-pulse 1.6s ease-in-out infinite; }
@keyframes dot-pulse { 50% { box-shadow: 0 0 0 2px var(--surface), 0 0 0 6px rgba(208, 59, 59, 0.25); } }
@media (prefers-reduced-motion: reduce) { .nav-dot.alarm { animation: none; } }
.sidebar-foot { margin-top: auto; padding: 10px; font-size: 12px; color: var(--muted); display: grid; gap: 8px; }
.instance-tag {
  display: inline-block; padding: 3px 8px; border-radius: 999px; background: var(--surface-2);
  color: var(--ink-2); font-weight: 500; border: 1px solid var(--border);
}

.main { min-width: 0; padding: 22px clamp(16px, 3vw, 36px) 60px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 18px; }
.page-head h1 { font-size: 22px; line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.page-head .sub { color: var(--muted); font-size: 13px; }
.page-head .spacer { flex: 1; }

/* ── Bausteine ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.main > .card + .card, .main > .card + .grid, .main > .grid + .card, .main > .tiles + .card { margin-top: 16px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 14px 16px 10px; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card-head .spacer { flex: 1; }
.card-body { padding: 0 16px 16px; }
.card-note { padding: 10px 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { padding: 14px 16px 16px; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; line-height: 1.1; }
.tile .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
.tile.hero .value { font-size: 40px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad-ink); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: transparent; }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; height: 34px; padding: 0 10px; min-width: 0;
}
textarea { height: auto; padding: 8px 10px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
input[type='search'] { min-width: min(260px, 100%); }
label.field { display: grid; gap: 5px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
label.field input, label.field select, label.field textarea { width: 100%; }
.field-hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; cursor: pointer; }
.check input { height: auto; }
input[type='checkbox'], input[type='radio'] { width: 16px; height: 16px; padding: 0; margin: 0; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.selection-bar { background: var(--accent-wash); border-top: 1px solid var(--line); padding-block: 8px; }

.segmented { display: inline-flex; flex-wrap: wrap; padding: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button {
  border: 0; background: transparent; font: inherit; font-size: 13px; padding: 4px 10px; border-radius: 7px;
  color: var(--ink-2); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.segmented button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
td { font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { border-top: 1px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); }

/* Verteilungsbalken (gestapelt) mit Legende */
.stack { display: flex; gap: 2px; height: 10px; min-width: 120px; }
.stack .seg { min-width: 3px; height: 100%; }
.stack .seg:first-child { border-radius: 4px 0 0 4px; }
.stack .seg:last-child { border-radius: 0 4px 4px 0; }
.stack .seg:only-child { border-radius: 4px; }
.s-run { background: var(--series-1); }
.s-conv { background: var(--series-2); }
.s-exp { background: var(--series-3); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
th.right, td.right { text-align: right; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

/* Status */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px;
  font-size: 12px; font-weight: 550; background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
  border: 1px solid var(--border);
}
.badge::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--neutral); }
.badge.good::before { background: var(--good); }
.badge.warn::before { background: var(--warn); }
.badge.bad::before { background: var(--bad); }
.badge.info::before { background: var(--accent); }
.badge.plain::before { display: none; }
.badge.buy { background: var(--accent); color: #fff; border-color: transparent; }
.badge.buy::before { background: #fff; }
.badge.buy-light { background: var(--accent-wash); color: var(--accent-ink); border-color: transparent; }
.badge.buy-light::before { background: var(--accent); }

.meter { display: flex; align-items: center; gap: 8px; min-width: 130px; }
.meter-track { flex: 1; height: 6px; border-radius: 3px; background: var(--accent-wash); overflow: hidden; }
.meter-fill { height: 100%; background: var(--accent); border-radius: 3px; }
.meter-text { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.app-name { font-weight: 550; }
.app-pkg { display: block; font-size: 12px; color: var(--muted); font-family: var(--mono); }

.notice {
  display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius);
  background: var(--accent-wash); color: var(--ink); font-size: 13.5px; margin-bottom: 16px;
}
.notice.warn { background: rgba(250, 178, 25, 0.14); }
.notice.bad { background: rgba(208, 59, 59, 0.1); }
.notice strong { font-weight: 600; }

/* Aktivität */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; padding: 9px 16px; border-top: 1px solid var(--line); align-items: baseline; }
.feed li:first-child { border-top: 0; }
.feed .what { min-width: 0; overflow-wrap: anywhere; }
.feed .when { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* Sicherheit */
.sec-banner {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: var(--radius);
  font-weight: 650; font-size: 15px; margin-bottom: 16px;
}
.sec-banner.ok { background: rgba(12, 163, 12, 0.12); color: var(--good-ink); }
.sec-banner.warn { background: rgba(250, 178, 25, 0.2); color: var(--warn-ink); }
.sec-banner.alarm { background: var(--bad); color: #fff; }
.good-ink { color: var(--good-ink); }
.warn-ink { color: var(--warn-ink); }
.findings { list-style: none; margin: 0; padding: 0 0 6px; }
.findings li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding: 9px 16px; border-top: 1px solid var(--line); line-height: 1.5; }
.findings li:first-child { border-top: 0; }
.findings strong { font-weight: 650; }
.finding-meta { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.lvl {
  width: 20px; height: 20px; border-radius: 6px; display: grid; place-items: center; margin-top: 1px;
  font-size: 12px; font-weight: 800; color: #fff; background: var(--accent);
}
.lvl.alarm { background: var(--bad); }
.lvl.warn { background: var(--warn); color: #3a2700; }
.chip {
  display: inline-block; padding: 1px 8px; margin: 1px 4px 1px 0; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--border); white-space: nowrap;
}
.chip.bad { background: rgba(208, 59, 59, 0.1); color: var(--bad-ink); border-color: transparent; }
.chip.warn { background: rgba(230, 160, 0, 0.14); color: var(--warn-ink); border-color: transparent; }
.sec-table th { position: static; }
.sec-table th.group { text-align: center; color: var(--accent-ink); border-bottom-color: var(--line-strong); }
td.zero { color: var(--muted); }
td.peak, .legend-peak { background: var(--accent); color: #fff; font-weight: 650; }
td.hot, .legend-hot { background: rgba(208, 59, 59, 0.12); color: var(--bad-ink); font-weight: 650; }
.legend-peak, .legend-hot { padding: 0 5px; border-radius: 4px; }
td.examples { max-width: 420px; overflow-wrap: anywhere; font-size: 12px; }
.ip-ex { font-size: 11.5px; margin-top: 4px; max-width: 520px; overflow-wrap: anywhere; }
.attempts { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.attempts li { display: grid; gap: 4px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13.5px; }
.attempt-ex { font-size: 12px; overflow-wrap: anywhere; }
.drawer .feed li { padding-inline: 0; }

/* Diagramm */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .base-line { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .bar { fill: var(--series-1); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart .bar.hover { filter: brightness(1.12); }
.chart-tip {
  position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); border-radius: 7px;
  padding: 6px 9px; font-size: 12px; white-space: nowrap; transform: translate(-50%, calc(-100% - 8px));
  box-shadow: var(--shadow);
}
.chart-tip b { font-weight: 650; }

/* Overlays */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
dialog::backdrop { background: rgba(10, 10, 10, 0.35); }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px 6px; }
.dlg-head h3 { margin: 0; font-size: 17px; font-weight: 650; flex: 1; }
.dlg-body { padding: 10px 18px 18px; max-height: calc(100vh - 180px); overflow: auto; }
.dlg-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 12px 18px 16px; border-top: 1px solid var(--line); }

.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(620px, 100vw); background: var(--surface); z-index: 40;
  border-left: 1px solid var(--border); box-shadow: -20px 0 60px rgba(0, 0, 0, 0.18);
  display: flex; flex-direction: column; transform: translateX(105%); transition: transform 0.18s ease;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: 18px 18px 10px; border-bottom: 1px solid var(--line); }
.drawer-head h3 { margin: 0; font-size: 17px; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.drawer-body { overflow: auto; padding: 16px 18px 40px; display: grid; gap: 18px; align-content: start; }
.drawer-body h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); font-weight: 600; }
.scrim { position: fixed; inset: 0; background: rgba(10, 10, 10, 0.25); z-index: 39; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast {
  background: var(--ink); color: var(--surface); padding: 10px 14px; border-radius: 9px; box-shadow: var(--shadow);
  max-width: min(420px, calc(100vw - 32px)); font-size: 13.5px;
}
.toast.bad { background: var(--bad); color: #fff; }

.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); min-width: 190px; z-index: 30; padding: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}
.menu-list button {
  display: block; width: 100%; text-align: left; border: 0; background: transparent; font: inherit; color: var(--ink);
  padding: 7px 10px; border-radius: 7px; cursor: pointer;
}
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger { color: var(--bad-ink); }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); padding: 28px 26px; }
.login-card h1 { font-size: 20px; margin: 14px 0 4px; }
.login-card form { display: grid; gap: 14px; margin-top: 18px; }
.error-text { color: var(--bad-ink); font-size: 13px; min-height: 18px; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

/* ── Schmal ─────────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center;
    padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto;
  }
  .brand { padding: 0 8px 0 0; }
  .brand-text, .sidebar-foot .instance-tag { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 0 9px; }
  .nav a span { display: none; }
  .nav-dot { position: absolute; top: 5px; right: 4px; width: 8px; height: 8px; margin: 0; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
  .main { padding-top: 16px; }
  .hide-sm { display: none; }
}
