*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Open Sans', Arial, Helvetica, sans-serif;
  background: #1a1a1a;
}

.app {
  --sidebar-width: min(380px, 32vw);
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  position: relative;
}

/* —— Vista previa —— */
.preview {
  flex: 1;
  position: relative;
  min-width: 0;
  background: #2a2a2a;
  overflow: hidden;
}

.link-volver {
  position: absolute;
  top: 1.25rem;
  left: 1.25rem;
  z-index: 50;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.875rem;
  text-decoration: none;
  transition: color 0.2s;
}

.link-volver:hover {
  color: #fff;
}

.preview-layers {
  --layer-fade-duration: 1s;
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-layers.is-booting {
  opacity: 0;
}

.preview-layers picture {
  position: absolute;
  inset: 0;
  display: block;
  pointer-events: none;
}

.preview-layers .layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center center;
  pointer-events: none;
}

/* Orden de apilado por grupo (en el picture) */
.preview-layers picture:has(> .layer[data-base='true']) { z-index: 10; }
.preview-layers picture:has(> .layer[data-group='pavimento']) { z-index: 20; }
.preview-layers picture:has(> .layer[data-group='mueblesBajos']) { z-index: 30; }
.preview-layers picture:has(> .layer[data-group='mueblesAltos']) { z-index: 40; }
.preview-layers picture:has(> .layer[data-group='zocalo']) { z-index: 50; }
.preview-layers picture:has(> .layer[data-group='encimera']) { z-index: 60; }
.preview-layers picture:has(> .layer[data-group='grifo']) { z-index: 70; }
.preview-layers picture:has(> .layer[data-group='atrezo']) { z-index: 80; }
.preview-layers picture:has(> .layer[data-group='apertura']) { z-index: 90; }

.preview-layers .layer.hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.preview-layers .layer:not(.hidden) {
  visibility: visible;
  opacity: 1;
}

/* Nueva capa encima durante/tras el fade (+9 en su bloque) */
.preview-layers picture:has(> .layer[data-group='pavimento'].layer-fade-over) { z-index: 29; }
.preview-layers picture:has(> .layer[data-group='mueblesBajos'].layer-fade-over) { z-index: 39; }
.preview-layers picture:has(> .layer[data-group='mueblesAltos'].layer-fade-over) { z-index: 49; }
.preview-layers picture:has(> .layer[data-group='zocalo'].layer-fade-over) { z-index: 59; }
.preview-layers picture:has(> .layer[data-group='encimera'].layer-fade-over) { z-index: 69; }
.preview-layers picture:has(> .layer[data-group='grifo'].layer-fade-over) { z-index: 79; }
.preview-layers picture:has(> .layer[data-group='apertura'].layer-fade-over) { z-index: 99; }

.preview-layers .layer.layer-fade-over {
  visibility: visible;
}

