/* ==========================================================================
   Chabela Cakes — base + shared primitives (owned by the design-system piece)
   1. Reset & element defaults   2. Typography helpers   3. Utilities
   4. Primitives (all prefixed .ds- so they never collide with component CSS):
      .ds-btn  .ds-chip  .ds-badge  .ds-field/.ds-input  .ds-stepper  .ds-segmented
      Choice controls (option chips, segmented) are <label>s wrapping a real
      <input type="radio">: arrow keys, one tab stop and form semantics come for free.
      .ds-card (product card reference)  .ds-skeleton  .ds-empty
   ========================================================================== */

/* 1. Reset & element defaults ------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  color-scheme: light;
  scroll-padding-top: calc(var(--header-h) + var(--safe-top) + var(--space-4));
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--fw-regular);
  line-height: var(--lh-snug);
  letter-spacing: var(--tracking-display);
  color: var(--color-text-brand);
  text-wrap: balance;
}
h1 { font-size: var(--text-3xl); line-height: var(--lh-tight); }
h2 { font-size: var(--text-2xl); line-height: var(--lh-tight); }
h3 { font-size: var(--text-lg); font-weight: var(--fw-medium); }
h4 { font-size: var(--text-md); font-weight: var(--fw-medium); }

p, ul, ol, dl, figure, blockquote { margin: 0; }
p { text-wrap: pretty; }
ul[role="list"], ol[role="list"] { list-style: none; padding: 0; }

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: .22em;
  text-decoration-color: var(--color-line-strong);
  transition: text-decoration-color var(--dur-fast) var(--ease-out);
}
@media (hover: hover) { a:hover { text-decoration-color: currentColor; } }

img, picture, svg, video { max-width: 100%; display: block; }
img { height: auto; }

button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
input, select, textarea { font-size: max(16px, 1em); } /* no iOS zoom on focus */
textarea { resize: vertical; }

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--c-blush-200); color: var(--c-ink-900); }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }

hr { border: 0; border-top: 1px solid var(--color-line); margin: var(--space-6) 0; }

/* Reduced motion — honour both the OS setting and the demo/static flag. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
html[data-reduced-motion] *, html[data-reduced-motion] *::before, html[data-reduced-motion] *::after {
  animation-duration: .01ms !important; animation-iteration-count: 1 !important;
  transition-duration: .01ms !important; scroll-behavior: auto !important;
}

/* 2. Typography helpers -------------------------------------------------- */
.ds-script {
  font-family: var(--font-script);
  font-weight: 400;
  font-size: var(--text-script);
  line-height: 1;
  letter-spacing: 0;
  color: var(--color-text-brand);
}
.ds-display { font-family: var(--font-display); font-weight: var(--fw-regular); letter-spacing: var(--tracking-display); }
.ds-display em, h1 em, h2 em { font-style: italic; }
.ds-eyebrow {
  font-family: var(--font-sans);
  font-size: var(--text-2xs);
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  line-height: 1.3;
  color: var(--color-text-brand);
}
.ds-lead { font-size: var(--text-md); line-height: var(--lh-relaxed); color: var(--color-text-muted); font-weight: var(--fw-light); }
.ds-muted { color: var(--color-text-muted); }
.ds-small { font-size: var(--text-sm); }
.ds-num, .ds-price { font-variant-numeric: lining-nums tabular-nums; }
.ds-price {
  font-family: var(--font-sans);
  font-weight: var(--fw-medium);
  letter-spacing: .01em;
  color: var(--color-text);
  white-space: nowrap;
}
.ds-price small { font-size: .78em; font-weight: var(--fw-regular); color: var(--color-text-muted); margin-right: .3em; }

/* 3. Utilities ----------------------------------------------------------- */
.ds-container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: max(var(--gutter), var(--safe-left)) max(var(--gutter), var(--safe-right));
}
.ds-container--narrow { max-width: calc(var(--container-narrow) + 2 * var(--gutter)); }
.ds-visually-hidden, .visually-hidden, .sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
.ds-divider { height: 1px; background: var(--color-line); border: 0; margin: 0; }
/* Candy-stripe band from the moodboard — decorative only. */
.ds-stripes {
  background: repeating-linear-gradient(90deg, var(--c-blush-200) 0 14px, var(--c-cream-50) 14px 28px);
}

/* 4. Primitives ========================================================== */

/* Button ------------------------------------------------------------------ */
.ds-btn {
  --btn-bg: var(--color-accent);
  --btn-fg: var(--color-text-on-brand);
  --btn-bd: transparent;
  --btn-bg-hover: var(--color-accent-hover);
  --btn-bg-press: var(--color-accent-pressed);
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-5);
  border: 1px solid var(--btn-bd);
  border-radius: var(--radius-pill);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-family: var(--font-sans);
  font-size: .9375rem;
  font-weight: var(--fw-medium);
  letter-spacing: .02em;
  line-height: 1.1;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.ds-btn svg { width: 1.15em; height: 1.15em; flex: none; }
@media (hover: hover) { .ds-btn:hover { background: var(--btn-bg-hover); } }
.ds-btn:active, .ds-btn.is-pressed { background: var(--btn-bg-press); transform: translateY(1px); } /* never shrinks below 44px */
.ds-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ds-btn:disabled, .ds-btn[aria-disabled="true"] {
  --btn-bg: var(--c-cream-300); --btn-bg-hover: var(--c-cream-300); --btn-bg-press: var(--c-cream-300);
  --btn-fg: var(--c-ink-500); --btn-bd: transparent;
  transform: none; cursor: not-allowed;
}
.ds-btn--secondary {
  --btn-bg: transparent; --btn-fg: var(--color-text-brand); --btn-bd: var(--color-line-strong);
  --btn-bg-hover: var(--c-blush-50); --btn-bg-press: var(--c-blush-100);
}
.ds-btn--soft {
  --btn-bg: var(--c-blush-100); --btn-fg: var(--color-text-brand);
  --btn-bg-hover: var(--c-blush-200); --btn-bg-press: var(--c-blush-300);
}
.ds-btn--ghost {
  --btn-bg: transparent; --btn-fg: var(--color-text-brand);
  --btn-bg-hover: rgba(110, 33, 41, .06); --btn-bg-press: rgba(110, 33, 41, .1);
  padding-inline: var(--space-3);
}
.ds-btn--on-brand {
  --btn-bg: var(--c-cream-ink); --btn-fg: var(--c-burgundy-700);
  --btn-bg-hover: #fff; --btn-bg-press: var(--c-blush-100);
}
.ds-btn--lg { min-height: var(--tap-lg); padding: 0 var(--space-7); font-size: var(--text-base); }
.ds-btn--block { display: flex; width: 100%; min-width: 0; padding-inline: var(--space-4); white-space: normal; text-align: center; }
.ds-btn--icon { width: var(--tap); padding: 0; }
.ds-btn--icon.ds-btn--lg { width: var(--tap-lg); }
/* Primary CTA with a trailing value (e.g. total). */
.ds-btn--split { justify-content: space-between; padding-inline: var(--space-6); }
.ds-btn--split .ds-price { color: inherit; }
/* Loading: keep width, swap label for a spinner. */
.ds-btn[aria-busy="true"] { color: transparent; pointer-events: none; }
.ds-btn[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px;
  border-radius: 50%; border: 2px solid var(--btn-fg); border-right-color: transparent;
  animation: ds-spin .7s linear infinite;
}
@keyframes ds-spin { to { transform: rotate(1turn); } }

