/* Budd7 — page de connexion (version en ligne).
   Direction artistique (SPEC) : sombre #121214 + grain, une seule lumière blanche douce,
   carte en verre (Liquid Glass), Geist / Geist Mono, accent bleu #2259EC, pilules à bord fin.
   Sombre par défaut, comme l'app ; clair (crème #F2F0ED, traits fins, angles plus nets) si
   l'utilisateur l'a choisi dans Budd7 (login.js lit k13.theme). Aucun style en ligne (CSP stricte). */

:root {
  --bg: #121214; --surface: #18181b; --surface-2: #1f1f22; --line: #2d2d2f; --line-strong: #3d3d41;
  --ink: #ededed; --ink-2: #a1a1a7; --ink-3: #8e8e94;
  --accent: #2259ec; --accent-hi: #3a6cf0; --accent-text: #7b9bff; --accent-soft: rgba(34, 89, 236, 0.16);
  --danger: #ff8a4c; --danger-soft: rgba(242, 90, 7, 0.12); --danger-line: rgba(242, 90, 7, 0.35);
  --glass: rgba(28, 28, 31, 0.62); --glass-edge: rgba(255, 255, 255, 0.14); --glass-ring: rgba(255, 255, 255, 0.07);
  --glass-shadow: 0 2px 6px -2px rgba(0, 0, 0, 0.5), 0 30px 70px -24px rgba(0, 0, 0, 0.85);
  --field: rgba(118, 118, 128, 0.16); --field-focus: rgba(118, 118, 128, 0.22);
  --light: rgba(255, 255, 255, 0.075); --grain: 0.045;
  --r: 14px; --r-field: 10px; --r-card: 26px;
  --font: "Geist", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, Roboto, sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  color-scheme: dark;
}
:root[data-theme="light"] {
    --bg: #f2f0ed; --surface: #faf9f7; --surface-2: #ffffff; --line: rgba(20, 16, 12, 0.13); --line-strong: rgba(20, 16, 12, 0.28);
    --ink: #141312; --ink-2: #4a4744; --ink-3: #625e5a;
    --accent-text: #2259ec; --accent-soft: rgba(34, 89, 236, 0.10);
    --danger: #b03a06; --danger-soft: rgba(194, 65, 12, 0.08); --danger-line: rgba(194, 65, 12, 0.30);
    --glass: rgba(250, 249, 247, 0.72); --glass-edge: rgba(255, 255, 255, 0.95); --glass-ring: rgba(20, 16, 12, 0.09);
    --glass-shadow: 0 1px 2px rgba(40, 30, 20, 0.06), 0 24px 60px -24px rgba(40, 30, 20, 0.30);
    --field: rgba(20, 16, 12, 0.045); --field-focus: rgba(20, 16, 12, 0.06);
    --light: transparent; --grain: 0;
    --r: 8px; --r-field: 6px; --r-card: 14px;
    color-scheme: light;
  }
