/**
 * Sanju Pansari — Design System (canonical tokens & components)
 * 8px grid · WCAG AA contrast · loads before final polish layers
 */

:root {
  /* ── Brand palette (Modern Grocery — forest green) ── */
  --ds-forest:       #2E7D32;
  --ds-forest-dark:  #1B5E20;
  --ds-forest-deep:  #145214;
  --ds-lime:         #66BB6A;
  --ds-lime-bright:  #81C784;
  --ds-cream:        #F5F5F5;
  --ds-surface:      #FFFFFF;
  --ds-ink:          #111827;
  --ds-ink-muted:    #4B5563;
  --ds-ink-subtle:   #6B7280;
  --ds-border:       #E5E7EB;
  --ds-border-soft:  #EEF3E8;

  /* Semantic */
  --ds-success:      #15803D;
  --ds-success-bg:   #DCFCE7;
  --ds-danger:       #B91C1C;
  --ds-danger-bg:    #FEE2E2;
  --ds-warning:      #B45309;
  --ds-info:         #1D4ED8;
  --ds-info-bg:      #DBEAFE;

  /* Map legacy tokens to brand (single source of truth) */
  --color-primary:   var(--ds-forest);
  --color-secondary: var(--ds-forest-dark);
  --color-accent:    var(--ds-lime);
  --color-success:   var(--ds-success);
  --color-bg:        var(--ds-cream);
  --color-text:      var(--ds-ink);
  --color-muted:     var(--ds-ink-muted);
  --color-border:    var(--ds-border);
  --navy:            var(--ds-forest);
  --navy-light:      var(--ds-lime);
  --navy-dark:       var(--ds-forest-dark);
  --gold:            var(--ds-lime);
  --gold-light:      var(--ds-lime-bright);
  --gold-dark:       var(--ds-forest);
  --text-dark:       var(--ds-ink);
  --text-body:       var(--ds-ink-muted);
  --text-muted:      var(--ds-ink-subtle);
  --light-bg:        var(--ds-cream);
  --border:          var(--ds-border);
  --sp-premium-forest: var(--ds-forest);
  --sp-primary:      var(--ds-forest);
  --sp-accent:       var(--ds-lime);

  /* ── 8px spacing scale ── */
  --ds-space-1:  4px;
  --ds-space-2:  8px;
  --ds-space-3:  12px;
  --ds-space-4:  16px;
  --ds-space-5:  20px;
  --ds-space-6:  24px;
  --ds-space-8:  32px;
  --ds-space-10: 40px;
  --ds-space-12: 48px;
  --ds-space-16: 64px;

  /* ── Typography scale ── */
  --ds-font-sans: 'Poppins', 'Public Sans', 'Inter', system-ui, -apple-system, sans-serif;
  --ds-font-display: var(--ds-font-sans);
  --ds-text-xs:   0.75rem;   /* 12px */
  --ds-text-sm:   0.875rem;  /* 14px */
  --ds-text-base: 1rem;      /* 16px */
  --ds-text-lg:   1.125rem;  /* 18px */
  --ds-text-xl:   1.25rem;   /* 20px */
  --ds-text-2xl:  1.5rem;    /* 24px */
  --ds-text-3xl:  1.875rem;  /* 30px */
  --ds-leading-tight: 1.25;
  --ds-leading-normal: 1.5;
  --ds-leading-relaxed: 1.65;

  /* ── Shape & elevation ── */
  --ds-radius-sm:  8px;
  --ds-radius:     12px;
  --ds-radius-lg:  16px;
  --ds-radius-xl:  20px;
  --ds-radius-full: 9999px;
  --ds-shadow-sm:  0 1px 3px rgba(17, 24, 39, 0.06);
  --ds-shadow:     0 4px 16px rgba(17, 24, 39, 0.08);
  --ds-shadow-lg:  0 12px 32px rgba(17, 24, 39, 0.12);
  --ds-transition: 0.2s ease;

  /* Layout chrome */
  --ds-focus-ring: 0 0 0 3px rgba(154, 205, 50, 0.45);
  --ds-tap-min:    44px;
}

/* ── Global accessibility ── */
:focus-visible {
  outline: 2px solid var(--ds-lime);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Headings on colored surfaces must stay readable */
.ds-surface-dark,
.cart-page-header,
.hero-swiper .slide-content {
  --heading-color: #ffffff;
}

.ds-surface-dark h1,
.ds-surface-dark h2,
.ds-surface-dark h3,
.cart-page-header h1,
.cart-page-header h2 {
  color: var(--heading-color, #fff) !important;
}

/* ── Button system ── */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--ds-space-2);
  min-height: var(--ds-tap-min);
  padding: var(--ds-space-3) var(--ds-space-5);
  border-radius: var(--ds-radius);
  font-family: var(--ds-font-sans);
  font-size: var(--ds-text-sm);
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--ds-transition), color var(--ds-transition),
              border-color var(--ds-transition), box-shadow var(--ds-transition),
              transform var(--ds-transition);
}

