:root {
  /* Palette Moderne & Douce */
  --primary-color: #3aaeb0; /* Bleu plus vibrant */
  --primary-hover: #3c247e;
  --success-color: #00daa1;
  --danger-color: #ef4444;
  --warning-color: #ffc875;
  
  --bg-color: #e8eef2; /* Gris clair moderne */
  --card-bg: #ffffff;
  
  /* Thème Tiroir Caisse (Plastique Sombre) */
  --drawer-frame: #1f2937; 
  --drawer-bg: #111827;
  --compartment-bg: #374151;
  --compartment-inset: rgba(0, 0, 0, 0.5);
  
  --text-main: #0a1026;
  --text-muted: #6b7280;
  --border-color: #e5e7eb;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

div.algo {
  margin: 0;
  padding: 20px;
  color: var(--text-main);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-container {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  height: 100%;
  width: 100%;
}

/* --- TOP PANEL --- */
.top-panel {
  background: var(--card-bg);
  padding: 12px 24px;
  border-radius: 12px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border: 1px solid var(--border-color);
}

.left-controls { display: flex; align-items: center; gap: 20px; }

.radio-group { 
  display: flex; 
  background: #f3f4f6; 
  border-radius: 8px; 
  padding: 3px; 
  border: 1px solid var(--border-color);
}
.radio-label { 
  padding: 6px 16px; 
  border-radius: 6px; 
  cursor: pointer; 
  font-size: 13px; 
  font-weight: 500;
  transition: all 0.2s ease;
  color: var(--text-muted);
}
.radio-label input { display: none; }
.radio-label:has(input:checked) { 
  background: white; 
  color: var(--primary-color); 
  box-shadow: 0 1px 2px rgba(0,0,0,0.1); 
  font-weight: 600;
}

.finance-stats { 
  display: flex; 
  gap: 25px; 
  font-size: 14px; 
  color: var(--text-main);
}
.finance-item strong { color: var(--primary-color); font-weight: 700; }

.timer-group { 
  display: flex; 
  gap: 20px; 
  font-variant-numeric: tabular-nums; 
  font-weight: 600; 
  color: var(--text-main);
}
.timer-display { display: none; background: #fee2e2; color: #991b1b; padding: 4px 8px; border-radius: 4px; font-size: 13px; }
.timer-display.visible { display: flex; align-items: center; gap: 6px; }

/* --- GAME AREA --- */
.game-area {
  display: flex;
  gap: 25px;
  flex: 1;
  min-height: 0; 
}

/* Left: Ticket & Client */
.left-column {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex-shrink: 0;
}

/* TICKET DESIGN AMÉLIORÉ */
.ticket-wrapper {
  background: white;
  padding: 20px;
  box-shadow: var(--shadow-md);
  font-family: 'Courier New', Courier, monospace; /* Style ticket */
  font-size: 13px;
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  /* Effet papier coupé */
  mask-image: linear-gradient(to bottom, black calc(100% - 10px), transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, black calc(100% - 10px), transparent 100%);
}
/* Dents de scie en bas (CSS pur) */
.ticket-wrapper::after {
  content: "";
  position: absolute;
  bottom: -10px; left: 0; right: 0;
  height: 20px;
  background: linear-gradient(135deg, transparent 50%, white 50%), linear-gradient(45deg, white 50%, transparent 50%);
  background-size: 20px 20px;
  background-repeat: repeat-x;
  transform: translateY(-50%) rotate(180deg);
  z-index: 1;
}

.ticket-header { 
  text-align: center; 
  border-bottom: 1px dashed #d1d5db; 
  padding-bottom: 15px; 
  margin-bottom: 15px; 
}
.ticket-header h3 { 
  margin: 0; font-size: 18px; letter-spacing: 2px; text-transform: uppercase; color: #111; 
}
.ticket-info { display: flex; justify-content: center; color: #666; font-size: 11px; margin-top: 8px; }

#ticket-items { 
  flex: 1; 
  overflow-y: auto; 
  display: flex; 
  flex-direction: column; 
  gap: 8px; 
  padding-right: 5px;
  /* Scrollbar fine */
  scrollbar-width: thin;
}

.ticket-row { display: flex; justify-content: space-between; align-items: baseline; }
.item-name { font-weight: 600; color: #333; }
.item-price { color: #111; }

.ticket-total-section { 
  border-top: 2px dashed #111; 
  margin-top: 15px; 
  padding-top: 10px; 
  margin-bottom: 10px;
}
.ticket-line { display: flex; justify-content: space-between; margin-bottom: 6px; }
.ticket-line span:first-child { font-weight: 600; }
.sub-info { color: #666; font-size: 12px; }

/* MISE EN AVANT DU RENDU SUR LE TICKET */
.ticket-rendu-highlight {
  display: flex; 
  justify-content: space-between;
  margin-top: 8px;
  background: #f3f4f6;
  padding: 8px 5px;
  border-radius: 4px;
  font-weight: 800;
  font-size: 15px;
  color: #111;
  border: 1px dashed #9ca3af;
}

/* ZONE CLIENT */
.client-money-zone {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 15px;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  position: relative;
}
.zone-label { 
  font-size: 11px; 
  font-weight: 700; 
  text-transform: uppercase; 
  letter-spacing: 0.5px; 
  color: var(--text-muted); 
  margin-bottom: 12px;
}
#visuel-donne-client { 
  display: flex; 
  flex-wrap: wrap; 
  gap: 12px; 
  justify-content: center; 
  align-items: center;
  flex: 1;
}

/* ZONE FEEDBACK UNIFIÉE */
.feedback-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 60px; /* Réserve l'espace */
}

/* MODIFICATION: Messages flash statiques (dans le flux) */
.flash-msg {
  position: static; /* Plus fixed */
  transform: none;
  width: auto;
  box-shadow: var(--shadow-sm);
  padding: 12px 16px;
  margin-bottom: 0;
  opacity: 0;
  display: none; /* JS gère le display */
  animation: fadeIn 0.3s forwards;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.flash-vert { background: var(--success-color); color: white; }
.flash-violet { background: #3c247e; color: white; }


/* Right: Caisse (TIROIR UX EXPERT) */
.caisse-container {
  flex: 1;
  background: var(--drawer-frame); /* Cadre sombre */
  border-radius: 16px;
  padding: 20px;
  box-shadow: 
    inset 0 1px 1px rgba(255,255,255,0.1), /* Highlight top */
    0 20px 25px -5px rgba(0, 0, 0, 0.3); /* Grosse ombre portée */
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  border: 1px solid #111;
}

.caisse-section {
  background: var(--drawer-bg);
  padding: 15px;
  border-radius: 12px;
  box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.6); /* Profondeur globale */
}

.caisse-row {
  display: flex;
  gap: 12px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

#zone-pieces .pile-wrapper { width: 68px; }
#zone-billets .pile-wrapper { width: 96px; }

/* Le compartiment individuel */
.pile-wrapper {
  background: var(--compartment-bg);
  /* Forme moulée */
  border-radius: 4px 4px 20px 20px; 
  padding: 25px 5px 8px 5px; /* Place pour bouton ask */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end; /* Monnaie au fond */
  height: 130px;
  position: relative;
  transition: all 0.2s;
  /* Effet de creux marqué */
  box-shadow: 
    inset 0 -10px 20px rgba(0,0,0,0.5), /* Ombre fond */
    inset 0 2px 5px rgba(0,0,0,0.4), /* Ombre bords */
    0 1px 0 rgba(255,255,255,0.05); /* Eclat bord extérieur */
  border: 1px solid rgba(0,0,0,0.3);
}

.pile-wrapper:active { transform: scale(0.98); }

.stock-label {
  font-size: 10px;
  font-weight: 600;
  color: #9ca3af;
  margin-top: 8px;
  background: rgba(0,0,0,0.6);
  padding: 2px 8px;
  border-radius: 10px;
  pointer-events: none;
}
.stock-empty { color: #ef4444; background: rgba(239, 68, 68, 0.1); }

.btn-ask {
  background-color: rgba(255,255,255,0.05)!important;
  border: 1px solid rgba(255,255,255,0.1)!important;
  color: white!important;
  width: 24px; height: 24px!important;
  border-radius: 50px!important;
  font-size: 10px!important;
  cursor: pointer!important;
  position: absolute!important;
  top: 6px; left: 50%; transform: translateX(-50%)!important;
  display: flex; align-items: center!important; 
  justify-content: center!important;
  transition: all 0.2s!important;
}
.btn-ask:hover { 
  background: var(--primary-color)!important; 
  border-color: var(--primary-color)!important;
  color: white!important; 
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.5)!important;
}

.badge-taken {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--primary-color);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,0.3);
  z-index: 10;
  cursor: pointer;
  border: 2px solid var(--drawer-bg); /* Bordure pour détacher */
  animation: popIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

/* === VISUELS ARGENT (SKEUOMORPHISME) === */
.visuel-item {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  user-select: none;
  transition: transform 0.1s;
  cursor: pointer;
  flex-shrink: 0; /* CRUCIAL: Empêche l'écrasement */
}
.visuel-item:hover { transform: translateY(-4px) scale(1.05); z-index: 5; }
.visuel-item:active { transform: scale(0.95); }

/* Pièces Réalistes */
.piece {
  width: 48px; height: 48px;
  border-radius: 50%;
  font-size: 14px;
  box-shadow: 
    inset 0 0 4px rgba(255,255,255,0.4), /* Reflet */
    inset 0 0 0 1px rgba(0,0,0,0.1), /* Cerclage fin */
    0 4px 6px rgba(0,0,0,0.3); /* Ombre portée */
  text-shadow: 0 1px 1px rgba(255,255,255,0.4);
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
/* Stries sur les bords pour effet métal */
.piece::before {
  content: ''; position: absolute; top: 2px; left: 2px; right: 2px; bottom: 2px;
  border-radius: 50%; border: 1px dashed rgba(0,0,0,0.1);
}

/* Modif: Suppression marges négatives pour éviter le collage */
.mini-piece { width: 32px; height: 32px; font-size: 10px; margin: 0; box-shadow: 0 2px 3px rgba(0,0,0,0.2); border-radius: 50%; }

/* Couleurs Métaux */
.bronze { 
  background: radial-gradient(circle at 30% 30%, #e6a57e, #bf7650);
  color: #5c2812; 
  border: 2px solid #a35d36;
}
.argent { 
  background: radial-gradient(circle at 30% 30%, #f3f4f6, #9ca3af);
  color: #374151; 
  border: 2px solid #d1d5db;
}
.dore { 
  /* Or Nordique (10, 20, 50 centimes) - Jaune ambré */
  background: radial-gradient(circle at 30% 30%, #fbbf24, #d97706);
  color: #451a03;
  border: 2px solid #b45309;
}

/* Billets Réalistes (Couleurs Officielles Euro) */
.billet {
  width: 86px; height: 48px;
  border-radius: 3px;
  color: white;
  font-size: 16px;
  font-family: 'Segoe UI', sans-serif;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5); /* Ombre texte renforcée */
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.1);
}
/* Filigrane simulé */
.billet::after {
  content: '€'; position: absolute; right: -5px; bottom: -10px;
  font-size: 40px; opacity: 0.15; font-weight: bold; color: black;
}

.mini-billet { width: 50px; height: 28px; font-size: 11px; margin: 0; }

/* Couleurs Billets Officielles */
.b5 { 
  /* Gris (Classic Grey) */
  background: linear-gradient(135deg, #b0b3b3 0%, #7d8181 100%); 
  color: #1f2937; /* Texte sombre pour gris clair */
  text-shadow: none;
}
.b10 { 
  /* Rouge (Prism Red) */
  background: linear-gradient(135deg, #ff7a7a 0%, #d63031 100%); 
}
.b20 { 
  /* Bleu (Gothic Blue) */
  background: linear-gradient(135deg, #74b9ff 0%, #0984e3 100%); 
}
.b50 { 
  /* Ocre (Renaissance Orange) */
  background: linear-gradient(135deg, #f0cca4 0%, #e17055 100%); 
  /* Correction Ocre plus fidèle */
  background: linear-gradient(135deg, #ffc048 0%, #d35400 100%);
}
.b100 { 
  /* Vert (Baroque Green) */
  background: linear-gradient(135deg, #55efc4 0%, #00b894 100%); 
}
.b200 { 
  /* Jaune-Brun (Rococo Yellow) */
  background: linear-gradient(135deg, #ffeaa7 0%, #fdcb6e 100%); 
  color: #444; text-shadow: none;
}
.b500 { 
  /* Violet (Modern Purple) */
  background: linear-gradient(135deg, #a29bfe 0%, #3c247e 100%); 
}


/* --- FOOTER (Zone Rendu) --- */
.footer-actions {
  background: white;
  border-top: 1px solid var(--border-color);
  padding: 15px 30px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  box-shadow: 0 -5px 20px rgba(0,0,0,0.05);
  z-index: 100;
  border-radius: 16px 16px 0 0; /* Arrondi moderne */
}

.footer-left { display: flex; align-items: center; gap: 30px; flex: 1; overflow: hidden; }

.rendu-label-group { display: flex; flex-direction: column; align-items: flex-start; min-width: 80px; }
.lbl-prepare { font-size: 10px; text-transform: uppercase; color: #9ca3af; font-weight: 800; letter-spacing: 1px; }
.val-prepare { font-size: 28px; font-weight: 800; color: var(--primary-color); letter-spacing: -1px; }

.rendu-visuels-row {
  display: flex;
  align-items: center;
  gap: 12px; /* Espacement augmenté */
  overflow-x: auto;
  padding: 10px 5px;
  max-width: 100%;
  scrollbar-width: none; /* Cache scrollbar */
}

.footer-right { display: flex; gap: 20px; align-items: center; }

.mini-stats { 
  display: flex; gap: 8px; 
  background: #f3f4f6; 
  padding: 6px 12px; 
  border-radius: 20px; 
  border: 1px solid #e5e7eb;
}
.mini-stat-item { 
  display: flex; align-items: center; gap: 6px; 
  font-size: 13px; font-weight: 700; 
  padding: 2px 6px;
}
.ms-vert { color: var(--success-color); }
.ms-bleu { color: var(--primary-color); }
.ms-violet { color: #3c247e; }

.btn-group { display: flex; gap: 12px; }
.btn { 
  border: none!important; 
  padding: 12px 24px!important; 
  border-radius: 8px!important; 
  cursor: pointer!important; 
  font-size: 14px!important; 
  font-weight: 600!important; 
  display: flex!important; align-items: center!important; gap: 8px!important; 
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1)!important;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1)!important;
}
.btn:hover { transform: translateY(-2px)!important; box-shadow: 0 4px 8px rgba(0,0,0,0.15)!important; }
.btn:active { transform: translateY(0)!important; }

.btn-primary { background: var(--primary-color)!important; color: white!important; }
.btn-primary:hover { background: var(--primary-hover)!important; }
.btn-warning { background: var(--warning-color); color: white!important; }
.btn-success { background: var(--success-color); color: white!important; }
.btn-icon-only { padding: 12px!important; }


/* --- FEEDBACK TOASTS --- */
.feedback-toast {
  padding: 12px; margin-top: 10px; border-radius: 6px; font-size: 13px;
  animation: slideDown 0.3s ease-out;
}
.fb-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.fb-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.fb-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

.helper-zone {
  display: none;
  background: #f3f4f6;
  color: #1f2937;
  padding: 12px;
  margin-top: 10px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid #e5e7eb;
  box-shadow: var(--shadow-sm);
}

/* Classes utilisées depuis le JavaScript (extraction des styles inline) */
.helper-zone.visible { display: block; }
.feedback-toast.visible { display: block; }
.flash-msg.show { display: flex; opacity: 1; }
.empty { opacity: 0.4; cursor: not-allowed; }
.clickable { cursor: pointer; }
.mini-small { font-size: 10px; }
.icon-error { color: #d63031; }
.icon-hint { color: #856404; }
.icon-warn { color: orange; }
.icon-small { font-size: 9px; }
.icon-check { color: var(--success-color); }
.icon-times { color: #3c247e;}
.ticket-change-missing { color: #d63031; font-weight: 700; }

@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }


/* ==========================================================================
   RESPONSIVE DESIGN (BREAKPOINTS 1024px & 767px)
   ========================================================================== */

/* --- TABLETTE / PETIT DESKTOP (<= 1024px) --- */
@media (max-width: 1024px) {
  .left-column { width: 260px; }
  .game-area { gap: 15px; }
  
  /* Compactage tiroir */
  #zone-pieces .pile-wrapper { width: 58px; height: 100px; }
  #zone-billets .pile-wrapper { width: 80px; height: 100px; }
  .piece { width: 40px; height: 40px; font-size: 12px; }
  .billet { width: 70px; height: 40px; font-size: 14px; }
  
  .val-prepare { font-size: 22px; }
  .btn { padding: 10px 18px!important; }
}

/* --- MOBILE (<= 767px) --- */
@media (max-width: 767px) {
  div.algo {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
    padding: 10px;
    background: #f0f2f5;
  }

  .main-container { gap: 10px; }

  /* TOP PANEL */
  .top-panel {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding: 15px;
  }
  .left-controls, .finance-stats, .timer-group {
    width: 100%;
    justify-content: space-between;
  }

  /* LAYOUT VERTICAL */
  .game-area { flex-direction: column; height: auto; gap: 10px; }
  .left-column { width: 100%; }
  
  #ticket-items { max-height: 180px; } /* Ticket moins haut */

  /* CAISSE MOBILE */
  .caisse-container {
    width: 100%;
    height: 450px; /* Scrollable */
    padding: 10px;
    background: #1f2937;
  }
  .caisse-row { justify-content: center; gap: 8px; }
  
  #zone-pieces .pile-wrapper { width: 60px; }
  #zone-billets .pile-wrapper { width: 85px; }

  /* FOOTER STICKY */
  .footer-actions {
    position: sticky;
    bottom: 0;
    flex-direction: column;
    gap: 12px;
    padding: 15px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
  }

  .footer-left { width: 100%; justify-content: space-between; }
  .rendu-visuels-row { max-width: 180px; }
  
  .footer-right { width: 100%; }
  .mini-stats { display: none; }
  .btn-group { flex: 1!important; }
  .btn-primary { flex: 1!important; justify-content: center!important; }
  
  /* Feedback mobile aussi dans le flux */
  .flash-msg {
    position: static;
    transform: none;
    width: auto;
    text-align: left;
    margin-bottom: 10px;
  }
}

/* Desktop: limiter la hauteur de l'application et activer le scrolling interne */
@media (min-width: 768px) {
  html, body { height: 100%; }
  div.algo { max-height: 95vh; }
  .main-container { height: 90vh; max-height: 95vh; overflow: hidden; display: flex; flex-direction: column; }
  .game-area { flex: 1; min-height: 0; overflow: auto; }
  .ticket-wrapper { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  #ticket-items { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

  /* Scrollbar styling (subtil) */
  #ticket-items::-webkit-scrollbar { width: 10px; }
  #ticket-items::-webkit-scrollbar-track { background: transparent; }
  #ticket-items::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 6px; }
}