:root {
  --brand: #0055a4;
  --brand-ink: #003a72;
  --bg: #f3f5f8;
  --surface: #ffffff;
  --ink: #14202e;
  --muted: #5f6b7a;
  --line: #e1e6ec;
  --armed: #0055a4;
  --armed-bg: #e6eef8;
  --off: #5f6b7a;
  --off-bg: #eceff3;
  --alarm: #c8102e;
  --alarm-bg: #fde8eb;
  --alarm-solid: #c8102e;
  --warn: #a15c00;
  --warn-bg: #fff2df;
  --ok: #1f7a3d;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 32, 46, .06), 0 4px 16px rgba(20, 32, 46, .06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1520;
    --surface: #16212f;
    --ink: #e8edf3;
    --muted: #96a3b4;
    --line: #253447;
    --armed: #6fa8e8;
    --armed-bg: #13294a;
    --off: #a3afbe;
    --off-bg: #1f2b3a;
    --alarm: #ff5a6e;
    --alarm-bg: #3a1219;
    --alarm-solid: #b3102a;
    --warn: #f2b25b;
    --warn-bg: #362508;
    --ok: #5cc982;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 560px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.pad { padding: 16px; }
[hidden] { display: none !important; }

/* ---------- barre du haut ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: var(--brand); color: #fff;
}
.brand { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; min-width: 0; }
.brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-mark {
  width: 22px; height: 26px; flex: none;
  background: #fff;
  clip-path: path("M11 0 L22 4 V12 C22 19 17 24 11 26 C5 24 0 19 0 12 V4 Z");
}
.icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 12px;
  background: transparent; color: inherit; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.15); }
.icon-btn svg, .ico { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- éléments communs ---------- */
h1 { font-size: 24px; line-height: 1.2; margin: 8px 0 4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 24px 4px 8px; font-weight: 650; }
p.lead { color: var(--muted); margin: 0 0 20px; }

.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line); overflow: hidden;
}
.card + .card { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 20px; border-radius: 12px; border: 0;
  font: inherit; font-weight: 650; cursor: pointer; text-decoration: none;
  background: var(--brand); color: #fff; width: 100%;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--off-bg); color: var(--ink); }
.btn.danger { background: var(--alarm-solid); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; width: auto; }
.btn + .btn { margin-top: 10px; }

label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
input[type=email], input[type=password], input[type=text] {
  width: 100%; min-height: 48px; padding: 0 14px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
input:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, a:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }
.error { color: var(--alarm); font-size: 14px; margin: 0 0 12px; }

/* ---------- connexion ---------- */
.auth { padding-top: 8vh; }
.auth-logo {
  width: 64px; height: 74px; margin: 0 0 20px; background: var(--brand);
  clip-path: path("M32 0 L64 11 V34 C64 54 50 68 32 74 C14 68 0 54 0 34 V11 Z");
  display: grid; place-items: center;
}
.auth-logo::after { content: ""; width: 14px; height: 14px; border-radius: 50%; background: #fff; margin-top: -6px; }

/* ---------- bandeaux ---------- */
.banner {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px; border-radius: var(--radius); margin-bottom: 12px;
  background: var(--warn-bg); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}
.banner .ico { color: var(--warn); flex: none; margin-top: 1px; }
.banner strong { display: block; }
.banner p { margin: 2px 0 10px; font-size: 14px; color: var(--muted); }
.banner.info { background: var(--armed-bg); border-color: color-mix(in srgb, var(--armed) 30%, transparent); }
.banner.info .ico { color: var(--armed); }

/* ---------- carte de site ---------- */
.site { display: block; color: inherit; text-decoration: none; }
.state {
  display: flex; align-items: center; gap: 14px; padding: 18px;
  background: var(--off-bg); color: var(--off);
}
.state .state-ico { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: color-mix(in srgb, currentColor 14%, transparent); flex: none; }
.state .state-ico .ico { width: 26px; height: 26px; }
.state .state-txt { min-width: 0; }
.state .site-name { font-size: 14px; font-weight: 600; color: var(--ink); opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.state .state-label { font-size: 22px; font-weight: 750; line-height: 1.15; }
.state.armed { background: var(--armed-bg); color: var(--armed); }
.state.alarm { background: var(--alarm-solid); color: #fff; }
.state.alarm .site-name { color: #fff; opacity: .9; }
.state.alarm .state-ico { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); background: rgba(255,255,255,.3); } }
@media (prefers-reduced-motion: reduce) { .state.alarm .state-ico { animation: none; } }

.meta { padding: 12px 18px; display: grid; gap: 6px; font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); }
.meta-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
.meta-row span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on { background: var(--ok); }
.dot.lost { background: var(--alarm); }
.meta .lost-txt { color: var(--alarm); font-weight: 600; }

/* ---------- détail d'un site ---------- */
.actions { padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.tabs { display: flex; gap: 6px; background: var(--off-bg); padding: 4px; border-radius: 12px; margin: 20px 0 12px; }
.tabs button {
  flex: 1; min-height: 38px; border: 0; border-radius: 9px; background: transparent;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.tabs button[aria-selected=true] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.day { font-size: 13px; font-weight: 650; color: var(--muted); margin: 18px 4px 8px; text-transform: capitalize; }
.ev { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.ev:last-child { border-bottom: 0; }
.ev .ev-ico { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--off-bg); color: var(--off); }
.ev .ev-ico .ico { width: 18px; height: 18px; }
.ev.alarme .ev-ico, .ev.autoprotection .ev-ico { background: var(--alarm-bg); color: var(--alarm); }
.ev.defaut .ev-ico { background: var(--warn-bg); color: var(--warn); }
.ev.mes_mhs .ev-ico { background: var(--armed-bg); color: var(--armed); }
.ev-body { flex: 1; min-width: 0; }
.ev-desc { font-weight: 600; overflow-wrap: anywhere; }
.ev.alarme .ev-desc { color: var(--alarm); }
.ev-time { font-size: 13px; color: var(--muted); }
.ev-ack { font-size: 12px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.more { margin-top: 12px; }

/* ---------- réglages ---------- */
.row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .row-txt { flex: 1; min-width: 0; }
.row .row-sub { font-size: 13px; color: var(--muted); }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 30px; background: var(--line); transition: background .2s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + span { background: var(--brand); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 2px; }

ol.steps { margin: 8px 0 0; padding-left: 20px; font-size: 14px; color: var(--muted); }
ol.steps li { margin-bottom: 4px; }
.footer-note { text-align: center; font-size: 13px; color: var(--muted); margin-top: 28px; }
.footer-note a { color: inherit; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 50;
}

.skeleton { height: 150px; border-radius: var(--radius); background: linear-gradient(90deg, var(--off-bg), var(--surface), var(--off-bg)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }
