:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #0284c7;
  --accent-soft: #e0f2fe;
  --ok: #16a34a;
  --low: #f59e0b;
  --crit: #dc2626;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .05);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #0f1829;
    --border: #24344d;
    --text: #e8eef7;
    --muted: #93a4bd;
    --accent: #38bdf8;
    --accent-soft: #0c2a3d;
    --ok: #4ade80;
    --low: #fbbf24;
    --crit: #f87171;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.view { display: none; }
.view.active { display: block; }
.page { display: none; padding: 16px; padding-bottom: 40px; }
.page.active { display: block; }

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

#view-login {
  min-height: 100dvh;
  display: none;
  place-items: center;
  padding: 24px;
}
#view-login.active { display: grid; }

.login-box {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-logo { font-size: 3rem; line-height: 1; }
.login-box h1 { margin: 12px 0 4px; font-size: 1.5rem; }
.login-box p { margin: 0 0 20px; }

input, select {
  width: 100%;
  padding: 13px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}
input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  font-family: inherit;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 13px 16px;
  cursor: pointer;
  transition: filter .15s;
}
button:active { filter: brightness(.92); }

.primary { background: var(--accent); color: #fff; width: 100%; font-weight: 600; }
.secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}
.danger { background: transparent; color: var(--crit); border-color: var(--crit); }
.block { width: 100%; margin-bottom: 12px; }

.error { color: var(--crit); font-size: .9rem; margin: 8px 0 0; }

/* ------------------------------------------------------------------ Kopfzeile */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(12px, env(safe-area-inset-top)) 12px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: 4px; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  padding: 6px 10px;
  line-height: 1;
}

/* --------------------------------------------------------------- Geräteliste */

.device-grid { display: grid; gap: 12px; }

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 14px;
}

.device-bar {
  position: relative;
  width: 44px;
  height: 72px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 2px solid var(--border);
  overflow: hidden;
  flex-shrink: 0;
}
.device-fill {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: var(--ok);
  transition: height .4s ease;
}
.device-fill.low { background: var(--low); }
.device-fill.critical { background: var(--crit); }

.device-info { flex: 1; min-width: 0; }
.device-name {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}
.device-value { font-size: 1.4rem; font-weight: 700; margin-top: 2px; }
.device-meta { font-size: .82rem; color: var(--muted); margin-top: 2px; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.dot.online { background: var(--ok); }

.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

/* ------------------------------------------------------------ Detailansicht */

.detail-head {
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.detail-numbers { flex: 1; min-width: 0; }
.big-value { font-size: 2rem; font-weight: 700; line-height: 1.1; }

.pill {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: .78rem;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
}
.pill.low { background: color-mix(in srgb, var(--low) 18%, transparent); color: var(--low); }
.pill.critical { background: color-mix(in srgb, var(--crit) 18%, transparent); color: var(--crit); }
.pill.offline { background: var(--surface-2); color: var(--muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.card-title {
  font-weight: 600;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.inline-select { width: auto; margin: 0; padding: 6px 10px; font-size: .85rem; }

.row { display: flex; gap: 8px; align-items: flex-start; }
.row input { margin-bottom: 0; }
.row button { white-space: nowrap; }

.meta-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.meta-row:last-child { border-bottom: none; }
.meta-row span:first-child { color: var(--muted); }

.feedback { font-size: .88rem; margin: 10px 0 0; color: var(--ok); }
.feedback.bad { color: var(--crit); }

#chart svg { width: 100%; height: 180px; display: block; }
.chart-empty { text-align: center; color: var(--muted); padding: 40px 0; font-size: .9rem; }

/* -------------------------------------------------------------- Verwaltung */

.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 10px;
  font-weight: 600;
  border-radius: 9px;
}
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.admin-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}
.admin-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.admin-item-name { font-weight: 600; }
.admin-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.admin-actions button { padding: 8px 12px; font-size: .85rem; }

.badge {
  font-size: .72rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

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

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, .6);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 100;
}
.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 85dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions button { flex: 1; }

label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }

.credentials {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: .82rem;
  word-break: break-all;
  margin: 10px 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
}
.checkbox-row input { width: auto; margin: 0; }

/* ------------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 200;
  box-shadow: var(--shadow);
}

@media (min-width: 700px) {
  .page { max-width: 760px; margin: 0 auto; }
  .device-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { max-width: 760px; margin: 0 auto; border-radius: 0 0 12px 12px; }
}
