/* ================================================================
   actualskit Design-System · Komponenten
   Bausteine für Dashboard und Landingpage. Braucht tokens.css + base.css.
   Übersicht mit Beispielen: design/README.md
   ================================================================ */

/* ================================================================ Layout-Helfer */

.container { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 0 var(--gutter); }
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.row { display: flex; gap: var(--sp-2) var(--sp-3); align-items: center; flex-wrap: wrap; }
.row + .row { margin-top: var(--sp-3); }
.row > .grow { flex: 1 1 200px; min-width: 0; }
.row > .end { align-self: flex-end; }
.spacer { flex: 1; }
.grid { display: grid; gap: var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); margin-bottom: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.divider { height: 1px; background: var(--border); border: 0; margin: var(--sp-4) 0; }
.mt-2 { margin-top: var(--sp-2); }
.mt-3 { margin-top: var(--sp-3); }
.mt-4 { margin-top: var(--sp-4); }
.mb-0 { margin-bottom: 0 !important; }

/* ================================================================ Buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 var(--sp-3); flex-shrink: 0;
  border: 1px solid var(--border-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); line-height: 1; white-space: nowrap;
  text-decoration: none; cursor: pointer; user-select: none;
  box-shadow: inset 0 1px 0 var(--highlight);
  transition: background var(--dur-1), border-color var(--dur-1), color var(--dur-1), transform var(--dur-1), box-shadow var(--dur-2);
}
.btn .ti { font-size: 15px; }
.btn:hover { background: var(--surface-3); color: var(--text); }
.btn:active { transform: scale(.98); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--border-focus); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: default; transform: none; pointer-events: none; }

.btn-primary { background: var(--accent-strong); border-color: transparent; color: var(--on-accent); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), var(--shadow-sm); }
.btn-primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-soft); border-color: rgba(235, 87, 87, .35); color: var(--red); }
.btn-small { height: var(--control-h-sm); padding: 0 var(--sp-2); font-size: var(--fs-xs); border-radius: var(--r-sm); }
.btn-big, .btn-lg { height: var(--control-h-lg); padding: 0 var(--sp-5); font-size: var(--fs-base); }
.btn-block { width: 100%; }

/* Runder Icon-Knopf (Abmelden, Menü, Schließen) */
.icon-btn {
  display: inline-grid; place-items: center; width: var(--control-h); height: var(--control-h); flex-shrink: 0;
  border: 1px solid transparent; border-radius: var(--r); background: transparent; color: var(--muted); font-size: 16px;
  transition: background var(--dur-1), color var(--dur-1), transform var(--dur-1);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { transform: scale(.94); }

/* ================================================================ Karten */

.card {
  position: relative; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-5); margin-bottom: var(--sp-4);
  box-shadow: inset 0 1px 0 var(--highlight);
  transition: border-color var(--dur-2);
}
.grid > .card { margin-bottom: 0; }
.card > :last-child { margin-bottom: 0; }
.card-hover:hover, a.card:hover { border-color: var(--border-strong); }
.card h2 {
  display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-4);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); color: var(--text); letter-spacing: 0;
}
.card h2 .ti { color: var(--faint); font-size: 16px; }
.card p { margin: 0 0 var(--sp-2); }
.card-flush { padding: 0; overflow: hidden; }
/* Gefahrenbereich (unwiderrufliche Aktionen) */
.card-danger { border-color: rgba(235, 87, 87, .28); background: linear-gradient(180deg, rgba(235, 87, 87, .045), transparent 60%), var(--surface); }
.card-danger h2 .ti { color: var(--red); }
/* Kartenkopf: Titel links, Status/Aktion rechts */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-4); }
.card-head h2 { margin: 0; }
/* Fußzeile mit Link/Aktion, durch eine Linie abgesetzt */
.card-foot { margin: var(--sp-4) calc(var(--sp-5) * -1) calc(var(--sp-5) * -1); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.card-foot a { color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.card-foot a:hover { color: var(--text); }

/* Kennzahl-Kacheln: Reihe kleiner Karten mit Wert */
.stats { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); margin-bottom: var(--sp-4); }
.stat {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5); box-shadow: inset 0 1px 0 var(--highlight);
}
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); min-height: 22px; }
.stat-top .ti { color: var(--faint); font-size: 16px; }
.stat .stat-value { font-size: var(--fs-2xl); margin-top: var(--sp-1); }
.stat .stat-sub { font-size: var(--fs-xs); color: var(--faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat .bar { margin: var(--sp-2) 0 0; }
/* genau 4 Kacheln: 4 → 2 → 1 Spalte je nach Breite des umgebenden Bereichs (container-type: inline-size) */
.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@container (max-width: 760px) { .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (max-width: 360px) { .stats-4 { grid-template-columns: 1fr; } }

/* Abschnittsüberschrift zwischen Karten */
h2.section { font-size: var(--fs-md); font-weight: var(--fw-semibold); margin: var(--sp-8) 0 var(--sp-3); }

/* ================================================================ Formulare */

label.field { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--muted); min-width: 0; }
label.field > input, label.field > select, label.field > textarea { width: 100%; }
/* Zahl + Einheit nebeneinander */
.input-group { display: flex; gap: 6px; }
.input-group > input[type=number] { width: 84px; }
.input-group > select { flex: 1; min-width: 0; }
.form-grid > label.check { min-height: var(--control-h); }
.form-grid > .btn { justify-self: start; }
.field-label { font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--muted); margin-bottom: 6px; }
/* Raster für Formularfelder (Filter usw.): so viele Spalten wie passen */
.form-grid { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); align-items: end; }
.form-grid .span-2 { grid-column: span 2; }
@container (max-width: 420px) { .form-grid .span-2 { grid-column: auto; } }
.field-hint { font-size: var(--fs-xs); color: var(--faint); font-weight: var(--fw-regular); }

