:root {
  --bg: #14110e;
  --panel: #1d1915;
  --panel2: #27211b;
  --line: #3a332a;
  --text: #efe8dc;
  --muted: #a99e8b;
  --brand: #c9a45c;
  --danger: #e07a68;
  --radius: 14px;
  --sheet-w: 380px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
img { display: block; }
[hidden] { display: none !important; }

.app { position: fixed; inset: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }

/* ---------------------------------------------------------------- barra superior */
.topbar { display: flex; align-items: center; gap: 10px; padding: calc(8px + env(safe-area-inset-top)) 14px 8px; border-bottom: 1px solid var(--line); background: var(--bg); z-index: 6; min-width: 0; }
.brand { display: flex; align-items: center; gap: 9px; background: none; border: 0; font-weight: 700; font-size: 15px; letter-spacing: .01em; white-space: nowrap; min-width: 0; flex: 0 1 auto; }
.brand #brandName { overflow: hidden; text-overflow: ellipsis; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 28%, transparent); flex: none; }
.mode-title { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex: none; }
.top-btn, .factory-sel { background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: 13px; }
.factory-sel { max-width: 30vw; text-overflow: ellipsis; }
@media (max-width: 520px) { .mode-title { display: none; } .top-btn, .factory-sel { padding: 6px 10px; font-size: 12px; } }

/* ---------------------------------------------------------------- escenario */
.stage { position: relative; overflow: hidden; min-height: 0; }
.viewport { position: absolute; inset: 0; background: #0f0d0b; }
.viewport > canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ---------------------------------------------------------------- inicio */
.home { position: absolute; inset: 0; overflow-y: auto; }
.home-inner { max-width: 760px; margin: 0 auto; padding: 22px 16px 40px; }
.home-brand { display: flex; align-items: center; gap: 14px; margin: 6px 0 20px; }
.home-brand .dot { width: 18px; height: 18px; }
.home-brand h1 { font-size: 24px; line-height: 1.15; letter-spacing: -.01em; }
.home-brand p { color: var(--muted); font-size: 14px; }
.mode-cards { display: grid; gap: 10px; }
.mode-card { display: flex; gap: 14px; align-items: center; text-align: left; padding: 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); transition: border-color .15s, transform .15s; }
.mode-card:not(:disabled):hover { border-color: var(--brand); }
.mode-card:not(:disabled):active { transform: scale(.99); }
.mode-card b { display: block; font-size: 16px; }
.mode-card.main:not(:disabled) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--panel)); }
.mode-card small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.ico { width: 44px; height: 44px; flex: none; display: grid; place-items: center; border-radius: 12px; background: color-mix(in srgb, var(--brand) 16%, var(--panel2)); color: var(--brand); }
.ico svg { width: 24px; height: 24px; }
.link-row { display: flex; align-items: center; gap: 12px; width: 100%; margin: 14px 0 22px; padding: 10px 12px; border-radius: var(--radius); background: none; border: 1px dashed var(--line); color: var(--text); text-align: left; }
.link-row .ico { width: 34px; height: 34px; border-radius: 10px; }
.sec-t { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin: 0 0 8px; }
.cat-strip { display: grid; grid-auto-flow: column; grid-auto-columns: 132px; gap: 10px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; }
.cat-strip figure { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.cat-strip img { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--panel2); }
.cat-strip figcaption { padding: 7px 9px 9px; }
.cat-strip b { display: block; font-size: 14px; }
.cat-strip small { color: var(--muted); font-size: 12px; }
.foot { margin-top: 26px; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------------------------------------------------------------- barra inferior */
.dock { border-top: 1px solid var(--line); background: var(--bg); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); z-index: 6; min-width: 0; }
.palette, .dock-actions { display: flex; gap: 6px; overflow-x: auto; padding: 2px 12px; scrollbar-width: none; }
.palette::-webkit-scrollbar, .dock-actions::-webkit-scrollbar { display: none; }
.palette { padding-bottom: 6px; }
.hint { padding: 0 14px 7px; color: var(--muted); font-size: 13px; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.chip.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 18%, var(--panel)); }
.chip.add { color: var(--muted); border-style: dashed; }
.chip.add.on { color: var(--text); border-style: solid; }
.chip-sep { flex: none; align-self: center; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 0 2px 0 6px; }
.sw { width: 14px; height: 14px; border-radius: 4px; display: inline-block; box-shadow: inset 0 0 0 1px rgba(0,0,0,.25); }
.btn { flex: none; padding: 10px 15px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); font-size: 14px; font-weight: 600; white-space: nowrap; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #15110c; }
.btn.ghost { background: none; }
.btn.danger { background: none; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); }
.btn.on { border-color: var(--brand); color: var(--brand); }
.btn.big { padding: 12px 20px; font-size: 15px; }
.btn.small { padding: 6px 11px; font-size: 13px; }

