/* MAS3D Studio — layout de la app (reutiliza los tokens de styles.css) */

html, body { height: 100%; }
body.studio { overflow: hidden; }

.studio-bar {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.studio-bar .brand { font-size: 1.15rem; }
.studio-bar .brand img { width: 28px; height: 28px; }
.studio-bar .tag { font-size: 0.72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 2px 8px; }
.studio-bar input.project-name {
  flex: 0 1 260px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; font-size: 0.9rem;
}
.studio-bar .spacer { flex: 1; }
.studio-bar .status { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }
.studio-bar .status.is-busy { color: var(--warn); }
.studio-bar .status.is-error { color: #ff6b6b; }

.studio-main { display: grid; grid-template-columns: 340px 1fr; height: calc(100% - 60px); }

/* ---------- Panel de parámetros ---------- */
.side { border-right: 1px solid var(--line); overflow-y: auto; background: var(--bg); }
.side section { padding: 16px 16px 6px; border-bottom: 1px solid var(--line); }
.side h2 { font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); margin: 0 0 12px; }
.side details { border-bottom: 1px solid var(--line); }
.side details > summary {
  list-style: none; cursor: pointer; padding: 14px 16px;
  font-family: var(--font-display); font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent);
  display: flex; justify-content: space-between;
}
.side details > summary::-webkit-details-marker { display: none; }
.side details > summary::after { content: "+"; color: var(--muted); }
.side details[open] > summary::after { content: "−"; }
.side details > .body { padding: 0 16px 8px; }

.ctl { display: grid; gap: 5px; margin-bottom: 12px; font-size: 0.82rem; color: var(--muted); }
.ctl-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.ctl input[type="text"], .ctl input[type="number"], .ctl select, .ctl textarea {
  width: 100%;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; color: var(--text); font-size: 0.9rem;
}
.ctl input:focus, .ctl select:focus, .ctl textarea:focus { outline: none; border-color: var(--accent); }
.ctl .hint { font-size: 0.74rem; color: var(--muted); opacity: 0.8; }
.ctl input[type="range"] { accent-color: var(--accent); }
.unit { position: relative; }
.unit input { padding-right: 34px !important; }
.unit::after { content: attr(data-unit); position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 0.75rem; color: var(--muted); pointer-events: none; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 14px; }
.seg button { border: 0; background: transparent; padding: 7px; border-radius: 7px; color: var(--muted); font-weight: 600; cursor: pointer; font-size: 0.85rem; }
.seg button.is-active { background: var(--surface-2); color: var(--text); }

.drop {
  display: block;
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 18px 12px; text-align: center;
  font-size: 0.85rem; color: var(--muted); cursor: pointer; transition: border-color .15s, background .15s;
  margin-bottom: 10px;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-soft); }
.drop strong { color: var(--text); }
.model-desc { font-size: 0.78rem; color: var(--muted); margin: -6px 0 12px; }
.side .actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 16px; }
.side .actions .btn { padding: 9px 10px; font-size: 0.82rem; }

