/* =========================================================================
   Plassol · Orquestador-Operador MCP — Design System (light / SaaS)
   Rediseño claro y premium. Mantiene las clases/IDs que usa app.js:
   .msg(.user/.bot/.system) · .msg-tools · .tool-chip · .typing · #chat-*
   ========================================================================= */

:root {
  /* Neutrales */
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #FBFCFE;
  --surface-3: #F3F5F9;
  --border: #E7EAF0;
  --border-strong: #D7DCE5;

  /* Texto */
  --text: #0F1A2A;
  --text-muted: #5A6577;
  --text-subtle: #8A93A4;

  /* Marca: emerald (Plassol / plásticos), fresco en claro */
  --primary: #0E9F6E;
  --primary-600: #0B8A5F;
  --primary-700: #097A53;
  --primary-soft: #E6F8F0;
  --primary-soft-2: #D2F1E4;
  --on-primary: #FFFFFF;

  /* Acento IA (indigo/violeta) para el cerebro */
  --ai-1: #6366F1;
  --ai-2: #8B5CF6;
  --ai-soft: #EEF0FE;

  /* Semánticos */
  --green: #16A34A; --green-soft: #E7F6EC;
  --amber: #E8930C; --amber-soft: #FDF3E3;
  --red: #E5484D;   --red-soft: #FCEBEC;
  --blue: #2563EB;  --blue-soft: #E8EFFE;

  /* Radios / sombras / motion */
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-xl: 22px; --r-full: 999px;
  --sh-xs: 0 1px 2px rgba(16,29,53,.05);
  --sh-sm: 0 1px 3px rgba(16,29,53,.07), 0 1px 2px rgba(16,29,53,.04);
  --sh-md: 0 6px 18px -4px rgba(16,29,53,.10), 0 2px 6px rgba(16,29,53,.05);
  --sh-lg: 0 20px 45px -12px rgba(16,29,53,.18), 0 6px 14px rgba(16,29,53,.07);
  --ring: 0 0 0 3px rgba(14,159,110,.20);
  --dur: 180ms; --ease: cubic-bezier(.16,1,.3,1);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --sidebar-w: 256px;
  --topbar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: var(--r-sm); }
::selection { background: var(--primary-soft-2); color: var(--primary-700); }
.mono-num { font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* Scrollbar sutil */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #D3D9E3; border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #BCC4D1; background-clip: content-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* =========================================================================
   APP SHELL
   ========================================================================= */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

/* ---- Sidebar ---- */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
  padding: 18px 14px; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 16px; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--primary) 0%, #14B981 100%);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 1.1rem;
  box-shadow: 0 6px 14px -4px rgba(14,159,110,.55);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text .name { font-weight: 700; font-size: 1.02rem; letter-spacing: -.01em; }
.brand-text .sub { font-size: .68rem; color: var(--text-subtle); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: .66rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--text-subtle); padding: 12px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: var(--r-md);
  color: var(--text-muted); font-size: .9rem; font-weight: 500; cursor: pointer; position: relative;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: .85; }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-700); font-weight: 600; }
.nav-item.active svg { opacity: 1; }
.nav-item .badge { margin-left: auto; font-size: .62rem; font-weight: 700; padding: 2px 7px; border-radius: var(--r-full); background: var(--ai-soft); color: var(--ai-1); }
.sidebar-spacer { flex: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.role-pill {
  display: inline-flex; align-items: center; gap: 7px; align-self: flex-start;
  font-size: .72rem; font-weight: 600; color: var(--primary-700);
  background: var(--primary-soft); padding: 5px 10px; border-radius: var(--r-full);
}
.role-pill .d { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px rgba(14,159,110,.18); }
.sidebar-foot .switch { font-size: .8rem; color: var(--text-muted); padding: 7px 10px; border-radius: var(--r-md); display: flex; align-items: center; gap: 9px; }
.sidebar-foot .switch:hover { background: var(--surface-3); color: var(--text); }
.sidebar-foot .switch svg { width: 16px; height: 16px; }

/* ---- Main column ---- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); flex: 0 0 auto;
  background: rgba(255,255,255,.82); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px; padding: 0 28px; position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { font-size: .74rem; color: var(--text-subtle); font-weight: 500; }
.topbar .title { font-size: 1.06rem; font-weight: 700; letter-spacing: -.01em; }
.topbar .head-left { display: flex; flex-direction: column; line-height: 1.2; }
.topbar .head-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px; font-size: .76rem; font-weight: 600; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border); padding: 6px 12px; border-radius: var(--r-full); box-shadow: var(--sh-xs);
}
.status-pill .pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .45; } }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--r-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-muted); display: grid; place-items: center; cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); box-shadow: var(--sh-xs); }
.icon-btn svg { width: 18px; height: 18px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto; background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; }

.content { padding: 26px 28px 40px; flex: 1; min-width: 0; }
.page-intro { margin-bottom: 20px; }
.page-intro h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.025em; }
.page-intro p { color: var(--text-muted); font-size: .95rem; margin-top: 5px; max-width: 760px; }

/* =========================================================================
   KPI STAT CARDS
   ========================================================================= */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; box-shadow: var(--sh-sm); position: relative; overflow: hidden;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }
.stat-top { display: flex; align-items: center; gap: 10px; }
.stat-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: 0 0 auto; }
.stat-ico svg { width: 18px; height: 18px; }
.stat-ico.em { background: var(--primary-soft); color: var(--primary-700); }
.stat-ico.bl { background: var(--blue-soft); color: var(--blue); }
.stat-ico.vi { background: var(--ai-soft); color: var(--ai-1); }
.stat-name { font-size: .82rem; color: var(--text-muted); font-weight: 600; }
.stat-val { font-size: 2.1rem; font-weight: 800; letter-spacing: -.03em; margin-top: 12px; display: flex; align-items: baseline; gap: 3px; }
.stat-unit { font-size: 1rem; font-weight: 700; color: var(--text-subtle); }
.stat-desc { font-size: .78rem; color: var(--text-subtle); margin-top: 4px; line-height: 1.45; }
.stat-trend { position: absolute; top: 16px; right: 16px; font-size: .72rem; font-weight: 700; color: var(--green); background: var(--green-soft); padding: 3px 8px; border-radius: var(--r-full); }

/* =========================================================================
   LAYOUT principal: chat + panel derecho
   ========================================================================= */
.workspace { display: grid; grid-template-columns: minmax(0,1.65fr) minmax(300px,1fr); gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-sm); }
.card-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.card-title { font-size: .98rem; font-weight: 700; letter-spacing: -.01em; }
.card-sub { font-size: .76rem; color: var(--text-subtle); }

/* =========================================================================
   CHAT (asistente IA)
   ========================================================================= */
.chat { display: flex; flex-direction: column; height: calc(100vh - var(--topbar-h) - 66px); min-height: 520px; overflow: hidden; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--border);
  background:
    radial-gradient(120% 120% at 0% 0%, rgba(99,102,241,.06), transparent 60%),
    radial-gradient(120% 120% at 100% 0%, rgba(14,159,110,.06), transparent 60%);
}
.chat-avatar {
  width: 42px; height: 42px; border-radius: 13px; flex: 0 0 auto;
  background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); color: #fff;
  display: grid; place-items: center; box-shadow: 0 6px 16px -5px rgba(109,94,246,.6);
}
.chat-avatar svg { width: 22px; height: 22px; }
.chat-head-meta { flex: 1; min-width: 0; }
.chat-head-meta .t { font-size: .98rem; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.chat-head-meta .t .on { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.chat-head-meta .s { font-size: .76rem; color: var(--text-muted); margin-top: 1px; }
.chat-channel { font-size: .7rem; font-weight: 600; color: var(--text-muted); background: var(--surface-3); border: 1px solid var(--border); padding: 5px 10px; border-radius: var(--r-full); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.chat-log { flex: 1; overflow-y: auto; padding: 20px 18px; display: flex; flex-direction: column; gap: 14px; background: linear-gradient(180deg, var(--surface-2), var(--surface)); }

/* Burbujas (clases que produce app.js: .msg.user / .msg.bot / .msg.system) */
.msg { max-width: 78%; font-size: .9rem; line-height: 1.5; white-space: normal; word-wrap: break-word; overflow-wrap: anywhere; animation: msgIn 240ms var(--ease); }
.msg-text { white-space: pre-wrap; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, var(--primary), var(--primary-600)); color: #fff; padding: 11px 15px; border-radius: 16px 16px 4px 16px; box-shadow: 0 6px 16px -8px rgba(14,159,110,.6); }
.msg.bot { align-self: flex-start; background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 12px 15px; border-radius: 16px 16px 16px 4px; box-shadow: var(--sh-xs); }
.msg.system { align-self: center; max-width: 92%; text-align: center; font-size: .76rem; color: var(--text-subtle); background: var(--surface-3); border: 1px solid var(--border); padding: 7px 14px; border-radius: var(--r-full); }

/* Tool chips */
.msg-tools { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border); }
.tool-chip { font-size: .68rem; font-weight: 600; color: var(--ai-1); background: var(--ai-soft); border: 1px solid #DDE0FB; padding: 3px 9px; border-radius: var(--r-full); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Typing */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 2px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-subtle); animation: typing 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes typing { 0%,60%,100% { transform: translateY(0); opacity: .4; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Sugerencias */
.chat-suggest { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 18px 0; }
.suggest-btn { font-size: .8rem; font-weight: 500; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); padding: 7px 13px; border-radius: var(--r-full); cursor: pointer; transition: all var(--dur) var(--ease); }
.suggest-btn:hover { color: var(--primary-700); border-color: var(--primary); background: var(--primary-soft); transform: translateY(-1px); }

/* Form de entrada */
.chat-form { display: flex; align-items: flex-end; gap: 10px; padding: 14px 18px 16px; border-top: 1px solid var(--border); background: var(--surface); }
.chat-input { flex: 1; font-family: inherit; font-size: .92rem; color: var(--text); padding: 12px 16px; border: 1px solid var(--border-strong); border-radius: 14px; resize: none; line-height: 1.45; max-height: 140px; background: var(--surface-2); transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease); }
.chat-input::placeholder { color: var(--text-subtle); }
.chat-input:focus { outline: none; border-color: var(--primary); background: var(--surface); box-shadow: var(--ring); }
.chat-send { flex: 0 0 auto; height: 46px; width: 46px; border-radius: 13px; border: none; cursor: pointer; background: linear-gradient(135deg, var(--primary), var(--primary-600)); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 18px -8px rgba(14,159,110,.7); transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease); }
.chat-send svg { width: 20px; height: 20px; }
.chat-send:hover { transform: translateY(-1px); filter: brightness(1.05); }
.chat-send:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* =========================================================================
   PANEL DERECHO: semáforo + KPIs
   ========================================================================= */
