/* ==========================================================================
   BoxMaker en /boxmaker/ — estilos propios.
   Se carga DESPUÉS de /styles.css y usa solo sus variables.
   Únicos colores escritos a mano (permitidos por la guía):
     WhatsApp (solo el botón de la franja) y el rojo suave de errores.
   Las líneas del SVG de piezas NO se recolorean aquí.
   ========================================================================== */

:root {
  /* Alturas medidas en el navegador: menú (logo 40 + 2×14 de padding + borde)
     y franja de título. La herramienta ocupa el resto de la pantalla. */
  --bm-nav-h: 69px;
  --bm-title-h: 133px;
  --bm-error: #e08f7c;
}

/* Lo que app.js oculta con [hidden] debe ocultarse aunque la clase del sitio
   (.field, .btn…) le ponga display. */
.bm-tool [hidden],
.bm-waband[hidden],
.bm-waband [hidden] { display: none !important; }

/* ---------- Franja de título ---------- */
.bm-titlebar { border-bottom: 1px solid var(--line-soft); }
.bm-titlebar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 26px var(--pad) 24px;
  min-height: calc(var(--bm-title-h) - 1px); /* 1px = borde inferior */
}
.bm-titlebar .eyebrow { margin-bottom: 12px; }
.bm-titlebar .hero-title {
  font-size: clamp(28px, 3.4vw, 42px);
  margin: 0;
}

/* ---------- Herramienta ---------- */
.bm-tool {
  display: grid;
  grid-template-columns: clamp(340px, 26vw, 460px) minmax(0, 1fr);
  grid-template-areas: "sidebar preview";
  height: calc(100dvh - var(--bm-nav-h) - var(--bm-title-h));
  min-height: 560px;
}

.bm-sidebar {
  grid-area: sidebar;
  background: var(--ink);
  border-right: 1px solid var(--line-soft);
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.bm-preview {
  grid-area: preview;
  background: var(--ink-raised);
  padding: 20px 24px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ---------- Formulario ---------- */
#params fieldset {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  margin: 0 0 16px;
  padding: 14px 14px 16px;
  min-width: 0;
}
#params legend,
.bm-technical summary {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper);
}
#params legend { padding: 0 6px; }

/* .field del sitio trae 18px de margen y 7px de hueco: aquí, más compacto. */
#params .field { gap: 6px; margin-bottom: 14px; }
#params .field:last-child { margin-bottom: 0; }
#params .field .field { margin-bottom: 10px; }
#params .field .field:last-child { margin-bottom: 0; }

#params .field-label {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper-dim);
}
#params .unit {
  text-transform: none;
  letter-spacing: 0.02em;
}

#params input[type="number"],
#params select {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 16px;
  padding: 8px 10px;
  background: var(--ink-deep);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--paper);
}
#params select { appearance: auto; }
#params select:focus {
  outline: none;
  border-color: var(--ember);
}
#params input[type="number"]:disabled {
  background: var(--ink-raised);
  color: var(--paper-dim);
  cursor: not-allowed;
}

/* Casillas y radios: sin el estilo de caja de texto de .field input. */
#params input[type="radio"],
#params input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  flex: 0 0 16px;
  accent-color: var(--ember);
  border: 0;
  box-shadow: none;
}
/* Foco visible (WCAG 2.4.7 / 1.4.11). .field input:focus de styles.css apaga
   el outline y las reglas de arriba pisan su borde y su halo: se repone aquí.
   Ámbar sobre --ink 3.17:1, sobre blanco 3.48:1. */
#params input[type="radio"]:focus-visible,
#params input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}
#params input[type="number"]:focus,
#params select:focus {
  border-color: var(--ember);
}
#params input[type="number"]:focus-visible,
#params select:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 1px;
}
.bm-technical summary:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: -2px;
  border-radius: 8px;
}
/* En el área de vista (--ink-raised) el ámbar no llega a 3:1: el foco va en --paper. */
.bm-preview :focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 2px;
}

#params .radio-option,
#params .field-checkbox {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
#params .radio-option { margin: 2px 0; }
#params .radio-option label,
#params .field-checkbox label {
  font-family: var(--font-body);
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--paper);
  cursor: pointer;
}

#params .help {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--paper-dim);
}

/* Bloques que dependen de la tapa: filete teal (información). */
#params .sliding-fields,
#params #handleFields,
#params .flat-fields {
  border-left: 2px solid var(--engrave);
  padding-left: 12px;
}

/* ---------- Ajustes de corte (plegado) ---------- */
.bm-technical {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  margin: 0 0 16px;
  background: var(--ink-deep);
}
.bm-technical summary {
  cursor: pointer;
  padding: 12px 14px;
  list-style-position: inside;
}
.bm-technical summary::marker { color: var(--ember); }
.bm-technical[open] summary { border-bottom: 1px solid var(--line-soft); }
.bm-technical-body { padding: 14px; }

/* ---------- Avisos, resumen y acciones ---------- */
#warnings { margin-bottom: 14px; }
#warnings:empty { display: none; margin: 0; }
#warnings .warning,
#warnings .error {
  padding: 8px 10px;
  margin-bottom: 8px;
  border-radius: 4px;
  border: 1px solid var(--line-soft);
  border-left-width: 3px;
  background: var(--ink-deep);
  color: var(--paper);
  font-size: 13.5px;
  line-height: 1.45;
}
#warnings .warning { border-left-color: var(--engrave); }
#warnings .error { border-left-color: var(--bm-error); }

#summary {
  margin-bottom: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  background: var(--ink-deep);
  color: var(--paper-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
}
#summary:empty { display: none; }

