/*
 * Visvero CRM – Statistik, Dashboard, Einstellungen (Aufgabe 17, neuer Look Command Center Aufgabe 12).
 * Nur Tokens aus tokens.css und die Aliasse aus app.css, keine festen Farbwerte.
 * Jede Gesprächsart hat einen eigenen Akzent (--kind), damit die drei Blöcke nie verwechselt werden. Er erscheint
 * nur als Leuchtkante, Punkt, Pfeil und Balken; Texte bleiben in Textfarbe (Lesbarkeit in hell und dunkel).
 */
:root {
  --kind-kalt: var(--channel-telefon);
  --kind-setting: var(--channel-teams);
  --kind-closing: var(--success);
  --kind-lost: var(--warning);
}
.kind-kalt { --kind: var(--kind-kalt); }
.kind-setting { --kind: var(--kind-setting); }
.kind-closing { --kind: var(--kind-closing); }
.kind-lost { --kind: var(--kind-lost); }
.kind-dot { display: inline-block; flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--kind); box-shadow: 0 0 10px var(--kind); }

/* ---------- Steuerleiste ---------- */
.stats-controls { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-bottom: 24px; }
/* Kompakter Schalter (Zeitraum, Kennzahl im Verlauf): leise Pillenspur, aktiver Knopf mit Verlaufsrand und Glühen
   (aktiver Zustand aus calls.css). Gesamthöhe 36 px wie input-sm daneben. */
.segmented.seg-compact {
  display: inline-flex; flex-wrap: nowrap; gap: 2px; padding: 2px; height: 36px; max-width: 100%;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border);
}
.seg-compact .seg-btn {
  min-height: 0; height: 30px; padding: 0 13px; border-radius: 999px; border-color: transparent;
  background: transparent; color: var(--text-muted); font-size: 13px; font-weight: var(--weight-medium); white-space: nowrap;
}
.seg-compact .seg-btn:hover { color: var(--text); background: var(--surface-hover); }
.seg-compact .seg-btn[aria-pressed="true"] { color: var(--text); background: var(--pill-active-bg); font-weight: 600; }
.custom-range { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.custom-range[hidden] { display: none; }
.range-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.custom-range .input-sm { padding-right: 8px; }
.stats-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; transition: opacity var(--dur-fast) var(--ease); }
.stats-body.is-loading, .is-loading > .table-wrap { opacity: .55; }

/* ---------- Drei Blöcke ---------- */
.stat-blocks { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.stat-block { position: relative; padding: 24px 24px 24px 28px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; overflow: hidden; }
/* Leuchtkante in der Farbe der Gesprächsart */
.stat-block::before {
  content: ''; position: absolute; left: 0; top: 18px; bottom: 18px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--kind); box-shadow: 0 0 14px var(--kind);
}
.stat-block-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.stat-block-title small, .stats-card-head .card-title small { font-size: 14px; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.metric {
  padding: 14px 16px 12px; border-radius: var(--radius); background: var(--surface-inner); border: 1px solid var(--border);
  display: grid; gap: 4px; min-width: 0;
}
.metric.is-strong { border-color: color-mix(in srgb, var(--kind) 40%, var(--border)); box-shadow: 0 10px 30px -18px var(--kind); }
.metric-label { font-size: 13px; line-height: 1.3; color: var(--text-muted); font-weight: var(--weight-medium); overflow-wrap: anywhere; hyphens: auto; }
.metric { align-content: start; grid-template-rows: auto 1fr auto; }
.metric-value { align-self: end; }
.metric-value {
  font-family: var(--font-display); font-weight: var(--weight-display); font-size: 26px; line-height: 1.15; letter-spacing: -.02em;
  font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.metric-foot { min-height: 22px; font-size: 12px; display: flex; align-items: center; }
.metric-foot .kpi-delta { font-size: 12px; }

.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 12px 16px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); }
.chain-step { display: inline-flex; align-items: baseline; gap: 6px; font-size: 13px; }
.chain-label { color: var(--text-muted); }
.chain-value { font-variant-numeric: tabular-nums; color: var(--text); }
.chain-arrow { color: var(--kind); font-weight: 600; }