.ds-btn:disabled,
.ds-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.ds-btn-primary {
  background: linear-gradient(135deg, var(--ds-lime) 0%, var(--ds-forest) 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(61, 107, 30, 0.22);
}

.ds-btn-primary:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.ds-btn-secondary {
  background: var(--ds-surface);
  border-color: var(--ds-border);
  color: var(--ds-ink);
}

.ds-btn-secondary:hover {
  border-color: var(--ds-forest);
  color: var(--ds-forest);
}

.ds-btn-ghost {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.55);
  color: #fff;
}

.ds-btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

.ds-btn-danger {
  background: var(--ds-danger-bg);
  border-color: #fecaca;
  color: var(--ds-danger);
}

/* ── Form system ── */
.ds-field {
  display: flex;
  flex-direction: column;
  gap: var(--ds-space-2);
  margin-bottom: var(--ds-space-4);
}

.ds-label {
  font-size: var(--ds-text-sm);
  font-weight: 600;
  color: var(--ds-ink);
}

.ds-input,
.ds-select,
.ds-textarea {
  width: 100%;
  min-height: var(--ds-tap-min);
  padding: var(--ds-space-3) var(--ds-space-4);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius);
  background: var(--ds-surface);
  color: var(--ds-ink);
  font-size: var(--ds-text-base);
  line-height: var(--ds-leading-normal);
  transition: border-color var(--ds-transition), box-shadow var(--ds-transition);
}

.ds-input:focus,
.ds-select:focus,
.ds-textarea:focus {
  border-color: var(--ds-forest);
  box-shadow: var(--ds-focus-ring);
}

.ds-input[aria-invalid="true"],
.ds-select[aria-invalid="true"],
.ds-textarea[aria-invalid="true"] {
  border-color: var(--ds-danger);
}

.ds-field-hint {
  font-size: var(--ds-text-xs);
  color: var(--ds-ink-subtle);
}

.ds-field-error {
  font-size: var(--ds-text-xs);
  color: var(--ds-danger);
  font-weight: 600;
}

/* ── Card system ── */
.ds-card {
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  box-shadow: var(--ds-shadow-sm);
  padding: var(--ds-space-6);
}

.ds-card-header {
  margin-bottom: var(--ds-space-4);
}

.ds-card-title {
  font-size: var(--ds-text-lg);
  font-weight: 800;
  color: var(--ds-ink);
  margin: 0;
}

.ds-card-subtitle {
  font-size: var(--ds-text-sm);
  color: var(--ds-ink-subtle);
  margin: var(--ds-space-1) 0 0;
}

/* ── Table system ── */
.ds-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-lg);
  background: var(--ds-surface);
}

.ds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--ds-text-sm);
}

.ds-table th,
.ds-table td {
  padding: var(--ds-space-3) var(--ds-space-4);
  text-align: left;
  border-bottom: 1px solid var(--ds-border-soft);
}

.ds-table th {
  background: var(--ds-cream);
  font-weight: 700;
  color: var(--ds-ink);
  white-space: nowrap;
}

.ds-table tbody tr:hover {
  background: rgba(244, 250, 235, 0.65);
}

/* ── Modal system ── */
.ds-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.55);
  z-index: 1040;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ds-space-4);
}

.ds-modal {
  width: min(100%, 520px);
  max-height: min(90vh, 720px);
  overflow: auto;
  background: var(--ds-surface);
  border-radius: var(--ds-radius-xl);
  box-shadow: var(--ds-shadow-lg);
  padding: var(--ds-space-6);
}

.ds-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--ds-space-4);
  margin-bottom: var(--ds-space-4);
}

.ds-modal-title {
  font-size: var(--ds-text-xl);
  font-weight: 800;
  margin: 0;
  color: var(--ds-ink);
}

/* ── Empty state ── */
.ds-empty {
  text-align: center;
  padding: var(--ds-space-12) var(--ds-space-6);
  background: var(--ds-surface);
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-xl);
  box-shadow: var(--ds-shadow-sm);
}

.ds-empty-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto var(--ds-space-4);
  border-radius: var(--ds-radius-full);
  background: var(--ds-cream);
  color: var(--ds-forest);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.75rem;
}

.ds-empty-title {
  font-size: var(--ds-text-xl);
  font-weight: 800;
  color: var(--ds-ink);
  margin: 0 0 var(--ds-space-2);
}

.ds-empty-desc {
  font-size: var(--ds-text-sm);
  color: var(--ds-ink-subtle);
  max-width: 36ch;
  margin: 0 auto var(--ds-space-6);
  line-height: var(--ds-leading-relaxed);
}

/* ── Page hero pattern ── */
.ds-page-hero {
  background: linear-gradient(135deg, var(--ds-forest-dark) 0%, var(--ds-forest) 55%, var(--ds-forest-deep) 100%);
  color: #fff;
  border-radius: var(--ds-radius-lg);
  padding: var(--ds-space-5) var(--ds-space-6);
  margin-bottom: var(--ds-space-4);
  box-shadow: var(--ds-shadow);
}

.ds-page-hero h1 {
  font-size: var(--ds-text-xl);
  font-weight: 800;
  margin: 0 0 var(--ds-space-2);
  line-height: var(--ds-leading-tight);
  color: #fff !important;
}

