:root {
  --bg: #f2f4f9;
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --text: #1a2233;
  --muted: #667085;
  --border: #d8deea;
  --primary: #1a52c9;
  --primary-ink: #ffffff;
  --primary-soft: #e6eefc;
  --header: #17479f;
  --header-ink: #ffffff;
  --ok: #1f9d57;
  --ok-soft: #e4f6ec;
  --warn: #b86a00;
  --warn-soft: #fff1d9;
  --danger: #cf2f2f;
  --danger-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 14px rgba(16, 24, 40, 0.06);
  --radius: 14px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1524;
    --surface: #172036;
    --surface-2: #1c2742;
    --text: #e8edf8;
    --muted: #94a0b8;
    --border: #2b3756;
    --primary: #6c97ff;
    --primary-ink: #0b1220;
    --primary-soft: #1f2d52;
    --header: #101c3a;
    --ok: #4cc585;
    --ok-soft: #14301f;
    --warn: #f0a63a;
    --warn-soft: #3a2a0d;
    --danger: #ff7b7b;
    --danger-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
p + p { margin-top: 8px; }

/* ---------------------------------------------------------------- en-tête */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 16px) 10px calc(env(safe-area-inset-left) + 16px);
  background: var(--header);
  color: var(--header-ink);
}
.top .logo { width: 34px; height: 34px; border-radius: 8px; flex: none; }
.top .titles { flex: 1; min-width: 0; }
.top h1 { font-size: 17px; font-weight: 650; line-height: 1.2; }
.top .sub { font-size: 13px; opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .icon-btn { color: var(--header-ink); }

.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 22px;
  cursor: pointer;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.16); }

/* ---------------------------------------------------------------- mise en page */
.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 16px);
}
.center { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; text-align: center; }
.brand .logo { width: 76px; height: 76px; border-radius: 18px; box-shadow: var(--shadow); }
.brand h1 { font-size: 24px; line-height: 1.2; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card + .card, .card + section, section + .card { margin-top: 14px; }
.card h2 { font-size: 17px; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.steps { margin: 12px 0 0; padding-left: 0; list-style: none; counter-reset: step; display: grid; gap: 12px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start; }
.steps li::before {
  content: counter(step);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 650;
}

/* ---------------------------------------------------------------- formulaires */
label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
input[type='text'] {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
input[type='text']:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 18px;
  font: inherit;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}
.btn.primary { color: var(--primary-ink); background: var(--primary); }
.btn.danger { color: var(--danger); background: var(--danger-soft); }
.btn.block { display: flex; width: 100%; margin-top: 14px; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:active:not(:disabled) { filter: brightness(0.94); }

/* ---------------------------------------------------------------- notifications */
.status { display: flex; align-items: flex-start; gap: 10px; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--danger); }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.row .btn { flex: 1 1 auto; }

.banner { margin: 0 0 12px; padding: 10px 14px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }
.banner.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- alertes */
.section-title { font-size: 13px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 22px 4px 8px; }
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.alert {
  display: grid;
  grid-template-columns: 8px 1fr auto;
  gap: 12px;
  align-items: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px 12px 0;
  overflow: hidden;
}
.alert::before { content: ''; align-self: stretch; background: var(--primary); margin: -12px 0; }
.alert.sos { background: var(--danger-soft); border-color: var(--danger); }
.alert.sos::before { background: var(--danger); }
.alert.final::before { background: var(--warn); }
.alert.test::before, .alert.info::before { background: var(--muted); }
.alert .kind { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--primary); }
.alert.sos .kind { color: var(--danger); }
.alert.final .kind { color: var(--warn); }
.alert.test .kind, .alert.info .kind { color: var(--muted); }
.alert .title { font-weight: 650; font-size: 17px; overflow-wrap: anywhere; }
.alert .body { color: var(--muted); font-size: 15px; overflow-wrap: anywhere; }
.alert time { font-size: 13px; color: var(--muted); white-space: nowrap; padding-top: 2px; }
.alert.fresh { animation: pulse 1.6s ease-out 1; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(26, 82, 201, 0.5); } 100% { box-shadow: 0 0 0 14px rgba(26, 82, 201, 0); } }
.empty { text-align: center; padding: 28px 12px; }
.alert .btn.ack { margin-top: 10px; min-height: 40px; padding: 0 16px; }
.alert .state { margin-top: 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.alert .state.ok { color: var(--ok); }
.alert .state.wait { color: var(--warn); }
.alert.over { opacity: 0.66; }
.alert.sos.over { background: var(--surface); border-color: var(--border); }
.alert.over::before { background: var(--muted); }

/* ---------------------------------------------------------------- feuille de réglages */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: rgba(8, 14, 30, 0.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%;
  max-width: 640px;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(env(safe-area-inset-bottom) + 18px);
  display: grid;
  gap: 10px;
}
.sheet h2 { font-size: 18px; }
.sheet .info { font-size: 14px; color: var(--muted); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: min(92vw, 520px);
  padding: 12px 18px;
  border-radius: 12px;
  background: #1a2233;
  color: #fff;
  font-size: 15px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.3);
}
.toast.err { background: var(--danger); }
.noscript { padding: 24px; text-align: center; }
