* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  /* Filet de securite : si un element deborde jamais horizontalement (bug futur),
     ca reste invisible au lieu d'apparaitre en glissant la page sur le cote. */
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f3f4f6;
  color: #111827;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
#loginScreen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    linear-gradient(rgba(61,36,25,0.55), rgba(61,36,25,0.72)),
    url('/assets/hammam-bg.jpg');
  background-size: cover;
  background-position: center;
}
.login-box {
  background: #faf6ef;
  border-radius: 18px;
  padding: 38px 28px 30px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  text-align: center;
}
.login-logo {
  width: 100%;
  max-width: 220px;
  height: auto;
  margin: 0 auto 6px;
  display: block;
}
.login-subtitle {
  font-size: 12.5px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: #b08d57;
  font-weight: 600;
  margin-bottom: 26px;
}
.login-box input {
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid #e3d9c6;
  background: white;
  border-radius: 10px;
  font-size: 16px;
  text-align: left;
}
.login-box input:focus {
  outline: none;
  border-color: #b08d57;
}
.login-box button {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, #4a2c1d, #6b4530);
  color: #f0e6d2;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: .5px;
  margin-top: 4px;
  cursor: pointer;
}
.error { color: #b3261e; margin-top: 10px; font-size: 14px; text-align: center; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #3d2415, #5a3823);
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.topbar-logo { height: 28px; width: auto; flex: none; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 8px; max-width: 1100px; }
.stats-card { border-radius: 12px; padding: 14px; }
.extras-stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; max-width: 1100px; }
.extras-stats-grid > div:first-child { grid-column: 1 / -1; }
.list-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; max-width: 1100px; }
.hamburger-btn { background:rgba(255,255,255,0.15); color:#f0e6d2; border:none; width:36px; height:36px; border-radius:8px; font-size:16px; cursor:pointer; flex:none; }
.day-count-badge { font-size:11px; color:#e8d5bf; white-space:nowrap; margin-left:8px; flex-shrink:0; }
.presence-indicator { display:flex; align-items:center; margin-left:8px; flex-shrink:0; }
.presence-avatar {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 11px; font-weight: 800;
  border: 2px solid #3d2415; margin-left: -8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.presence-avatar:first-child { margin-left: 0; }
@media (max-width: 480px) {
  .day-count-badge { display: none; }
}

.sidebar-overlay { position:fixed; inset:0; background:rgba(0,0,0,0.4); z-index:399; opacity:0; pointer-events:none; transition:opacity .25s ease; }
.sidebar-overlay.show { opacity:1; pointer-events:auto; }
.sidebar {
  position:fixed; top:0; left:-260px; bottom:0; width:240px; z-index:400;
  background:linear-gradient(180deg,#3d2415,#2a1810);
  transition:left .25s ease; display:flex; flex-direction:column; padding:16px 0;
  overflow-y:auto;
}
.sidebar.open { left:0; }
.sidebar-header { display:flex; align-items:center; gap:8px; padding:0 16px 18px; border-bottom:1px solid rgba(255,255,255,0.1); margin-bottom:10px; }
.sidebar-header span { color:#f0e6d2; font-weight:700; font-size:13px; }
.sidebar-nav { display:flex; flex-direction:column; gap:2px; padding:0 10px; }
.sidebar-item { background:none; border:none; text-align:left; color:#e8dcc8; padding:11px 12px; border-radius:8px; font-size:14px; cursor:pointer; touch-action:none; }
.sidebar-item.sidebar-dragging { opacity:0.35; background:rgba(255,255,255,0.08); }
.res-cell [data-res-id] { touch-action: none; }
.sidebar-item:hover { background:rgba(255,255,255,0.08); }
.sidebar-item.active { background:linear-gradient(135deg,#5a3823,#8a6a3e); color:white; font-weight:600; }
.nav-btn {
  background: #f3f4f6;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 20px;
}
.topbar input[type="date"] {
  flex: 1;
  padding: 8px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
  min-width: 0;
}
.user-label { font-size: 12px; color: #f0e6d2; white-space: nowrap; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.logout-btn {
  background: rgba(255,255,255,0.15);
  color: #f0e6d2;
  border: none;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Grid ---------- */
.grid-wrapper {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.grid {
  display: grid;
  min-width: max-content;
  position: relative;
}

.grid-row {
  display: grid;
  grid-template-columns: var(--corner-w, 50px) repeat(var(--n-cols), var(--col-w, 110px));
}
.cell-header {
  position: sticky;
  top: 45px;
  z-index: 10;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  padding: 6px 3px;
  border: 1px solid rgba(0,0,0,0.08);
  color: #1f2937;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.3;
  overflow: hidden;
}
.cell-section {
  position: sticky;
  top: 0;
  z-index: 11;
  font-size: 12px;
  font-weight: 800;
  text-align: center;
  padding: 6px 3px;
  border: 1px solid rgba(0,0,0,0.08);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hour-cell {
  position: sticky;
  left: 0;
  z-index: 9;
  background: #eef2ff;
  font-weight: 700;
  text-align: center;
  padding: 6px 2px;
  border: 1px solid rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}
.hour-corner {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 12;
  background: #eef2ff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.res-cell {
  border: 1px solid rgba(0,0,0,0.08);
  min-height: 58px;
  padding: 3px;
  font-size: 9.5px;
  background: white;
  line-height: 1.25;
  overflow-wrap: break-word;
  word-break: break-word;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.res-cell * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.res-cell.filled {
  background: #fff8e1;
}
.res-cell.full {
  background: #ffd9d6;
}
.res-cell.alerte {
  background: #fef08a;
}
.res-cell.reclamation {
  background: repeating-linear-gradient(45deg, #fecaca, #fecaca 8px, #fca5a5 8px, #fca5a5 16px);
}
.res-cell.drop-target {
  outline: 2px dashed #5a3823;
  outline-offset: -2px;
}
.res-cell.drag-hover {
  background: #ffe4d6 !important;
  outline: 2px solid #5a3823;
  outline-offset: -2px;
}
.res-client { font-weight: 700; color: #1f2937; }
.res-detail { color: #4b5563; }
.res-staff { color: #2563eb; font-weight: 600; }
.res-prix { color: #059669; font-weight: 700; }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
}
.modal.show {
  opacity: 1;
  pointer-events: auto;
}
/* La fenetre de confirmation peut etre declenchee depuis un autre modal deja ouvert
   (ex: Supprimer un client depuis la fiche reservation) - elle doit toujours passer
   par-dessus, sinon elle reste cachee derriere jusqu'a ce qu'on ferme l'autre modal. */
#confirmModal { z-index: 150; }
.modal-content {
  background: white;
  width: 100%;
  max-width: 480px;
  border-radius: 16px 16px 0 0;
  padding: 20px;
  max-height: 85vh;
  overflow-y: auto;
  transform: translateY(48px);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
}
.modal.show .modal-content {
  transform: translateY(0);
}
.modal-content h2 { margin-bottom: 4px; font-size: 18px; color: #5a3823; }
.modal-content input, .modal-content select, .modal-content textarea {
  width: 100%;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  font-size: 15px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.row2 input, .row2 select { margin-bottom: 0; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.btn-primary { background: #5a3823; color: white; border: none; padding: 14px; border-radius: 10px; font-weight: 700; font-size: 15px; }
.btn-danger { background: #fee2e2; color: #dc2626; border: none; padding: 14px; border-radius: 10px; font-weight: 700; font-size: 15px; }
.btn-secondary { background: #efe7d9; color: #5a3823; border: none; padding: 14px; border-radius: 10px; font-size: 15px; font-weight: 700; }
.btn-mini-add { background: none; border: none; color: #5a3823; font-size: 12.5px; font-weight: 700; cursor: pointer; padding: 4px 0; text-decoration: underline; display: block; margin-bottom: 6px; }
.gender-row { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 9px; padding: 8px; margin-bottom: 8px; }
.gender-row-top { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.gender-row input[type="number"] { width: 64px; flex: none; }
.gender-row select { flex: 1; margin: 0; }
.gender-row input[type="text"] { width: 100%; margin: 0; }
.gender-row .row-del { background: #fee2e2; color: #b91c1c; border: none; width: 28px; height: 28px; border-radius: 7px; font-weight: 700; cursor: pointer; flex: none; }
.chip { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; padding: 8px 12px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.chip.active { background: #5a3823; color: white; border-color: #5a3823; }

/* ---------- Carte de reservation dans le slot (design aligne sur le tableau) ---------- */
.slot-card { background: #f9fafb; border-radius: 12px; padding: 12px; margin-bottom: 10px; font-size: 13.5px; line-height: 1.55; }
.slot-card .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.slot-card .row button { flex: 1 1 auto; min-width: 70px; padding: 8px 6px; border: none; border-radius: 8px; font-size: 12px; font-weight: 700; cursor: pointer; }
.slot-btn-edit { background: #e0e7ff; color: #3730a3; }
.slot-btn-move { background: #dbeafe; color: #1d4ed8; }
.slot-btn-copy { background: #f3f4f6; color: #374151; }
.slot-btn-split { background: #ede9fe; color: #6d28d9; }
.slot-btn-del { background: #fee2e2; color: #b91c1c; }

/* ---------- Barre de date simple ---------- */
/* ==========================================================================
   Barre de date et calendrier
   Palette tiree du spa lui-meme : espresso, laiton, sable, creme. Aucun gris
   froid : ils juraient avec le reste de l'app.
   Signature : dans le calendrier, plus une journee est remplie, plus sa case
   est teintee. Le mois se lit comme une carte, sans avoir a lire les chiffres.
   ========================================================================== */
:root {
  --cal-ink: #2b2117;
  --cal-espresso: #4a2c1d;
  --cal-brown: #5a3823;
  --cal-brass: #a37e42;
  --cal-brass-pale: #d8c39a;
  --cal-sand: #f3e9d8;
  --cal-sand-deep: #e7d7bd;
  --cal-cream: #fdfaf4;
  --cal-muted: #a3968a;
}

.datebar {
  display:flex; align-items:center; gap:8px;
  background:white; border-radius:16px; padding:7px 10px; margin:8px 12px;
  box-shadow:0 1px 2px rgba(74,44,29,0.06), 0 6px 18px rgba(74,44,29,0.07);
}
.datebar-caisse { margin:0 0 16px; max-width:430px; }

.datebar .nav-btn2 {
  background:var(--cal-sand); border:none; color:var(--cal-brown);
  width:34px; height:34px; border-radius:11px;
  font-size:17px; font-weight:700; cursor:pointer; flex:none;
  transition:background .15s ease, transform .15s ease;
}
.datebar .nav-btn2:hover { background:var(--cal-sand-deep); }
.datebar .nav-btn2:active { transform:scale(0.94); }

.datebar .date-wrap { flex:1; position:relative; }
.datebar .date-display {
  width:100%; text-align:center; font-size:14.5px; font-weight:700;
  color:var(--cal-ink); text-transform:capitalize;
  padding:7px 4px; background:var(--cal-sand); border-radius:11px; cursor:pointer;
  letter-spacing:0.1px;
  transition:background .15s ease;
}
.datebar .date-display:hover { background:var(--cal-sand-deep); }

/* Champ date de la Caisse : meme allure que l'affichage de date du tableau */
.datebar .date-input {
  flex:1; min-width:0; padding:7px 10px; font-size:14.5px; font-weight:600;
  color:var(--cal-ink); background:var(--cal-sand);
  border:none; border-radius:11px; font-family:inherit; cursor:pointer;
}
.datebar .date-input:focus-visible { outline:2px solid var(--cal-brass); outline-offset:1px; }

.datebar .today-btn2 {
  background:var(--cal-espresso); color:#fdfaf4; border:none; border-radius:11px;
  padding:0 13px; height:34px; font-size:12.5px; font-weight:700; cursor:pointer;
  flex:none; white-space:nowrap; letter-spacing:0.2px;
  transition:background .15s ease, transform .15s ease;
}
.datebar .today-btn2:hover { background:var(--cal-brown); }
.datebar .today-btn2:active { transform:scale(0.96); }

/* Point discret : cette journee a des reservations */
.date-res-dot {
  display:inline-block; width:6px; height:6px; border-radius:50%;
  background:var(--cal-brass); margin-left:6px; vertical-align:middle;
}

/* ---------- Calendrier (feuille qui monte du bas) ---------- */
.cal-popup-overlay {
  position:fixed; inset:0; background:rgba(43,33,23,0);
  display:flex; align-items:flex-end; justify-content:center; z-index:200;
  visibility:hidden; opacity:0; pointer-events:none;
  transition:background .22s ease, opacity .22s ease;
}
.cal-popup-overlay.show { visibility:visible; opacity:1; pointer-events:auto; background:rgba(43,33,23,0.5); }
.cal-popup {
  background:var(--cal-cream); width:100%; max-width:430px;
  border-radius:26px 26px 0 0; padding:10px 16px 24px;
  max-height:85vh; overflow-y:auto;
  transform:translateY(36px);
  transition:transform .28s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow:0 -10px 40px rgba(43,33,23,0.22);
}
.cal-popup-overlay.show .cal-popup { transform:translateY(0); }

/* Petite poignee, pour qu'on comprenne que la feuille vient du bas */
.cal-popup::before {
  content:''; display:block; width:42px; height:4px; border-radius:2px;
  background:var(--cal-sand-deep); margin:0 auto 14px;
}

.cal-popup-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:16px; }
.cal-popup-monthbtn {
  font-size:16.5px; font-weight:800; color:var(--cal-espresso);
  background:var(--cal-sand); border:none; padding:9px 15px; border-radius:12px;
  cursor:pointer; text-transform:capitalize; letter-spacing:0.2px;
  transition:background .15s ease;
}
.cal-popup-monthbtn:hover { background:var(--cal-sand-deep); }
.cal-popup-nav {
  background:var(--cal-sand); border:none; color:var(--cal-brown);
  width:36px; height:36px; border-radius:12px; font-size:16px; font-weight:700; cursor:pointer;
  transition:background .15s ease, transform .15s ease;
}
.cal-popup-nav:hover { background:var(--cal-sand-deep); }
.cal-popup-nav:active { transform:scale(0.94); }
.cal-popup-close {
  background:transparent; border:none; color:var(--cal-muted);
  width:36px; height:36px; border-radius:12px; font-size:19px; cursor:pointer;
  transition:background .15s ease, color .15s ease;
}
.cal-popup-close:hover { background:var(--cal-sand); color:var(--cal-brown); }

.cal-popup-dows { display:grid; grid-template-columns:repeat(7,1fr); text-align:center; margin-bottom:10px; }
.cal-popup-dows span {
  font-size:10.5px; color:var(--cal-brass); font-weight:800;
  text-transform:uppercase; letter-spacing:1.1px;
}

.cal-popup-days { display:grid; grid-template-columns:repeat(7,1fr); gap:5px; }

/* Case de journee : carre arrondi plutot que rond, comme un carreau de zellige,
   et ca laisse la place au nombre de reservations sous le chiffre. */
.cal-popup-day {
  aspect-ratio:1; border-radius:13px;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px;
  cursor:pointer; position:relative;
  background:transparent;
  transition:background .15s ease, transform .12s ease;
}
.cal-popup-day:hover { background:var(--cal-sand); }
.cal-popup-day:active { transform:scale(0.94); }
.cal-popup-day .pd-num { font-size:14px; font-weight:700; color:var(--cal-ink); line-height:1; }
.cal-popup-day.otherm { cursor:default; }
.cal-popup-day.otherm:hover { background:transparent; }
.cal-popup-day.otherm .pd-num { color:var(--cal-brass-pale); font-weight:600; }

/* Teinte selon le remplissage de la journee */
.cal-popup-day.calme  { background:#f7efe1; }
.cal-popup-day.moyen  { background:var(--cal-sand); }
.cal-popup-day.charge { background:var(--cal-sand-deep); }
.cal-popup-day.charge .pd-num { color:var(--cal-espresso); font-weight:800; }

/* Aujourd'hui : cercle de laiton, dans la palette du spa */
.cal-popup-day.today:not(.selected) { box-shadow:inset 0 0 0 2px var(--cal-brass); }

/* Journee choisie */
.cal-popup-day.selected {
  background:linear-gradient(150deg, var(--cal-espresso), #8a6a3e);
  box-shadow:0 4px 14px rgba(74,44,29,0.3);
}
.cal-popup-day.selected .pd-num { color:#fdfaf4; }

.cal-popup-day .pd-count {
  min-width:15px; height:15px; padding:0 4px; border-radius:8px;
  background:var(--cal-brass); color:#fff;
  font-size:9.5px; font-weight:800; line-height:15px; text-align:center;
}
.cal-popup-day .pd-count-vide { background:transparent; }
.cal-popup-day.selected .pd-count { background:#fdfaf4; color:var(--cal-espresso); }
.cal-popup-day.selected .pd-count-vide { background:transparent; }

/* ---------- Choix du mois dans l'annee ---------- */
.cal-popup-yeargrid { display:grid; grid-template-columns:repeat(3,1fr); gap:9px; }
.cal-popup-yearmonth {
  background:var(--cal-sand); border-radius:14px; padding:15px 4px; text-align:center;
  font-size:13.5px; font-weight:700; color:var(--cal-ink); cursor:pointer;
  text-transform:capitalize;
  transition:background .15s ease, transform .12s ease;
}
.cal-popup-yearmonth:hover { background:var(--cal-sand-deep); }
.cal-popup-yearmonth:active { transform:scale(0.96); }
.cal-popup-yearmonth.selected {
  background:linear-gradient(150deg, var(--cal-espresso), #8a6a3e); color:#fdfaf4;
  box-shadow:0 4px 14px rgba(74,44,29,0.28);
}
.cal-popup-yearmonth .ym-dot { width:5px; height:5px; border-radius:50%; background:var(--cal-brass); margin:6px auto 0; }
.cal-popup-yearmonth.selected .ym-dot { background:#fdfaf4; }

/* Confort : ceux qui ont demande moins d'animation n'en ont pas */
@media (prefers-reduced-motion: reduce) {
  .cal-popup, .cal-popup-overlay, .cal-popup-day, .cal-popup-nav,
  .cal-popup-yearmonth, .datebar .nav-btn2, .datebar .today-btn2 { transition:none; }
  .cal-popup { transform:none; }
}

/* ---------- Personnaliser le formulaire (ordre des champs) ---------- */
.field-order-row { display:flex; align-items:center; gap:10px; padding:10px 12px; background:white; border:1px solid #eee; border-radius:10px; margin-bottom:6px; }
.field-order-row .fo-label { flex:1; font-size:14px; font-weight:600; color:#374151; }
.field-order-row .fo-arrows { display:flex; gap:4px; }
.field-order-row .fo-arrows button { width:32px; height:32px; border:none; border-radius:8px; background:#efe7d9; color:#5a3823; font-size:15px; font-weight:700; cursor:pointer; }
.field-order-row .fo-arrows button:disabled { opacity:0.3; cursor:default; }
.field-order-row .fo-arrows button.fo-hide { background:#fee2e2; color:#b91c1c; }
.field-hidden-row { display:flex; align-items:center; gap:10px; padding:10px 12px; background:#f9fafb; border:1px dashed #d1d5db; border-radius:10px; margin-bottom:6px; }
.field-hidden-row .fo-label { flex:1; font-size:14px; color:#9ca3af; }
.field-hidden-row button { padding:7px 12px; border:none; border-radius:8px; background:#e0e7ff; color:#3730a3; font-size:12.5px; font-weight:700; cursor:pointer; }

/* ---------- Glisser-deposer fluide (deplacement d'une reservation) ---------- */
.drag-ghost {
  position: fixed;
  top: 0; left: 0;
  z-index: 999;
  pointer-events: none;
  background: #5a3823;
  color: #f4e9d8;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3);
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}
