:root {
  --ed-fondo: #e9edf2;
  --ed-panel: #ffffff;
  --ed-borde: #d9dee7;
  --ed-texto: #18212d;
  --ed-suave: #687386;
  --ed-acento: #9423da;
  --ed-acento-suave: #f3e8fc;
  --ed-peligro: #b42318;
  --ed-ok: #127a43;
  --ed-seleccion: #2f6fed;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ed-fondo);
  color: var(--ed-texto);
  font: 13px/1.4 "Inter", system-ui, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* ── Ingreso ─────────────────────────────────────────────────────────── */
.ed-ingreso { position: fixed; inset: 0; display: grid; place-items: center; }
.ed-ingreso[hidden] { display: none; }
.ed-ingreso-caja { width: min(340px, calc(100vw - 32px)); display: grid; gap: 12px; padding: 28px; background: var(--ed-panel); border: 1px solid var(--ed-borde); border-radius: 10px; }
.ed-ingreso-caja h1 { margin: 0 0 4px; font-size: 18px; }
.ed-ingreso-caja label { display: grid; gap: 4px; font-weight: 600; }
.ed-ingreso-caja input { padding: 8px 10px; border: 1px solid var(--ed-borde); border-radius: 6px; }

/* ── Estructura ──────────────────────────────────────────────────────── */
.ed-app { display: grid; grid-template-columns: 250px minmax(0, 1fr) 340px; grid-template-rows: auto minmax(0, 1fr); height: 100vh; }
.ed-app[hidden] { display: none; }
.ed-barra { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 12px; background: #17202b; color: #fff; }
.ed-marca { margin-right: 6px; }
.ed-campo-barra { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #c9d1dc; }
.ed-campo-barra select { padding: 4px 6px; border-radius: 5px; border: 1px solid #3a4655; background: #222d3b; color: #fff; max-width: 220px; }
.ed-check { display: flex; align-items: center; gap: 4px; font-size: 12px; color: #c9d1dc; }
.ed-sep { flex: 0 0 1px; align-self: stretch; background: #3a4655; margin: 0 2px; }
.ed-estado { font-size: 12px; color: #c9d1dc; margin-left: auto; }
.ed-estado.es-error { color: #ffb4ab; }

.ed-izq, .ed-der { overflow: auto; background: var(--ed-panel); border-color: var(--ed-borde); border-style: solid; border-width: 0; }
.ed-izq { border-right-width: 1px; padding: 10px 0; }
.ed-der { border-left-width: 1px; }
.ed-lienzo { overflow: auto; position: relative; }
.ed-zoom { position: relative; width: max-content; margin: 0 auto; padding: 24px 32px 64px; }
.ed-zoom .doc-raiz.doc-previa { padding: 0; background: transparent; }

/* ── Botones ─────────────────────────────────────────────────────────── */
.ed-btn { padding: 5px 10px; border: 1px solid #3a4655; border-radius: 6px; background: #222d3b; color: #fff; cursor: pointer; white-space: nowrap; }
.ed-btn:hover { background: #2c3949; }
.ed-btn:disabled { opacity: .45; cursor: not-allowed; }
.ed-btn-primario { background: var(--ed-acento); border-color: var(--ed-acento); }
.ed-btn-primario:hover { background: #7f1bbd; }
.ed-btn-suave { background: transparent; }
.ed-icono { padding: 4px 9px; font-size: 15px; line-height: 1; }
.ed-der .ed-btn, .ed-izq .ed-btn, .ed-modal .ed-btn { background: #fff; color: var(--ed-texto); border-color: var(--ed-borde); }
.ed-der .ed-btn:hover, .ed-izq .ed-btn:hover, .ed-modal .ed-btn:hover { background: #f4f6f9; }
.ed-modal .ed-btn-primario { background: var(--ed-acento); color: #fff; border-color: var(--ed-acento); }
.ed-btn-chico { padding: 2px 7px; font-size: 12px; }
.ed-btn-peligro { color: var(--ed-peligro) !important; }

/* ── Panel izquierdo: estructura ─────────────────────────────────────── */
.ed-arbol-grupo { margin-bottom: 6px; }
.ed-arbol-titulo { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 6px 12px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ed-suave); }
.ed-arbol-item { display: flex; align-items: center; gap: 6px; width: 100%; padding: 4px 12px 4px 20px; border: 0; background: none; text-align: left; cursor: pointer; }
.ed-arbol-item:hover { background: #f4f6f9; }
.ed-arbol-item.es-activo { background: var(--ed-acento-suave); color: #5b1287; font-weight: 600; }
.ed-arbol-item small { color: var(--ed-suave); margin-left: auto; font-size: 11px; }
.ed-arbol-cabeza { font-weight: 600; padding-left: 12px; }
.ed-agregar { display: flex; flex-wrap: wrap; gap: 4px; padding: 4px 12px 8px 20px; }
.ed-datos { padding: 0 12px 12px; font-size: 12px; }
.ed-datos-grupo { margin: 0 0 2px; }
.ed-datos-grupo summary { padding: 4px 4px; font-weight: 600; cursor: pointer; color: #26313f; border-radius: 3px; }
.ed-datos-grupo summary:hover { background: var(--ed-acento-suave); }
.ed-datos-grupo[open] summary { margin-bottom: 2px; }
.ed-datos button { display: block; width: 100%; padding: 2px 4px 2px 16px; border: 0; background: none; text-align: left; font-family: inherit; font-size: 12px; cursor: pointer; color: #3a4655; border-radius: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-datos button:hover { background: var(--ed-acento-suave); }
.ed-datos p { margin: 4px 0 6px; color: var(--ed-suave); }

/* ── Panel derecho: resumen y propiedades ────────────────────────────── */
.ed-resumen { padding: 12px 14px; border-bottom: 1px solid var(--ed-borde); background: #fbfcfd; }
.ed-resumen h3 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ed-suave); }
.ed-resumen .ed-hojas { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.ed-resumen .ed-hoja-chip { padding: 2px 7px; border-radius: 999px; background: #eef1f5; font-size: 12px; }
.ed-resumen .ed-faltan { margin: 6px 0 0; padding: 8px 10px; border-radius: 6px; background: #fff3f2; color: var(--ed-peligro); font-size: 12px; }
.ed-resumen .ed-faltan ul { margin: 4px 0 0; padding-left: 16px; }
.ed-resumen .ed-ok { color: var(--ed-ok); font-size: 12px; margin: 6px 0 0; }
.ed-resumen .ed-aviso { color: #9a5b00; font-size: 12px; margin: 4px 0 0; }

.ed-props { padding: 12px 14px 40px; }
.ed-props h2 { margin: 0 0 2px; font-size: 15px; }
.ed-props .ed-sub { margin: 0 0 12px; color: var(--ed-suave); font-size: 12px; }
.ed-seccion { margin: 14px 0 6px; padding-top: 10px; border-top: 1px solid #eef1f5; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ed-suave); }
.ed-fila { display: grid; grid-template-columns: repeat(auto-fit, minmax(70px, 1fr)); gap: 6px; margin-bottom: 6px; }
.ed-campo { display: grid; gap: 2px; font-size: 11.5px; color: var(--ed-suave); min-width: 0; }
.ed-campo input, .ed-campo select, .ed-campo textarea { width: 100%; box-sizing: border-box; padding: 4px 6px; border: 1px solid var(--ed-borde); border-radius: 5px; background: #fff; color: var(--ed-texto); font-size: 12.5px; }
.ed-campo textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; resize: vertical; }
.ed-campo input:focus, .ed-campo select:focus, .ed-campo textarea:focus { outline: 2px solid var(--ed-acento); outline-offset: -1px; }
.ed-campo-color { display: flex; gap: 4px; }
.ed-campo-color input[type=color] { flex: 0 0 30px; width: 30px; padding: 1px; height: 27px; }
.ed-campo-check { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ed-texto); }
.ed-campo-check input { width: auto; }
.ed-renglon { border: 1px solid #eef1f5; border-radius: 6px; padding: 6px; margin-bottom: 6px; background: #fbfcfd; }
.ed-renglon-acciones { display: flex; gap: 4px; justify-content: flex-end; margin-top: 4px; }
.ed-ayuda { font-size: 11.5px; color: var(--ed-suave); margin: 2px 0 8px; }
.ed-acciones { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ── Lienzo: selección, guías, arrastre ──────────────────────────────── */
.ed-capa { position: absolute; inset: 0; pointer-events: none; }
.doc-raiz .doc-el, .doc-raiz .doc-tras, .doc-raiz .doc-titulos .doc-celda { cursor: pointer; }
.doc-raiz .doc-el:hover { outline: 1px dashed rgba(47, 111, 237, .55); outline-offset: 0; }
.ed-sel { position: absolute; border: 1.5px solid var(--ed-seleccion); pointer-events: auto; cursor: move; box-sizing: border-box; }
.ed-sel.es-fija { cursor: default; }
.ed-sel.es-fija.es-corrible { cursor: ew-resize; }
.ed-sel.es-fija.es-movible { cursor: move; }
.ed-sel-eco { position: absolute; border: 1px dashed rgba(47, 111, 237, .6); pointer-events: none; box-sizing: border-box; }
.ed-tirador { position: absolute; width: 9px; height: 9px; background: #fff; border: 1.5px solid var(--ed-seleccion); box-sizing: border-box; pointer-events: auto; }
.ed-tirador[data-t=nw] { left: -5px; top: -5px; cursor: nwse-resize; }
.ed-tirador[data-t=n] { left: calc(50% - 4.5px); top: -5px; cursor: ns-resize; }
.ed-tirador[data-t=ne] { right: -5px; top: -5px; cursor: nesw-resize; }
.ed-tirador[data-t=e] { right: -5px; top: calc(50% - 4.5px); cursor: ew-resize; }
.ed-tirador[data-t=se] { right: -5px; bottom: -5px; cursor: nwse-resize; }
.ed-tirador[data-t=s] { left: calc(50% - 4.5px); bottom: -5px; cursor: ns-resize; }
.ed-tirador[data-t=sw] { left: -5px; bottom: -5px; cursor: nesw-resize; }
.ed-tirador[data-t=w] { left: -5px; top: calc(50% - 4.5px); cursor: ew-resize; }
.ed-medida { position: absolute; padding: 1px 5px; border-radius: 3px; background: var(--ed-seleccion); color: #fff; font-size: 11px; white-space: nowrap; pointer-events: none; transform: translateY(-120%); }
.ed-guia { position: absolute; height: 0; border-top: 1px dashed rgba(148, 35, 218, .55); pointer-events: auto; cursor: ns-resize; }
.ed-guia::before { content: ""; position: absolute; left: 0; right: 0; top: -5px; height: 9px; }
.ed-guia span { position: absolute; right: 0; top: 0; transform: translate(calc(100% + 6px), -50%); padding: 1px 6px; border-radius: 3px; background: var(--ed-acento); color: #fff; font-size: 11px; white-space: nowrap; }
.ed-margen { position: absolute; border: 1px dotted rgba(104, 115, 134, .45); pointer-events: none; }

/* ── Modal ───────────────────────────────────────────────────────────── */
.ed-modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(15, 20, 28, .45); z-index: 50; }
.ed-modal[hidden] { display: none; }
.ed-modal-caja { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; background: #fff; border-radius: 10px; overflow: hidden; }
.ed-modal-caja h2 { margin: 0; padding: 14px 18px; font-size: 16px; border-bottom: 1px solid var(--ed-borde); }
.ed-modal-cuerpo { padding: 14px 18px; overflow: auto; }
.ed-modal-cuerpo textarea { width: 100%; box-sizing: border-box; min-height: 52vh; font-family: ui-monospace, Consolas, monospace; font-size: 12px; border: 1px solid var(--ed-borde); border-radius: 6px; padding: 8px; }
.ed-modal-pie { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--ed-borde); }
.ed-error { color: var(--ed-peligro); margin: 0; }
.ed-versiones { width: 100%; border-collapse: collapse; }
.ed-versiones td, .ed-versiones th { padding: 6px 8px; border-bottom: 1px solid #eef1f5; text-align: left; }

/* Un solo "Agregar" por parte y secciones plegables (lo poco usado, cerrado). */
.ed-agregar-menu { width: 100%; padding: 5px 8px; border: 1px dashed #b9c2d0; border-radius: 6px; background: #fff; color: #3a4655; font: inherit; font-size: 12.5px; cursor: pointer; }
.ed-agregar-menu:hover { border-color: var(--ed-seleccion); }
.ed-plegable { margin: 10px 0 4px; border-top: 1px solid #e3e7ee; padding-top: 6px; }
.ed-plegable > summary { cursor: pointer; font-size: 12px; font-weight: 600; color: #4a5567; padding: 4px 0; }
.ed-plegable[open] > summary { margin-bottom: 6px; }
.ed-se-lee { margin: -2px 0 6px; font-size: 11.5px; color: #4a5567; background: #f4f6f9; border-radius: 4px; padding: 3px 6px; }

/* "Mostrar solo si" con listas. */
.ed-condicion { display: grid; gap: 6px; margin: 6px 0 10px; padding: 8px; border: 1px solid #e3e7ee; border-radius: 6px; background: #fafbfc; }
.ed-condicion-titulo { font-size: 12px; color: #4a5567; }
.ed-condicion select, .ed-condicion input { width: 100%; padding: 5px 6px; border: 1px solid #cfd6e0; border-radius: 4px; font: inherit; font-size: 12.5px; background: #fff; }
.ed-condicion-reglas { display: grid; gap: 6px; }
.ed-condicion-regla { display: grid; grid-template-columns: 1fr; gap: 4px; padding: 6px; border: 1px solid #e3e7ee; border-radius: 4px; background: #fff; }
.ed-condicion-regla > button { justify-self: end; }
.ed-condicion-acciones { display: flex; gap: 6px; flex-wrap: wrap; }
.ed-condicion .ed-ayuda { margin: 0; }
