:root {
  --bg: #f2eee8;
  --bg-2: #e7e1d8;
  --ink: #1f1d1b;
  --ink-2: #6b665f;
  --line: rgba(31, 29, 27, 0.12);
  --card: rgba(255, 253, 250, 0.9);
  --accent: #1f1d1b;
  --sheet-h: 220px;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }

/* ---------- Header ---------- */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 3;
  padding: calc(14px + env(safe-area-inset-top)) 18px 0;
  pointer-events: none;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 11px; letter-spacing: 0.22em; font-weight: 600; }
.brand-x { color: var(--ink-2); letter-spacing: 0; }
.brand-client { font-weight: 500; }
.badge {
  margin-left: 6px; padding: 3px 8px; border-radius: 99px; border: 1px solid var(--line);
  letter-spacing: 0.08em; font-weight: 500; font-size: 10px; color: var(--ink-2); background: var(--card);
}
.title { font-family: var(--serif); font-weight: 500; font-size: 34px; line-height: 1.05; margin: 12px 0 2px; }
.title em { font-style: italic; color: var(--ink-2); }
.spec { margin: 0; font-size: 13px; color: var(--ink-2); }

/* ---------- Botón de ayuda + instructivo ---------- */
.help-btn {
  position: fixed; top: calc(14px + env(safe-area-inset-top)); right: max(16px, env(safe-area-inset-right)); z-index: 5;
  width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}
.help-btn svg { width: 24px; height: 24px; fill: currentColor; }
.help {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 20px;
  background: rgba(31, 29, 27, 0.4); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.help[hidden] { display: none; }
.help-card {
  position: relative; width: 100%; max-width: 420px; background: var(--bg);
  border-radius: 22px; padding: 26px 22px 22px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.3);
  max-height: 86vh; overflow-y: auto;
}
.help-close {
  position: absolute; top: 14px; right: 14px; width: 32px; height: 32px; border-radius: 50%;
  border: 0; background: var(--bg-2); color: var(--ink-2); font-size: 14px; cursor: pointer; line-height: 1;
}
.help-card h2 { font-family: var(--serif); font-weight: 600; font-size: 27px; margin: 0 0 16px; }
.help-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 13px; }
.help-list li { font-size: 14.5px; line-height: 1.5; color: var(--ink-2); }
.help-list strong { color: var(--ink); font-weight: 600; }
.help-list em { font-style: normal; font-weight: 600; color: var(--ink); background: var(--bg-2); padding: 1px 7px; border-radius: 6px; }
.help-link { display: inline-block; margin-top: 18px; color: var(--ink); font-size: 13px; font-weight: 500; text-decoration: none; }

/* ---------- Overlay del AR a medida (WebXR) ---------- */
#lmAR { position: fixed; inset: 0; z-index: 50; font-family: var(--sans); }
#lmGest { position: absolute; inset: 0; touch-action: none; }
#lmHint {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  background: rgba(31, 29, 27, 0.72); color: #fff; padding: 9px 15px; border-radius: 99px;
  font-size: 13px; font-weight: 500; max-width: 92vw; text-align: center; transition: opacity 0.5s;
}
#lmHint.fade { opacity: 0; pointer-events: none; }
#lmFps {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); left: calc(14px + env(safe-area-inset-left));
  color: rgba(255, 255, 255, 0.75); font-size: 11px; font-weight: 600;
  background: rgba(0, 0, 0, 0.35); padding: 3px 7px; border-radius: 6px;
}
#lmExit {
  position: absolute; top: calc(14px + env(safe-area-inset-top)); right: calc(14px + env(safe-area-inset-right));
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(31, 29, 27, 0.6);
  color: #fff; font-size: 16px; cursor: pointer; line-height: 1;
}
#lmBar {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px max(14px, env(safe-area-inset-left)) calc(14px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-right));
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.35));
}
#lmHgt {
  display: flex; align-items: center; gap: 12px; color: #fff; font-size: 13px; font-weight: 600;
  background: rgba(31, 29, 27, 0.58); padding: 9px 15px; border-radius: 99px;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
