:root {
  --black: #17140f;
  --black-soft: #211b14;
  --cream: #f8efdd;
  --cream-dim: #6b6255;
  --paper: #ffffff;
  --paper-dim: #faf6ee;
  --border: #ece3d3;
  --red: #e8432b;
  --red-dark: #c22f1c;
  --gold: #f2b134;
  --green: #2f9e58;
  --font-display: 'Bebas Neue', sans-serif;
  --font-body: 'Inter', sans-serif;
  --radius: 14px;
}

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

body {
  font-family: var(--font-body);
  background: var(--paper-dim);
  color: var(--black);
}

a { text-decoration: none; color: inherit; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: 0.4px; }

/* ===== Login page ===== */
.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, rgba(232,67,43,0.18), transparent 45%),
              radial-gradient(circle at 80% 80%, rgba(242,177,52,0.15), transparent 45%),
              var(--black);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--paper);
  border-radius: 22px;
  padding: 44px 36px;
  box-shadow: 0 30px 70px -20px rgba(0,0,0,0.55);
}
.login-logo { font-family: var(--font-display); font-size: 2.4rem; color: var(--red); margin-bottom: 6px; }
.login-card h1 { font-family: var(--font-body); font-size: 1.15rem; font-weight: 700; margin-bottom: 24px; color: var(--black); }
.login-hint { background: var(--paper-dim); border: 1px dashed var(--border); border-radius: 10px; padding: 12px 14px; font-size: 0.8rem; color: var(--cream-dim); margin-top: 18px; }

/* ===== Form elements ===== */
.field { margin-bottom: 18px; }
.field label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: var(--black); }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border);
  font-family: var(--font-body); font-size: 0.95rem; background: var(--paper);
  transition: border-color 0.2s ease;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--red); }
.field-error { color: var(--red); font-size: 0.8rem; margin-top: 4px; }
.field-checkbox { display: flex; align-items: center; gap: 10px; }
.field-checkbox input { width: auto; }

.field-checkbox-list {
  max-height: 180px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px;
  padding: 6px 12px;
}
.field-checkbox-list .checkbox-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.field-checkbox-list .checkbox-row:last-child { border-bottom: none; }
.field-checkbox-list .checkbox-row input { width: auto; }
.field-checkbox-list .empty-note { color: var(--cream-dim); font-size: 0.85rem; padding: 8px 0; }

.map-picker {
  width: 100%; height: 280px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--border); margin-top: 4px; cursor: crosshair;
}

