:root {
  --bg-color: #FAF8F5;
  --card-bg: #FFFFFF;
  --text-main: #1A1A1A;
  --primary-color: #C86D51;   /* decorativo y títulos grandes */
  --primary-dark: #A24226;    /* botones y texto: contraste AA con blanco */
  --wsp-color: #0E7C3A;       /* verde oscuro: el #25D366 original no da contraste con texto blanco */
  --wsp-hover: #0A6330;
  --border-color: #EFEAE4;
  --danger: #B3261E;
  --border-radius: 18px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* que ningún display: de otra regla anule el atributo hidden */
html { -webkit-text-size-adjust: 100%; }
img { max-width: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  margin: 0;
  --pad: clamp(16px, 3vw, 40px);
  padding: max(var(--pad), env(safe-area-inset-top)) max(var(--pad), env(safe-area-inset-right))
           max(var(--pad), env(safe-area-inset-bottom)) max(var(--pad), env(safe-area-inset-left));
  font-size: 1.25rem; /* = 20px, pero respeta el tamaño de letra que el usuario eligió en su celular */
  line-height: 1.45;
}

:focus-visible { outline: 4px solid #1D4ED8; outline-offset: 3px; }

header {
  text-align: center;
  padding: clamp(16px, 3vw, 40px) 0;
  border-bottom: 2px solid var(--border-color);
  margin: 0 auto clamp(20px, 3vw, 40px);
  max-width: 82.5rem;
}
header h1 { font-size: clamp(2rem, 1.4rem + 2.4vw, 3.2rem); color: var(--primary-dark); margin: 0 0 8px 0; line-height: 1.1; }
header p { margin: 0 auto; font-size: clamp(1.1rem, 1rem + .5vw, 1.4rem); color: #4A4A4A; max-width: 46ch; }

/* ---------- Galería ---------- */
.grilla-productos {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18.75rem), 1fr));
  gap: clamp(16px, 2vw, 32px);
  max-width: 82.5rem;
  margin: 0 auto;
}
.vacio { text-align: center; grid-column: 1 / -1; }

