/* =========================================================
 * overrides.css · Joyería Acacio
 *
 * Parches CSS aplicados sobre el bundle de Vite (que está
 * minificado y no se puede editar directamente). Se carga
 * al final del <head> en index.html, así que estos estilos
 * GANAN sobre los del index-*.css.
 *
 * Cuando se rebuildee el frontend, lo ideal es mover estos
 * fixes al código fuente (ver CAMBIOS-FRONTEND-PENDIENTES.md).
 *
 * Tabla de contenidos:
 *   §1  Reset / fundamentos responsivos
 *   §2  Container y safe-area (notch iPhone)
 *   §3  Mobile pequeño  (≤360px)
 *   §4  Mobile normal   (≤480px)
 *   §5  Tablet vertical (481-767px)
 *   §6  Tablet horizont (768-1023px)
 *   §7  Desktop XL      (1600px+)
 *   §8  Pantallas 4K    (2200px+)
 *   §9  Landscape mobile
 *   §10 Touch (hover:none) y tap-targets
 *   §11 prefers-reduced-motion
 *   §12 Print
 *   §13 Misc: focus, scroll, lightbox, modal, toast
 * ========================================================= */

/* ──────────────────────────────────────────────────────────
 * §1  Reset / fundamentos responsivos
 * ────────────────────────────────────────────────────────── */

/* Evitar overflow horizontal por elementos que se salen del viewport
   (ej. hero__floating con left/right negativos en mobile chico).
   El bundle ya pone overflow-x: hidden en body, lo reforzamos en html
   por las dudas del scroll-chaining en iOS. */
html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Imágenes y videos siempre fluidos. */
img, video, svg {
  max-width: 100%;
  height: auto;
}

/* Si un elemento tiene texto largo (URL, código, número grande),
   que rompa antes de causar overflow horizontal. */
.amount, .product-card__price, .gold-card__price, .calc-result__value {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ──────────────────────────────────────────────────────────
 * §2  Container y safe-area (notch iPhone, gestos Android)
 * ────────────────────────────────────────────────────────── */

/* Padding del container respeta el notch en iPhone con orientación
   landscape, y la barra de gestos en Android. */
.container {
  padding-left: max(1.25rem, env(safe-area-inset-left));
  padding-right: max(1.25rem, env(safe-area-inset-right));
}

/* Botón flotante de WhatsApp respeta el área segura inferior
   (iPhone con barra de gestos). */
.float-wa {
  bottom: max(1.25rem, env(safe-area-inset-bottom));
  right: max(1.25rem, env(safe-area-inset-right));
}

/* ──────────────────────────────────────────────────────────
 * §3  Mobile pequeño · ≤ 360px (iPhone SE, Galaxy Fold)
 * ────────────────────────────────────────────────────────── */
@media (max-width: 360px) {
  :root { --container: 100%; }

  .container {
    padding-left: max(.8rem, env(safe-area-inset-left));
    padding-right: max(.8rem, env(safe-area-inset-right));
  }

  /* Header: comprimir para que entren todos los elementos */
  .brand__logo { width: 2.4rem; height: 2.4rem; }
  .brand__title { font-size: 1.05rem; }
  .brand__sub { display: none; }
  .header-actions { gap: .35rem; }
  .icon-btn { width: 2.3rem; height: 2.3rem; }

  /* Hero ultra-compacto */
  .hero { padding: 2rem 0 1.5rem; }
  .hero__title { font-size: clamp(1.75rem, 9vw, 2.2rem); margin-bottom: 1rem; }
  .hero__lead { font-size: .95rem; margin-bottom: 1.25rem; }
  .hero__cta { gap: .5rem; }
  .hero__cta .btn { flex: 1 1 auto; padding: .75rem 1rem; font-size: .85rem; }

  /* Floating badges del hero: dentro del viewport */
  .hero__floating.top    { top: .5rem; left: .5rem; }
  .hero__floating.bottom { bottom: .5rem; right: .5rem; }

  /* Stats: 2 columnas para que no se aplasten */
  .hero__stats { grid-template-columns: repeat(2, 1fr); gap: .4rem; }
  .luxe-stat { padding: .75rem .85rem; }
  .luxe-stat .value { font-size: 1.15rem; }

  /* Productos: 1 columna en pantalla muy chica */
  .product-grid { grid-template-columns: 1fr; gap: .75rem; }

  /* Section title más chico */
  .section-title { font-size: clamp(1.4rem, 6.5vw, 1.9rem); }
  .section { padding: 2rem 0; }

  /* Float WA aún más compacto */
  .float-wa { padding: .65rem .9rem; font-size: .8rem; }
  .float-wa svg { width: 1rem; height: 1rem; }
}

/* ──────────────────────────────────────────────────────────
 * §4  Mobile normal · ≤ 480px
 * ────────────────────────────────────────────────────────── */
@media (min-width: 361px) and (max-width: 480px) {
  :root { --container: 100%; }

  .container { padding-left: 1rem; padding-right: 1rem; }

  /* Hero compacto */
  .hero { padding: 2.5rem 0 2rem; }
  .hero__title { font-size: clamp(2rem, 8vw, 2.8rem); }
  .hero__floating.top {
    top: .75rem; left: .25rem;
    padding: .65rem .8rem;
  }
  .hero__floating.bottom {
    bottom: 1rem; right: .25rem;
    padding: .65rem .8rem;
  }
  .hero__floating .badge-value { font-size: 1rem; }

  /* Stats: 2 columnas */
  .hero__stats { grid-template-columns: 1fr 1fr; gap: .5rem; }

  /* Productos */
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: .75rem;
  }

  /* Filtros */
  .filters { gap: .35rem; }
  .filter-chip { padding: .45rem .85rem; font-size: .78rem; }

  /* Sections */
  .section { padding: 2.5rem 0; }
  .section-title { font-size: clamp(1.5rem, 6vw, 2.2rem); }

  /* Floating WA */
  .float-wa {
    padding: .75rem 1rem;
    font-size: .85rem;
    bottom: .75rem;
    right: .75rem;
  }
}

