/* ============================================================
   public-view.css — Vista pública (solo lectura)
   ------------------------------------------------------------
   Render de posiciones libres (layout.x/y) + líneas SVG, con el
   diseño corporativo. Espejo del constructor visual, sin edición.
   ============================================================ */
:root {
  --pv-bg: #f4f7fa;
  --pv-panel: #ffffff;
  --pv-text: #17242f;
  --pv-muted: #6b7a88;
  --pv-border: #d8e0e8;
  --pv-accent: #05668d;
  --pv-line: #9fb2c2;
  --pv-shadow: 0 1px 2px rgba(0,0,0,.14);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: "Roboto Condensed", "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--pv-bg);
  color: var(--pv-text);
}

.pv-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------------- Header ---------------- */
.pv-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--pv-panel);
  border-bottom: 1px solid var(--pv-border);
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  z-index: 10;
  flex-wrap: wrap;
}
.pv-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
}
.pv-brand img { height: 26px; width: auto; display: block; }
.pv-updated { font-size: 11px; color: var(--pv-muted); }
.pv-spacer { flex: 1; }

.pv-toolbar { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pv-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 31px;
  padding: 6px 9px;
  border: 1px solid var(--pv-border);
  border-radius: 8px;
  background: #fff;
  color: var(--pv-text);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s, transform .1s;
}
.pv-btn:hover { background: #f0f6f9; border-color: var(--pv-accent); }
.pv-btn:active { transform: scale(.96); }
.pv-btn.is-clicked { box-shadow: 0 0 0 3px rgba(5,102,141,.14); }
.pv-iconbtn { padding: 6px; }
.pv-btn .material-icons-round { font-size: 18px; }
.pv-sep { width: 1px; height: 20px; background: var(--pv-border); margin: 0 3px; }

.pv-segment {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--pv-border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.pv-segment-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 31px;
  border: 0;
  border-right: 1px solid var(--pv-border);
  background: #fff;
  color: var(--pv-muted);
  padding: 6px 9px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  line-height: 1;
  transition: background .12s, color .12s;
}
.pv-segment-btn:last-child { border-right: 0; }
.pv-segment-btn:hover { background: #f0f6f9; color: var(--pv-text); }
.pv-segment-btn.is-active { background: var(--pv-accent); color: #fff; }
.pv-segment-btn .material-icons-round { font-size: 18px; }

.pv-zoom-ind {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  color: var(--pv-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------------- Canvas ---------------- */
.pv-canvas {
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: grab;
  background:
    radial-gradient(circle, rgba(5,102,141,.06) 1px, transparent 1px);
  background-size: 22px 22px;
}
.pv-canvas.is-panning { cursor: grabbing; }

.pv-stage {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  will-change: transform;
}

.pv-links {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
  z-index: 1;
}
.pv-link {
  fill: none;
  stroke: var(--pv-line);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.pv-node-layer { position: absolute; inset: 0; z-index: 2; }

/* ---------------- Nodo ---------------- */
.pv-node {
  position: absolute;
  width: 170px;
  min-height: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 8px 12px;
  background: var(--pv-panel);
  border: 1px solid var(--pv-border);
  border-top: 3px solid var(--pv-accent);
  border-radius: 7px;
  box-shadow: var(--pv-shadow);
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}
.pv-node:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(5,102,141,.18);
}
.pv-node.is-selected {
  box-shadow: 0 0 0 3px rgba(23,105,255,.28), 0 6px 16px rgba(0,0,0,.16);
}
.pv-role {
  font-weight: 700;
  font-size: 12.5px;
  line-height: 1.15;
  color: var(--pv-text);
}
.pv-pname { font-size: 11.5px; line-height: 1.1; color: var(--pv-muted); }
.pv-tag {
  font-size: 10px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--pv-muted);
}
/* root / empresa: NODO PRINCIPAL destacado (logo + marca, más grande y redondeado).
   Crece centrado sobre el MISMO ancla del box lógico (170×64): borde inferior en
   y+64 y centro en x+85, para que las líneas sigan saliendo perfectas. */
.pv-node.kind-root {
  flex-direction: row;        /* logo a la IZQUIERDA, texto a la derecha */
  justify-content: center;
  width: 224px;
  height: 84px;
  min-height: 0;
  margin-left: -27px;   /* (170-224)/2 */
  margin-top: -20px;    /* 64-84 */
  padding: 10px 16px;
  gap: 12px;
  background: linear-gradient(135deg, #0c058d 0%, #05668d 100%);
  border: 0;
  border-radius: 20px;
  box-shadow: 0 8px 22px rgba(12,5,141,.30), 0 1px 3px rgba(0,0,0,.16);
}
.pv-node.kind-root:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(12,5,141,.36), 0 2px 6px rgba(0,0,0,.18);
}
.pv-logo-plate {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 11px;
  padding: 5px 11px;
  box-shadow: 0 2px 6px rgba(0,0,0,.20);
}
.pv-node.kind-root .pv-logo {
  height: 40px;
  width: auto;
  max-width: 150px;
  object-fit: contain;   /* proporcional, nunca se deforma */
  display: block;
  margin: 0;
}
.pv-node.kind-root .pv-role { color: #fff !important; font-weight: 700; font-size: 14px; text-align: left; }

/* Botón colapsar rama */
.pv-toggle {
  position: absolute;
  bottom: -11px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid var(--pv-border);
  color: var(--pv-accent);
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,.16);
  z-index: 3;
}
.pv-toggle:hover { background: var(--pv-accent); color: #fff; border-color: var(--pv-accent); }

/* ---------------- Popup de detalles ---------------- */
.pv-details {
  position: fixed;
  top: 0; right: 0;
  width: 300px;
  max-width: 86vw;
  height: 100%;
  background: #fff;
  border-left: 1px solid var(--pv-border);
  box-shadow: -6px 0 24px rgba(0,0,0,.12);
  transform: translateX(100%);
  transition: transform .22s ease;
  z-index: 40;
  display: flex;
  flex-direction: column;
}
.pv-details.open { transform: translateX(0); }
.pv-details-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--pv-border);
}
.pv-details-kind {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #fff;
  background: var(--pv-accent);
  padding: 3px 9px;
  border-radius: 20px;
}
.pv-details-close {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--pv-muted);
  display: inline-flex;
}
.pv-details-body { padding: 16px; overflow: auto; }
.pv-details-body h3 { margin: 0 0 2px; font-size: 18px; }
.pv-details-body .pv-sub { color: var(--pv-muted); margin: 0 0 14px; font-size: 13px; }
.pv-row {
  display: flex;
  gap: 8px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--pv-border);
  font-size: 13px;
}
.pv-row .pv-k { color: var(--pv-muted); min-width: 84px; }
.pv-row .pv-v { color: var(--pv-text); word-break: break-word; }
.pv-row a { color: var(--pv-accent); text-decoration: none; }

.pv-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--pv-muted);
  font-size: 14px;
}

