/* ============================================================================
   baigo storefront — design tokens + shared components
   ----------------------------------------------------------------------------
   Loaded BEFORE the inline <style> in templates/base.html so inline rules and
   per-page styles still cascade on top. Safe to add to: new components built
   in upcoming redesign batches should reference these tokens rather than
   hard-coding values, so we end up with one source of truth.
   ========================================================================= */

:root {
  /* === BRAND ============================================================ */
  --sf-brand: #0f766e;
  --sf-brand-hover: #0b5f59;
  --sf-brand-on: #ffffff;
  --sf-brand-soft: #d5f5ef;

  /* === SEMANTIC FEEDBACK COLORS ========================================= */
  --sf-success: #16a34a;
  --sf-success-bg: #f0fdf4;
  --sf-success-border: #86efac;
  --sf-warning: #d97706;
  --sf-warning-bg: #fffbeb;
  --sf-warning-border: #fcd34d;
  --sf-danger: #dc2626;
  --sf-danger-bg: #fef2f2;
  --sf-danger-border: #fca5a5;
  --sf-info: #2563eb;
  --sf-info-bg: #eff6ff;
  --sf-info-border: #93c5fd;

  /* === SHADOWS ========================================================== */
  --sf-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --sf-shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08);
  --sf-shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);
  --sf-shadow-focus: 0 0 0 4px rgba(15, 118, 110, 0.18);

  /* === RADII ============================================================ */
  --sf-radius-sm: 4px;
  --sf-radius-md: 8px;
  --sf-radius-lg: 12px;
  --sf-radius-xl: 16px;
  --sf-radius-pill: 9999px;

  /* === TYPE SCALE ======================================================= */
  --sf-text-xs: 12px;
  --sf-text-sm: 14px;
  --sf-text-base: 16px;
  --sf-text-lg: 18px;
  --sf-text-xl: 20px;
  --sf-text-2xl: 24px;
  --sf-text-3xl: 30px;
  --sf-text-4xl: 36px;
  --sf-text-display: 48px;

  --sf-leading-tight: 1.2;
  --sf-leading-normal: 1.5;
  --sf-leading-relaxed: 1.7;

  --sf-weight-regular: 400;
  --sf-weight-medium: 500;
  --sf-weight-semibold: 600;
  --sf-weight-bold: 700;

  /* === SPACING (4px grid) =============================================== */
  --sf-space-1: 4px;
  --sf-space-2: 8px;
  --sf-space-3: 12px;
  --sf-space-4: 16px;
  --sf-space-5: 20px;
  --sf-space-6: 24px;
  --sf-space-8: 32px;
  --sf-space-10: 40px;
  --sf-space-12: 48px;
  --sf-space-16: 64px;

  /* === LAYOUT =========================================================== */
  --sf-content-max: 80rem;        /* matches existing max-w-7xl */
  --sf-touch-target: 44px;        /* WCAG AA minimum */
}

/* === ACCESSIBILITY HELPERS ============================================== */

.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;
}
.sr-only.focus\:not-sr-only:focus,
.sr-only.focus\:not-sr-only:focus-visible {
  position: static;
  width: auto;
  height: auto;
  padding: var(--sf-space-3) var(--sf-space-4);
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--sf-brand);
  color: var(--sf-brand-on);
  padding: var(--sf-space-3) var(--sf-space-4);
  z-index: 100;
  text-decoration: none;
  font-weight: var(--sf-weight-semibold);
  border-radius: 0 0 var(--sf-radius-md) 0;
  transition: top 0.15s;
}
.skip-link:focus,
.skip-link:focus-visible {
  top: 0;
  outline: 2px solid var(--sf-brand-on);
  outline-offset: -4px;
}

[hidden] {
  display: none !important;
}

/* === BUTTON SYSTEM ===================================================== */
/* Use .sf-btn + a modifier on any <button> or <a>. Existing per-page button
   class strings still work; future batches migrate them to these. */