.goal { display: grid; gap: 8px; }
.goal-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--text-muted); flex-wrap: wrap; }
.goal-num { font-weight: 600; color: var(--text); }
.goal .goal-bar { height: 8px; }
.goal.is-reached .goal-num { color: var(--success); }

/* ---------- Karten ---------- */
/* sr-only-Beschriftungen (caption, th) in scrollbaren Tabellen dürfen die Seite nicht verbreitern */
.table-wrap { position: relative; }
.stats-card { padding: 24px; display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: 18px; min-width: 0; }
.stats-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px 12px; flex-wrap: wrap; min-height: 40px; }
.stats-card-head .card-title, .stat-block-title { flex-wrap: wrap; row-gap: 2px; column-gap: 10px; }
.ct-text { white-space: nowrap; }
.stats-card-head .card-title small, .stat-block-title small { white-space: nowrap; }
.stats-card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stats-card .table-wrap { margin: 0 -24px; }
.stats-card .table th:first-child, .stats-card .table td:first-child { padding-left: 24px; }
.stats-card .table th:last-child, .stats-card .table td:last-child { padding-right: 24px; }
.stats-table tfoot td { font-weight: 600; border-top: 1px solid var(--border-strong); border-bottom: 0; }
.stats-table tr.is-sub td { color: var(--text-muted); font-size: 13px; }
.campaign-cell { padding-left: 12px; white-space: nowrap; }
.campaign-cell.ad-level-2 { padding-left: 28px; }
/* Aufklappbare Karte (Meta-Anzeigen): Kopf wie .stats-card-head, Pfeil wie .form-section */
.stats-collapsible > summary { list-style: none; cursor: pointer; border-radius: var(--radius); }
.stats-collapsible > summary::-webkit-details-marker { display: none; }
.stats-collapsible > summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; box-shadow: none; }
.stats-collapsible > summary svg { flex: none; color: var(--text-muted); transition: transform var(--dur-fast) var(--ease); }
.stats-collapsible:not([open]) > summary svg { transform: rotate(-90deg); }
.stats-collapsible:not([open]) { gap: 0; }
.stats-alert { margin: 0; }
.funnel-note { margin-top: -6px; }
.chart-box, .timeline-box { min-height: 120px; }
.hbars-empty { padding: 24px 0; text-align: center; font-size: 14px; }

/* Waagerechte Balken */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 12px; align-items: center; font-size: 13.5px; }
.hbar-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 8px; border-radius: 999px; background: var(--chart-track); overflow: hidden; }
.hbar-fill { display: block; height: 100%; border-radius: inherit; background: var(--kind, var(--brand-gradient)); box-shadow: 0 0 10px var(--kind, var(--glow-color)); }
.hbar-value { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; white-space: nowrap; }
.hbar-sub { margin-left: 6px; font-weight: 400; color: var(--text-muted); font-size: 12px; }
.reason-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 36px; }
.reason-group { display: grid; gap: 12px; align-content: start; }
.reason-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text); }

