/* ═══════════════════════════════════════════════════════════════════
   Choiceasy Brand — Design Tokens + Core Components
   Used by all storefront pages. Palette/type sourced from the Session 2.5
   design system (design-tokens.css) — values remapped onto these existing
   variable names so every page picks up the rebrand without a rebuild.
   ═══════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Serif+Display:ital@0;1&family=Cormorant+Garamond:ital,wght@0,500;0,600;0,700;1,500;1,600&display=swap');

:root {
  /* Brand palette — matches the live brand_settings row (id=1) as of the
     Session 6.1 bronze polish. brand-loader.js overrides these dynamically
     at runtime; these are the fallback if that fetch is slow or fails, so
     they must stay in sync with the DB, not an earlier launch palette. */
  --brand-primary:       #7A6543;    /* Choiceasy warm bronze */
  --brand-primary-dark:  #5F4E30;
  --brand-primary-light: #9b8c72;
  --brand-accent:        #cbb89a;    /* warm beige */
  --brand-accent-dark:   #a2937b;

  /* Neutrals */
  --color-bg:            #F4EFE6;
  --color-surface:       #FDFBF6;
  --color-surface-alt:   #E8E1D0;
  --color-text:          #2C2620;
  --color-text-muted:    #5C5347;
  --color-text-subtle:   #8B7F65;
  --color-border:        #E2DDD8;
  --color-border-strong: #cdc6bc;

  /* Semantic */
  --color-success:       #166534;
  --color-warning:       #92400e;
  --color-error:         #991b1b;
  --color-info:          #1e40af;

  /* Typography */
  --font-serif:  'Cormorant Garamond', Georgia, "Times New Roman", serif;
  --font-sans:   'DM Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-arabic: "Noto Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;

  /* Spacing scale (4px base) */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --sp-12: 48px; --sp-16: 64px; --sp-20: 80px;

  /* Radius */
  --rad-sm: 4px; --rad-md: 8px; --rad-lg: 14px; --rad-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.09);

  /* Layout */
  --max-w:          1280px;
  --header-h:       72px;
  --nav-h:          48px;
  --transition:     180ms ease;
}

/* RTL overrides — applied when <html dir="rtl"> */
html[dir="rtl"] { font-family: var(--font-arabic); }
html[dir="rtl"] body { direction: rtl; text-align: right; }

/* ── Reset + base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; max-width: 100%; overflow-x: hidden; }
body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--brand-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--font-serif); font-weight: 400; margin: 0 0 var(--sp-4); }
h1 { font-size: 2rem; line-height: 1.2; }
h2 { font-size: 1.5rem; line-height: 1.3; }
h3 { font-size: 1.25rem; line-height: 1.35; }
button { font-family: inherit; cursor: pointer; }

.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 0 var(--sp-4);
}
@media (min-width: 768px) { .container { padding: 0 var(--sp-6); } }

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-6);
  border-radius: var(--rad-md);
  border: 1px solid transparent;
  font-size: 0.95rem; font-weight: 600;
  text-decoration: none; cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary  { background: var(--brand-primary); color: #fff; }
.btn-primary:hover  { background: var(--brand-primary-dark); text-decoration: none; }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-surface-alt); text-decoration: none; }
.btn-accent   { background: var(--brand-accent); color: #fff; }
.btn-accent:hover   { background: var(--brand-accent-dark); text-decoration: none; }
.btn-ghost    { background: transparent; color: var(--color-text); }
.btn-ghost:hover    { background: var(--color-surface-alt); text-decoration: none; }
.btn-lg       { padding: var(--sp-4) var(--sp-8); font-size: 1rem; }
.btn-sm       { padding: var(--sp-2) var(--sp-4); font-size: 0.875rem; }
.btn-block    { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Header ─────────────────────────────────────────────────── */
.cef-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  height: var(--header-h);
}
.cef-header-inner {
  height: 100%;
  display: flex; align-items: center; gap: var(--sp-6);
}
.cef-logo {
  font-family: var(--font-serif); font-size: 1.4rem; font-weight: 400;
  color: var(--color-text);
}
.cef-logo .dot { color: var(--brand-primary); }
.cef-search {
  flex: 1; max-width: 500px;
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: var(--color-surface-alt);
  border-radius: var(--rad-md);
  border: 1px solid var(--color-border);
}
.cef-search input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 0.95rem; color: var(--color-text);
  font-family: inherit;
}
.cef-header-actions { display: flex; align-items: center; gap: var(--sp-3); margin-inline-start: auto; }
.cef-icon-btn {
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--rad-md); border: none;
  background: transparent; color: var(--color-text);
  cursor: pointer; position: relative;
}
.cef-icon-btn:hover { background: var(--color-surface-alt); }

