/* ═══ FC ÉVÉNEMENT — LAYOUT ═══ */
/* ═══ RESET ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--sf);
  background: var(--bg);
  color: var(--label);
  font-size: 14px;
  line-height: 1.45;
  transition: background .2s, color .2s;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button { font-family: var(--sf); cursor: pointer; }
input, textarea, select { font-family: var(--sf); }
::-webkit-scrollbar { width: 0; height: 0; }

/* ═══ LAYOUT ═══ */
.layout {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ═══ TOPBAR ═══ */
.topbar {
  grid-column: 1 / -1;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--sep);
  display: flex;
  align-items: center;
  padding: 0 18px;
  gap: 0;
  z-index: 100;
}
[data-theme="dark"] .topbar {
  background: rgba(20,26,36,0.84);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--sf-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--label);
  flex-shrink: 0;
  padding-right: 18px;
  border-right: 1px solid var(--sep);
  margin-right: 8px;
  user-select: none;
}
.logo-mark {
  width: 34px; height: 34px;
  object-fit: contain;
  flex-shrink: 0;
}

.topbar-nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.topbar-nav::-webkit-scrollbar { display: none; }

.tnav-btn {
  padding: 5px 11px;
  height: 32px;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--label2);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex; align-items: center; gap: 5px;
  border: none;
  letter-spacing: -0.1px;
}
.tnav-btn:hover { background: var(--fill); color: var(--label); }
.tnav-btn.active { background: var(--blue); color: #fff; box-shadow: var(--shadow-sm); font-weight: 600; }

.live-pill {
  display: none;
  align-items: center;
  gap: 5px;
  background: var(--red-bg);
  border: 0.5px solid rgba(191,0,4,0.25);
  border-radius: var(--r-pill);
  padding: 4px 11px;
  font-size: 11px;
  font-weight: 600;
  color: var(--red);
  margin-left: 10px;
}
.live-pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--red); animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.3;transform:scale(.7)} }

.topbar-right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.theme-toggle {
  display: flex;
  background: var(--fill);
  border-radius: 9px;
  padding: 2px;
  gap: 1px;
}
.tt-opt {
  padding: 4px 11px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: var(--label2);
  transition: all .12s;
  border: none;
  background: transparent;
  font-family: var(--sf);
}
.tt-opt.active {
  background: var(--bg2);
  color: var(--label);
  box-shadow: 0 1px 3px rgba(0,0,0,0.10);
}

.sync-status {
  display: flex; align-items: center; gap: 5px;
  font-size: 11px; color: var(--label2);
  padding: 4px 11px;
  background: var(--fill2);
  border-radius: var(--r-pill);
}
.sync-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--label4); transition: background .3s; }
.sync-dot.ok { background: var(--green); }
.sync-dot.syncing { background: var(--orange); animation: pulse 1s infinite; }
.sync-dot.err { background: var(--red); }

/* ═══ SIDEBAR ═══ */
.sidebar {
  grid-column: 1;
  grid-row: 2;
  background: rgba(255,255,255,0.6);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-right: 1px solid var(--sep);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width .28s cubic-bezier(.4,0,.2,1);
  width: var(--sidebar-w);
  min-width: 0;
}
.sidebar.collapsed {
  width: 44px;
}
[data-theme="dark"] .sidebar {
  background: rgba(20,26,36,0.7);
}
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 6px;
  flex-shrink: 0;
  gap: 6px;
}
.sidebar-toggle-btn {
  width: 26px; height: 26px;
  border-radius: var(--r-sm);
  background: var(--fill);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .12s, transform .28s cubic-bezier(.4,0,.2,1);
  color: var(--label2);
}
.sidebar-toggle-btn:hover { background: var(--fill3); color: var(--label); }
.sidebar.collapsed .sidebar-toggle-btn { transform: rotate(180deg); }
.sidebar-title-text {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--label3);
  white-space: nowrap;
  overflow: hidden;
  opacity: 1;
  transition: opacity .15s;
}
.sidebar.collapsed .sidebar-title-text { opacity: 0; pointer-events: none; }
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 8px 12px;
  opacity: 1;
  transition: opacity .15s .08s;
}
.sidebar.collapsed .sidebar-content { opacity: 0; pointer-events: none; }
.sidebar-collapsed-hint {
  display: none;
  flex: 1;
  align-items: flex-start;
  justify-content: center;
  padding-top: 10px;
  opacity: 0;
  transition: opacity .15s .1s;
}
.sidebar.collapsed .sidebar-collapsed-hint { display: flex; opacity: 1; }
.sidebar-collapsed-dots {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-items: center;
}
.sidebar-collapsed-dots .cdot {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--label4);
}
.sidebar-collapsed-dots .cdot.done { background: var(--green); }

