/* =========================================================
   EMANUEL RELOJES — Probador Virtual
   Design System de marca
   ========================================================= */

:root {
  --color-bg: #f1f5f2;
  --color-primary: #06402b;
  --color-accent: #80ed80;
  --color-surface: #ffffff;
  --shadow-card: 2px 2px 6px rgba(0, 0, 0, 0.2);
  --radius-card: 10px;
  --font-heading: 'Italiana', serif;
  --font-body: 'Literata', serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--color-bg);
  color: var(--color-primary);
  font-family: var(--font-body);
  overscroll-behavior: none;
}

h1, h2, h3, .logo {
  font-family: var(--font-heading);
  font-weight: 400;
  letter-spacing: 0.03em;
  margin: 0;
}

button {
  font-family: var(--font-body);
  cursor: pointer;
  border: none;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------
   Header
   --------------------------------------------------------- */
.app-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 14px 16px 10px;
  text-align: center;
}

.app-header .logo {
  font-size: 0.8rem;
  letter-spacing: 0.25em;
  opacity: 0.75;
}

.app-header h1 { font-size: 1.9rem; }

/* ---------------------------------------------------------
   Shell / pasos del flujo
   --------------------------------------------------------- */
#app {
  position: relative;
  max-width: 940px;
  margin: 0 auto;
  padding: 0 12px 32px;
}

.step { display: none; }
.step.is-active { display: block; }

/* Banner de producto que llega por ?producto= desde Tiendanube */
.product-banner {
  max-width: 460px;
  margin: 0 auto 12px;
  padding: 8px 14px;
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  font-size: 0.85rem;
  text-align: center;
}

.product-banner strong { font-weight: 600; }

.product-banner-back {
  display: inline-block;
  margin-left: 10px;
  color: var(--color-primary);
  font-size: 0.8rem;
  opacity: 0.8;
}

/* ---------------------------------------------------------
   PASO 1 — Cámara
   --------------------------------------------------------- */