@media (prefers-color-scheme: light) {
  :root[data-theme="auto"] {
    --bg: #f2f0ed; --surface: #faf9f7; --surface-2: #ffffff; --line: rgba(20, 16, 12, 0.13); --line-strong: rgba(20, 16, 12, 0.28);
    --ink: #141312; --ink-2: #4a4744; --ink-3: #625e5a;
    --accent-text: #2259ec; --accent-soft: rgba(34, 89, 236, 0.10);
    --danger: #b03a06; --danger-soft: rgba(194, 65, 12, 0.08); --danger-line: rgba(194, 65, 12, 0.30);
    --glass: rgba(250, 249, 247, 0.72); --glass-edge: rgba(255, 255, 255, 0.95); --glass-ring: rgba(20, 16, 12, 0.09);
    --glass-shadow: 0 1px 2px rgba(40, 30, 20, 0.06), 0 24px 60px -24px rgba(40, 30, 20, 0.30);
    --field: rgba(20, 16, 12, 0.045); --field-focus: rgba(20, 16, 12, 0.06);
    --light: transparent; --grain: 0;
    --r: 8px; --r-field: 6px; --r-card: 14px;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body {
  font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  min-height: 100vh; min-height: 100dvh; display: flex; justify-content: center;
  padding: max(28px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
/* Grain (sombre) */
body::after {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 50; opacity: var(--grain);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1.4 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
/* La seule lumière : un halo blanc très doux au-dessus de la carte */
.light {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(60% 46% at 50% 4%, var(--light), transparent 70%);
}

.stage { position: relative; z-index: 1; width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 22px; margin: auto 0; }

/* ---------- Marque ---------- */
.brand { text-align: center; padding-top: 6px; }
.logo { display: block; width: 148px; height: auto; margin: 0 auto; overflow: visible; color: var(--ink); }
.logo .letters { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.logo .plane { color: var(--accent); transform-box: fill-box; transform-origin: 30% 60%; }
.logo .plane .wing { fill: currentColor; stroke: currentColor; stroke-width: 1.2; stroke-linejoin: round; }
.logo .plane .body { fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; }
.tag { margin: 12px 0 0; font: 500 11px/1 var(--mono); letter-spacing: 0.16em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- Carte en verre ---------- */
.card {
  position: relative; border-radius: var(--r-card); padding: 26px 22px 22px;
  background: var(--glass); box-shadow: var(--glass-shadow), inset 0 1px 0 var(--glass-edge), inset 0 0 0 1px var(--glass-ring);
}
@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .card { -webkit-backdrop-filter: blur(24px) saturate(170%); backdrop-filter: blur(24px) saturate(170%); }
}
@media (prefers-reduced-transparency: reduce) { .card { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; } }
/* Clair : trait fin, sans arête lumineuse */
:root[data-theme="light"] .card { box-shadow: var(--glass-shadow), inset 0 0 0 1px var(--glass-ring); }
@media (prefers-color-scheme: light) { :root[data-theme="auto"] .card { box-shadow: var(--glass-shadow), inset 0 0 0 1px var(--glass-ring); } }

.kicker { margin: 0 0 8px; font: 600 26px/1.1 var(--font); letter-spacing: -0.035em; }
.lead { margin: 0 0 20px; color: var(--ink-2); }

/* ---------- Champs ---------- */
.field { margin: 0 0 14px; }
.field > label, legend {
  display: block; margin: 0 0 7px; padding: 0;
  font: 500 10.5px/1.2 var(--mono); letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3);
}
input:not([type="checkbox"]), select {
  width: 100%; min-height: 46px; padding: 11px 13px; border-radius: var(--r-field);
  font: 16px/1.3 var(--font); color: var(--ink); background: var(--field);
  border: 1px solid transparent; outline: none; -webkit-appearance: none; appearance: none;
  transition: border-color 150ms var(--ease), background-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
input::placeholder { color: var(--ink-3); opacity: 0.75; }
/* 16px minimum: iOS Safari zooms into any focused field under 16px. */
input[type="email"], #imap_host, #smtp_host, #username, #imap_port, #smtp_port { font-family: var(--mono); font-size: 16px; letter-spacing: -0.02em; }
input:not([type="checkbox"]):hover, select:hover { border-color: var(--line); }
input:not([type="checkbox"]):focus, select:focus { background: var(--field-focus); border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid="true"] { border-color: var(--danger-line); }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e94' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6.5 9.5 5.5 5.5 5.5-5.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 40px;
}

.pw { position: relative; }
.pw input { padding-right: 92px; }
.pw-toggle {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%); min-height: 34px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--ink-2);
  font: 500 12px/1 var(--font); cursor: pointer; transition: border-color 150ms var(--ease), color 150ms var(--ease);
}
.pw-toggle:hover { border-color: var(--line-strong); color: var(--ink); }

.hint { margin: 8px 0 0; font-size: 13px; color: var(--ink-2); }
.hint strong { color: var(--ink); font-weight: 600; }

/* Interrupteur « Rester connecté » (façon iOS) */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin: 18px 0 4px; cursor: pointer; }
.switch-row .txt { display: flex; flex-direction: column; gap: 2px; }
.switch-row .txt strong { font-weight: 550; }
.switch-row .txt span { font-size: 13px; color: var(--ink-3); }
.switch { position: relative; flex: none; width: 46px; height: 28px; }
.switch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--field); box-shadow: inset 0 0 0 1px var(--line); transition: background-color 180ms var(--ease); }
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); transition: transform 220ms cubic-bezier(0.3, 1.3, 0.5, 1);
}
.switch input:checked + .track { background: var(--accent); box-shadow: none; }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Réglages avancés */
.advanced { margin: 16px 0 0; border-top: 1px solid var(--line); }
.advanced summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; justify-content: space-between;
  min-height: 46px; color: var(--ink-2); font-weight: 500; border-radius: 6px;
}
.advanced summary::-webkit-details-marker { display: none; }
.advanced summary::after {
  content: ""; width: 18px; height: 18px; flex: none; transition: transform 200ms var(--ease);
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e94' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6.5 9.5 5.5 5.5 5.5-5.5'/%3E%3C/svg%3E") center / 18px no-repeat;
}
.advanced[open] summary::after { transform: rotate(180deg); }
.advanced summary:hover { color: var(--ink); }
.advanced > .hint { margin: 0 0 14px; }
.advanced.flag summary { color: var(--accent-text); }
fieldset { border: 0; margin: 0 0 6px; padding: 0; }
legend { margin-bottom: 10px; color: var(--ink-2); }
.row { display: flex; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.row .port { width: 96px; flex: none; }
.check { display: flex; align-items: center; gap: 10px; margin: -4px 0 14px; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* Code TOTP */
input.code {
  text-align: center; font: 500 30px/1 var(--mono); letter-spacing: 0.42em; padding-left: calc(13px + 0.42em);
  min-height: 64px;
}

/* ---------- Messages ---------- */
.msg { margin: 16px 0 0; font-size: 14px; line-height: 1.45; }
.msg:empty { display: none; }
.msg.err { padding: 11px 13px; border-radius: var(--r-field); color: var(--ink); background: var(--danger-soft); box-shadow: inset 0 0 0 1px var(--danger-line); }
.msg.err strong { display: block; color: var(--danger); font-weight: 600; margin-bottom: 2px; }
.msg.info { color: var(--ink-2); }

/* ---------- Boutons ---------- */
button.primary {
  position: relative; width: 100%; min-height: 50px; margin-top: 20px; border: 0; border-radius: 999px;
  background: var(--accent); color: #fff; font: 600 16px/1 var(--font); letter-spacing: -0.01em; cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), 0 8px 24px -10px rgba(34, 89, 236, 0.7);
  transition: background-color 150ms var(--ease), transform 150ms var(--ease), opacity 150ms var(--ease);
}
button.primary:hover { background: var(--accent-hi); }
button.primary:active { transform: scale(0.985); }
button.primary[aria-busy="true"] { cursor: progress; }
button.primary[aria-busy="true"] .label { opacity: 0; }
button.primary .spinner {
  position: absolute; left: 50%; top: 50%; width: 20px; height: 20px; margin: -10px 0 0 -10px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff; opacity: 0;
}
button.primary[aria-busy="true"] .spinner { opacity: 1; animation: spin 0.8s linear infinite; }
button.link {
  display: block; margin: 12px auto 0; min-height: 44px; padding: 0 14px; border: 0; background: none;
  color: var(--accent-text); font: 500 14px/1 var(--font); cursor: pointer; border-radius: 999px;
}
button.link:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Passkey ---------- */
.passkey-box { margin: 0 0 6px; }
.passkey-box[hidden] { display: none; }
button.passkey {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; min-height: 52px;
  border: 0; border-radius: 999px; cursor: pointer; color: var(--ink); font: 600 16px/1 var(--font); letter-spacing: -0.01em;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.13), rgba(255, 255, 255, 0.05));
  box-shadow: inset 0 0 0 1px var(--line-strong), inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 10px 28px -16px rgba(0, 0, 0, 0.8);
  transition: background-color 150ms var(--ease), transform 150ms var(--ease), box-shadow 150ms var(--ease);
}
:root[data-theme="light"] button.passkey { background: rgba(255, 255, 255, 0.75); box-shadow: inset 0 0 0 1px var(--line-strong), 0 8px 22px -14px rgba(60, 40, 20, 0.45); }
@media (prefers-color-scheme: light) { :root[data-theme="auto"] button.passkey { background: rgba(255, 255, 255, 0.75); } }
button.passkey:hover { box-shadow: inset 0 0 0 1px var(--accent), inset 0 1px 0 rgba(255, 255, 255, 0.16); }
button.passkey:active { transform: scale(0.985); }
button.passkey .key {
  width: 20px; height: 20px; flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237b9bff' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='8' cy='12' r='4.2'/%3E%3Cpath d='M12.2 12H21M17.5 12v3M20 12v2.2'/%3E%3C/svg%3E") center / 20px no-repeat;
}
button.passkey .spinner {
  position: absolute; right: 18px; top: 50%; width: 18px; height: 18px; margin-top: -9px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent); opacity: 0;
}
button.passkey[aria-busy="true"] { cursor: progress; }
button.passkey[aria-busy="true"] .spinner { opacity: 1; animation: spin 0.8s linear infinite; }
.hint.center { text-align: center; color: var(--ink-3); font-size: 12.5px; }
.or { display: flex; align-items: center; gap: 12px; margin: 18px 0 16px; font: 500 10.5px/1.2 var(--mono); letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--ink-3); }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.or span { text-align: center; }