.image-preview-wrap {
  width: 100%; height: 140px; border-radius: 10px; border: 1px dashed var(--border);
  background: var(--paper-dim); margin-bottom: 8px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.image-preview { width: 100%; height: 100%; object-fit: cover; }
.image-preview-placeholder { color: var(--cream-dim); font-size: 0.85rem; font-weight: 600; }
.image-preview-wrap-sm { width: 90px; height: 90px; padding: 10px; }
.image-preview-wrap-sm .image-preview { object-fit: contain; }
.image-preview-wrap-sm .image-preview-placeholder { font-size: 0.7rem; text-align: center; padding: 0 6px; }

.product-thumb {
  width: 44px; height: 44px; border-radius: 8px; object-fit: cover;
  background: var(--paper-dim); border: 1px solid var(--border); display: block;
}
.product-thumb-placeholder {
  width: 44px; height: 44px; border-radius: 8px; background: var(--paper-dim);
  border: 1px solid var(--border); display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 24px; border-radius: 10px; font-weight: 700; font-size: 0.9rem;
  border: 2px solid transparent; cursor: pointer; transition: all 0.2s ease;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-block { width: 100%; }
.btn-secondary { background: var(--paper); border-color: var(--border); color: var(--black); }
.btn-secondary:hover { border-color: var(--black); }
.btn-danger { background: transparent; color: var(--red); border-color: transparent; padding: 8px 12px; }
.btn-danger:hover { background: #fdeceb; }
.btn-sm { padding: 8px 14px; font-size: 0.82rem; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.alert { padding: 12px 16px; border-radius: 10px; font-size: 0.88rem; margin-bottom: 16px; }
.alert-error { background: #fdeceb; color: var(--red-dark); border: 1px solid #f7c9c2; }
.alert-success { background: #eaf7ef; color: var(--green); border: 1px solid #c8ecd5; }

/* ===== App shell ===== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 250px; background: var(--black); color: var(--cream);
  padding: 26px 20px; display: flex; flex-direction: column; flex-shrink: 0;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-logo { font-family: var(--font-display); font-size: 1.9rem; color: var(--gold); margin-bottom: 6px; }
.sidebar-sub { font-size: 0.75rem; color: rgba(248,239,221,0.5); margin-bottom: 30px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar-nav a {
  padding: 12px 14px; border-radius: 10px; font-weight: 600; font-size: 0.92rem;
  color: rgba(248,239,221,0.75); display: flex; align-items: center; gap: 10px;
  transition: background 0.2s ease, color 0.2s ease;
}
.sidebar-nav a:hover { background: rgba(248,239,221,0.06); color: var(--cream); }
.sidebar-nav a.active { background: var(--red); color: #fff; }
.sidebar-footer { border-top: 1px solid rgba(248,239,221,0.1); padding-top: 16px; margin-top: 16px; }
.sidebar-footer .admin-email { font-size: 0.78rem; color: rgba(248,239,221,0.5); margin-bottom: 10px; word-break: break-all; }
.logout-btn {
  width: 100%; background: transparent; border: 1px solid rgba(248,239,221,0.2); color: var(--cream);
  padding: 10px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 0.85rem;
  transition: all 0.2s ease;
}
.logout-btn:hover { background: rgba(248,239,221,0.08); }

.main-content { flex: 1; min-width: 0; }
.topbar {
  padding: 22px 32px; background: var(--paper); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar h1 { font-family: var(--font-body); font-size: 1.3rem; font-weight: 800; }
.topbar p { color: var(--cream-dim); font-size: 0.88rem; margin-top: 2px; }
.content { padding: 32px; }

.mobile-topbar { display: none; }

/* ===== Cards / stats ===== */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; margin-bottom: 30px; }
.stat-card {
  background: var(--paper); border-radius: var(--radius); padding: 22px;
  border: 1px solid var(--border);
}
.stat-card .stat-value { font-family: var(--font-display); font-size: 2.2rem; color: var(--red); }
.stat-card .stat-label { color: var(--cream-dim); font-size: 0.85rem; font-weight: 600; }

.panel { background: var(--paper); border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.panel-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.panel-header h2 { font-family: var(--font-body); font-size: 1.05rem; font-weight: 800; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 14px 24px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--cream-dim); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 700; }
tbody tr:hover { background: var(--paper-dim); }
td.actions { display: flex; gap: 8px; }
.empty-row td { text-align: center; color: var(--cream-dim); padding: 40px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.badge-available { background: #eaf7ef; color: var(--green); }
.badge-unavailable { background: #f4f1ea; color: var(--cream-dim); }

.toggle {
  position: relative; width: 44px; height: 24px; border-radius: 999px; border: none;
  background: #ddd6c6; cursor: pointer; transition: background 0.2s ease; flex-shrink: 0;
}
.toggle.on { background: var(--green); }
.toggle::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform 0.2s ease;
}
.toggle.on::after { transform: translateX(20px); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(23,20,15,0.55); backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 20px;
  overflow-y: auto; z-index: 200;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--paper); border-radius: 20px; width: 100%; max-width: 520px;
  padding: 30px; box-shadow: 0 40px 80px -20px rgba(0,0,0,0.5);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.modal-header h2 { font-family: var(--font-body); font-size: 1.15rem; font-weight: 800; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--cream-dim); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 16px; }

/* ===== Toast ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 300; }
.toast {
  padding: 14px 20px; border-radius: 12px; color: #fff; font-weight: 600; font-size: 0.9rem;
  box-shadow: 0 12px 30px -10px rgba(0,0,0,0.4); animation: toast-in 0.25s ease;
  max-width: 320px;
}
.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.page-actions { display: flex; gap: 10px; }
.hidden { display: none !important; }

/* ===== Responsive ===== */
.mobile-menu-btn {
  background: none; border: 1px solid rgba(248,239,221,0.25); color: var(--cream);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font-size: 1rem;
}
.mobile-nav-dropdown {
  display: none; flex-direction: column; gap: 4px; background: var(--black-soft);
  padding: 12px; position: sticky; top: 57px; z-index: 49; border-bottom: 1px solid rgba(248,239,221,0.1);
}
.mobile-nav-dropdown.open { display: flex; }
.mobile-nav-dropdown a { padding: 12px 14px; border-radius: 10px; color: rgba(248,239,221,0.8); font-weight: 600; font-size: 0.92rem; }
.mobile-nav-dropdown a.active { background: var(--red); color: #fff; }
.mobile-nav-dropdown button.logout-btn { margin-top: 6px; }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar { display: none; }
  .mobile-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--black); color: var(--cream); padding: 16px 20px; position: sticky; top: 0; z-index: 50;
  }
  .mobile-topbar .sidebar-logo { margin: 0; font-size: 1.5rem; }
  .content { padding: 20px; }
  .topbar { padding: 18px 20px; flex-wrap: wrap; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
}

/* ===== Ticket de caisse (impression) ===== */
#printTicket { display: none; }
.print-ticket {
  font-family: 'Courier New', monospace; width: 300px; margin: 0 auto;
  font-size: 12px; color: #000; line-height: 1.5;
}
.print-ticket h2 { font-family: 'Courier New', monospace; text-align: center; font-size: 18px; letter-spacing: 2px; margin-bottom: 2px; }
.print-ticket .center { text-align: center; }
.print-ticket .divider { border-top: 1px dashed #000; margin: 8px 0; }
.print-ticket .row { display: flex; justify-content: space-between; gap: 10px; }
.print-ticket .sale-line { margin-bottom: 6px; }
.print-ticket .sale-line .row span:first-child { white-space: nowrap; }

@media print {
  /* "visibility: hidden" laisse les éléments occuper leur place dans la mise en page :
     la longue page admin derrière le ticket générait des pages blanches supplémentaires
     à l'impression. "display: none" les retire complètement du flux. */
  body > *:not(#printTicket) { display: none !important; }
  #printTicket { display: block !important; }
  @page { margin: 10mm; size: auto; }
}
