:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #0b1220;
  --muted: #5b6577;
  --border: #dfe4ee;
  --primary: #2b5cff;
  --primary-2: #00b3d6;
  --primary-ink: #ffffff;
  --danger: #d92d4b;
  --warn-bg: #fff4d6;
  --warn-ink: #8a5a00;
  --ok: #12a150;
  --radius: 20px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(11, 18, 32, .04), 0 12px 32px -12px rgba(11, 18, 32, .18);
  --tabbar-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #1b2539;
    --text: #e8edf6;
    --muted: #93a0b5;
    --border: #26324a;
    --primary: #5b82ff;
    --primary-2: #22c7e6;
    --warn-bg: #3a2e0b;
    --warn-ink: #ffd36b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 16px 40px -16px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

h1, h2, p { margin: 0; }
a { color: inherit; }
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.muted { color: var(--muted); }
.small { font-size: 14px; }
.accent {
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

/* ---------- Splash ---------- */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 50px; padding: 0 20px; border-radius: 14px; border: 0;
  font-weight: 600; font-size: 16px; text-decoration: none; cursor: pointer;
  transition: transform .12s ease, opacity .2s ease, background .2s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-block { width: 100%; }
.btn-primary { background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 70%, var(--primary-2))); color: var(--primary-ink); box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--primary) 70%, transparent); }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-ghost { background: transparent; color: var(--danger); }
.btn-ms { background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow); }
.btn-ms .ms-logo { width: 20px; height: 20px; stroke: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 999px; border: 0;
  background: var(--primary); color: var(--primary-ink); font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip svg { width: 16px; height: 16px; }
.chip-ghost { background: var(--surface-2); color: var(--text); }

.badge { display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); }

.alert { margin-top: 16px; padding: 12px 14px; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); font-size: 14px; }

/* ---------- Connexion ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--primary) 18%, transparent), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--primary-2) 16%, transparent), transparent 60%),
    var(--bg);
}
.login-inner { width: 100%; max-width: 400px; text-align: center; }
.login-logo { width: 88px; height: 88px; margin-bottom: 28px; filter: drop-shadow(0 12px 24px rgba(43, 92, 255, .35)); }
.login h1 { font-size: clamp(28px, 7vw, 34px); line-height: 1.15; letter-spacing: -.02em; margin-bottom: 14px; }
.login .muted { margin-bottom: 32px; }

/* ---------- Structure app ---------- */
.app { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(8px + var(--safe-top)) 20px 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
}
.topbar-title { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.view {
  max-width: 520px; margin: 0 auto;
  padding: 4px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  animation: fade .25s ease;
}
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center; gap: 8px;
  padding: 8px 16px calc(8px + var(--safe-bottom));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px); -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.tab {
  flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; border: 0; background: none; color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer;
  border-radius: 12px;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--primary); }

/* ---------- Carte de visite ---------- */
.bizcard {
  position: relative; overflow: hidden;
  background: var(--surface); border-radius: 28px; padding: 18px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.bizcard::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 6px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
}
.bizcard-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.bizcard-id { min-width: 0; }
.bizcard-name { font-size: 20px; line-height: 1.2; letter-spacing: -.02em; font-weight: 750; overflow-wrap: anywhere; }
.bizcard-title { color: var(--text); font-weight: 500; margin-top: 2px; }
.bizcard-company { color: var(--muted); font-size: 14px; margin-top: 2px; }
.bizcard-title:empty, .bizcard-company:empty { display: none; }

.avatar { width: 58px; height: 58px; border-radius: 50%; object-fit: cover; flex: none; background: var(--surface-2); }
.avatar-lg { width: 112px; height: 112px; }
.avatar-initials {
  display: grid; place-items: center; font-weight: 700; font-size: 24px; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.avatar-lg.avatar-initials { font-size: 38px; }

.qr-frame {
  display: block; width: min(100%, 34dvh); margin: 0 auto; aspect-ratio: 1; padding: 14px; border: 0; cursor: zoom-in;
  background: #fff; border-radius: 20px; box-shadow: inset 0 0 0 1px #e6e9f0;
}
/* Le SVG du QR code porte ses propres attributs : on neutralise les styles d'icônes hérités */
.qr-frame svg, .present-qr svg {
  width: 100%; height: 100%; display: block;
  stroke: none; fill: none; stroke-width: 1; stroke-linecap: butt; stroke-linejoin: miter;
}
.qr-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 14px 0 12px;
  padding: 4px; background: var(--surface-2); border-radius: 14px;
}
.segmented button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; border: 0; border-radius: 11px; background: transparent; color: var(--muted);
  font-weight: 600; font-size: 15px; cursor: pointer; transition: background .2s, color .2s;
}
.segmented button svg { width: 18px; height: 18px; }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.segmented button:disabled { opacity: .45; cursor: not-allowed; }