/* ---------------- Modal de exportación ---------------- */
.pv-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 25, 40, .45);
  padding: 20px;
}
.pv-modal.open { display: flex; }
.pv-modal-box {
  width: 980px;
  max-width: 100%;
  max-height: 92vh;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,.32);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pv-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--pv-border);
}
.pv-modal-head h3 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.pv-modal-body {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 0;
  min-height: 0;
  flex: 1;
}
.pv-modal-opts {
  padding: 16px;
  border-right: 1px solid var(--pv-border);
  overflow: auto;
}
.pv-opt-group { margin-bottom: 18px; }
.pv-opt-group > label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--pv-muted);
  margin-bottom: 7px;
}
.pv-opt-choices { display: flex; flex-direction: column; gap: 6px; }
.pv-choice {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--pv-border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color .12s, background .12s;
}
.pv-choice:hover { background: #f4f9fc; }
.pv-choice.is-active { border-color: var(--pv-accent); background: #eef7fb; }
.pv-choice .material-icons-round { font-size: 20px; color: var(--pv-accent); }
.pv-choice-txt { display: flex; flex-direction: column; }
.pv-choice-txt b { font-size: 13px; }
.pv-choice-txt small { font-size: 11px; color: var(--pv-muted); line-height: 1.25; }
.pv-opt-group.is-disabled { opacity: .4; pointer-events: none; }

.pv-modal-preview {
  position: relative;
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.pv-preview-hint {
  font-size: 12px;
  color: var(--pv-muted);
  margin-bottom: 8px;
  min-height: 16px;
}
.pv-preview-view {
  flex: 1;
  min-height: 340px;
  border: 1px dashed var(--pv-border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  /* checkerboard: se ve cuando el fondo es transparente (PNG) */
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #eef1f4 25%, transparent 25%),
    linear-gradient(-45deg, #eef1f4 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #eef1f4 75%),
    linear-gradient(-45deg, transparent 75%, #eef1f4 75%);
  background-size: 18px 18px;
  background-position: 0 0, 0 9px, 9px -9px, -9px 0;
}
.pv-preview-view.solid-bg { background-image: none; background-color: #fff; }
.pv-page {
  position: relative;
  background: #fff;
  box-shadow: 0 4px 18px rgba(0,0,0,.22);
}
.pv-preview-scaler {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
}
.pv-preview-scaler .pv-node { transition: none; }
.pv-preview-scaler.is-custom .pv-node { cursor: grab; }
.pv-preview-scaler.is-custom .pv-node.is-dragging { cursor: grabbing; box-shadow: 0 0 0 3px rgba(5,102,141,.3); }

.pv-modal-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--pv-border);
}
.pv-btn-primary {
  background: var(--pv-accent);
  color: #fff;
  border-color: var(--pv-accent);
}
.pv-btn-primary:hover { background: #045876; color: #fff; }
.pv-btn-primary.is-busy { opacity: .7; pointer-events: none; }

@media (max-width: 760px) {
  .pv-modal-body { grid-template-columns: 1fr; }
  .pv-modal-opts { border-right: 0; border-bottom: 1px solid var(--pv-border); }
}

@media (max-width: 640px) {
  .pv-updated { display: none; }
  .pv-btn span:not(.material-icons-round) { display: none; }
}