/* Chip (category filters, options) --------------------------------------- */
.ds-chip {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-4);
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--fw-regular);
  letter-spacing: .015em;
  white-space: nowrap;
  touch-action: manipulation;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out);
}
.ds-chip .ds-chip__count { font-size: var(--text-xs); color: var(--color-text-subtle); font-variant-numeric: tabular-nums; }
@media (hover: hover) { .ds-chip:hover { border-color: var(--c-burgundy-300); background: var(--c-blush-50); } }
.ds-chip:active { transform: translateY(1px); }
.ds-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ds-chip[aria-pressed="true"], .ds-chip[aria-selected="true"], .ds-chip[aria-checked="true"], .ds-chip.is-active {
  background: var(--color-accent); border-color: var(--color-accent); color: var(--color-text-on-brand);
}
.ds-chip[aria-pressed="true"] .ds-chip__count, .ds-chip[aria-selected="true"] .ds-chip__count,
.ds-chip[aria-checked="true"] .ds-chip__count, .ds-chip.is-active .ds-chip__count { color: var(--color-text-on-brand-muted); }
.ds-chip:disabled { opacity: .45; cursor: not-allowed; }
/* Native radio inside a chip / segmented label: invisible but still focusable. */
.ds-chip > input[type="radio"], .ds-chip > input[type="checkbox"],
.ds-segmented > label > input {
  position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none;
}
label.ds-chip { position: relative; cursor: pointer; user-select: none; -webkit-user-select: none; }
.ds-chip:has(> input:checked) {
  background: var(--color-accent); border-color: var(--color-accent); color: var(--color-text-on-brand);
}
.ds-chip:has(> input:checked) .ds-chip__count { color: var(--color-text-on-brand-muted); }
.ds-chip:has(> input:focus-visible) { box-shadow: var(--focus-ring); }
.ds-chip:has(> input:disabled) { opacity: .45; cursor: not-allowed; }
/* Option chip with a sub-label (size + price). Shrinks and wraps so a row of
   three always fits a 320px phone. */
.ds-chip--option {
  flex-direction: column; gap: 2px; min-width: 0; min-height: 60px;
  padding: var(--space-2) var(--space-2); border-radius: var(--radius-md);
  line-height: 1.2; text-align: center; white-space: normal; text-wrap: balance;
}
.ds-chip--option small { font-size: var(--text-xs); color: var(--color-text-muted); font-variant-numeric: tabular-nums; }
.ds-chip--option[aria-checked="true"] small, .ds-chip--option.is-active small,
.ds-chip--option:has(> input:checked) small { color: var(--color-text-on-brand-muted); }
/* A row of option chips: equal columns that never overflow. */
.ds-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: var(--space-2); }

/* Badge ------------------------------------------------------------------- */
.ds-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px 4px;
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text-brand);
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: var(--fw-medium);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  line-height: 1.2;
  white-space: nowrap;
}
.ds-badge--brand { background: var(--color-accent); color: var(--color-text-on-brand); }
.ds-badge--blush { background: var(--c-blush-200); color: var(--c-burgundy-800); }
.ds-badge--success { background: var(--color-success-bg); color: var(--color-success); }
.ds-badge--warning { background: var(--color-warning-bg); color: var(--color-warning); }
/* Count bubble (cart) */
.ds-count {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: var(--radius-pill); background: var(--color-accent); color: var(--color-text-on-brand);
  font: var(--fw-medium) 11px/1 var(--font-sans); font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--color-bg);
}