/* ──────────────────────────────────────────────────────────
 * §5  Tablet vertical · 481-767px
 * ────────────────────────────────────────────────────────── */
@media (min-width: 481px) and (max-width: 767px) {
  .product-grid { grid-template-columns: repeat(2, 1fr); gap: 1rem; }
  .hero__stats   { grid-template-columns: repeat(3, 1fr); }
  .gold-grid     { grid-template-columns: repeat(2, 1fr); }
  .feature-grid  { grid-template-columns: repeat(2, 1fr); }
  .product-specs { grid-template-columns: repeat(2, 1fr); }
}

/* ──────────────────────────────────────────────────────────
 * §6  Tablet horizontal · 768-1023px
 * ────────────────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 1023px) {
  .product-grid { grid-template-columns: repeat(3, 1fr); }

  /* Aprovechar ancho extra del tablet horizontal en product detail */
  .product-detail {
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
  }

  /* Footer: 2 columnas en lugar de auto-fit (que dejaba 1) */
  .site-footer__inner { grid-template-columns: repeat(2, 1fr); }

  /* Admin sidebar inline en tablet (en lugar de full-width arriba) */
  .admin-layout { grid-template-columns: 220px 1fr; }
  .admin-sidebar { padding: 1.2rem .9rem; }
  .admin-main { padding: 1.5rem 1.5rem 3rem; }
}

/* ──────────────────────────────────────────────────────────
 * §7  Pantallas grandes · ≥ 1600px
 * ────────────────────────────────────────────────────────── */
@media (min-width: 1600px) {
  :root { --container: 92rem; }
  .product-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
  .hero__title { font-size: clamp(3rem, 4.5vw, 5.6rem); }
}

/* ──────────────────────────────────────────────────────────
 * §8  Pantallas 4K · ≥ 2200px
 * ────────────────────────────────────────────────────────── */
@media (min-width: 2200px) {
  :root { --container: 110rem; }
  html { font-size: 18px; }
}

/* En monitores ultra-wide muy grandes, frenar el container para que
   el contenido no quede regado de un extremo al otro. */
@media (min-width: 3000px) {
  :root { --container: 120rem; }
}

/* ──────────────────────────────────────────────────────────
 * §9  Landscape mobile (alturas chicas)
 * ────────────────────────────────────────────────────────── */
@media (max-height: 520px) and (orientation: landscape) {
  .hero {
    padding: 2rem 0;
    min-height: 0;
  }
  .hero__grid { gap: 1.5rem; }
  .hero__image { aspect-ratio: 16 / 9; }
  .hero__title { font-size: clamp(1.8rem, 4vw, 2.5rem); margin-bottom: .75rem; }
  .hero__lead { margin-bottom: 1rem; }
  .login-shell { padding: 1rem; min-height: 100svh; }
}

/* En landscape de mobile, el header sticky se come 60px de pantalla.
   Lo reducimos un poco. */
