/* bots-dashboard - ohne Framework. Farbrollen nach der dataviz-Referenzpalette, hell und dunkel
   jeweils als eigene, validierte Stufen (kein automatisches Invertieren). Die Linienfarbe je Bot
   kommt aus config.yaml (overview.bots[].color) und wird per Inline-Style auf --bot-color gesetzt;
   Text traegt nie die Reihenfarbe, nur der Swatch daneben. */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface-1: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --wash: rgba(11, 11, 11, 0.04);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;
  --inactive: #898781;
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;
  --status-neutral: #898781;
  --delta-up: #006300;
  --delta-down: #d03b3b;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface-1: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --wash: rgba(255, 255, 255, 0.05);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --delta-up: #0ca30c;
    --delta-down: #e66767;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  background: var(--page);
  color: var(--text-primary);
}

h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: 1rem; }

a { color: inherit; }
a:focus-visible, button:focus-visible, summary:focus-visible { outline: 2px solid var(--series-1); outline-offset: 1px; }

/* --- Kopf --------------------------------------------------------------- */

.kopf {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 8px;
}

.kopf-zeile { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.kopf-zeile .badge { margin-left: auto; }

.kopf-meta { margin: 6px 0 0; color: var(--text-secondary); font-size: 0.85rem; }

.zurueck { font-size: 0.85rem; color: var(--text-secondary); text-decoration: none; }
.zurueck:hover { text-decoration: underline; }

.hinweis {
  margin: 8px 0 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--status-warning);
  border-radius: 6px;
  background: var(--surface-1);
  font-size: 0.9rem;
}
.hinweis-fehler { border-left-color: var(--status-critical); }

/* --- Status-Badge (Icon + Text, nie Farbe allein) ---------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-1);
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  --status-color: var(--status-neutral);
}
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--status-color); flex: none; }
.badge-running { --status-color: var(--status-good); }
.badge-paused { --status-color: var(--status-warning); }
.badge-problem { --status-color: var(--status-critical); }
.badge-inactive, .badge-unknown { --status-color: var(--status-neutral); }
.badge-inactive .badge-dot, .badge-unknown .badge-dot { background: transparent; border: 2px solid var(--status-color); width: 8px; height: 8px; }

.status-grund {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  overflow-wrap: anywhere;
}
.status-grund:empty { display: none; }

/* --- Kacheln (Stat-Tiles) ---------------------------------------------- */

.kacheln {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.kachel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 0;
}
.kachel-label { font-size: 0.8rem; color: var(--text-secondary); }
.kachel-wert { font-size: 1.5rem; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.kachel-hero .kachel-wert { font-size: 2rem; }
.kachel-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.delta.up { color: var(--delta-up); }
.delta.down { color: var(--delta-down); }

/* --- Karten und Layout ---------------------------------------------------- */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  display: grid;
  gap: 16px;
}

.karte {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px 16px;
  min-width: 0;
}

.karte-kopf {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 10px;
}
.karte-meta { font-size: 0.8rem; color: var(--text-muted); }

/* Feste Hoehe schliesst die Achsenbeschriftung ein - Chart.js zeichnet sie in die Canvas. */
.chart-box { position: relative; height: 240px; width: 100%; }
.chart-hoch { height: 320px; }
.chart-box canvas { transition: opacity 0.2s; }
body.laden .chart-box canvas { opacity: 0.6; }

.leer { margin: 8px 0 0; color: var(--text-muted); font-size: 0.9rem; }

/* HTML-Tooltip des Charts (app.js): Wert fett, Name sekundaer, Reihe als Linienschluessel - nie Text in Reihenfarbe. */
.tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  padding: 6px 10px;
  border: 1px solid var(--axis);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 0.8rem;
  line-height: 1.4;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  max-width: 260px;
}
.tooltip-titel { font-weight: 600; color: var(--text-secondary); margin-bottom: 2px; }
.tooltip-zeile { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.tooltip-zeile strong { font-variant-numeric: tabular-nums; }
.tooltip-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip-name { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; }

/* --- Filterzeile (Zeitraum + Modus): eine Zeile ueber dem Chart ------------------ */

.filterzeile { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 8px; }
.filter { display: flex; flex-wrap: wrap; gap: 6px; }
.filter button {
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.filter button:hover { background: var(--wash); }
.filter button.aktiv { color: var(--text-primary); font-weight: 700; border-color: var(--text-secondary); }
.filter button.aktiv::before { content: "\2713\00a0"; }

/* --- Legende: HTML statt Canvas, klickbar (ein-/ausblenden je Bot) --------------- */

.legende { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0 0 8px; padding: 0; font-size: 0.85rem; color: var(--text-secondary); }
.legende li { display: inline-flex; }
.legende-bot {
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
}
.legende-bot:hover { background: var(--wash); }
.legende-bot[aria-pressed="false"] { color: var(--text-muted); text-decoration: line-through; }
.legende-bot[aria-pressed="false"] .swatch { opacity: 0.35; }
.legende-bot:disabled { cursor: default; color: var(--text-muted); text-decoration: none; }
.legende-bot:disabled .legende-text::after { content: " – keine Kurve"; font-size: 0.8em; }

.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; background: var(--bot-color, var(--text-muted)); flex: none; }
.swatch-linie { width: 14px; height: 2px; border-radius: 1px; }
.swatch-punkt { width: 10px; height: 10px; border-radius: 50%; }
.legende .swatch { margin-right: 0; }

/* --- Bot-Karten ------------------------------------------------------------ */

.bots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
}

.bot-karte {
  border-left: 4px solid var(--bot-color, var(--inactive));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.bot-karte.bot-inaktiv { border-left-color: var(--inactive); color: var(--text-secondary); }
.bot-karte.bot-inaktiv .kachel-wert, .bot-karte.bot-fehler .kachel-wert { color: var(--text-muted); }

.bot-kopf { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.bot-kopf h2, .bot-kopf h3 { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.bot-kopf .badge { margin-left: auto; }

.bot-beschreibung { margin: 0; font-size: 0.9rem; color: var(--text-secondary); }

.tags { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0; padding: 0; }
.tag {
  display: inline-block;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.kennzahlen {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px 12px;
  margin: 4px 0 0;
}
.kennzahlen div { min-width: 0; }
.kennzahlen dt { font-size: 0.75rem; color: var(--text-muted); }
.kennzahlen dd { margin: 0; font-weight: 600; font-size: 0.95rem; overflow-wrap: anywhere; }

.bot-links { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: auto; padding-top: 6px; font-size: 0.85rem; }
.bot-links a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
}
.bot-links a:hover { background: var(--wash); }
.bot-links a.extern { color: var(--text-secondary); font-weight: 400; }

/* --- Tabellen ------------------------------------------------------------ */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--grid); white-space: nowrap; vertical-align: top; }
th { font-weight: 600; color: var(--text-secondary); font-size: 0.8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.text-lang { white-space: normal; min-width: 200px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--wash); }
td.leer-zeile { color: var(--text-muted); text-align: center; }
td.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82rem; }
.sekundaer { color: var(--text-muted); font-size: 0.8rem; }

.tabelle-details { margin-top: 10px; }
.tabelle-details summary { cursor: pointer; font-size: 0.85rem; color: var(--text-secondary); }
.tabelle-details .table-wrap { margin-top: 8px; }

/* Schluessel-Wert-Listen (Kontodaten, Health-Details) */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 16px; margin: 0; font-size: 0.9rem; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 700px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

.fuss {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- Mobil ab 360 px ------------------------------------------------------ */

@media (max-width: 480px) {
  body { font-size: 14px; }
  .kopf { padding: 12px 10px 6px; }
  main { padding: 6px 10px 20px; gap: 12px; }
  .karte { padding: 12px 10px; }
  .kacheln { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
  .kachel-wert { font-size: 1.25rem; }
  .kachel-hero .kachel-wert { font-size: 1.6rem; }
  .chart-box { height: 200px; }
  .chart-hoch { height: 260px; }
  .bots { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .kv { gap: 4px 10px; }
  th, td { padding: 5px 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .chart-box canvas { transition: none; }
}
