/* Interface domotique privée.
 * Thème clair par défaut, thème sombre via [data-theme="dark"] sur <html>.
 * Toutes les couleurs sont définies en clair sur :root puis redéfinies dans le
 * bloc sombre : aucune couleur n'existe uniquement dans l'un des deux. */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --bg-accent: radial-gradient(1200px 600px at 50% -20%, #e8eeff 0%, transparent 70%);
  --surface: #ffffff;
  --surface-soft: #f7f8fa;
  --surface-strong: #eef0f4;
  --border: rgba(16, 22, 36, .10);
  --border-strong: rgba(16, 22, 36, .18);
  --text: #121723;
  --text-soft: #39414f;
  --muted: #68717f;
  --accent: #2f62f5;
  --accent-soft: rgba(47, 98, 245, .10);
  --ok: #0f9a63;
  --warn: #b5700a;
  --warn-soft: rgba(181, 112, 10, .10);
  --error: #cf3030;
  --error-soft: rgba(207, 48, 48, .08);
  --unlock-from: #13a06a;
  --unlock-to: #0b8154;
  --lock-from: #2b3550;
  --lock-to: #1b2236;
  --on-action: #ffffff;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(16, 22, 36, .06), 0 8px 24px rgba(16, 22, 36, .07);
  --shadow-lg: 0 20px 50px rgba(16, 22, 36, .16);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0e16;
  --bg-accent: radial-gradient(1200px 600px at 50% -20%, #18233f 0%, transparent 70%);
  --surface: #151a26;
  --surface-soft: #1a202e;
  --surface-strong: #222938;
  --border: rgba(255, 255, 255, .10);
  --border-strong: rgba(255, 255, 255, .20);
  --text: #eef1f7;
  --text-soft: #c3cad8;
  --muted: #8e98ab;
  --accent: #6d94ff;
  --accent-soft: rgba(109, 148, 255, .14);
  --ok: #35c98d;
  --warn: #ffb85c;
  --warn-soft: rgba(255, 184, 92, .14);
  --error: #ff7b7b;
  --error-soft: rgba(255, 123, 123, .14);
  --unlock-from: #15b377;
  --unlock-to: #0d8d5c;
  --lock-from: #3b4766;
  --lock-to: #262f47;
  --on-action: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* L'attribut `hidden` doit gagner contre nos propres `display:` : sans cette
   règle, un `display: grid/flex/block` d'auteur l'emporte sur la feuille de
   style du navigateur et l'élément reste visible malgré `el.hidden = true`. */
[hidden] { display: none !important; }
body {
  min-height: 100vh;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg) var(--bg-accent) no-repeat;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { letter-spacing: -.01em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .86em;
       background: var(--surface-strong); padding: .12em .42em; border-radius: 6px; }
.muted { color: var(--muted); }
.skip { position: absolute; left: -9999px; }
.skip:focus { left: 1rem; top: 1rem; background: var(--accent); color: #fff;
              padding: .5rem .9rem; border-radius: 10px; z-index: 60; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- barre supérieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .8rem;
  padding: calc(.65rem + env(safe-area-inset-top, 0px)) clamp(.9rem, 4vw, 2rem) .65rem;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar__brand { display: flex; align-items: center; gap: .55rem; margin-right: auto;
                 min-width: 0; }
.topbar__brand strong { display: block; font-size: .98rem; }
.topbar__brand small { color: var(--muted); font-size: .74rem; }
.topbar__dot { flex: none; width: 9px; height: 9px; border-radius: 50%;
               background: var(--muted); }
.topbar__dot[data-state="online"] { background: var(--ok);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--ok) 18%, transparent); }
.topbar__dot[data-state="offline"] { background: var(--error);
  box-shadow: 0 0 0 4px var(--error-soft); }

.burger {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  width: 42px; height: 42px; flex: none;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  cursor: pointer; box-shadow: var(--shadow);
}
.burger:hover { border-color: var(--border-strong); }
.burger svg { display: block; }

/* ---------- panneau latéral (menu burger) ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; display: none; }
.drawer[open] { display: block; }
.drawer__backdrop { position: absolute; inset: 0; background: rgba(8, 11, 18, .45);
                    border: 0; width: 100%; cursor: pointer; }
.drawer__panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(340px, 86vw);
  display: flex; flex-direction: column; gap: .35rem; overflow-y: auto;
  padding: calc(1rem + env(safe-area-inset-top, 0px)) 1rem
           calc(1.2rem + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: slide-in .22s ease;
}
@keyframes slide-in { from { transform: translateX(14px); opacity: .6; } }
.drawer__head { display: flex; align-items: center; justify-content: space-between;
                margin-bottom: .4rem; }
.drawer__head strong { font-size: 1.02rem; }
.drawer__close { background: none; border: 0; color: var(--muted); font-size: 1.5rem;
                 line-height: 1; cursor: pointer; padding: .2rem .4rem; }
.drawer__user { display: flex; align-items: center; gap: .7rem; padding: .7rem;
                border-radius: var(--radius-sm); background: var(--surface-soft);
                border: 1px solid var(--border); margin-bottom: .6rem; }
.drawer__avatar { display: grid; place-items: center; width: 38px; height: 38px; flex: none;
                  border-radius: 50%; background: var(--accent-soft); color: var(--accent);
                  font-weight: 700; }
.drawer__user div { min-width: 0; }
.drawer__user strong { display: block; font-size: .92rem; }
.drawer__user small { color: var(--muted); font-size: .76rem; }
.drawer__label { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em;
                 color: var(--muted); margin: .9rem .35rem .3rem; }
.drawer a.drawer__item, .drawer button.drawer__item {
  display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left;
  font: inherit; color: var(--text); cursor: pointer;
  padding: .7rem .75rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none;
}
.drawer__item:hover { background: var(--surface-soft); text-decoration: none;
                      border-color: var(--border); }
.drawer__item.is-active { background: var(--accent-soft); color: var(--accent);
                          font-weight: 600; }
.drawer__item svg { flex: none; opacity: .75; }
.drawer__item small { margin-left: auto; color: var(--muted); font-size: .76rem; }
.drawer__item--danger { color: var(--error); }
.drawer form { margin: 0; }
.drawer__foot { margin-top: auto; padding-top: 1rem; color: var(--muted);
                font-size: .74rem; display: grid; gap: .3rem; }

/* ---------- structure ---------- */
.shell { max-width: 880px; margin: 0 auto; padding: clamp(1rem, 3vw, 1.75rem)
         clamp(.9rem, 4vw, 2rem) 2.5rem; display: grid; gap: 1rem; }
.shell--wide { max-width: 1080px; }
.page-title { font-size: clamp(1.25rem, 4vw, 1.6rem); margin: 0; }
.stack { display: grid; gap: .8rem; }
.grid { display: grid; gap: 1rem; }
.grid--2 { grid-template-columns: 1fr; }
@media (min-width: 820px) { .grid--2 { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border);
        border-radius: var(--radius); padding: clamp(1rem, 3vw, 1.4rem);
        box-shadow: var(--shadow); }
.card h2 { margin: 0 0 .15rem; font-size: 1.02rem; }
.card__head { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
              justify-content: space-between; margin-bottom: .9rem; }
.footer { display: grid; gap: .25rem; max-width: 880px; margin: 0 auto;
          padding: 0 clamp(.9rem, 4vw, 2rem) 2.5rem; color: var(--muted);
          font-size: .76rem; }

/* ---------- accueil : état + deux actions ---------- */
.home { display: grid; gap: 1rem; }
.hero { display: grid; gap: .25rem; margin-bottom: .2rem; }
.hero h1 { margin: 0; font-size: clamp(1.4rem, 5vw, 1.9rem); }
.hero p { margin: 0; color: var(--muted); font-size: .9rem; }

/* ligne d'état compacte */
.statusline { display: flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.pill { display: inline-flex; align-items: center; gap: .35rem;
        padding: .34rem .7rem; border-radius: 999px; font-size: .8rem;
        border: 1px solid var(--border); background: var(--surface);
        color: var(--text-soft); }
.pill[data-state="online"] { color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.pill[data-state="offline"] { color: var(--error); border-color: var(--border-strong);
  background: var(--error-soft); }
.pill[data-state="unlocked"] { color: var(--warn); background: var(--warn-soft);
  border-color: color-mix(in srgb, var(--warn) 32%, transparent); }
.pill[data-state="open"] { color: var(--warn); background: var(--warn-soft); }
.pill[data-confirmed="0"] { border-style: dashed; }
.pill--warn { color: var(--warn); background: var(--warn-soft); }

.actions { display: grid; gap: .7rem; }
@media (min-width: 520px) { .actions { grid-template-columns: 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .55rem;
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 14px;
  padding: .8rem 1.1rem; min-height: 46px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  transition: transform .12s ease, filter .18s ease, opacity .18s ease;
}
.btn:hover:not(:disabled) { filter: brightness(.98); border-color: var(--border-strong); }
.btn:active:not(:disabled) { transform: scale(.985); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn--primary { background: var(--accent); border-color: transparent;
                color: var(--on-action); }
.btn--primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn--quiet { background: transparent; box-shadow: none; font-weight: 500;
              padding: .5rem .75rem; }
.btn--block { width: 100%; }
.btn--action { min-height: 76px; font-size: 1.08rem; letter-spacing: .02em;
               border-color: transparent; color: var(--on-action);
               flex-direction: column; gap: .2rem; }
.btn--action small { font-weight: 500; font-size: .74rem; opacity: .85; }
.btn--unlock { background: linear-gradient(145deg, var(--unlock-from), var(--unlock-to)); }
.btn--lock { background: linear-gradient(145deg, var(--lock-from), var(--lock-to)); }
.btn[aria-busy="true"] { cursor: progress; }
.btn__spin { width: 15px; height: 15px; border-radius: 50%;
             border: 2px solid currentColor; border-top-color: transparent;
             animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.feedback { padding: .75rem .9rem; border-radius: var(--radius-sm); font-size: .87rem;
            border: 1px solid var(--border); background: var(--surface-soft);
            color: var(--text-soft); }
.feedback--ok { border-color: color-mix(in srgb, var(--ok) 35%, transparent);
                background: color-mix(in srgb, var(--ok) 8%, var(--surface));
                color: var(--ok); }
.feedback--warn { border-color: color-mix(in srgb, var(--warn) 35%, transparent);
                  background: var(--warn-soft); color: var(--warn); }
.feedback--error { border-color: color-mix(in srgb, var(--error) 35%, transparent);
                   background: var(--error-soft); color: var(--error); }

.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .88rem;
         border: 1px solid var(--border); background: var(--surface-soft); }
.alert--error { border-color: color-mix(in srgb, var(--error) 35%, transparent);
                background: var(--error-soft); color: var(--error); }
.alert--warning { border-color: color-mix(in srgb, var(--warn) 35%, transparent);
                  background: var(--warn-soft); color: var(--warn); }
.alert--success { border-color: color-mix(in srgb, var(--ok) 35%, transparent);
                  background: color-mix(in srgb, var(--ok) 8%, var(--surface));
                  color: var(--ok); }

.note { margin: .6rem 0 0; font-size: .8rem; color: var(--muted); }
.note--error { color: var(--error); }

/* ---------- listes, tableaux, formulaires ---------- */
.dl { display: grid; grid-template-columns: 1fr; gap: .1rem .8rem; margin: 1rem 0 0; }
.dl dt { color: var(--muted); font-size: .77rem; }
.dl dd { margin: 0 0 .55rem; font-size: .89rem; }
@media (min-width: 560px) { .dl { grid-template-columns: minmax(150px, 38%) 1fr; } }
.checklist { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .4rem; }
.checklist li { font-size: .88rem; padding-left: 1.5rem; position: relative; }
.checklist li::before { position: absolute; left: 0; font-weight: 700; }
.checklist li.ok::before { content: "✓"; color: var(--ok); }
.checklist li.no::before { content: "✕"; color: var(--error); }

.events { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.events li { display: flex; flex-wrap: wrap; align-items: center; gap: .55rem;
             padding: .6rem .7rem; border-radius: var(--radius-sm);
             background: var(--surface-soft); border: 1px solid var(--border);
             font-size: .85rem; }
.events__time { color: var(--muted); min-width: 5rem; }
.events__method { font-weight: 600; }
.events__actor { color: var(--muted); }
.events li .badge { margin-left: auto; }

.badge { padding: .2rem .55rem; border-radius: 999px; font-size: .73rem;
         border: 1px solid var(--border); background: var(--surface-soft);
         color: var(--muted); }
.badge--unlock, .badge--accepted, .badge--success { color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 32%, transparent); }
.badge--failed, .badge--denied, .badge--alarm { color: var(--error);
  border-color: color-mix(in srgb, var(--error) 32%, transparent); }
.badge--throttled, .badge--busy { color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 32%, transparent); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .86rem; min-width: 520px; }
.table th, .table td { text-align: left; padding: .6rem .7rem;
                       border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; font-size: .74rem;
            text-transform: uppercase; letter-spacing: .05em; }
.table tbody tr:hover { background: var(--surface-soft); }

.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end;
           margin-bottom: 1rem; }
.field { display: grid; gap: .3rem; }
.field > span { font-size: .79rem; color: var(--muted); }
.field input, .field select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: .7rem .8rem; min-height: 46px; width: 100%;
}
.field--inline { min-width: 160px; }
.errorlist { list-style: none; margin: .3rem 0 0; padding: 0; color: var(--error);
             font-size: .8rem; display: grid; gap: .2rem; }
.helptext { font-size: .78rem; color: var(--muted); }
.helptext ul { margin: .3rem 0 0; padding-left: 1.1rem; }

/* ---------- connexion ---------- */
.auth { display: grid; place-items: center; min-height: 74vh; }
.auth__card { width: min(400px, 100%); text-align: center; }
.auth__card h1 { font-size: 1.28rem; margin: .7rem 0 .2rem; }
.auth__card form { margin-top: 1.2rem; text-align: left; }
.auth__logo { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto;
              border-radius: 17px; color: var(--accent); background: var(--accent-soft);
              border: 1px solid var(--border); }

/* ---------- modale de confirmation ---------- */
.modal { border: none; padding: 0; background: transparent; max-width: min(420px, 92vw); }
.modal::backdrop { background: rgba(8, 11, 18, .5); backdrop-filter: blur(3px); }
.modal__inner { background: var(--surface); border: 1px solid var(--border);
                border-radius: var(--radius); padding: 1.25rem; display: grid; gap: .7rem;
                box-shadow: var(--shadow-lg); color: var(--text); }
.modal__inner h2 { margin: 0; font-size: 1.05rem; }
.modal__actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: .3rem; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
