/* ── product.css — Public product page ──────────────────────────────────
   Mobile-first. No frameworks. Clean & minimal.
   WCAG 2.1 AA · Safe-area · dvh · prefers-reduced-motion
────────────────────────────────────────────────────────────────────────── */
:root {
  --c-primary:  #2563eb;
  --c-primary-d:#1d4ed8;
  --c-success:  #16a34a;
  --c-danger:   #dc2626;
  --c-gray-50:  #f9fafb;
  --c-gray-100: #f3f4f6;
  --c-gray-200: #e5e7eb;
  --c-gray-300: #d1d5db;
  --c-gray-500: #6b7280;
  --c-gray-700: #374151;
  --c-gray-900: #111827;
  --radius:     10px;
  --radius-lg:  16px;
  --shadow:     0 2px 8px rgba(0,0,0,.10);
  --font: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Segoe UI', Roboto, Arial, sans-serif;
  --wa-green: #25d366;
  --wa-dark:  #128c7e;
  --chat-h:   420px;
  --focus-ring: 0 0 0 2px #fff, 0 0 0 4px var(--c-primary);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--c-gray-50);
  color: var(--c-gray-900);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh; min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Accessibility ─────────────────────────────────────────────────── */
@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;
  }
}

:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 4px; }
:focus:not(:focus-visible) { outline: none; box-shadow: none; }

/* ── Page layout ─────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 0 0 40px rgba(0,0,0,.06);
}

/* ── Skeleton ────────────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--c-gray-100) 25%,
              var(--c-gray-200) 50%, var(--c-gray-100) 75%);
  background-size: 400% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
}
@keyframes shimmer { to { background-position: -200% center; } }

/* ── Product image carousel ──────────────────────────────────────────── */
.carousel {
  position: relative;
  background: var(--c-gray-100);
  overflow: hidden;
  max-height: 260px;   /* constrain on small mobile */
}
.carousel-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  scrollbar-width: none;          /* Firefox */
}
.carousel-track::-webkit-scrollbar { display: none; }

.carousel-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  max-height: inherit;
}
.carousel-slide img {
  width: auto; height: auto;
  max-width: 75%;
  max-height: 85%;
  object-fit: contain; display: block;
}

.carousel-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 44px; height: 44px; border: none; border-radius: 50%;
  background: rgba(0,0,0,.40); color: #fff;
  font-size: 22px; line-height: 1;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .15s; z-index: 2;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.carousel-btn:hover { background: rgba(0,0,0,.65); }
.carousel-btn:active { background: rgba(0,0,0,.75); transform: translateY(-50%) scale(.95); }
.carousel-prev { left: 10px; }
.carousel-next { right: 10px; }

.carousel-dots {
  position: absolute; bottom: 12px;
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; z-index: 2;
}
.carousel-dot {
  width: 8px; height: 8px; border-radius: 50%; border: none; padding: 0;
  background: rgba(255,255,255,.50); cursor: pointer;
  transition: background .2s, transform .2s;
}
.carousel-dot.active {
  background: #fff; transform: scale(1.3);
}

/* ── Product header ──────────────────────────────────────────────────── */
.product-header {
  background: linear-gradient(135deg, #1e293b 0%, #1e40af 100%);
  padding: 28px 24px 24px;
  color: #fff;
}
.brand-name {
  font-size: 12px; font-weight: 600; opacity: .7;
  text-transform: uppercase; letter-spacing: .08em;
  margin-bottom: 12px;
}
.product-name {
  font-size: 22px; font-weight: 800; line-height: 1.25;
  margin-bottom: 10px;
}
.product-meta {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 0;          /* spacing lives in header padding-bottom now */
}
.product-price {
  font-size: 26px; font-weight: 700;
  display: flex; align-items: baseline; gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.product-price .currency { font-size: 16px; opacity: .75; }
.product-price .decimals { font-size: 16px; }
.product-price .price-original {
  font-size: 15px; font-weight: 400;
  text-decoration: line-through; opacity: .55;
  margin-right: 4px;
}
.product-price .discount-badge {
  font-size: 13px; font-weight: 700;
  background: #dc2626; color: #fff;
  padding: 2px 8px; border-radius: 6px;
  margin-left: 6px;
}

.meta-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 9999px;
  font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.15);
  color: #fff;
}
.meta-chip.out { background: rgba(220,38,38,.35); }
.meta-chip.shipping { background: rgba(34,197,94,.25); }
.meta-chip.delivery { background: rgba(59,130,246,.25); }
.meta-chip.payment { background: rgba(168,85,247,.25); }
.meta-chip.urgency { background: rgba(245,158,11,.30); animation: pulse-urgency 2s ease-in-out infinite; }
@keyframes pulse-urgency {
  0%, 100% { opacity: 1; }
  50%      { opacity: .7; }
}