.bm-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.bm-actions .btn { flex: 1 1 auto; padding: 12px 16px; }
/* Contraste AA: texto --paper sobre ámbar (4.87:1); el blanco del sitio da 3.48:1. */
.bm-tool .btn-primary { color: var(--paper); }
#downloadBtn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.bm-status:empty { display: none; }
.bm-status,
.bm-notice {
  margin-top: 10px;
  font-size: 13.5px;
  line-height: 1.45;
  color: var(--paper);
}
.bm-notice {
  padding: 8px 10px;
  border: 1px solid var(--line-soft);
  border-left: 3px solid var(--engrave);
  border-radius: 4px;
  background: var(--ink-deep);
}

.bm-wa-inline { margin-top: 14px; }
.bm-wa-inline a {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--paper);
  text-decoration: underline;
  text-decoration-color: var(--ember);
  text-underline-offset: 3px;
}
.bm-wa-inline a:hover { color: var(--ember); }

/* ---------- Vista previa ---------- */
.preview-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 14px;
}
.preview-tabs [role="tablist"] {
  display: inline-flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}
.preview-tabs [role="tab"] {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--paper);
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 8px 14px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.preview-tabs [role="tab"]:hover { border-bottom-color: var(--line); }
.preview-tabs [role="tab"][aria-selected="true"] {
  font-weight: 600;
  border-bottom-color: var(--ember);
}

.open-control {
  flex: 1 1 160px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--paper);
}
.open-control input {
  flex: 1;
  min-width: 80px;
  accent-color: var(--ember);
}

.bm-btn-sm { padding: 8px 14px; font-size: 13px; }
.bm-preview .btn-ghost { background: var(--ink-deep); }
.bm-preview .btn-ghost[disabled] { opacity: 0.5; cursor: not-allowed; }

#preview {
  flex: 1 1 auto;
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
}
#preview svg {
  max-width: 100%;
  max-height: 100%;
  height: auto;
  background: var(--ink-deep);
  border: 1px solid var(--line);
  border-radius: 4px;
}

/* Escenario 3D: el visor lee --ink, --sheet, --paper, --engrave y --ember. */
#preview3d {
  position: relative;
  flex: 1 1 auto;
  width: 100%;
  min-height: 300px;
  background: var(--ink);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  overflow: hidden;
}
.viewer3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.viewer3d-message {
  position: absolute;
  inset: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 14px;
  color: var(--paper);
  background: var(--ink);
}
.viewer3d-message[hidden] { display: none; }

/* Nombre de la pieza elegida y medidas, flotando sobre el escenario. */
.piece-label,
.dims-panel {
  position: absolute;
  margin: 0;
  padding: 4px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.3;
  color: var(--paper);
  background: var(--ink-deep);
  border: 1px solid var(--line);
  border-radius: 4px;
  pointer-events: none;
}
.piece-label { top: 10px; left: 10px; }
.dims-panel { bottom: 10px; left: 10px; }

.engrave-note {
  margin: 12px 0 0;
  padding: 8px 10px;
  border-left: 3px solid var(--engrave);
  background: var(--ink-deep);
  border-radius: 4px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--paper);
}

/* ---------- Texto explicativo ---------- */
.bm-prose { max-width: 66ch; }
.bm-prose p + p { margin-top: 18px; }

.bm-steps { grid-template-columns: repeat(3, 1fr); }

.bm-lids {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}
.bm-lid {
  background: var(--ink);
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 24px 24px 26px;
}
.bm-lid h3 { font-size: 21px; margin-bottom: 10px; }
.bm-lid p { font-size: 15px; color: var(--paper-dim); }

.bm-faq {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 32px 40px;
  max-width: 980px;
}
.bm-faq-item h3 { font-size: 21px; margin-bottom: 10px; }
.bm-faq-item p { font-size: 15.5px; color: var(--paper-dim); }

/* ---------- Franja de WhatsApp ---------- */
.bm-waband { background: var(--ink); }
.bm-waband-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 24px 40px;
  padding-top: clamp(56px, 8vh, 88px);
  padding-bottom: clamp(56px, 8vh, 88px);
}
.bm-waband h2 { font-size: clamp(28px, 3.4vw, 42px); }
.bm-waband .section-sub { margin-top: 12px; }
.bm-btn-wa {
  background: #25D366;
  color: var(--paper);
}
.bm-btn-wa:hover { transform: translateY(-1px); border-color: var(--paper); }

/* ---------- Responsive (cortes del sitio) ---------- */
@media (max-width: 980px) {
  .bm-lids { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 820px) {
  /* Vista primero, formulario después; sin altura fija. */
  .bm-tool {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "preview" "sidebar";
    height: auto;
    min-height: 0;
  }
  .bm-sidebar {
    border-right: 0;
    border-top: 1px solid var(--line-soft);
    overflow-y: visible;
    padding: 20px var(--pad) 28px;
  }
  .bm-preview {
    overflow-y: visible;
    padding: 16px var(--pad) 20px;
  }
  #params { max-width: 560px; }
  #preview { min-height: 260px; }
  #preview3d { flex: none; height: min(70vh, 520px); }
  .bm-steps { grid-template-columns: 1fr; row-gap: 36px; }
  .bm-faq { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .bm-titlebar-inner { min-height: 0; }
  #preview { min-height: 0; padding: 10px; }
  .bm-lids { grid-template-columns: 1fr; }
  .bm-actions { flex-direction: column; }
  .bm-actions .btn,
  .bm-btn-wa { width: 100%; }
  .bm-preview .bm-btn-sm { flex: 1 1 auto; }
}
