/* Catálogo Bsale — estilos base. Cambia los colores de marca en :root. */
:root {
  --brand: #1f4fd1;
  --brand-ink: #ffffff;
  --brand-soft: #e8eefc;
  --messenger: #0866ff;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --ink: #16181d;
  --muted: #5b6270;
  --line: #e3e6eb;
  --ok: #137a3f;
  --ok-soft: #e4f5ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-lg: 0 8px 24px rgb(16 24 40 / 12%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Tema oscuro opcional: solo si config.php tiene store.theme = 'dark'. Por defecto el sitio es claro. */
:root[data-theme="dark"] {
  --brand: #7aa2ff;
  --brand-ink: #0b1020;
  --brand-soft: #1b2440;
  --messenger: #0866ff;
  --bg: #0f1115;
  --surface: #171a21;
  --ink: #eef0f4;
  --muted: #a3aab8;
  --line: #2a2f3a;
  --ok: #5fd08f;
  --ok-soft: #12291c;
  --warn: #f3b75b;
  --warn-soft: #2e2311;
  --bad: #ff8a80;
  --bad-soft: #321615;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-lg: 0 8px 24px rgb(0 0 0 / 45%);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 88px; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
img { max-width: 100%; display: block; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2.1rem); letter-spacing: -.01em; }

.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: 8px; top: -48px; z-index: 50; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { top: 8px; }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

/* Aviso de modo demostración */
.demo-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: .9rem; padding: 8px 16px; border-bottom: 1px solid var(--line); }

/* Encabezado */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.site-header .container { display: flex; align-items: center; gap: 16px; min-height: 68px; flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.brand { display: flex; flex-direction: column; text-decoration: none; color: var(--ink); margin-right: auto; }
.brand strong { font-size: 1.15rem; }
.brand span { font-size: .8rem; color: var(--muted); }
.site-nav { display: flex; gap: 6px; }
.site-nav a { text-decoration: none; color: var(--ink); padding: 8px 12px; border-radius: 10px; font-weight: 500; }
.site-nav a:hover, .site-nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }

