/* ============================================================
   SeptiGenesis — Command Center · Chat IA (command-chat.css)
   Estilos del asistente operativo con memoria. Prefijo `.sc-`
   para no colisionar con `.cc-` (command.css es de otro agente).
   Reusa las variables --cc-* del Command Center para coherencia.
   ============================================================ */

/* ── Botón flotante + overlay (el chat NO es lo primero que se ve) ── */
.cc-chat-fab {
  position: fixed; right: 22px; bottom: 22px; z-index: 900;
  width: 60px; height: 60px; border-radius: 50%; cursor: pointer;
  background: #fff; border: 2px solid var(--cc-teal-btn, #008077);
  box-shadow: 0 8px 24px rgba(0,169,157,.4); transition: transform .15s ease, box-shadow .15s ease;
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px;
}
.cc-chat-fab-img { width: 30px; height: 30px; object-fit: contain; }
.cc-chat-fab-ia { font-size: 9px; font-weight: 800; letter-spacing: .06em; color: var(--cc-teal-btn, #008077); line-height: 1; margin-top: 1px; }
.cc-chat-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 30px rgba(0,169,157,.5); }
.cc-chat-fab:focus-visible { outline: 3px solid #0e2a27; outline-offset: 3px; }
.cc-chat-overlay { position: fixed; inset: 0; z-index: 950; display: flex; align-items: center; justify-content: center; padding: 16px; }
.cc-chat-backdrop { position: absolute; inset: 0; background: rgba(11,31,29,.5); backdrop-filter: blur(2px); }
.cc-chat-window {
  position: relative; background: var(--cc-surface, #fff); border-radius: 18px;
  width: min(1000px, 96vw); height: min(88vh, 860px); overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.35); display: flex; flex-direction: column;
}
.cc-chat-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--cc-navy, #0e2a27); color: #fff; flex-shrink: 0;
}
.cc-chat-bar strong { font-size: 15px; font-weight: 700; }
.cc-chat-close { background: transparent; border: none; color: #cfe3e0; font-size: 20px; cursor: pointer; line-height: 1; padding: 4px 8px; border-radius: 8px; }
.cc-chat-close:hover { background: rgba(255,255,255,.12); color: #fff; }
.cc-chat-mount { flex: 1; min-height: 0; overflow: hidden; }
/* Dentro del overlay el chat ocupa todo el alto disponible */
.cc-chat-mount .sc-wrap { height: 100%; min-height: 0; }
@media (max-width: 560px) {
  .cc-chat-window { width: 100vw; height: 100vh; border-radius: 0; }
  .cc-chat-fab { right: 16px; bottom: 16px; width: 52px; height: 52px; font-size: 23px; }
}

.sc-wrap {
  display: flex;
  gap: 14px;
  height: calc(100vh - 150px);
  min-height: 460px;
}

/* ── Sidebar de conversaciones (izquierda) ─────────────────── */
.sc-side {
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  background: var(--cc-surface, #fff);
  border: 1px solid var(--cc-line, #e4ebe9);
  border-radius: var(--cc-radius, 14px);
  box-shadow: var(--cc-shadow, 0 1px 3px rgba(11, 31, 29, .06));
  overflow: hidden;
}
.sc-side-head {
  padding: 12px;
  border-bottom: 1px solid var(--cc-line, #e4ebe9);
}
.sc-new-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px;
  border: none;
  border-radius: var(--cc-radius-sm, 10px);
  background: var(--cc-teal-btn, #008077);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s ease;
}
.sc-new-btn:hover { background: var(--cc-teal-dk, #007a71); }

/* Botón "Generar PDF del plan" — secundario (outline navy), bajo el de nueva conv. */
.sc-pdf-btn {
  width: 100%;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--cc-navy, #143e6b);
  border-radius: var(--cc-radius-sm, 10px);
  background: transparent;
  color: var(--cc-navy, #143e6b);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s ease, opacity .15s ease;
}
.sc-pdf-btn:hover:not(:disabled) { background: rgba(20, 62, 107, .07); }
.sc-pdf-btn:disabled { opacity: .55; cursor: default; }
.sc-pdf-btn.is-busy { opacity: .6; }

.sc-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.sc-conv {
  position: relative;
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 34px 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--cc-radius-sm, 10px);
  background: transparent;
  color: var(--cc-txt, #16302c);
  font: inherit;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.sc-conv:hover { background: var(--cc-teal-lt, rgba(0, 169, 157, .12)); }
.sc-conv.active {
  background: var(--cc-teal-lt, rgba(0, 169, 157, .12));
  border-color: var(--cc-teal-bd, rgba(0, 169, 157, .34));
}
.sc-conv-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--cc-txt, #16302c);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sc-conv-sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--cc-txt-2, #5c716d);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sc-conv-del {
  position: absolute;
  top: 50%;
  right: 6px;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--cc-txt-3, #5f6f6b);
  cursor: pointer;
  opacity: 0;
  font-size: 14px;
  line-height: 1;
  transition: opacity .12s ease, background .12s ease, color .12s ease;
}
.sc-conv:hover .sc-conv-del { opacity: 1; }
.sc-conv-del:hover { background: rgba(192, 57, 43, .12); color: var(--cc-err, #c0392b); }

.sc-side-empty {
  padding: 24px 14px;
  text-align: center;
  color: var(--cc-txt-3, #5f6f6b);
  font-size: 13px;
}

/* ── Panel de chat (derecha) ───────────────────────────────── */
.sc-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--cc-surface, #fff);
  border: 1px solid var(--cc-line, #e4ebe9);
  border-radius: var(--cc-radius, 14px);
  box-shadow: var(--cc-shadow, 0 1px 3px rgba(11, 31, 29, .06));
  overflow: hidden;
  min-width: 0;
}
.sc-thread {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Estado inicial vacío */
.sc-hero {
  margin: auto;
  max-width: 460px;
  text-align: center;
  color: var(--cc-txt-2, #5c716d);
}
.sc-hero-ico {
  font-size: 40px;
  margin-bottom: 8px;
}
.sc-hero h3 {
  margin: 0 0 6px;
  color: var(--cc-txt, #16302c);
  font-size: 18px;
  font-weight: 700;
}
.sc-hero p { margin: 0; font-size: 14px; line-height: 1.5; }

/* Burbujas */
.sc-msg {
  display: flex;
  max-width: 82%;
}
.sc-msg.user { align-self: flex-end; justify-content: flex-end; }
.sc-msg.bot { align-self: flex-start; }
.sc-bubble {
  padding: 11px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
/* Usuario: teal sólido, texto blanco (contraste AA). */
.sc-msg.user .sc-bubble {
  /* WCAG AA: #fff sobre #00a99d = 2.93:1 (falla). #008077 = 4.82:1 ✅ */
  background: var(--cc-teal-btn, #008077);
  color: #fff;
  border-bottom-right-radius: 4px;
}
/* Asistente: superficie clara con borde, texto navy (contraste AA). */
.sc-msg.bot .sc-bubble {
  background: var(--cc-bg, #f4f7f6);
  color: var(--cc-ink, #0b1f1d);
  border: 1px solid var(--cc-line, #e4ebe9);
  border-bottom-left-radius: 4px;
}

/* Indicador "escribiendo…" */
.sc-typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 13px 16px;
}
.sc-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cc-txt-3, #5f6f6b);
  animation: sc-blink 1.2s infinite ease-in-out both;
}
.sc-typing span:nth-child(2) { animation-delay: .18s; }
.sc-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes sc-blink {
  0%, 80%, 100% { opacity: .25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ── Composer (input) ──────────────────────────────────────── */
.sc-composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 12px;
  border-top: 1px solid var(--cc-line, #e4ebe9);
  background: var(--cc-surface, #fff);
}
.sc-input {
  flex: 1;
  resize: none;
  max-height: 140px;
  min-height: 44px;
  padding: 11px 14px;
  border: 1px solid var(--cc-line, #e4ebe9);
  border-radius: var(--cc-radius-sm, 10px);
  background: var(--cc-bg, #f4f7f6);
  color: var(--cc-ink, #0b1f1d);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
}
.sc-input:focus {
  outline: none;
  border-color: var(--cc-teal, #00a99d);
  background: var(--cc-surface, #fff);
}
.sc-input::placeholder { color: var(--cc-txt-3, #5f6f6b); }
.sc-send {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--cc-radius-sm, 10px);
  background: var(--cc-teal-btn, #008077);
  color: #fff;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.sc-send:hover:not(:disabled) { background: var(--cc-teal-dk, #007a71); }
.sc-send:active:not(:disabled) { transform: scale(.94); }
.sc-send:disabled { opacity: .55; cursor: default; }
.sc-send.is-sending svg { animation: sc-spin .8s linear infinite; }
@keyframes sc-spin { to { transform: rotate(360deg); } }

/* Botón dictar (Web Speech). Sólo se muestra si el navegador lo soporta. */
.sc-mic {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--cc-line, #e4ebe9);
  border-radius: var(--cc-radius-sm, 10px);
  background: var(--cc-bg, #f4f7f6);
  color: var(--cc-teal-btn, #008077);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.sc-mic:hover { background: var(--cc-teal-lt, rgba(0, 169, 157, .12)); }
.sc-mic:active { transform: scale(.94); }
.sc-mic:focus-visible { outline: 2px solid var(--cc-teal-btn, #008077); outline-offset: 2px; }
.sc-mic.is-listening {
  background: var(--cc-teal-btn, #008077);
  color: #fff;
  border-color: var(--cc-teal-btn, #008077);
  animation: sc-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes sc-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 169, 157, .45); }
  50% { box-shadow: 0 0 0 5px rgba(0, 169, 157, 0); }
}

/* ── Responsive (mobile) ───────────────────────────────────── */
@media (max-width: 760px) {
  /* dvh sigue al teclado/URL bar: el composer nunca queda tapado. */
  .cc-chat-window { height: 100dvh; }
  .cc-chat-mount .sc-wrap { height: 100%; }
  .sc-wrap {
    flex-direction: column;
    height: 100%;
    min-height: 0;
  }
  .sc-side {
    flex: 0 0 auto;
    max-height: 180px;
  }
  /* main ocupa el resto; el thread hace scroll y el composer queda fijo abajo. */
  .sc-main {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    display: flex;
    flex-direction: column;
  }
  .sc-thread { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
  .sc-composer {
    flex: 0 0 auto;
    position: sticky;
    bottom: 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
  .sc-msg { max-width: 92%; }
}
