:root {
  /* Paleta cósmica heredada del login (Perseus Hub Chat v2). La fuente NO cambia
     (el usuario prefiere la actual). */
  --bg: #0a0a0f;
  --bg-sidebar: #0b0a11;
  --fg: #f2f1f7;
  --muted: #8b8a9e;
  --muted-2: #6e6c82;
  --accent: #8b5cf6;
  --accent-hover: #a855f7;
  --card: #121019;
  --card-hover: #1a1726;
  --card-2: #0e0d17; /* tarjeta de gráfico */
  --card-input: #131120;
  --border: rgba(255, 255, 255, 0.08);
  --border-soft: rgba(255, 255, 255, 0.06);
  --green: #34d399;
  --green-soft: #6ee7b7;
  --yellow: #f0a020;
  --red: #ff6b6b;
  --pill-violet: #d8b4fe;
  --pill-blue: #93b7fb;
  --grad-accent: linear-gradient(135deg, #6366f1, #a855f7 55%, #e040c0);
  --grad-send: linear-gradient(135deg, #6366f1, #8b5cf6 55%, #c026d3);
  /* Alias usados por componentes existentes (.conversation-item, etc.). */
  --text: #f2f1f7;
  --text-muted: #8b8a9e;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Animaciones del sistema cósmico (Perseus Hub Chat v2). */
@keyframes psPulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.82);
  }
}
@keyframes psGlow {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 0.85;
  }
}

* {
  box-sizing: border-box;
}

/* El atributo `hidden` debe ganar SIEMPRE: reglas de autor con `display:flex/
   grid/...` (p.ej. #login-screen, .btn) lo pisarían si no, dejando elementos
   "ocultos" visibles e interceptando clicks. (bug 2026-06-16: el overlay del
   login tapaba la app y bloqueaba los botones). */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  /* iOS Safari: el scroll exterior descolocaba/cortaba la ventana. El layout
     gestiona su propio scroll interno (transcript), así que bloqueamos el
     scroll del documento. */
  overflow: hidden;
  overscroll-behavior: none;
  /* Móvil: desactiva el doble-tap-para-zoom (que descolocaba la ventana) y el
     retardo de 350ms en los taps. Mantiene el scroll y el pinch-zoom (no
     rompemos accesibilidad como haría user-scalable=no en el viewport). */
  touch-action: manipulation;
}

#app {
  height: 100%;
}

h1 {
  margin: 0 0 0.25rem 0;
  font-size: 1.4rem;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.error {
  color: var(--red);
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

code {
  background: #0b0e13;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85em;
}

pre {
  background: #0b0e13;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem 0.8rem;
  overflow-x: auto;
  font-size: 0.8rem;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  margin: 0.5rem 0 0 0;
}

/* ─── Login screen (portada con fondo Swirl) ────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  margin: 0;
  max-width: none;
  overflow: hidden;
  /* Color base = fondo del Swirl, visible antes de que el canvas pinte. */
  background: hsl(260, 40%, 5%);
}

/* Contenedor del canvas Swirl. El propio canvas se inserta con position:fixed
   (full viewport) desde swirl.js; queda detrás del overlay. */
.content--canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.content--canvas canvas {
  display: block;
}

.login-overlay {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2.25rem;
  text-align: center;
}

.login-title {
  margin: 0;
  font-size: clamp(2.75rem, 9vw, 5.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  text-transform: none;
  text-shadow: 0 2px 40px rgba(0, 0, 0, 0.55);
}

/* Botón Google rectangular (blanco sobre el fondo oscuro). */
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.85rem 1.6rem;
  background: #fff;
  color: #1f2328;
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  transition: transform 80ms ease, box-shadow 150ms ease;
}
.btn-google:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.btn-google:active {
  transform: translateY(0);
}
.btn-google .google-g {
  width: 1.2rem;
  height: 1.2rem;
  flex: none;
}

/* ─── App layout ────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh; /* fallback */
  height: 100dvh; /* iOS: sigue la barra dinámica de Safari */
  position: relative;
  z-index: 1;
}

.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.1rem 0.85rem;
  position: relative;
  z-index: 1;
  /* overflow:hidden (no auto) → el scroll lo gestiona el hijo flexible
     (.conversation-list). Sin esto, el sidebar entero scrollea y la lista de
     Conversaciones no tiene un alto propio que repartir. */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-title {
  margin-top: 0;
}

.sidebar-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1rem 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

/* Header de Cuentas: título + botón "+" para abrir el modal de conexión. */
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.sidebar-head .sidebar-title {
  margin: 0;
}

/* Botón circular "+" / "×" (abrir/cerrar modal). */
.icon-btn {
  flex: none;
  width: 1.7rem;
  height: 1.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms;
}
.icon-btn:hover {
  border-color: var(--accent);
  background: var(--card-hover);
  color: var(--accent);
}

.provider-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

/* Cuentas conectadas — fila compacta: logo + nombre (+ counts). */
.provider-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 0.85rem;
}

.provider-item.is-connected {
  border-color: rgba(76, 217, 100, 0.3);
}

.provider-logo {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  object-fit: contain;
}

.provider-item-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.25;
}

.provider-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.provider-counts {
  font-size: 0.7rem;
}