.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.action {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  min-height: 64px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--surface); text-decoration: none; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: transform .12s ease;
}
.action svg { width: 22px; height: 22px; color: var(--primary); }
.action:active { transform: scale(.96); }

/* ---------- Formulaire ---------- */
.form { display: grid; gap: 14px; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: grid; gap: 12px;
}
.view > .panel { margin-top: 14px; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }
@media (max-width: 380px) { .grid-2 { grid-template-columns: 1fr; } }

.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field textarea {
  width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); font: inherit; font-size: 16px;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
}
.field.invalid input, .field.invalid textarea { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; }

.switch { display: flex; align-items: center; gap: 14px; cursor: pointer; padding: 4px 0; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  position: relative; width: 50px; height: 30px; flex: none; border-radius: 999px;
  background: var(--border); transition: background .2s;
}
.switch-track::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 + .switch-track { background: var(--ok); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 25%, transparent); }
.switch-label { display: grid; }
.switch-label small { color: var(--muted); font-size: 13px; }

.linkbox { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.linkbox code { flex: 1 1 100%; font-size: 13px; overflow-wrap: anywhere; color: var(--muted); }

.savebar {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px); z-index: 5;
  transition: transform .25s ease, opacity .25s ease;
}
.savebar.idle { opacity: 0; transform: translateY(16px); pointer-events: none; }

/* ---------- Présentation ---------- */
.present {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background: #fff; color: #0b1220; cursor: zoom-out; animation: fade .2s ease;
}
.present-card { width: min(92vw, 70vh, 560px); text-align: center; }
.present-qr { width: 100%; aspect-ratio: 1; }
.present-name { font-size: 24px; font-weight: 750; margin-top: 16px; letter-spacing: -.02em; }
.present-sub { color: #5b6577; }
.present-hint { color: #93a0b5; font-size: 13px; }

/* ---------- Feuille iOS ---------- */
.sheet { position: fixed; inset: 0; z-index: 45; display: flex; align-items: flex-end; background: rgba(0, 0, 0, .45); animation: fade .2s ease; }
.sheet-panel {
  width: 100%; max-width: 520px; margin: 0 auto; padding: 24px 24px calc(24px + var(--safe-bottom));
  background: var(--surface); border-radius: 24px 24px 0 0;
}
.sheet-panel h2 { font-size: 20px; margin-bottom: 12px; }
.sheet-panel ol { padding-left: 20px; margin: 0 0 20px; display: grid; gap: 10px; }
.inline-icon { width: 18px; height: 18px; vertical-align: -3px; color: var(--primary); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-size: 15px; font-weight: 500; box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Carte publique ---------- */
body.public {
  background:
    radial-gradient(900px 500px at 0% -10%, color-mix(in srgb, var(--primary) 20%, transparent), transparent 60%),
    radial-gradient(800px 500px at 100% 110%, color-mix(in srgb, var(--primary-2) 16%, transparent), transparent 60%),
    var(--bg);
}
.public-wrap { max-width: 460px; margin: 0 auto; padding: calc(32px + var(--safe-top)) 16px calc(32px + var(--safe-bottom)); }
.bizcard-public { display: grid; gap: 20px; padding: 32px 22px 22px; }
.bizcard-head { text-align: center; display: grid; justify-items: center; gap: 2px; }
.bizcard-head .avatar { margin-bottom: 14px; box-shadow: 0 0 0 4px var(--surface), 0 0 0 6px color-mix(in srgb, var(--primary) 35%, transparent); }
.bizcard-head .bizcard-name { font-size: 26px; }
.contact-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.contact-list a {
  display: flex; align-items: center; gap: 14px; padding: 10px; border-radius: 14px; text-decoration: none;
  transition: background .15s;
}
.contact-list a:hover, .contact-list a:active { background: var(--surface-2); }
.contact-icon {
  width: 42px; height: 42px; flex: none; border-radius: 12px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary);
}
.contact-text { display: grid; min-width: 0; }
.contact-text small { color: var(--muted); font-size: 12px; }
.contact-text span { overflow-wrap: anywhere; font-weight: 500; }
.bizcard-note { color: var(--muted); font-size: 14px; text-align: center; white-space: pre-line; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
