*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Kopfzeile */
.topbar { background: var(--bg-deep); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { font-size: 1.2rem; font-weight: 700; color: var(--text); letter-spacing: 0.01em; }
.brand:hover { text-decoration: none; }
.brand-games { color: var(--accent); }
.topbar-label { color: var(--text-muted); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; justify-content: flex-end; }
.logout { display: flex; align-items: center; gap: 12px; margin: 0; }
.who { color: var(--text-muted); font-size: 0.95rem; }
.btn-small { padding: 6px 16px; font-size: 0.9rem; }

/* Meldungen */
.flash {
  width: 100%;
  max-width: 720px;
  padding: 12px 16px;
  border: 1px solid var(--accent-2);
  border-radius: var(--radius-field);
  background: rgba(16, 185, 129, 0.08);
}
.form-error {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius-field);
  background: rgba(248, 113, 113, 0.08);
  color: var(--text);
}
.hint {
  margin: 20px 0 0;
  padding: 12px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-field);
  color: var(--text-muted);
  font-size: 0.95rem;
}
.hint code { display: block; margin-top: 8px; color: var(--text); word-break: break-all; }
.check { flex-direction: row !important; align-items: center; gap: 10px !important; font-weight: 400 !important; }
.check input { width: 18px; height: 18px; }

/* Übersicht */
.card-wide { max-width: 720px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-top: 16px; }
.stat { background: var(--surface-raised); border: 1px solid var(--border); border-radius: var(--radius-field); padding: 16px; }
.stat-value { font-size: 1.8rem; font-weight: 800; }
.stat-label { color: var(--text-muted); font-size: 0.9rem; }

/* Inhalt */
.main {
  flex: 1;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 56px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 32px;
}
.card h1 { margin: 0 0 8px; font-size: 1.75rem; line-height: 1.25; }
.card-login, .card-error { max-width: 440px; }

.muted { color: var(--text-muted); margin: 0 0 24px; }
.notice {
  margin: 20px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-field);
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* Formulare */
.form { display: flex; flex-direction: column; gap: 16px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.95rem; }
.form input {
  font: inherit;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-field);
  padding: 11px 14px;
}
.form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.form input:disabled { opacity: 0.6; cursor: not-allowed; }

/* Knöpfe */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 700;
  padding: 12px 26px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--accent-gradient); color: #ffffff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-outline:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }

/* Fehlerseiten */
.error-code {
  margin: 0 0 4px;
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* Fußzeile */
.footer { background: var(--bg-deep); border-top: 1px solid var(--border); color: var(--text-muted); font-size: 0.9rem; }
.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 18px 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
}
.footer-links { display: flex; gap: 18px; }
.footer-links a { color: var(--text-muted); }
.footer-links a:hover { color: var(--text); }

@media (max-width: 520px) {
  .main { padding: 32px 16px; }
  .card { padding: 24px 20px; }
}

/* Breite Karten, Überschriften mit Aktion */
.card-full { max-width: 1100px; }
.card h2 { margin: 0 0 12px; font-size: 1.25rem; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.card-head h1, .card-head h2 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 20px; align-items: center; }
.actions form { margin: 0; }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }

/* Tabellen */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th { text-align: left; color: var(--text-muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border-strong); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: var(--surface-raised); }
.table code { font-size: 0.85rem; color: var(--text); }

/* Status-Abzeichen */
.badge { display: inline-block; padding: 2px 10px; border-radius: var(--radius-pill); font-size: 0.8rem; font-weight: 700; border: 1px solid var(--border-strong); color: var(--text-muted); }
.badge-large { font-size: 0.95rem; padding: 4px 14px; }
.badge-active, .badge-success { color: var(--accent); border-color: var(--accent-2); }
.badge-invited { color: #93c5fd; border-color: #3b82f6; }
.badge-disabled, .badge-failure, .badge-denied { color: var(--danger); border-color: var(--danger); }

/* Filter und Formulare in einer Zeile */
.filter { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin: 0 0 20px; }
.filter label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--text-muted); }
.filter input, .filter select, .inline-form input, .form textarea, .copy {
  font: inherit; color: var(--text); background: var(--surface-raised);
  border: 1px solid var(--border-strong); border-radius: var(--radius-field); padding: 8px 12px;
}
.filter input[type="search"] { min-width: 280px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.inline-form input { flex: 1; min-width: 220px; }
.form textarea { resize: vertical; }
.label-block { display: flex; flex-direction: column; gap: 6px; font-weight: 600; margin-top: 16px; }
.copy { width: 100%; font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.9rem; resize: vertical; }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.1); }

/* Fakten (Beschriftung: Wert) */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 24px; margin: 0; }
.facts dt { color: var(--text-muted); }
.facts dd { margin: 0; }

/* Seitenblättern */
.pager { display: flex; gap: 16px; align-items: center; justify-content: center; margin-top: 20px; }

