/* Analytics-Seite (analytics.html). Nutzt die Design-Tokens aus styles.css.
   Diagramm-Farben: validierte Standard-Palette (Blau = Hauptreihe, Orange = zweite Reihe),
   Status-Farben bleiben für Rechnungsstatus reserviert. */

.an {
  --an-c1: #2a78d6;
  --an-c2: #eb6834;
  --an-c1-wash: rgba(42, 120, 214, 0.1);
  --an-c2-wash: rgba(235, 104, 52, 0.1);
  --an-grid: #cfd9e4;
  --an-track: #e3ebf3;

  --an-s-offen: #c98500;
  --an-s-zur_pruefung: #2a78d6;
  --an-s-bezahlt: #0f8a4b;
  --an-s-im_einspruch: #d03a30;
  --an-s-storniert: #75889d;
  --an-s-unbekannt: #aebccb;
}

.an-caption { margin: -12px 0 16px; }

.an-custom {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: -12px 0 16px;
}
.an-field { display: flex; flex-direction: column; gap: 4px; }
.an-field .input { width: 170px; }

.an-note {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.an-note-error { border-left-color: var(--status-einspruch); color: var(--status-einspruch); }

#analytics-body { transition: opacity 0.15s ease; }
#analytics-body.is-loading { opacity: 0.55; }

/* ---------- Kennzahlen ---------- */
.an-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.an-kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 16px 18px;
  min-width: 0;
}
.an-kpi-label { margin: 0; font-size: 12px; color: var(--text-muted); font-weight: 500; }
.an-kpi-value {
  margin: 6px 0 4px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.an-kpi-sub { margin: 0; font-size: 12px; color: var(--text-muted); }

/* ---------- Karten ---------- */
.an-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 20px;
  margin-bottom: 20px;
  min-width: 0;
}
.an-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}
.an-grid-2 > .an-card { margin-bottom: 20px; }
.an-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.an-card-title { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-primary); }
.an-card-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-muted); }
.an-head-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.an-search { width: 220px; }

.an-empty { margin: 8px 0; font-size: 13px; color: var(--text-muted); }

/* ---------- Segment-Schalter ---------- */
.an-seg {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}
.an-seg-btn {
  border: none;
  background: transparent;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.an-seg-btn:hover { color: var(--text-primary); background: var(--surface-raised); }
.an-seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* ---------- Legende ---------- */
.an-legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); }
.an-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.an-key { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.an-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex-shrink: 0; }

/* ---------- Liniendiagramm ---------- */
.an-line { position: relative; width: 100%; }
.an-line svg { display: block; width: 100%; height: auto; overflow: visible; }
.an-axis-text { font-size: 11px; fill: var(--text-muted); font-family: inherit; }
.an-gridline { stroke: var(--an-grid); stroke-width: 1; }
.an-crosshair { stroke: var(--border-strong); stroke-width: 1; }

/* ---------- Balkenlisten ---------- */
.an-bars { display: flex; flex-direction: column; gap: 4px; }
.an-bar-row {
  display: grid;
  grid-template-columns: minmax(90px, 36%) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  outline: none;
}
.an-bar-row:hover, .an-bar-row:focus-visible { background: var(--surface-raised); }
.an-bar-row:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.an-bar-label { min-width: 0; }
.an-bar-name {
  display: block;
  font-size: 13px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.an-bar-sub {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.an-bar-track { height: 14px; display: flex; align-items: center; }
.an-bar-fill {
  height: 14px;
  min-width: 3px;
  background: var(--an-c1);
  border-radius: 0 4px 4px 0;
  transition: filter 0.15s ease;
}
.an-bar-row:hover .an-bar-fill, .an-bar-row:focus-visible .an-bar-fill { filter: brightness(1.12); }
.an-bar-fill.is-warn { background: var(--an-c2); }
.an-bar-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
  min-width: 70px;
}

/* ---------- Donut ---------- */
.an-donut-wrap { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.an-donut { position: relative; width: 168px; height: 168px; flex-shrink: 0; }
.an-donut svg { width: 100%; height: 100%; display: block; }
.an-donut-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.an-donut-total { font-size: 24px; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.an-donut-cap { font-size: 11px; color: var(--text-muted); }
.an-donut-seg { transition: stroke-width 0.15s ease; cursor: default; }
.an-donut-seg:hover { stroke-width: 26; }
.an-status-list { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 220px; }
.an-status-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 7px 6px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}
.an-status-row:hover, .an-status-row:focus-visible { background: var(--surface-raised); }
.an-status-row .n { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.an-status-row .v { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 84px; text-align: right; }

/* ---------- Wochentage ---------- */
.an-cols { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; align-items: end; height: 190px; }
.an-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; outline: none; border-radius: var(--radius-sm); }
.an-col:hover, .an-col:focus-visible { background: var(--surface-raised); }
.an-col:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.an-col-val { font-size: 12px; font-weight: 600; color: var(--text-primary); min-height: 16px; font-variant-numeric: tabular-nums; }
.an-col-bar { width: min(100%, 24px); background: var(--an-c1); border-radius: 4px 4px 0 0; min-height: 2px; }
.an-col-label { font-size: 12px; color: var(--text-muted); padding-bottom: 4px; }
.an-col-baseline { height: 1px; background: var(--an-grid); margin-top: -1px; }

/* ---------- Tabellen ---------- */
.an-table-wrap { box-shadow: none; }
.an-table-wrap th[data-sort] { cursor: pointer; user-select: none; white-space: nowrap; }
.an-table-wrap th[data-sort]:hover { color: var(--text-primary); }
.an-table-wrap th.sorted::after { content: " ↓"; }
.an-table-wrap th.sorted.asc::after { content: " ↑"; }
.an-num { text-align: right; }
td.an-num { font-variant-numeric: tabular-nums; }
.an-more { display: flex; justify-content: center; margin-top: 14px; }
.an-tl-table { max-height: 320px; overflow: auto; }

/* ---------- Tooltip ---------- */
.an-tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop);
  padding: 9px 12px;
  font-size: 12px;
  max-width: 280px;
}
.an-tip[hidden] { display: none; }
.an-tip-title { font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; }
.an-tip-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.an-tip-row .l { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); }
.an-tip-row .v { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-primary); }

@media (max-width: 860px) {
  .an-grid-2 { grid-template-columns: 1fr; gap: 0; }
  .an-search { width: 100%; }
  .an-bar-row { grid-template-columns: minmax(80px, 38%) 1fr auto; gap: 8px; }
}
@media (max-width: 520px) {
  .container-wide.an { padding: 24px 16px 32px; }
  .an-kpi-value { font-size: 20px; }
  .an-donut-wrap { justify-content: center; }
}