/* ---------- Área de trabajo ---------- */
.work { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; }
.work-tabs { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.work-tabs .seg { margin: 0; }
.work-tabs .toggles { display: flex; gap: 14px; align-items: center; font-size: 0.82rem; color: var(--muted); margin-left: auto; flex-wrap: wrap; }
.work-tabs label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.work-tabs input[type="range"] { width: 110px; accent-color: var(--accent); }

.stage { position: relative; min-height: 0; background: radial-gradient(ellipse at 50% 40%, #0f1620, #07090c 75%); }
.stage > .view { position: absolute; inset: 0; display: none; }
.stage > .view.is-active { display: block; }
#view-3d canvas { width: 100% !important; height: 100% !important; display: block; }
.stage svg { width: 100%; height: 100%; }
.stage .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }

.stats {
  position: absolute; left: 12px; bottom: 12px; right: 12px;
  display: flex; flex-wrap: wrap; gap: 8px; pointer-events: none;
}
.stats span {
  background: rgba(7,9,12,0.82); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 0.76rem; color: var(--muted);
}
.stats b { color: var(--text); font-family: var(--font-display); font-weight: 600; }

/* ---------- Tabla de piezas ---------- */
.parts { border-top: 1px solid var(--line); max-height: 26vh; overflow: auto; background: var(--bg-2); }
.parts table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.parts th, .parts td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.parts th { position: sticky; top: 0; background: var(--bg-2); color: var(--muted); font-weight: 500; font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.06em; }
.parts td.warn { color: var(--warn); white-space: normal; min-width: 220px; }
.parts td.ok { color: var(--ok); }
.parts .dl { border: 1px solid var(--line); background: transparent; border-radius: 6px; padding: 3px 8px; font-size: 0.75rem; cursor: pointer; margin-right: 4px; color: var(--text); }
.parts .dl:hover { border-color: var(--accent); color: var(--accent); }
.warnings { padding: 10px 14px; font-size: 0.82rem; color: var(--warn); border-bottom: 1px solid var(--line); }
.warnings:empty { display: none; }
.warnings li { margin: 2px 0; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  body.studio { overflow: auto; }
  .studio-main { grid-template-columns: 1fr; height: auto; }
  .side { border-right: 0; max-height: none; }
  .work { grid-template-rows: auto 60vh auto; }
  .studio-bar .tag, .studio-bar .status, .studio-bar .cloud-chip, .studio-bar #to-shop { display: none; }
  .studio-bar input.project-name { flex-basis: 140px; }
}
.parts td.ok .note, .parts td.warn .note { color: var(--accent); }
.parts td.ok { white-space: normal; }
.ctl.check { display: flex; gap: 8px; align-items: center; color: var(--text); }
body[data-refining] #view-sheet::after, body[data-refining] #view-print::after {
  content: "Optimizando el nesting por contorno…";
  position: absolute; top: 12px; right: 12px;
  background: rgba(7,9,12,0.85); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 0.76rem; color: var(--warn);
}
/* Las vistas SVG dejan lugar a las estadísticas superpuestas */
.stage > #view-2d, .stage > #view-sheet { inset: 0 0 76px 0; }
.parts td.dl-cell { white-space: normal; min-width: 240px; }
.parts td.dl-cell .dl { margin: 2px 4px 2px 0; }
#view-2d .handle { cursor: grab; }
#view-2d .handle.is-dragging { cursor: grabbing; fill: rgba(255,255,255,0.18); }
#view-2d svg { touch-action: none; }

/* ---------- Montaje sobre foto ---------- */
.stage > #view-mockup { inset: 0 0 76px 0; display: none; flex-direction: column; }
.stage > #view-mockup.is-active { display: flex; }
.mk-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: rgba(7,9,12,0.8); }
.mk-bar .btn { padding: 7px 12px; font-size: 0.8rem; }
.mk-toggle { display: inline-flex; gap: 6px; align-items: center; font-size: 0.82rem; color: var(--muted); }
.mk-toggle input[type="color"] { width: 30px; height: 24px; border: 1px solid var(--line); border-radius: 6px; background: none; padding: 0; }
.mk-scale { font-size: 0.78rem; color: var(--muted); margin-right: auto; }
.mk-stage { position: relative; flex: 1; overflow: hidden; background: #050608; touch-action: none; }
.mk-photo { position: absolute; display: none; user-select: none; -webkit-user-drag: none; transition: filter .2s; }
.mk-sign { position: absolute; left: 0; top: 0; transform-origin: 0 0; display: none; cursor: move; }
.mk-sign svg { display: block; }
.mk-overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.mk-handle {
  position: absolute; width: 16px; height: 16px; margin: -8px 0 0 -8px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 2px rgba(0,0,0,0.4); cursor: grab; display: none;
}
.mk-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 20px; font-size: 0.92rem; }
#view-mockup.has-photo .mk-photo, #view-mockup.has-photo .mk-sign, #view-mockup.has-photo .mk-handle { display: block; }
#view-mockup.has-photo .mk-empty { display: none; }
#view-mockup.is-night .mk-photo { filter: brightness(0.38) saturate(0.85); }
#view-mockup.is-measuring .mk-stage { cursor: crosshair; }
#view-mockup.is-measuring .mk-sign { pointer-events: none; }
.mk-select { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font-size: 0.8rem; color: var(--text); }
.mk-render { position: absolute; display: none; pointer-events: none; }
#view-mockup.is-render.has-photo.has-render:not(.is-dragging) .mk-render { display: block; }
#view-mockup.is-render.has-render:not(.is-dragging) .mk-sign { opacity: 0; }
.stage > #view-print { inset: 0 0 76px 0; }
.mk-sun input[type="range"] { width: 80px; accent-color: var(--warn); }
#view-mockup:not(.is-render) .mk-sun, #view-mockup.is-night .mk-sun { display: none; }