.search { display: flex; flex: 1 1 320px; max-width: 480px; }
.search input {
  flex: 1; min-width: 0; height: 44px; padding: 0 14px; font: inherit; color: var(--ink);
  background: var(--bg); border: 1px solid var(--line); border-right: 0; border-radius: 10px 0 0 10px;
}
.search button { height: 44px; padding: 0 16px; border-radius: 0 10px 10px 0; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2;
  background: var(--brand); color: var(--brand-ink);
  transition: filter .15s ease, background-color .15s ease;
}
.btn:hover { filter: brightness(.92); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn-messenger { background: var(--messenger); color: #fff; }
.btn-whatsapp { background: #157a3e; color: #fff; }
.btn[hidden] { display: none; }
.btn-outline { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-outline:hover { background: var(--brand-soft); filter: none; }
.btn-block { width: 100%; }
.btn svg { width: 20px; height: 20px; flex: none; }

/* Filtros */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin: 24px 0 12px; }
.toolbar p { margin: 0; color: var(--muted); }
.toolbar select { height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: thin; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none; font-size: .92rem;
}
.chip small { color: var(--muted); }
.chip[aria-current="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.chip[aria-current="true"] small { color: inherit; opacity: .8; }

/* Grilla de productos */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; margin: 8px 0 32px; padding: 0; list-style: none; }
.card {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); transition: box-shadow .15s ease, transform .15s ease;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-media { aspect-ratio: 4 / 3; background: var(--brand-soft); display: grid; place-items: center; overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.placeholder { font-size: 2.2rem; font-weight: 700; color: var(--brand); opacity: .55; letter-spacing: .04em; user-select: none; }
.card-body { display: flex; flex-direction: column; gap: 6px; padding: 14px; flex: 1; }
.card-cat { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-title { font-size: 1rem; font-weight: 600; margin: 0; }
.card-title a { color: inherit; text-decoration: none; }
.card-title a::after { content: ""; position: absolute; inset: 0; }
.card { position: relative; }
.card-price { font-size: 1.2rem; font-weight: 700; margin-top: auto; }
.card-price small { font-size: .78rem; font-weight: 500; color: var(--muted); }
.card-actions { padding: 0 14px 14px; position: relative; z-index: 1; }
.card-actions .btn { font-size: .92rem; padding: 10px 8px; gap: 6px; text-align: center; }
.card-actions .btn svg { width: 18px; height: 18px; }

.badge { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; width: fit-content; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.in { color: var(--ok); background: var(--ok-soft); }
.badge.low { color: var(--warn); background: var(--warn-soft); }
.badge.out { color: var(--bad); background: var(--bad-soft); }

/* Paginación */
.pagination { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 40px; padding: 0; list-style: none; }
.pagination a, .pagination span {
  display: inline-flex; min-width: 44px; height: 44px; align-items: center; justify-content: center; padding: 0 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); text-decoration: none;
}
.pagination [aria-current="page"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* Estados vacíos y avisos */
.empty, .notice { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px 20px; text-align: center; margin: 24px 0; }
.notice.error { border-color: var(--bad); }
.alert { border-radius: 10px; padding: 12px 14px; margin: 0 0 16px; }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert.error { background: var(--bad-soft); color: var(--bad); }

/* Detalle de producto */
.breadcrumbs { font-size: .9rem; color: var(--muted); margin: 20px 0 12px; }
.breadcrumbs a { color: var(--muted); }
.product { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 32px; align-items: start; margin-bottom: 48px; }
.product-gallery { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; list-style: none; margin: 0; padding: 2px; }
.thumbs a { display: block; width: 72px; height: 72px; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.thumbs a[aria-current="true"] { border-color: var(--brand); }
.thumbs img { width: 100%; height: 100%; object-fit: contain; }
.product-media { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; aspect-ratio: 1 / 1; display: grid; place-items: center; }
.product-media img { width: 100%; height: 100%; object-fit: contain; }
.product-media .placeholder { font-size: 4rem; }
.product-info { display: flex; flex-direction: column; gap: 14px; }
.product-price { font-size: 1.9rem; font-weight: 800; }
.product-desc { color: var(--muted); white-space: pre-line; margin: 0; }
.product-info h2 { font-size: 1.1rem; margin: 8px 0 0; }
.variants { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.variants th, .variants td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.variants th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.variants tr:last-child td { border-bottom: 0; }
.variants td.num { white-space: nowrap; font-weight: 600; }
.variant-picker { display: flex; flex-wrap: wrap; gap: 8px; border: 0; padding: 0; margin: 0; }
.variant-picker legend { font-weight: 600; margin-bottom: 8px; }
.variant-picker label { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }
.variant-picker input { accent-color: var(--brand); }
.variant-picker label:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }
.actions .btn { flex: 1 1 220px; }
.hint { font-size: .85rem; color: var(--muted); margin: 0; }
.mt { margin-top: 16px; }
.sku { font-size: .85rem; color: var(--muted); }

/* Formulario de contacto */
.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; max-width: 640px; margin: 24px auto 48px; box-shadow: var(--shadow); }
.field select { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; }
.field input, .field textarea {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
.field textarea { min-height: 140px; resize: vertical; }
.field .error-text { color: var(--bad); font-size: .88rem; margin: 0; }
.field [aria-invalid="true"] { border-color: var(--bad); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.product-ref { display: flex; gap: 12px; align-items: center; background: var(--brand-soft); border-radius: 10px; padding: 10px 12px; margin-bottom: 16px; }

/* Pie */
.site-footer { border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: .9rem; padding: 24px 0; }
.site-footer .container { display: flex; flex-wrap: wrap; gap: 8px 24px; justify-content: space-between; }

/* Aviso flotante (mensaje copiado) */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow-lg);
  max-width: calc(100% - 32px); transition: opacity .2s ease, transform .2s ease; z-index: 60; font-size: .95rem;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.show.has-link { pointer-events: auto; }
.toast a { color: inherit; font-weight: 700; }

@media (max-width: 760px) {
  .product { grid-template-columns: 1fr; gap: 20px; }
  .product-media { aspect-ratio: 4 / 3; }
  .field-row { grid-template-columns: 1fr; gap: 0; }
  .site-header { position: static; }
  .search { max-width: none; order: 3; flex-basis: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .card-body { padding: 12px; }
  .card-actions { padding: 0 12px 12px; }
  .variants .hide-sm { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* ---------- Carrito y pedido ---------- */
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-lg { min-height: 52px; font-size: 1.05rem; }
.mt-sm { margin-top: 10px; }
.link-button { background: none; border: 0; padding: 4px 0; font: inherit; color: var(--brand); text-decoration: underline; cursor: pointer; }
.optional { font-weight: 400; color: var(--muted); font-size: .88rem; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

.cart-link { display: inline-flex; align-items: center; gap: 6px; }
.cart-link svg { width: 20px; height: 20px; }
.cart-count { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px; background: var(--brand); color: var(--brand-ink); font-size: .78rem; font-weight: 700; }
.cart-count[hidden] { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; margin: 24px 0 16px; }
.page-head h1 { margin: 0; }
.steps { display: flex; flex-wrap: wrap; gap: 6px 18px; list-style: none; margin: 0; padding: 0; font-size: .92rem; color: var(--muted); }
.steps li { display: inline-flex; align-items: center; gap: 8px; }
.steps .current { color: var(--ink); font-weight: 700; }
.steps .done { color: var(--ok); }
.step-num { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; border: 2px solid currentColor; font-size: .85rem; font-weight: 700; flex: none; }
.steps .current .step-num { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

.checkout-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; margin-bottom: 48px; }
.checkout-layout .form-card { max-width: none; margin: 0 0 20px; }
.checkout-form fieldset.form-card { min-width: 0; }
.checkout-form legend { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; font-weight: 700; padding: 0 6px; }
.summary { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); position: sticky; top: 92px; }
.summary h2 { font-size: 1.15rem; }
.summary-items { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; font-size: .92rem; max-height: 320px; overflow: auto; }
.summary-items li { display: flex; justify-content: space-between; gap: 12px; }
.summary-rows { margin: 0 0 12px; display: grid; gap: 6px; }
.summary-rows div { display: flex; justify-content: space-between; gap: 12px; }
.summary-rows dt { color: var(--muted); }
.summary-rows dd { margin: 0; text-align: right; }
.summary-total { border-top: 1px solid var(--line); padding-top: 10px; font-size: 1.2rem; font-weight: 800; }
.summary-total dt { color: var(--ink); }

.cart-list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.cart-item { display: grid; grid-template-columns: 72px minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 14px; border-bottom: 1px solid var(--line); }
.cart-item:last-child { border-bottom: 0; }
.cart-thumb { width: 72px; height: 72px; border-radius: 10px; overflow: hidden; background: #fff; display: grid; place-items: center; border: 1px solid var(--line); }
.cart-thumb img { width: 100%; height: 100%; object-fit: contain; }
.cart-thumb .placeholder { font-size: 1.1rem; }
.cart-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cart-name { color: var(--ink); font-weight: 600; text-decoration: none; }
.cart-name:hover { text-decoration: underline; }
.cart-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 4px; }
.qty-form { display: flex; align-items: center; gap: 8px; }
.qty { width: 84px; min-height: 40px; padding: 6px 10px; font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; }
.cart-subtotal { white-space: nowrap; }

.buy-form { display: flex; flex-direction: column; gap: 14px; }
.buy-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }
.buy-row .btn { flex: 1 1 200px; }
.qty-field { display: flex; flex-direction: column; gap: 4px; font-weight: 600; }

.choice-group { border: 0; padding: 0; margin: 0 0 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.choice-group > legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.choice-stack { flex-direction: column; }
.choice { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); cursor: pointer; }
.choice input { accent-color: var(--brand); width: 18px; height: 18px; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.method-fields { border-left: 3px solid var(--brand-soft); padding-left: 14px; margin-bottom: 8px; }
.method-fields[hidden] { display: none; }
.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.order-message { width: 100%; font: .92rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; resize: vertical; }
.order-send h2 { display: flex; align-items: center; gap: 10px; }

@media (max-width: 900px) {
  .checkout-layout { grid-template-columns: 1fr; }
  .summary { position: static; }
}
@media (max-width: 760px) {
  html { scroll-padding-top: 16px; }
  .cart-item { grid-template-columns: 56px minmax(0, 1fr); }
  .cart-thumb { width: 56px; height: 56px; }
  .cart-subtotal { grid-column: 2; }
  .site-nav { flex-wrap: wrap; }
}