@media (max-height: 520px) {
  .site-header__inner { padding: .6rem 0; }
  .brand__logo { width: 2.3rem; height: 2.3rem; }
}

/* ──────────────────────────────────────────────────────────
 * §10 Touch (hover:none) y tap targets
 *
 * En dispositivos sin hover real (mobile, tablet), los efectos
 * :hover quedan "pegados" tras tocar y se ven mal. Los desactivamos
 * y mostramos los overlays siempre.
 * ────────────────────────────────────────────────────────── */
@media (hover: none) {

  /* Overlay del producto siempre visible (no se oculta hasta hover) */
  .product-card__overlay {
    transform: none !important;
    position: static;
    padding: .5rem 1.1rem 0;
    opacity: 1;
  }
  .product-card:hover .product-card__overlay { transform: none; }

  /* Anular el lift de cards en touch */
  .product-card:hover,
  .luxe-card:hover,
  .gold-card:hover,
  .feature:hover { transform: none; }

  .product-card:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--line);
  }

  /* Botones e icon-btns sin transform en touch */
  .btn-primary:hover,
  .btn-ghost:hover,
  .btn-outline:hover,
  .btn-whatsapp:hover,
  .icon-btn:hover,
  .icon-btn-sm:hover,
  .filter-chip:hover,
  .pill:hover { transform: none; }

  /* Tap targets mínimos 44×44 (WCAG 2.5.5 AAA, también iOS HIG)
     para todo lo que sea clickable en mobile. */
  .icon-btn,
  .icon-btn-sm,
  .filter-chip,
  .nav a,
  .mobile-drawer a,
  .pagination button,
  .admin-tabs button,
  .segmented button,
  .lightbox__close,
  .lightbox__nav { min-height: 44px; min-width: 44px; }

  .filter-chip {
    padding: .55rem 1rem;
    line-height: 1.2;
  }

  /* La imagen del lightbox abre en zoom-out — en touch no tiene mucho
     sentido el cursor:zoom-in del bundle, lo limpiamos. */
  .product-gallery__main { cursor: default; }
  .product-gallery__main:hover img { transform: none; }

  /* Tabla con scroll snap táctil */
  .table-scroll { scroll-snap-type: y proximity; }
  .luxe-table tbody tr { scroll-snap-align: start; }
}

/* ──────────────────────────────────────────────────────────
 * §11 prefers-reduced-motion: matar todo lo costoso
 * ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  /* El bundle ya tiene una regla genérica con * que anula la mayoría
     de animaciones. Reforzamos las que tienen animaciones complejas
     (gradientes deslizantes, glows, blob drifts) y que el * no
     siempre cubre por especificidad. */
  .text-shine,
  .ambient-layer::before,
  .ambient-layer::after,
  .hero::before,
  .hero__image,
  .float-wa,
  .marquee__track,
  .luxe-shine::after,
  .product-card__price {
    animation: none !important;
  }

  /* El gradiente animado del precio queda como gold sólido */
  .product-card__price {
    background: var(--gold);
    -webkit-background-clip: initial;
    background-clip: initial;
    color: var(--gold);
    -webkit-text-fill-color: var(--gold);
  }

  /* Marquee se queda quieta — mejor centrar el contenido */
  .marquee__track {
    justify-content: center;
    transform: none !important;
  }

  .reveal {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }

  .scroll-indicator { display: none; }
}

/* ──────────────────────────────────────────────────────────
 * §12 Print: vista limpia para imprimir un producto
 * ────────────────────────────────────────────────────────── */
@media print {
  .ambient-layer,
  .noise-layer,
  .site-header,
  .site-footer,
  .float-wa,
  .marquee,
  .hero__floating,
  .scroll-indicator,
  .skip-link,
  .toast-stack,
  .lightbox,
  .modal-backdrop {
    display: none !important;
  }

  body {
    background: #fff !important;
    color: #000 !important;
  }

  .product-detail {
    grid-template-columns: 1fr 1fr !important;
    page-break-inside: avoid;
  }

  .product-card,
  .luxe-card,
  .gold-card,
  .feature {
    box-shadow: none !important;
    border-color: #ccc !important;
    background: #fff !important;
    color: #000 !important;
  }

  a { color: #000 !important; text-decoration: underline; }

  /* Mostrar URL después de los links externos al imprimir */
  a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: .8em;
    color: #666;
  }
}