.cef-portal-menu { position: relative; }
.cef-portal-menu summary { list-style: none; }
.cef-portal-menu summary::-webkit-details-marker { display: none; }
.cef-portal-btn { width: auto; padding: 0 var(--sp-3); gap: 6px; border: 1px solid var(--color-border-strong); border-radius: 99px; }
.cef-portal-btn-label { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.cef-portal-caret { opacity: 0.6; flex-shrink: 0; }
@media (max-width: 700px) { .cef-portal-btn-label { display: none; } .cef-portal-btn { padding: 0; border-radius: var(--rad-md); border: none; } }
.cef-portal-dropdown {
  position: absolute; top: calc(100% + 8px); inset-inline-end: 0; min-width: 260px;
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--rad-lg);
  box-shadow: var(--shadow-lg); padding: var(--sp-2); z-index: 100;
}
.cef-portal-item { display: block; padding: var(--sp-3); border-radius: var(--rad-md); text-decoration: none; color: var(--color-text); }
.cef-portal-item:hover { background: var(--color-surface-alt); }
.cef-portal-item strong { display: block; font-size: 0.9rem; }
.cef-portal-item span { display: block; font-size: 0.78rem; color: var(--color-text-muted); margin-top: 2px; }
@media (max-width: 767px) {
  .cef-portal-dropdown { position: fixed; inset: auto 12px 12px 12px; border-radius: var(--rad-lg); }
}
.cef-icon-badge {
  position: absolute; top: 4px; inset-inline-end: 4px;
  background: var(--brand-primary); color: #fff;
  min-width: 18px; height: 18px; border-radius: 9px;
  font-size: 0.7rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 var(--sp-1);
}

@media (max-width: 640px) {
  :root { --header-h: 112px; }
  .cef-header { height: auto; padding: var(--sp-2) 0; }
  .cef-header-inner { flex-wrap: wrap; row-gap: var(--sp-2); gap: var(--sp-2); }
  .cef-logo { order: 1; }
  .cef-header-actions { order: 2; margin-inline-start: auto; gap: var(--sp-1); }
  .cef-search { order: 3; flex: 1 1 100%; max-width: none; }
  .cef-lang-toggle { padding: 1px; }
  .cef-lang-btn { padding: 3px 7px; font-size: 0.72rem; }
  .cef-icon-btn { width: 36px; height: 36px; }

  /* Clearance so the floating chat bubble never sits on top of page-bottom
     content (e.g. the cart/checkout total) on short mobile pages. */
  main.container, main { padding-bottom: max(var(--sp-8), 84px); }
}

/* Language toggle */
.cef-lang-toggle {
  display: inline-flex;
  background: var(--color-surface-alt);
  border-radius: var(--rad-md);
  padding: 2px;
}
.cef-lang-btn {
  padding: 4px 10px;
  border: none; background: transparent;
  border-radius: var(--rad-sm);
  font-size: 0.8rem; font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
}
.cef-lang-btn.active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }

/* ── Nav ─────────────────────────────────────────────────────── */
.cef-nav {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  height: var(--nav-h);
}
.cef-nav-inner { height: 100%; display: flex; align-items: center; gap: var(--sp-5); overflow-x: auto; }
.cef-nav-link {
  color: var(--color-text); font-size: 0.9rem; font-weight: 500;
  white-space: nowrap;
}
.cef-nav-link:hover { color: var(--brand-primary); text-decoration: none; }