/* Dashboard */
.dash-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 20px 0; }
.view-wide > .stats-card + .stats-card, .view-wide > .kpi-row + .stats-card { margin-top: 20px; }
.week-nav { display: inline-flex; align-items: center; gap: 4px; padding: 2px; height: 36px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.week-nav .btn-icon.btn-sm { width: 30px; height: 30px; border-radius: 999px; }
.week-title { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 168px; text-align: center; }

/* ---------- Einstellungen (Vorlage „Branding“ und „Ziele“) ---------- */
.settings-layout { display: grid; grid-template-columns: 264px minmax(0, 1fr); gap: 24px; align-items: start; }
.settings-layout.is-single { grid-template-columns: minmax(0, 1fr); }
.set-nav { position: sticky; top: calc(var(--topbar-h) + 24px); padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.set-tab {
  position: relative; isolation: isolate;
  display: flex; align-items: center; gap: 12px; width: 100%; height: 44px; padding: 0 14px;
  border: 0; border-radius: 13px; background: transparent; cursor: pointer; text-align: left;
  color: var(--text-muted); font: inherit; font-size: 14px; font-weight: var(--weight-medium); white-space: nowrap;
  transition: color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease);
}
.set-tab svg { flex: none; }
.set-tab:hover { color: var(--text); background: var(--surface-hover); }
.set-tab:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; box-shadow: none; border-radius: 13px; }
.set-tab[aria-selected="true"] { color: var(--text); background: var(--pill-active-bg); box-shadow: var(--glow); }
.set-tab[aria-selected="true"] svg { stroke: url(#g-icon); }
.set-tab[aria-selected="true"]::before {
  content: ''; position: absolute; inset: 0; border-radius: inherit; padding: 1px; pointer-events: none;
  background: var(--brand-gradient);
  -webkit-mask: var(--mask-fill) content-box, var(--mask-fill);
  -webkit-mask-composite: xor;
  mask: var(--mask-fill) content-box exclude, var(--mask-fill);
}
.settings-panel { padding: 32px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; min-width: 0; }
.settings-panel:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.settings-panel .i-grad { stroke: url(#g-icon); }
.settings-section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; min-width: 0; }
.settings-section + .settings-section { margin-top: 36px; padding-top: 36px; border-top: 1px solid var(--hairline); }
.settings-section-head { display: grid; gap: 8px; margin-bottom: 8px; }
.set-intro { margin: 0; color: var(--text-muted); font-size: 15px; max-width: 640px; }
.settings-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.settings-section > .settings-actions:last-child { margin-top: 12px; }
.settings-actions .spacer { flex: 1; }
.inline-error { color: var(--danger); font-size: 14px; font-weight: var(--weight-medium); }
.inline-error:empty { display: none; }
.inline-ok { color: var(--success); font-size: 14px; font-weight: var(--weight-medium); }

/* Branding */
.set-name { max-width: 420px; }
.color-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.color-row { display: flex; gap: 10px; align-items: center; }
.color-row .input { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; text-transform: uppercase; }
.swatch {
  position: relative; flex: none; width: 44px; height: 44px; border-radius: 12px; overflow: hidden; cursor: pointer;
  background: var(--sw, var(--surface-2)); border: 1px solid var(--border-strong);
  box-shadow: 0 6px 18px -8px var(--sw, transparent);
}
.swatch:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; }
.brand-preview { margin-top: 8px; padding: 26px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface-inner); }
.bp-line { height: 3px; border-radius: 999px; background: var(--brand-gradient); box-shadow: 0 0 16px var(--glow-color-strong); margin-bottom: 26px; }
.bp-row { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.bp-row .btn, .bp-row .nav-pill { pointer-events: none; }
.bp-num { font-family: var(--font-display); font-weight: var(--weight-display); font-size: 42px; line-height: 1; letter-spacing: -0.02em; }
.logo-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.logo-preview {
  display: grid; place-items: center; flex: none; width: 76px; height: 76px; border-radius: 20px; overflow: hidden;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); font-size: 12px;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-preview .brand-mark-img { width: 48px; height: 48px; border-radius: 12px; }

/* Ziele */
.goals-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: start; }
.calc-hint {
  display: flex; align-items: center; gap: 14px; padding: 18px 22px; border-radius: 18px;
  border: 1px solid var(--border); background: var(--surface-inner); font-size: 15px;
}
.calc-hint svg { flex: none; }
.calc-hint strong { font-family: var(--font-display); font-weight: var(--weight-display); font-size: 26px; vertical-align: -2px; margin: 0 2px; }
.calc-hint.is-warn { color: var(--text); border-color: color-mix(in srgb, var(--warning) 45%, transparent); background: var(--warning-bg); }
.calc-hint.is-warn svg { color: var(--warning); }
.budget-table td { padding: 10px 12px; }
.budget-table th { padding: 0 12px 12px; }

/* Stufen */
.stage-list { display: grid; gap: 10px; }
.stage-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) 90px 140px auto; gap: 8px 10px; align-items: center;
  padding: 12px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface-inner);
}
.stage-row.is-core { background: var(--surface-2); }
.stage-move { display: flex; flex-direction: column; gap: 2px; grid-row: span 2; }
.stage-move .btn { height: 22px; width: 26px; padding: 0; }
.stage-follow { grid-column: 2 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; min-height: 36px; }
.stage-follow .check { font-size: 13px; color: var(--text-muted); white-space: nowrap; }
.stage-follow .input { height: 36px; font-size: 13px; width: auto; }
.stage-lock { display: inline-flex; align-items: center; gap: 4px; color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.stage-row .input { min-width: 0; }

/* Listen */
.chip-editor { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 4px 0 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; max-width: 100%;
}
.chip > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; color: var(--text-muted); }
.chip button:hover { background: var(--danger-bg); color: var(--danger); }
.chip-add { display: flex; gap: 8px; }
.chip-add .input { height: 36px; font-size: 13px; width: 220px; }
.list-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 36px; }
.list-grid .settings-section + .settings-section { margin-top: 0; padding-top: 0; border-top: 0; }
.list-grid + .settings-section { margin-top: 36px; padding-top: 36px; border-top: 1px solid var(--hairline); }

