:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --border: #2a3647;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3d8bfd;
  --danger: #e35d6a;
  --ok: #3ecf8e;
  --orange: #f0a500;
  --font: system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.nav { display: flex; gap: 1rem; align-items: center; }
.nav a { color: var(--muted); }
.nav a:hover { color: var(--text); }

button.linkish.danger-text,
.linkish.danger-text {
  color: var(--danger);
}
button.linkish.danger-text:hover,
.linkish.danger-text:hover {
  color: #ff8a94;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  flex: 1;
}

.footer {
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0.75rem 1rem;
  text-align: center;
}

h1 { font-size: 1.5rem; margin: 0 0 0.5rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.75rem; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}
a.btn:hover { text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.small { padding: 0.25rem 0.5rem; font-size: 0.85rem; }

.row { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.stack.narrow { max-width: 420px; }

label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0c1017;
  color: var(--text);
  font: inherit;
}
textarea { font-family: var(--mono); }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th, .table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
}
.table.compact th, .table.compact td { padding: 0.35rem 0.45rem; }
.actions {
  white-space: normal;
  vertical-align: middle;
}
.actions .inline { vertical-align: middle; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}

/* Kennzahlen: Flex-Zeile (zuverlässiger als Grid bei älteren Clients); auf Desktop eine Reihe */
.kpi-strip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1rem 0.85rem;
  margin-bottom: 1rem;
}
.kpi-grid {
  display: flex;
  flex-flow: row wrap;
  align-items: stretch;
  justify-content: flex-start;
  gap: 0.6rem;
  width: 100%;
}
.kpi-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.35rem;
  flex: 1 1 8.5rem;
  min-width: min(100%, 7.5rem);
  min-height: 4.35rem;
  padding: 0.65rem 0.55rem 0.7rem;
  background: #0c1017;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04);
}
@media (min-width: 1100px) {
  .kpi-tile {
    flex: 1 1 0;
    min-width: 0;
  }
}
.kpi-tile--ok { border-top: 3px solid var(--ok); }
.kpi-tile--warn { border-top: 3px solid var(--orange); }
.kpi-tile--bad { border-top: 3px solid var(--danger); }
.kpi-tile--muted { border-top: 3px solid #5a6573; }
.kpi-num {
  display: block;
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
  color: var(--text);
}
.kpi-label {
  display: block;
  font-size: 0.78rem;
  line-height: 1.25;
  color: var(--muted);
  max-width: 100%;
  hyphens: auto;
  overflow-wrap: anywhere;
}
.kpi-foot { margin: 0.75rem 0 0; padding-top: 0.35rem; }

/* HTMX: unsichtbarer Poll-Trigger */
.htmx-auto-refresh {
  display: none;
}
.kpi-ok { color: var(--ok); }
.kpi-warn { color: var(--orange); }
.kpi-bad { color: var(--danger); }
.kpi-muted { color: #9aa8bc; }

/* Tabellen-Aktionen: nebeneinander — Form ist kein Block über volle Breite */
.table td.actions {
  white-space: nowrap;
  width: 1%;
}
.action-group {
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem 0.65rem;
  vertical-align: middle;
}
.action-delete-form {
  display: inline-flex;
  flex: 0 0 auto;
  margin: 0;
  padding: 0;
  align-items: center;
}
.action-group > a.btn {
  flex: 0 0 auto;
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--accent);
  text-decoration: none;
}
.btn-ghost:hover {
  background: rgba(61, 139, 253, 0.12);
  border-color: var(--accent);
  text-decoration: none;
}
.btn-danger-outline {
  background: transparent;
  border-color: rgba(227, 93, 106, 0.55);
  color: var(--danger);
}
.btn-danger-outline:hover {
  background: rgba(227, 93, 106, 0.18);
  border-color: var(--danger);
  color: #ffb8bf;
}

.alert { padding: 0.65rem 0.85rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-error { background: rgba(227, 93, 106, 0.15); border: 1px solid var(--danger); }
.alert-ok { background: rgba(62, 207, 142, 0.12); border: 1px solid var(--ok); }

.code-block {
  background: #0c1017;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: auto;
  max-height: 24rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.code-block.small { font-size: 0.8rem; max-height: 10rem; }
.journal-payload { max-height: 70vh; white-space: pre; }

.table-wrap { overflow-x: auto; max-width: 100%; }
.api-key-cell {
  min-width: 22rem;
  max-width: 40rem;
  vertical-align: top;
}
.api-key {
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: normal;
  word-break: break-all;
  display: block;
  line-height: 1.35;
}

.light {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  vertical-align: middle;
  border: 1px solid rgba(255,255,255,0.15);
}
.light.large { width: 20px; height: 20px; }
.light-gray { background: #6b7280; }
.light-green { background: var(--ok); }
.light-orange { background: var(--orange); }
.light-red { background: var(--danger); }

.kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.35rem 1rem;
  font-size: 0.9rem;
}
.kv dt { color: var(--muted); margin: 0; }
.kv dd { margin: 0; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.filters { margin-bottom: 1rem; }

.pre-wrap { white-space: pre-wrap; word-break: break-word; max-width: 28rem; }

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1a2332, var(--bg));
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.inline { display: inline; margin: 0; padding: 0; }
.linkish {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.linkish:hover { text-decoration: underline; }

.inline-form { margin-top: 0.75rem; }

@media (max-width: 640px) {
  .table { font-size: 0.8rem; }
  .kv { grid-template-columns: 1fr; }
}