/* Plantilla de pared: selector de hoja + botón en una fila */
.tpl-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; margin-bottom: 6px; }
.tpl-row .ctl { margin: 0; }
.tpl-row .btn { white-space: nowrap; }

/* ---------- Biblioteca de proyectos ---------- */
.saved-ind { font-size: .74rem; color: var(--muted); min-width: 0; white-space: nowrap; }
.proj-dlg {
  width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0;
  border: 1px solid var(--line); border-radius: 16px; background: var(--bg-2, #0d1218); color: var(--text);
  box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.proj-dlg[open] { display: flex; flex-direction: column; }
.proj-dlg::backdrop { background: rgba(3,5,8,.7); backdrop-filter: blur(3px); }
.proj-head { display: flex; gap: 12px; align-items: center; padding: 16px 18px 10px; }
.proj-head h2 { margin: 0; font-size: 1.15rem; }
.proj-head input { flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.03); color: var(--text); font: inherit; }
.proj-x { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 6px; }
.proj-actions { display: flex; gap: 8px; padding: 0 18px 12px; flex-wrap: wrap; }
.proj-list { overflow: auto; padding: 4px 18px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.proj-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: rgba(255,255,255,.02); display: flex; flex-direction: column; }
.proj-card.is-current { border-color: var(--accent, #36e2f2); box-shadow: 0 0 0 1px var(--accent, #36e2f2) inset; }
.proj-thumb { height: 92px; display: grid; place-items: center; padding: 10px; background: #080b0f; color: #9fb4c8; cursor: pointer; }
.proj-thumb svg { width: 100%; height: 100%; }
.proj-card .meta { padding: 10px 12px 6px; display: grid; gap: 3px; }
.proj-card .meta b { font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-card .meta span { font-size: .74rem; color: var(--muted); }
.proj-card .badges { display: flex; gap: 4px; flex-wrap: wrap; }
.proj-card .badges i { font-style: normal; font-size: .66rem; padding: 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.proj-card .ops { display: flex; gap: 6px; padding: 6px 12px 12px; margin-top: auto; }
.proj-card .ops button { flex: 1; padding: 5px 0; border-radius: 8px; border: 1px solid var(--line); background: none; color: var(--text); font: 500 .76rem/1 inherit; font-family: inherit; cursor: pointer; }
.proj-card .ops button:hover { border-color: var(--accent, #36e2f2); }
.proj-card .ops [data-op=del]:hover { border-color: #ff5d6c; color: #ff8a95; }
.proj-empty { grid-column: 1 / -1; color: var(--muted); font-size: .9rem; padding: 26px 0; text-align: center; }
.proj-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 18px 16px; border-top: 1px solid var(--line); }
.proj-usage { flex: 1; font-size: .74rem; color: var(--muted); min-width: 160px; }
@media (max-width: 640px) {
  .proj-list { grid-template-columns: 1fr 1fr; }
  .proj-head { flex-wrap: wrap; }
  .saved-ind { display: none; }
}

/* Barra del Studio en celular: dos renglones (marca + acciones / proyectos + nombre) */
@media (max-width: 640px) {
  .studio-bar { height: auto; flex-wrap: wrap; gap: 8px 10px; padding: 10px 16px; }
  .studio-bar .brand { order: 1; }
  .studio-bar .spacer { order: 2; }
  .studio-bar #to-quote { order: 3; }
  .studio-bar #export-zip { order: 4; }
  .studio-bar #projects-btn { order: 5; }
  .studio-bar input.project-name { order: 6; flex: 1 1 0; }
  .studio-bar .gate-user { order: 7; }
}

/* Indicador de la nube */
.cloud-chip { font-size: .76rem; color: var(--muted); white-space: nowrap; text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
.cloud-chip:hover { color: var(--text); border-color: var(--accent); }
.cloud-chip[data-phase=ok] { color: var(--ok, #3cf0a0); }
.cloud-chip[data-phase=syncing] { color: var(--accent); }
.cloud-chip[data-phase=error] { color: #ff6b6b; border-color: rgba(255,107,107,.4); }
.cloud-chip[data-phase=offline] { color: var(--warn, #ffb020); }
.cloud-chip--float { position: fixed; left: 12px; bottom: 12px; z-index: 50; background: var(--bg-2, #0c1016); }
.proj-thumb img { width: 100%; height: 100%; object-fit: contain; }
