/* ==========================================================================
   C-FOOD MODERN ENHANCEMENTS & BUG FIXES
   1. Fix Z-index mobile scroll collision (Nutriscore & badges vs sticky search bar)
   2. Fix "NON RECOMMANDÉ" badge text overlapping dish title on mobile
   3. Custom Restaurant Color Palette variables & overrides
   4. Language Switcher Floating UI
   5. Clear Error Messages & Toast Notifications
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. THEME VARIABLES (DYNAMIC RESTAURANT PALETTE)
   -------------------------------------------------------------------------- */
:root {
  --cfood-primary: #1e487c;
  --cfood-accent: #d32f2f;
  --cfood-primary-dark: #132f52;
  --cfood-accent-hover: #b71c1c;
}

/* Dynamic theming hooks for buttons and primary elements */
.cfood-themed-bg {
  background-color: var(--cfood-primary) !important;
}
.cfood-themed-accent-bg {
  background-color: var(--cfood-accent) !important;
}
.cfood-themed-text {
  color: var(--cfood-primary) !important;
}
.cfood-themed-accent-text {
  color: var(--cfood-accent) !important;
}

/* --------------------------------------------------------------------------
   2. Z-INDEX HIERARCHY & MOBILE SCROLL BUG FIX
   -------------------------------------------------------------------------- */
/* Sticky Search Bar and Category Header on Kiosk / Menu / Mobile */
.kiosk-search-container,
div:has(> input[placeholder*="Rechercher"]),
div:has(> input[placeholder*="search"]),
.sticky-top-bar,
header.sticky,
div.sticky {
  z-index: 45 !important;
  position: sticky !important;
}

/* Search bar wrapper background blur & solid mask to prevent bleeding */
div:has(> input[placeholder*="Rechercher"]),
div:has(> input[placeholder*="search"]) {
  background-color: rgba(255, 255, 255, 0.97) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.03) !important;
}

/* Dish card wrapper and contents */
.dish-card,
div[class*="rounded-"][class*="shadow-sm"],
div[class*="rounded-2xl"],
div[class*="rounded-3xl"] {
  position: relative;
  z-index: 1 !important;
}

/* Badges: Nutriscore ('A', 'B' circle) and Recommendation ('MEILLEUR CHOIX' / 'NON RECOMMANDÉ') */
.nutriscore-badge,
[class*="nutriscore"],
[class*="bg-emerald-"],
[class*="bg-amber-"],
[class*="bg-red-"],
div:has(> span:contains("MEILLEUR CHOIX")),
div:has(> span:contains("NON RECOMMANDÉ")) {
  z-index: 10 !important;
}

/* Stacking context isolation on cards */
.kiosk-dish-card,
.grid > div {
  isolation: isolate;
}

/* --------------------------------------------------------------------------
   3. MOBILE DISH BADGE & TITLE OVERLAP FIX
   -------------------------------------------------------------------------- */
@media (max-width: 640px) {
  /* Recommendation badge on mobile */
  span:has-text("MEILLEUR CHOIX"),
  span:has-text("NON RECOMMANDÉ"),
  div[class*="bg-amber"],
  div[class*="bg-red"],
  div[class*="bg-orange"] {
    max-width: 90% !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
    overflow: hidden !important;
    font-size: 0.65rem !important;
    line-height: 1.1 !important;
    padding: 3px 6px !important;
  }

  /* Ensure dish name doesn't collide with the badge above it */
  .dish-title,
  h3[class*="font-display"],
  h4[class*="font-display"],
  h3.uppercase,
  h4.uppercase {
    margin-top: 6px !important;
    line-height: 1.25 !important;
    word-break: break-word !important;
    font-size: 0.85rem !important;
    clear: both !important;
  }
}

/* --------------------------------------------------------------------------
   4. LANGUAGE SWITCHER WIDGET (FR / EN)
   -------------------------------------------------------------------------- */
#cfood-lang-switcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 99999;
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 9999px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.04);
  padding: 4px;
  gap: 2px;
  user-select: none;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

#cfood-lang-switcher:hover {
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
  transform: translateY(-2px);
}

.cfood-lang-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 9999px;
  border: none;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cfood-lang-btn.active {
  background: var(--cfood-primary, #1e487c);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(30, 72, 124, 0.3);
}

.cfood-lang-flag {
  font-size: 14px;
  line-height: 1;
}

@media (max-width: 640px) {
  #cfood-lang-switcher {
    bottom: 80px; /* Above mobile bottom bar/cart */
    right: 14px;
    padding: 3px;
  }
  .cfood-lang-btn {
    padding: 5px 9px;
    font-size: 11px;
  }
}

