/* LoloDomo : interface (téléphone d'abord). Aucune règle de style en ligne : CSP style-src 'self'. */

@font-face {
  font-family: "Figtree";
  src: url("/fonts/figtree.woff") format("woff");
  font-weight: 300 900;
  font-display: swap;
}

:root {
  --bg: #F4F2EE;
  --surface: #FFFFFF;
  --border: #E4E0D8;
  --border-strong: #DDD8CF;
  --text: #1C1B19;
  --muted: #57534B;
  --faint: #6B665D;
  --on-bg: #F6C453;
  --on-border: #E3A92B;
  --on-text: #2A1E05;
  --icon-bg: #F1EEE8;
  --icon-on-bg: rgba(255, 255, 255, 0.45);
  --blue: #2F5D8A;
  --blue-soft: #E8EEF4;
  --blue-text: #FFFFFF;
  --shutter-bg: #DCE8F3;
  --shutter-border: #C3D5E6;
  --shutter-icon-bg: rgba(255, 255, 255, 0.6);
  --neutral: #EFEDE8;
  --chip-on: #1C1B19;
  --chip-on-text: #FFFFFF;
  --danger: #A8321F;
  --ok: #2E7D4F;
  --off: #A8321F;
  --slider: #B7791F;
  --scrim: rgba(28, 27, 25, 0.45);
  --shadow: 0 10px 24px rgba(28, 27, 25, 0.18);
  --focus: #2F5D8A;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121315;
    --surface: #1C1D20;
    --border: #2B2D31;
    --border-strong: #3A3C41;
    --text: #ECEBE8;
    --muted: #A6A29A;
    --faint: #9A968E;
    --on-bg: #F6C453;
    --on-border: #F6C453;
    --on-text: #2A1E05;
    --icon-bg: #26282C;
    --icon-on-bg: rgba(255, 255, 255, 0.35);
    --blue: #8DB6E0;
    --blue-soft: #22303D;
    --blue-text: #0F1A24;
    --shutter-bg: #1D2B38;
    --shutter-border: #2D4152;
    --shutter-icon-bg: rgba(255, 255, 255, 0.08);
    --neutral: #26282C;
    --chip-on: #ECEBE8;
    --chip-on-text: #121315;
    --danger: #F08A78;
    --ok: #5CC28A;
    --off: #F08A78;
    --slider: #F6C453;
    --scrim: rgba(0, 0, 0, 0.6);
    --shadow: 0 10px 24px rgba(0, 0, 0, 0.5);
    --focus: #8DB6E0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Figtree", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
button, input { touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg { display: block; }

/* ---------- Connexion ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.login-brand h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; }
.login-brand img { border-radius: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
.field input, .text-input {
  height: 48px; border: 1px solid var(--border-strong); border-radius: 12px; padding: 0 14px;
  font: inherit; font-size: 16px; background: var(--surface); color: var(--text); width: 100%;
}
.form-error { margin: 0; color: var(--danger); font-size: 14px; }

/* ---------- Boutons ---------- */
.btn {
  height: 44px; padding: 0 18px; border-radius: 12px; border: 0; cursor: pointer;
  font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-block { width: 100%; height: 48px; }
.btn-primary { background: var(--on-bg); color: var(--on-text); }
.btn-dark { background: var(--chip-on); color: var(--chip-on-text); border-radius: 22px; }
.btn-ghost { background: var(--surface); border: 1px solid var(--border-strong); }
.btn-danger { background: var(--danger); color: #FFFFFF; }
.btn:disabled { opacity: 0.6; cursor: default; }
.icon-btn {
  width: 44px; height: 44px; flex: none; border-radius: 14px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn.plain { border: 0; background: transparent; }
.icon-btn.danger { color: var(--danger); }

/* ---------- Mise en page ---------- */
.app { max-width: 720px; margin: 0 auto; padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(16px + env(safe-area-inset-top)) 0 10px;
}
.topbar-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; }
.topbar-titles { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.topbar h1 { margin: 0; font-size: 30px; font-weight: 700; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary { margin: 0; font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); }
.dot.ko { background: var(--off); }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 16px 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 44px; padding: 0 18px; border-radius: 22px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 15px; font-weight: 600; white-space: nowrap; cursor: pointer;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chip[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-text); border-color: var(--chip-on); }
.chip-add { width: 44px; padding: 0; border-style: dashed; color: var(--muted); background: transparent; display: inline-flex; align-items: center; justify-content: center; }
.hint { margin: 4px 16px 10px; font-size: 12px; color: var(--faint); }

.grid {
  padding: 0 16px; display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
.wide { grid-column: 1 / -1; }
.empty { grid-column: 1 / -1; text-align: center; color: var(--muted); margin: 32px 0; }

/* ---------- Tuiles ---------- */
.tile {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 24px;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}
.tile.on { background: var(--on-bg); color: var(--on-text); border-color: var(--on-border); }
.tile.busy { opacity: 0.7; }
.tile.unknown .tile-state { opacity: 0.7; }

.tile-toggle {
  aspect-ratio: 1 / 1; padding: 16px; display: flex; flex-direction: column; justify-content: space-between;
  align-items: flex-start; text-align: left; cursor: pointer; width: 100%;
}
.tile-icon {
  width: 48px; height: 48px; border-radius: 14px; background: var(--icon-bg); flex: none;
  display: flex; align-items: center; justify-content: center;
}
.tile.on .tile-icon { background: var(--icon-on-bg); }
.tile-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile-name { font-size: 16px; font-weight: 600; line-height: 1.2; overflow-wrap: anywhere; }
.tile-state { font-size: 13px; opacity: 0.8; }

/* Panneau du variateur */
.dimmer-big { font-size: 56px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; margin: 8px 0 0; }
.dimmer-note { text-align: center; min-height: 1.35em; }
.slider { width: 100%; height: 36px; margin: 0; accent-color: var(--slider); cursor: pointer; }
.slider-big { height: 48px; }
.slider-big.is-off { opacity: 0.45; }
.slider-wrap { display: flex; flex-direction: column; gap: 2px; }
.slider-scale { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Store : même tuile que les lumières, sur fond bleu ; un appui ouvre le panneau */
.tile-shutter { background: var(--shutter-bg); border-color: var(--shutter-border); }
.tile-shutter .tile-icon { background: var(--shutter-icon-bg); color: var(--blue); }
.tile-shutter .tile-state { opacity: 1; color: var(--muted); }
.tile-shutter.moving { border-color: var(--blue); }
.tile-shutter.moving .tile-state { color: var(--blue); font-weight: 600; }

/* Panneau du store */
.shutter-actions { display: flex; flex-direction: column; gap: 10px; }
.shutter-btn {
  min-height: 64px; border-radius: 18px; border: 0; cursor: pointer; font: inherit; font-size: 18px; font-weight: 600;
  background: var(--blue-soft); color: var(--blue); display: flex; align-items: center; justify-content: center; gap: 10px;
}
.shutter-btn.stop { background: var(--neutral); color: var(--text); }
.shutter-btn.active { background: var(--blue); color: var(--blue-text); }

/* Titre de section (réglages) */
.section-label { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }

/* ---------- Panneaux (bas d'écran) ---------- */
.scrim {
  position: fixed; inset: 0; z-index: 20; background: var(--scrim);
  display: flex; flex-direction: column; justify-content: flex-end; align-items: center;
}
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; overflow-y: auto; background: var(--bg);
  border-radius: 28px 28px 0 0; padding: 12px 16px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.sheet-body { display: flex; flex-direction: column; gap: 14px; }
.sheet-grip { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--border-strong); flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.sheet p { margin: 0; }
.sheet-note { font-size: 14px; color: var(--muted); }
.sheet-small { font-size: 12px; color: var(--faint); }

.room-list { display: flex; flex-direction: column; gap: 8px; }
.room-row {
  height: 58px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 0 6px 0 12px; display: flex; align-items: center; gap: 10px; position: relative;
  touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.room-row.dragging { z-index: 2; border-color: var(--on-border); box-shadow: var(--shadow); touch-action: none; }
.room-row .grip { color: var(--faint); flex: none; }
.room-row .tile-text { flex: 1; }
.room-row.is-hidden .room-name { color: var(--muted); }
.room-row .icon-btn[aria-pressed="true"] { color: var(--faint); }
.room-name { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-count { font-size: 12px; color: var(--faint); }
.room-row .text-input { height: 40px; flex: 1; min-width: 0; }
.confirm-text { flex: 1; font-size: 14px; color: var(--danger); line-height: 1.2; }
.row-btn { height: 40px; padding: 0 12px; border-radius: 10px; font-size: 14px; }
.add-row { display: flex; gap: 8px; align-items: flex-end; }
.add-row .field { flex: 1; }
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-item {
  height: 52px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface);
  display: flex; align-items: center; gap: 12px; padding: 0 16px; cursor: pointer; text-align: left; width: 100%;
  font-size: 16px; font-weight: 600;
}
.menu-item.danger { color: var(--danger); }

/* ---------- Réglages ---------- */
.settings-list { display: flex; flex-direction: column; gap: 18px; }
.settings-section { display: flex; flex-direction: column; gap: 8px; }
.settings-row {
  min-height: 58px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 8px 14px; display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer; width: 100%;
}
.settings-row .tile-text { flex: 1; }
.settings-row.is-hidden .room-name { color: var(--muted); }
.badge { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 8px; background: var(--neutral); color: var(--muted); }
.settings-form { display: flex; flex-direction: column; gap: 14px; }
select.text-input { appearance: auto; }
.fieldset { border: 1px solid var(--border); border-radius: 14px; padding: 8px 14px 12px; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.fieldset legend { font-size: 14px; color: var(--muted); padding: 0 4px; }
.check-row { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 16px; cursor: pointer; }
.check-row input { width: 22px; height: 22px; accent-color: var(--blue); flex: none; }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }
.button-row .btn { flex: 1 1 auto; }

/* ---------- Outils ---------- */
.segmented { display: flex; background: var(--neutral); border-radius: 12px; padding: 3px; gap: 3px; }
.seg { flex: 1; height: 40px; border: 0; border-radius: 10px; background: transparent; font-size: 15px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.button-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.level-row { display: flex; gap: 8px; grid-column: 1 / -1; }
.level-select { width: auto; flex: 1; height: 44px; }
.test-result { display: flex; flex-direction: column; gap: 8px; }
.test-result:empty { display: none; }
.test-line { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; font-size: 14px; }
.test-label { width: 56px; color: var(--muted); }
.test-desc { color: var(--muted); }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px 8px; }
.test-verdict { margin: 0; font-weight: 600; font-size: 15px; }
.test-verdict.ok { color: var(--ok); }
.test-verdict.ko { color: var(--danger); }
.test-result .add-row { align-items: center; }
.test-result .add-row .sheet-note { flex: 1; }
.unknown-row {
  min-height: 58px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 8px 8px 8px 14px; display: flex; align-items: center; gap: 8px;
}
.unknown-row .tile-text { flex: 1; }
.empty-note { text-align: center; padding: 16px 0; }

/* ---------- Message éphémère ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 30;
  bottom: calc(20px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px);
  background: var(--chip-on); color: var(--chip-on-text); padding: 12px 16px; border-radius: 14px;
  font-size: 15px; box-shadow: var(--shadow);
}

@media (min-width: 560px) {
  .tile-toggle { aspect-ratio: auto; min-height: 150px; }
}
@media (prefers-reduced-motion: reduce) {
  .tile { transition: none; }
}