/* ---------- Téléphone connecté par QR code ---------- */
.step-link .kicker { text-align: center; }
.link-wait { text-align: center; }
.link-wait .lead { margin-bottom: 18px; }
.qr-hint { margin-top: 14px; }
.link-account { margin: -6px 0 16px; font: 600 17px/1.3 var(--mono); color: var(--ink); word-break: break-all; }
.link-account[hidden], #link-confirm[hidden] { display: none; }
#link-confirm { margin-bottom: 6px; }
.match { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 4px 0 14px; }
.match[hidden] { display: none; }
.match-lbl { font: 500 10.5px/1 var(--mono); letter-spacing: 0.14em; text-transform: uppercase; color: var(--ink-3); }
.match-code { font: 600 46px/1 var(--mono); letter-spacing: 0.22em; padding-left: 0.22em; color: var(--ink); font-variant-numeric: tabular-nums; }
.pulse { display: flex; justify-content: center; gap: 6px; margin: 18px 0 4px; }
.pulse span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0.35; }
.step-link.over .pulse, .step-link.confirm .pulse { display: none; }
@media (prefers-reduced-motion: no-preference) {
  .pulse span { animation: blink 1.2s var(--ease) infinite; }
  .pulse span:nth-child(2) { animation-delay: 0.15s; }
  .pulse span:nth-child(3) { animation-delay: 0.3s; }
}
@keyframes blink { 50% { opacity: 1; } }