/* --------------------------------------------------------------------------
   5. TOAST NOTIFICATIONS & FORM ERROR STYLING
   -------------------------------------------------------------------------- */
#cfood-toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  z-index: 999999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.cfood-toast {
  pointer-events: auto;
  min-width: 300px;
  max-width: 440px;
  padding: 14px 18px;
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16), 0 2px 6px rgba(0, 0, 0, 0.06);
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  animation: cfoodToastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.cfood-toast.toast-error {
  background: #ffffff;
  color: #1e293b;
  border-left: 5px solid #ef4444;
  border-top: 1px solid #fee2e2;
  border-right: 1px solid #fee2e2;
  border-bottom: 1px solid #fee2e2;
}

.cfood-toast.toast-success {
  background: #ffffff;
  color: #1e293b;
  border-left: 5px solid #10b981;
  border-top: 1px solid #d1fae5;
  border-right: 1px solid #d1fae5;
  border-bottom: 1px solid #d1fae5;
}

.cfood-toast-icon {
  font-size: 20px;
  line-height: 1;
  margin-top: 1px;
}

.cfood-toast.toast-error .cfood-toast-icon {
  color: #ef4444;
}

.cfood-toast.toast-success .cfood-toast-icon {
  color: #10b981;
}

.cfood-toast-content {
  flex: 1;
}

.cfood-toast-title {
  font-weight: 700;
  margin-bottom: 3px;
  font-size: 14px;
}

.cfood-toast-close {
  background: none;
  border: none;
  color: #94a3b8;
  cursor: pointer;
  font-size: 16px;
  padding: 0;
  margin-left: 4px;
  line-height: 1;
}
.cfood-toast-close:hover {
  color: #475569;
}

@keyframes cfoodToastIn {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.96);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Invalid form input highlight */
.cfood-input-error {
  border: 2px solid #ef4444 !important;
  background-color: #fef2f2 !important;
  animation: cfoodShake 0.4s ease;
}

@keyframes cfoodShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* --------------------------------------------------------------------------
   6. ADMIN COLOR PALETTE SETTINGS PANEL
   -------------------------------------------------------------------------- */
.cfood-palette-card {
  background: #ffffff;
  border-radius: 20px;
  padding: 28px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
  border: 1px solid #e2e8f0;
  margin-top: 24px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.cfood-palette-title {
  font-size: 18px;
  font-weight: 800;
  color: #0f172a;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.cfood-palette-desc {
  font-size: 13.5px;
  color: #64748b;
  margin-bottom: 22px;
  line-height: 1.5;
}

.cfood-presets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.cfood-preset-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1.5px solid #e2e8f0;
  background: #f8fafc;
  cursor: pointer;
  transition: all 0.2s ease;
}

.cfood-preset-chip:hover {
  border-color: #cbd5e1;
  background: #ffffff;
  transform: translateY(-1px);
}

.cfood-preset-chip.active {
  border-color: var(--cfood-primary, #1e487c);
  background: #ffffff;
  box-shadow: 0 4px 12px rgba(30, 72, 124, 0.12);
}

.cfood-preset-dots {
  display: flex;
  gap: 4px;
}

.cfood-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.cfood-preset-name {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.cfood-pickers-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
  padding: 20px;
  background: #f8fafc;
  border-radius: 16px;
}

.cfood-picker-group label {
  display: block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
  margin-bottom: 8px;
}

.cfood-picker-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cfood-picker-controls input[type="color"] {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  background: none;
  padding: 0;
}

.cfood-hex-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #cbd5e1;
  border-radius: 10px;
  font-family: monospace;
  font-size: 14px;
  font-weight: 600;
  color: #0f172a;
  background: #ffffff;
  text-transform: uppercase;
}

.cfood-palette-preview {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--cfood-primary, #1e487c), var(--cfood-primary-dark, #132f52));
  color: #ffffff;
  margin-bottom: 24px;
}

.cfood-preview-badge {
  background: var(--cfood-accent, #d32f2f);
  color: #ffffff;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.cfood-save-palette-btn {
  background: var(--cfood-primary, #1e487c);
  color: #ffffff;
  padding: 12px 26px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(30, 72, 124, 0.25);
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.cfood-save-palette-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(30, 72, 124, 0.35);
}