/* ── Inline Buy Button (in header) ────────────────────────────────────── */
.btn-buy {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 14px 24px;
  margin-top: 18px;
  background: #25D366; color: #fff;
  border: none; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 3px 14px rgba(37,211,102,.4);
  transition: transform .15s, box-shadow .15s;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
  text-decoration: none;
  white-space: nowrap;
  animation: btn-buy-pulse 2.2s ease-in-out infinite;
  line-height: 1;
}
.btn-buy:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(37,211,102,.55); }
.btn-buy:active { transform: scale(.96); }

/* Pulso suave permanente */
@keyframes btn-buy-pulse {
  0%, 100% { box-shadow: 0 3px 14px rgba(37,211,102,.4); }
  50%      { box-shadow: 0 3px 22px rgba(37,211,102,.7), 0 0 0 6px rgba(37,211,102,.12); }
}

/* Pulso fuerte cuando hay handoff */
.btn-buy.handoff-pulse {
  animation: btn-buy-handoff 0.8s ease-in-out infinite;
}
@keyframes btn-buy-handoff {
  0%, 100% { box-shadow: 0 3px 14px rgba(37,211,102,.45); transform: scale(1); }
  50%      { box-shadow: 0 4px 30px rgba(37,211,102,.85), 0 0 0 10px rgba(37,211,102,.2); transform: scale(1.05); }
}

/* ── Floating Action Button ──────────────────────────────────────────── */

/* Preguntar: esquina inferior derecha */
.fab-chat {
  position: fixed;
  bottom: calc(16px + var(--safe-bottom));
  right: 16px;
  z-index: 100;
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  background: var(--c-primary); color: #fff;
  border: none; border-radius: 9999px;
  font-family: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(37,99,235,.40);
  transition: transform .15s, opacity .2s, box-shadow .15s;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
.fab-chat:hover { transform: translateY(-2px); }
.fab-chat:active { transform: scale(.95); }
.fab-chat.hidden { opacity: 0; pointer-events: none; transform: translateY(12px); }
.fab-label { white-space: nowrap; }

/* ── Chat collapse (mobile) ──────────────────────────────────────────── */
.chat-collapse-btn {
  display: none; /* visible only on mobile via JS */
  margin-left: auto;
  background: none; border: none; color: var(--c-gray-500);
  cursor: pointer; padding: 4px;
  transition: transform .2s;
}
.chat-collapsible.collapsed {
  max-height: 0; overflow: hidden;
  transition: max-height .3s ease;
}
.chat-collapsible {
  max-height: 800px;
  transition: max-height .3s ease;
}
/* Rotate chevron when collapsed */
.chat-collapsible.collapsed ~ .nothing { /* placeholder — rotation handled via JS aria-label */ }
.chat-section.chat-closed .chat-collapse-btn { transform: rotate(180deg); }

/* ── Chat heading clickable on mobile ────────────────────────────────── */
@media (max-width: 767px) {
  .chat-heading { cursor: pointer; }
  .chat-collapse-btn { display: flex; }
  .fab-chat { bottom: calc(16px + var(--safe-bottom)); right: 16px; }
}

/* ── Mobile phones ≤ 479px — stack header elements ───────────────────── */
@media (max-width: 479px) {
  .product-header { padding: 24px 20px 20px; }

  .product-name { font-size: 20px; }

  .btn-buy {
    padding: 12px 20px;
    font-size: 14px;
    margin-top: 14px;
  }

  .product-price { font-size: 24px; margin-bottom: 10px; }

  .product-meta { gap: 6px; }
  .meta-chip { font-size: 11px; padding: 4px 9px; }

  .product-body { padding: 20px 16px 0; gap: 14px; }
  .product-desc { padding: 14px; font-size: 13px; }
  .attrs-section { padding: 14px; }
  .attr-chip { font-size: 12px; padding: 5px 12px; }

  .chat-section { padding: 0 16px 16px; }
}

/* ── Product body ────────────────────────────────────────────────────── */
.product-body {
  padding: 24px 20px 0;
  display: flex; flex-direction: column; gap: 16px;
}

.product-desc {
  font-size: 14px; color: var(--c-gray-700);
  line-height: 1.65;
  background: var(--c-gray-50);
  border: 1px solid var(--c-gray-100);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0;                    /* gap in parent handles spacing */
  white-space: pre-line;        /* respect newlines in description */
}

.attrs-section {
  background: var(--c-gray-50);
  border: 1px solid var(--c-gray-100);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0;
}
.attrs-title {
  font-size: 12px; font-weight: 600; color: var(--c-gray-500);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 10px;
}
.attrs-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.attr-chip {
  padding: 6px 14px; border-radius: 9999px;
  border: 1px solid var(--c-gray-200);
  font-size: 13px; color: var(--c-gray-700);
  background: #fff;
}

/* ── Divider ────────────────────────────────────────────────────────── */
.section-divider {
  height: 1px; background: var(--c-gray-100);
  margin: 8px 0 0;
}

/* ── Chat widget ─────────────────────────────────────────────────────── */
.chat-section { padding: 0 20px 20px; flex: 1; display: flex; flex-direction: column; }

.chat-heading {
  font-size: 14px; font-weight: 600; color: var(--c-gray-700);
  margin-bottom: 12px; display: flex; align-items: center; gap: 8px;
}
.online-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c-success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

.chat-box {
  border: 1px solid var(--c-gray-200);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: var(--chat-h);
  box-shadow: var(--shadow);
}

.chat-messages {
  flex: 1; overflow-y: auto;
  padding: 16px 12px;
  display: flex; flex-direction: column; gap: 10px;
  background: #f0f2f5;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.msg {
  display: flex;
  max-width: 80%;
}
.msg.bot  { align-self: flex-start; }
.msg.user { align-self: flex-end;   }

.msg-bubble {
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: 0 1px 2px rgba(0,0,0,.08);
}
.msg.bot  .msg-bubble { background: #fff; color: var(--c-gray-900);
                         border-bottom-left-radius: 3px; }
.msg.user .msg-bubble { background: var(--c-primary); color: #fff;
                         border-bottom-right-radius: 3px; }

/* Typing indicator */
.msg-typing .msg-bubble {
  display: flex; gap: 4px; align-items: center; padding: 12px 16px;
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--c-gray-300);
  animation: bounce .8s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .30s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%            { transform: translateY(-5px); }
}

