/* ==========================================================
   Salon Démo — Composants partagés
   ========================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: radial-gradient(1100px 560px at 8% -12%, var(--glow), transparent 62%), var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  transition: background-color var(--t) var(--ease), color var(--t) var(--ease);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
.i { flex: none; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
::selection { background: var(--gold-soft); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Structure d'application ---------- */
.shell { display: flex; gap: 12px; padding: 12px; height: 100vh; height: 100dvh; }
.main { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.page { flex: 1; min-height: 0; overflow-y: auto; padding-right: 2px; }

/* ---------- Rail latéral flottant ---------- */
.rail {
  width: 76px; flex: none;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 10px 0;
  background: var(--rail);
  border: 1px solid var(--line);
  border-radius: 38px;
}
.rail-logo { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; background: var(--card); border: 1px solid var(--line); color: var(--gold); flex: none; }
.rail-nav, .rail-foot {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  background: var(--card); border: 1px solid var(--line);
  width: 62px; padding: 6px 0; border-radius: 31px;
}
.rail-nav { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; }
.rail-nav::-webkit-scrollbar { display: none; }
.rail-foot { flex: none; }
.rail-btn {
  width: 50px; height: 50px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  color: var(--text-2); background: var(--card-2);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.rail-btn:active { transform: scale(.92); }
.rail-btn:hover { color: var(--text); }
.rail-btn.is-active { background: var(--gold); color: var(--on-gold); box-shadow: 0 6px 16px rgba(201, 154, 63, .35); }
.rail-btn .dot-badge { position: absolute; }

/* ---------- Barre supérieure ---------- */
.topbar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  min-height: 64px; padding: 8px 12px 8px 20px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
}
.topbar h1 { font-size: 19px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
.topbar .sub { font-size: 13px; color: var(--text-2); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding-left: 12px; margin-left: 2px; border-left: 1px solid var(--line); }
.user-chip .who { line-height: 1.2; text-align: left; }
.user-chip .who b { display: block; font-size: 14px; font-weight: 700; }
.user-chip .who span { font-size: 12px; color: var(--text-2); }

/* ---------- Carte ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); }

/* ---------- Boutons ---------- */
.btn {
  min-height: var(--tap); padding: 0 20px; border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 700; font-size: 15px; letter-spacing: -.005em;
  background: var(--card-2); border: 1px solid var(--line-2);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast), border-color var(--t-fast), opacity var(--t-fast);
  user-select: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:hover { border-color: var(--gold-line); }
.btn[disabled] { opacity: .42; pointer-events: none; }
.btn-gold { background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--on-gold); border-color: transparent; box-shadow: 0 8px 22px rgba(201, 154, 63, .28); }
.btn-gold:hover { border-color: transparent; filter: brightness(1.06); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); background: var(--danger-soft); border-color: transparent; }
.btn-lg { min-height: 64px; font-size: 17px; border-radius: 18px; }
.btn-block { width: 100%; }

.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 50%; flex: none;
  display: grid; place-items: center; position: relative;
  background: var(--card-2); color: var(--text-2); border: 1px solid var(--line);
  transition: transform var(--t-fast) var(--ease), background var(--t-fast), color var(--t-fast);
}
.icon-btn:active { transform: scale(.92); }
.icon-btn:hover { color: var(--text); }
.icon-btn.gold { background: var(--gold); color: var(--on-gold); border-color: transparent; }
.icon-btn.danger { color: var(--danger); }
.icon-btn .pip { position: absolute; top: 11px; right: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); border: 2px solid var(--card-2); }

