/* Crise — feuille de style
   Un seul écran, lisible en pleine panique : de gros chiffres, des états
   explicites, et des actions destructrices qui demandent un maintien. */

*,
*::before,
*::after { box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  --bg: #0a0c10;
  --bg-2: #10141a;
  --surface: rgba(255, 255, 255, 0.035);
  --surface-2: rgba(255, 255, 255, 0.065);
  --surface-3: rgba(255, 255, 255, 0.095);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.17);
  --text: #f4f2ee;
  --muted: #9297a1;
  --track: rgba(255, 255, 255, 0.12);
  --accent: #f3b45f;
  --ok: #5ecb95;
  --warn: #e8b04a;
  --err: #f0725f;
  --state: var(--muted);
  --toast-bg: #191d23;
  --toast-text: #f6f3ee;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 24px 50px -34px rgba(0, 0, 0, 0.9);
  --ease: cubic-bezier(0.22, 0.8, 0.24, 1);
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f4f1eb;
  --bg-2: #fbf9f4;
  --surface: #ffffff;
  --surface-2: #f0ebe2;
  --surface-3: #e7e0d5;
  --border: rgba(30, 25, 18, 0.10);
  --border-strong: rgba(30, 25, 18, 0.18);
  --text: #1a1814;
  --muted: #6e6860;
  --track: rgba(30, 25, 18, 0.12);
  --accent: #c98215;
  --ok: #2f9e6b;
  --warn: #b87a13;
  --err: #c9574a;
  --toast-bg: #1b1916;
  --toast-text: #f8f5ef;
  --shadow: 0 1px 2px rgba(45, 35, 20, 0.04), 0 24px 48px -34px rgba(45, 35, 20, 0.35);
  color-scheme: light;
}

body[data-health="ok"] { --state: var(--ok); }
body[data-health="degraded"] { --state: var(--warn); }
body[data-health="server"],
body[data-health="relay"],
body[data-health="plug"] { --state: var(--err); }
body[data-health="setup"],
body[data-health="loading"],
body[data-health="unknown"] { --state: var(--muted); }

html,
body { min-height: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(65% 38% at 50% -8%, color-mix(in srgb, var(--state) 15%, transparent), transparent 70%),
    radial-gradient(45% 40% at 100% 100%, rgba(126, 148, 255, 0.06), transparent 65%);
  transition: background 0.5s var(--ease);
}

html[data-theme="light"] body::before {
  background:
    radial-gradient(65% 38% at 50% -8%, color-mix(in srgb, var(--state) 16%, transparent), transparent 70%),
    radial-gradient(45% 40% at 100% 100%, rgba(120, 140, 235, 0.06), transparent 65%);
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}
.icon--sm { width: 16px; height: 16px; stroke-width: 1.8; }

code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}

/* ---------- Structure ---------- */

.app {
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 3vh, 26px);
  width: min(780px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  padding-top: max(18px, env(safe-area-inset-top));
}

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

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid color-mix(in srgb, var(--state) 32%, var(--border));
  border-radius: 11px;
  background: color-mix(in srgb, var(--state) 10%, var(--surface-2));
  color: var(--state);
  transition: color 0.3s, border-color 0.3s, background 0.3s;
}
.brand-mark .icon { width: 20px; height: 20px; stroke-width: 2; }

.brand-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.chip.is-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.chip.is-warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 38%, transparent); }
.chip.is-err { color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, transparent); }
.chip.is-idle { color: var(--muted); }

.top-actions { display: flex; gap: 7px; flex: 0 0 auto; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, transform 0.12s;
  -webkit-appearance: none;
  appearance: none;
}
.icon-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn .icon { width: 20px; height: 20px; }

/* ---------- En-tête ---------- */

.hero { display: flex; flex-direction: column; gap: 7px; }

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(34px, 9.5vw, 52px);
  font-weight: 640;
  letter-spacing: -0.045em;
  line-height: 1.0;
  text-wrap: balance;
}

.hero-sub {
  max-width: 46ch;
  margin: 0;
  color: var(--muted);
  font-size: clamp(13px, 1.7vw, 14.5px);
  line-height: 1.45;
}

.stale {
  margin: 4px 0 0;
  padding: 8px 11px;
  border: 1px solid color-mix(in srgb, var(--warn) 32%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  color: var(--text);
  font-size: 11.5px;
  line-height: 1.4;
}

/* ---------- Onglets ---------- */

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
}

.tabs button {
  flex: 1;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
  -webkit-appearance: none;
  appearance: none;
}
.tabs button:hover { color: var(--text); }
.tabs button[aria-selected="true"] { background: var(--text); color: var(--bg); }

/* ---------- Énergie ---------- */

