/* Tokens de diseño (--bg, --panel, --sb-*, --warning/--danger/--success, radios,
   tipografia) y chrome de sidebar/topbar/nav/botones vienen de theme-light.css +
   theme-dark.css + theme-accent.css + phos-shell.css (PHOS_CORE, idénticos en
   toda la suite). Este archivo solo tiene estilos propios de PhosScribe. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100vh; }
h1, h2, h3, h4, p { margin: 0; }

.nav-badge {
  flex: 0 0 auto;
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--sb-text-dim);
}
/* ── Main content ─────────────────────────────────── */

/* ── Page empty state ─────────────────────────────── */
.page-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
}

.page-empty svg { width: 40px; height: 40px; stroke-width: 1.5; opacity: .5; }
.page-empty h2 { font-size: 18px; font-weight: 600; color: var(--ink); }
.page-empty p { font-size: 14px; max-width: 360px; line-height: 1.6; }
/* ── Page shell ──────────────────────────────────── */

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.02em;
}

.page-subtitle {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
}

/* ── Table ────────────────────────────────────────── */
.pi-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.pi-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.pi-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  vertical-align: middle;
}

.pi-table tr:last-child td { border-bottom: none; }
.pi-table tr:hover td { background: var(--surface); }
.pi-table .mono { font-family: 'Courier New', monospace; font-size: 12px; }

/* ── Forms ────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

.form-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.form-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select.form-input { cursor: pointer; }
textarea.form-input { resize: vertical; line-height: 1.55; }

/* ── Badges de estado ─────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
}

.badge-pendiente  { background: var(--surface); color: var(--muted); }
.badge-ejecutando { background: #eff6ff; color: #3b82f6; }
.badge-completado { background: #d1fae5; color: #059669; }
.badge-descartado { background: var(--warning-dim); color: var(--warning); }
.badge-error      { background: var(--danger-dim); color: var(--danger); }

:root[data-theme="dark"] .badge-ejecutando { background: rgba(59,130,246,.15); color: #93c5fd; }
:root[data-theme="dark"] .badge-completado { background: rgba(16,185,129,.15); color: #6ee7b7; }

/* ── Modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Suite Phos (overlay iframe centrado, Fase 37) ─── */
#suite-overlay.hidden { display: none; }
#suite-overlay.modal-overlay { padding: 0; }
#suite-overlay .modal-panel {
  padding: 0; gap: 0; max-width: none; overflow: hidden;
  width: min(1100px, 92vw); height: min(800px, 90vh);
}
#suite-frame { width: 100%; height: 100%; border: none; display: block; }

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--ink);
}

.modal-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  margin: 0;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

/* ── Campo row (editor de plantilla) ──────────────── */
.campo-row {
  display: grid;
  grid-template-columns: 1fr 110px 1.4fr 32px;
  gap: 8px;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.campo-row:last-child { border-bottom: none; }

/* ── Run log ──────────────────────────────────────── */
.run-log {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.65;
  color: var(--ink);
  max-height: 260px;
  overflow-y: auto;
}

.run-log-line       { margin: 0; }
.run-log-line.error { color: var(--danger); }
.run-log-line.ok    { color: var(--success); }
.run-log-line.dim   { color: var(--muted); }

/* ── Result JSON viewer ───────────────────────────── */
.result-json {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
  max-height: 320px;
  overflow: auto;
  white-space: pre;
  margin: 0;
}

/* ── Runs layout ──────────────────────────────────── */
.runs-layout {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .runs-layout { grid-template-columns: 1fr; }}

/* ── Dashboard stats ──────────────────────────────── */
.ops-chart-panel{margin:14px 0;padding:16px;background:var(--panel);border:1px solid var(--line);border-radius:var(--radius)}.ops-chart-panel h3{display:flex;align-items:center;gap:8px;margin:0 0 14px}.activity-chart{display:flex;align-items:end;gap:12px;height:140px}.chart-day{display:flex;flex:1;height:100%;flex-direction:column;justify-content:end;align-items:center;gap:5px}.chart-bar{width:min(28px,80%);min-height:3px;border-radius:5px 5px 0 0;background:var(--accent)}.chart-day small{color:var(--muted);font-size:10px}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
}

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.04em;
  margin-top: 4px;
  line-height: 1;
}

/* ── Estado PRONTO (coming soon) ─────────────────── */
.badge-pronto {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  background: var(--warning-dim);
  color: var(--warning);
  border: 1px solid rgba(245,158,11,.25);
  text-transform: uppercase;
}

/* ── Flow Studio ─────────────────────────────────── */
[data-page="studio"] { display: flex; flex-direction: column; flex: 1; }

.studio-header {
  position: sticky;
  top: var(--topbar-h);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.studio-section {
  margin: 0 28px 16px;
  padding: 20px 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 0;
  box-shadow: var(--shadow-xs);
}

.studio-section:first-of-type { margin-top: 20px; }
.studio-section:last-of-type  { margin-bottom: 40px; }

.studio-section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 16px;
}

.studio-grid-3 {
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 16px;
}

.studio-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 720px) {
  .studio-grid-3 { grid-template-columns: 1fr; }
  .studio-grid-2 { grid-template-columns: 1fr; }}

/* ── Pipeline ─────────────────────────────────────── */
.pipeline-stages {
  display: flex;
  flex-direction: column;
}

.stage-connector {
  display: flex;
  justify-content: center;
  padding: 4px 0;
}