/* sidebar-label moved to sidebar-toggle */
.hist-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: var(--r-md);
  transition: background .12s;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.hist-item:hover { background: var(--fill2); }
.hist-item.active-history { background: var(--blue-bg); }
.hist-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--label4); flex-shrink: 0; margin-top: 4px; }
.hist-dot.done { background: var(--green); }
.hist-name { font-size: 13px; font-weight: 500; color: var(--label); line-height: 1.3; }
.hist-meta { font-size: 11px; color: var(--label3); margin-top: 1px; }

/* ═══ MAIN ═══ */
.main {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

/* ═══ START SCREEN ═══ */
.start-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg);
}
.start-card {
  background: var(--bg2);
  border: 1px solid var(--sep);
  border-radius: var(--r-2xl);
  padding: 32px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}
.start-kicker {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--blue);
  margin-bottom: 8px;
}
.start-card h2 {
  font-family: var(--sf-display);
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--label);
  margin-bottom: 5px;
}
.start-card p { font-size: 14px; color: var(--label2); margin-bottom: 22px; line-height: 1.6; }

/* ═══ MOBILE NAV ═══ */
.mobile-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: rgba(255,255,255,0.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 0.5px solid var(--sep);
  padding-bottom: env(safe-area-inset-bottom, 0);
  height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0));
}
[data-theme="dark"] .mobile-nav { background: rgba(28,28,30,0.82); }
.mobile-nav-inner { display: flex; height: var(--mobile-nav-h); }
.mnav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  border: none; background: transparent; color: var(--label3);
  cursor: pointer; font-size: 10px; font-weight: 500;
  transition: color .12s; padding: 0; font-family: var(--sf);
}
.mnav-btn.active { color: var(--blue); }
.mnav-icon { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; }
.mnav-icon svg { width: 22px; height: 22px; stroke-width: 1.8; }

/* ═══ DRAWER ═══ */
.drawer-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 150; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.drawer-overlay.open { display: block; }
.drawer {
  position: fixed; left: 0; top: 0; bottom: 0; width: 280px; z-index: 151;
  background: var(--bg2); border-right: 0.5px solid var(--sep);
  overflow-y: auto; padding: 18px 14px;
  transform: translateX(-100%);
  transition: transform .24s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column; gap: 0;
  box-shadow: 4px 0 32px rgba(0,0,0,.12);
}
.drawer.open { transform: translateX(0); }
.drawer-close {
  align-self: flex-end; background: var(--fill); border: none; color: var(--label2);
  width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font-size: 13px;
  display: flex; align-items: center; justify-content: center; margin-bottom: 8px;
}