/* ---------------------------------------------------------------- panel de material */
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 52%; display: flex; flex-direction: column; background: var(--panel); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -12px 40px rgba(0,0,0,.45); z-index: 20; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.sheet-title { font-weight: 700; font-size: 17px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); border: 1px solid color-mix(in srgb, var(--brand) 50%, transparent); border-radius: 999px; padding: 1px 8px; }
.sheet-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.x { margin-left: auto; width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--panel2); border: 1px solid var(--line); }
.sheet-body { overflow-y: auto; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }
.sec { margin-bottom: 16px; }
.sec.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips.swatches { margin-top: 8px; }
.dot-btn { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); }
.dot-btn.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--brand); }
.cards { display: grid; grid-auto-flow: column; grid-auto-columns: 112px; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.card { text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; padding: 0 0 8px; }
.card img { width: 100%; aspect-ratio: 1; object-fit: cover; margin-bottom: 6px; background: var(--bg); }
.card b, .card small { display: block; padding: 0 8px; }
.card b { font-size: 13px; }
.card small { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card.on { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.dims { display: flex; gap: 12px; flex-wrap: wrap; }
.dims label { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.dims input { width: 76px; padding: 8px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- modo foto */
.photo-wrap { position: absolute; touch-action: none; user-select: none; -webkit-user-select: none; }
.photo-wrap > canvas { display: block; width: 100% !important; height: 100% !important; }
.photo-svg, .photo-handles { position: absolute; inset: 0; pointer-events: none; }
.photo-svg { overflow: hidden; }
.photo-handles { overflow: visible; }
.handle { position: absolute; width: 34px; height: 34px; margin: -17px 0 0 -17px; border-radius: 50%; border: 3px solid #fff; background: color-mix(in srgb, var(--brand) 55%, transparent); box-shadow: 0 2px 10px rgba(0,0,0,.5); pointer-events: auto; touch-action: none; }
.loupe { position: absolute; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 4px 18px rgba(0,0,0,.55); pointer-events: none; }
.ql-preview { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------------------------------------------------------------- AR en vivo (dom-overlay) */
.xr-cross { display: none; }
.app.xr-active, .app.xr-active .stage { background: transparent; }
.app.xr-active .home, .app.xr-active .viewport { display: none !important; }
.app.xr-active .topbar, .app.xr-active .dock { background: rgba(16, 13, 10, .74); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.app.xr-active .sheet { max-height: 52%; background: rgba(29, 25, 21, .94); }
.app.xr-active .xr-cross { display: block; position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px; pointer-events: none; }
.app.xr-active .xr-cross::before, .app.xr-active .xr-cross::after { content: ""; position: absolute; background: rgba(255,255,255,.9); box-shadow: 0 0 3px rgba(0,0,0,.6); }
.app.xr-active .xr-cross::before { left: 12px; top: 0; width: 2px; height: 26px; }
.app.xr-active .xr-cross::after { top: 12px; left: 0; height: 2px; width: 26px; }
#app:xr-overlay { background: transparent; }

/* ---------------------------------------------------------------- simulador AR y medidas */
.app.sim-active .xr-cross { display: block; position: absolute; left: 50%; top: 50%; width: 26px; height: 26px; margin: -13px; pointer-events: none; z-index: 2; }
.app.sim-active .xr-cross::before, .app.sim-active .xr-cross::after { content: ""; position: absolute; background: rgba(255,255,255,.95); box-shadow: 0 0 3px rgba(0,0,0,.7); }
.app.sim-active .xr-cross::before { left: 12px; top: 0; width: 2px; height: 26px; }
.app.sim-active .xr-cross::after { top: 12px; left: 0; height: 2px; width: 26px; }
.app.sim-active .viewport > canvas { cursor: grab; }
.measure-hud { position: absolute; top: calc(58px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 8; max-width: calc(100% - 32px); padding: 7px 14px; border-radius: 999px; background: rgba(16, 13, 10, .82); border: 1px solid color-mix(in srgb, var(--brand) 55%, transparent); color: #fff; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.chip.furn { border-color: color-mix(in srgb, #7fb3d5 55%, var(--line)); }
.chip-note { color: var(--muted); font-size: 11px; }
.note { margin: 0 0 12px; padding: 8px 10px; border-radius: 10px; background: color-mix(in srgb, var(--brand) 12%, var(--panel2)); font-size: 13px; }

/* ---------------------------------------------------------------- ficha técnica */
.ficha { margin: 4px 0 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel2); }
.ficha summary { cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 14px; }
.ficha dl { display: grid; grid-template-columns: minmax(110px, 40%) 1fr; gap: 6px 10px; padding: 2px 12px 12px; font-size: 13px; }
.ficha dt { color: var(--muted); }
.ficha dd { overflow-wrap: anywhere; }
.ficha .btn { margin: 0 12px 12px; display: inline-block; text-decoration: none; }
.specials { margin: 0 0 14px 18px; font-size: 13px; color: var(--muted); }
.specials b { color: var(--text); }
.samples { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px 10px; display: grid; gap: 6px; }
.samples legend { padding: 0 6px; font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------------- modales, tablas, formularios */
.modal { position: absolute; inset: 0; background: rgba(8, 6, 5, .62); display: grid; place-items: end center; z-index: 40; padding: 12px; }
.modal-box { width: min(560px, 100%); max-height: 88%; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-box h2 { font-size: 20px; margin-bottom: 6px; }
.modal-box > .muted { margin-bottom: 14px; font-size: 14px; }
.stack { display: grid; gap: 8px; margin-top: 16px; }
.quote { width: 100%; border-collapse: collapse; margin-bottom: 16px; font-size: 14px; }
.quote th { text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.quote td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.quote td small { display: block; color: var(--muted); font-size: 12px; }
.quote .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form textarea { width: 100%; padding: 10px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); color: var(--text); font-size: 15px; }
.form input:focus, .form textarea:focus, .dims input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-size: 13px; }
.form .check input { width: 20px; height: 20px; flex: none; margin-top: 1px; accent-color: var(--brand); }
.projects { display: grid; gap: 10px; }
.project { display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center; padding: 8px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); }
.project img, .thumb-ph { width: 64px; height: 48px; object-fit: cover; border-radius: 8px; background: var(--bg); display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.project small { display: block; color: var(--muted); font-size: 12px; }
.p-acts { display: flex; gap: 6px; }
.toast { position: absolute; left: 50%; bottom: 120px; transform: translate(-50%, 20px); max-width: min(92vw, 520px); background: #2c2620; border: 1px solid var(--line); color: var(--text); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 28px rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; text-align: center; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- escritorio: panel a la derecha */
@media (min-width: 900px) {
  .app.sheet-open { grid-template-columns: minmax(0, 1fr) var(--sheet-w); }
  .app.sheet-open .topbar { grid-column: 1 / -1; }
  .app.sheet-open .stage { grid-column: 1; }
  .app.sheet-open .dock { grid-column: 1; }
  .sheet { position: relative; grid-column: 2; grid-row: 2 / 4; max-height: none; border-radius: 0; border-top: 0; border-left: 1px solid var(--line); box-shadow: none; }
  .app:not(.sheet-open) .sheet { display: none; }
  .modal { place-items: center; }
  .mode-cards { grid-template-columns: repeat(3, 1fr); }
  .mode-card { flex-direction: column; align-items: flex-start; }
}