.tarjeta-producto {
  background: var(--card-bg);
  border: 2px solid var(--border-color);
  border-radius: var(--border-radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 10px rgba(0,0,0,0.05);
  transition: transform .15s ease, box-shadow .15s ease;
}
.tarjeta-producto .foto { position: relative; }
.tarjeta-producto img { width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; display: block; background: #EFEAE4; }
.foto-enlace { display: block; cursor: zoom-in; }
.foto-enlace:focus-visible { outline-offset: -6px; }
.tarjeta-producto.es-vendida img { filter: grayscale(0.8); opacity: .75; }
.etiqueta-vendida {
  position: absolute; top: 12px; left: 12px;
  background: #1A1A1A; color: #fff; font-weight: bold;
  padding: 6px 14px; border-radius: 999px; font-size: 1.05rem;
}

.info-producto { padding: 20px; display: flex; flex-direction: column; gap: 12px; flex-grow: 1; }
.info-producto h2 { font-size: 1.5rem; margin: 0; overflow-wrap: anywhere; }
.precio { font-size: 1.8rem; font-weight: bold; color: var(--primary-dark); }

.btn-comprar {
  display: block;
  background-color: var(--wsp-color);
  color: #FFFFFF;
  text-decoration: none;
  font-weight: bold;
  font-size: 1.2rem;
  text-align: center;
  padding: 18px 16px;
  min-height: 60px;
  border-radius: 12px;
  margin-top: auto;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.btn-comprar:hover, .btn-comprar:active { background-color: var(--wsp-hover); }
.btn-comprar:active { transform: scale(0.98); }
.btn-comprar.enviando { opacity: .85; pointer-events: none; }
.btn-vendido { background: #6B6B6B; box-shadow: none; cursor: default; }

footer { text-align: center; margin: 40px auto 16px; max-width: 82.5rem; }
.enlace-wsp { color: var(--wsp-color); font-weight: bold; }

/* ---------- Panel de administración ---------- */
.admin-container {
  width: 100%;
  max-width: 37.5rem;
  margin: 0 auto;
  background: #FFF;
  padding: 24px;
  border-radius: var(--border-radius);
  border: 2px solid var(--primary-color);
}
.titulo-admin { color: var(--primary-dark); text-align: center; margin-top: 0; }
.subtitulo-admin { margin: 8px 0 16px; }

.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-weight: bold; font-size: 1.2rem; margin-bottom: 8px; }
.form-control {
  width: 100%;
  padding: 16px;
  font-size: 1.2rem;
  border: 2px solid #8A8A8A;
  border-radius: 10px;
  background: #fff;
  color: var(--text-main);
}
#vista-previa { display: block; width: 100%; max-height: 260px; object-fit: contain; margin-top: 12px; border-radius: 10px; background: #EFEAE4; }

.btn-submit {
  width: 100%;
  background: var(--primary-dark);
  color: white;
  font-size: 1.4rem;
  font-weight: bold;
  padding: 20px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.btn-submit:disabled { opacity: .6; cursor: wait; }

.btn-secundario, .btn-peligro {
  font: inherit; font-weight: bold; font-size: 1.05rem;
  padding: 14px 16px; min-height: 52px;
  border-radius: 10px; cursor: pointer;
  background: #fff; color: var(--primary-dark); border: 2px solid var(--primary-dark);
}
.btn-peligro { color: var(--danger); border-color: var(--danger); }
.btn-texto { background: none; border: none; font: inherit; color: #4A4A4A; text-decoration: underline; padding: 14px; cursor: pointer; }
.enlace-boton { display: inline-block; text-decoration: none; text-align: center; }
.form-salir { text-align: center; margin-top: 16px; }
.enlaces-admin { margin: 0 0 12px; }
.ayuda { font-size: 1rem; color: #4A4A4A; }

.mensaje { padding: 14px 16px; border-radius: 10px; font-weight: bold; margin: 0 0 16px; }
.mensaje.ok { background: #DDF3E4; color: #0B4A24; }
.mensaje.error { background: #FBE3E1; color: #7A130D; }

.aviso { background: #FFF4D6; border: 2px solid #E0A800; border-radius: 12px; padding: 16px; margin-bottom: 24px; }
.aviso-titulo { margin: 0 0 8px; font-weight: bold; }
.aviso ul { margin: 0 0 12px; padding-left: 20px; font-size: 1rem; }

hr { border: 0; border-top: 2px solid var(--border-color); margin: 28px 0; }

.lista-piezas { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.pieza {
  display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center;
  border: 2px solid var(--border-color); border-radius: 14px; padding: 12px;
}
.pieza img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; background: #EFEAE4; }
.pieza.es-vendida img { filter: grayscale(.8); }
.pieza-datos { display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; }
.pieza-botones { grid-column: 1 / -1; display: grid; gap: 10px; }
.pieza.trabajando { opacity: .5; pointer-events: none; }

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

/* ---------- Clave visual (login) ---------- */
.instruccion { text-align: center; font-size: 1.3rem; margin: 0 0 8px; }
.contador { text-align: center; font-weight: bold; font-size: 1.2rem; margin: 0 0 16px; color: var(--primary-dark); }
.grilla-clave { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.ficha-clave {
  position: relative; padding: 0; border: 4px solid transparent; border-radius: 20px;
  background: none; cursor: pointer; aspect-ratio: 1; touch-action: manipulation;
}
.ficha-clave img { width: 100%; height: 100%; display: block; border-radius: 14px; }
.ficha-clave[aria-pressed="true"] { border-color: #1D4ED8; box-shadow: 0 0 0 3px #fff, 0 0 0 7px #1D4ED8; }
.ficha-clave[aria-pressed="true"] img { opacity: .72; }
.ficha-clave .marca {
  display: none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  min-width: 56px; height: 56px; border-radius: 999px; background: #1D4ED8; color: #fff;
  font-size: 1.9rem; font-weight: bold; line-height: 56px; text-align: center;
}
.ficha-clave[aria-pressed="true"] .marca { display: block; }
.btn-secundario.ancho { width: 100%; margin-top: 12px; }
.btn-submit:disabled { background: #8A8A8A; }

/* =====================================================================
   Pantallas grandes (laptop, monitor) y ajustes por dispositivo
   ===================================================================== */

/* Visor de foto grande */
#visor {
  border: none; padding: 0; background: transparent; color: #fff;
  max-width: 96vw; max-height: 96vh; overflow: visible; text-align: center;
}
#visor::backdrop { background: rgba(20, 12, 8, .86); }
#visor img { display: block; margin: 0 auto; max-width: 92vw; max-height: 78vh; border-radius: 12px; background: #fff; }
#visor-titulo { font-size: 1.4rem; font-weight: bold; margin: 14px 0 0; }
.visor-cerrar {
  font: inherit; font-weight: bold; font-size: 1.15rem; cursor: pointer;
  background: #fff; color: #1A1A1A; border: none; border-radius: 999px;
  padding: 12px 22px; margin-bottom: 14px; min-height: 52px;
}

/* Interacción con ratón / trackpad (no afecta al táctil) */
@media (hover: hover) {
  .tarjeta-producto:hover { transform: translateY(-4px); box-shadow: 0 12px 24px rgba(60, 30, 15, .14); }
  .btn-comprar:hover { background-color: var(--wsp-hover); }
  .btn-secundario:hover { background: #FBEFEA; }
  .btn-peligro:hover { background: #FDECEA; }
  .btn-submit:not(:disabled):hover { background: #8E3820; }
  .ficha-clave:hover { border-color: #93B4F5; }
  .btn-texto:hover { color: #000; }
}

/* ---- Tablet / laptop pequeña ---- */
@media (min-width: 720px) {
  .admin-container { padding: 32px; }
  .btn-comprar { font-size: 1.15rem; }
}

/* ---- Laptop: panel en dos columnas (formulario fijo a la izquierda, piezas a la derecha) ---- */
@media (min-width: 980px) {
  .admin-container.admin-ancho { max-width: 77.5rem; }
  .admin-container.admin-ancho .titulo-admin { font-size: 2.2rem; }
  .admin-container.admin-ancho .encabezado-admin { margin-bottom: 24px; }
  .admin-layout {
    display: grid;
    grid-template-columns: minmax(22.5rem, 27.5rem) minmax(0, 1fr);
    gap: 40px;
    align-items: start;
  }
  .col-form { position: sticky; top: 16px; }
  .col-form .subtitulo-admin, .col-lista .subtitulo-admin { margin-top: 0; }
  .lista-piezas { grid-template-columns: repeat(auto-fill, minmax(min(100%, 21.25rem), 1fr)); }
  .pieza { align-content: start; }
  .pieza-botones { grid-template-columns: 1fr 1fr; }
  .pieza-botones .btn-peligro { grid-column: 1 / -1; }
  .enlaces-admin { display: inline-block; margin-right: 12px; }
  .form-salir { display: inline-block; margin-left: 8px; }
}

/* Entrada con clave visual: tarjeta centrada; la grilla se adapta para que ENTRAR quede siempre a la vista */
.admin-login { max-width: 32.5rem; }
@media (min-width: 720px) {
  body.admin:has(.admin-login) { display: grid; align-content: center; min-height: 100vh; }
  .admin-login { max-width: 40rem; }
  .grilla-clave { grid-template-columns: repeat(4, 1fr); gap: 14px; }   /* tablet: 4 x 3 */
}
@media (min-width: 1000px) {
  .admin-login { max-width: 56.25rem; }
  .grilla-clave { grid-template-columns: repeat(6, 1fr); gap: 14px; }   /* laptop: 6 x 2 */
  .admin-login .btn-submit, .admin-login .btn-secundario.ancho { max-width: 30rem; margin-left: auto; margin-right: auto; display: block; }
}

/* ---- Monitores grandes: todo crece un poco para seguir siendo cómodo de leer ---- */
@media (min-width: 1600px) { html { font-size: 112.5%; } }
@media (min-width: 2200px) { html { font-size: 131.25%; } }

/* ---- Celulares apaisados (landscape): 2 columnas en la clave y menos alto ---- */
@media (max-height: 520px) and (orientation: landscape) {
  header { padding: 8px 0; margin-bottom: 12px; }
  .grilla-clave { grid-template-columns: repeat(6, 1fr); gap: 8px; }
  #visor img { max-height: 70vh; }
}

/* ---- Impresión: solo el catálogo ---- */
@media print {
  .btn-comprar, footer, #visor { display: none !important; }
  body { background: #fff; }
  .tarjeta-producto { break-inside: avoid; box-shadow: none; }
}

/* Botón "elegir archivo" grande y claro */
.form-control::file-selector-button {
  font: inherit; font-weight: bold; cursor: pointer;
  background: var(--primary-dark); color: #fff; border: none; border-radius: 8px;
  padding: 12px 18px; margin-right: 14px;
}

/* ---------- Saludo de Tuki en el encabezado (según hora / venta) ---------- */
.encabezado-admin {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.encabezado-admin .titulo-admin {
  margin: 0;
}
.saludo-encabezado {
  flex-shrink: 0;
  width: 200px;          /* celular */
  filter: drop-shadow(0 3px 8px rgba(0,0,0,.12));
  transition: opacity .35s ease, transform .35s ease;
}
.saludo-encabezado img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
}
.saludo-encabezado.es-venta {
  animation: saludo-rebote 0.7s ease both;
}
@keyframes saludo-rebote {
  0%   { transform: scale(0.6) translateY(12px); opacity: 0; }
  60%  { transform: scale(1.1) translateY(-3px); opacity: 1; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}
@media (min-width: 480px) {
  .saludo-encabezado { width: 190px; }
}
@media (min-width: 720px) {
  .saludo-encabezado { width: 230px; }
  .encabezado-admin { gap: 16px; }
}
@media (min-width: 1100px) {
  .saludo-encabezado { width: 250px; }
}