.energy {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.energy .card-head { align-items: center; }

.range { width: 100%; }
.range button { min-height: 36px; }

.energy-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
}

.energy-total {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin: 0;
  font-size: clamp(34px, 9vw, 44px);
  font-weight: 640;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.045em;
  line-height: 1;
}
.energy-total small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.03em;
}

.energy-note {
  flex: 1 1 140px;
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}
.energy-note:empty { display: none; }

.chart { display: flex; flex-direction: column; gap: 5px; }
.chart[hidden] { display: none; }

.chart-bars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  align-items: end;
  gap: 2px;
  height: 142px;
  padding-top: 6px;
  border-bottom: 1px solid var(--border);
}

.bar {
  position: relative;
  display: flex;
  align-items: flex-end;
  height: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.bar-fill {
  display: block;
  width: 100%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg,
    color-mix(in srgb, var(--accent) 90%, white),
    color-mix(in srgb, var(--accent) 55%, transparent));
  opacity: 0.7;
  transition: height 0.3s var(--ease), opacity 0.16s, background 0.16s;
}

.bar[data-zero="1"] .bar-fill { min-height: 0; height: 0 !important; }
.bar:hover .bar-fill { opacity: 1; }
.bar.is-active .bar-fill {
  background: linear-gradient(180deg, var(--accent), color-mix(in srgb, var(--accent) 48%, transparent));
  opacity: 1;
}
.bar-fill.is-partial {
  background: repeating-linear-gradient(135deg,
    color-mix(in srgb, var(--accent) 78%, transparent) 0 3px,
    color-mix(in srgb, var(--accent) 28%, transparent) 3px 6px);
}
.bar:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chart-axis {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 2px;
  color: var(--muted);
  font-size: 8.5px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.chart-axis span {
  overflow: hidden;
  white-space: nowrap;
}

.chart-readout {
  min-height: 18px;
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.chart-readout:empty { display: none; }

/* ---------- Carte serveur ---------- */

.board { display: flex; flex-direction: column; gap: 22px; }

.card {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: linear-gradient(168deg, var(--surface-2), var(--surface));
  box-shadow: var(--shadow);
  padding: 16px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.card-title { display: flex; align-items: center; gap: 10px; min-width: 0; }

.icon-badge {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--muted);
}
.icon-badge .icon { width: 20px; height: 20px; }

.card-title h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.meta {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  white-space: nowrap;
}
.status .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.status.is-ok { color: var(--ok); }
.status.is-warn { color: var(--warn); }
.status.is-err { color: var(--err); }
.status.is-idle { color: var(--muted); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 15px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.stat { min-width: 0; }
.stat dt {
  color: var(--muted);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.stat dd {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 4px 0 0;
  font-size: 15px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.stat dd b { font-size: 16px; font-weight: 620; }
.stat dd small { color: var(--muted); font-size: 10.5px; font-weight: 450; letter-spacing: 0; }

.notice {
  margin: 13px 0 0;
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--warn) 30%, var(--border));
  border-radius: 11px;
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  font-size: 11.5px;
  line-height: 1.45;
}
.notice.is-err {
  border-color: color-mix(in srgb, var(--err) 34%, var(--border));
  background: color-mix(in srgb, var(--err) 8%, transparent);
}

/* ---------- Prise ---------- */

.power {
  display: flex;
  flex-direction: column;
  gap: 11px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.power-head { display: flex; align-items: center; gap: 9px; min-width: 0; }

.power-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--muted);
}

.power-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.power-name { font-size: 12.5px; font-weight: 560; }
.power-extra {
  overflow: hidden;
  color: var(--muted);
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.power-extra.is-error { color: var(--err); }

.power-value {
  flex: 0 0 auto;
  font-size: 25px;
  font-weight: 640;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.035em;
  line-height: 1;
}
.power-value small { margin-left: 2px; color: var(--muted); font-size: 10px; font-weight: 500; letter-spacing: 0.04em; }

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

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 11px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 550;
  line-height: 1.2;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, opacity 0.16s, transform 0.12s;
  -webkit-appearance: none;
  appearance: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.42; cursor: default; transform: none; }

.btn--primary { background: var(--text); color: var(--bg); }
.btn--primary:hover { opacity: 0.9; }
.btn--ghost { border-color: var(--border); background: var(--surface); color: var(--text); }
.btn--ghost:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn--danger {
  border-color: color-mix(in srgb, var(--err) 28%, var(--border));
  background: color-mix(in srgb, var(--err) 7%, var(--surface));
  color: var(--err);
}
.btn--danger:hover {
  border-color: color-mix(in srgb, var(--err) 48%, var(--border));
  background: color-mix(in srgb, var(--err) 13%, var(--surface));
}

.node-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 12px;
}
.node-foot:not(:has(> :not([hidden]))) { display: none; }
.node-foot .btn { font-size: 12px; }
.node-foot .icon { width: 15px; height: 15px; }

/* ---------- Invités ---------- */

.guests-section { display: flex; flex-direction: column; gap: 10px; }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}
.section-head h2 {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.count {
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.hint {
  margin: 0;
  padding: 0 2px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}
.hint[hidden] { display: none; }
.hint.is-err { color: var(--err); }

.guests { display: grid; grid-template-columns: 1fr; gap: 9px; }
@media (min-width: 720px) {
  .guests { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.guest {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  transition: border-color 0.25s, background 0.25s, opacity 0.25s;
}
.guest[data-state="running"] { border-color: color-mix(in srgb, var(--ok) 20%, var(--border)); }
.guest[data-state="missing"],
.guest[data-state="unknown"] {
  border-color: color-mix(in srgb, var(--err) 26%, var(--border));
  background: color-mix(in srgb, var(--err) 4%, var(--surface));
}
.guest.is-pending {
  border-color: color-mix(in srgb, var(--warn) 40%, var(--border));
  background: color-mix(in srgb, var(--warn) 5%, var(--surface));
}
.guest.is-pending .status .dot { animation: pulse 1.1s ease-in-out infinite; }

.guest-head { display: flex; flex-direction: column; gap: 5px; min-width: 0; }

.guest-title { display: flex; align-items: center; gap: 7px; min-width: 0; }

.kind {
  flex: 0 0 auto;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 8.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.guest h3 {
  flex: 1;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.012em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.guest-title .status { flex: 0 0 auto; }
.guest-meta {
  margin: 0;
  color: var(--muted);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.guest-actions { display: flex; gap: 5px; margin-top: auto; }

.act {
  display: flex;
  flex: 1 1 0;
  min-width: 58px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 52px;
  padding: 7px 3px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 9.5px;
  font-weight: 550;
  line-height: 1.15;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s, opacity 0.16s, transform 0.12s;
  -webkit-appearance: none;
  appearance: none;
}
.act .icon { width: 17px; height: 17px; stroke-width: 1.9; }
.act:hover { border-color: var(--border-strong); background: var(--surface-3); }
.act:active { transform: scale(0.96); }
.act[hidden] { display: none; }
.act:disabled { opacity: 0.38; cursor: default; transform: none; }

.act--danger {
  border-color: color-mix(in srgb, var(--err) 22%, var(--border));
  background: color-mix(in srgb, var(--err) 6%, var(--surface-2));
  color: var(--err);
}
.act--danger:hover {
  border-color: color-mix(in srgb, var(--err) 42%, var(--border));
  background: color-mix(in srgb, var(--err) 11%, var(--surface-2));
}

.empty {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  text-align: center;
}

/* ---------- Première configuration ---------- */

.setup {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px dashed color-mix(in srgb, var(--warn) 45%, var(--border));
  border-radius: 18px;
  background: color-mix(in srgb, var(--warn) 6%, transparent);
}
.setup[hidden] { display: none; }
.setup > div { flex: 1; min-width: 0; }
.setup h2 { margin: 0; font-size: 13px; font-weight: 620; }
.setup p { margin: 3px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.4; }
.setup-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 11px;
  background: color-mix(in srgb, var(--warn) 16%, transparent);
  color: var(--warn);
}
.setup-icon .icon { width: 19px; height: 19px; }
.setup .btn { flex: 0 0 auto; font-size: 11.5px; }

/* ---------- Pied de page ---------- */

.foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: auto;
  padding-top: 6px;
  color: var(--muted);
  font-size: 11px;
}

.dot {
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.err { background: var(--err); }
.dot.warn { background: var(--warn); }

.foot .sync { margin-left: auto; font-variant-numeric: tabular-nums; }

.link {
  position: relative;
  padding: 3px 1px;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 11px;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--muted) 45%, transparent);
  text-underline-offset: 3px;
  cursor: pointer;
}
.link:hover { color: var(--text); }
/* Zone tactile confortable sans agrandir visuellement le lien. */
.link::after {
  content: "";
  position: absolute;
  inset: -14px -10px;
}

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 90;
  max-width: calc(100vw - 28px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--toast-bg);
  color: var(--toast-text);
  font-size: 12.5px;
  text-align: center;
  box-shadow: 0 18px 44px -14px rgba(0, 0, 0, 0.55);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s, transform 0.25s var(--ease);
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Fenêtres ---------- */

.sheet {
  width: min(560px, calc(100vw - 28px));
  max-height: min(90dvh, 900px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-2);
  color: var(--text);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.7);
  overflow: hidden;
}
.sheet[open] { display: flex; flex-direction: column; }
.sheet::backdrop {
  background: rgba(5, 6, 8, 0.6);
  backdrop-filter: blur(10px);
}

.sheet-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex: 0 0 auto;
  padding: 20px 20px 12px;
}
.sheet-head h2 {
  margin: 2px 0 0;
  font-size: 24px;
  font-weight: 640;
  letter-spacing: -0.03em;
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 4px 20px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet-body::-webkit-scrollbar { width: 8px; }
.sheet-body::-webkit-scrollbar-thumb { border-radius: 99px; background: var(--border-strong); }

.block { display: flex; flex-direction: column; gap: 11px; }
.block h3 {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
}
.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus-visible {
  border-color: color-mix(in srgb, var(--accent) 60%, transparent);
  outline: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
  outline-offset: 1px;
}
.field input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }

.hint code { font-size: 10.5px; }
.hint.notice {
  padding: 9px 11px;
  border: 1px solid color-mix(in srgb, var(--warn) 32%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 7%, transparent);
  color: var(--text);
}

.segmented {
  display: flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}
.segmented button {
  flex: 1;
  padding: 7px 5px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.16s, color 0.16s;
}
.segmented button.is-active { background: var(--text); color: var(--bg); }

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex: 0 0 auto;
  padding: 12px 20px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}

/* ---------- Confirmation ---------- */

.sheet--confirm {
  width: min(420px, calc(100vw - 28px));
  max-height: none;
  overflow: visible;
}

.confirm-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  padding: 22px 22px 4px;
}