/* Form fields ------------------------------------------------------------- */
.ds-field { display: grid; gap: var(--space-2); align-content: start; }
.ds-label {
  font-family: var(--font-sans); font-size: var(--text-sm); font-weight: var(--fw-medium);
  color: var(--color-text); letter-spacing: .01em;
}
.ds-label .ds-optional { font-weight: var(--fw-regular); color: var(--color-text-subtle); margin-left: .35em; }
.ds-hint { font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.4; }
.ds-error { display: flex; align-items: flex-start; gap: 6px; font-size: var(--text-sm); color: var(--color-danger); line-height: 1.4; }
.ds-error::before {
  content: "!"; flex: none; display: grid; place-items: center; width: 16px; height: 16px; margin-top: 1px;
  border-radius: 50%; background: var(--color-danger); color: #fff; font: 600 11px/1 var(--font-sans);
}
.ds-input, .ds-select, .ds-textarea {
  display: block; width: 100%;
  min-height: var(--tap-lg);
  padding: 14px var(--space-4);
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.35;
  appearance: none;
  -webkit-appearance: none;
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out);
}
.ds-textarea { min-height: 112px; }
.ds-input::placeholder, .ds-textarea::placeholder { color: var(--c-ink-500); opacity: 1; }
@media (hover: hover) { .ds-input:hover, .ds-select:hover, .ds-textarea:hover { border-color: var(--c-burgundy-300); } }
.ds-input:focus, .ds-select:focus, .ds-textarea:focus {
  outline: none; border-color: var(--color-accent); background: #fff;
  box-shadow: 0 0 0 3px rgba(155, 58, 69, .16);
}
.ds-input[aria-invalid="true"], .ds-select[aria-invalid="true"], .ds-textarea[aria-invalid="true"] {
  border-color: var(--color-danger); background: #fff;
}
.ds-input[aria-invalid="true"]:focus, .ds-textarea[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px rgba(179, 38, 30, .14); }
.ds-input:disabled, .ds-select:disabled, .ds-textarea:disabled { background: var(--color-surface-sunken); color: var(--color-text-subtle); cursor: not-allowed; }
.ds-select {
  padding-right: var(--space-9);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236E2129' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 18px center;
}
/* Input with a fixed prefix, e.g. +54 9 */
.ds-input-group { display: flex; align-items: stretch; }
.ds-input-group > .ds-input-addon {
  display: grid; place-items: center; padding: 0 var(--space-3) 0 var(--space-4);
  border: 1px solid var(--color-line-strong); border-right: 0; border-radius: var(--radius-md) 0 0 var(--radius-md);
  background: var(--color-surface-sunken); color: var(--color-text-muted); font-size: var(--text-base); white-space: nowrap;
}
.ds-input-group > .ds-input { border-radius: 0 var(--radius-md) var(--radius-md) 0; }
/* Segmented choice (Retiro / Envío) */
.ds-segmented {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  border-radius: var(--radius-pill); background: var(--color-surface-sunken);
}
.ds-segmented > button, .ds-segmented > label {
  display: grid; place-items: center; min-height: var(--tap); padding: 0 var(--space-4);
  border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--color-text-muted);
  font-size: var(--text-sm); font-weight: var(--fw-medium); cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.ds-segmented > [aria-checked="true"], .ds-segmented > [aria-pressed="true"], .ds-segmented > .is-active,
.ds-segmented > label:has(> input:checked) {
  background: var(--color-surface); color: var(--color-text-brand); box-shadow: var(--shadow-sm);
}
.ds-segmented > :focus-visible, .ds-segmented > label:has(> input:focus-visible) { outline: none; box-shadow: var(--focus-ring); }
.ds-segmented > label { position: relative; text-align: center; line-height: 1.2; }

/* Quantity stepper -------------------------------------------------------- */
.ds-stepper {
  display: inline-flex; align-items: center; justify-self: start; width: max-content;
  border: 1px solid var(--color-line-strong);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
}
.ds-stepper button {
  display: grid; place-items: center; width: var(--tap); height: var(--tap);
  border: 0; border-radius: 50%; background: transparent; color: var(--color-text-brand);
  font-size: 1.25rem; line-height: 1;
  transition: background-color var(--dur-fast) var(--ease-out), transform var(--dur-instant) var(--ease-out);
}
.ds-stepper button svg { width: 16px; height: 16px; }
@media (hover: hover) { .ds-stepper button:hover { background: var(--c-blush-50); } }
.ds-stepper button:active { background: var(--c-blush-100); }
.ds-stepper button:disabled { color: var(--c-ink-300); background: transparent; transform: none; }
.ds-stepper button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ds-stepper output, .ds-stepper .ds-stepper__value {
  min-width: 2ch; text-align: center; font-weight: var(--fw-medium); font-variant-numeric: tabular-nums;
}