.ds-page-hero p {
  margin: 0;
  font-size: var(--ds-text-sm);
  color: rgba(255, 255, 255, 0.92);
  line-height: var(--ds-leading-relaxed);
}

/* ── Floating actions (WhatsApp, theme toggle) ── */
.wa-float {
  position: fixed;
  z-index: 980;
  width: 52px;
  height: 52px;
  border-radius: var(--ds-radius-full);
  background: #25D366;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.55rem;
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
  transition: transform var(--ds-transition);
}

.wa-float:hover {
  transform: scale(1.06);
  color: #fff;
}

@media (max-width: 991px) {
  .wa-float {
    left: var(--ds-space-4);
    right: auto;
    bottom: calc(var(--bottom-nav-h, 72px) + env(safe-area-inset-bottom, 0px) + var(--ds-space-4));
  }

  .sp-theme-toggle {
    top: auto;
    bottom: calc(var(--bottom-nav-h, 72px) + env(safe-area-inset-bottom, 0px) + 68px);
    right: var(--ds-space-4);
  }

  /* Avoid FAB + theme toggle stacking on cart/checkout */
  body.page-cart .wa-float,
  body.page-checkout .wa-float,
  body.page-pay .wa-float {
    bottom: calc(var(--bottom-nav-h, 72px) + env(safe-area-inset-bottom, 0px) + 72px);
  }
}

@media (min-width: 992px) {
  .wa-float {
    right: var(--ds-space-6);
    bottom: var(--ds-space-6);
    left: auto;
  }

  .sp-theme-toggle {
    top: auto;
    bottom: 96px;
    right: var(--ds-space-6);
  }
}

/* Savings bar — readable on all breakpoints */
.pd-savings-bar {
  font-size: clamp(0.8125rem, 2.8vw, 0.875rem);
  line-height: 1.45;
  padding: var(--ds-space-2) var(--ds-space-4);
}

/* Flash messages — consistent feedback */
.flash-message {
  display: flex;
  align-items: flex-start;
  gap: var(--ds-space-2);
  border-radius: var(--ds-radius);
  font-size: var(--ds-text-sm);
  font-weight: 600;
  line-height: var(--ds-leading-normal);
}

.flash-message[role="alert"] {
  border-left: 4px solid currentColor;
}

/* Loading state utility */
.ds-loading {
  position: relative;
  pointer-events: none;
}

.ds-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.55);
}

/* Dark theme token overrides */
/* Primary CTAs — consistent contrast on green fills */
.btn-primary,
.product-card-addcart,
.checkout-btn,
.hero-swiper .btn-primary,
.slide-buttons .btn-primary {
  color: #fff !important;
}

.btn-gold,
.slide-buttons .btn-gold {
  color: var(--ds-forest-deep, #1F3A10) !important;
}

/* PWA install popup — above bottom nav, below hero CTAs on scroll */
.sanju-install-popup {
  z-index: 970;
  max-width: min(100%, 420px);
  margin: 0 auto;
}

@media (max-width: 991px) {
  body:not(.page-cart):not(.page-checkout) .sanju-install-popup {
    bottom: calc(var(--bottom-nav-h, 72px) + env(safe-area-inset-bottom, 0px) + var(--ds-space-4, 16px)) !important;
  }
}

/* De-emphasize header cart when already on cart page */
body.page-cart .pd-cart-pill {
  box-shadow: none !important;
}

body.page-cart .bottom-nav-cart.active .bottom-nav-icon-wrap {
  box-shadow: none;
}

@keyframes dsWaPulse {
  0% { box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4); }
  70% { box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4), 0 0 0 12px rgba(37, 211, 102, 0); }
  100% { box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4); }
}

.wa-float {
  animation: dsWaPulse 2.4s infinite;
}

/* ── Mobile category chips (header strip + homepage) ── */
.hp-cat-scroll,
.pd-mobile-cat-strip {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 8px;
}

.hp-cat-scroll::-webkit-scrollbar,
.pd-mobile-cat-strip::-webkit-scrollbar { display: none; }

.hp-cat-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--ds-border-soft, #EEF3E8);
  border-radius: var(--ds-radius-full, 9999px);
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--ds-ink, #111827);
  text-decoration: none;
  box-shadow: var(--ds-shadow-sm);
  min-height: 40px;
  white-space: nowrap;
}

.hp-cat-chip i { color: var(--ds-forest, #3D6B1E); }
.hp-cat-chip:active { transform: scale(0.97); }

.pd-mobile-cat-strip {
  padding: 8px var(--ds-space-4, 16px) 10px;
  background: #fff;
  border-bottom: 1px solid var(--ds-border-soft, #EEF3E8);
}

body.page-home .pd-mobile-cat-strip { display: none; }

/* Homepage uses hero tiles + category grid — skip duplicate chip row */
body.page-home .hp-cat-scroll { display: none; }

.hp-cat-scroll {
  display: none;
  padding: 0 var(--ds-space-4, 16px) var(--ds-space-4, 16px);
}

@media (prefers-reduced-motion: reduce) {
  .wa-float { animation: none; }
}
