/* Mission Control — dark theme moderno. Comentarios en español. */
:root {
  --bg-base: #06060a;
  --bg-primary: #0a0a0f;
  --bg-card: #12121a;
  --bg-card-hover: #1a1a2e;
  --bg-terminal: #0d1117;
  --border: #2a2a3e;
  --border-hover: #3a3a5e;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-blue: #60a5fa;
  --accent-green: #22c55e;
  --accent-amber: #f59e0b;
  --accent-purple: #a78bfa;
  --accent-red: #ef4444;
  --accent-cyan: #22d3ee;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-blue); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* Scrollbar global */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ── Header ── */
.header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.logo .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent-green); box-shadow: 0 0 10px var(--accent-green); }
.logo small { color: var(--text-muted); font-weight: 400; }
.header .spacer { flex: 1; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.conn .pip { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-red); }
.conn.online .pip { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }
.userbox { display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 12px; color: #06060a; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-secondary); padding: 6px 12px; border-radius: 8px; font-size: 12px; }
.btn-ghost:hover { border-color: var(--border-hover); color: var(--text-primary); }

/* ── Tabs ── */
.tabs { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--bg-primary); overflow-x: auto; }
.tab { position: relative; background: transparent; border: none; color: var(--text-secondary); padding: 12px 16px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--text-primary); }
.tab.active::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; background: var(--accent-blue); border-radius: 2px; animation: slideDown .2s ease; }

/* ── Layout de vistas ── */
.view { display: none; padding: 20px; animation: slideDown .25s ease; }
.view.active { display: block; }
#view-graph.active { display: block; padding: 0; position: relative; }

/* ── Cards ── */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; transition: transform .15s, border-color .15s; }
.card:hover { border-color: var(--border-hover); }
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.metric { text-align: left; }
.metric .num { font-size: 30px; font-weight: 800; }
.metric .lbl { color: var(--text-muted); font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); margin: 22px 0 10px; }

/* Markdown renderizado */
.md { line-height: 1.7; color: var(--text-secondary); }
.md h1, .md h2, .md h3 { color: var(--text-primary); margin: 14px 0 8px; }
.md h1 { font-size: 20px; } .md h2 { font-size: 16px; } .md h3 { font-size: 14px; }
.md ul { padding-left: 20px; } .md li { margin: 3px 0; }
.md code { background: #1e1e2e; padding: 1px 6px; border-radius: 4px; font-size: 12px; color: var(--accent-cyan); }
.md table { border-collapse: collapse; margin: 10px 0; width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; font-size: 13px; }
.md a { color: var(--accent-blue); }

/* ── Badges ── */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.pri-urgent { background: rgba(239,68,68,.15); color: var(--accent-red); }
.pri-high { background: rgba(245,158,11,.15); color: var(--accent-amber); }
.pri-normal { background: rgba(96,165,250,.15); color: var(--accent-blue); }
.pri-low { background: rgba(148,163,184,.15); color: var(--text-secondary); }
.st-pending { background: rgba(148,163,184,.15); color: var(--text-secondary); }
.st-queued { background: rgba(245,158,11,.15); color: var(--accent-amber); }
.st-running { background: rgba(34,197,94,.18); color: var(--accent-green); animation: pulse 1.4s infinite; }
.st-completed { background: rgba(34,211,238,.15); color: var(--accent-cyan); }
.st-failed { background: rgba(239,68,68,.15); color: var(--accent-red); }
.tag-verificado { background: rgba(34,197,94,.15); color: var(--accent-green); }
.tag-definido { background: rgba(245,158,11,.15); color: var(--accent-amber); }
.tag-pendiente { background: rgba(148,163,184,.15); color: var(--text-secondary); }

/* ── Kanban ── */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; }
.kanban .col { background: var(--bg-primary); border: 1px solid var(--border); border-radius: 10px; padding: 10px; min-height: 200px; }
.kanban .col h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 10px; display: flex; justify-content: space-between; }
.task-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: pointer; transition: border-color .15s, transform .15s; }
.task-card:hover { border-color: var(--border-hover); transform: translateY(-1px); }
.task-card .t { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.task-card .meta { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.task-card .platt-flag { font-size: 10px; color: var(--accent-green); margin-top: 6px; }

/* ── Terminal de Platt ── */
.platt-wrap { display: grid; grid-template-columns: 40% 60%; gap: 14px; height: calc(100vh - 160px); }
.platt-list { overflow-y: auto; }
.platt-list .group-title { font-size: 11px; text-transform: uppercase; color: var(--text-muted); margin: 12px 0 6px; }
.platt-list .pitem { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 6px; cursor: pointer; }
.platt-list .pitem.sel { border-color: var(--accent-blue); }
.platt-list .pitem.running { border-color: var(--accent-green); box-shadow: 0 0 0 1px var(--accent-green); animation: glow 1.6s infinite; }
.terminal { background: var(--bg-terminal); border: 1px solid var(--border); border-radius: 10px; display: flex; flex-direction: column; overflow: hidden; }
.terminal .thead { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); background: #0b0e14; }
.terminal .thead .prompt { color: var(--accent-green); font-family: ui-monospace, monospace; font-size: 12px; }
.terminal .thead .tbtns { margin-left: auto; display: flex; gap: 6px; }
.terminal pre { flex: 1; overflow-y: auto; padding: 12px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; color: #e6edf3; }
.line-stdout { color: #e6edf3; }
.line-stderr { color: var(--accent-red); }
.line-system { color: var(--accent-amber); }
.working { color: var(--accent-green); }
.working .dots::after { content: ''; animation: dots 1.4s steps(4,end) infinite; }

/* ── Timeline (journal/decisions) ── */
.timeline { border-left: 2px solid var(--border); margin-left: 8px; padding-left: 20px; }
.timeline .item { position: relative; margin-bottom: 18px; }
.timeline .item::before { content: ''; position: absolute; left: -27px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent-blue); box-shadow: 0 0 0 3px var(--bg-base); }

/* ── Events feed ── */
.event-row { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--bg-card); font-size: 12.5px; animation: slideDown .25s ease; }
.event-row .ev-tool { font-weight: 700; }
.event-row .ev-detail { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.event-row .ev-ts { color: var(--text-muted); font-size: 11px; }
.live-badge { display: inline-flex; align-items: center; gap: 6px; color: var(--accent-green); font-size: 12px; }
.live-badge .pip { width: 8px; height: 8px; border-radius: 50%; background: var(--accent-green); animation: pulse 1.2s infinite; }

/* ── Team ── */
.team-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.member { display: flex; gap: 12px; align-items: flex-start; }
.member .big-av { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #06060a; flex-shrink: 0; }
.member.agent .big-av { box-shadow: 0 0 0 2px var(--accent-green); }
.member.agent.running .big-av { animation: glow 1.5s infinite; }

/* ── Modal ── */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: none; place-items: center; z-index: 100; }
.overlay.show { display: grid; }
.modal { background: var(--bg-card); border: 1px solid var(--border-hover); border-radius: 14px; padding: 22px; width: min(560px, 92vw); max-height: 88vh; overflow-y: auto; animation: scaleIn .2s ease; }
.modal h3 { margin-bottom: 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-secondary); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; background: var(--bg-primary); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-primary); padding: 10px 12px; font-size: 13px; min-height: 44px; outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--accent-blue); }
.field textarea { min-height: 120px; resize: vertical; font-family: inherit; }
.row { display: flex; gap: 10px; }
.row > .field { flex: 1; }
.btn-primary { background: var(--accent-blue); color: #06060a; border: none; padding: 11px 18px; border-radius: 9px; font-weight: 700; font-size: 13px; min-height: 44px; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; }

/* ── Graph ── */
#graph-svg { width: 100%; height: calc(100vh - 110px); display: block; cursor: grab; }
.node circle { stroke: #0a0a0f; stroke-width: 2px; cursor: pointer; transition: filter .2s; }
.node text { fill: var(--text-secondary); font-size: 11px; pointer-events: none; }
.node.pending circle { opacity: .4; stroke-dasharray: 3 3; }
.node.pulse circle { animation: nodepulse .6s ease; }
.node.glow circle { animation: glow 1.4s infinite; }
.edge { fill: none; stroke: var(--border); stroke-width: 1.4px; opacity: .6; }
.edge-label { fill: var(--text-muted); font-size: 9px; pointer-events: none; }
.gtooltip { position: absolute; background: var(--bg-card); border: 1px solid var(--border-hover); border-radius: 8px; padding: 10px 12px; font-size: 12px; pointer-events: none; max-width: 220px; z-index: 60; display: none; }

/* ── Login ── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, #14142a 0%, var(--bg-base) 60%); }
.login-card { width: min(380px, 92vw); background: var(--bg-card); border: 1px solid var(--border); border-radius: 16px; padding: 28px; }
.login-card .brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 20px; }
.login-err { color: var(--accent-red); font-size: 12px; min-height: 16px; margin-top: 6px; }

/* ── Animaciones ── */
.slide-in { animation: slideDown .3s ease; }
/* Barras de uso (dashboard) */
.usage-bar { margin: 10px 0; }
.usage-header { display: flex; justify-content: space-between; font-size: 11px; margin-bottom: 4px; color: var(--text-secondary); }
.usage-bar .bar { height: 6px; background: #1a1a2e; border-radius: 3px; overflow: hidden; }
.usage-bar .bar-fill { height: 100%; border-radius: 3px; transition: width .5s; }
.bar-fill.green { background: var(--accent-green); }
.bar-fill.amber { background: var(--accent-amber); }
.bar-fill.red { background: var(--accent-red); }
.usage-reset { font-size: 9px; color: var(--text-muted); margin-top: 3px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes glow { 0%, 100% { box-shadow: 0 0 4px var(--accent-green); } 50% { box-shadow: 0 0 16px var(--accent-green); } }
@keyframes nodepulse { 0% { filter: drop-shadow(0 0 0 var(--accent-cyan)); } 50% { filter: drop-shadow(0 0 12px var(--accent-cyan)); } 100% { filter: none; } }
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }


/* ═══════════════ Mobile UX/UI (iOS 26 · Android · web) ═══════════════ */
:root { --hdr-h: 56px; --bn-h: 60px; }

/* Ergonomía táctil global */
* { -webkit-tap-highlight-color: transparent; }
button, a, .tab, .task-card, .pitem, .bn-item, .event-row, .badge { touch-action: manipulation; }
body { overscroll-behavior-y: none; }
.bottomnav { display: none; }

/* Safe-area del notch en modo instalado (todas las tallas) */
@supports (padding: env(safe-area-inset-top)) {
  .header { padding-top: calc(12px + env(safe-area-inset-top)); }
}

/* ───────── Móvil / iPad portrait (≤ 860px) ───────── */
@media (max-width: 700px) {
  /* Header glass compacto */
  .header {
    gap: 10px; padding: 10px 14px;
    padding-top: calc(10px + env(safe-area-inset-top));
    padding-left: calc(14px + env(safe-area-inset-left));
    padding-right: calc(14px + env(safe-area-inset-right));
    background: rgba(10,10,15,.72);
    backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  }
  .logo { font-size: 15px; } .logo small { display: none; }
  #user-name { display: none; }
  #conn-text { display: none; }

  /* Tabs superiores fuera; navegamos con la barra inferior */
  .tabs { display: none; }

  /* Vistas con aire inferior para no chocar con la bottom nav */
  .view { padding: 14px; padding-bottom: calc(var(--bn-h) + env(safe-area-inset-bottom) + 20px); }
  #view-graph.active { padding: 0; }

  /* Grids */
  .grid-4 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .team-grid { grid-template-columns: 1fr; }
  .card { padding: 14px; }
  .metric .num { font-size: 26px; }
  .section-title { margin: 16px 0 8px; }

  /* Graph a pantalla completa (alto estable con svh) */
  #graph-svg { height: calc(100vh - 130px); height: calc(100svh - var(--hdr-h) - var(--bn-h) - env(safe-area-inset-bottom)); }

  /* Kanban: columnas deslizables con snap (swipe entre estados) */
  .kanban { display: flex; grid-template-columns: none; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
  .kanban::-webkit-scrollbar { display: none; }
  .kanban .col { scroll-snap-align: start; flex: 0 0 84%; min-height: 55svh; }

  /* Platt: lista horizontal arriba, terminal grande abajo */
  .platt-wrap { display: flex; flex-direction: column; gap: 12px; height: auto; }
  .platt-list { display: flex; gap: 8px; overflow-x: auto; max-height: none; padding-bottom: 4px; }
  .platt-list::-webkit-scrollbar { display: none; }
  .platt-list .group-title { display: none; }
  .platt-list .pitem { flex: 0 0 72%; margin-bottom: 0; }
  .terminal { height: 50vh; height: 50svh; min-height: 320px; }
  .terminal pre { font-size: 13.5px; line-height: 1.5; overflow-wrap: anywhere; }

  /* Modales tipo "sheet" desde abajo (patrón iOS) */
  .overlay { align-items: flex-end; }
  .modal { width: 100%; max-width: 100%; border-radius: 22px 22px 0 0; max-height: 90svh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); animation: sheetUp .3s cubic-bezier(.2,.8,.2,1); }
  .field input, .field textarea, .field select { font-size: 16px; } /* evita el zoom de iOS al enfocar */

  /* Barra de navegación inferior (Liquid Glass, zona del pulgar) */
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
    height: calc(var(--bn-h) + env(safe-area-inset-bottom));
    padding: 0 4px env(safe-area-inset-bottom);
    background: rgba(8,8,12,.8);
    backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px);
    border-top: 1px solid var(--border);
    /* Scroll horizontal real (momentum iOS); el JS centra la activa con scrollIntoView */
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .bottomnav::-webkit-scrollbar { display: none; }
  .bn-item {
    flex: 0 0 auto; min-width: 64px; background: transparent; border: 0; color: var(--text-muted);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; padding: 6px 10px;
  }
  .bn-ic { font-size: 21px; line-height: 1; filter: grayscale(.5) opacity(.65); transition: transform .18s ease, filter .18s ease; }
  .bn-lb { font-size: 10.5px; max-width: 72px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bn-item.active { color: var(--text-primary); }
  .bn-item.active .bn-ic { filter: none; transform: translateY(-2px) scale(1.12); }
  .bn-item.active .bn-lb { color: var(--accent-blue); font-weight: 700; }
  .bn-item:active .bn-ic { transform: scale(.92); }
}

/* Teléfonos pequeños */
@media (max-width: 380px) {
  .bn-lb { font-size: 10px; }
  .metric .num { font-size: 22px; }
}

@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { *, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }


/* ═══════════════ Grafo con salud (semáforos) ═══════════════ */
/* Nodo caído: pulso continuo. */
.node-error circle.health-circle { animation: node-error-pulse 1.5s infinite; }
@keyframes node-error-pulse { 0%, 100% { r: 24; } 50% { r: 28; } }

/* Nodo Platt ejecutando: glow verde. */
.node-running circle.health-circle { animation: node-running-glow 2s infinite; }
@keyframes node-running-glow {
  0%, 100% { filter: drop-shadow(0 0 4px #22c55e); }
  50% { filter: drop-shadow(0 0 12px #22c55e); }
}

/* Nodo degradado (amarillo): brillo ámbar suave. */
.node-warning circle.health-circle { animation: node-warning-glow 2s infinite; }
@keyframes node-warning-glow {
  0%, 100% { filter: drop-shadow(0 0 2px #f59e0b); }
  50% { filter: drop-shadow(0 0 10px #f59e0b); }
}

.node-health-label { pointer-events: none; }

/* Tooltip del grafo (detalle de salud) */
.graph-tooltip, .gtooltip {
  position: absolute; background: #12121a; border: 1px solid #2a2a3e;
  border-radius: 8px; padding: 10px; min-width: 180px; z-index: 100;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5); pointer-events: none;
}
.gtooltip .tt-name { font-size: 13px; font-weight: 600; color: #e2e8f0; }
.gtooltip .tt-type { font-size: 10px; color: #64748b; margin-top: 2px; }
.gtooltip .tt-health { display: flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: #e2e8f0; }
.gtooltip .tt-detail { font-size: 10px; color: #94a3b8; margin-top: 4px; }

/* ═══════════════ Terminal interactiva ═══════════════ */
.terminal-layout { display: grid; grid-template-columns: 380px 1fr; gap: 12px; height: calc(100vh - 140px); }
.term-side { display: flex; flex-direction: column; overflow-y: auto; }
.term-side .field textarea { min-height: 140px; }
.terminal-screen {
  flex: 1; background: #0d1117; color: #e6edf3; padding: 12px;
  font-family: 'SF Mono', ui-monospace, Menlo, monospace; font-size: 13px; line-height: 1.6;
  overflow-y: auto; border-radius: 8px; border: 1px solid #2a2a3e;
  white-space: pre-wrap; word-break: break-word;
}
.terminal-screen .error { color: #ef4444; }
.terminal-screen .system { color: #22c55e; }

.term-history { overflow-y: auto; }
.term-history .th-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; }
.term-history .th-item:hover { border-color: var(--border-hover); }
.term-history .th-top { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); }
.term-history .th-model { color: var(--accent-purple); font-weight: 600; }
.term-history .th-time { margin-left: auto; }
.term-history .th-prompt { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

@media (max-width: 700px) {
  .terminal-layout { grid-template-columns: 1fr; height: auto; }
  .terminal-screen { height: 320px; font-size: 13px; overflow-wrap: anywhere; }
}
@media (max-width: 430px) {
  .terminal-layout { grid-template-columns: 1fr; height: auto; }
  .terminal-screen { height: 300px; font-size: 12.5px; overflow-wrap: anywhere; }
}

/* ═══════════════ Alertas en tiempo real (toasts) ═══════════════ */
.alerts-container {
  position: fixed; top: 60px; right: 16px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 400px; width: calc(100% - 32px); pointer-events: none;
}
.alert-toast {
  background: #12121a; border-radius: 10px; padding: 12px;
  border-left: 4px solid #64748b; box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  pointer-events: auto;
}
.alert-critical { border-left-color: #ef4444; }
.alert-warning  { border-left-color: #f59e0b; }
.alert-info     { border-left-color: #22c55e; }

.alert-header { display: flex; align-items: center; gap: 8px; }
.alert-icon { font-size: 16px; }
.alert-title { flex: 1; font-size: 12px; color: #e2e8f0; font-weight: 500; line-height: 1.4; }
.alert-close {
  background: none; border: none; color: #64748b;
  font-size: 14px; cursor: pointer; padding: 2px; line-height: 1;
}
.alert-close:hover { color: #e2e8f0; }

.alert-actions { margin-top: 8px; }
.alert-fix-btn {
  width: 100%; padding: 8px; border-radius: 6px;
  background: #1a1a2e; border: 1px solid #ef4444;
  color: #ef4444; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
}
.alert-fix-btn:hover:not(:disabled) { background: #ef4444; color: #fff; }
.alert-fix-btn:disabled { opacity: 0.7; cursor: default; }

@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOutRight { from { opacity: 1; } to { opacity: 0; transform: translateX(50px); } }

@media (max-width: 430px) {
  .alerts-container { right: 8px; left: 8px; top: 50px; max-width: 100%; width: auto; }
  .alert-toast { padding: 10px; }
  .alert-title { font-size: 11px; }
}

/* ── Grafo: panel lateral (ficha de nodo) + leyenda ── */
#side-panel {
  position: absolute; top: 0; right: 0; width: 340px; height: 100%;
  background: var(--bg-card); border-left: 1px solid var(--border-hover);
  padding: 18px; box-sizing: border-box; transform: translateX(100%);
  transition: transform .2s; overflow-y: auto; z-index: 45;
}
#side-panel.open { transform: translateX(0); }
.pp-close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: var(--text-secondary); font-size: 18px; cursor: pointer; }
.pp-title { font-size: 17px; font-weight: 700; margin-bottom: 8px; padding-right: 24px; }
.pp-badge { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 6px; margin-bottom: 12px; }
.pp-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.pp-k { color: var(--text-muted); } .pp-v { color: var(--text-secondary); text-align: right; }
.pp-sec { color: #60a5fa; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin: 14px 0 4px; }
.pp-text { color: var(--text-secondary); font-size: 13px; line-height: 1.5; }
/* Bloque de diagnóstico + acción de fix en el panel lateral del grafo */
.pp-diag { border-radius: 10px; padding: 12px; margin: 4px 0 14px; border: 1px solid; }
.pp-diag-red { background: #ef444414; border-color: #ef444455; }
.pp-diag-yellow { background: #f59e0b14; border-color: #f59e0b55; }
.pp-diag-head { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.pp-diag-why { color: var(--text-secondary); font-size: 13px; line-height: 1.4; }
.pp-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: #e2e8f0;
  background: #0f1420; border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; white-space: pre-wrap; word-break: break-word; }
.pp-diag-actions { margin-top: 12px; }
.pp-fix-btn { width: 100%; min-height: 44px; background: #a78bfa; color: #0b0e16; border: none; border-radius: 8px;
  font-size: 13px; font-weight: 700; cursor: pointer; transition: filter .15s; }
.pp-fix-btn:hover:not(:disabled) { filter: brightness(1.1); }
.pp-fix-btn:disabled { opacity: .7; cursor: default; }
.pp-note { color: var(--text-muted); font-size: 12px; font-style: italic; }
.pp-fix-result { margin-top: 8px; font-size: 12px; color: var(--text-secondary); }
.pp-link { color: #60a5fa; text-decoration: none; font-weight: 600; }
.pp-err { color: #ef4444; }
#graph-legend {
  position: absolute; left: 12px; bottom: 12px; display: flex; gap: 12px; flex-wrap: wrap;
  background: rgba(11,14,22,.82); border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 11px; color: var(--text-muted); z-index: 30; pointer-events: none;
}
#graph-legend span { display: inline-flex; align-items: center; gap: 4px; }
.lg-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
@media (max-width: 640px) { #side-panel { width: 100%; } #graph-legend { display: none; } }

/* ── Panel Platt: badges de estado faltantes ── */
.st-cancelled { background: rgba(148,163,184,.15); color: var(--text-secondary); }
.st-orphan_review { background: rgba(245,158,11,.18); color: var(--accent-amber); }

/* ── Panel Platt: zona RESULTADO ── */
.platt-result {
  border-bottom: 1px solid var(--border); padding: 10px 12px; background: #0b0e14;
  max-height: 34%; overflow-y: auto; border-left: 3px solid var(--border);
}
.platt-result.res-completed { border-left-color: var(--accent-cyan); }
.platt-result.res-failed { border-left-color: var(--accent-red); }
.platt-result.res-cancelled { border-left-color: var(--text-muted); }
.platt-result.res-orphan_review { border-left-color: var(--accent-amber); }
.platt-result.res-running, .platt-result.res-queued { border-left-color: var(--accent-green); }
.platt-result .result-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.platt-result .result-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); }
.platt-result .result-body { font-size: 12.5px; }
.platt-result .res-muted { color: var(--text-muted); }

/* ── Panel Platt: zona ACTIVIDAD (carriles por subagente) ── */
.platt-act-head { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); padding: 8px 12px 4px; }
.platt-lanes { flex: 1; overflow-y: auto; padding: 6px 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.lane { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--bg-terminal); }
.lane.lane-sub { border-left: 2px solid var(--accent-purple); }
.lane-head { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; background: #0b0e14; user-select: none; }
.lane-head:hover { background: var(--bg-card-hover); }
.lane-toggle { color: var(--text-muted); font-size: 11px; transition: transform .15s; }
.lane.collapsed .lane-toggle { transform: rotate(-90deg); }
.lane-name { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.lane-sub .lane-name { color: var(--accent-purple); }
.lane-count { margin-left: auto; font-size: 11px; color: var(--text-muted); background: rgba(148,163,184,.12); border-radius: 999px; padding: 1px 8px; }
.lane-body { padding: 8px 10px; font-family: ui-monospace, 'SF Mono', Menlo, monospace; font-size: 12.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.lane.collapsed .lane-body { display: none; }
@media (max-width: 640px) {
  .platt-result { max-height: 40%; }
  .lane-body { font-size: 13px; overflow-wrap: anywhere; }
}

/* ── Terminal interactiva del VPS (xterm) ───────────────────────────── */
#view-console.view.active { display: flex; }
/* ── Terminal VPS — estética VS Code / editor profesional ──
   Paleta: editor #1e1e1e · chrome #252526 · borde #333 · acento #007acc */
.vps-term {
  display: flex; flex-direction: column;
  height: calc(100vh - 170px); min-height: 360px;
  border: 1px solid #333; border-radius: 8px; overflow: hidden;
  background: #1e1e1e; width: 100%;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
}
/* Pantalla completa: ocupa todo el viewport por encima del panel */
.vps-term.fullscreen {
  position: fixed; inset: 0; z-index: 300;
  height: 100dvh; min-height: 0; border-radius: 0; border: none;
}

/* Pestañas tipo VS Code (planas, acento superior en la activa) */
.vps-tabs {
  display: flex; gap: 0; padding: 0; background: #252526;
  overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  border-bottom: 1px solid #333;
}
.vps-tab {
  display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto;
  padding: 9px 14px; background: #2d2d2d; color: #969696;
  border: none; border-right: 1px solid #252526;
  border-top: 2px solid transparent;
  font-size: 12.5px; cursor: pointer; max-width: 220px;
  transition: background .12s, color .12s;
}
.vps-tab:hover { background: #333; color: #cccccc; }
.vps-tab.active { background: #1e1e1e; color: #ffffff; border-top-color: #007acc; }
.vps-tab-lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vps-tab-lbl em { color: #cca700; font-style: normal; font-size: 11px; opacity: .9; }
.vps-tab-lbl em.st-esperando { color: #f48771; }
/* Semáforo por sesión: libre gris · corriendo azul · procesando ámbar (pulsa) ·
   esperando confirmación rojo (parpadea). El borde superior de la tab acompaña. */
.vps-tab.st-corriendo  { border-top-color: #3b8eea; }
.vps-tab.st-procesando { border-top-color: #cca700; }
.vps-tab.st-esperando  { border-top-color: #f14c4c; }
.vps-tab-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto;
  background: #4a4a4a; /* libre */
}
.vps-tab-dot.st-corriendo  { background: #3b8eea; }
.vps-tab-dot.st-procesando { background: #cca700; animation: vt-pulse 1s ease-in-out infinite; }
.vps-tab-dot.st-esperando  { background: #f14c4c; animation: vt-blink .7s step-end infinite; }
@keyframes vt-pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
@keyframes vt-blink { 0%,100% { opacity: 1; } 50% { opacity: .15; } }
@media (prefers-reduced-motion: reduce) {
  .vps-tab-dot.st-procesando, .vps-tab-dot.st-esperando { animation: none; }
}

/* Barra de búsqueda en buffer (Ctrl+Shift+F) */
.vps-search {
  display: flex; gap: 6px; align-items: center;
  padding: 6px 10px; background: #252526; border-bottom: 1px solid #333;
}
.vps-search input {
  flex: 1; min-width: 0; background: #1e1e1e; color: #d4d4d4;
  border: 1px solid #3c3c3c; border-radius: 4px; padding: 5px 9px;
  font-size: 13px; outline: none;
}
.vps-search input:focus { border-color: #007acc; }
.vps-tab-x {
  border: none; background: transparent; color: #7a7a7a; cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 2px; border-radius: 4px;
}
.vps-tab-x:hover { color: #f48771; background: rgba(255,255,255,.08); }
.vps-tab-add {
  flex: 0 0 auto; padding: 9px 13px; background: transparent; color: #969696;
  border: none; cursor: pointer; font-size: 15px;
}
.vps-tab-add:hover { background: #333; color: #fff; }

.vps-term-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 12px; background: #252526; border-bottom: 1px solid #333;
  flex-wrap: wrap; user-select: none;
}
.vps-term-title {
  color: #cccccc; font-size: 12.5px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
}
.vps-term-title::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: #23d18b; box-shadow: 0 0 6px #23d18b;
}
.vps-term-hint { color: #808080; font-size: 12px; }
.vps-term-hint b { color: #cccccc; }
.vps-term-hint code { color: #4ec9b0; background: #1e1e1e; padding: 1px 5px; border-radius: 4px; }
.vps-term-btns { margin-left: auto; display: flex; gap: 5px; flex-wrap: wrap; }
.vps-term-bar .btn-ghost {
  border-color: #3a3a3a; color: #cccccc; background: #2d2d2d;
  padding: 5px 10px; border-radius: 6px; transition: background .12s, border-color .12s;
}
.vps-term-bar .btn-ghost:hover { background: #37373d; border-color: #4a4a4a; color: #fff; }
#vt-full { border-color: #0e639c; color: #fff; background: #0e639c; }
#vt-full:hover { background: #1177bb; border-color: #1177bb; }
.vps-theme {
  background: #2d2d2d; color: #cccccc; border: 1px solid #3a3a3a;
  border-radius: 6px; padding: 5px 8px; font-size: 12px; cursor: pointer; outline: none;
}
.vps-theme:hover { border-color: #4a4a4a; background: #37373d; }
.vps-theme:focus { border-color: #007acc; }
.vps-term-screen { flex: 1; min-height: 0; padding: 8px 6px 8px 10px; background: #1e1e1e; }
.vps-term-screen .xterm { height: 100%; }

/* Menú contextual (clic derecho) tipo editor */
.vps-ctx {
  position: fixed; z-index: 400; min-width: 190px; padding: 5px;
  background: #252526; border: 1px solid #454545; border-radius: 6px;
  box-shadow: 0 6px 22px rgba(0,0,0,.5); font-size: 13px;
}
.vps-ctx[hidden] { display: none; }
.vps-ctx-item {
  display: flex; justify-content: space-between; align-items: center; gap: 20px;
  width: 100%; text-align: left; padding: 6px 10px; border: none;
  background: transparent; color: #cccccc; border-radius: 4px; cursor: pointer;
}
.vps-ctx-item:hover { background: #04395e; color: #fff; }
.vps-ctx-item.disabled { color: #6a6a6a; pointer-events: none; }
.vps-ctx-key { color: #8a8a8a; font-size: 11px; }
.vps-ctx-sep { height: 1px; background: #3a3a3a; margin: 5px 6px; }

/* Barra de teclas especiales (scroll horizontal en móvil) */
.vps-keys {
  display: flex; gap: 6px; padding: 7px 10px; overflow-x: auto;
  background: #252526; border-top: 1px solid #333;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin;
}
.vt-key {
  flex: 0 0 auto; min-width: 40px; padding: 7px 10px;
  background: #2d2d2d; color: #cccccc; border: 1px solid #3a3a3a;
  border-radius: 6px; font-size: 14px; font-family: ui-monospace, Menlo, monospace;
  cursor: pointer; user-select: none; touch-action: manipulation;
}
.vt-key:hover { background: #37373d; }
.vt-key:active { background: #094771; transform: translateY(1px); }

/* Línea de comando rápida */
.vps-cmd {
  display: flex; gap: 8px; padding: 8px 10px;
  background: #252526; border-top: 1px solid #333;
}
.vps-cmd-in {
  flex: 1; min-width: 0; padding: 10px 12px;
  background: #1e1e1e; color: #d4d4d4; border: 1px solid #3a3a3a; border-radius: 6px;
  font-family: ui-monospace, Menlo, monospace; font-size: 14px; outline: none;
}
.vps-cmd-in:focus { border-color: #007acc; box-shadow: 0 0 0 1px #007acc; }
.vps-cmd-send {
  flex: 0 0 auto; padding: 10px 16px; border: none; border-radius: 6px;
  background: #0e639c; color: #fff; font-weight: 600; font-size: 14px; cursor: pointer;
}
.vps-cmd-send:hover { background: #1177bb; }
.vps-cmd-send:active { background: #0e639c; }

@media (max-width: 640px) {
  .vps-term { height: calc(100dvh - 150px); }
  .vps-term-hint { display: none; }
  .vps-term-title { font-size: 12px; }
}