/* ---------- Avatar / puces ---------- */
.avatar {
  --sz: 40px; width: var(--sz); height: var(--sz); border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font-size: calc(var(--sz) * .36); font-weight: 800; letter-spacing: .02em;
  color: var(--av-on, #fff); background: var(--av, var(--card-3));
}
.badge { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: var(--r-pill); font-size: 12px; font-weight: 700; background: var(--card-3); color: var(--text-2); }
.badge.gold { background: var(--gold-soft); color: var(--gold-2); }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Champs ---------- */
.field { display: flex; flex-direction: column; gap: 8px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.input {
  width: 100%; min-height: var(--tap); padding: 0 16px;
  background: var(--card-2); border: 1px solid var(--line-2); border-radius: 14px;
  outline: none; transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.input::placeholder { color: var(--text-3); }
.input:focus { border-color: var(--gold); box-shadow: 0 0 0 4px var(--gold-soft); }
.input.is-error { border-color: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.input-icon { position: relative; }
.input-icon > .i { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon > .input { padding-left: 46px; }
.hint { font-size: 12px; color: var(--text-3); }
.hint.err { color: var(--danger); }

/* ---------- Switch ---------- */
.switch { position: relative; width: 58px; height: 34px; flex: none; border-radius: var(--r-pill); background: var(--card-3); border: 1px solid var(--line-2); transition: background var(--t), border-color var(--t); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--text-2); transition: transform var(--t) var(--ease), background var(--t); }
.is-on > .switch, .switch.is-on { background: var(--gold); border-color: transparent; }
.is-on > .switch::after, .switch.is-on::after { transform: translateX(24px); background: var(--on-gold); }

/* ---------- Contrôle segmenté ---------- */
.seg { display: grid; gap: 6px; padding: 5px; background: var(--card-2); border: 1px solid var(--line); border-radius: 18px; }
.seg-btn {
  min-height: 52px; border-radius: 13px; padding: 6px 8px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 700; font-size: 13.5px; color: var(--text-2); text-align: center; line-height: 1.15;
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.seg-btn:active { transform: scale(.96); }
.seg-btn.is-active { background: var(--gold); color: var(--on-gold); box-shadow: 0 4px 14px rgba(201, 154, 63, .3); }

/* ---------- Surcouches : feuille / tiroir ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px;
  background: var(--scrim); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 0; transition: opacity .2s var(--ease);
}
.overlay.in { opacity: 1; }
.sheet {
  width: min(560px, 100%); max-height: calc(100dvh - 32px); display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--line-2); border-radius: var(--r-xl); box-shadow: var(--shadow);
  transform: translateY(18px) scale(.98); transition: transform .28s var(--ease);
}
.overlay.in .sheet { transform: none; }
.sheet-sm { width: min(420px, 100%); }
.sheet-lg { width: min(780px, 100%); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 18px 8px 24px; }
.sheet-head h3 { font-size: 19px; font-weight: 800; letter-spacing: -.01em; }
.sheet-body { padding: 8px 24px 24px; overflow-y: auto; }
.overlay.drawer { place-items: stretch end; padding: 12px; }
.overlay.drawer .sheet { width: min(460px, 100%); height: 100%; max-height: none; transform: translateX(28px); }
.overlay.drawer.in .sheet { transform: none; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 120; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-radius: var(--r-pill);
  background: var(--card-3); border: 1px solid var(--line-2); box-shadow: var(--shadow); font-weight: 600; font-size: 14px;
  animation: toast-in .3s var(--ease) both;
}
.toast.err { color: var(--danger); }
.toast.ok .i { color: var(--success); }
.toast.out { animation: toast-out .25s var(--ease) both; }

/* ---------- Clavier numérique ---------- */
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
  min-height: 64px; border-radius: 18px; font-size: 24px; font-weight: 700;
  background: var(--card-2); border: 1px solid var(--line);
  display: grid; place-items: center; transition: transform var(--t-fast) var(--ease), background var(--t-fast);
}
.key:active { transform: scale(.94); background: var(--card-3); }
.key.ghost { background: transparent; border-color: transparent; color: var(--text-2); font-size: 15px; }

/* ---------- États vides ---------- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; padding: 32px 16px; color: var(--text-2); }
.empty .ico { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold); }
.empty b { color: var(--text); font-size: 16px; }
.empty p { font-size: 13.5px; max-width: 28ch; }

/* ---------- Animations ---------- */
@keyframes toast-in  { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }
@keyframes fade-up   { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pop       { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }
@keyframes shake     { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); } }
@keyframes draw      { to { stroke-dashoffset: 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
[hidden] { display: none !important; }

/* Téléphone : les modales deviennent des feuilles ancrées en bas, les tiroirs passent en plein écran */
@media (max-width: 699px) {
  .overlay { padding: 0; place-items: end center; }
  .sheet, .sheet-sm, .sheet-lg { width: 100%; max-height: 92dvh; border-radius: 24px 24px 0 0; border-bottom: 0; }
  .sheet-head { padding: 14px 12px 6px 18px; }
  .sheet-body { padding: 6px 18px calc(20px + env(safe-area-inset-bottom, 0px)); }
  .overlay.drawer { padding: 0; place-items: stretch; }
  .overlay.drawer .sheet { width: 100%; height: 100%; max-height: none; border-radius: 0; }
  .toasts { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
}


/* ==========================================================
   RESPONSIVE COMMUN (toutes les pages)
   ========================================================== */
.only-phone { display: none; }
.tb-left { display: flex; align-items: center; gap: 10px; min-width: 0; }

/* Tiroir de navigation (téléphone) */
.overlay.navd { place-items: stretch start; padding: 0; }
.overlay.navd .sheet { width: min(300px, 86vw); height: 100%; max-height: none; border-radius: 0 var(--r-xl) var(--r-xl) 0; transform: translateX(-28px); display: flex; }
.overlay.navd.in .sheet { transform: none; }
.overlay.navd .sheet-body { display: flex; flex-direction: column; flex: 1; padding: 4px 12px 16px; }
.mnav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.mnav-item { display: flex; align-items: center; gap: 14px; min-height: 54px; padding: 0 16px; border-radius: 14px; font-weight: 600; font-size: 15px; color: var(--text-2); width: 100%; text-align: left; }
.mnav-item:active { background: var(--card-3); }
.mnav-item.is-active { background: var(--gold); color: var(--on-gold); font-weight: 700; }
.mnav-out { color: var(--danger); margin-top: 8px; border-top: 1px solid var(--line); border-radius: 0 0 14px 14px; }

/* Rail plus étroit sur iPad portrait et petits écrans larges */
@media (max-width: 1023px) {
  .rail { width: 64px; padding: 8px 0; }
  .rail-logo { width: 46px; height: 46px; }
  .rail-nav, .rail-foot { width: 54px; }
  .rail-btn { width: 44px; height: 44px; }
  .topbar .user-chip .who { display: none; }
}

/* Téléphone : plus de rail, menu hamburger, en-tête compact */
@media (max-width: 699px) {
  .only-phone { display: grid; }
  .rail { display: none; }
  .shell { padding: 8px; gap: 8px; }
  .main { gap: 8px; }
  .topbar { min-height: 54px; padding: 6px 8px 6px 8px; gap: 8px; border-radius: var(--r-md); }
  .topbar h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .topbar .sub { display: none; }
  .topbar-right { gap: 6px; flex: none; }
  .topbar .icon-btn { width: 44px; height: 44px; }
  .topbar .user-chip { padding-left: 4px; border: 0; margin: 0; }
  .topbar .user-chip .avatar { --sz: 38px !important; }
  .topbar .select { max-width: 150px; font-size: 13px; padding-right: 30px; }
  .topbar .btn-sm { display: none; }
  .toasts { bottom: 16px; }
}
@media (max-width: 380px) { body:not(.caisse) .topbar-right .icon-btn:not(.gold):not(.only-phone) { display: none; } }
.mnav-item, .rail-btn, .btn { text-decoration: none; }
.tb-left { flex: 1; } .tb-left > div { min-width: 0; } .tb-left h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }


/* ==========================================================
   MOBILE — barre du bas + feuilles qui montent du bas
   ========================================================== */
.bnav { display: none; }
.mgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 4px; }
.mg-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 92px; padding: 10px 6px; border-radius: 18px; text-align: center; font-size: 12.5px; font-weight: 600; line-height: 1.2; color: var(--text-2); background: var(--card-2); border: 1px solid var(--line); text-decoration: none; }
.mg-item .mg-ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--card-3); color: var(--text); }
.mg-item:active { transform: scale(.96); }
.mg-item.is-active { border-color: var(--gold); color: var(--text); }
.mg-item.is-active .mg-ico { background: var(--gold); color: var(--on-gold); }
.mg-foot { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 6px; display: flex; flex-direction: column; }
.mg-foot .mnav-item { border-radius: 12px; }
.mg-foot .mnav-out { border-top: 0; margin-top: 0; }

@media (max-width: 699px) {
  /* barre de navigation du bas */
  body.has-bnav .bnav {
    display: grid; grid-template-columns: repeat(var(--n, 5), minmax(0, 1fr)); align-items: end;
    position: fixed; z-index: 55; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    height: 64px; padding: 0 4px 4px; border-radius: 26px;
    background: var(--card); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  }
  .bn-item { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 54px; color: var(--text-3); font-size: 11px; font-weight: 600; text-decoration: none; }
  .bn-item.is-active { color: var(--gold-2); }
  .bn-item.is-active::before { content: ""; position: absolute; top: -5px; width: 26px; height: 3px; border-radius: 3px; background: var(--gold); }
  .bn-center { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding-bottom: 4px; color: var(--text-3); font-size: 11px; font-weight: 600; text-decoration: none; }
  .bn-circle { width: 62px; height: 62px; margin-top: -32px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(180deg, var(--gold-2), var(--gold)); color: var(--on-gold); border: 5px solid var(--bg); box-shadow: 0 8px 22px rgba(201, 154, 63, .4); }
  .bn-center:active .bn-circle { transform: scale(.94); }
  .bn-center.is-active { color: var(--gold-2); }
  body.has-bnav .page { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  body.has-bnav .toasts { bottom: calc(92px + env(safe-area-inset-bottom, 0px)); }

  /* toutes les fenêtres montent du bas de l'écran */
  .overlay .sheet, .overlay.drawer .sheet { transform: translateY(100%); transition: transform .34s var(--ease); }
  .overlay.in .sheet, .overlay.drawer.in .sheet { transform: none; }
}


/* ==========================================================
   MOBILE v2 — plus grand, plus simple
   ========================================================== */
.btn.only-phone { display: none; }
@media (max-width: 699px) {
  body { font-size: 16px; }
  .btn.only-phone { display: inline-flex; }

  /* barre du bas : grande */
  body.has-bnav .bnav { height: 78px; padding: 0 6px 6px; border-radius: 30px; }
  .bn-item { min-height: 66px; gap: 4px; font-size: 12.5px; }
  .bn-item svg.i { width: 28px; height: 28px; }
  .bn-center { font-size: 12.5px; gap: 3px; padding-bottom: 6px; }
  .bn-circle { width: 74px; height: 74px; margin-top: -40px; }
  .bn-circle svg.i { width: 32px; height: 32px; }
  body.has-bnav .page { padding-bottom: calc(116px + env(safe-area-inset-bottom, 0px)); }
  body.has-bnav .toasts { bottom: calc(104px + env(safe-area-inset-bottom, 0px)); }

  /* en-tête : titre + notifications + avatar (le thème est dans « Plus ») */
  .topbar [data-theme-toggle], #themeSlot { display: none !important; }
  .topbar { min-height: 60px; }
  .topbar h1 { font-size: 18px; }
  .topbar .icon-btn { width: 48px; height: 48px; }

  /* champs et boutons plus gros (16 px évite le zoom automatique d'iOS) */
  .input, .select, .date { min-height: 54px; font-size: 16px; border-radius: 16px; }
  .btn { min-height: 54px; font-size: 16px; border-radius: 16px; }
  .btn-sm { min-height: 50px; }
  .pill { min-height: 46px; padding: 0 18px; font-size: 15px; }
  .chip { min-height: 46px; padding: 0 18px; font-size: 15px; }
  .field > label { font-size: 14px; }
  .sheet-head h3 { font-size: 20px; }
  .sheet-head .icon-btn { width: 48px; height: 48px; }
  .row-switch { min-height: 60px; }
  .switch { width: 62px; height: 36px; }
  .switch::after { width: 28px; height: 28px; }
  .is-on > .switch::after, .switch.is-on::after { transform: translateX(26px); }
  .mg-item { min-height: 104px; font-size: 13.5px; }
  .mg-item .mg-ico { width: 50px; height: 50px; }
  .mnav-item { min-height: 58px; font-size: 16px; }
}

/* Déconnexion en rouge sur toutes les pages (menu latéral) */
.rail-foot .rail-btn[data-logout] { color: var(--danger); background: var(--danger-soft); }
.rail-foot .rail-btn[data-logout]:hover { color: var(--danger); filter: brightness(1.15); }