input, select, textarea {
  min-width: 0; height: var(--control-h); padding: 0 10px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-1), box-shadow var(--dur-2), background var(--dur-1);
}
textarea { height: auto; padding: 8px 10px; line-height: var(--lh); }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: rgba(255, 255, 255, .2); }
input:focus, select:focus, textarea:focus, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--border-focus); box-shadow: var(--ring);
}
input:disabled, select:disabled, textarea:disabled { opacity: .5; cursor: not-allowed; }
input[type=number] { width: 110px; font-family: var(--font-mono); }
input[type=date], input[type=time] { font-family: var(--font-mono); color-scheme: dark; }
select {
  appearance: none; -webkit-appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a8f98' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
select option, select optgroup { background: var(--surface-2); color: var(--text); }

/* Checkbox im eigenen Stil */
input[type=checkbox] {
  appearance: none; -webkit-appearance: none; flex-shrink: 0;
  width: 16px; height: 16px; padding: 0; margin: 0; border-radius: var(--r-xs);
  background: var(--surface-2); border: 1px solid var(--border-strong); cursor: pointer;
  display: inline-grid; place-items: center;
}
input[type=checkbox]::after {
  content: ""; width: 9px; height: 5px; margin-top: -2px;
  border: 2px solid var(--on-accent); border-top: 0; border-right: 0; transform: rotate(-45deg) scale(0);
  transition: transform var(--dur-2) var(--ease);
}
input[type=checkbox]:checked { background: var(--accent-strong); border-color: var(--accent-strong); }
input[type=checkbox]:checked::after { transform: rotate(-45deg) scale(1); }
label.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; font-size: var(--fs-sm); }

/* ================================================================ Badges, Chips, Status-Punkt */

.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: var(--r-full); border: 1px solid var(--border-strong); background: transparent;
  font-size: var(--fs-xs); font-weight: var(--fw-medium); color: var(--muted); white-space: nowrap; line-height: 1;
}
.badge .ti { font-size: 13px; }
.badge-green { color: var(--green); background: var(--green-soft); border-color: transparent; }
.badge-red { color: var(--red); background: var(--red-soft); border-color: transparent; }
.badge-orange { color: var(--orange); background: var(--orange-soft); border-color: transparent; }
.badge-accent { color: var(--accent); background: var(--accent-soft); border-color: transparent; }