/* Chat input area */
.chat-input-area {
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--c-gray-200);
  display: flex; gap: 8px; align-items: flex-end;
}
.chat-input {
  flex: 1; padding: 9px 13px;
  border: 1px solid var(--c-gray-200); border-radius: 9999px;
  font-family: inherit; font-size: 16px; outline: none;
  resize: none; max-height: 100px; overflow-y: auto;
  transition: border-color .15s;
  background: var(--c-gray-50);
  -webkit-appearance: none; appearance: none;
}
.chat-input:focus { border-color: var(--c-primary); background: #fff; }
.chat-input::placeholder { color: var(--c-gray-300); }

.btn-send {
  width: 44px; height: 44px;
  background: var(--c-primary); border: none; border-radius: 50%;
  color: #fff; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer; transition: background .15s;
  touch-action: manipulation;
}
.btn-send:hover { background: var(--c-primary-d); }
.btn-send:active { transform: scale(.95); }
.btn-send:disabled { background: var(--c-gray-300); cursor: not-allowed; }

/* ── WhatsApp handoff CTA ────────────────────────────────────────────── */
.wa-cta {
  margin: 16px 0 0;
  padding: 14px 16px;
  background: #f0fdf4; border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  display: none; /* shown when handoff triggered */
}
.wa-cta.visible { display: flex; align-items: center; gap: 12px; }

/* Flash / pulse when handoff triggers */
.wa-cta.wa-cta-flash {
  animation: wa-cta-pulse 0.7s ease-in-out 4;
}
@keyframes wa-cta-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); transform: scale(1); }
  50%      { box-shadow: 0 0 18px 4px rgba(34,197,94,.45); transform: scale(1.02); }
}

.wa-cta a {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--wa-green); color: #fff;
  padding: 12px 20px; border-radius: 9999px;
  font-weight: 600; font-size: 14px; text-decoration: none;
  transition: background .15s; flex-shrink: 0;
  min-height: 44px;
  touch-action: manipulation;
}
.wa-cta a:hover { background: var(--wa-dark); }
.wa-cta a:active { transform: scale(.97); }
.wa-cta-text { font-size: 13px; color: var(--c-success); line-height: 1.4; }

/* ── Inactive overlay ────────────────────────────────────────────────── */
.inactive-notice {
  text-align: center; padding: 40px 20px;
  color: var(--c-gray-500);
}
.inactive-notice h2 { font-size: 18px; color: var(--c-gray-700); margin-bottom: 8px; }

/* ── Footer ──────────────────────────────────────────────────────────── */
.page-footer {
  text-align: center; padding: 16px 20px;
  font-size: 12px; color: var(--c-gray-400);
  border-top: 1px solid var(--c-gray-100);
}
.page-footer a { color: var(--c-gray-400); }

/* ── Error state ─────────────────────────────────────────────────────── */
.error-state {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh;
  padding: 40px 20px; text-align: center;
  flex-direction: column; gap: 12px; color: var(--c-gray-500);
}
.error-state h2 { font-size: 20px; color: var(--c-gray-700); }