.sf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sf-space-2);
  min-height: var(--sf-touch-target);
  padding: 0 var(--sf-space-5);
  border-radius: var(--sf-radius-md);
  border: 1px solid transparent;
  font-family: inherit;
  font-weight: var(--sf-weight-semibold);
  font-size: var(--sf-text-sm);
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  user-select: none;
}
.sf-btn:disabled,
.sf-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
}
.sf-btn-primary {
  background: var(--sf-brand);
  color: var(--sf-brand-on);
}
.sf-btn-primary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--sf-brand-hover);
}
.sf-btn-secondary {
  background: #ffffff;
  color: #0f172a;
  border-color: #cbd5e1;
}
.sf-btn-secondary:hover:not(:disabled):not([aria-disabled="true"]) {
  background: #f1f5f9;
}
.sf-btn-ghost {
  background: transparent;
  color: var(--sf-brand);
}
.sf-btn-ghost:hover:not(:disabled):not([aria-disabled="true"]) {
  background: var(--sf-brand-soft);
}
.sf-btn-danger {
  background: var(--sf-danger);
  color: #ffffff;
}
.sf-btn-danger:hover:not(:disabled):not([aria-disabled="true"]) {
  background: #b91c1c;
}
.sf-btn-sm {
  min-height: 32px;
  padding: 0 var(--sf-space-3);
  font-size: var(--sf-text-xs);
}
.sf-btn-lg {
  min-height: 52px;
  padding: 0 var(--sf-space-6);
  font-size: var(--sf-text-base);
}
.sf-btn-block {
  width: 100%;
}

/* === FORM CONTROLS ====================================================== */

.sf-input,
.sf-select,
.sf-textarea {
  display: block;
  width: 100%;
  min-height: var(--sf-touch-target);
  padding: 0 var(--sf-space-3);
  font-family: inherit;
  font-size: var(--sf-text-base);
  line-height: 1.4;
  color: #0f172a;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: var(--sf-radius-md);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sf-textarea {
  min-height: 96px;
  padding: var(--sf-space-3);
}
.sf-input:focus-visible,
.sf-select:focus-visible,
.sf-textarea:focus-visible {
  border-color: var(--sf-brand);
  box-shadow: var(--sf-shadow-focus);
  outline: none;
}
.sf-input[aria-invalid="true"],
.sf-select[aria-invalid="true"],
.sf-textarea[aria-invalid="true"] {
  border-color: var(--sf-danger);
}

/* === ALERT / MESSAGE BANNER =========================================== */