/* pulsierender Punkt für „online“ */
.pulse { position: relative; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.pulse::after { content: ""; position: absolute; inset: 0; border-radius: 50%; background: currentColor; animation: ds-ping 2s var(--ease) infinite; }
/* ruhiger Punkt für andere Zustände */
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--sp-2) 0; }
.chip {
  display: inline-flex; align-items: center; gap: 2px; height: 26px; padding: 0 4px 0 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-full);
  font-size: var(--fs-sm); animation: ds-pop var(--dur-2) var(--ease) both;
}
.chip a { color: var(--text); }
.chip button {
  display: grid; place-items: center; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%;
  background: none; color: var(--faint); font-size: 14px; line-height: 1; transition: color var(--dur-1), background var(--dur-1);
}
.chip button:hover { color: var(--red); background: var(--red-soft); }
.chip-static { padding: 0 10px; }

/* Erwähnung (@Name, #kanal) */
.mention { background: var(--accent-soft); color: var(--accent); border-radius: var(--r-xs); padding: 0 4px; }
a.mention:hover { background: var(--accent-strong); color: var(--on-accent); }

/* ================================================================ Tabellen */

.table-wrap { overflow-x: auto; margin: 0 calc(var(--sp-5) * -1); padding: 0 var(--sp-5); }
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--faint); font-weight: var(--fw-medium); font-size: var(--fs-xs); white-space: nowrap; }
th:first-child, td:first-child { padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
tbody tr { transition: background var(--dur-1); }
tbody tr:hover { background: rgba(255, 255, 255, .018); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ================================================================ Hinweiskasten */

.callout {
  display: flex; gap: var(--sp-3); align-items: flex-start; margin-bottom: var(--sp-4);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--r-lg); font-size: var(--fs-sm);
  background: var(--accent-soft); border: 1px solid rgba(113, 112, 255, .3); color: var(--text);
}
.callout > .ti { font-size: 18px; color: var(--accent); margin-top: 1px; flex-shrink: 0; }
.callout p { margin: 2px 0 0; color: var(--muted); }
.callout-warn { background: var(--orange-soft); border-color: rgba(242, 153, 74, .3); }
.callout-warn > .ti { color: var(--orange); }
.callout-danger { background: var(--red-soft); border-color: rgba(235, 87, 87, .3); }
.callout-danger > .ti { color: var(--red); }

/* ================================================================ Listen (Zeilen mit Trennlinien, z. B. in .card-flush) */

.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; min-width: 0;
  padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--border); transition: background var(--dur-1);
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: rgba(255, 255, 255, .015); }
.list-title { font-weight: var(--fw-medium); min-width: 0; }
.list-sub { font-size: var(--fs-xs); color: var(--faint); }
.list-row > .grow { flex: 1 1 180px; min-width: 0; }
.list-row > .full { flex-basis: 100%; }
.list-head { padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.list-head h2 { margin: 0; }
.list-head p { margin: 4px 0 0; }
.list .empty { padding: var(--sp-8) var(--sp-5); }
/* Formular unter einer Liste („hinzufügen“) */
.list-form { padding: var(--sp-4) var(--sp-5) var(--sp-5); border-top: 1px solid var(--border); background: rgba(255, 255, 255, .012); }
.form-title { font-size: var(--fs-sm); font-weight: var(--fw-semibold); margin-bottom: var(--sp-3); }

/* ================================================================ Speichern-Leiste (läuft am unteren Rand mit) */

.savebar {
  position: sticky; bottom: var(--sp-4); z-index: var(--z-sticky);
  display: flex; align-items: center; justify-content: flex-end; gap: var(--sp-3);
  margin-top: var(--sp-4); pointer-events: none;
}
.savebar > * { pointer-events: auto; }
.savebar .btn-primary { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .14), var(--shadow-lg); }

/* ================================================================ Schlüssel/Wert-Liste */

