/* msk-analytics Dashboard – keine externen Schriften oder Skripte. */

:root {
  color-scheme: light dark;

  --bg:        #f6f7f9;
  --surface:   #ffffff;
  --surface-2: #f0f2f5;
  --border:    #dfe3e8;
  --text:      #16181d;
  --muted:     #616a76;
  --accent:    #6b4ce6;
  --accent-2:  #d94f9a;
  --good:      #17916b;
  --warn:      #b8760c;
  --bad:       #c33c3c;
  --shadow:    0 1px 2px rgba(16, 18, 24, .06), 0 8px 24px rgba(16, 18, 24, .05);

  --c1: #6b4ce6; --c2: #d94f9a; --c3: #2e8fd8; --c4: #17916b;
  --c5: #d98c1f; --c6: #8a56c4; --c7: #4aa3a3; --c8: #b1566b;

  --radius: 14px;
  --radius-sm: 9px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1115;
    --surface:   #171a21;
    --surface-2: #1e222b;
    --border:    #2b303b;
    --text:      #e8eaee;
    --muted:     #98a1b0;
    --accent:    #9b83ff;
    --accent-2:  #ef7cb8;
    --good:      #3ec49a;
    --warn:      #e0a13c;
    --bad:       #ef6f6f;
    --shadow:    0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);

    --c1: #9b83ff; --c2: #ef7cb8; --c3: #62b6f0; --c4: #3ec49a;
    --c5: #eab452; --c6: #b394e8; --c7: #6fc9c9; --c8: #de8397;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

/* ── Kopfzeile ─────────────────────────────────────────────────────────── */

header.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; letter-spacing: -.2px; margin-right: 6px; }
.brand span { color: var(--accent); }

.top .spacer { flex: 1 1 auto; }

nav.tabs { display: flex; gap: 4px; flex-wrap: wrap; }

nav.tabs button {
  border: 0; background: transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 999px; cursor: pointer;
  font: inherit; font-weight: 600;
}
nav.tabs button:hover { background: var(--surface-2); color: var(--text); }
nav.tabs button[aria-selected="true"] { background: var(--accent); color: #fff; }

/* ── Bedienelemente ────────────────────────────────────────────────────── */

select, input[type="text"], input[type="password"], input[type="date"], input[type="number"] {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

button.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 13px;
}
button.btn:hover { background: var(--surface-2); }
button.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.btn.primary:hover { filter: brightness(1.08); }
button.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--border)); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--muted);
}

/* ── Layout ────────────────────────────────────────────────────────────── */

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
section[hidden] { display: none !important; }

.grid { display: grid; gap: 16px; }
.grid.kpis  { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.two   { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.card h2 {
  margin: 0 0 4px; font-size: 14px; font-weight: 700;
  letter-spacing: .02em; text-transform: uppercase; color: var(--muted);
}
.card .hint { margin: 0 0 12px; font-size: 12.5px; color: var(--muted); }

.kpi .value { font-size: 30px; font-weight: 700; letter-spacing: -.5px; line-height: 1.1; }
.kpi .label { font-size: 13px; color: var(--muted); margin-top: 2px; }
.kpi .sub   { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ── Tabellen ──────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr.sel { background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* Balken im Tabellenhintergrund */
.barcell { position: relative; }
.barcell .bar {
  position: absolute; inset: 3px auto 3px 0;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border-radius: 4px; z-index: 0;
}
.barcell .lbl { position: relative; z-index: 1; }

/* ── Diagramme ─────────────────────────────────────────────────────────── */

.chart { width: 100%; display: block; overflow: visible; }
.chart .axis   { stroke: var(--border); stroke-width: 1; }
.chart .gridln { stroke: var(--border); stroke-width: 1; stroke-dasharray: 3 4; opacity: .7; }
.chart text    { fill: var(--muted); font-size: 11px; }
.chart .area   { fill: url(#accentGrad); }
.chart .line   { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot    { fill: var(--accent); }
.chart .hit    { fill: transparent; cursor: crosshair; }

.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; font-size: 13px; }
.legend .item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }

.tooltip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 7px 10px; font-size: 13px; white-space: nowrap;
}
.tooltip[hidden] { display: none; }

/* ── Funnel ────────────────────────────────────────────────────────────── */

.funnel-step { margin-bottom: 10px; }
.funnel-step .head {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 13px; margin-bottom: 4px;
}
.funnel-step .name { font-weight: 600; }
.funnel-step .meta { color: var(--muted); font-variant-numeric: tabular-nums; }
.funnel-step .track {
  height: 30px; background: var(--surface-2); border-radius: 7px;
  overflow: hidden; display: flex; align-items: center;
}
.funnel-step .fill {
  height: 100%; flex: none; border-radius: 7px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; padding-left: 9px;
  color: #fff; font-size: 12.5px; font-weight: 700;
  white-space: nowrap; overflow: hidden;
  transition: width .35s ease;
}
.funnel-step .fill.narrow { padding-left: 0; min-width: 4px; }
.funnel-step .track .outside {
  padding-left: 8px; font-size: 12.5px; font-weight: 700; color: var(--muted);
  white-space: nowrap;
}
.funnel-step .drop { font-size: 12px; color: var(--bad); }

.step-editor { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.step-editor .row { display: flex; gap: 6px; align-items: center; }
.step-editor .row select { flex: 1 1 auto; min-width: 0; }
.step-editor .idx {
  width: 22px; height: 22px; flex: none; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}

/* ── Flow ──────────────────────────────────────────────────────────────── */

.flow-row {
  display: grid; grid-template-columns: 1fr auto 1fr auto;
  gap: 10px; align-items: center; padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.flow-row:last-child { border-bottom: 0; }
.flow-row .arrow { color: var(--muted); }
.flow-row .n { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 13px; }
.flow-row .node {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 5px 9px;
  font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.flow-row .node.end { color: var(--muted); font-style: italic; }

/* ── Login ─────────────────────────────────────────────────────────────── */

.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.field input { width: 100%; }
.error {
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  color: var(--bad);
  border-radius: var(--radius-sm); padding: 9px 11px; font-size: 13.5px; margin-bottom: 13px;
}
.error[hidden] { display: none; }

/* ── Sonstiges ─────────────────────────────────────────────────────────── */

.empty { color: var(--muted); font-size: 14px; padding: 22px 0; text-align: center; }
.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; background: var(--surface-2);
  padding: 3px 6px; border-radius: 5px; word-break: break-all;
}
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.notice {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px; color: var(--text);
}
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; font-weight: 600;
  z-index: 100; box-shadow: var(--shadow);
}
.toast[hidden] { display: none; }

@media (max-width: 640px) {
  main { padding: 14px; }
  header.top { padding: 10px 14px; }
  .kpi .value { font-size: 25px; }
}

/* ── Layout-Hilfsklassen ───────────────────────────────────────────────────
 * Ersetzen style="…"-Attribute im HTML. Die Content-Security-Policy erlaubt
 * bewusst keine Inline-Styles, damit von dieser Seite aus nichts nachgeladen
 * oder eingeschleust werden kann. */

.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.w-full { width: 100%; }
.grow { flex: 1 1 auto; min-width: 0; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* Kennzahl innerhalb einer Karte (z. B. Funnel-Gesamtabschluss) */
.stat-big { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 13px; }

/* Ringdiagramm */
.chart.donut { max-width: 150px; margin: 0 auto; }
.chart .donut-total { font-size: 16px; font-weight: 700; fill: var(--text); }
