/* Diagramas · estilos propios */
body { overflow: hidden; }
.shell { display: grid; height: 100dvh; grid-template-columns: 340px minmax(0, 1fr); grid-template-rows: 48px minmax(0, 1fr); grid-template-areas: "top top" "ed stage"; }
.topbar { grid-area: top; }
.topbar .top-actions { margin-left: auto; }
.editor { grid-area: ed; display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--panel); }
.ed-h { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px 0 14px; border-bottom: 1px solid var(--border); }
#src { flex: 1; min-height: 0; padding: 12px 14px; border: 0; outline: 0; resize: none; background: none; font: 400 13px/1.7 var(--mono); tab-size: 2; white-space: pre; overflow: auto; }
.help { border-top: 1px solid var(--border); font-size: 12px; }
.help summary { padding: 9px 14px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.help summary:hover { color: var(--text); }
.help dl { display: grid; gap: 2px 0; margin: 0; padding: 0 14px 12px; max-height: 38vh; overflow: auto; }
.help dt { margin-top: 6px; font-weight: 500; }
.help dd { margin: 0; color: var(--text-2); line-height: 1.5; }
.help code, .empty-st code { padding: 1px 5px; border-radius: 4px; background: var(--sunken); font: 11.5px var(--mono); }

.stage { grid-area: stage; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.st-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 40px; padding: 6px 10px; border-bottom: 1px solid var(--border); background: var(--panel); }
.rng { display: flex; align-items: center; gap: 6px; }
.rng input { width: 90px; accent-color: var(--accent); }
.zoom { display: flex; align-items: center; gap: 2px; }
.canvas { position: relative; flex: 1; min-height: 0; overflow: hidden; cursor: default; outline: none;
  background-image: radial-gradient(var(--border) 1px, transparent 1px); background-size: 20px 20px; touch-action: none; }
.canvas.grab { cursor: grabbing; }
.ed-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 40px; padding: 5px 10px; border-bottom: 1px solid var(--border); background: var(--panel); }
.ed-bar .ed-tip { min-width: 0; }
.ed-bar .ed-tip b { color: var(--accent); }
.canvas.editing .vp .nd { cursor: move; }
.canvas.editing .vp .hd-c { cursor: crosshair; }
.canvas.editing .vp .hit { cursor: pointer; pointer-events: stroke; }
.vp .nd.drop > :first-child, .vp .nd.drop > :nth-child(2) { filter: drop-shadow(0 0 6px var(--accent)); }
.vp #tmpLink { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }
.sel-bar { position: absolute; z-index: 5; display: flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow, 0 6px 20px rgba(0,0,0,.15)); white-space: nowrap; flex-wrap: wrap; justify-content: center; max-width: calc(100% - 12px); }
.sel-bar button { min-height: 32px; padding: 0 10px; border: 0; border-radius: 7px; background: none; color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.sel-bar button:hover { background: var(--hover, rgba(127,127,127,.12)); }
.sel-bar button.danger { color: var(--danger, #d33); }
.ren-in { position: absolute; z-index: 6; height: 36px; padding: 0 10px; border: 2px solid var(--accent); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; font-size: 16px; text-align: center; outline: none; }
:root[data-input="touch"] .sel-bar button { min-height: 40px; padding: 0 12px; }
:root[data-input="touch"] .ed-bar .btn, :root[data-input="touch"] .ed-bar .icon-btn { min-height: 38px; min-width: 38px; }
.vp svg { position: absolute; left: 0; top: 0; transform-origin: 0 0; overflow: visible; user-select: none; }
.vp [data-line] { cursor: pointer; }
.vp .nd:hover > :first-child { filter: brightness(.96); }
.empty-st { position: absolute; inset: 0; display: grid; place-content: center; gap: 6px; text-align: center; color: var(--text-2); pointer-events: none; }
.empty-st p { margin: 0; }
.empty-st[hidden] { display: none; }
.tpl-menu { position: fixed; z-index: 60; display: grid; width: 220px; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--panel); box-shadow: var(--shadow-lg, 0 10px 30px rgba(0,0,0,.15)); }
.tpl-menu button { height: 30px; padding: 0 10px; border: 0; border-radius: 6px; background: none; text-align: left; font-size: 13px; }
.tpl-menu button:hover, .tpl-menu button:focus-visible { background: var(--hover); outline: none; }
.tpl-menu p { margin: 4px 10px 4px; }

@media (max-width: 760px) {
  body { overflow: auto; }
  .shell { height: auto; min-height: 100dvh; grid-template-columns: minmax(0, 1fr); grid-template-rows: 48px auto auto; grid-template-areas: "top" "ed" "stage"; }
  .editor { border-right: 0; border-bottom: 1px solid var(--border); }
  #src { min-height: 180px; flex: none; }
  .canvas { height: 60vh; flex: none; }
}

/* Pantallas táctiles: barra para insertar flechas */
.ins-bar { display: flex; flex: none; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.ins-bar .btn { flex: none; min-width: 44px; justify-content: center; font-size: 16px; }
.ins-bar .btn span { font-size: 13px; color: var(--text-2); }
:root[data-input="touch"] #src { font-size: 16px; }
:root[data-input="touch"] .ins-bar.touch-only { display: flex !important; }