.sf-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sf-space-2);
  padding: var(--sf-space-3) var(--sf-space-4);
  border-radius: var(--sf-radius-md);
  border: 1px solid transparent;
  font-size: var(--sf-text-sm);
}
.sf-alert-success { background: var(--sf-success-bg); border-color: var(--sf-success-border); color: #166534; }
.sf-alert-warning { background: var(--sf-warning-bg); border-color: var(--sf-warning-border); color: #92400e; }
.sf-alert-danger  { background: var(--sf-danger-bg);  border-color: var(--sf-danger-border);  color: #991b1b; }
.sf-alert-info    { background: var(--sf-info-bg);    border-color: var(--sf-info-border);    color: #1e40af; }

/* === PERFORMANCE / PERCEIVED SPEED ===================================== */

.sf-page-transition-bar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  width: 100%;
  height: 3px;
  pointer-events: none;
  transform: scaleX(0);
  transform-origin: left;
  background: linear-gradient(90deg, var(--sf-brand), #f6c85f, #2563eb);
  opacity: 0;
}

body.sf-page-loading .sf-page-transition-bar {
  animation: sf-page-progress 1.1s ease-out forwards;
  opacity: 1;
}

@keyframes sf-page-progress {
  0% { transform: scaleX(0); }
  55% { transform: scaleX(0.72); }
  100% { transform: scaleX(0.94); }
}

.sf-skeleton-media,
.storefront-product-card-media,
[data-product-gallery] .aspect-square {
  position: relative;
  overflow: hidden;
  background-color: #ffffff !important;
  background-image: none !important;
}

.sf-skeleton-media::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,0.58), transparent),
    linear-gradient(135deg, rgba(15,118,110,0.08), rgba(37,99,235,0.08));
  background-size: 220% 100%, 100% 100%;
  animation: sf-skeleton-shimmer 1.25s ease-in-out infinite;
  pointer-events: none;
}

.storefront-product-card-media:not(.image-failed)::before,
.storefront-product-card-media:not(.image-failed)::after,
[data-product-gallery] .aspect-square::before,
[data-product-gallery] .aspect-square::after {
  content: none !important;
  display: none !important;
  background: none !important;
  animation: none !important;
}

.storefront-product-card-media > img,
[data-product-gallery] .aspect-square > img,
[data-product-gallery] .aspect-square > template + img {
  position: relative;
  z-index: 1;
  display: block;
  margin: auto;
  object-fit: contain;
  background: #ffffff !important;
}

@keyframes sf-skeleton-shimmer {
  0% { background-position: 220% 0, 0 0; }
  100% { background-position: -120% 0, 0 0; }
}

.sf-ad-pixel {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.storefront-defer-section {
  content-visibility: auto;
  contain-intrinsic-size: 1px 720px;
}

.storefront-home-hero {
  border-bottom: 1px solid var(--sf-border);
}

.storefront-home-hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.25rem;
  padding-top: 1.5rem;
  padding-bottom: 2rem;
}

.storefront-home-title {
  max-width: 820px;
  line-height: 1.04;
}

.storefront-home-subtitle {
  color: var(--muted);
}

.storefront-home-proof {
  max-width: 720px;
}

.storefront-home-panel {
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.08);
}

.storefront-home-category-mini-grid,
.storefront-home-category-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0.875rem;
}

.storefront-home-mini-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  min-height: 76px;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.storefront-home-mini-card:hover,
.storefront-home-category-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.storefront-home-mini-icon,
.storefront-home-category-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  color: #ffffff;
  font-weight: 800;
}

.storefront-home-mini-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
}

.storefront-home-category-card {
  display: flex;
  gap: 1rem;
  min-height: 156px;
  padding: 1.125rem;
  transition: border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.storefront-home-category-icon {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  font-size: 1.15rem;
}

.storefront-home-mini-icon img,
.storefront-home-category-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
}

.storefront-mobile-category-chips {
  display: none;
}

.storefront-product-mobile-action {
  display: none;
}

.storefront-product-gallery-main {
  aspect-ratio: auto !important;
  height: clamp(220px, calc(100vh - 250px), 500px);
  min-height: 210px;
}

.storefront-product-gallery-main img {
  object-fit: contain;
}

@media (min-width: 900px) {
  .storefront-product-page {
    padding-top: 0.55rem !important;
  }

  .storefront-product-page .storefront-hero-grid {
    grid-template-columns: minmax(0, 0.98fr) minmax(360px, 0.82fr);
    gap: 1rem !important;
    align-items: start;
    min-height: calc(100vh - 125px);
    padding: 0.55rem !important;
  }

  .storefront-product-buy-panel .storefront-section-heading {
    font-size: clamp(1.35rem, 2vw, 2rem) !important;
    line-height: 1.05 !important;
    margin-bottom: 0.2rem !important;
  }

  .storefront-product-price-card {
    background: transparent !important;
    border-color: transparent !important;
    box-shadow: none !important;
    padding: 0.6rem !important;
    margin-bottom: 0.45rem !important;
  }

  .storefront-product-price-card .text-2xl,
  .storefront-product-price-card .text-3xl {
    font-size: clamp(1.45rem, 2vw, 1.9rem) !important;
    line-height: 1.12 !important;
  }

  .storefront-product-price-card .mt-2 {
    margin-top: 0.35rem !important;
  }

  .storefront-product-price-card .mt-3 {
    margin-top: 0.35rem !important;
  }

  .storefront-product-options-panel {
    border: 0 !important;
    box-shadow: none !important;
    padding: 0.55rem !important;
    margin-bottom: 0.45rem !important;
  }

  .storefront-product-options-panel .mb-3 {
    margin-bottom: 0.35rem !important;
  }

  .storefront-product-options-panel .p-3 {
    padding: 0.38rem !important;
  }

  .storefront-product-options-panel .storefront-touch-button {
    min-height: 32px;
    padding-top: 0.2rem !important;
    padding-bottom: 0.2rem !important;
  }

  .storefront-product-delivery {
    margin-bottom: 0.45rem !important;
    font-size: 0.82rem;
  }

  .storefront-product-main-action {
    position: sticky !important;
    bottom: 0.75rem !important;
    z-index: 25;
    margin-bottom: 0.35rem !important;
    padding: 0.35rem !important;
    border: 0 !important;
    border-radius: 0.75rem;
    background: transparent !important;
    box-shadow: none !important;
  }

  .storefront-product-main-action .storefront-touch-button {
    min-height: 42px;
  }

  .storefront-product-qty-control {
    border: 0 !important;
    box-shadow: none !important;
  }

  .storefront-product-back-link:not(.storefront-product-mobile-back) {
    display: inline-flex !important;
    width: 100% !important;
    margin-bottom: 0.35rem !important;
    padding-top: 0.65rem !important;
    padding-bottom: 0.65rem !important;
  }
}