.camera-stage {
  position: relative;
  width: 100%;
  /* Encuadre APAISADO: el brazo se fotografía acostado, cruzando la
     pantalla. Se acota también por alto para que el obturador entre. */
  max-width: min(620px, calc((100vh - 230px) * 4 / 3));
  margin: 0 auto;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.camera-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Espejo sólo para cámara frontal — se aplica desde JS */
.camera-video.is-mirrored { transform: scaleX(-1); }

.guide-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.guide-arm {
  /* Relleno algo más presente: sobre una foto real, sólo con el trazo
     punteado la mano no se lee. */
  fill: rgba(128, 237, 128, 0.17);
  stroke: var(--color-accent);
  stroke-width: 3;
  stroke-dasharray: 10 8;
  stroke-linejoin: round;
}

.guide-fingers {
  stroke: var(--color-accent);
  stroke-width: 5;
  stroke-linecap: round;
  opacity: 0.7;
  fill: none;
}

/* Línea vertical que cruza la muñeca */
.guide-wrist-band {
  stroke: #ffffff;
  stroke-width: 4;
  stroke-dasharray: 12 10;
  opacity: 0.9;
}

/* Las dos marcas entre las que hay que apoyar la muñeca: son la regla
   de medir, por eso van más marcadas que el resto de la silueta. */
.guide-wrist-tick {
  stroke: var(--color-accent);
  stroke-width: 7;
  stroke-linecap: round;
  fill: none;
}

.guide-wrist-mark {
  fill: var(--color-accent);
  stroke: #ffffff;
  stroke-width: 3;
}

.guide-label {
  fill: #ffffff;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 34px;
  paint-order: stroke;
  stroke: rgba(0, 0, 0, 0.6);
  stroke-width: 7px;
}

.guide-label-small {
  font-size: 26px;
  font-weight: 400;
  opacity: 0.9;
}

.camera-message {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: rgba(6, 64, 43, 0.94);
  color: #fff;
  font-size: 0.9rem;
  line-height: 1.5;
}

.camera-message.hidden { display: none; }

.camera-message button {
  background: var(--color-accent);
  color: var(--color-primary);
  padding: 10px 20px;
  border-radius: 50px;
  font-weight: 600;
}

.camera-actions {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.btn-shutter {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
  border: 4px solid var(--color-accent);
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.btn-shutter:active { transform: scale(0.92); }
.btn-shutter:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------------------------------------------------------
   PASO 2 — Editor de canvas
   --------------------------------------------------------- */
.step-editor.is-active {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}

.canvas-stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#canvas {
  /* Mantiene el 4:3 del encuadre y se acota también por altura, para que
     la toolbar y el catálogo nunca queden fuera de la pantalla. */
  aspect-ratio: 4 / 3;
  width: auto;
  height: auto;
  max-width: min(100%, 620px);
  max-height: calc(100vh - 250px);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  background: #000;
  user-select: none;
  -webkit-user-select: none;
}

.canvas-toolbar {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-pill {
  background: var(--color-primary);
  color: #fff;
  padding: 9px 18px;
  border-radius: 50px;
  font-size: 0.9rem;
  box-shadow: var(--shadow-card);
}

.btn-pill-ghost {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1px solid var(--color-primary);
}

.canvas-hint {
  margin: 10px 0 0;
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
  max-width: 420px;
}

/* ---------------------------------------------------------
   Catálogo — panel lateral (desktop) / bottom-sheet (mobile)
   --------------------------------------------------------- */
.catalog-drawer {
  flex: 0 0 300px;
  background: var(--color-surface);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  max-height: calc(100vh - 150px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.catalog-drawer-handle { display: none; }

.catalog-drawer-scroll {
  padding: 16px;
  overflow-y: auto;
  flex: 1 1 auto;
  -webkit-overflow-scrolling: touch;
}

.catalog-title { font-size: 1.4rem; margin-bottom: 12px; }

.catalog-search { margin-bottom: 8px; }

.catalog-search input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid rgba(6, 64, 43, 0.25);
  border-radius: 50px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  color: var(--color-primary);
  background: var(--color-bg);
}

.catalog-search input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.catalog-count {
  margin: 0 0 10px;
  font-size: 0.72rem;
  opacity: 0.6;
}

.catalog-empty {
  font-size: 0.85rem;
  opacity: 0.7;
  text-align: center;
  padding: 20px 10px;
}

.catalog-empty.hidden { display: none; }

.catalog-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.watch-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  width: 100%;
  border-radius: var(--radius-card);
  border: 2px solid transparent;
  background: var(--color-bg);
  text-align: left;
  transition: border-color 0.15s ease, transform 0.1s ease;
}

.watch-card:active { transform: scale(0.98); }

.watch-card.is-selected {
  border-color: var(--color-accent);
  background: #eafcea;
}

.watch-card-thumb {
  width: 54px;
  height: 54px;
  object-fit: contain;
  background: #fff;
  border-radius: 8px;
  flex-shrink: 0;
}

.watch-card-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.watch-card-name { font-weight: 600; font-size: 0.95rem; }

/* Distintivo del reloj desde el que entró el cliente */
.watch-card-origin {
  display: inline-block;
  align-self: flex-start;
  background: var(--color-accent);
  color: var(--color-primary);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 50px;
}

/* Bloque de precios */
.watch-card-price {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.85rem;
}

.price-old { opacity: 0.55; font-size: 0.78rem; }
.price-now { font-weight: 600; font-size: 0.95rem; }

.price-off {
  background: #e11d48;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
}

.watch-card-transfer {
  font-size: 0.75rem;
  color: #0a6b46;
  font-weight: 600;
}

/* Swatches de variantes */
.variant-swatches {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.swatch {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #fff;
  outline: 1px solid rgba(6, 64, 43, 0.25);
  outline-offset: 0;
  flex-shrink: 0;
}

.swatch.is-active {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* Controles de manipulación */
/* Va arriba del catálogo: afecta a todos los relojes por igual. */
.watch-controls {
  margin-bottom: 16px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: var(--radius-card);
}

.watch-controls.hidden { display: none; }

.controls-title { font-size: 1.05rem; margin-bottom: 10px; }

.controls-help {
  font-size: 0.78rem;
  opacity: 0.7;
  margin: 0 0 10px;
  line-height: 1.4;
}

/* Selector de contextura de muñeca */
.wrist-picker {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.wrist-picker button {
  flex: 1;
  padding: 8px 4px;
  border-radius: 50px;
  border: 1.5px solid rgba(6, 64, 43, 0.3);
  background: var(--color-surface);
  color: var(--color-primary);
  font-size: 0.82rem;
  font-family: var(--font-body);
}

.wrist-picker button.is-active {
  background: var(--color-accent);
  border-color: var(--color-primary);
  font-weight: 600;
}

.size-readout {
  font-size: 0.75rem;
  opacity: 0.7;
  margin: 0 0 10px;
  line-height: 1.4;
}

.controls-swatches-label {
  font-size: 0.9rem;
  margin-bottom: 6px;
  display: block;
}

.catalog-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid rgba(6, 64, 43, 0.1);
  background: var(--color-surface);
}

.btn-primary, .btn-secondary {
  padding: 12px 16px;
  border-radius: 50px;
  font-weight: 600;
  font-size: 0.95rem;
  box-shadow: var(--shadow-card);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-primary);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-primary);
  border: 1.5px solid var(--color-primary);
}

.btn-primary:disabled, .btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* Toast de feedback */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(12px);
  background: var(--color-primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: 50px;
  font-size: 0.85rem;
  box-shadow: var(--shadow-card);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 60;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------------------------------------------------------
   Mobile — catálogo como bottom sheet deslizable
   --------------------------------------------------------- */
@media (max-width: 760px) {
  .step-editor.is-active { flex-direction: column; }

  .catalog-drawer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 80vh;
    flex: none;
    border-radius: 18px 18px 0 0;
    transform: translateY(calc(100% - 54px));
    transition: transform 0.28s ease;
    z-index: 40;
  }

  .catalog-drawer.is-open { transform: translateY(0); }

  .catalog-drawer-handle {
    display: block;
    width: 100%;
    height: 54px;
    background: var(--color-surface);
    position: relative;
    flex-shrink: 0;
  }

  .catalog-drawer-handle::before {
    content: "";
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 42px;
    height: 5px;
    border-radius: 4px;
    background: rgba(6, 64, 43, 0.25);
  }

  .catalog-drawer-handle::after {
    content: "⌚ Catálogo";
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.85rem;
    color: var(--color-primary);
    font-weight: 600;
  }

  /* En mobile la sheet cerrada ocupa 54px abajo: descontamos ese alto
     y el de la toolbar para que la foto entre completa. */
  #canvas {
    max-width: 100%;
    max-height: calc(100vh - 260px);
  }

  /* espacio para que la sheet cerrada no tape la toolbar */
  .step-editor.is-active { padding-bottom: 70px; }
}