.confirm-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-bottom: 2px;
  border: 1px solid color-mix(in srgb, var(--warn) 32%, var(--border));
  border-radius: 13px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  color: var(--warn);
}
.confirm-icon .icon { width: 22px; height: 22px; }

.confirm-body h2 {
  margin: 0;
  font-size: 21px;
  font-weight: 630;
  letter-spacing: -0.025em;
  line-height: 1.15;
}

.confirm-text {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  padding: 18px 22px 22px;
}
.confirm-actions .btn { flex: 1; padding: 11px 14px; font-size: 13px; }
.confirm-actions .btn--danger {
  border-color: color-mix(in srgb, var(--err) 32%, var(--border));
  background: color-mix(in srgb, var(--err) 10%, var(--surface));
}
.confirm-actions .btn--danger:hover { background: color-mix(in srgb, var(--err) 16%, var(--surface)); }

.btn.is-hold {
  position: relative;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.btn.is-hold .hold-fill {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, currentColor 26%, transparent);
  transform: scaleX(var(--hold, 0));
  transform-origin: left center;
  pointer-events: none;
}
.btn.is-hold .hold-label { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.btn.is-hold .hold-label small {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.03em;
  opacity: 0.72;
}
.btn.is-hold.is-holding { border-color: currentColor; }

/* ---------- Adaptations ---------- */

@media (max-width: 400px) {
  .app { padding-right: 13px; padding-left: 13px; }
  .brand-name { display: none; }
  .card { border-radius: 20px; padding: 14px; }
  .hero h1 { font-size: clamp(31px, 10vw, 40px); }
  .power-value { font-size: 22px; }
  .status { font-size: 9px; }
  .guest h3 { font-size: 14px; }
  .act { font-size: 9px; min-width: 54px; }
  .setup { flex-wrap: wrap; }
  .setup .btn { margin-left: 48px; }
  .chart-bars { height: 124px; }
  .chart-axis { font-size: 8px; }
  .energy-total { font-size: clamp(30px, 9vw, 38px); }
}

@media (max-width: 640px) {
  .sheet {
    width: 100vw;
    max-width: none;
    max-height: 93dvh;
    margin: auto auto 0;
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 24px 24px 0 0;
  }
  .sheet--confirm {
    width: calc(100vw - 24px);
    margin: auto;
    border: 1px solid var(--border);
    border-radius: 22px;
  }
  .sheet-head { padding: 17px 18px 10px; }
  .sheet-body { padding: 4px 18px 22px; }
  .sheet-foot { padding-right: 18px; padding-left: 18px; }
  .confirm-body { padding: 20px 20px 4px; }
  .confirm-actions { padding: 16px 20px 20px; }
}

@media (max-height: 640px) and (orientation: landscape) {
  .app { gap: 14px; padding-top: 12px; }
  .hero h1 { font-size: clamp(28px, 6vw, 38px); }
}

@media (hover: hover) {
  .guest:hover { border-color: var(--border-strong); }
  .guest[data-state="running"]:hover { border-color: color-mix(in srgb, var(--ok) 32%, var(--border)); }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