/* ──────────────────────────────────────────────────────────
 * §13 Misc: focus, scroll, lightbox, modal, toast,
 *           tablas admin con scroll horizontal, helpers.
 * ────────────────────────────────────────────────────────── */

/* Skip-link con transición suave */
.skip-link { transition: left .2s ease; }

/* Focus-within visible en cards (teclado / lectores de pantalla) */
.product-card:focus-within {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px var(--gold-soft);
}

/* Helper class para el JSX: pausar animaciones cuando el elemento NO
   está en viewport (la clase la pone un IntersectionObserver). */
.pause-when-offscreen.is-offscreen,
.pause-when-offscreen.is-offscreen *,
.pause-when-offscreen.is-offscreen *::before,
.pause-when-offscreen.is-offscreen *::after {
  animation-play-state: paused !important;
}

/* Imágenes lazy con placeholder degradado mientras cargan */
.product-card__media {
  background: linear-gradient(135deg, #1a1a22, #0a0a0d 60%, #0e0e12);
}

/* Microinteracción extra: borde dorado al input válido */
.input:not(:placeholder-shown):valid {
  border-color: var(--gold-dim);
}

/* Scroll-margin-top para que los anchors no queden tapados por el
   header sticky (que mide ~6rem). */
:target { scroll-margin-top: 6rem; }
html { scroll-padding-top: 6rem; }

/* Reducir las animaciones del fondo siempre — son las más costosas
   en CPU/GPU y casi no se notan al ralentizarlas. */
.ambient-layer::before,
.ambient-layer::after {
  animation-duration: 60s;
  opacity: .35;
}

/* Tap highlight color → toque dorado discreto en lugar del azul iOS */
* {
  -webkit-tap-highlight-color: rgba(212, 175, 55, .15);
}

/* ─── Lightbox: navegación más usable en mobile ─── */
@media (max-width: 640px) {
  .lightbox__close {
    top: max(.6rem, env(safe-area-inset-top));
    right: max(.6rem, env(safe-area-inset-right));
    width: 2.6rem; height: 2.6rem;
  }
  .lightbox__nav.prev { left: .5rem; }
  .lightbox__nav.next { right: .5rem; }
  .lightbox__nav { width: 2.6rem; height: 2.6rem; }
  .lightbox__counter {
    bottom: max(.6rem, env(safe-area-inset-bottom));
    font-size: .72rem;
    padding: .3rem .8rem;
  }
  .lightbox__img { max-width: 96vw; max-height: 80vh; }
}

/* ─── Modal: en mobile, casi full-screen y scrolleable ─── */
@media (max-width: 640px) {
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    max-width: 100%;
    max-height: 95dvh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 1.2rem 1rem 1.4rem;
  }
  .modal__title { font-size: 1.2rem; }
  .modal__grid { grid-template-columns: 1fr; gap: .85rem; }
}

/* ─── Toasts: en mobile no chocan con el header sticky ─── */
@media (max-width: 640px) {
  .toast-stack {
    top: auto;
    bottom: max(5rem, calc(env(safe-area-inset-bottom) + 5rem));
    right: .75rem;
    left: .75rem;
  }
  .toast { min-width: 0; max-width: 100%; }
}

/* ─── Exchange (/exchange): tabla “Entidades” con scroll en viewports angostos ───
   Misma idea que admin: la API puede devolver muchas filas; el nombre de entidad
   largo no debe forzar overflow del viewport completo. */
@media (max-width: 768px) {
  #entidades .table-shell {
    width: 100%;
    max-width: 100%;
  }
  #entidades .table-scroll {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  /* Ancho mínimo para columnas legibles; el scroll horizontal queda en .table-scroll */
  #entidades .luxe-table {
    min-width: 32rem;
  }
  #entidades .entity-cell {
    max-width: 14rem;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

/* ─── Admin: tabla con scroll horizontal en mobile ───
   El bundle pone min-width:100% pero las celdas pueden hacer crecer
   la tabla más allá del contenedor. Le agregamos scroll horizontal
   suave al wrapper más cercano. */