@media (min-width: 640px) {
  .storefront-home-category-mini-grid,
  .storefront-home-category-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .storefront-home-hero-grid {
    grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.8fr);
    gap: 2rem;
    padding-top: 2rem;
    padding-bottom: 2.5rem;
  }
}

@media (min-width: 1100px) {
  .storefront-home-category-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .storefront-home-hero {
    background:
      linear-gradient(180deg, rgba(15,118,110,0.08), rgba(15,118,110,0)),
      #ffffff;
  }

  .storefront-home-hero-grid {
    padding-top: 1rem;
    padding-bottom: 1.25rem;
  }

  .storefront-home-kicker {
    font-size: 0.78rem;
    margin-bottom: 0.75rem;
    padding: 0.45rem 0.75rem;
  }

  .storefront-home-title {
    font-size: 1.65rem;
    line-height: 1.12;
    margin-bottom: 0.65rem;
  }

  .storefront-home-subtitle {
    font-size: 0.95rem;
    margin-bottom: 1rem;
  }

  .storefront-mobile-category-chips {
    display: flex;
    gap: 0.5rem;
    margin: 0 0 1rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .storefront-mobile-category-chips::-webkit-scrollbar {
    display: none;
  }

  .storefront-mobile-category-chips a {
    flex: 0 0 auto;
    min-height: 40px;
    border: 1px solid #b7d0e8;
    border-radius: 9999px;
    background: #ffffff;
    color: #102033;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 0.9rem;
    font-size: 0.85rem;
    font-weight: 800;
    text-decoration: none;
  }

  .storefront-home-proof {
    grid-template-columns: minmax(0, 1fr);
  }

  .storefront-home-panel {
    padding: 0.9rem;
    border-radius: 12px;
  }

  .storefront-home-category-mini-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }

  .storefront-home-mini-card {
    min-height: 88px;
    flex-direction: column;
    align-items: flex-start;
    padding: 0.75rem;
  }

  .storefront-home-category-card {
    min-height: 118px;
    gap: 0.75rem;
    padding: 0.9rem;
  }

  .storefront-home-category-card .text-lg {
    font-size: 1rem;
  }

  .storefront-product-grid,
  .storefront-category-grid,
  .storefront-tile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.65rem;
  }

  .storefront-product-card {
    border-radius: 14px !important;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  }

  .storefront-product-card-media {
    min-height: 0;
    aspect-ratio: 1 / 0.82;
    padding: 0.65rem !important;
  }

  .storefront-product-card-body {
    padding: 0.75rem !important;
  }

  .storefront-product-card-title {
    min-height: 2.45rem !important;
    font-size: 0.92rem !important;
  }

  .storefront-product-card .text-xl {
    font-size: 1.2rem;
    line-height: 1.35;
  }

  .storefront-card-action {
    min-height: 44px;
    border-radius: 10px !important;
    background: var(--sf-brand) !important;
    color: #ffffff !important;
    font-size: 0.92rem !important;
  }

  .storefront-card-action-label {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    color: #ffffff !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  .storefront-catalog-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .storefront-product-page {
    padding-top: 0.45rem;
    padding-bottom: 8.5rem;
  }

  .storefront-product-top-row {
    margin-bottom: 0.45rem !important;
  }

  .storefront-product-page .storefront-hero-grid {
    gap: 0.55rem;
    border-radius: 14px;
    padding: 0.5rem;
  }

  [data-product-gallery] .storefront-product-gallery-main {
    height: clamp(170px, 28vh, 230px);
    min-height: 170px;
    border-radius: 14px;
    margin-bottom: 0.35rem;
    padding: 0.35rem !important;
  }

  .storefront-product-page h1 {
    font-size: 1.22rem !important;
    line-height: 1.12;
    margin-bottom: 0.25rem !important;
  }

  .storefront-product-buy-panel > .text-sm {
    margin-bottom: 0.4rem !important;
  }

  .storefront-product-price-card {
    padding: 0.65rem !important;
    margin-bottom: 0.55rem !important;
  }

  .storefront-product-price-card .text-2xl,
  .storefront-product-price-card .text-3xl {
    font-size: 1.55rem !important;
    line-height: 1.15 !important;
  }

  .storefront-product-price-card .mt-3 {
    margin-top: 0.35rem !important;
  }

  .storefront-product-options-panel {
    padding: 0.65rem !important;
    margin-bottom: 0.55rem !important;
  }

  .storefront-product-options-panel .mb-3 {
    margin-bottom: 0.45rem !important;
  }

  .storefront-product-options-panel .p-3 {
    padding: 0.55rem !important;
  }

  .storefront-product-options-panel .storefront-touch-button {
    min-height: 38px;
    padding-top: 0.4rem !important;
    padding-bottom: 0.4rem !important;
  }

  .storefront-product-delivery {
    margin-bottom: 0.55rem !important;
  }

  .storefront-product-back-link:not(.storefront-product-mobile-back) {
    display: none !important;
  }

  .storefront-product-main-action {
    display: none !important;
  }

  .storefront-product-mobile-action {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 55;
    display: grid;
    grid-template-columns: minmax(64px, 0.7fr) minmax(112px, 1fr) minmax(120px, 1.2fr);
    gap: 0.5rem;
    align-items: center;
    padding: 0.65rem 0.75rem;
    border-top: 1px solid #b7d0e8;
    background: rgba(255,255,255,0.97);
    box-shadow: 0 -12px 28px rgba(15, 23, 42, 0.14);
    backdrop-filter: blur(14px);
  }

  .storefront-product-mobile-price {
    min-width: 0;
    line-height: 1.1;
  }

  .storefront-product-mobile-price strong {
    display: block;
    font-size: 1rem;
  }

  .storefront-product-mobile-qty {
    display: grid;
    grid-template-columns: 38px minmax(36px, 1fr) 38px;
    overflow: hidden;
    border: 1px solid #b7d0e8;
    border-radius: 12px;
    background: #ffffff;
  }

  .storefront-product-mobile-qty button,
  .storefront-product-mobile-qty input {
    min-height: 46px;
    border: 0;
    text-align: center;
    font-weight: 900;
    font-size: 1rem;
    background: transparent;
  }

  .storefront-product-mobile-qty button {
    background: #eef7ff;
  }

  .storefront-product-mobile-add {
    min-height: 48px;
    border: 0;
    border-radius: 12px;
    background: var(--sf-brand);
    color: #ffffff;
    font-weight: 900;
    font-size: 0.95rem;
  }

  .storefront-product-mobile-add:disabled {
    opacity: 0.65;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.sf-page-loading .sf-page-transition-bar,
  .sf-skeleton-media::before {
    animation: none;
  }
}
