/* ==========================================================================
   Diagrama por áreas (vista Diagrama y dibujo reutilizable del portal).
   Solo tokens de base.css: el SVG usa var(--token) para que funcione en modo oscuro.
   ========================================================================== */

/* ---------- dibujo (components/diagram_render.js) ---------- */
.dg-svg { display: block; width: 100%; height: auto; max-width: calc(var(--dg-vbw, 1000) * 1.25px); margin: 0 auto; overflow: visible; user-select: none; -webkit-user-select: none; }
.dg-svg text { font-family: var(--font); }

.dg-edge { fill: none; stroke: var(--hair-2); stroke-width: 2; stroke-linejoin: round; }
.dg-edge.dg-dash { stroke-dasharray: 4 5; }
.dg-edge.dg-risk { stroke: var(--crit); stroke-dasharray: 6 5; }
.dg-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: none; }
.dg-svg.dg-editable .dg-hit { pointer-events: stroke; cursor: pointer; }
.dg-svg.dg-editable .dg-hit:hover { stroke: var(--accent-wash); }
.dg-elabel { font-size: 11.5px; font-weight: 500; fill: var(--ink-2); stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; paint-order: stroke; pointer-events: none; }
.dg-elabel.dg-risk { fill: var(--crit-ink); font-weight: 600; }

.dg-node { cursor: pointer; outline: none; transition: opacity .15s; }
.dg-node .dg-box { fill: var(--surface); stroke: var(--hair-2); stroke-width: 1.25; transition: stroke .12s; }
.dg-node:hover .dg-box { stroke: var(--ink-3); }
.dg-node.dg-coord .dg-box { fill: var(--surface-2); stroke-dasharray: 5 4; stroke-width: 1.5; }
.dg-node.dg-sel .dg-box { stroke: var(--accent); stroke-width: 2.5; }
.dg-node:focus-visible .dg-box { stroke: var(--accent); stroke-width: 3; }
.dg-node:focus-visible:not(.dg-sel) .dg-box { stroke-dasharray: none; }
.dg-node.dg-pending .dg-box { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 4; }
.dg-node.dg-dim { opacity: .32; }
.dg-node .dg-t { font-size: 14.5px; font-weight: 650; fill: var(--ink); }
.dg-node .dg-s { font-size: 12px; fill: var(--ink-2); }
.dg-node .dg-track { fill: var(--surface-3); }
.dg-node.dg-coord .dg-track { fill: var(--hair); }
.dg-node .dg-fill { fill: var(--good); }
.dg-node .dg-ptxt { font-size: 11px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.dg-node .dg-btxt { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dg-node .dg-check { fill: none; stroke: var(--ink-inv); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.dg-svg.dg-editable .dg-node { cursor: grab; touch-action: none; }
.dg-svg.dg-is-dragging, .dg-svg.dg-is-dragging .dg-node { cursor: grabbing; }
.dg-node.dg-dragging .dg-box { stroke: var(--accent); stroke-width: 2.5; filter: drop-shadow(0 6px 12px rgba(16,24,40,.18)); }
@media (prefers-reduced-motion: reduce) { .dg-node, .dg-node .dg-box { transition: none; } }
@media (forced-colors: active) { .dg-node:focus-visible .dg-box, .dg-node.dg-sel .dg-box { stroke: Highlight; } }

/* ---------- vista ---------- */
.dg { display: grid; gap: 12px; }
.dg-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dg-filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.dg-owner { width: auto; min-width: 190px; min-height: 32px; }
.dg-q { width: 260px; min-height: 32px; }
.dg-chk { min-height: 32px; font-size: 13.5px; color: var(--ink-2); }
.dg-tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.dg-bar .btn.sm { min-height: 32px; }
.dg-hint { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 12px; }
.dg-hint kbd, .dg kbd { font-family: var(--mono); font-size: 11.5px; padding: 0 5px; border: 1px solid currentColor; border-radius: 4px; opacity: .85; }

.dg-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 430px); gap: 16px; align-items: start; }
.dg-canvas { min-width: 0; overflow: hidden; }
.dg-canvas-h { display: flex; gap: 10px 18px; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: 12px 16px 10px; border-bottom: 1px solid var(--hair); }
.dg-ttl-wrap { display: flex; gap: 10px; align-items: baseline; min-width: 0; flex-wrap: wrap; }
.dg-ttl-wrap h2 { font-size: 15px; font-weight: 650; }
.dg-ttl-wrap span { font-size: 12.5px; }
.dg-legend { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.dg-legend li { display: inline-flex; gap: 6px; align-items: center; }
.dg-sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.dg-ln { width: 26px; height: 8px; overflow: visible; }

.dg-stage {
  overflow: auto; padding: 8px; min-height: 260px; overscroll-behavior: contain;
  background-color: var(--surface);
  background-image: radial-gradient(circle, var(--hair) 1px, transparent 1.3px);
  background-size: 18px 18px; background-position: 9px 9px;
}
.dg-stage .dg-svg { min-width: min(calc(var(--dg-vbw, 1000) * .62px), 1400px); }
.dg-stage.dg-editing { background-image: radial-gradient(circle, var(--hair-2) 1px, transparent 1.3px); }
.dg-empty { display: grid; place-items: center; min-height: 320px; }
.dg-empty .empty { max-width: 520px; }
.dg-empty-p { margin: 4px auto 14px; max-width: 460px; }
.dg-empty-a { justify-content: center; }

/* ---------- ficha ---------- */
.dg-panel {
  position: sticky; top: calc(var(--topbar-h) + 12px);
  max-height: calc(100vh - var(--topbar-h) - 24px); max-height: calc(100dvh - var(--topbar-h) - 24px);
  overflow: auto; overscroll-behavior: contain; scrollbar-width: thin;
}
.dg-panel:focus:not(:focus-visible) { outline: none; }
.dg-p-head { padding: 14px 18px 14px; border-bottom: 1px solid var(--hair); display: grid; gap: 6px; }
.dg-p-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: -4px -6px -2px 0; }
.dg-p-top .btn { min-width: 32px; min-height: 32px; }
.dg-p-head h2 { font-size: 19px; font-weight: 680; letter-spacing: -.01em; overflow-wrap: anywhere; }
.dg-p-sub { margin: 0; color: var(--ink-2); }
.dg-p-desc { font-size: 13.5px; color: var(--ink-2); }
.dg-p-prog { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.dg-p-prog .progress { height: 6px; }
.dg-lvl { display: inline-flex; gap: 6px; align-items: center; font-weight: 600; color: var(--ink); white-space: nowrap; }
.dg-p-open { margin: 0; font-size: 12.5px; color: var(--ink-2); }
.dg-p-actions { margin-top: 6px; gap: 6px; }
.dg-p-actions .btn { min-height: 32px; }

.dg-sec { padding: 14px 18px; border-bottom: 1px solid var(--hair); }
.dg-sec:last-child { border-bottom: 0; }
.dg-sec .section-title .btn { min-height: 32px; text-transform: none; letter-spacing: 0; font-size: 12.5px; color: var(--info-ink); }
.dg-none { margin: 0; font-size: 13px; }
.dg-filtered { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 18px; background: var(--surface-2); border-bottom: 1px solid var(--hair); font-size: 12.5px; color: var(--ink-2); }

.dg-list, .dg-tasks, .dg-plist { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.dg-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: start; font-size: 13.5px; }
.dg-row > .dg-row-b:first-child { grid-column: 1 / 3; }
.dg-row-lead { padding-top: 1px; min-width: 70px; }
.dg-row-b { display: grid; gap: 3px; min-width: 0; }
.dg-row.is-closed .dg-link { color: var(--ink-3); }
.dg-link { border: 0; background: none; padding: 0; margin: 0; text-align: left; color: var(--ink); font-weight: 560; line-height: 1.4; cursor: pointer; overflow-wrap: anywhere; border-radius: 4px; }
.dg-link:hover { color: var(--info-ink); text-decoration: underline; text-underline-offset: 2px; }
.dg-clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.dg-chips { display: flex; gap: 5px; flex-wrap: wrap; align-items: center; }
.dg-meta { font-size: 12px; color: var(--ink-3); }

.dg-step + .dg-step { margin-top: 14px; }
.dg-step-h { font-size: 12.5px; font-weight: 650; color: var(--ink-2); margin: 0 0 6px; display: flex; gap: 8px; align-items: center; }
.dg-step-h .num { margin-left: auto; font-weight: 500; }
.dg-task { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; padding: 8px 10px; border: 1px solid var(--hair); border-radius: var(--r); background: var(--surface); }
.dg-task.is-closed { background: var(--surface-2); }
.dg-task.is-closed .dg-link { color: var(--ink-3); text-decoration: line-through; text-decoration-color: var(--ink-3); }
.dg-task-b { display: grid; gap: 5px; min-width: 0; }
.dg-cb { width: 18px; height: 18px; margin: 1px 0 0; accent-color: var(--good); cursor: pointer; }
.dg-cb:disabled { cursor: not-allowed; }
/* objetivo táctil de 32px sin agrandar la casilla */
.dg-cbw { display: grid; place-items: center; width: 32px; height: 32px; margin: -7px -5px -7px -5px; cursor: pointer; border-radius: var(--r-sm); }
.dg-cbw:hover { background: var(--surface-3); }
.dg-cbw .dg-cb { margin: 0; }

.dg-pick { width: 100%; display: flex; gap: 10px; align-items: center; min-height: 36px; padding: 6px 10px; border: 1px solid var(--hair); border-radius: var(--r-sm); background: var(--surface); text-align: left; }
.dg-pick:hover { border-color: var(--ink-3); }
.dg-pick-t { flex: 1; font-weight: 580; }
.dg-pick-n { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.dg-pick.is-dim { opacity: .5; }
.dg-att { min-height: 24px; }

.dg-dlg .help code { font-family: var(--mono); }
.dg-dlg-del { margin-right: auto; }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  .dg-grid { grid-template-columns: minmax(0, 1fr); }
  .dg-panel { position: static; max-height: none; overflow: visible; scroll-margin-top: calc(var(--topbar-h) + 8px); }
}
@media (max-width: 760px) {
  .dg-filters { width: 100%; }
  .dg-q { flex: 1; width: auto; min-width: 160px; }
  .dg-owner { flex: 1; min-width: 0; }
  .dg-legend { font-size: 11.5px; gap: 4px 10px; }
  .dg-p-head, .dg-sec { padding-left: 14px; padding-right: 14px; }
}
@media print {
  .dg-bar, .dg-hint, .dg-p-actions, .dg-sec .section-title .btn { display: none !important; }
  .dg-grid { grid-template-columns: 1fr; }
  .dg-panel { position: static; max-height: none; overflow: visible; }
}