.side-col { display: flex; flex-direction: column; gap: 16px; }
.semaforo { padding: 16px 18px 18px; }
.semaforo .lbl { font-size: .8rem; color: var(--text-muted); font-weight: 600; margin-bottom: 14px; }
.sem-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.sem-box { text-align: center; padding: 14px 6px; border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface-2); }
.sem-box .top { display: flex; align-items: center; justify-content: center; gap: 6px; font-size: .72rem; color: var(--text-muted); font-weight: 600; }
.sem-num { font-size: 1.9rem; font-weight: 800; letter-spacing: -.03em; margin-top: 6px; }
.sdot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.sdot.g { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.sdot.a { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.sdot.r { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.sem-num.g { color: var(--green); } .sem-num.a { color: var(--amber); } .sem-num.r { color: var(--red); }

.mini-kpis { display: flex; flex-direction: column; }
.mini-kpi { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.mini-kpi:last-child { border-bottom: none; }
.mini-kpi .mk-l { font-size: .82rem; color: var(--text-muted); }
.mini-kpi .mk-l small { display: block; color: var(--text-subtle); font-size: .7rem; margin-top: 2px; }
.mini-kpi .mk-v { font-size: 1.15rem; font-weight: 800; letter-spacing: -.02em; }

.note { font-size: .74rem; color: var(--text-subtle); line-height: 1.5; padding: 14px 18px; }
.note code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; font-size: .92em; }

/* =========================================================================
   MARKDOWN renderizado dentro de las burbujas del bot (.msg-md)
   ========================================================================= */
.msg-md { font-size: .9rem; line-height: 1.55; }
.msg-md > :first-child { margin-top: 0; }
.msg-md > :last-child { margin-bottom: 0; }
.msg-md p { margin: 8px 0; }
.msg-md h1, .msg-md h2, .msg-md h3, .msg-md h4 { font-weight: 700; letter-spacing: -.01em; line-height: 1.25; margin: 14px 0 7px; }
.msg-md h1 { font-size: 1.05rem; }
.msg-md h2 { font-size: 1rem; }
.msg-md h3 { font-size: .94rem; }
.msg-md h4 { font-size: .88rem; color: var(--text-muted); }
.msg-md ul, .msg-md ol { margin: 8px 0; padding-left: 20px; }
.msg-md li { margin: 3px 0; }
.msg-md li::marker { color: var(--primary); }
.msg-md strong { font-weight: 700; }
.msg-md a { color: var(--primary-700); text-decoration: underline; text-underline-offset: 2px; }
.msg-md code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em; background: var(--surface-3); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }
.msg-md pre { background: var(--surface-3); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; overflow-x: auto; margin: 10px 0; }
.msg-md pre code { background: none; border: none; padding: 0; font-size: .82em; line-height: 1.5; }
.msg-md blockquote { margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--primary); background: var(--primary-soft); border-radius: 0 8px 8px 0; color: var(--text-muted); }
.msg-md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.md-table { overflow-x: auto; margin: 10px 0; border: 1px solid var(--border); border-radius: 10px; }
.msg-md table { border-collapse: collapse; width: 100%; font-size: .84rem; }
.msg-md th, .msg-md td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.msg-md thead th { background: var(--surface-3); font-weight: 700; color: var(--text); }
.msg-md tbody tr:last-child td { border-bottom: none; }
.msg-md tbody tr:nth-child(even) td { background: var(--surface-2); }

/* =========================================================================
   RESPONSIVE
   ========================================================================= */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .chat { height: 70vh; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; border-right: none; border-bottom: 1px solid var(--border); padding: 12px 16px; gap: 4px; }
  .brand { padding: 0 12px 0 0; }
  .nav-group, .nav-label, .sidebar-spacer { display: none; }
  .sidebar-foot { border-top: none; padding-top: 0; margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .stats { grid-template-columns: 1fr; }
  .content { padding: 18px 16px 32px; }
  .topbar { padding: 0 16px; }
}

/* =========================================================================
   VISTAS DEDICADAS (SPA): inventario · cartera · copiloto · auditoría · cotizaciones
   ========================================================================= */
.view[hidden] { display: none; }
.view-header { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.view-header h1 { font-size: 1.5rem; font-weight: 800; letter-spacing: -.025em; }
.view-header p { color: var(--text-muted); font-size: .92rem; margin-top: 4px; max-width: 720px; }
.view-actions { margin-left: auto; display: flex; gap: 8px; flex: 0 0 auto; }

.btn-primary { font-family: inherit; font-size: .85rem; font-weight: 600; color: #fff; cursor: pointer;
  background: linear-gradient(135deg, var(--primary), var(--primary-600)); border: none; padding: 9px 16px; border-radius: 10px;
  box-shadow: 0 8px 18px -8px rgba(14,159,110,.7); transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease); }
.btn-primary:hover { transform: translateY(-1px); filter: brightness(1.05); }
.btn-ghost { font-family: inherit; font-size: .85rem; font-weight: 600; color: var(--text-muted); cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); padding: 8px 14px; border-radius: 10px; transition: all var(--dur) var(--ease); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-strong); box-shadow: var(--sh-xs); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-sm); padding: 18px; }
.sumchips { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.sumchip { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-xs);
  padding: 10px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 110px; }
