:root {
  --bg: #f4f2fb;
  --surface: #ffffff;
  --text: #1d2340;
  --muted: #646a85;
  --border: #dcd9ea;
  --primary: #5b5bd6;
  --primary-text: #ffffff;
  --ok: #1f9d68;
  --warn: #d98a00;
  --danger: #d43c4c;
  --meter-bg: #e6e3f3;
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12152a;
    --surface: #1d2140;
    --text: #eceaf7;
    --muted: #a3a6c2;
    --border: #2f3460;
    --primary: #7b7bf0;
    --meter-bg: #2a2e55;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  min-height: 100dvh;
}

[hidden] { display: none !important; }

h1 { font-size: 1.5rem; margin: 1.2rem 0; }

.view { display: flex; flex-direction: column; gap: 16px; }
.view.center { align-items: center; justify-content: center; min-height: 80dvh; text-align: center; }
.center-text { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }

.logo { width: 96px; height: 96px; border-radius: 24px; }

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

.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.hint { font-size: .92rem; color: var(--muted); }
.error { color: var(--danger); margin: 0; }

label { display: flex; flex-direction: column; gap: 6px; text-align: left; }
label.check { flex-direction: row; align-items: center; gap: 10px; }

input:not([type]), input[type=password] {
  font: inherit;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input[type=range] { width: 100%; accent-color: var(--primary); }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--primary); }

.btn {
  font: inherit;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); }
.btn.link { border: none; background: none; color: var(--primary); padding: 6px; }
.btn.big { padding: 18px; font-size: 1.15rem; font-weight: 600; }
.btn.active { background: var(--ok); border-color: var(--ok); color: #fff; }

.btn.role {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  padding: 20px;
}
.role-icon { font-size: 2.4rem; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.pill {
  font-size: .85rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--meter-bg);
  color: var(--muted);
}
.pill.ok { background: var(--ok); color: #fff; }
.pill.warn { background: var(--warn); color: #fff; }
.pill.bad { background: var(--danger); color: #fff; }

.status-big {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  padding: 28px 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background .3s, color .3s;
}
.status-big.active { background: var(--warn); color: #fff; border-color: var(--warn); }
.status-big.offline { color: var(--danger); }

.meter {
  position: relative;
  height: 22px;
  border-radius: 11px;
  background: var(--meter-bg);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--ok), var(--warn) 70%, var(--danger));
  transition: width .15s linear;
}
.meter-threshold {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 3px;
  background: var(--text);
  left: 50%;
}

.alarm {
  background: var(--danger);
  color: #fff;
  padding: 14px;
  border-radius: var(--radius);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .65; } }

details summary { cursor: pointer; font-weight: 600; margin-bottom: 4px; }
details[open] summary { margin-bottom: 14px; }

#dim-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  color: #222;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 40px;
  z-index: 10;
  font-size: .9rem;
}
