:root {
  --bg: #eef0f2; --card: #ffffff; --ink: #1d1d1f; --grey: #86868b;
  --sep: #d8d8dd; --fill: #f2f2f7; --fill-2: #e8e8ed;
  --blue: #0071e3; --blue-hover: #0058b9; --blue-soft: #e8f1fd;
  --accent: #0071e3; --accent-hover: #0058b9; --accent-rgb: 0,113,227;
  --green: #34c759; --green-hover: #28a746;
  --red: #ff3b30; --orange: #ff9500;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 6px 20px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.14);
}
[data-theme="dark"] {
  --bg: #000000; --card: #1c1c1e; --ink: #f5f5f7; --grey: #98989d;
  --sep: #38383a; --fill: #2c2c2e; --fill-2: #3a3a3c;
  --blue: #0a84ff; --blue-hover: #409cff; --blue-soft: #0a2540;
  --accent: #0a84ff; --accent-hover: #409cff; --accent-rgb: 10,132,255;
  --green: #30d158; --green-hover: #4ade7b;
  --red: #ff453a; --orange: #ff9f0a;
  --shadow: none;
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.6);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Barre de défilement fine et discrète, cohérente avec le thème, pour
   tout élément qui défile dans l'app (au lieu de la grosse barre par
   défaut du navigateur) - un seul réglage ici plutôt que de le répéter
   à chaque endroit qui défile. */
* { scrollbar-width: thin; scrollbar-color: var(--sep) transparent; }
*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--sep); border-radius: 999px; }
*::-webkit-scrollbar-thumb:hover { background: var(--grey); }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Inter", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background .25s ease, color .25s ease;
  overflow-x: hidden; /* filet de sécurité : un élément qui déborde ne doit
                         jamais rendre toute la page défilable horizontalement */
  max-width: 100vw;
}

.theme-btn {
  position: fixed; top: 18px; right: 18px; z-index: 60;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: var(--fill); color: var(--grey); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.theme-btn:hover { color: var(--ink); }
.theme-btn svg { width: 20px; height: 20px; }
.theme-btn .moon { display: none; }
[data-theme="dark"] .theme-btn .sun { display: none; }
[data-theme="dark"] .theme-btn .moon { display: block; }

.ai-chat-fab {
  position: fixed; bottom: 24px; right: 24px; z-index: 70;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  color: #fff; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  background: linear-gradient(115deg, #6366f1, #a855f7, #ec4899, #6366f1);
  background-size: 300% 300%;
  animation: aiFabGradient 6s ease infinite, aiFabPulse 2.6s ease-in-out infinite;
}
.ai-chat-fab.visible { display: flex; }
.ai-chat-fab:hover { animation-play-state: paused; filter: brightness(1.12); }
@keyframes aiFabGradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
@keyframes aiFabPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(168,85,247,.55), var(--shadow-lg); }
  50% { box-shadow: 0 0 0 10px rgba(168,85,247,0), var(--shadow-lg); }
}

