/* Farbrollen einmal definieren; die Dunkelvariante tauscht nur die Werte. */
:root {
  color-scheme: light dark;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-contrast: #ffffff;

  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --critical: #b91c1c;
  --critical-bg: #fee2e2;
  --unknown: #64748b;
  --unknown-bg: #e2e8f0;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1a2334;
    --border: #26324a;
    --text: #e6edf7;
    --text-muted: #94a3b8;
    --accent: #60a5fa;
    --accent-contrast: #08111f;

    --ok: #4ade80;
    --ok-bg: #14331f;
    --warn: #fbbf24;
    --warn-bg: #3a2a08;
    --critical: #f87171;
    --critical-bg: #3d1414;
    --unknown: #94a3b8;
    --unknown-bg: #1f2937;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0; font-weight: 650; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; }
a { color: var(--accent); }

/* ---------- Gerüst ---------- */

.boot {
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  color: var(--text-muted);
}

.spinner {
  width: 26px;
  height: 26px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
  * { transition: none !important; }
}

.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.topbar .brand img { width: 26px; height: 26px; border-radius: 7px; }
.topbar .spacer { flex: 1; }

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 max(10px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tabs a {
  padding: 11px 14px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 550;
  font-size: 0.92rem;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

main {
  flex: 1;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-left)) calc(40px + env(safe-area-inset-bottom));
}

.page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head .spacer { flex: 1; }

/* ---------- Bausteine ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.stat { padding: 14px 16px; }
.stat .label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.stat .value { font-size: 1.7rem; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 0.82rem; color: var(--text-muted); }
.stat.is-critical .value { color: var(--critical); }
.stat.is-warn .value { color: var(--warn); }
.stat.is-ok .value { color: var(--ok); }

.site-list { display: grid; gap: 10px; }

.site {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease;
}
.site:hover { border-color: var(--accent); }

.dot { width: 11px; height: 11px; border-radius: 50%; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.critical { background: var(--critical); }
.dot.unknown { background: var(--unknown); }
.dot.disabled { background: var(--unknown); opacity: 0.4; }

.site .name { font-weight: 600; }
.site .url { font-size: 0.84rem; color: var(--text-muted); word-break: break-all; }
.site .meta { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-muted); margin-top: 3px; }
.site .right { text-align: right; font-size: 0.84rem; color: var(--text-muted); white-space: nowrap; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.critical { background: var(--critical-bg); color: var(--critical); }
.badge.unknown { background: var(--unknown-bg); color: var(--unknown); }

.incident {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.incident:last-child { border-bottom: none; }
.incident .title { font-weight: 600; }
.incident .detail { font-size: 0.86rem; color: var(--text-muted); white-space: pre-line; margin-top: 2px; }
.incident .when { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }

.empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }
.empty p { margin: 6px 0 0; }

/* ---------- Formulare ---------- */

.field { display: grid; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 0.85rem; font-weight: 600; }
.field .description { font-size: 0.8rem; color: var(--text-muted); }

input[type="text"], input[type="url"], input[type="email"], input[type="password"],
input[type="number"], input[type="time"], textarea, select {
  width: 100%;
  padding: 9px 11px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
textarea { min-height: 76px; resize: vertical; }

.checkbox { display: flex; align-items: center; gap: 9px; margin-bottom: 11px; font-size: 0.92rem; }
.checkbox input { width: 17px; height: 17px; accent-color: var(--accent); }

button {
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
button.danger { color: var(--critical); }
button.small { padding: 5px 10px; font-size: 0.84rem; }

.actions { display: flex; gap: 9px; flex-wrap: wrap; }

.section { padding: 18px; margin-bottom: 16px; }
.section > h2 { margin-bottom: 4px; }
.section > .description { color: var(--text-muted); font-size: 0.87rem; margin: 0 0 16px; }

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

/* ---------- Anmeldung ---------- */

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 400px; padding: 26px; }
.auth .logo { display: flex; align-items: center; gap: 11px; margin-bottom: 6px; }
.auth .logo img { width: 34px; height: 34px; border-radius: 9px; }
.auth .description { color: var(--text-muted); font-size: 0.88rem; margin: 0 0 20px; }
.auth button { width: 100%; margin-top: 6px; }

.error {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--critical-bg);
  color: var(--critical);
  font-size: 0.87rem;
  margin-bottom: 14px;
}

/* ---------- Detailseite ---------- */

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; align-items: start; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 16px; font-size: 0.89rem; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; word-break: break-word; }

.check-row {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.89rem;
}
.check-row:last-child { border-bottom: none; }
.check-row .kind { font-weight: 600; min-width: 108px; }
.check-row .message { color: var(--text-muted); flex: 1; }

.update-list { margin: 8px 0 0; padding-left: 18px; font-size: 0.87rem; }
.update-list li { margin-bottom: 3px; }

code, .code { font-family: var(--mono); font-size: 0.85em; background: var(--surface-2); padding: 2px 6px; border-radius: 5px; word-break: break-all; }

/* ---------- Hinweise ---------- */

.toasts {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  gap: 8px;
  z-index: 100;
  width: min(420px, calc(100vw - 32px));
}

.toast {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 0.89rem;
  animation: rise 0.2s ease;
}
.toast.error { border-color: var(--critical); color: var(--critical); }
.toast.success { border-color: var(--ok); color: var(--ok); }

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.banner {
  padding: 12px 15px;
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 0.88rem;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.banner .spacer { flex: 1; }

/* ---------- Dialog ---------- */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 22px;
  width: min(520px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(8, 12, 22, 0.55); }
dialog h2 { margin-bottom: 16px; }

@media (max-width: 520px) {
  /* Auf schmalen Geräten würde die Wortmarke die Schaltflächen verdrängen. */
  .topbar .brand { font-size: 0; gap: 0; }
  .topbar .brand img { width: 28px; height: 28px; }
}

@media (max-width: 620px) {
  .site { grid-template-columns: auto 1fr; }
  .site .right { grid-column: 2; text-align: left; }
  .incident { grid-template-columns: auto 1fr; }
  .incident .when { grid-column: 2; }
}