/* Empty-state: sin cuentas conectadas → invitar a conectar la primera. */
.provider-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.85rem 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--card);
}
.provider-empty-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* ─── Connect modal (grid de plataformas con logos) ─────────────────────── */
.connect-modal {
  position: fixed;
  inset: 0;
  /* Por encima del drawer móvil (sidebar 1001 / overlay 1000): el modal de
     conexiones debe quedar SIEMPRE delante, no detrás del drawer abierto. */
  z-index: 1100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.connect-modal[hidden] {
  display: none;
}
.connect-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}
.connect-card {
  position: relative;
  z-index: 1;
  width: min(640px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.35rem 1.5rem 1.35rem;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}
.connect-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.connect-card-head .sidebar-title {
  margin: 0;
}
.connect-card-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0.4rem 0 1.1rem 0;
}
.connect-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.7rem;
}
.connect-tile {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0b0e13;
}
.connect-tile.is-connected {
  border-color: rgba(76, 217, 100, 0.35);
}
.connect-tile-top {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}
.connect-tile .provider-logo {
  width: 1.6rem;
  height: 1.6rem;
}
.connect-tile-name {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.connect-tile-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.connect-status {
  font-size: 0.74rem;
  white-space: nowrap;
}
.connect-status.connected {
  color: var(--green);
}
.connect-tile-action {
  flex: none;
}

/* ─── Chat panel ────────────────────────────────────────────────────── */
.chat {
  display: flex;
  flex-direction: column;
  height: 100vh; /* fallback */
  height: 100dvh;
  overflow: hidden;
  position: relative;
  /* El Swirl ya no es fondo de todo el chat (ahora vive dentro del input), así
     que no hace falta velo: fondo base limpio. */
  background: var(--bg);
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

/* Selector multi-cuenta: pill resumen + popover con checkboxes. */
.account-picker {
  position: relative;
  display: inline-flex;
}
.account-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.account-trigger:hover,
.account-trigger:focus-visible {
  border-color: var(--accent, #4285f4);
  outline: none;
}
.account-trigger-icon {
  font-size: 0.7rem;
  opacity: 0.8;
}
.account-trigger-label {
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-popover {
  position: absolute;
  top: calc(100% + 0.4rem);
  right: 0;
  z-index: 40;
  width: min(22rem, 84vw);
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  background: var(--card, #1b1b1f);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  padding: 0.5rem;
  gap: 0.45rem;
}
.account-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.account-popover-title {
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted, #9aa0a6);
}
.account-clear {
  background: transparent;
  border: none;
  color: var(--accent, #4285f4);
  font-size: 0.74rem;
  cursor: pointer;
  padding: 0.1rem 0.2rem;
}
.account-clear:hover {
  text-decoration: underline;
}
.account-filter {
  background: var(--bg, #121214);
  color: var(--fg, #eee);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
  width: 100%;
}
.account-filter:focus-visible {
  border-color: var(--accent, #4285f4);
  outline: none;
}
.account-list {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
}
.account-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.45rem;
  border-radius: 7px;
  cursor: pointer;
}
.account-row:hover {
  background: rgba(255, 255, 255, 0.05);
}
.account-row-check {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent, #4285f4);
  cursor: pointer;
}
.account-row-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.account-row-name {
  font-size: 0.84rem;
  color: var(--fg, #eee);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-row-id {
  font-size: 0.7rem;
  color: var(--text-muted, #9aa0a6);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-row-channel {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.15rem 0.4rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}
.account-row-channel .provider-logo {
  width: 0.95rem;
  height: 0.95rem;
}
.account-row-channel-name {
  font-size: 0.7rem;
  color: var(--text-muted, #c4c7cc);
  white-space: nowrap;
}
.account-row-empty {
  padding: 0.6rem 0.45rem;
  font-size: 0.8rem;
  color: var(--text-muted, #9aa0a6);
  text-align: center;
}

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.msg {
  max-width: 80%;
  padding: 0.7rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
}

.msg-user {
  align-self: flex-end;
  background: rgba(122, 162, 247, 0.12);
  border-color: rgba(122, 162, 247, 0.35);
}

.msg-assistant {
  align-self: flex-start;
}

.msg-text {
  line-height: 1.5;
  font-size: 0.95rem;
  word-wrap: break-word;
}

/* ── Markdown rendering inside .msg-text (marked + DOMPurify output) ── */
.msg-text > *:first-child {
  margin-top: 0;
}
.msg-text > *:last-child {
  margin-bottom: 0;
}
.msg-text p {
  margin: 0.4rem 0;
}
.msg-text h1,
.msg-text h2,
.msg-text h3,
.msg-text h4,
.msg-text h5,
.msg-text h6 {
  margin: 0.8rem 0 0.4rem 0;
  line-height: 1.25;
  text-transform: none;
  color: var(--fg);
}
.msg-text h1 { font-size: 1.25rem; }
.msg-text h2 { font-size: 1.1rem; }
.msg-text h3 { font-size: 1rem; font-weight: 600; }
.msg-text h4,
.msg-text h5,
.msg-text h6 { font-size: 0.95rem; font-weight: 600; }
.msg-text ul,
.msg-text ol {
  margin: 0.4rem 0;
  padding-left: 1.5rem;
}
.msg-text li {
  margin: 0.15rem 0;
}
.msg-text li > p {
  margin: 0.15rem 0;
}
.msg-text a {
  color: var(--accent);
  text-decoration: underline;
}
.msg-text a:hover {
  color: var(--accent-hover);
}
.msg-text blockquote {
  margin: 0.5rem 0;
  padding: 0.1rem 0.8rem;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.msg-text pre {
  margin: 0.5rem 0;
}
.msg-text pre code {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--fg);
  font-size: 0.85em;
}
.msg-text hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8rem 0;
}
.msg-text table {
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.85rem;
  width: auto;
  max-width: 100%;
  display: block;
  overflow-x: auto;
}
.msg-text table thead {
  background: rgba(122, 162, 247, 0.12);
}
.msg-text table th,
.msg-text table td {
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  text-align: left;
  vertical-align: top;
}
.msg-text table th {
  font-weight: 600;
  color: var(--fg);
}
.msg-text table tbody tr:nth-child(even) {
  background: rgba(255, 255, 255, 0.02);
}
/* Fase 5: filas 11+ ocultas (siguen en el DOM para el export) + fila-nota. */
.msg-text table tbody tr.table-row-hidden {
  display: none;
}
.msg-text table tbody tr.table-more-row td {
  color: var(--muted);
  font-style: italic;
  font-size: 0.8rem;
  text-align: center;
  background: transparent;
}

.msg-chart {
  position: relative;
  margin: 0.7rem 0 0.4rem 0;
  padding: 0.9rem 1rem 0.7rem 1rem;
  background: #0b0e13;
  border: 1px solid var(--border);
  border-radius: 10px;
  max-width: 100%;
  min-height: 240px;
  height: 280px;
  /* El bubble (.msg) es flex column; sin flex-shrink:0 el canvas se aplasta a
     medida que se añaden más mensajes/bloques. La altura ya está fijada arriba;
     esto solo evita que el flexbox lo encoja por debajo de ella. */
  flex-shrink: 0;
}

.msg-chart canvas {
  max-width: 100%;
}

/* ─── Sheets export result (drive.sheet@1) ─────────────────────────── */
.msg-sheet-link {
  margin: 0.7rem 0 0.2rem 0;
}
.sheet-link-cta {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, rgba(76, 217, 100, 0.12), rgba(122, 162, 247, 0.08));
  border: 1px solid rgba(76, 217, 100, 0.35);
  border-radius: 10px;
  color: var(--fg);
  text-decoration: none;
  transition: background 150ms, border-color 150ms, transform 80ms;
}
.sheet-link-cta:hover {
  background: linear-gradient(135deg, rgba(76, 217, 100, 0.18), rgba(122, 162, 247, 0.12));
  border-color: rgba(76, 217, 100, 0.6);
  transform: translateY(-1px);
}
.sheet-icon {
  font-size: 1.4rem;
  flex-shrink: 0;
}
.sheet-link-text {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.sheet-link-text strong {
  font-size: 0.95rem;
  color: var(--fg);
}
.sheet-link-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.15rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet-arrow {
  color: var(--green);
  font-size: 1.1rem;
  flex-shrink: 0;
}
.tool-use,
.tool-result {
  margin-top: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #0b0e13;
}

.tool-use summary,
.tool-result summary {
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.tool-result.is-error summary {
  color: var(--red);
}

.tool-use pre,
.tool-result pre {
  margin: 0;
  border: none;
  border-top: 1px solid var(--border);
  border-radius: 0 0 6px 6px;
}

/* Skill activation card (Plan 2): visual distinto del tool_use genérico —
   accent color en el borde para que destaque como "evento de configuración"
   y no como una llamada normal a tool. Nested .skill-body es el cuerpo
   markdown colapsado por defecto. */
.tool-use--skill {
  border-color: var(--accent, #6aa9ff);
  background: #0a1422;
}
.tool-use--skill > summary {
  color: var(--accent, #6aa9ff);
  font-weight: 500;
}
.tool-use--skill .skill-body {
  margin: 0;
  border-top: 1px solid var(--border);
  background: #0b0e13;
}
.tool-use--skill .skill-body > summary {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  color: var(--muted);
}
.tool-use--skill .skill-body-pre {
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.78rem;
}

/* ─── Chat form ─────────────────────────────────────────────────────── */
.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.6rem;
  padding: 0.8rem 1.5rem 1.2rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* F4: el botón "Enviar" se transforma en "Detener" mientras el chat procesa
   (como el botón de pausa de Claude Code) — un único botón, misma posición.
   Click en modo Detener → aborta el turno. */
#btn-send.is-stop {
  background: transparent;
  color: var(--red);
  border-color: var(--red);
  font-weight: 600;
}
#btn-send.is-stop:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.1);
  border-color: var(--red);
}

.chat-form textarea {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
  min-height: 2.4rem;
}

.chat-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ─── Buttons ───────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 120ms, border-color 120ms;
  font-family: inherit;
}

.btn.small {
  padding: 0.3rem 0.6rem;
  font-size: 0.78rem;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  background: var(--card-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b0e13;
  font-weight: 600;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ─── Conversaciones (Fase 4) ─────────────────────────────────────────── */
.sidebar-title-section {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
#btn-new-conversation {
  width: 100%;
  margin: 0.5rem 0 0.75rem 0;
}
.conversation-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  /* Ocupa el espacio restante del sidebar y scrollea dentro de él. El
     min-height:0 es OBLIGATORIO: sin él, un hijo flex en columna no encoge por
     debajo de su contenido y el overflow-y nunca se activa (el footer se
     descolgaría fuera de la vista en ventanas pequeñas). */
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}
.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.84rem;
  color: var(--text);
  border: 1px solid transparent;
}
.conversation-item:hover {
  background: var(--card-hover);
}
.conversation-item.is-active {
  background: var(--card-hover);
  border-color: var(--accent);
}
.conversation-item .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conversation-item .conv-delete {
  background: none;
  border: none;
  color: var(--text-muted, #888);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 0 0.3rem;
}
.conversation-item .conv-delete:hover {
  color: #ff6b6b;
}
#active-conversation-label {
  margin-left: 0.75rem;
}

/* ── HITL approval card (Fase 6) ──────────────────────────────────── */
/* Approval card — compact one-row layout con resumen humano arriba,
   meta secundaria debajo, JSON crudo en <details> cerrado (abierto cuando
   severidad=unknown). Paleta toma --yellow/--green/--red del root. */
.approval-card {
  border: 1px solid var(--yellow);
  background: rgba(240, 160, 32, 0.05);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
  margin: 0.6rem 0;
}
.approval-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.approval-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 0.92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.approval-title[data-sev="destructive"] {
  color: var(--red);
}
.approval-title[data-sev="unknown"] {
  color: var(--muted);
  font-style: italic;
}
.approval-actions {
  flex: none;
  display: inline-flex;
  gap: 0.4rem;
}
.approval-btn {
  padding: 0.3rem 0.7rem;
  border-radius: 4px;
  background: transparent;
  color: var(--fg);
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: background 150ms, border-color 150ms;
}
.approval-btn.approve {
  border-color: var(--green);
  color: var(--green);
}
.approval-btn.approve:hover:not(:disabled) {
  background: rgba(76, 217, 100, 0.12);
}
.approval-btn.reject {
  border-color: var(--red);
  color: var(--red);
}
.approval-btn.reject:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.10);
}
.approval-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.approval-meta {
  margin-top: 0.3rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.approval-meta strong {
  color: var(--fg);
  font-weight: 600;
}
.approval-details {
  margin-top: 0.35rem;
  font-size: 0.82rem;
}
.approval-details summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
  padding: 0.1rem 0;
}
.approval-details summary:hover {
  color: var(--accent);
}
.approval-details pre {
  background: rgba(0, 0, 0, 0.25);
  padding: 0.5rem 0.6rem;
  border-radius: 4px;
  font-size: 0.78rem;
  margin: 0.3rem 0 0 0;
  overflow-x: auto;
}

/* Approval badge — coherente con la approval-card. Mismo padding/radius/font
   que la card; cambia color por decisión final. Aparece via live SSE
   (replaceApprovalCardWithBadge) o F5 rehydration (appendRehydratedApprovalBadge). */
.approval-badge {
  display: inline-block;
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.85rem;
  margin: 0.4rem 0;
  border: 1px solid transparent;
}
.approval-badge-approved {
  background: rgba(76, 217, 100, 0.10);
  border-color: var(--green);
  color: var(--green);
}
.approval-badge-rejected {
  background: rgba(255, 107, 107, 0.08);
  border-color: var(--red);
  color: var(--red);
}
.approval-badge-timeout,
.approval-badge-client_disconnected,
.approval-badge-expired {
  background: rgba(154, 164, 173, 0.10);
  border-color: var(--muted);
  color: var(--muted);
}
.approval-comment {
  font-style: italic;
  opacity: 0.85;
}
.approval-when {
  font-size: 0.78rem;
  opacity: 0.7;
  margin-left: 0.3rem;
}

/* ── CTA opt-in: exportar a Sheets bajo tablas/charts ──────────────────
 * Estilo ghost neutro: transparente con borde sutil. NO ámbar (ámbar es
 * lenguaje de "approval pendiente" en HITL y crearía conflicto visual).
 * Hover/focus pasa a azul --accent para señalizar interacción.
 */
.export-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.6rem;
  padding: 0.35rem 0.7rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted, #aaa);
  border-radius: 4px;
  font-size: 0.83rem;
  cursor: pointer;
  transition: border-color 0.1s, color 0.1s;
}
.export-cta:hover:not(:disabled),
.export-cta:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
  outline: none;
}
.export-cta:disabled {
  opacity: 0.7;
  cursor: wait;
}
/* Variante de error (reconectar Drive / fallo genérico). */
.export-cta-error,
.export-cta-error:hover {
  border-color: #cf222e;
  color: #cf222e;
}
.export-cta-error:focus-visible {
  border-color: #ff6b6b;
  color: #ff6b6b;
}
/* F14: el botón CSV va junto al de Sheets, con un pequeño respiro. */
.export-cta-csv {
  margin-left: 0.4rem;
}

/* ────────────────────────────────────────────────────────────────────────
   UX-P0: Loading & thinking states (2026-06-02)
   ──────────────────────────────────────────────────────────────────────── */

/* UX1: indicador "Pensando…" mientras se espera el primer signal del LLM.
   Dots con animación staggered + pulse general en el contenedor. */
.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--muted);
  font-size: 0.88rem;
  font-style: italic;
  animation: thinking-pulse 1.2s ease-in-out infinite;
  padding: 0.3rem 0;
}
.thinking-indicator .dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
  animation: thinking-dot 1.4s ease-in-out infinite;
}
.thinking-indicator .dot:nth-child(2) {
  animation-delay: 0.2s;
}
.thinking-indicator .dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes thinking-pulse {
  0%,
  100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}
@keyframes thinking-dot {
  0%,
  60%,
  100% {
    transform: scale(0.8);
    opacity: 0.5;
  }
  30% {
    transform: scale(1.4);
    opacity: 1;
  }
}

/* UX2: cursor parpadeante al final del último delta durante streaming. */
.streaming-cursor {
  display: inline-block;
  margin-left: 0.05rem;
  color: var(--fg);
  animation: cursor-blink 1s steps(1) infinite;
  font-weight: normal;
  user-select: none;
}
@keyframes cursor-blink {
  0%,
  50% {
    opacity: 1;
  }
  50.01%,
  100% {
    opacity: 0;
  }
}

/* UX3: timer ⏳ Xs hasta tool_result. Color muted mientras corre, verde al
   éxito, rojo al error. Sin background, sin border — minimal junto al nombre
   de la tool en el <summary>. */
.tool-elapsed {
  display: inline-block;
  margin-left: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--mono, monospace);
  transition: color 200ms;
}
.tool-elapsed[data-state="done"] {
  color: var(--green, #4ec27a);
}
.tool-elapsed[data-state="error"] {
  color: var(--red, #e07070);
}
.tool-elapsed:not([data-state]) .elapsed-value {
  /* Mientras el timer corre, pulse discreto para indicar "vivo". */
  animation: thinking-pulse 1.2s ease-in-out infinite;
}

/* Accesibilidad / batería: si el OS pide reducir motion, suprimimos todas las
   animaciones del sprint UX-P0. Los elementos siguen presentes
   (semánticamente informativos) — solo dejan de animarse. */
@media (prefers-reduced-motion: reduce) {
  .thinking-indicator,
  .thinking-indicator .dot,
  .streaming-cursor,
  .tool-elapsed:not([data-state]) .elapsed-value {
    animation: none;
  }
  .streaming-cursor {
    opacity: 0.5;
  }
}

/* ────────────────────────────────────────────────────────────────────────
   UX-P1: Skeleton F5 + Approval fade (2026-06-02)
   ──────────────────────────────────────────────────────────────────────── */

/* Skeleton bubbles durante la carga del history (selectConversation → fetch).
   Shimmer = gradient lineal que se desplaza horizontalmente con keyframes.
   Las dos .skel-line dan sensación de bubble con varias líneas de texto. */
.msg-skeleton {
  pointer-events: none;
}
.msg-skeleton .skel-line {
  height: 0.8rem;
  margin: 0.35rem 0;
  border-radius: 4px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.04) 0%,
    rgba(255, 255, 255, 0.12) 50%,
    rgba(255, 255, 255, 0.04) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Approval card → badge: fade out 200ms en el card, fade in en el badge.
   Coincide con el setTimeout(200) de replaceApprovalCardWithBadge. */
.approval-card.fading-out {
  opacity: 0;
  transition: opacity 200ms ease-out;
  pointer-events: none;
}
.approval-badge.fading-in {
  animation: approval-badge-fade-in 200ms ease-out;
}
@keyframes approval-badge-fade-in {
  from {
    opacity: 0;
    transform: translateY(-2px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Reduced motion: skeletons sin shimmer (gradient estático) y fade
   instantáneo. Los elementos siguen visibles. */
@media (prefers-reduced-motion: reduce) {
  .msg-skeleton .skel-line {
    animation: none;
    background: rgba(255, 255, 255, 0.08);
  }
  .approval-card.fading-out {
    transition: none;
    opacity: 0;
  }
  .approval-badge.fading-in {
    animation: none;
  }
}

/* Banner amber para catálogo incompleto (gateway caído / providers que no
   respondieron al list_tools). `:not([hidden])` para que el attr HTML
   `hidden` se respete frente al `display: flex`. */
.catalog-partial-banner:not([hidden]) {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  margin-bottom: 0.5rem;
  background: rgba(217, 160, 0, 0.08);
  border: 1px solid var(--yellow, #d9a000);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--fg);
}
.catalog-partial-icon {
  font-size: 1rem;
  user-select: none;
  flex: none;
}
.catalog-partial-text {
  flex: 1;
  min-width: 0;
}
.catalog-partial-text strong {
  font-family: var(--mono, monospace);
  color: var(--yellow, #d9a000);
}

/* ────────────────────────────────────────────────────────────────────────
   Scrollbars integradas al tema dark (2026-06-15)
   El default del SO es claro y rompe la estética. Thin + thumb gris sutil.
   ──────────────────────────────────────────────────────────────────────── */

/* Firefox */
.transcript,
.sidebar,
.conversation-list,
.connect-card,
.connect-grid,
.msg-text table,
.skill-body-pre,
pre {
  scrollbar-width: thin;
  scrollbar-color: #2f3742 transparent;
}

/* WebKit (Chrome, Safari, Edge) */
.transcript::-webkit-scrollbar,
.sidebar::-webkit-scrollbar,
.conversation-list::-webkit-scrollbar,
.connect-card::-webkit-scrollbar,
.connect-grid::-webkit-scrollbar,
.msg-text table::-webkit-scrollbar,
.skill-body-pre::-webkit-scrollbar,
pre::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}
.transcript::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track,
.conversation-list::-webkit-scrollbar-track,
.connect-card::-webkit-scrollbar-track,
.connect-grid::-webkit-scrollbar-track,
.msg-text table::-webkit-scrollbar-track,
.skill-body-pre::-webkit-scrollbar-track,
pre::-webkit-scrollbar-track {
  background: transparent;
}
.transcript::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb,
.conversation-list::-webkit-scrollbar-thumb,
.connect-card::-webkit-scrollbar-thumb,
.connect-grid::-webkit-scrollbar-thumb,
.msg-text table::-webkit-scrollbar-thumb,
.skill-body-pre::-webkit-scrollbar-thumb,
pre::-webkit-scrollbar-thumb {
  background: #2f3742;
  border-radius: 6px;
}
.transcript::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover,
.conversation-list::-webkit-scrollbar-thumb:hover,
.connect-card::-webkit-scrollbar-thumb:hover,
.connect-grid::-webkit-scrollbar-thumb:hover,
.msg-text table::-webkit-scrollbar-thumb:hover,
.skill-body-pre::-webkit-scrollbar-thumb:hover,
pre::-webkit-scrollbar-thumb:hover {
  background: #3c4554;
}
.transcript::-webkit-scrollbar-corner,
.connect-grid::-webkit-scrollbar-corner,
.msg-text table::-webkit-scrollbar-corner {
  background: transparent;
}

/* ════════════════════════════════════════════════════════════════════════
   Perseus Hub Chat v2 — rediseño post-login (paleta cósmica del login).
   Componentes nuevos/restyle: fondo Swirl, wordmark, pills de cabecera, fila
   Perseus, input pill, botón Enviar gradiente, footer con avatar. Preserva
   todos los id/handlers. Sin logo, sin cambiar la fuente.
   ════════════════════════════════════════════════════════════════════════ */

/* Fondo Swirl sutil del chat: canvas fijo a baja opacidad detrás de todo. */
/* Swirl ACOTADO al módulo del input: rellena la caja del input como su fondo
   (detrás del texto), no flota en el chat. */
.app-canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  opacity: 0.32; /* imperceptible: apenas un matiz tras el texto */
  pointer-events: none;
}
.app-canvas canvas {
  display: block;
  /* Funde los bordes laterales para que no corte duro dentro de la caja. */
  -webkit-mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 14%,
    #000 86%,
    transparent 100%
  );
  mask-image: linear-gradient(
    to right,
    transparent 0%,
    #000 14%,
    #000 86%,
    transparent 100%
  );
}

/* Wordmark del sidebar (solo texto). */
.sidebar-brand {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  padding: 0.1rem 0.4rem 0.9rem;
}

/* Pill de recuento junto a "CUENTAS". */
.count-pill {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--green-soft);
  background: rgba(52, 211, 153, 0.12);
  border: 1px solid rgba(52, 211, 153, 0.28);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  margin-left: auto;
}
.sidebar-head .icon-btn {
  margin-left: 0.4rem;
}

/* Filas de cuenta conectada: logo + nombre + punto de estado pulsante. */
.provider-item {
  border: none;
  background: transparent;
  padding: 0.5rem 0.5rem;
  border-radius: 9px;
}
.provider-item.is-connected {
  border: none;
}
.provider-item:hover {
  background: rgba(255, 255, 255, 0.04);
}
.provider-item-meta {
  flex: 1;
}
.provider-name {
  font-weight: 600;
  color: #d8d6e6;
  font-size: 0.85rem;
}
.provider-status-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
}
.provider-status-dot.is-live {
  animation: psPulse 3s ease-in-out infinite;
}

/* Botón "Nueva conversación" (debajo de Cuentas, encima de Recientes). */
.btn-new-conv {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  margin: 1rem 0 0.5rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  border: 1px solid rgba(139, 92, 246, 0.3);
  background: rgba(139, 92, 246, 0.1);
  color: #ddd6fe;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 120ms, border-color 120ms;
}
.btn-new-conv:hover {
  background: rgba(139, 92, 246, 0.18);
  border-color: rgba(139, 92, 246, 0.5);
}
.btn-new-conv .plus {
  font-size: 1.1rem;
  line-height: 1;
}

/* Section title estilo "etiqueta". */
.sidebar-title,
.sidebar-title-section {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted-2);
}
.sidebar-title-section {
  margin: 0.4rem 0 0.5rem;
  padding: 0;
  border-top: none;
}
.sidebar-head {
  align-items: center;
}

/* Conversación activa: borde izquierdo violeta. */
.conversation-item {
  border-radius: 9px;
  border-left: 2px solid transparent;
  color: #8b8a9e;
}
.conversation-item.is-active {
  background: rgba(255, 255, 255, 0.05);
  border-color: transparent;
  border-left: 2px solid var(--accent-hover);
  color: #edebfa;
  font-weight: 600;
}

/* Footer del sidebar: avatar de iniciales + email + plan + salir. */
.sidebar-footer {
  gap: 0.6rem;
}
.user-avatar {
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #c026d3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
}
.sidebar-footer-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.user-plan {
  font-size: 0.66rem;
  color: var(--muted-2);
}
/* Badge de versión (+ etiqueta de entorno) en el footer del sidebar. */
.app-version {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* ── Cabecera del chat: título + pills de estado + glow ── */
.chat-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  padding: 1rem 1.4rem;
  border-bottom: 1px solid var(--border-soft);
}
.chat-header-glow {
  position: absolute;
  top: -130px;
  left: 28%;
  width: 620px;
  height: 280px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.14), rgba(139, 92, 246, 0) 68%);
  filter: blur(44px);
  pointer-events: none;
  animation: psGlow 8s ease-in-out infinite;
}
#chat-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  position: relative;
}
.header-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-left: auto;
  position: relative;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.74rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill-green {
  color: var(--green-soft);
  background: rgba(52, 211, 153, 0.1);
  border-color: rgba(52, 211, 153, 0.26);
}
.pill-green .pill-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.9);
}
.pill-violet {
  color: var(--pill-violet);
  background: rgba(168, 85, 247, 0.1);
  border-color: rgba(168, 85, 247, 0.28);
}
.pill-blue {
  color: var(--pill-blue);
  background: rgba(66, 133, 244, 0.1);
  border-color: rgba(66, 133, 244, 0.24);
}

/* Pill del trigger multi-cuenta en la cabecera (color azul como las pills). */
.account-trigger.pill-blue {
  font-size: 0.74rem;
  font-weight: 600;
}
.account-trigger.has-selection {
  color: #fff;
  border-color: rgba(66, 133, 244, 0.5);
}

/* ── Mensajes ── */
.transcript {
  position: relative;
  gap: 1.5rem;
  padding: 1.6rem 2rem;
}
.msg {
  border: none;
  background: transparent;
  padding: 0;
  border-radius: 0;
}
.msg-user {
  align-self: flex-end;
  max-width: 680px;
  /* Algo más marcada para contrastar con el fondo de partículas y diferenciarse
     claramente de la burbuja del asistente (violeta). */
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 16px 16px 4px 16px;
  padding: 0.8rem 1.1rem;
  color: #edebfa;
}
.msg-assistant {
  align-self: stretch;
  max-width: 100%;
  width: 100%;
  /* Burbuja de Perseus: panel translúcido violeta — distinto de la burbuja
     blanca del usuario (queda claro quién responde) y aporta contraste sobre
     el fondo de partículas para que el texto se lea bien. */
  background: rgba(139, 92, 246, 0.07);
  border: 1px solid rgba(139, 92, 246, 0.16);
  border-radius: 4px 16px 16px 16px;
  padding: 0.95rem 1.15rem 1.05rem;
}
/* Fila "Perseus" del asistente (texto, sin logo) + nota de actividad opaca. */
.msg-perseus {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
  font-size: 0.82rem;
}
.msg-perseus-name {
  font-weight: 700;
  color: #c4b5fd;
}
.msg-perseus-note {
  color: var(--muted-2);
  font-size: 0.78rem;
}

/* Tarjeta del gráfico (Chart.js intacto, solo el contenedor). */
.msg-chart {
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.1rem 1.2rem 0.8rem;
}

/* Acciones bajo la respuesta (Exportar/CSV/Copiar) — botones discretos. */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}
.export-cta,
.msg-copy-btn {
  margin-top: 0;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #c9c7da;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  padding: 0.5rem 0.85rem;
  cursor: pointer;
  font-family: inherit;
}
.export-cta:hover:not(:disabled),
.msg-copy-btn:hover {
  border-color: var(--accent);
  color: #fff;
}

/* ── Input pill + botón Enviar gradiente ── */
.chat-form {
  display: block;
  border-top: 1px solid var(--border-soft);
  padding: 1rem 2rem 1.4rem;
  position: relative;
}
.chat-input-pill {
  position: relative; /* contiene el canvas del Swirl (su fondo) */
  overflow: hidden; /* recorta el Swirl a la caja redondeada */
  display: flex;
  align-items: flex-end;
  gap: 0.7rem;
  background: var(--card-input);
  border: 1px solid rgba(139, 92, 246, 0.22);
  border-radius: 18px;
  padding: 0.65rem 0.65rem 0.65rem 1.1rem;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.25);
}
/* El contenido del input va por ENCIMA del Swirl (que es el fondo de la caja). */
.chat-input-pill > :not(.app-canvas) {
  position: relative;
  z-index: 1;
}
.chat-input-pill:focus-within {
  border-color: rgba(139, 92, 246, 0.5);
}
.chat-form textarea {
  flex: 1;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0.45rem 0;
  min-height: 1.6rem;
  max-height: 40vh;
  font-size: 0.98rem;
  color: var(--fg);
  resize: none;
}
.chat-form textarea:focus {
  outline: none;
  border: none;
}
.chat-input-hint {
  font-size: 0.7rem;
  color: #5e5c72;
  font-weight: 600;
  padding-bottom: 0.6rem;
}
.btn-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--grad-send);
  color: #fff;
  border: none;
  border-radius: 13px;
  padding: 0.6rem 1.3rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
  transition: filter 120ms, transform 80ms;
}
.btn-send:hover:not(:disabled) {
  filter: brightness(1.08);
}
.btn-send:disabled {
  opacity: 0.6;
  cursor: wait;
}
/* Morph a "Detener" durante el turno (preservado). */
#btn-send.is-stop {
  background: transparent;
  color: var(--red);
  border: 1px solid var(--red);
  box-shadow: none;
  font-weight: 600;
}
#btn-send.is-stop:hover:not(:disabled) {
  background: rgba(255, 107, 107, 0.1);
  filter: none;
}
.chat-form-foot {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted-2);
  margin: 0.7rem 0 0;
}

/* ────────────────────────────────────────────────────────────────────────
   Responsive — ventana pequeña en desktop (2026-06-15)
   No es layout de teléfono: solo evita que en ventanas estrechas el sidebar
   se coma el chat. Sidebar más angosto + paddings reducidos.
   ──────────────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .layout {
    grid-template-columns: 248px 1fr;
  }
  .sidebar {
    padding: 1rem 0.7rem;
  }
  .chat-header {
    padding: 0.8rem 1rem;
  }
  .transcript {
    padding: 0.8rem 1rem;
  }
  .chat-form {
    padding: 0.7rem 1rem 1rem 1rem;
  }
  .msg {
    max-width: 92%;
  }
  .connect-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}

/* ────────────────────────────────────────────────────────────────────────
   F16 — Mobile (teléfono): sidebar como drawer + chat a ancho completo.
   ──────────────────────────────────────────────────────────────────────── */
/* Botón hamburguesa: oculto en desktop, visible solo en móvil. */
#btn-menu {
  display: none;
}
.drawer-overlay {
  display: none;
}

@media (max-width: 640px) {
  .layout {
    grid-template-columns: 1fr; /* una sola columna; el sidebar sale del flujo */
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 84vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 220ms ease;
    z-index: 1001;
    box-shadow: 2px 0 28px rgba(0, 0, 0, 0.55);
  }
  body.drawer-open .sidebar {
    transform: translateX(0);
  }
  /* Overlay oscuro al abrir el drawer (cierra al tocar). */
  .drawer-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
  }
  body.drawer-open .drawer-overlay {
    opacity: 1;
    pointer-events: auto;
  }
  #btn-menu {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /* Top-bar móvil compacto: fila 1 = ☰ + título; fila 2 = pills de estado.
     Sin el subtítulo verboso de antes. Respeta el notch (safe-area). */
  .chat-header {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex-wrap: wrap;
    padding: calc(0.6rem + env(safe-area-inset-top)) 0.9rem 0.6rem;
  }
  .chat-header-glow {
    display: none; /* evita paint extra en móvil */
  }
  #chat-title {
    flex: 1;
    font-size: 1.05rem;
  }
  .header-status {
    flex-basis: 100%;
    margin-left: 0;
    gap: 0.4rem;
  }
  .header-status .pill {
    font-size: 0.68rem;
    padding: 0.25rem 0.55rem;
  }
  .account-trigger-label {
    max-width: 7rem;
  }
  /* En móvil el popover ocupa casi todo el ancho, anclado a la derecha. */
  .account-popover {
    position: fixed;
    top: auto;
    right: 0.6rem;
    left: 0.6rem;
    width: auto;
    max-height: 56vh;
  }
  .transcript {
    padding: 1rem 0.9rem;
    gap: 1.2rem;
  }
  .chat-form {
    padding: 0.7rem 0.9rem calc(0.7rem + env(safe-area-inset-bottom));
  }
  .msg-user {
    max-width: 88%;
  }
  /* Drawer: respeta el notch arriba. */
  .sidebar {
    padding-top: calc(1.1rem + env(safe-area-inset-top));
  }
  /* Fondo Swirl en móvil: algo más contenido que en desktop (batería) pero
     visible. */
  .app-canvas {
    opacity: 0.3;
  }
  /* Tap targets cómodos en móvil. */
  .btn,
  .icon-btn {
    min-height: 40px;
  }
  .connect-grid {
    grid-template-columns: 1fr;
  }
  /* Modal de conexiones a pantalla completa en el teléfono (cómodo para el
     pulgar; antes quedaba una tarjeta centrada con padding que en 390px se
     veía apretada). */
  .connect-modal {
    padding: 0;
  }
  .connect-card {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
    border: none;
  }
}

/* ═══════════════ Avisos proactivos (Sistema → Usuario) ═══════════════════ */
@keyframes psToastIn {
  0% { opacity: 0; transform: translateX(36px) scale(0.96); }
  100% { opacity: 1; transform: none; }
}

/* Sidebar: secciones AVISOS / Recientes */
.group-label {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted-2); padding: 0.6rem 0.6rem 0.2rem;
  display: flex; align-items: center; justify-content: space-between;
}
.avisos-pill {
  display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.62rem; font-weight: 700;
  color: #ffc9cf; background: rgba(255, 107, 107, 0.12); border: 1px solid rgba(255, 107, 107, 0.3);
  padding: 0.08rem 0.45rem; border-radius: 999px;
}
.avisos-pill .pill-dot {
  width: 0.4rem; height: 0.4rem; border-radius: 50%; background: var(--red);
  box-shadow: 0 0 6px var(--red); animation: psPulse 2.4s ease-in-out infinite;
}

/* Sidebar: item de aviso */
.conversation-item.alert-item { gap: 0.55rem; padding: 0.5rem 0.6rem; }
.conversation-item.alert-item.sev-rojo {
  background: linear-gradient(90deg, rgba(255, 107, 107, 0.14), rgba(255, 107, 107, 0.02));
  border-color: rgba(255, 107, 107, 0.3);
}
.conversation-item.alert-item.sev-amarillo {
  background: linear-gradient(90deg, rgba(240, 160, 32, 0.1), rgba(240, 160, 32, 0.02));
  border-color: rgba(240, 160, 32, 0.24);
}
.alert-item .alert-dot { width: 0.6rem; height: 0.6rem; flex: none; border-radius: 50%; }
.alert-item.sev-rojo .alert-dot { background: var(--red); box-shadow: 0 0 8px var(--red); }
.alert-item.sev-amarillo .alert-dot { background: var(--yellow); box-shadow: 0 0 8px rgba(240, 160, 32, 0.6); }
.alert-item .alert-title { display: flex; flex-direction: column; gap: 1px; white-space: normal; line-height: 1.2; }
.alert-item .alert-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.82rem; color: #c9c7da; }
.alert-item.unseen .alert-name { font-weight: 700; color: #fff; }
.alert-item .alert-sub { font-size: 0.66rem; color: var(--muted); }
.alert-item.sev-rojo .alert-sub { color: #e79aa6; }
.alert-item .alert-unseen-dot { width: 0.45rem; height: 0.45rem; flex: none; border-radius: 50%; background: var(--red); }
.alert-item.sev-amarillo .alert-unseen-dot { background: var(--yellow); }
.alert-item.resolved { opacity: 0.6; }
.alert-item.resolved .alert-dot { box-shadow: none; }

/* Tarjeta de aviso (transcript) */
.alert-card {
  align-self: flex-start; max-width: min(680px, 94%); border-radius: 14px; overflow: hidden;
  border: 1px solid var(--border); background: var(--card);
}
.alert-card.sev-rojo { border-color: rgba(255, 107, 107, 0.28); box-shadow: 0 18px 50px rgba(255, 107, 107, 0.08); }
.alert-card.sev-amarillo { border-color: rgba(240, 160, 32, 0.26); }
.alert-band { display: flex; align-items: center; gap: 0.7rem; padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); }
.alert-card.sev-rojo .alert-band { background: linear-gradient(100deg, rgba(255, 107, 107, 0.18), rgba(255, 107, 107, 0.04)); }
.alert-card.sev-amarillo .alert-band { background: linear-gradient(100deg, rgba(240, 160, 32, 0.16), rgba(240, 160, 32, 0.03)); }
.alert-band-icon {
  width: 1.7rem; height: 1.7rem; flex: none; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
}
.alert-card.sev-rojo .alert-band-icon { background: rgba(255, 107, 107, 0.16); border: 1px solid rgba(255, 107, 107, 0.5); }
.alert-card.sev-amarillo .alert-band-icon { background: rgba(240, 160, 32, 0.16); border: 1px solid rgba(240, 160, 32, 0.5); }
.alert-band-icon::after { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; }
.alert-card.sev-rojo .alert-band-icon::after { background: var(--red); box-shadow: 0 0 8px var(--red); }
.alert-card.sev-amarillo .alert-band-icon::after { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.alert-band-h { flex: 1; min-width: 0; }
.alert-band-title { font-weight: 700; font-size: 0.92rem; }
.alert-card.sev-rojo .alert-band-title { color: #ffe4e6; }
.alert-band-sub { font-size: 0.72rem; color: var(--muted); margin-top: 1px; }
.alert-band-snap { font-size: 0.7rem; color: var(--muted-2); white-space: nowrap; }
.alert-card-body { padding: 0.9rem 1rem 1rem; }

/* summary strip */
.alert-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; margin-bottom: 1rem; }
.alert-summary .tile { border-radius: 10px; padding: 0.6rem 0.7rem; border: 1px solid var(--border); background: rgba(255, 255, 255, 0.03); }
.tile.tone-rojo { background: rgba(255, 107, 107, 0.08); border-color: rgba(255, 107, 107, 0.26); }
.tile.tone-amarillo { background: rgba(240, 160, 32, 0.08); border-color: rgba(240, 160, 32, 0.26); }
.tile .tile-n { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.tile.tone-verde { background: rgba(80, 200, 120, 0.07); border-color: rgba(80, 200, 120, 0.24); }
.tile.tone-rojo .tile-n { color: #fb7185; }
.tile.tone-amarillo .tile-n { color: var(--yellow); }
.tile.tone-verde .tile-n { color: var(--green); }
.tile.tone-neutro .tile-n { color: var(--fg); }
.tile .tile-label { font-size: 0.66rem; color: var(--muted); font-weight: 600; margin-top: 0.3rem; }

/* check rows */
.check-row { display: flex; gap: 0.7rem; padding: 0.6rem 0; border-bottom: 1px solid var(--border-soft); }
.check-row:last-child { border-bottom: none; }
.check-dot { width: 0.5rem; height: 0.5rem; flex: none; margin-top: 0.35rem; border-radius: 50%; background: var(--muted); }
.check-row.tone-rojo .check-dot { background: var(--red); box-shadow: 0 0 7px var(--red); }
.check-row.tone-amarillo .check-dot { background: var(--yellow); box-shadow: 0 0 7px rgba(240, 160, 32, 0.6); }
.check-row.tone-verde .check-dot { background: var(--green); box-shadow: 0 0 7px rgba(80, 200, 120, 0.6); }
.check-main { flex: 1; min-width: 0; }
.check-key { font-size: 0.86rem; font-weight: 700; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 0.15rem; }
.check-badge { font-size: 0.62rem; font-weight: 700; padding: 0.05rem 0.45rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.check-badge.tone-rojo { color: #fca5a5; background: rgba(255, 107, 107, 0.14); border-color: rgba(255, 107, 107, 0.3); }
.check-badge.tone-amarillo { color: #e9c46a; background: rgba(240, 160, 32, 0.14); border-color: rgba(240, 160, 32, 0.3); }
.check-badge.tone-verde { color: #86e8a8; background: rgba(80, 200, 120, 0.14); border-color: rgba(80, 200, 120, 0.3); }
.check-text { font-size: 0.84rem; color: #cfcde0; line-height: 1.5; }
.check-text strong { color: #fff; }
.check-text p { margin: 0; }
.check-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem; }
.chip { font-size: 0.7rem; font-weight: 600; padding: 0.12rem 0.55rem; border-radius: 999px; border: 1px solid var(--border); color: #cfcde0; }
.chip.tone-rojo { color: #fca5a5; background: rgba(255, 107, 107, 0.1); border-color: rgba(255, 107, 107, 0.26); }
.chip.tone-amarillo { color: #e9c46a; background: rgba(240, 160, 32, 0.1); border-color: rgba(240, 160, 32, 0.26); }
.chip.tone-verde { color: #86e8a8; background: rgba(80, 200, 120, 0.1); border-color: rgba(80, 200, 120, 0.26); }

/* action checklist */
.alert-action {
  margin-top: 0.9rem; border-radius: 12px; padding: 0.8rem 0.9rem;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.12), rgba(192, 38, 211, 0.04));
  border: 1px solid rgba(139, 92, 246, 0.28);
}
.action-head { font-size: 0.8rem; font-weight: 700; color: #ddd6fe; margin-bottom: 0.5rem; }
.action-row { display: flex; gap: 0.6rem; align-items: flex-start; margin-top: 0.5rem; }
.action-n {
  width: 1.2rem; height: 1.2rem; flex: none; border-radius: 6px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 0.7rem; font-weight: 800; color: #c4b5fd;
  background: rgba(139, 92, 246, 0.12); border: 1px solid rgba(196, 181, 253, 0.4); margin-top: 1px;
}
.action-text { font-size: 0.84rem; color: #d8d6e6; line-height: 1.5; }
.action-text strong { color: #fff; }
.action-text p { margin: 0; }

/* cta + footer */
.alert-cta { margin-top: 0.9rem; }
.alert-cta-brain {
  font-size: 0.82rem; font-weight: 700; color: #fff; border: none; border-radius: 10px;
  padding: 0.55rem 0.9rem; cursor: pointer; background: var(--grad-send);
  box-shadow: 0 8px 20px rgba(124, 58, 237, 0.35); font-family: inherit;
}
.alert-foot { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.7rem; flex-wrap: wrap; }
.alert-sheet-btn {
  font-size: 0.78rem; color: #cfe; text-decoration: none; border: 1px solid var(--border);
  background: var(--card-2); border-radius: 9px; padding: 0.4rem 0.7rem;
}
.alert-sheet-btn:hover { border-color: var(--accent); }
.alert-foot-note { font-size: 0.7rem; color: var(--muted-2); }

/* toast de push en tiempo real */
.alert-toast {
  position: fixed; top: 1rem; right: 1rem; z-index: 90; width: 320px; display: flex; gap: 0.7rem;
  background: var(--card); border: 1px solid var(--border); border-left: 3px solid var(--red);
  border-radius: 12px; padding: 0.7rem 0.8rem; box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
  animation: psToastIn 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}
.alert-toast.sev-amarillo { border-left-color: var(--yellow); }
.alert-toast .toast-icon {
  width: 1.7rem; height: 1.7rem; flex: none; border-radius: 50%; display: inline-flex;
  align-items: center; justify-content: center; background: rgba(255, 107, 107, 0.16); border: 1px solid rgba(255, 107, 107, 0.5);
}
.alert-toast.sev-amarillo .toast-icon { background: rgba(240, 160, 32, 0.16); border-color: rgba(240, 160, 32, 0.5); }
.alert-toast .toast-icon::after { content: ""; width: 0.6rem; height: 0.6rem; border-radius: 50%; background: var(--red); box-shadow: 0 0 8px var(--red); }
.alert-toast.sev-amarillo .toast-icon::after { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.alert-toast .toast-body { flex: 1; min-width: 0; }
.alert-toast .toast-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.alert-toast .toast-title { font-size: 0.84rem; font-weight: 700; color: #ffe4e6; }
.alert-toast .toast-when { font-size: 0.66rem; color: var(--muted-2); }
.alert-toast .toast-sub { font-size: 0.74rem; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-toast .toast-actions { display: flex; gap: 0.5rem; margin-top: 0.6rem; }
.alert-toast .toast-see {
  flex: 1; font-size: 0.76rem; font-weight: 700; color: #fff; border: none; border-radius: 8px;
  padding: 0.4rem; cursor: pointer; background: linear-gradient(135deg, var(--red), #c026d3); font-family: inherit;
}
.alert-toast .toast-dismiss {
  font-size: 0.76rem; color: var(--muted); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.4rem 0.7rem; cursor: pointer; font-family: inherit;
}