.sidebar-toggle {
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
  z-index: 50;
  width: 28px;
  height: 56px;
  padding: 0;
  border: none;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.sidebar-toggle:hover {
  background: rgba(0, 0, 0, 0.65);
}

.sidebar-toggle-icon::after {
  content: '›';
  font-size: 1.25rem;
  line-height: 1;
}

.app.sidebar-collapsed .sidebar-toggle-icon::after {
  content: '‹';
}

/* —— Sidebar —— */
.sidebar {
  width: var(--sidebar-width);
  min-width: 280px;
  display: flex;
  flex-direction: column;
  background: rgba(18, 18, 18, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  transition: transform 0.35s ease, width 0.35s ease, min-width 0.35s ease;
  z-index: 40;
}

.app.sidebar-collapsed .sidebar {
  transform: translateX(100%);
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-logo {
  height: 50px;
  width: auto;
  object-fit: contain;
}

.sidebar-title {
  margin: 0;
  font-family: 'Basier Square', 'Open Sans SemiBold', sans-serif;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.35;
  color: #ccc;
  position: relative;
  top: -2px;
}

.menu-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 1.15rem 1.5rem;
  border: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: transparent;
  color: #fff;
  font-family: 'Open Sans SemiBold', sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.menu-item:hover,
.menu-item:focus-visible {
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.menu-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 0 1rem;
  min-height: 0;
}

.menu-panel:not([hidden]) {
  display: flex;
}

.menu-panel[hidden] {
  display: none !important;
}

.menu-main[hidden] {
  display: none !important;
}

.btn-volver {
  margin: 1rem 1.5rem 0.5rem;
  padding: 0;
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  text-align: left;
}

.btn-volver:hover {
  color: #fff;
}

.panel-title {
  margin: 0 1.5rem 1rem;
  padding: 0.65rem 1rem;
  background: #847361;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-align: center;
}

.menu-panel .panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 0 1.5rem;
}

.menu-panel .panel-content[hidden] {
  display: none !important;
}

.panel-placeholder {
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
  line-height: 1.5;
  padding: 1rem 0;
}

/* Pestañas LISO / ENMARCADA / TEXTURA */
.muebles-apertura-hint {
  display: none;
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  line-height: 1.35;
  color: rgba(255, 255, 255, 0.85);
}

#app:has(#panel-apertura .apertura-type-btn[data-option="gola"].is-active) .muebles-apertura-hint--gola,
#app:has(#panel-apertura .apertura-type-btn[data-option="tirador"].is-active) .muebles-apertura-hint--tirador,
#app:has(#panel-apertura .apertura-type-btn[data-option="perfil-j"].is-active) .muebles-apertura-hint--perfil-j {
  display: block;
}

.tab-group {
  display: flex;
  margin-bottom: 1rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.tab-btn {
  flex: 1;
  padding: 0.65rem 0.5rem;
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.75);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.tab-btn.is-active {
  background: #847361;
  color: #fff;
}

.acabado-panel.hidden {
  display: none !important;
}

.swatch-grid--textura .swatch {
  min-height: 3rem;
}

.tab-btn[hidden] {
  display: none;
}

.swatch[hidden] {
  display: none !important;
}

/* Toggle Con/Sin aplacado */
.toggle-group {
  display: flex;
  margin-bottom: 1.25rem;
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.toggle-btn {
  flex: 1;
  padding: 0.65rem 0.5rem;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.toggle-btn.is-active {
  background: #fff;
  color: #111;
}

.toggle-btn:not(:last-child) {
  border-right: 1px solid rgba(255, 255, 255, 0.25);
}

/* Grid de muestras */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem 0.75rem;
}

.swatch-grid--cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
  width: 100%;
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  color: #fff;
}

.swatch-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border: 2px solid transparent;
  overflow: hidden;
}

.swatch-thumb picture {
  display: block;
  width: 100%;
  height: 100%;
}

.swatch-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #333;
}

.swatch.is-active .swatch-thumb {
  border-color: #fff;
}

.swatch-check {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 18px;
  height: 18px;
  background: #fff;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #111;
  line-height: 1;
}

.swatch.is-active .swatch-check {
  display: flex;
}

.swatch-check::before {
  content: '✓';
}

.swatch-label {
  max-width: 100%;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-align: center;
  overflow-wrap: anywhere;
}

