
/* ═══ MERLIN ASSISTANT AI CHAT ═══ */

.ai-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 90px);
  max-height: calc(100vh - 90px);
}
/* 20-oct: en escritorio el chat ocupa fijo el hueco entre la barra superior y el borde inferior, como en móvil: la franja
   de tokens arriba y el compositor abajo no se mueven, solo se desplazan los mensajes, y se usa todo el ancho. Antes era una caja de 100vh−90px
   dentro del contenido con padding: la página entera hacía scroll y parecía «una ventana dentro de otra». */
@media (min-width: 901px) {
  .view-ai .ai-container { position: fixed; top: var(--m-topbar, 90px); left: var(--sidebar-w); right: 0; bottom: 0; height: auto; max-height: none; background: var(--m-bg); z-index: 4; }
  .view-ai .ai-token-bar-wrap { padding-left: 28px; padding-right: 104px; }
  .view-ai .ai-messages { padding: 20px 28px; }
  .view-ai .ai-input-bar { padding-left: 28px; padding-right: 28px; }
  .view-ai .ai-toolbar { right: 22px; }
}

.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.ai-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  gap: 12px;
}

.ai-welcome-icon {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--m-brand-softer);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  color: var(--m-brand);
}

.ai-welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--m-text);
}

.ai-welcome-sub {
  font-size: 14px;
  color: var(--m-text-soft);
  max-width: 400px;
  line-height: 1.5;
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
  max-width: 500px;
}

.ai-suggestion {
  background: var(--m-bg-2);
  border: 1px solid var(--m-border);
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 13px;
  color: var(--m-text-soft);
  cursor: pointer;
  transition: all 0.2s;
}

.ai-suggestion:hover {
  background: var(--m-brand-softer);
  border-color: var(--m-brand);
  color: var(--m-brand);
}

.ai-msg {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: aiMsgIn 0.3s ease;
}

@keyframes aiMsgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-msg-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

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

.ai-msg-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 10px;
  background: var(--m-bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--m-text-soft);
}

.ai-avatar-merlin {
  background: var(--m-brand-softer);
  color: var(--m-brand);
}

.ai-msg-bubble {
  background: var(--m-bg-2);
  border: 1px solid var(--m-border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--m-text);
  min-width: 0;
  overflow-wrap: anywhere;   /* claves, URLs y rutas largas se parten, no se salen (8-sep) */
}
.ai-msg-bubble pre {
  margin: 6px 0; padding: 8px 10px; border-radius: 8px;
  background: rgba(0,0,0,.25); font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.ai-msg-bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; overflow-wrap: anywhere; }

.ai-msg-user .ai-msg-bubble {
  background: var(--m-brand);
  border-color: var(--m-brand);
  color: white;
}

.ai-thinking {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--m-text-dim);
  animation: aiDotPulse 1.4s infinite;
}

.ai-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aiDotPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.ai-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--m-bg-2);
  border-top: 1px solid var(--m-border);
  border-radius: 0 0 12px 12px;
}

.ai-input-bar input {
  flex: 1;
  background: var(--m-bg);
  border: 1px solid var(--m-border);
  border-radius: 12px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--m-text);
  outline: none;
}

.ai-input-bar input:focus {
  border-color: var(--m-brand);
}

.ai-input-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  border: 1px solid var(--m-border);
  background: var(--m-bg);
  color: var(--m-text-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 18px;
}

.ai-input-btn:hover {
  background: var(--m-bg-3);
  color: var(--m-text);
}

.ai-send-btn {
  background: var(--m-brand);
  border-color: var(--m-brand);
  color: white;
}

.ai-send-btn:hover {
  opacity: 0.9;
  background: var(--m-brand);
  color: white;
}