/* ── Unavailable overlay (shown on deactivation / deletion) ────────── */
.unavailable-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  padding: 20px;
  animation: fadeInOverlay .3s ease;
}
.unavailable-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  text-align: center;
  max-width: 360px;
  width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
.unavailable-card h2 { font-size: 18px; color: var(--c-gray-700); margin: 0; }
.unavailable-card p  { font-size: 14px; color: var(--c-gray-500); margin: 0; }
@keyframes fadeInOverlay { from { opacity: 0 } to { opacity: 1 } }

/* ── Desktop QR Gate ─────────────────────────────────────────────────── */
.desktop-gate {
  min-height: 100vh; min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 50%, #c7d2fe 100%);
  padding: 40px 20px;
}
.dg-card {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,.10);
  padding: 48px 40px;
  text-align: center;
  max-width: 440px;
  width: 100%;
}
.dg-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 28px;
  font-size: 20px;
  font-weight: 700;
  color: var(--c-primary);
}
.dg-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--c-gray-900);
  margin-bottom: 8px;
  line-height: 1.3;
}
.dg-sub {
  font-size: 15px;
  color: var(--c-gray-500);
  margin-bottom: 32px;
  line-height: 1.5;
}
.dg-qr-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 2px solid var(--c-gray-200);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
}
.dg-qr-wrap canvas {
  display: block;
  image-rendering: pixelated;
}
.dg-url {
  font-size: 12px;
  color: var(--c-gray-400);
  word-break: break-all;
  margin-bottom: 28px;
  padding: 0 12px;
}
.dg-skip {
  background: none;
  border: none;
  color: var(--c-gray-400);
  font-size: 13px;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: 8px;
  transition: color .15s, background .15s;
}
.dg-skip:hover {
  color: var(--c-primary);
  background: rgba(37,99,235,.06);
}

/* ═══════════════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════════════ */

/* sm ≥480: floating card above mobile-edge */
@media (min-width: 480px) {
  body { padding: 20px 16px; background: var(--c-gray-100); }
  .page-wrap {
    border-radius: var(--radius-lg);
    margin: 20px auto;
    min-height: auto;
    box-shadow: 0 4px 24px rgba(0,0,0,.10);
  }
  .carousel { max-height: 300px; }
  .chat-input { font-size: 14px; }    /* restore — no iOS zoom issue on tablets */
}

/* md ≥640: tablet — comfortable sizing */
@media (min-width: 640px) {
  body { padding: 24px; }
  .page-wrap { max-width: 600px; }
  .product-name { font-size: 24px; }
  .btn-buy { font-size: 14px; padding: 12px 24px; width: auto; border-radius: 9999px; margin-top: 20px; }
  .product-header { padding: 32px 28px 28px; }
  .product-body { padding: 28px 28px 0; gap: 20px; }
  .product-desc { padding: 18px; font-size: 14px; }
  .attrs-section { padding: 18px; }
  .chat-section { padding: 0 24px 24px; }
  .carousel { max-height: 340px; }
  :root { --chat-h: 440px; }
}

/* lg ≥900: desktop — two-column layout */
@media (min-width: 900px) {
  :root { --chat-h: 520px; }

  body { padding: 40px 24px; }

  .page-wrap {
    max-width: 1040px;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 400px;
    grid-template-areas:
      "carousel  chat"
      "main      chat"
      "footer    footer";
    align-items: start;
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .carousel      { grid-area: carousel; max-height: 380px; }
  .product-main  { grid-area: main; }
  .chat-section  {
    grid-area: chat;
    padding: 24px;
    border-left: 1px solid var(--c-gray-100);
    position: sticky;
    top: 24px;
    align-self: start;
  }
  .page-footer   { grid-area: footer; }
  .section-divider { display: none; }

  /* On desktop two-column layout, chat is always visible — hide chat fab & collapse */
  .fab-chat { display: none !important; }
  .chat-collapse-btn { display: none !important; }
  .chat-collapsible { max-height: none !important; overflow: visible !important; }

  .inactive-notice { padding: 60px 28px; }
}

/* xl ≥1200: wider desktop */
@media (min-width: 1200px) {
  .page-wrap { max-width: 1160px; grid-template-columns: 1fr 440px; }
}

/* ── Landscape phone — limited vertical space ─────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  :root { --chat-h: 260px; }
  .product-header { padding: 16px 20px; }
  .product-name { font-size: 18px; }
  .product-price { font-size: 22px; }
  .btn-buy { font-size: 12px; padding: 8px 14px; }
}

/* ── Print ────────────────────────────────────────────────────────── */
@media print {
  .chat-section, .page-footer { display: none !important; }
  .page-wrap { box-shadow: none; max-width: 100%; }
  .carousel { break-inside: avoid; }
}