.stage-arrow {
  font-size: 20px;
  color: var(--muted);
  line-height: 1;
  opacity: .6;
}

.stage-card {
  display: flex;
  gap: 14px;
  padding: 16px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s, opacity .2s;
}

.stage-card.stage-inactive { opacity: .5; }

.stage-source      { border-left: 3px solid #3b82f6; }
.stage-classify    { border-left: 3px solid #f59e0b; }
.stage-extract     { border-left: 3px solid #10b981; }
.stage-destination { border-left: 3px solid #8b5cf6; }

.stage-badge {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 700;
  display: grid;
  place-items: center;
  margin-top: 1px;
}

.stage-badge-optional {
  background: var(--warning);
  color: #fff;
}

.stage-content  { flex: 1; min-width: 0; }
.stage-title    { font-size: 14px; font-weight: 600; color: var(--ink); }
.stage-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; }

.stage-optional-tag {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--warning-dim);
  color: var(--warning);
  margin-left: 6px;
  vertical-align: middle;
}

/* ── Toggle switch ───────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-flex;
  cursor: pointer;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  display: block;
  width: 36px;
  height: 20px;
  border-radius: 20px;
  background: var(--line);
  transition: background .2s;
  position: relative;
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}

.toggle-switch input:checked + .toggle-track {
  background: #10b981;
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(16px);
}

/* ── Studio de grafo (Drawflow) ───────────────────────── */
.gstudio { display: flex; flex-direction: column; height: calc(100vh - 56px); }
.gstudio-topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--surface); flex-wrap: nowrap; overflow-x: auto;
}
.gstudio-body { display: grid; grid-template-columns: 200px 1fr 280px; flex: 1; min-height: 0; }
.gstudio-palette { border-right: 1px solid var(--line); padding: 10px; overflow-y: auto; background: var(--surface); }
.g-pal-group { margin-bottom: 14px; }
.g-pal-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; margin-bottom: 6px; }
.g-pal-item {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; margin-bottom: 5px;
  border: 1px solid var(--line); border-radius: 7px; background: var(--bg); cursor: grab; font-size: 13px;
}
.g-pal-item:hover { background: var(--surface); }
.g-pal-item i { width: 15px; height: 15px; }
.gstudio-canvas { position: relative; min-width: 0; background: var(--bg); }
#drawflow { width: 100%; height: 100%; }
.gstudio-props { border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; background: var(--surface); }
.g-props-empty { font-size: 12px; color: var(--muted); line-height: 1.6; }
.g-props-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.gstudio-preview { border-top: 1px solid var(--line); background: var(--surface); max-height: 200px; display: flex; flex-direction: column; }
.gstudio-preview-head { display: flex; gap: 10px; align-items: baseline; padding: 6px 12px; border-bottom: 1px solid var(--line); }
.gstudio-preview-body { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px 12px; overflow: hidden; }
.gstudio-preview-out { margin: 0; background: #0d1117; color: #c9d1d9; border-radius: 6px; padding: 8px; font-size: 11px; overflow: auto; }

/* Nodos Drawflow */
#drawflow .drawflow .drawflow-node { background: transparent; border: none; padding: 0; box-shadow: none; width: auto; min-width: 160px; }
#drawflow .drawflow-node.selected .g-node-inner { outline: 2px solid var(--accent, #6366f1); }
.g-node-inner {
  display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-panel); padding: 9px 11px; box-shadow: 0 1px 3px rgba(0,0,0,.08); min-width: 160px;
}
/* los <i data-lucide> se reemplazan por <svg> al crear iconos; fijar tamaño en ambos */
.g-node-inner i, .g-node-inner svg { width: 15px; height: 15px; color: var(--muted); flex: 0 0 auto; }
.g-pal-item i, .g-pal-item svg { width: 14px; height: 14px; flex: 0 0 auto; }
.g-node-title { font-size: 12px; font-weight: 600; color: var(--ink); }
.g-node-sub { font-size: 11px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#drawflow .drawflow-node .input, #drawflow .drawflow-node .output { background: var(--surface); border: 2px solid #9ca3af; }

/* ── Panel de prueba mejorado ─────────────────────── */
.gstudio-preview { border-top: 1px solid var(--line); background: var(--surface); max-height: 260px; display: flex; flex-direction: column; }
.gstudio-preview-body { display: grid; grid-template-columns: 1fr 1.1fr; gap: 8px; padding: 8px 12px; min-height: 0; flex: 1; overflow: hidden; }
.gstudio-preview-muestra { display: flex; flex-direction: column; gap: 5px; min-height: 0; }
.gstudio-preview-out {
  margin: 0; background: #0d1117; color: #c9d1d9; border-radius: 6px; padding: 8px 10px;
  font-size: 11px; font-family: 'Courier New', monospace; overflow: auto; line-height: 1.55;
  white-space: pre;
}
/* JSON syntax highlighting */
.jv-k { color: #79c0ff; }  /* key     */
.jv-s { color: #a5d6ff; }  /* string  */
.jv-n { color: #f8c555; }  /* number  */
.jv-b { color: #ff7b72; }  /* boolean */
.jv-z { color: #8b949e; }  /* null    */

/* ── Chip de proveedor vinculado ──────────────────── */
.prov-connect {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-panel);
  background: var(--bg); margin-bottom: 8px;
}
.prov-connect-info { flex: 1; }
.prov-connect-name { font-size: 12px; font-weight: 600; color: var(--ink); }
.prov-connect-sub  { font-size: 11px; color: var(--muted); }