/* ── Product card ───────────────────────────────────────────── */
.product-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--rad-md);
  overflow: hidden;
  transition: var(--transition);
  display: flex; flex-direction: column;
}
.product-card:hover { border-color: var(--color-border-strong); box-shadow: var(--shadow-md); }
.product-card-img {
  aspect-ratio: 1 / 1;
  background: var(--color-surface-alt);
  overflow: hidden;
  position: relative;
}
.product-card-img img {
  width: 100%; height: 100%; object-fit: cover;
  transition: transform 300ms ease;
}
.product-card:hover .product-card-img img { transform: scale(1.04); }
.product-card-body { padding: var(--sp-3) var(--sp-4) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); flex: 1; }
.product-card-provider { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-subtle); }
.product-card-name { font-size: 0.95rem; font-weight: 500; line-height: 1.35; color: var(--color-text); margin: 0; min-height: 2.6em; }
.product-card-price { font-size: 1.05rem; font-weight: 700; color: var(--color-text); }
.product-card-price-old { text-decoration: line-through; color: var(--color-text-subtle); font-weight: 400; font-size: 0.85rem; margin-inline-start: var(--sp-2); }
.product-badge {
  position: absolute; top: var(--sp-2); inset-inline-start: var(--sp-2);
  background: var(--brand-accent); color: #fff;
  padding: 2px 8px; border-radius: var(--rad-sm);
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Product grid ───────────────────────────────────────────── */
.product-grid {
  display: grid; gap: var(--sp-4);
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 640px)  { .product-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .product-grid { grid-template-columns: repeat(4, 1fr); } }

/* ── Footer ─────────────────────────────────────────────────── */
.cef-footer {
  background: var(--brand-primary-dark); color: #fff;
  padding: var(--sp-12) 0 var(--sp-6);
  margin-top: var(--sp-16);
}
.cef-footer a { color: #fff; opacity: 0.85; }
.cef-footer a:hover { opacity: 1; }
.cef-footer-cols {
  display: grid; gap: var(--sp-8);
  grid-template-columns: 1fr;
}
@media (min-width: 768px) { .cef-footer-cols { grid-template-columns: 2fr 1fr 1fr 1fr; } }
.cef-footer h4 { color: #fff; font-size: 0.95rem; margin-bottom: var(--sp-3); }
.cef-footer-links { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.cef-footer-links a { font-size: 0.9rem; }
.cef-footer-bottom {
  margin-top: var(--sp-10); padding-top: var(--sp-5);
  border-top: 1px solid rgba(255,255,255,0.15);
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--sp-3);
  font-size: 0.85rem; opacity: 0.8;
}

/* ── Hero ───────────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-dark) 100%);
  color: #fff;
  padding: var(--sp-16) 0;
  text-align: center;
}
.hero h1 { color: #fff; font-size: 2.5rem; margin-bottom: var(--sp-4); }
.hero p { font-size: 1.1rem; opacity: 0.9; margin-bottom: var(--sp-6); }

/* ── Category tile ───────────────────────────────────────────── */
.cat-grid {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 640px)  { .cat-grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1024px) { .cat-grid { grid-template-columns: repeat(6, 1fr); } }
.cat-tile {
  aspect-ratio: 1 / 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--rad-md);
  padding: var(--sp-3);
  text-align: center;
  font-size: 0.85rem; font-weight: 600; color: var(--color-text);
  transition: var(--transition);
}
.cat-tile:hover { border-color: var(--brand-primary); color: var(--brand-primary); text-decoration: none; }
.cat-tile-icon { font-size: 2rem; margin-bottom: var(--sp-2); }

/* ── Variant picker ─────────────────────────────────────────── */
.variant-group { margin-bottom: var(--sp-5); }
.variant-group-label { display: flex; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.variant-group-label .label-name { font-weight: 600; font-size: 0.9rem; flex-shrink: 0; }
.variant-group-label .label-value { color: var(--color-text-muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.variant-options { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.variant-opt {
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--rad-md);
  background: var(--color-surface); color: var(--color-text);
  cursor: pointer; font-size: 0.875rem;
  transition: var(--transition);
}
.variant-opt:hover  { border-color: var(--brand-primary); }
.variant-opt.selected { border-color: var(--brand-primary); background: var(--brand-primary); color: #fff; }
.variant-opt.swatch { padding: 0; width: 36px; height: 36px; border-radius: 50%; overflow: hidden; position: relative; }
.variant-opt.swatch.selected { outline: 2px solid var(--brand-primary); outline-offset: 2px; }
.variant-opt.disabled { opacity: 0.4; cursor: not-allowed; text-decoration: line-through; }

/* ── Forms ──────────────────────────────────────────────────── */
.form-group { margin-bottom: var(--sp-4); }
.form-group label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: var(--sp-1); color: var(--color-text); }
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: var(--sp-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--rad-md);
  font-family: inherit; font-size: 0.95rem;
  background: var(--color-surface); color: var(--color-text);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(45,106,51,0.1);
}

/* ── Utilities ──────────────────────────────────────────────── */
.row { display: flex; gap: var(--sp-4); flex-wrap: wrap; }
.col { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.text-muted { color: var(--color-text-muted); }
.text-sm    { font-size: 0.875rem; }
.text-xs    { font-size: 0.75rem; }
.mt-0 { margin-top: 0; } .mt-2 { margin-top: var(--sp-2); } .mt-4 { margin-top: var(--sp-4); } .mt-6 { margin-top: var(--sp-6); } .mt-8 { margin-top: var(--sp-8); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--sp-2); } .mb-4 { margin-bottom: var(--sp-4); } .mb-6 { margin-bottom: var(--sp-6); }
.py-8 { padding: var(--sp-8) 0; }
.py-12 { padding: var(--sp-12) 0; }

/* ── Loading state ──────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--color-surface-alt) 0%, #e5e7eb 50%, var(--color-surface-alt) 100%);
  background-size: 200% 100%;
  animation: skeleton-shine 1.4s ease-in-out infinite;
  border-radius: var(--rad-md);
}
@keyframes skeleton-shine { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ── Toast ──────────────────────────────────────────────────── */
.cef-toast {
  position: fixed; bottom: var(--sp-6); inset-inline-start: 50%;
  transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--color-text); color: #fff;
  padding: var(--sp-3) var(--sp-5); border-radius: var(--rad-md);
  font-size: 0.9rem; z-index: 100;
  transition: all 250ms ease;
  pointer-events: none;
}
html[dir="rtl"] .cef-toast { transform: translateX(50%) translateY(20px); }
.cef-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
html[dir="rtl"] .cef-toast.show { transform: translateX(50%) translateY(0); }
.cef-toast.success { background: var(--color-success); }
.cef-toast.error { background: var(--color-error); }

/* ── Confirm dialog (window.cefConfirm) ────────────────────────── */
.cef-confirm-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 200; padding: var(--sp-4); }
.cef-confirm-card { background: var(--color-surface); border-radius: var(--rad-lg); padding: var(--sp-6); max-width: 360px; text-align: center; }
.cef-confirm-card h3 { margin: 0 0 var(--sp-2); }
.cef-confirm-actions { display: flex; gap: var(--sp-3); justify-content: center; margin-top: var(--sp-5); }