/* Product card (reference pattern) --------------------------------------- */
.ds-card {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: var(--space-3);
  color: inherit;
  text-decoration: none;
}
.ds-card__media {
  position: relative;
  aspect-ratio: 4 / 5;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--color-surface-sunken);
  isolation: isolate;
}
.ds-card__media img { width: 100%; height: 100%; object-fit: cover; }
/* Hover: a quiet title underline, no image zoom (the motion budget is spent elsewhere). */
@media (hover: hover) { .ds-card:hover .ds-card__link { text-decoration: underline; text-decoration-color: var(--color-line-strong); } }
.ds-card__badge { position: absolute; top: var(--space-3); left: var(--space-3); z-index: 1; }
.ds-card__add {
  position: absolute; right: var(--space-2); bottom: var(--space-2); z-index: 1;
  box-shadow: var(--shadow-md);
}
.ds-card__body { display: grid; gap: var(--space-1); align-content: start; padding-inline: 2px; }
.ds-card__title {
  font-family: var(--font-display); font-size: var(--text-md); font-weight: var(--fw-medium);
  line-height: 1.2; color: var(--color-text); letter-spacing: -.005em;
}
.ds-card__desc {
  font-size: var(--text-sm); color: var(--color-text-muted); line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.ds-card__price { margin-top: var(--space-1); font-size: var(--text-sm); }
.ds-card__link::after { content: ""; position: absolute; inset: 0; border-radius: var(--radius-lg); }
.ds-card__link { color: inherit; text-decoration: none; }
.ds-card__link:focus-visible { outline: none; }
.ds-card__link:focus-visible::after { box-shadow: var(--focus-ring); }

/* Skeleton (loading) — static, no shimmer: motion budget is reserved. */
.ds-skeleton { background: var(--color-surface-sunken); border-radius: var(--radius-sm); }
.ds-skeleton--text { height: .9em; border-radius: var(--radius-xs); }

/* Image that failed to load: components add .is-broken (never show a broken icon). */
.ds-img-fallback, .ds-card__media.is-broken {
  display: grid; place-items: center;
  background: var(--c-blush-100) url("../assets/wordmark.svg") center / 46% auto no-repeat;
}
.ds-card__media.is-broken img { opacity: 0; }

/* Empty state ------------------------------------------------------------- */
.ds-empty { display: grid; justify-items: center; gap: var(--space-3); text-align: center; padding: var(--space-9) var(--space-6); }
.ds-empty__art {
  display: grid; place-items: center; width: 88px; height: 88px; margin-bottom: var(--space-2);
  border-radius: 50%; background: var(--c-blush-100); color: var(--color-text-brand);
}
.ds-empty__art svg { width: 40px; height: 40px; }
.ds-empty h3 { font-size: var(--text-xl); font-weight: var(--fw-regular); }
.ds-empty p { color: var(--color-text-muted); max-width: 26ch; }

/* Notice / inline alert ---------------------------------------------------- */
.ds-notice {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-md);
  background: var(--c-blush-50); box-shadow: inset 0 0 0 1px var(--c-blush-200);
  font-size: var(--text-sm); line-height: 1.45; color: var(--color-text);
}
.ds-notice svg { flex: none; width: 18px; height: 18px; margin-top: 1px; color: var(--color-text-brand); }
.ds-notice--danger { background: var(--color-danger-bg); box-shadow: inset 0 0 0 1px rgba(179, 38, 30, .2); }
.ds-notice--danger svg { color: var(--color-danger); }
.ds-notice--success { background: var(--color-success-bg); box-shadow: inset 0 0 0 1px rgba(46, 101, 71, .2); }
.ds-notice--success svg { color: var(--color-success); }