/* ---------- Invitation à un compte préparé ---------- */
.step-invite .kicker { text-align: center; }
#invite-go[hidden], #invite-boxes[hidden], #invite-hint[hidden] { display: none; }
#invite-go { margin: 6px 0 10px; }
.step-invite .plane { display: block; width: 44px; height: 44px; margin: 0 auto 14px; color: var(--accent); }

/* ---------- Pied ---------- */
.foot { text-align: center; color: var(--ink-3); font-size: 12.5px; padding: 0 8px; }
.foot p { margin: 0 0 8px; }
.foot p:first-child { display: inline-flex; align-items: center; gap: 7px; font: 500 11px/1 var(--mono); letter-spacing: 0.08em; color: var(--ink-2); }
.lock {
  width: 12px; height: 12px; flex: none;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e94' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='5' y='10.5' width='14' height='9.5' rx='2'/%3E%3Cpath d='M8.5 10.5V8a3.5 3.5 0 0 1 7 0v2.5'/%3E%3C/svg%3E") center / 12px no-repeat;
}

/* ---------- Étapes ---------- */
.step { display: none; }
body[data-step="login"] .step-login, body[data-step="totp"] .step-totp, body[data-step="link"] .step-link,
body[data-step="invite"] .step-invite { display: block; }
body:not([data-step="login"]):not([data-step="totp"]):not([data-step="link"]):not([data-step="invite"]) .step-login { display: block; }

/* ---------- Animations calmes ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
@keyframes takeoff {
  0% { transform: none; opacity: 1; }
  20% { transform: translate(-2px, 2px) rotate(2deg); }
  100% { transform: translate(160px, -120px) rotate(-12deg); opacity: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .brand { animation: rise 420ms var(--ease) both; }
  .card { animation: rise 420ms var(--ease) 60ms both; }
  .foot { animation: rise 420ms var(--ease) 120ms both; }
  .step { animation: rise 240ms var(--ease) both; }
  .card.shake { animation: shake 320ms var(--ease); }
  body.done .logo .plane { animation: takeoff 560ms cubic-bezier(0.55, 0, 0.75, 0.4) both; }
  body.done .logo .letters { transition: opacity 300ms var(--ease) 140ms; opacity: 0.35; }
}

@media (max-width: 380px) {
  .card { padding: 22px 16px 18px; }
  .row .port { width: 84px; }
}
@media (min-height: 760px) { .stage { gap: 28px; } }

/* ---------- Téléphone (audit 25/11) ---------- */
/* Pas d'attente du double-tap (zoom) sur ce qui se touche. */
button, a, label, summary, select, input { touch-action: manipulation; }
/* Titres et adresses très longues : passent à la ligne au lieu de déborder. */
.kicker, .lead, .hint, .msg { overflow-wrap: anywhere; }
/* Bouton Afficher dans le champ mot de passe : zone de toucher de 44 px sans changer le dessin. */
.pw-toggle::after { content: ""; position: absolute; inset: -6px -4px; }
.check { min-height: 44px; margin-top: -8px; }
@media (max-width: 380px) {
  .match-code { font-size: 38px; letter-spacing: 0.18em; padding-left: 0.18em; }
  input.code { font-size: 26px; letter-spacing: 0.32em; padding-left: calc(13px + 0.32em); }
}
/* Paysage sur téléphone : la carte remonte, le logo se fait petit. */
@media (pointer: coarse) and (max-height: 500px) {
  body { padding-top: max(14px, env(safe-area-inset-top)); }
  .stage { gap: 14px; }
  .logo { width: 112px; }
  .tag { display: none; }
}