.sumchip .sc-l { font-size: .72rem; color: var(--text-subtle); font-weight: 600; }
.sumchip .sc-v { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

.badge { display: inline-flex; align-items: center; font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: var(--r-full); }
.badge.g { color: var(--green); background: var(--green-soft); }
.badge.a { color: var(--amber); background: var(--amber-soft); }
.badge.r { color: var(--red); background: var(--red-soft); }
.badge.vi { color: var(--ai-1); background: var(--ai-soft); }
.badge.muted { color: var(--text-muted); background: var(--surface-3); }
.chip-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .72rem; font-weight: 600; color: var(--ai-1);
  background: var(--ai-soft); border: 1px solid #DDE0FB; padding: 3px 8px; border-radius: var(--r-full); }

.dtable-wrap { overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: .86rem; }
.dtable th { text-align: left; font-weight: 700; color: var(--text-muted); font-size: .74rem; text-transform: uppercase; letter-spacing: .04em;
  padding: 0 14px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.dtable td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
.dtable tbody tr:last-child td { border-bottom: none; }
.dtable tbody tr:hover td { background: var(--surface-2); }
.dtable .num, .dtable th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em; }
.muted { color: var(--text-subtle); }

.loading { display: flex; align-items: center; gap: 10px; color: var(--text-muted); font-size: .9rem; padding: 30px 4px; }
.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--primary); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { text-align: center; color: var(--text-muted); padding: 48px 20px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-lg); }
.empty-ic { font-size: 2rem; margin-bottom: 8px; }
.empty p { font-weight: 600; color: var(--text); }
.empty small { color: var(--text-subtle); }
.empty a { color: var(--primary-700); text-decoration: underline; }

.cart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.cart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-sm); padding: 18px; }
.cart-top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.cart-name { font-weight: 700; font-size: .98rem; flex: 1; min-width: 0; }
.cart-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cm-l { font-size: .74rem; color: var(--text-subtle); }
.cm-v { font-size: 1rem; font-weight: 700; margin-top: 2px; }
.cart-alert { margin-top: 14px; font-size: .8rem; padding: 9px 12px; border-radius: var(--r-md); line-height: 1.4; }
.cart-alert.r { background: var(--red-soft); color: #B42318; }
.cart-alert.a { background: var(--amber-soft); color: #93600A; }

.cop-grid { display: grid; grid-template-columns: 280px 1fr; gap: 16px; align-items: start; }
.cop-trm-l { font-size: .8rem; color: var(--text-muted); font-weight: 600; }
.cop-trm-v { font-size: 2.4rem; font-weight: 800; letter-spacing: -.03em; margin: 6px 0 10px; }
.chips-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.cop-form { display: flex; gap: 10px; align-items: flex-end; }
.cop-form .chat-input { flex: 1; }
.cop-out { margin-top: 14px; }
.cop-answer { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; }

@media (max-width: 760px) {
  .cop-grid { grid-template-columns: 1fr; }
  .view-header { flex-direction: column; }
  .view-actions { margin-left: 0; }
}

/* =========================================================================
   CONSOLA DEL AGENTE (trazas reales)
   ========================================================================= */
.agent-console { margin-top: 16px; }
.ac-mode { font-size: .72rem; font-weight: 700; padding: 3px 10px; border-radius: var(--r-full); background: var(--surface-3); color: var(--text-muted); }
.ac-mode.real { background: var(--ai-soft); color: var(--ai-1); }
.ac-mode.offline { background: var(--amber-soft); color: var(--amber); }
.ac-stats { margin-left: auto; font-size: .76rem; color: var(--text-subtle); }
.ac-body { padding: 6px 8px; max-height: 380px; overflow-y: auto; }
.ac-empty { color: var(--text-subtle); font-size: .85rem; line-height: 1.55; padding: 16px; }
.ac-step { display: grid; grid-template-columns: 24px 62px 1fr; align-items: start; gap: 8px; padding: 9px 8px; border-radius: var(--r-md); }
.ac-step + .ac-step { border-top: 1px solid var(--border); }
.ac-step.sub { margin-left: 16px; }
.ac-ic { font-size: .92rem; line-height: 1.45; text-align: center; }
.ac-tcol { font-size: .68rem; color: var(--text-subtle); padding-top: 3px; font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.ac-main { min-width: 0; }
.ac-label { display: block; font-size: .86rem; color: var(--text); line-height: 1.4; }
.ac-label b { font-weight: 700; }
.ac-detail { display: block; font-size: .76rem; color: var(--text-muted); margin-top: 3px; word-break: break-word; line-height: 1.45; }
.ac-detail code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.ac-step.api { background: rgba(99,102,241,.045); }
.ac-step.api .ac-label b { color: var(--ai-1); }
.ac-step.final .ac-label, .ac-step.tool_result .ac-label b { color: var(--primary-700); }

/* =========================================================================
   CABINA DE MANDO (Consola) — topología en vivo
   ========================================================================= */
.ckpt-live { display: inline-flex; align-items: center; gap: 7px; font-size: .72rem; font-weight: 700; letter-spacing: .05em; color: var(--text-muted); background: var(--surface-3); border: 1px solid var(--border); padding: 6px 12px; border-radius: var(--r-full); }
.ckpt-live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-subtle); }
.ckpt-live.on { color: var(--green); background: var(--green-soft); border-color: transparent; }
.ckpt-live.on .dot { background: var(--green); box-shadow: 0 0 0 3px rgba(22,163,74,.2); animation: pulse 1.6s infinite; }

.ckpt-metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.ckpt-metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--sh-sm); padding: 16px 18px; }
.ckpt-metric .mv { font-size: 1.9rem; font-weight: 800; letter-spacing: -.03em; }
.ckpt-metric .ml { font-size: .78rem; color: var(--text-subtle); font-weight: 600; margin-top: 2px; }

.ckpt-grid { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; align-items: stretch; }
.ckpt-stage { padding: 14px; display: flex; align-items: center; justify-content: center; background: radial-gradient(120% 90% at 50% 0%, rgba(99,102,241,.06), transparent 60%), var(--surface); overflow: hidden; }
.ckpt-svg { width: 100%; height: auto; display: block; }

.ckpt-line { fill: none; stroke: var(--border-strong); stroke-width: 2; opacity: .55; }
.ckpt-line.hot { stroke: var(--ai-1); opacity: 1; stroke-width: 2.5; stroke-dasharray: 7 7; animation: ckptflow .9s linear; }
.ckpt-line.sys.hot { stroke: var(--primary); }
@keyframes ckptflow { from { stroke-dashoffset: 28; } to { stroke-dashoffset: 0; } }

.ckpt-node { display: flex; align-items: center; gap: 11px; height: 100%; box-sizing: border-box; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 0 16px; box-shadow: var(--sh-sm); transition: box-shadow .2s, border-color .2s, transform .2s; }
.ckpt-node .led { width: 11px; height: 11px; border-radius: 50%; background: var(--border-strong); flex: 0 0 auto; transition: background .2s; }
.ckpt-node .ic { font-size: 1.6rem; flex: 0 0 auto; }
.ckpt-node .lbl { font-size: 1rem; font-weight: 600; line-height: 1.2; flex: 1; min-width: 0; }
.ckpt-node .cnt { font-size: 1rem; font-weight: 800; color: var(--text-subtle); flex: 0 0 auto; }
.ckpt-node.hot { border-color: var(--ai-1); box-shadow: 0 0 0 3px var(--ai-soft), var(--sh-md); transform: translateY(-1px); }
.ckpt-node.hot .led { background: var(--ai-1); box-shadow: 0 0 0 3px var(--ai-soft); }
.ckpt-node.hot .cnt { color: var(--ai-1); }

.ckpt-hub { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; box-sizing: border-box; border-radius: 26px; color: #fff; text-align: center; gap: 2px;
  background: linear-gradient(135deg, var(--ai-1), var(--ai-2)); box-shadow: 0 14px 34px -10px rgba(109,94,246,.65); position: relative; }
.ckpt-hub::after { content: ''; position: absolute; inset: -6px; border-radius: 32px; border: 2px solid rgba(109,94,246,.35); animation: hubring 2.4s ease-out infinite; }
@keyframes hubring { 0% { transform: scale(.92); opacity: .7; } 100% { transform: scale(1.12); opacity: 0; } }
.ckpt-hub .hub-core { line-height: 0; }
.ckpt-hub .hub-brain { width: 54px; height: 54px; display: block; filter: drop-shadow(0 2px 6px rgba(0,0,0,.25)); }
.ckpt-hub .hub-t { font-size: .92rem; font-weight: 800; letter-spacing: .05em; margin-top: 8px; }
.ckpt-hub .hub-s { font-size: .72rem; opacity: .85; margin-top: 1px; }
.ckpt-hub.hot { box-shadow: 0 0 0 4px rgba(109,94,246,.3), 0 16px 40px -8px rgba(109,94,246,.85); }

.ckpt-feedwrap { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.ckpt-feedhead { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: .8rem; font-weight: 700; color: var(--text-muted); }
.ckpt-feed { flex: 1; overflow-y: auto; max-height: 560px; padding: 4px 0; }
.fe { display: flex; flex-direction: column; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--surface-3); animation: msgIn .25s var(--ease); }
.fe-top { display: flex; align-items: center; gap: 8px; }
.fe-t { font-size: .72rem; color: var(--text-subtle); }
.fe-ic { font-size: .98rem; }
.fe-x { font-size: .88rem; color: var(--text); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fe-x b { font-weight: 700; }
.fe.api { background: rgba(99,102,241,.05); }
.fe.api .fe-x b { color: var(--ai-1); }
.fe.final .fe-x { color: var(--primary-700); font-weight: 600; }
.cbadge { font-size: .62rem; font-weight: 700; padding: 2px 7px; border-radius: var(--r-full); flex: 0 0 auto; background: var(--surface-3); color: var(--text-muted); }
.cbadge.wa { background: var(--green-soft); color: var(--green); }
.cbadge.intra { background: var(--ai-soft); color: var(--ai-1); }
.cbadge.mcp { background: var(--blue-soft); color: var(--blue); }

@media (max-width: 980px) {
  .ckpt-grid { grid-template-columns: 1fr; }
  .ckpt-metrics { grid-template-columns: repeat(2, 1fr); }
}