.admin-card .admin-table,
.admin-table {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.admin-table > thead,
.admin-table > tbody { width: 100%; display: table; min-width: 640px; }

/* En admin layout < 1024 el sidebar se va arriba: que el nav scrolle
   horizontalmente como un dock en lugar de apilarse. */
@media (max-width: 1023px) {
  .admin-sidebar {
    position: relative;
    min-height: 0;
    border-right: none;
    border-bottom: 1px solid var(--line);
    padding: .85rem 1rem;
  }
  .admin-sidebar__brand {
    padding-bottom: .8rem;
    margin-bottom: .8rem;
  }
  .admin-nav {
    flex-direction: row;
    overflow-x: auto;
    scrollbar-width: none;
    gap: .35rem;
    padding-bottom: .25rem;
  }
  .admin-nav::-webkit-scrollbar { display: none; }
  .admin-nav a {
    flex: 0 0 auto;
    padding: .55rem .9rem;
    font-size: .85rem;
    white-space: nowrap;
  }
}

/* ─── Admin stats: en mobile chico, 2 columnas en lugar de auto-fit ─── */
@media (max-width: 480px) {
  .admin-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: .55rem;
  }
  .admin-stat .value { font-size: 1.4rem; }
}

/* ─── Filter chips: scroll horizontal en mobile, sin scrollbar ─── */
@media (max-width: 640px) {
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: .25rem;
    /* extender el scroll hasta los bordes del container, dando un
       hint visual de que hay más chips a la derecha */
    margin-left: calc(-1 * max(1rem, env(safe-area-inset-left)));
    margin-right: calc(-1 * max(1rem, env(safe-area-inset-right)));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  .filters::-webkit-scrollbar { display: none; }
  .filter-chip { flex: 0 0 auto; scroll-snap-align: start; }
}

/* ─── Float WA: en pantallas con header sticky bajo, no taparse mutuamente ─── */
@media (max-width: 480px) {
  .float-wa {
    bottom: max(.75rem, env(safe-area-inset-bottom));
    right: max(.75rem, env(safe-area-inset-right));
  }
}

/* ─── Pagination: en mobile más compacta ─── */
@media (max-width: 480px) {
  .pagination { gap: .2rem; flex-wrap: wrap; justify-content: center; }
  .pagination button {
    padding: .55rem .75rem;
    font-size: .8rem;
    min-height: 40px; min-width: 40px;
  }
}

/* ─── Mobile drawer: tap targets más cómodos ─── */
@media (max-width: 900px) {
  .mobile-drawer a {
    padding: 1rem 1.1rem;
    font-size: 1rem;
    min-height: 48px;
  }
}

/* ─── Header en pantallas medianas justas (~640-900) ─── */
@media (min-width: 640px) and (max-width: 899px) {
  .header-actions { gap: .5rem; }
  /* Hay espacio: dejamos brand sub */
}

/* ─── Hero: evitar que el image overflow vertical sea exagerado ─── */
@media (max-width: 1023px) {
  .hero__image { aspect-ratio: 4 / 5; max-height: 70vh; }
}

/* ─── Long-press preview: evitar el menu contextual de iOS sobre los
   logos del producto que son links ─── */
.product-card__media img {
  -webkit-touch-callout: none;
}

/* ─── Forzar que los inputs de tipo number en mobile no muestren
   las flechas (steppers) que rompen la altura ─── */
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* ─── Inputs: tipografía 16px en mobile para que iOS no haga zoom
   automático al enfocar el input. */
@media (max-width: 640px) {
  .input,
  .select,
  textarea.input,
  input,
  textarea,
  select { font-size: 16px; }
}

/* ─── Login card en mobile: respetar safe-area arriba (notch) ─── */
@media (max-width: 480px) {
  .login-shell {
    padding-top: max(2rem, env(safe-area-inset-top));
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
  .login-card { padding: 1.6rem 1.3rem; }
}

/* ─── Footer en mobile chico: bajar tipografía y compactar ─── */
@media (max-width: 480px) {
  .site-footer__inner {
    grid-template-columns: 1fr;
    gap: 1.4rem;
    padding: 2rem 0 1rem;
  }
  .footer-bar {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: .5rem;
    padding-bottom: max(2rem, env(safe-area-inset-bottom));
  }
}

/* ─── Mejor fallback visual para imágenes que no cargaron ─── */
img:not([src]),
img[src=""],
img.broken {
  background: linear-gradient(135deg, #1a1a22, #0a0a0d);
  border: 1px dashed var(--line);
}

/* ─── Cualquier <pre> / <code> que pudiera aparecer (admin) ─── */
pre, code {
  overflow-x: auto;
  word-break: normal;
  white-space: pre;
}

/* ─── Disabled visual consistente ─── */
button:disabled,
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: .5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ─── Mantener letterspacing legible cuando el font-size baja en mobile ─── */
@media (max-width: 480px) {
  .eyebrow { letter-spacing: .18em; font-size: .68rem; }
  .uppercase { letter-spacing: .08em; }
}
