/* Maison — feuille de styles unique. Aucun style en ligne (CSP stricte). */
:root {
  --bg: #f4f2ed;
  --surface: #ffffff;
  --surface-2: #ebe8e1;
  --text: #182033;
  --muted: #5d6679;
  --border: rgba(24, 32, 51, 0.10);
  --accent: #2557e8;
  --accent-ink: #ffffff;
  --accent-soft: rgba(37, 87, 232, 0.10);
  --on: #e8960c;
  --on-soft: rgba(232, 150, 12, 0.14);
  --danger: #b4341a;
  --ok: #1d7a43;
  --shadow: 0 1px 2px rgba(24, 32, 51, 0.06), 0 6px 20px rgba(24, 32, 51, 0.06);
  --radius: 18px;
  --tabbar: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1222;
    --surface: #141d33;
    --surface-2: #1d2843;
    --text: #edf0f7;
    --muted: #9aa4b9;
    --border: rgba(255, 255, 255, 0.08);
    --accent: #6b93ff;
    --accent-ink: #0b1222;
    --accent-soft: rgba(107, 147, 255, 0.16);
    --on: #ffb43c;
    --on-soft: rgba(255, 180, 60, 0.16);
    --danger: #ff8a6b;
    --ok: #5fd08f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  display: flex; flex-direction: column; height: 100dvh; overflow: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); margin: 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-end { display: flex; justify-content: flex-end; gap: 10px; }

/* Boutons et champs */
.btn {
  min-height: 48px; padding: 0 18px; border-radius: 14px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-weight: 600;
}
.btn:disabled { opacity: 0.55; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; padding: 0 14px; font-size: 0.9rem; border-radius: 12px; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 10px 4px; min-height: 44px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.92rem; }
input:not([type=range]):not([type=color]) {
  min-height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 400; font-size: 17px;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Vues */
.view { flex: 1; min-height: 0; overflow-y: auto; }
.view-center { display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 20px 24px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.login { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.login-logo { font-size: 44px; }
.login h1 { font-size: 2rem; }
.login > p { margin: -8px 0 6px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.9rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Bannière « la maison ne répond pas » */
.banner {
  flex: none; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(8px + var(--safe-top)) 16px 8px;
  background: var(--danger); color: #fff; font-weight: 600; font-size: 0.95rem;
}
.banner .link { color: #fff; text-decoration: underline; min-height: 36px; }

/* Structure de l'appli */
.app { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 18px 10px;
}
.banner:not([hidden]) ~ .app .topbar { padding-top: 14px; }
.topbar h1 { font-size: 1.75rem; letter-spacing: -0.01em; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 1.05rem;
}
.panel { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 4px 16px calc(var(--tabbar) + var(--safe-bottom) + 20px); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--tabbar) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font-size: 0.75rem; font-weight: 600;
}
.tabbar button span { font-size: 1.35rem; filter: grayscale(1); opacity: 0.7; }
.tabbar button[aria-current="page"] { color: var(--accent); }
.tabbar button[aria-current="page"] span { filter: none; opacity: 1; }

/* Parler */
#panel-parler { display: flex; flex-direction: column; padding-bottom: 0; overflow: hidden; }
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 6px 2px 12px; }
.chat-empty { margin: auto 0; text-align: center; }
.chips { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.chip {
  min-height: 44px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 0.95rem;
}
.bubble {
  max-width: 85%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word;
}
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }
.bubble.bot { align-self: flex-start; background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.bubble.bot.error { color: var(--danger); }
.bubble.typing { color: var(--muted); }
.bubble.typing::after { content: "…"; animation: blink 1.2s steps(3) infinite; }
@keyframes blink { 50% { opacity: 0.3; } }
.done-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.done { font-size: 0.8rem; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.done.ok { color: var(--ok); }
.done.ko { color: var(--danger); }
.ask-card { margin-top: 10px; padding: 12px; border-radius: 14px; background: var(--surface-2); display: flex; flex-direction: column; gap: 10px; white-space: normal; }
.ask-card ul { margin: 0; padding-left: 18px; }
.ask-card .row-end { justify-content: flex-start; }

.composer {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 10px 0 calc(var(--tabbar) + var(--safe-bottom) + 12px);
}
.mic {
  width: 84px; height: 84px; border-radius: 50%; border: 0;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; box-shadow: 0 8px 24px var(--accent-soft);
  transition: transform 0.15s ease;
}
.mic svg { width: 36px; height: 36px; fill: currentColor; }
.mic:active { transform: scale(0.96); }
.mic.listening { background: var(--danger); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
.mic.working { opacity: 0.6; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(180, 52, 26, 0.45); } 50% { box-shadow: 0 0 0 16px rgba(180, 52, 26, 0); } }
.mic-status { margin: 0; min-height: 1.3em; text-align: center; }
.talk-form { display: flex; gap: 8px; width: 100%; }
.talk-form input { flex: 1; min-width: 0; }

/* Scénarios */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding-top: 6px; }
.tile {
  position: relative; min-height: 132px; padding: 16px; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; transition: transform 0.12s ease;
}
.tile:active { transform: scale(0.98); }
.tile-icon { font-size: 2rem; line-height: 1; }
.tile-name { font-weight: 700; font-size: 1.05rem; }
.tile-desc { color: var(--muted); font-size: 0.85rem; }
.tile.busy { opacity: 0.6; }
.tile.ok { border-color: var(--ok); }
.tile .lock { position: absolute; top: 12px; right: 12px; font-size: 0.85rem; }

/* Appareils */
.coins { display: flex; flex-direction: column; gap: 22px; padding-top: 6px; }
.coin h2 { font-size: 1rem; margin: 0 4px 8px; display: flex; gap: 8px; align-items: center; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; }
.device + .device { border-top: 1px solid var(--border); }
.device-row { display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 12px 8px 14px; }
.device-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; background: none; border: 0; padding: 0; text-align: left; min-height: 48px; }
.device-main:disabled { cursor: default; }
.dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border); }
.device.on .dot { background: var(--on); border-color: transparent; box-shadow: 0 0 0 4px var(--on-soft); }
.device-text { min-width: 0; display: flex; flex-direction: column; }
.device-label { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-sub { font-size: 0.85rem; color: var(--muted); }
.device.unavailable .device-label { color: var(--muted); }
.chevron { color: var(--muted); font-size: 0.85rem; margin-left: auto; transition: transform 0.15s ease; }
.device.open .chevron { transform: rotate(90deg); }

.switch {
  flex: none; position: relative; width: 58px; height: 48px; border: 0; background: none; padding: 0;
}
.switch::before {
  content: ""; position: absolute; left: 2px; top: 9px; width: 54px; height: 30px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border); transition: background 0.2s ease;
}
.switch::after {
  content: ""; position: absolute; left: 5px; top: 12px; width: 24px; height: 24px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.2s ease;
}
.switch[aria-checked="true"]::before { background: var(--on); border-color: transparent; }
.switch[aria-checked="true"]::after { transform: translateX(24px); }
.switch[aria-busy="true"] { opacity: 0.6; }
.switch:disabled { opacity: 0.4; }

.light-controls { padding: 4px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row span { min-width: 3.2em; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
input[type=range] { flex: 1; height: 44px; accent-color: var(--on); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--border); padding: 0;
}
.swatch.picked { border-color: var(--text); }
.swatch-label { font-size: 0.8rem; color: var(--muted); margin-bottom: -6px; }
.custom-color { position: relative; width: 44px; height: 44px; border-radius: 50%; overflow: hidden; border: 2px dashed var(--border); display: grid; place-items: center; font-size: 1.1rem; }
.custom-color input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.empty { text-align: center; padding: 40px 12px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* Feuilles et fenêtres */
dialog { border: 0; padding: 0; color: var(--text); background: var(--surface); }
dialog::backdrop { background: rgba(5, 10, 20, 0.45); }
.modal { width: min(92vw, 400px); border-radius: 20px; padding: 22px; }
.modal h2 { font-size: 1.2rem; }
.modal p { margin: 0; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92dvh; margin: auto auto 0; border-radius: 22px 22px 0 0;
  padding: 0 0 var(--safe-bottom);
}
.sheet-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 8px; background: var(--surface); z-index: 1; }
.sheet-body { padding: 4px 18px 24px; display: flex; flex-direction: column; gap: 22px; }
.sheet-body h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }
.list { background: var(--bg); border-radius: 14px; overflow: hidden; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; min-height: 56px; }
.list-item + .list-item { border-top: 1px solid var(--border); }
.list-item > div { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-item .small { color: var(--muted); }
.tag { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.journal { font-size: 0.8rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.journal div { padding: 6px 8px; background: var(--bg); border-radius: 8px; }
.alert { padding: 10px 12px; border-radius: 12px; background: var(--on-soft); }

/* Message court */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-bottom) + 14px); transform: translateX(-50%);
  z-index: 40; width: max-content; max-width: min(92vw, 460px); padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 600; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
}
.toast.bad { background: var(--danger); color: #fff; }

@media (min-width: 720px) {
  .panel, .topbar { max-width: 720px; width: 100%; margin: 0 auto; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.sheet-body section > .btn, .sheet-body section > .journal { margin-top: 10px; }
body.down .coins, body.down .tiles { opacity: 0.55; }