@media (max-width: 860px) {
  /* Le menu du bas flottant occupe cet espace en mobile - sans ça, le
     bouton et le panneau du chat lui rentrent dedans. */
  .ai-chat-fab { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .ai-chat-panel { bottom: calc(164px + env(safe-area-inset-bottom, 0px)); max-height: calc(100vh - 210px); }
}
.ai-chat-panel {
  position: fixed; bottom: 92px; right: 24px; z-index: 70;
  width: 340px; max-width: calc(100vw - 32px); height: 460px; max-height: calc(100vh - 140px);
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow-lg);
  flex-direction: column; overflow: hidden;
}
.ai-chat-header {
  display: flex; align-items: center; gap: 10px; padding: 14px 16px;
  border-bottom: 1px solid var(--sep); font-weight: 600; font-size: 15px;
}
.ai-chat-credits { margin-left: auto; font-size: 11.5px; font-weight: 400; color: var(--grey); }
.ai-chat-close { border: none; background: none; color: var(--grey); cursor: pointer; font-size: 14px; padding: 2px 4px; }
.ai-chat-messages { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.ai-chat-msg { max-width: 85%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.4; white-space: pre-wrap; animation: aiMsgIn .28s ease-out; }
@keyframes aiMsgIn {
  from { opacity: 0; transform: translateY(8px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.ai-chat-msg.user { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.ai-chat-msg.bot { align-self: flex-start; background: var(--fill); color: var(--ink); border-bottom-left-radius: 4px; }
.ai-chat-msg.error { background: var(--red); color: #fff; }
.ai-chat-typing { opacity: .6; }
.ai-chat-input-row { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid var(--sep); }
.ai-chat-input-row input {
  flex: 1; min-width: 0; border: none; border-radius: 999px; padding: 10px 14px; background: var(--fill);
  color: var(--ink); font-family: inherit; font-size: 16px;
}
.ai-chat-input-row .btn { padding: 10px 18px; font-size: 14px; flex-shrink: 0; }
.ai-chat-send-btn { width: 40px; height: 40px; padding: 0 !important; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
[data-theme="dark"] .sidebar-theme-btn .sun { display: none; }
[data-theme="dark"] .sidebar-theme-btn .moon { display: block !important; }

.btn {
  border: none; border-radius: 999px; font-family: inherit;
  font-size: 15px; font-weight: 600; padding: 12px 22px;
  cursor: pointer; letter-spacing: -.01em;
  transition: background .18s ease, color .18s ease, box-shadow .18s ease,
              transform .15s cubic-bezier(.34,1.56,.64,1);
  color: var(--ink); background: var(--fill);
}
.btn:active:not(:disabled) { transform: scale(.96); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { background: var(--green-hover); }
.btn-soft:hover { background: var(--fill-2); }
.btn-ghost { background: none; color: var(--grey); font-weight: 500; }
.btn-ghost:hover { color: var(--red); }

/* Retour doux au clic pour tous les autres éléments cliquables de
   l'app (onglets, avatars, bascules...) - avant, aucune transition
   sur transform : le clic était sec, sans aucun effet visuel. */
button, .switch, .clients-pagination button {
  transition: background .18s ease, color .18s ease, border-color .18s ease,
              box-shadow .18s ease, opacity .18s ease,
              transform .15s cubic-bezier(.34,1.56,.64,1);
}
button:active:not(:disabled), .switch:active {
  transform: scale(.95);
}

.fld { margin-bottom: 15px; }
.fld label {
  display: block; font-size: 13px; font-weight: 500;
  color: var(--grey); margin-bottom: 7px; letter-spacing: -.01em;
}
.fld input, .fld select, .fld textarea {
  width: 100%; padding: 14px 15px; border: 1px solid var(--sep); border-radius: 12px;
  background: var(--card); color: var(--ink); font-family: inherit; font-size: 16px;
  outline: 2px solid transparent; outline-offset: -2px;
  transition: outline-color .15s ease, background .25s ease, border-color .15s ease;
}
.fld input:focus, .fld select:focus, .fld textarea:focus { outline-color: var(--blue); }

/* Les champs heure/date natifs se centrent par défaut sur mobile
   (Safari/Chrome iOS notamment), contrairement à un champ texte
   normal - décalage visuel vers la droite par rapport aux autres
   champs du même formulaire. Le rendu interne (shadow DOM du
   navigateur) ne répond pas de façon fiable à text-align - on réduit
   plutôt la largeur du champ à celle de son contenu, pour qu'il n'y
   ait plus d'espace vide où le centrer.
   */
.fld input[type="time"], .fld input[type="date"] {
  width: auto; min-width: 150px; max-width: 100%;
}
.fld input::placeholder { color: var(--grey); opacity: .6; }

/* Certains navigateurs mobiles (Chrome Android notamment) rendent
   l'icône native d'un input[type=date] dans une zone qui déborde de sa
   propre boîte, décalant visuellement le champ vers la droite malgré
   width:100%+border-box. On retire ce rendu natif : le champ reste
   entièrement cliquable (le sélecteur de date natif s'ouvre toujours
   au tap), seule la petite icône calendrier disparaît visuellement. */
input[type="date"] { -webkit-appearance: none; appearance: none; }

/* ============ Page de connexion / création de compte ============ */
/* Partagée par dashboard.html (gérants), compte.html (clients de chaque
   salon) et signup.html (création d'enseigne) - le dégradé de droite
   utilise --accent-rgb, déjà posé par applyAccentColor() avec la
   couleur propre à chaque salon ; le panneau de gauche affiche l'image
   uploadée dans Réglages (sinon un dégradé de secours). */
.auth-layout { display: flex; min-height: 100vh; align-items: stretch; }
.auth-visual {
  flex: 1 1 44%; position: relative; min-width: 0; overflow: hidden;
  background: linear-gradient(160deg, #1c1c1e 0%, #0a0a0c 100%);
  background-size: cover; background-position: center;
  display: flex; align-items: flex-end; padding: 44px;
}
.auth-visual::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,.05) 0%, rgba(0,0,0,.6) 100%);
}
.auth-visual-overlay { position: relative; z-index: 1; color: #fff; }
.auth-visual-title { font-size: 26px; font-weight: 700; margin: 0 0 6px; letter-spacing: -.01em; }
.auth-visual-sub { font-size: 15px; opacity: .8; margin: 0; }
.auth-form-side {
  flex: 1 1 56%; display: flex; align-items: center; justify-content: center;
  padding: 40px 24px; position: relative; overflow: hidden; background: var(--bg);
}
.auth-form-side::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background:
    radial-gradient(circle at 50% -10%, rgba(var(--accent-rgb), .30) 0%, rgba(var(--accent-rgb), 0) 55%),
    radial-gradient(circle at 50% 15%, rgba(var(--accent-rgb), .16) 0%, rgba(var(--accent-rgb), 0) 45%);
}
.auth-form-card { width: 100%; max-width: 380px; text-align: center; position: relative; z-index: 1; }
.auth-glow-icon {
  width: 62px; height: 62px; border-radius: 50%; margin: 0 auto 20px;
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,.9), rgba(var(--accent-rgb), 1) 60%);
  box-shadow: 0 0 0 8px rgba(var(--accent-rgb), .14), 0 10px 30px rgba(var(--accent-rgb), .35);
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.auth-title { font-size: 25px; font-weight: 700; margin: 0 0 6px; letter-spacing: -.01em; }
.auth-sub { color: var(--grey); margin: 0 0 26px; font-size: 14.5px; }
.auth-form-card .fld { text-align: left; margin-bottom: 14px; }
.auth-form-card .fld input {
  background: var(--card); border: 1px solid var(--sep);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.auth-links { margin-top: 16px; font-size: 14px; }
.auth-links a { color: var(--accent); text-decoration: none; font-weight: 500; }
.auth-back-link {
  position: absolute; top: 20px; left: 20px; z-index: 2; color: #fff; text-decoration: none;
  font-size: 14px; font-weight: 500; opacity: .85; display: flex; align-items: center; gap: 6px;
}
@media (max-width: 780px) {
  .auth-layout { flex-direction: column; }
  .auth-visual { flex: 0 0 auto; min-height: 180px; padding: 20px 24px; }
  .auth-visual-title { font-size: 21px; }
  .auth-form-side { flex: 1 1 auto; padding: 34px 20px 40px; }
}

/* ============ Sélecteur d'indicatif téléphonique ============ */
/* Emoji drapeau natif (rendu par le systeme, aucune requete reseau) -
   parfait sur Mac/iOS (Apple Color Emoji). Sur certains Windows/Linux
   plus anciens, peut s'afficher en lettres (ex: "FR") plutot qu'en
   drapeau colore selon la police emoji installee - compromis assume,
   preferable a une image externe (flagcdn.com) qui peut ne pas charger
   du tout (reseau, bloqueur de pub) et laisser une icone cassee. */
.phone-cc-picker { position: relative; flex: 0 0 150px; }
.phone-cc-btn {
  width: 100%; height: 100%; display: flex; align-items: center; gap: 7px; cursor: pointer;
  background: var(--fill); border: none; border-radius: 12px; padding: 0 10px 0 12px;
  font-size: 14.5px; color: var(--ink); font-family: inherit; outline: 2px solid transparent; outline-offset: -2px;
}
.phone-cc-btn:focus-visible { outline-color: var(--blue); }
.phone-cc-btn .flag-emoji { font-size: 18px; line-height: 1; flex-shrink: 0; }
.phone-cc-btn .code { white-space: nowrap; }
.phone-cc-btn .chev { margin-left: auto; color: var(--grey); flex-shrink: 0; }
.phone-cc-list {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow-lg);
  max-height: 260px; overflow-y: auto; width: 250px; padding: 6px;
}
.phone-cc-list.on { display: block; }
.phone-cc-opt {
  display: flex; align-items: center; gap: 9px; padding: 9px 10px; border-radius: 9px; cursor: pointer; font-size: 14px;
}
.phone-cc-opt:hover { background: var(--fill); }
.phone-cc-opt .flag-emoji { font-size: 18px; line-height: 1; flex-shrink: 0; }
.phone-cc-opt .code { color: var(--grey); font-variant-numeric: tabular-nums; flex-shrink: 0; }
.phone-cc-opt .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(140%);
  opacity: 0;
  background: var(--ink); color: var(--bg);
  padding: 14px 20px; border-radius: 16px; font-size: 15px; font-weight: 500;
  line-height: 1.4; text-align: left;
  /* Au-dessus de toutes les modales/overlays (dont la popup de recomptage,
     z-index 400, qui floute ce qu'elle recouvre) - sinon un message d'erreur
     affiche pendant une popup est cache derriere et illisible. */
  z-index: 10000; transition: transform .3s cubic-bezier(.3,1.3,.5,1), opacity .25s ease; pointer-events: none;
  max-width: 90vw;
}
.toast.on { transform: translateX(-50%) translateY(0); opacity: 1; }
.toast.err { background: var(--red); color: #fff; }

/* Fenêtres modales — remplacent alert()/confirm()/prompt() natifs */
/* Au-dessus des écrans plein cadre de la caisse (attente carte z-index 410,
   recomptage 400) : une confirmation demandée depuis l'un d'eux doit rester
   visible - sinon le bouton qui l'ouvre semble ne rien faire. Sous les toasts. */
.modal-overlay {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,0.42);
  backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity .16s ease;
}
.modal-overlay.on { opacity: 1; pointer-events: auto; }
.modal-box {
  background: var(--card); border-radius: 20px; padding: 26px;
  max-width: 420px; width: 100%;
  box-shadow: 0 24px 70px rgba(0,0,0,0.35);
  transform: translateY(10px) scale(.97);
  transition: transform .18s cubic-bezier(.2,.9,.3,1.1);
  max-height: 90vh; overflow-y: auto;
}
.modal-overlay.on .modal-box { transform: translateY(0) scale(1); }
.modal-title { font-size: 18px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 10px; color: var(--ink); }
.modal-message { font-size: 14.5px; color: var(--grey); line-height: 1.55; margin: 0 0 20px; white-space: pre-line; }
.modal-input {
  width: 100%; padding: 13px 15px; border: none; border-radius: 12px;
  background: var(--fill); color: var(--ink); font-family: inherit; font-size: 15px;
  outline: 2px solid transparent; outline-offset: -2px; margin-bottom: 16px;
}
.modal-input:focus { outline-color: var(--blue); }
.modal-error { color: var(--red); font-size: 13px; margin: -10px 0 14px; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; padding: 13px; font-size: 14.5px; }
.modal-danger-btn { background: var(--red) !important; color: #fff !important; }

/* Bascule à deux options (ex: Matin/Après-midi) - un vrai composant
   de segmented control, volontairement neutre (jamais var(--accent))
   pour ne jamais entrer en conflit avec la couleur personnalisée d'un
   salon, contrairement à une réutilisation de .btn-primary/.btn-soft. */
.half-toggle { display: flex; background: var(--fill); border-radius: 12px; padding: 3px; gap: 3px; }
.half-toggle button {
  flex: 1; border: none; background: none; padding: 9px 0; border-radius: 9px;
  font-family: inherit; font-size: 14px; font-weight: 500; color: var(--grey);
  cursor: pointer; transition: background .15s ease, color .15s ease;
}
.half-toggle button.sel { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.half-toggle button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.cam-choice.sel { background: var(--blue) !important; color: #fff !important; }
.cam-dot {
  width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--grey); flex-shrink: 0;
  box-sizing: border-box; position: relative;
}
.cam-choice.sel .cam-dot { border-color: #fff; }
.cam-choice.sel .cam-dot::after {
  content: ''; position: absolute; inset: 2px; border-radius: 50%; background: #fff;
}

.autocomplete-dropdown {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px;
  background: var(--card); border-radius: 12px; box-shadow: 0 12px 30px rgba(0,0,0,0.25);
  max-height: 220px; overflow-y: auto; z-index: 50;
}
.autocomplete-item { padding: 10px 14px; cursor: pointer; }
.autocomplete-item:hover { background: var(--fill); }
.autocomplete-item .ac-name { font-size: 14px; font-weight: 600; }
.autocomplete-item .ac-meta { font-size: 12px; color: var(--grey); margin-top: 1px; }

/* ============ Connexion TPE / imprimante (pastilles, guide, bouton reglages) ============
   Partage par la caisse (fenetre "Connexion TPE / imprimante") et le dashboard. */
.bridge-device { display: flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 500; color: var(--ink); }
.bridge-device-icon { position: relative; display: inline-flex; color: var(--grey); }
.bridge-device-dot {
  position: absolute; right: -2px; bottom: -2px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--sep); border: 2px solid var(--fill); transition: background .2s ease;
}
.bridge-device-dot.is-online { background: var(--green); }
.bridge-device-dot.is-offline { background: var(--red); }

.bridge-guide-steps { list-style: none; margin: 0 0 14px; padding: 0; counter-reset: step; }
.bridge-guide-steps li { counter-increment: step; display: flex; gap: 12px; align-items: flex-start;
                         font-size: 14.5px; line-height: 1.5; color: var(--ink); padding: 11px 0; }
.bridge-guide-steps li + li { border-top: 1px solid var(--sep); }
.bridge-guide-steps li::before { content: counter(step); flex: 0 0 26px; height: 26px; border-radius: 50%;
                                 background: var(--blue-soft); color: var(--blue); font-weight: 700; font-size: 13px;
                                 display: flex; align-items: center; justify-content: center; }
.bridge-guide-never { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--grey);
                      margin: 0 0 16px; cursor: pointer; }

.conn-rows { display: flex; gap: 26px; flex-wrap: wrap; margin: 4px 0 14px; }
.conn-hint { font-size: 12.5px; color: var(--grey); line-height: 1.5; margin: 0 0 16px; }

/* Bouton reglages (caisse), a gauche du bouton de theme : meme taille, meme style. */
.conn-btn {
  position: fixed; top: 18px; right: 70px; z-index: 60;
  width: 42px; height: 42px; border-radius: 50%; border: none;
  background: var(--fill); color: var(--grey); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.conn-btn:hover { color: var(--ink); }
.conn-btn svg { width: 20px; height: 20px; }
.conn-dot { position: absolute; top: 2px; right: 2px; width: 11px; height: 11px; border-radius: 50%;
            border: 2px solid var(--bg); display: none; }
.conn-dot.is-online { display: block; background: var(--green); }
.conn-dot.is-offline { display: block; background: var(--red); }