.ai-mic-btn.listening {
  background: var(--m-red, #ef4444);
  border-color: var(--m-red, #ef4444);
  color: white;
  animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* Franja de estado del chat, sobre el fondo (sin banda gris): «Tokens · 2,5M / 2,5M» con la barra a
   todo el ancho, debajo SMS/llamadas si el plan los incluye; a la derecha, centrados, voz 🔊 y nueva
   conversación (.ai-toolbar vive dentro para centrarse sea cual sea la altura). */
.ai-token-bar-wrap {
  position: relative;
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px 90px 10px 14px;   /* 20-oct: dos botones (voz, historial); «nueva conversación» bajó al compositor */
  border-bottom: 1px solid var(--m-border);
  font-size: 12px; color: var(--m-text-soft);
}
.ai-token-main { display: flex; flex-direction: column; gap: 6px; }
.ai-token-info { display: flex; justify-content: space-between; color: var(--m-text-dim); }
.ai-token-info span:last-child { color: var(--m-text); font-weight: 500; font-variant-numeric: tabular-nums; }
.ai-token-track { height: 4px; background: var(--m-bg-3); border-radius: 2px; overflow: hidden; }
.ai-token-fill { height: 100%; border-radius: 2px; transition: width 0.5s ease; }
#ai-comms-bar { display: flex; gap: 14px; color: var(--m-text-dim); }
#ai-comms-bar i { font-size: 12px; vertical-align: -1px; }

/* 6-sep: voz de Merlin apagada (botón de la barra) */
.ai-input-btn.muted { color: var(--m-text-dim); opacity: .7; }

/* 🔇 sin tocar la fuente de iconos (ti-volume-off no está en el recorte): raya sobre ti-volume */
.ai-input-btn.muted i { position: relative; }
.ai-input-btn.muted i::after { content: ''; position: absolute; left: 10%; top: 50%; width: 80%; height: 2px; background: currentColor; transform: rotate(-45deg); border-radius: 1px; }

.ai-toolbar { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); display: flex; align-items: center; gap: 2px; }
.ai-toolbar .ai-input-btn { width: 34px; height: 34px; min-width: 34px; border: none; background: transparent; border-radius: 50%; font-size: 18px; }
.ai-toolbar .ai-input-btn:hover { background: var(--m-bg-3); }
#ai-voice[hidden] { display: none !important; }
/* Menú flotante (lo usa la lista de conversaciones; el selector de modelo se quitó el 20-oct) */
.ai-mode-menu { position: absolute; bottom: calc(100% + 8px); left: 0; min-width: 260px; padding: 6px; background: var(--m-bg-2); border: 1px solid var(--m-border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); z-index: 20; }
.ai-mode-menu button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: none; background: transparent; color: var(--m-text); font-size: 13px; border-radius: 8px; cursor: pointer; text-align: left; }
.ai-mode-menu button i { font-size: 16px; }
.ai-mode-menu button small { margin-left: auto; color: var(--m-text-dim); font-size: 11px; white-space: nowrap; }
.ai-mode-menu button:hover, .ai-mode-menu button.active { background: var(--m-brand-soft); color: var(--m-brand); }

/* 9-oct: lista de conversaciones (10 por usuario, guardadas en la unidad). Reusa .ai-mode-menu; se abre hacia abajo. */
.ai-hist-menu { top: calc(100% + 6px); bottom: auto; right: 8px; left: auto; max-height: 50vh; overflow-y: auto; }
.ai-hist-row { display: flex; align-items: center; }
.ai-hist-row > button:first-child { flex: 1; min-width: 0; }
.ai-hist-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-mode-menu .ai-hist-del { width: 28px; flex: none; padding: 8px 4px; justify-content: center; color: var(--m-text-dim); }
#ai-history[aria-expanded="true"] { color: var(--m-brand); }

/* 18-oct: espera con estado, Reintentar y formulario de credenciales del asistente */
.ai-thinking .ai-estado { margin-left: 8px; font-size: 12px; color: var(--m-text-soft); }
.ai-reintentar { margin-left: 8px; font: inherit; font-size: 12px; padding: 4px 10px; border-radius: 14px; border: 1px solid var(--m-border); background: var(--m-bg-2); color: var(--m-text); cursor: pointer; }
.ai-reintentar:hover { border-color: var(--m-brand); color: var(--m-brand); }
.ai-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; padding: 12px; border: 1px solid var(--m-border); border-radius: 12px; background: var(--m-bg); max-width: 360px; }
.ai-form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--m-text-soft); }
.ai-form input, .ai-form select { font: inherit; font-size: 14px; color: var(--m-text); background: var(--m-bg-2); border: 1px solid var(--m-border); border-radius: 8px; padding: 8px 10px; }
.ai-form .ai-form-nota { font-size: 11px; color: var(--m-text-dim); }
.ai-form button { align-self: flex-start; font: inherit; font-size: 13px; padding: 8px 14px; border-radius: 10px; border: 0; background: var(--m-brand); color: #fff; cursor: pointer; }
.ai-form.enviado { opacity: .55; pointer-events: none; }