/* —— Apertura (como TDV: tipo + submodelos) —— */
.apertura-types {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.apertura-type-btn {
  position: relative;
  flex: 1 1 30%;
  min-width: 5.5rem;
  max-width: 7.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.35rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.apertura-type-btn__icon {
  width: 100%;
  aspect-ratio: 1;
  background: #6b6b6b;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.apertura-type-btn__icon picture {
  display: block;
  width: 100%;
  height: 100%;
}

.apertura-type-btn__icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.apertura-type-btn__label {
  font-size: 0.78rem;
  letter-spacing: 0.12em;
}

.apertura-type-btn.is-active {
  background: #fff;
  color: #111;
  border-color: #fff;
}

.apertura-type-btn.is-active::after {
  content: '';
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 22px;
  height: 22px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111' stroke-width='3'%3E%3Cpath d='M5 12l5 5L20 7'/%3E%3C/svg%3E") center/14px no-repeat;
  border: 1px solid #ccc;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.apertura-sub {
  margin-top: 0.5rem;
}

.apertura-sub[hidden] {
  display: none !important;
}

.gola-variants {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0.75rem;
  background: rgba(0, 0, 0, 0.35);
}

.gola-variant-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem;
  border: 2px solid transparent;
  background: transparent;
  color: #fff;
  cursor: pointer;
  min-width: 0;
}

.gola-variant-btn__swatch {
  width: 100%;
  aspect-ratio: 1;
  display: block;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.gola-variant-btn__swatch picture {
  display: block;
  width: 100%;
  height: 100%;
}

.gola-variant-btn__swatch img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gola-variant-btn__label {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.gola-variant-btn.is-active {
  border-color: #fff;
}

.gola-variant-btn.is-active .gola-variant-btn__swatch {
  box-shadow: 0 0 0 2px #fff;
}

.tirador-models {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  padding: 0.75rem;
  background: transparent;
}

.tirador-model-btn[data-model="perfil-5"] {
  grid-column: 1 / -1;
  justify-self: center;
  max-width: 25%;
}

.tirador-model-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem;
  border: 2px solid transparent;
  background: transparent;
  color: #fff;
  cursor: pointer;
  min-width: 0;
}

.tirador-model-btn__icon {
  width: 72px;
  aspect-ratio: 1;
  background: #333;
  overflow: hidden;
  display: block;
}

.tirador-model-btn__icon picture {
  display: block;
  width: 100%;
  height: 100%;
}

.tirador-model-btn__icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.tirador-model-btn__label {
  font-size: 0.7rem;
  color: #fff;
  letter-spacing: 0.05em;
}

.tirador-model-btn.is-active {
  border-color: #fff;
}

.sidebar-footer {
  padding: 1rem 1.5rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.design-load-message {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(32rem, 90vw);
  margin: 0;
  padding: 0.75rem 1rem;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  font-size: 0.85rem;
  line-height: 1.4;
  text-align: center;
  border-radius: 4px;
}

/* Overlay formulario exportar: solo sobre la cocina; el menú sigue usable */
.ob-formulario-overlay {
  position: absolute;
  inset: 0;
  z-index: 9999;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: rgba(0, 0, 0, 0.45);
}

.ob-formulario-overlay.is-loading {
  overflow: hidden;
}

.ob-formulario-overlay__iframe {
  display: block;
  width: 100%;
  height: max(100%, 32rem);
  min-height: 100%;
  border: 0;
  background: transparent;
  visibility: hidden;
}

.ob-formulario-overlay:not(.is-loading) .ob-formulario-overlay__iframe {
  visibility: visible;
}

.ob-formulario-overlay__loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  color: #fff;
  pointer-events: none;
}

.ob-formulario-overlay:not(.is-loading) .ob-formulario-overlay__loading {
  visibility: hidden;
}

/* X propia del overlay: solo si no podemos enganchar la X interna del iframe */
.ob-formulario-overlay__close {
  display: none;
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.ob-formulario-overlay.has-fallback-close:not(.is-loading) .ob-formulario-overlay__close {
  display: block;
}

.ob-formulario-overlay__spinner {
  width: 2rem;
  height: 2rem;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ob-formulario-spin 0.7s linear infinite;
}

.ob-formulario-overlay__loading-text {
  margin: 0;
  font-size: 0.78rem;
  letter-spacing: 0.1em;
}

@keyframes ob-formulario-spin {
  to {
    transform: rotate(360deg);
  }
}

.btn-exportar {
  width: 100%;
  padding: 1rem;
  border: none;
  background: #3d3d3d;
  color: #fff;
  font-family: 'Open Sans SemiBold', sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.14em;
  cursor: pointer;
  opacity: 1;
  transition: background 0.2s;
}

.btn-exportar:hover {
  background: #4a4a4a;
}

@media (min-width: 901px) {
  .app {
    position: relative;
  }

  .preview {
    flex: 1 1 100%;
    width: 100%;
  }

  .sidebar {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    max-height: none;
  }

  .sidebar-toggle {
    right: var(--sidebar-width);
    transition: background 0.2s, right 0.35s ease;
  }

  .app.sidebar-collapsed .sidebar-toggle {
    right: 0;
  }

  .app.sidebar-collapsed .sidebar {
    width: var(--sidebar-width);
    min-width: 280px;
  }
}

@media (max-width: 900px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    max-height: 45vh;
  }

  .app.sidebar-collapsed .sidebar {
    transform: translateY(100%);
  }

  .preview {
    flex: 1;
    min-height: 55vh;
  }

  /* Formulario de exportar abierto: el overlay vive dentro de .preview y en
     móvil esa franja es pequeña, así que plegamos el menú y la preview crece
     hasta ocupar toda la pantalla. Al cerrar, se quita la clase y vuelve solo. */
  .sidebar {
    transition: transform 0.35s ease, max-height 0.35s ease, opacity 0.25s ease;
  }

  .app.is-exporting .sidebar {
    max-height: 0;
    min-height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
  }

  .app.is-exporting .preview {
    min-height: 0;
  }
}

@media (max-width: 715px) {
  .preview {
    flex: none;
    min-height: 0;
    width: 100%;
    height: min(calc(100vw * 9 / 16), calc(100dvh - 14rem));
    transition: height 0.35s ease;
  }

  .app.is-exporting .preview {
    height: 100vh;
    height: 100dvh;
  }

  .sidebar {
    flex: 1 1 auto;
    max-height: none;
    min-height: 0;
    overflow: hidden;
  }

  .app.is-exporting .sidebar {
    flex: 0 1 auto;
    max-height: 0;
  }

  .sidebar-header,
  .sidebar-footer {
    flex-shrink: 0;
  }

  .menu-main,
  .menu-panel {
    min-height: 0;
  }
}