.kv { display: grid; grid-template-columns: minmax(110px, auto) 1fr; gap: 9px var(--sp-4); margin: 0; font-size: var(--fs-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ================================================================ Kennzahlen & Balken */

.stat-value { font-size: var(--fs-3xl); font-weight: var(--fw-semibold); letter-spacing: var(--tracking-display); font-variant-numeric: tabular-nums; line-height: 1.1; margin: 2px 0 0; }
.stat-label { font-size: var(--fs-xs); color: var(--muted); }

.meter-label { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: var(--fs-sm); }
.meter-label span:last-child { font-family: var(--font-mono); color: var(--muted); font-size: var(--fs-xs); }
.bar { height: 4px; background: var(--track); border-radius: var(--r-full); overflow: hidden; margin: 8px 0 14px; }
.bar:last-child { margin-bottom: 0; }
.bar > div { height: 100%; border-radius: inherit; background: var(--accent); transition: width var(--dur-4) var(--ease); animation: ds-grow var(--dur-4) var(--ease) both; }
.bar > div.warn { background: var(--orange); }
.bar > div.crit { background: var(--red); }

/* ================================================================ Ausklappen */

details > summary {
  display: inline-flex; align-items: center; gap: 4px; cursor: pointer; list-style: none;
  color: var(--muted); font-size: var(--fs-sm); transition: color var(--dur-1);
}
details > summary:hover { color: var(--text); }
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; width: 6px; height: 6px; margin: 0 4px 0 2px; border: solid currentColor; border-width: 0 1.5px 1.5px 0;
  transform: rotate(-45deg); transition: transform var(--dur-2) var(--ease);
}
details[open] > summary::before { transform: rotate(45deg); }
details[open] > *:not(summary) { animation: ds-fade-up var(--dur-3) var(--ease) both; }

/* ================================================================ Konsole, Log, Editor */

pre.log, .code-editor {
  margin: 0; background: var(--bg-sunken); color: #c9ccd1;
  border: 1px solid var(--border); border-radius: var(--r);
  padding: var(--sp-3) var(--sp-4); font-family: var(--font-mono); font-size: 12px; line-height: 1.7;
}
pre.log { max-height: 440px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
textarea.code-editor { display: block; width: 100%; height: auto; min-height: 380px; resize: vertical; tab-size: 4; white-space: pre; overflow: auto; font-size: 12.5px; line-height: 1.6; }

/* ================================================================ Leer-Zustand, Lade-Platzhalter */

.empty { text-align: center; padding: var(--sp-10) var(--sp-5); color: var(--muted); font-size: var(--fs-sm); }
.empty .ti { display: grid; place-items: center; width: 40px; height: 40px; margin: 0 auto var(--sp-3); font-size: 20px; color: var(--faint);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-lg); }

.skeleton {
  border-radius: var(--r-lg);
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 40%, var(--surface) 60%);
  background-size: 300% 100%; animation: ds-shimmer 1.6s ease-in-out infinite;
}

/* ================================================================ Benachrichtigungen (Toasts) */

.toasts {
  position: fixed; right: var(--sp-6); bottom: var(--sp-6); z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: 400px;
  background: var(--surface-3); border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  padding: 10px 14px; font-size: var(--fs-sm); box-shadow: var(--shadow-lg);
  animation: ds-toast-in var(--dur-3) var(--ease) both;
}
.toast .ti { color: var(--green); font-size: 17px; flex-shrink: 0; }
.toast.error .ti { color: var(--red); }
.toast.out { animation: ds-toast-out var(--dur-2) ease-in both; }

@media (max-width: 600px) {
  .toasts { left: var(--sp-4); right: var(--sp-4); bottom: var(--sp-4); }
  .toast { max-width: none; }
}

/* ================================================================ Segment-Umschalter / Reiter */

.tabs { display: inline-flex; gap: 2px; padding: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); max-width: 100%; overflow-x: auto; }
.tabs button, .tabs a {
  height: 26px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted);
  font-size: var(--fs-sm); font-weight: var(--fw-medium); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
  transition: background var(--dur-1), color var(--dur-1);
}
.tabs button:hover, .tabs a:hover { color: var(--text); }
.tabs .active { background: var(--surface-4); color: var(--text); box-shadow: var(--shadow-sm); }

/* ================================================================ Avatar */

.avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; background: var(--surface-3); flex-shrink: 0; }
.avatar-lg { width: 72px; height: 72px; border: 1px solid var(--border-strong); }

/* ================================================================ Animationen (Präfix ds- = Design-System) */

@keyframes ds-fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ds-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ds-grow { from { width: 0; } }
@keyframes ds-pop { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
@keyframes ds-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes ds-ping { 0% { transform: scale(1); opacity: .6; } 80%, 100% { transform: scale(2.8); opacity: 0; } }
@keyframes ds-toast-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes ds-toast-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }
