/* ai-agents.css — AI Operations Center de Mind Miami.
 *
 * TODO va bajo .aiw a propósito: este módulo tiene una densidad y una
 * jerarquía propias (tablas, rails, gráficas) y si sus estilos se escapan
 * contaminan los otros dieciocho portales. Ningún selector de este archivo
 * puede aplicar fuera de .aiw.
 *
 * El acento se toma de var(--ws-accent) para que brand-theme.jsx y los temas
 * por cliente sigan funcionando. La ÚNICA excepción es Neuron: su azul es
 * suyo en todos los workspaces, porque es la identidad del producto y no la
 * del cliente.
 */

.aiw {
  --ai-purple: #8B5CF6;
  --ai-blue:   #3B82F6;
  --ai-green:  #22C55E;
  --ai-amber:  #F59E0B;
  --ai-red:    #EF4444;
  /* Azul oficial de Neuron — NO sigue el acento del cliente. */
  --ai-neuron:      #22B5F5;
  --ai-neuron-deep: #0A78C8;
  --ai-neuron-dark: #16263B;

  --ai-r-btn: 8px;
  --ai-r-input: 10px;
  --ai-r-card: 15px;
  --ai-r-panel: 18px;

  --ai-shadow: 0 12px 32px rgba(0,0,0,.22), 0 0 0 1px rgba(255,255,255,.02);
  --ai-glow: 0 0 0 1px var(--ws-accent-soft), 0 0 22px -6px var(--ws-accent);

  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  height: 100%;
  min-height: 0;
  background: var(--ws-bg-0);
  color: var(--ws-fg-1);
  font-family: var(--ws-font);
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.aiw-side {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--ws-bg-1);
  border-right: 1px solid var(--ws-border);
}
.aiw-side-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--ws-border);
}
.aiw-side-brand b {
  font-family: var(--ws-font-display); font-size: 13.5px; font-weight: 700;
  letter-spacing: -0.2px; display: block; line-height: 1.15;
}
.aiw-side-brand span {
  font-size: 10px; color: var(--ws-fg-4); letter-spacing: .4px;
}
.aiw-nav { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 8px; }
.aiw-nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 11px; margin-bottom: 2px;
  border: none; border-left: 3px solid transparent; border-radius: 0 10px 10px 0;
  background: transparent; color: var(--ws-fg-3);
  font-family: var(--ws-font); font-size: 12.5px; font-weight: 600;
  cursor: pointer; text-align: left;
  transition: background .18s ease, color .18s ease, border-color .18s ease;
}
.aiw-nav-item i { width: 17px; text-align: center; font-size: 13px; color: var(--ws-fg-4); transition: color .18s ease; }
.aiw-nav-item:hover { background: var(--ws-bg-2); color: var(--ws-fg-1); }
.aiw-nav-item.on {
  background: var(--ws-accent-soft); color: var(--ws-fg-1);
  border-left-color: var(--ws-accent);
}
.aiw-nav-item.on i { color: var(--ws-accent); }
.aiw-nav-count {
  margin-left: auto; min-width: 20px; height: 19px; padding: 0 6px;
  border-radius: 999px; background: var(--ws-bg-3); color: var(--ws-fg-2);
  font-size: 10.5px; font-weight: 800; font-variant-numeric: tabular-nums;
  display: inline-flex; align-items: center; justify-content: center;
}
.aiw-nav-count.alert { background: var(--ai-red); color: #fff; }
.aiw-side-foot { padding: 12px; border-top: 1px solid var(--ws-border); }
.aiw-side-tag {
  font-size: 8.5px; font-weight: 800; letter-spacing: 1.1px;
  color: var(--ws-fg-4); text-transform: uppercase; margin-top: 10px;
}

/* ── Topbar ──────────────────────────────────────────────────────────── */
.aiw-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.aiw-top {
  display: flex; align-items: center; gap: 10px;
  height: 66px; flex-shrink: 0; padding: 0 24px;
  border-bottom: 1px solid var(--ws-border); background: var(--ws-bg-1);
}
.aiw-search {
  display: flex; align-items: center; gap: 9px;
  flex: 1; max-width: 440px; height: 38px; padding: 0 12px;
  border-radius: var(--ai-r-input); cursor: text;
  background: var(--ws-bg-2); border: 1px solid var(--ws-border);
  color: var(--ws-fg-4); font-size: 12.5px;
  transition: border-color .16s ease;
}
.aiw-search:hover { border-color: var(--ws-border-mid); }
.aiw-kbd {
  margin-left: auto; padding: 2px 6px; border-radius: 5px;
  background: var(--ws-bg-3); border: 1px solid var(--ws-border);
  font-family: var(--ws-font-mono, 'JetBrains Mono', monospace);
  font-size: 9.5px; color: var(--ws-fg-3);
}
.aiw-body { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 22px 24px 40px; }

/* ── Cabecera de página ──────────────────────────────────────────────── */
.aiw-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.aiw-head h1 {
  margin: 0; font-family: var(--ws-font-display);
  font-size: 27px; font-weight: 700; letter-spacing: -0.7px; line-height: 1.15;
}
.aiw-head p { margin: 5px 0 0; font-size: 13px; color: var(--ws-fg-3); line-height: 1.5; }

/* ── Superficies ─────────────────────────────────────────────────────── */
.aiw-panel {
  background: var(--ws-bg-1); border: 1px solid var(--ws-border);
  border-radius: var(--ai-r-panel); padding: 16px 17px;
  min-width: 0;
}
.aiw-panel-head {
  display: flex; align-items: center; gap: 9px; margin-bottom: 13px;
}
.aiw-panel-head h2 {
  margin: 0; font-family: var(--ws-font-display);
  font-size: 14.5px; font-weight: 700; letter-spacing: -0.2px;
}
.aiw-panel-head .aiw-panel-act { margin-left: auto; }

.aiw-card {
  background: var(--ws-bg-2); border: 1px solid var(--ws-border);
  border-radius: var(--ai-r-card); padding: 13px 14px; min-width: 0;
}
.aiw-card.click { cursor: pointer; text-align: left; width: 100%; font-family: var(--ws-font); color: inherit;
  transition: border-color .16s ease, background .16s ease, transform .16s ease; }
.aiw-card.click:hover { border-color: var(--ws-border-mid); background: var(--ws-bg-3); }
.aiw-card.sel { border-color: var(--ws-accent); box-shadow: inset 3px 0 0 var(--ws-accent); }

/* ── KPI ─────────────────────────────────────────────────────────────── */
.aiw-kpi { display: flex; flex-direction: column; gap: 9px; min-height: 108px; }
.aiw-kpi-top { display: flex; align-items: center; gap: 10px; }
.aiw-kpi-ico {
  width: 38px; height: 38px; border-radius: 11px; flex-shrink: 0;
  display: grid; place-items: center; font-size: 14px;
}
.aiw-kpi-label {
  font-size: 10px; font-weight: 700; letter-spacing: .9px;
  text-transform: uppercase; color: var(--ws-fg-4);
}
.aiw-kpi-val {
  font-family: var(--ws-font-display); font-size: 28px; font-weight: 700;
  letter-spacing: -1px; line-height: 1; font-variant-numeric: tabular-nums;
}
.aiw-kpi-val.none { font-size: 22px; color: var(--ws-fg-4); letter-spacing: 0; }
.aiw-kpi-foot { display: flex; align-items: center; gap: 6px; font-size: 10.5px; color: var(--ws-fg-4); }
.aiw-delta { font-weight: 800; font-variant-numeric: tabular-nums; }
.aiw-delta.up { color: var(--ai-green); }
.aiw-delta.down { color: var(--ai-red); }

/* ── Badges de estado ────────────────────────────────────────────────── */
.aiw-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 10px; font-weight: 800; letter-spacing: .3px; white-space: nowrap;
  border: 1px solid transparent;
}
.aiw-badge i { font-size: 8px; }
.aiw-badge.active       { background: rgba(34,197,94,.14);  color: var(--ai-green);  border-color: rgba(34,197,94,.4); }
.aiw-badge.approval     { background: rgba(139,92,246,.14); color: var(--ai-purple); border-color: rgba(139,92,246,.4); }
.aiw-badge.paused       { background: rgba(245,158,11,.14); color: var(--ai-amber);  border-color: rgba(245,158,11,.4); }
.aiw-badge.warning      { background: rgba(245,158,11,.14); color: var(--ai-amber);  border-color: rgba(245,158,11,.4); }
.aiw-badge.error        { background: rgba(239,68,68,.14);  color: var(--ai-red);    border-color: rgba(239,68,68,.4); }
.aiw-badge.inactive     { background: var(--ws-bg-3);       color: var(--ws-fg-4);   border-color: var(--ws-border); }
.aiw-badge.training     { background: rgba(59,130,246,.14); color: var(--ai-blue);   border-color: rgba(59,130,246,.4); }
.aiw-badge.syncing      { background: rgba(59,130,246,.14); color: var(--ai-blue);   border-color: rgba(59,130,246,.4); }
.aiw-badge.connected    { background: rgba(34,197,94,.14);  color: var(--ai-green);  border-color: rgba(34,197,94,.4); }
.aiw-badge.disconnected { background: var(--ws-bg-3);       color: var(--ws-fg-4);   border-color: var(--ws-border); }

/* ── Tabla ───────────────────────────────────────────────────────────── */
.aiw-table-wrap { overflow-x: auto; border-radius: var(--ai-r-card); border: 1px solid var(--ws-border); }
.aiw-table { width: 100%; border-collapse: collapse; min-width: 780px; }
.aiw-table th {
  position: sticky; top: 0; z-index: 2;
  padding: 10px 13px; text-align: left; white-space: nowrap;
  background: var(--ws-bg-2); border-bottom: 1px solid var(--ws-border);
  font-size: 10px; font-weight: 700; letter-spacing: .8px;
  text-transform: uppercase; color: var(--ws-fg-4);
}
.aiw-table td {
  padding: 12px 13px; border-bottom: 1px solid var(--ws-border);
  font-size: 12.5px; vertical-align: middle; background: var(--ws-bg-1);
}
.aiw-table tr:last-child td { border-bottom: none; }
.aiw-table tbody tr { transition: background .14s ease; }
.aiw-table tbody tr:hover td { background: var(--ws-bg-2); }
.aiw-mono {
  font-family: var(--ws-font-mono, 'JetBrains Mono', monospace);
  font-size: 11px; color: var(--ws-fg-4);
}

/* ── Estados ─────────────────────────────────────────────────────────── */
.aiw-empty {
  display: flex; flex-direction: column; align-items: center; gap: 9px;
  padding: 34px 20px; text-align: center;
}
.aiw-empty h3 { margin: 0; font-family: var(--ws-font-display); font-size: 14px; font-weight: 700; }
.aiw-empty p { margin: 0; font-size: 12px; color: var(--ws-fg-3); line-height: 1.55; max-width: 380px; }
.aiw-skel {
  border-radius: 8px;
  background: linear-gradient(90deg, var(--ws-bg-2) 25%, var(--ws-bg-3) 37%, var(--ws-bg-2) 63%);
  background-size: 400% 100%;
  animation: aiwShimmer 1.5s ease infinite;
}
@keyframes aiwShimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ── Neuron ──────────────────────────────────────────────────────────── */
.aiw-neuron { position: relative; display: inline-grid; place-items: center; flex-shrink: 0; line-height: 0; }
.aiw-neuron img, .aiw-neuron svg { width: 100%; height: 100%; object-fit: contain; display: block; }
.aiw-neuron.glow::after {
  content: ''; position: absolute; inset: -14%;
  border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, rgba(34,181,245,.28), transparent 68%);
  animation: aiwBreathe 4.5s ease-in-out infinite;
}
.aiw-neuron.float { animation: aiwFloat 5.5s ease-in-out infinite; }
@keyframes aiwFloat { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
@keyframes aiwBreathe { 0%,100% { opacity: .55; } 50% { opacity: 1; } }

.aiw-neuron-hero {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 20px 18px; text-align: center;
  border-radius: var(--ai-r-panel);
  background:
    radial-gradient(120% 90% at 50% 0%, rgba(34,181,245,.16), transparent 62%),
    var(--ws-bg-1);
  border: 1px solid var(--ws-border);
}

/* ── Asistente flotante ──────────────────────────────────────────────── */
.aiw-fab {
  position: fixed; right: 22px; bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 60; width: 58px; height: 58px; padding: 6px;
  border-radius: 50%; cursor: pointer;
  background: var(--ws-bg-1); border: 1px solid var(--ws-border);
  box-shadow: var(--ai-shadow);
  transition: transform .16s ease, border-color .16s ease;
}
.aiw-fab:hover { transform: translateY(-2px); border-color: var(--ai-neuron); }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 1179px) {
  .aiw { grid-template-columns: 1fr; }
  .aiw-side {
    flex-direction: row; align-items: center; gap: 8px;
    border-right: none; border-bottom: 1px solid var(--ws-border);
    overflow-x: auto; padding: 8px 12px;
  }
  .aiw-side-brand, .aiw-side-foot { display: none; }
  .aiw-nav { display: flex; gap: 6px; padding: 0; overflow: visible; }
  .aiw-nav-item {
    width: auto; white-space: nowrap; border-left: none; border-radius: 999px;
    border: 1px solid var(--ws-border); margin: 0; padding: 8px 13px; min-height: 40px;
  }
  .aiw-nav-item.on { border-color: var(--ws-accent); }
  .aiw-top { padding: 0 14px; height: 60px; }
  .aiw-body { padding: 16px 14px 90px; }
  .aiw-head h1 { font-size: 22px; }
}
@media (max-width: 767px) {
  .aiw-search { max-width: none; }
  .aiw-kbd { display: none; }
  .aiw-fab { width: 50px; height: 50px; right: 14px; bottom: calc(76px + env(safe-area-inset-bottom)); }
}

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

/* ── Tema claro ──────────────────────────────────────────────────────── */
:root[data-theme="light"] .aiw-table td { background: var(--ws-bg-1); }
:root[data-theme="light"] .aiw-nav-item:hover { background: var(--ws-bg-2); }