@media (max-width: 600px) {
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  .filter input[type="search"] { min-width: 0; width: 100%; }
}
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions form { margin: 0; }
a.who { color: var(--text-muted); }
a.who:hover { color: var(--text); }

/* Nodes (P2-3): Warn-Abzeichen, RAM-Balken, Checklisten, Kachel als Link */
.badge-warn { color: #fbbf24; border-color: #d97706; }
meter.ram { width: 120px; height: 10px; vertical-align: middle; }
.checklist { list-style: none; padding: 0; margin: 0 0 16px; }
.checklist li { padding: 4px 0; }
.checklist .ok::before { content: "✓ "; color: var(--accent); font-weight: 700; }
.checklist .bad::before { content: "✗ "; color: var(--danger); font-weight: 700; }
.checklist .todo::before { content: "• "; color: var(--text-muted); }
a.stat-link { color: var(--text); display: block; }
a.stat-link:hover { text-decoration: none; border-color: var(--accent); }
.warnings { display: flex; flex-wrap: wrap; gap: 6px; }
.form select { font: inherit; color: var(--text); background: var(--surface-raised); border: 1px solid var(--border-strong); border-radius: var(--radius-field); padding: 11px 14px; }
.form-row { display: flex; flex-wrap: wrap; gap: 16px; }
.form-row > label { flex: 1; min-width: 200px; }

/* Live-Konsole (P2-6): Ausgabe in Festbreitenschrift mit eigener Scrollfläche, Farben nur
   über Klassen (style-src 'self', kein Inline-Stil). */
.head-side { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.console-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: flex-end; margin: 0 0 8px; }
.console-filter { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--text-muted); }
.console-filter input, .console-input input {
  font: inherit; color: var(--text); background: var(--surface-raised);
  border: 1px solid var(--border-strong); border-radius: var(--radius-field); padding: 8px 12px;
}
.console-lines {
  list-style: none; margin: 0; padding: 10px 12px; height: 60vh; overflow-y: auto;
  background: var(--bg-deep); border: 1px solid var(--border); border-radius: var(--radius-field);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 0.85rem; line-height: 1.45;
}
.console-lines li { unicode-bidi: isolate; white-space: pre-wrap; overflow-wrap: anywhere; }
.console-ts { color: var(--text-muted); }
.k-warn { color: #fbbf24; }
.k-err { color: var(--danger); }
.k-in { font-weight: 700; }
.k-res { padding-left: 2ch; }
.k-sys { color: var(--text-muted); font-style: italic; }
.console-ops { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; margin: 0 0 14px; }
.console-ops p { margin: 0; }
.console-ops .actions { margin-top: 0; }
.console-form { margin-top: 12px; }
.console-input { display: flex; flex-direction: column; gap: 6px; font-weight: 600; }
.console-input input { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; width: 100%; }
.console-form .actions { margin-top: 10px; }
.console-msg { min-height: 1.4em; margin: 8px 0 0; color: var(--danger); }

/* RAM-Diagramm (v0.1.25): SVG aus Go, Farben nur über Klassen (style-src 'self'). */
.chart { display: block; width: 100%; height: auto; max-width: 720px; margin: 8px 0; }
.chart-avg { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart-max { fill: none; stroke: var(--accent-2); stroke-width: 1; opacity: .6; }
.chart-limit { stroke: var(--danger); stroke-dasharray: 6 4; }
.chart-top { stroke: var(--text-muted); stroke-dasharray: 2 4; }
.chart-grid { stroke: var(--border); }
.chart-label { fill: var(--text-muted); font-size: 14px; }
.chart-now { font-weight: 600; margin: 4px 0 8px; }
.chart-ranges { display: flex; flex-wrap: wrap; gap: 12px; margin: 0 0 12px; }
.chart-ranges a[aria-current="page"] { font-weight: 700; text-decoration: underline; }
.chart-table summary { cursor: pointer; color: var(--text-muted); }
.ram-bars { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; align-items: center; margin: 12px 0; }

/* Gruppen und Dateiauswahl in Formularen (v0.3.0) */
.form fieldset.choice { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px 24px; }
.form fieldset.choice legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 6px; width: 100%; }
.form input[type="file"] { padding: 8px; }

/* Rechtstexte (v0.3.0): gut lesbarer Fließtext */
.legal-text { max-width: 78ch; line-height: 1.6; }
.legal-text h2 { font-size: 1.2rem; margin: 28px 0 8px; }
.legal-text h3 { font-size: 1.05rem; margin: 20px 0 6px; }
.legal-text p { margin: 0 0 12px; overflow-wrap: anywhere; }

/* Rechnungen (v0.3.2): Ansicht aus der Momentaufnahme. */
.num { text-align: right; white-space: nowrap; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 32px; margin-bottom: 12px; }
.invoice-view .table { margin: 12px 0; }
@media (max-width: 640px) {
  .invoice-parties { grid-template-columns: 1fr; }
}