.edit-table td { vertical-align: middle; padding-top: 8px; padding-bottom: 8px; }
.edit-table .input { height: 40px; font-size: 14px; }
.edit-table input[type="color"] { width: 44px; height: 36px; padding: 2px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface-2); cursor: pointer; }

/* Arbeitszeit */
.days-row { display: flex; flex-wrap: wrap; gap: 8px; }
.day-check {
  position: relative; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border-strong); cursor: pointer; font-size: 14px; font-weight: var(--weight-medium);
}
.day-check:has(input:checked) { border-color: var(--brand-g2); background: var(--pill-active-bg); box-shadow: 0 0 0 1px var(--brand-g2), var(--glow); }
.time-row { display: flex; flex-wrap: wrap; gap: 16px; }
.time-row .input { width: 160px; }
.small-input { width: 140px; }

/* Daten */
.danger-zone { border: 1px solid var(--danger); border-radius: var(--radius); padding: 20px; display: grid; gap: 12px; background: var(--danger-bg); }
.danger-zone .alert-error { background: transparent; padding: 0; color: var(--text); }
.danger-zone .alert-error svg { color: var(--danger); }
.export-links { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- schmal ---------- */
@media (max-width: 1180px) {
  .goals-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 1023.98px) {
  .settings-layout { grid-template-columns: 220px minmax(0, 1fr); }
  .color-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .reason-grid, .dash-grid, .list-grid { grid-template-columns: 1fr; }
}
@media (max-width: 767.98px) {
  .stats-controls { gap: 10px; margin-bottom: 18px; }
  .stats-controls .period-seg { overflow-x: auto; scrollbar-width: none; width: 100%; }
  .stats-controls .period-seg::-webkit-scrollbar { display: none; }
  .seg-compact .seg-btn { flex: none; }
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .set-nav { position: relative; top: 0; flex-direction: row; overflow-x: auto; scrollbar-width: none; padding: 6px; }
  .set-nav::-webkit-scrollbar { display: none; }
  .set-tab { flex: none; width: auto; height: 40px; }
  .settings-panel { padding: 22px 18px; }
  .goals-grid { grid-template-columns: minmax(0, 1fr); }
  .bp-row { gap: 18px; }
  .settings-section > .settings-actions:last-child .btn { flex: 1 1 100%; }
  .settings-actions .spacer { display: none; }
  .budget-table { min-width: 520px; }
}
@media (max-width: 640px) {
  .stat-block { padding: 20px 16px 20px 20px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric { padding: 12px; }
  .metric-value { font-size: 22px; }
  .stats-card { padding: 20px 16px; }
  .stats-card .table-wrap { margin: 0 -16px; }
  .stats-card .table th:first-child, .stats-card .table td:first-child { padding-left: 16px; }
  .stats-card .table th:last-child, .stats-card .table td:last-child { padding-right: 16px; }
  .stage-row { grid-template-columns: auto minmax(0, 1fr) 72px auto; grid-auto-flow: row dense; }
  .stage-row > .stage-type, .stage-row > .stage-label { grid-column: 2 / -1; }
  .stage-row > .stage-prob { max-width: 110px; }
  .stage-move { grid-row: span 3; }
  .stage-move .btn { height: 34px; width: 34px; }
  .hbar { grid-template-columns: minmax(70px, 38%) 1fr auto; }
  .week-title { min-width: 0; }
  .chip-add .input { width: 160px; }
  .calc-hint { padding: 16px; font-size: 14px; }
}