/* ═══ LOADING / LOCK ═══ */
#loading-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
}
.spinner { width: 32px; height: 32px; border: 2.5px solid var(--sep2); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#lock-screen {
  position: fixed; inset: 0; background: var(--bg); z-index: 2000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.lock-card {
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(40px) saturate(200%);
  -webkit-backdrop-filter: blur(40px) saturate(200%);
  border: 1px solid var(--sep);
  border-radius: var(--r-2xl);
  padding: 44px 32px;
  width: 100%; max-width: 320px; text-align: center;
  box-shadow: var(--shadow-lg);
}
[data-theme="dark"] .lock-card { background: rgba(20,26,36,0.88); }
.lock-mark {
  width: 100%; max-width: 220px; height: auto; margin: 0 auto 18px;
  display: block; object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(30,22,12,0.18));
}
.lock-logo { font-family: var(--sf-display); font-size: 22px; font-weight: 700; letter-spacing: -0.4px; color: var(--label); margin-bottom: 4px; }
.lock-sub  { font-size: 13px; color: var(--label2); margin-bottom: 26px; }
.code-inputs { display: flex; gap: 10px; justify-content: center; margin-bottom: 10px; }
.code-digit {
  width: 14px; height: 14px;
  border-radius: 50%;
  border: none;
  background: var(--fill3);
  color: transparent;
  text-align: center;
  outline: none; transition: all .15s;
  caret-color: transparent;
  cursor: default;
  padding: 0;
  -webkit-appearance: none;
}
.code-digit.filled { background: var(--blue); transform: scale(1.15); }
.code-digit.error { background: var(--red); animation: shake .28s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-5px)} 75%{transform:translateX(5px)} }
.lock-attempts { font-size: 12px; color: var(--red); margin-top: 6px; min-height: 16px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 22px; max-width: 230px; margin-left: auto; margin-right: auto; }
.keypad-btn {
  width: 100%; aspect-ratio: 1; border-radius: 50%;
  border: 1px solid var(--sep); background: var(--fill2); color: var(--label);
  font-family: var(--sf-display); font-size: 19px; font-weight: 600;
  cursor: pointer; transition: all .1s; touch-action: manipulation;
}
.keypad-btn:hover { background: var(--fill3); }
.keypad-btn:active { transform: scale(.92); background: var(--blue-bg); }
.keypad-back { font-size: 16px; color: var(--label2); background: transparent; border-color: transparent; }
.keypad-back:active { background: var(--red-bg); color: var(--red); }
.keypad-spacer { pointer-events: none; }
.lock-hint { font-size: 11px; color: var(--label3); margin-top: 18px; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { grid-column: 1; }
  .mobile-nav { display: flex; flex-direction: column; }
  .toasts { bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom,0) + 10px); right: 10px; }
  .topbar-nav { display: none; }
  #sync-label { display: none; }
  .live-layout { display: block; height: 100%; overflow: hidden; }
  .paniers-zone { height: 100%; padding: 10px; padding-bottom: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom,0) + 10px); }
  .resize-handle { display: none; }
  .panier-panel { display: none; }
  .paniers-grid { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 4px; }
  .p-btn { min-height: 58px; font-size: 11px; }
  .cat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .frow { grid-template-columns: 1fr; }
  #jump-input { width: 60px !important; }
  #search-name-input { width: 110px !important; }
  .topbar { padding: 0 12px; gap: 0; }
  .topbar-right { gap: 4px; }
  .logo { font-size: 14px; gap: 7px; padding-right: 12px; }
  .logo-mark { width: 28px; height: 28px; }
  .btn { padding: 6px 11px; font-size: 12px; }
  .btn.sm { padding: 4px 9px; font-size: 11px; }
  .modal { border-radius: var(--r-xl) var(--r-xl) 0 0; max-height: 94dvh; }
  .stat-cell { padding: 10px 8px; }
  .stat-n { font-size: 22px; }
}
@media (max-width: 420px) {
  .paniers-grid { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .stat-n { font-size: 20px; }
  .logo-text { display: none; }
}
@media (min-width: 769px) {
  .mobile-sheet, .mobile-nav, .drawer, .drawer-overlay { display: none !important; }
  #drawer-toggle { display: none !important; }
  .toasts { bottom: 16px; right: 16px; }
}

/* Bouton recherche client topbar */
.cs-topbar-btn {
  display:flex; align-items:center; gap:5px;
  padding:5px 11px; height:32px; border-radius:var(--r-sm);
  border:1px solid var(--sep2); background:var(--fill2);
  color:var(--label2); font-size:12px; font-weight:600;
  cursor:pointer; transition:all .15s; font-family:var(--sf);
  flex-shrink:0;
}
.cs-topbar-btn:hover { background:var(--blue-bg); border-color:var(--blue); color:var(--blue); }
@media (max-width: 768px) { .cs-topbar-label { display:none; } }