#lmHgt span { flex: none; }
#lmHgt input { flex: 1; accent-color: #fff; }
#lmTela { display: flex; align-items: center; gap: 6px; overflow-x: auto; scrollbar-width: none; }
#lmTela::-webkit-scrollbar { display: none; }
.lmChip {
  flex: none; border: 0; border-radius: 99px; padding: 7px 13px; font-size: 13px; font-weight: 600;
  background: rgba(255, 255, 255, 0.88); color: #1f1d1b; cursor: pointer;
}
.lmChip.on { background: #1f1d1b; color: #fff; }
.lmColors { display: flex; align-items: center; gap: 6px; flex: none; padding-left: 4px; }
.lmDot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.7); padding: 0; cursor: pointer; }
.lmDot.on { border-color: #fff; box-shadow: 0 0 0 2px #1f1d1b; }

/* ---------- Visor ---------- */
model-viewer {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  background: radial-gradient(120% 80% at 50% 38%, #fbf9f6 0%, var(--bg) 55%, var(--bg-2) 100%);
  --poster-color: transparent;
  --progress-bar-color: var(--ink);
}

/* ---------- Botón AR ---------- */
.ar-btn {
  position: absolute; right: 16px; bottom: calc(var(--sheet-h) + 14px);
  display: inline-flex; align-items: center; gap: 10px;
  padding: 14px 20px; border: 0; border-radius: 99px;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}
.ar-btn svg { width: 20px; height: 20px; fill: currentColor; }

/* ---------- Panel configurador ---------- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  pointer-events: auto; /* el slot por defecto de model-viewer lo desactiva */
  background: var(--card);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  border-top: 1px solid var(--line);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.06);
}
.tabs {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 10px; padding: 0 16px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; border: 0; background: none; cursor: pointer;
  padding: 8px 12px; border-radius: 99px; font-size: 14px; font-weight: 500; color: var(--ink-2);
}
.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; }
.tab-toggle { display: inline-flex; align-items: center; gap: 6px; margin-left: auto; border: 1px solid var(--line) !important; }
.tab-toggle svg { width: 18px; height: 18px; fill: currentColor; }
.tab-toggle[aria-pressed="true"] { background: #fff !important; color: var(--ink) !important; border-color: var(--ink) !important; }

.panel { min-height: 92px; }
.panel[hidden] { display: none; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: flex; align-items: center; gap: 8px;
  padding: 6px 12px 6px 6px; border-radius: 99px; border: 1px solid var(--line);
  background: #fff; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.chip:disabled { opacity: 0.4; cursor: default; }
.chip .sw { width: 30px; height: 30px; }
.chips.small .chip { font-size: 13px; }
.chips.small .sw { width: 24px; height: 24px; }

.sw {
  display: inline-block; border-radius: 50%; flex: none;
  background-size: 260%; background-blend-mode: multiply;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.swatches { display: flex; gap: 12px; flex-wrap: wrap; padding-top: 2px; }
.swatch {
  width: 42px; height: 42px; padding: 0; border-radius: 50%; border: 0; cursor: pointer;
  background: none; position: relative;
}
.swatch .sw { width: 100%; height: 100%; }
.swatch[aria-pressed="true"]::after {
  content: ""; position: absolute; inset: -5px; border-radius: 50%; border: 2px solid var(--ink);
}

.note { margin: 10px 0 0; font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.note strong { color: var(--ink); font-weight: 600; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.label { font-size: 13px; color: var(--ink-2); }
.seg { display: inline-flex; background: var(--bg-2); border-radius: 99px; padding: 3px; }
.seg button {
  border: 0; background: none; padding: 7px 14px; border-radius: 99px; cursor: pointer; font-size: 14px; color: var(--ink-2);
}
.seg button[aria-pressed="true"] { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1); }

.sheet-foot {
  display: flex; flex-wrap: wrap; gap: 4px 12px; justify-content: space-between;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2);
}
.sheet-foot a { color: var(--ink); text-decoration: none; font-weight: 500; }
.ios-tip { display: none; }
.is-ios .ios-tip { display: inline; }

/* ---------- Medidas ---------- */
.dot, .dim { display: none; }
.show-dims .dot {
  display: block; width: 10px; height: 10px; padding: 0; border-radius: 50%;
  border: 2px solid #fff; background: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
  --min-hotspot-opacity: 1;
}
.show-dims .dim {
  display: block; padding: 4px 9px; border-radius: 99px; background: var(--ink); color: #fff;
  font-size: 12px; font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  --min-hotspot-opacity: 1;
}
.dim-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; display: none; }
.show-dims .dim-lines { display: block; }
.dim-lines line { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 5 4; }
model-viewer[ar-status="session-started"] .dim-lines line,
model-viewer[ar-status="object-placed"] .dim-lines line { stroke: #fff; }

/* ---------- Estados ---------- */
.toast {
  position: absolute; left: 50%; top: calc(18px + env(safe-area-inset-top)); transform: translate(-50%, -20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 99px; font-size: 13px; font-weight: 500;
  opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; z-index: 4; max-width: calc(100% - 32px); text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.busy {
  position: absolute; left: 16px; bottom: calc(var(--sheet-h) + 22px);
  display: none; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2);
  background: var(--card); padding: 8px 12px; border-radius: 99px; border: 1px solid var(--line);
}
.busy.on { display: inline-flex; }
.spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--ink); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* En AR (WebXR): panel compacto sobre la cámara */
model-viewer[ar-status="session-started"] .sheet,
model-viewer[ar-status="object-placed"] .sheet {
  left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  border-radius: 20px; padding: 6px 12px 12px;
}

/* Handle para colapsar el panel en AR y liberar la pantalla para arrastrar/escalar el sillón */
.sheet-grip { display: none; }
model-viewer[ar-status="session-started"] .sheet-grip,
model-viewer[ar-status="object-placed"] .sheet-grip {
  display: flex; position: relative; align-items: center; justify-content: center;
  width: 100%; border: 0; background: none; cursor: pointer;
  padding: 14px 0 8px; color: var(--ink-2); font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
}
model-viewer[ar-status="session-started"] .sheet-grip::before,
model-viewer[ar-status="object-placed"] .sheet-grip::before {
  content: ""; position: absolute; top: 5px; left: 50%; transform: translateX(-50%);
  width: 42px; height: 4px; border-radius: 99px; background: var(--line);
}
/* Colapsado en AR: queda solo el handle; el sillón se mueve/rota/escala en toda la pantalla */
model-viewer.ar-min[ar-status="session-started"] .tabs,
model-viewer.ar-min[ar-status="object-placed"] .tabs,
model-viewer.ar-min[ar-status="session-started"] .panel,
model-viewer.ar-min[ar-status="object-placed"] .panel {
  display: none !important;
}
/* Colapsado = píldora chica abajo-centro, para no interceptar el gesto de 2 dedos (rotar) ni el de 1 dedo (mover) */
model-viewer.ar-min[ar-status="session-started"] .sheet,
model-viewer.ar-min[ar-status="object-placed"] .sheet {
  left: 50%; right: auto; transform: translateX(-50%);
  width: auto; max-width: 68vw; padding: 2px 12px 6px; touch-action: none;
}
model-viewer.ar-min[ar-status="session-started"] .sheet-grip,
model-viewer.ar-min[ar-status="object-placed"] .sheet-grip {
  padding: 9px 4px 3px;
}
model-viewer.ar-min[ar-status="session-started"] .sheet-grip::before,
model-viewer.ar-min[ar-status="object-placed"] .sheet-grip::before {
  display: none;
}

/* Botón de ayuda DENTRO de la cámara (solo durante la sesión AR) */
.ar-help-btn, .ar-help { display: none; }
model-viewer[ar-status="session-started"] .ar-help-btn,
model-viewer[ar-status="object-placed"] .ar-help-btn {
  display: inline-flex; align-items: center; justify-content: center; pointer-events: auto;
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: calc(12px + env(safe-area-inset-right)); z-index: 5;
  width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: rgba(31, 29, 27, 0.55); color: #fff; cursor: pointer;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}
.ar-help-btn svg { width: 24px; height: 24px; fill: currentColor; }
model-viewer[ar-status="session-started"] .ar-help:not([hidden]),
model-viewer[ar-status="object-placed"] .ar-help:not([hidden]) {
  display: flex; pointer-events: auto;
  position: absolute; inset: 0; z-index: 6; align-items: center; justify-content: center; padding: 20px;
  background: rgba(10, 8, 6, 0.5); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.ar-help-card {
  position: relative; max-width: 320px; width: 100%;
  background: rgba(28, 24, 20, 0.94); color: #fff; border-radius: 18px; padding: 20px 18px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.ar-help-card h3 { margin: 0 0 12px; font-family: var(--serif); font-weight: 600; font-size: 22px; }
.ar-help-card ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.ar-help-card li { font-size: 14px; line-height: 1.45; color: rgba(255, 255, 255, 0.85); }
.ar-help-card b { color: #fff; font-weight: 600; }
.ar-help-close {
  position: absolute; top: 12px; right: 12px; width: 30px; height: 30px; border-radius: 50%;
  border: 0; background: rgba(255, 255, 255, 0.14); color: #fff; font-size: 13px; cursor: pointer; line-height: 1;
}
model-viewer[ar-status="session-started"] .sheet-foot,
model-viewer[ar-status="object-placed"] .sheet-foot,
model-viewer[ar-status="session-started"] .note,
model-viewer[ar-status="object-placed"] .note { display: none; }
model-viewer[ar-status="session-started"] .panel,
model-viewer[ar-status="object-placed"] .panel { min-height: 0; }

/* ---------- QR (escritorio) ---------- */
.qr {
  position: fixed; left: 24px; bottom: 44px; z-index: 3;
  display: flex; gap: 14px; align-items: center; max-width: 320px;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 12px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.qr[hidden] { display: none; }
.qr-code { width: 104px; height: 104px; flex: none; background: #fff; border-radius: 10px; padding: 6px; }
.qr-code img, .qr-code svg { width: 100%; height: 100%; display: block; }
.qr strong { font-size: 14px; }
.qr p { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-2); line-height: 1.4; }

.legal {
  position: fixed; left: 0; right: 0; bottom: 12px; z-index: 1; margin: 0; text-align: center;
  font-size: 11px; color: var(--ink-2); display: none;
}

/* ---------- Escritorio ---------- */
@media (min-width: 900px) {
  .top { padding: 28px 36px 0; }
  .title { font-size: 52px; }
  .spec { font-size: 15px; }
  model-viewer { right: 420px; width: auto; }
  .sheet {
    position: fixed;
    left: auto; right: 28px; top: 50%; bottom: auto; transform: translateY(-50%);
    width: 380px; border-radius: 22px; border: 1px solid var(--line); padding: 16px 18px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
  }
  .tabs { flex-wrap: wrap; margin: 0 0 12px; padding: 0; }
  .tab-toggle { margin-left: 0; }
  .chips { flex-wrap: wrap; margin: 0; padding: 2px 0; overflow: visible; }
  .ar-btn { right: auto; left: 50%; transform: translateX(-50%); bottom: 40px; }
  .busy { left: 36px; bottom: auto; top: 160px; }
  .legal { display: block; }
}
