/* ColegiApp — Widget de chat IA
   Vanilla CSS, todos los selectores con prefijo .cg-chat- para no
   chocar con los estilos de la landing. */

.cg-chat-root {
  --cg-primary: oklch(68% 0.19 32);
  --cg-primary-dark: oklch(58% 0.19 32);
  --cg-bg: #ffffff;
  --cg-fg: #0f172a;
  --cg-muted: #64748b;
  --cg-border: #e2e8f0;
  --cg-user-bg: oklch(68% 0.19 32);
  --cg-user-fg: #ffffff;
  --cg-bot-bg: #f1f5f9;
  --cg-bot-fg: #0f172a;

  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  color: var(--cg-fg);
}

/* ── Botón flotante ─────────────────────────────────────────────────────── */
.cg-chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--cg-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 10px 25px oklch(68% 0.19 32 / 0.35), 0 4px 10px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: cg-pulse 2.5s ease-in-out infinite;
}
.cg-chat-fab:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 14px 30px oklch(68% 0.19 32 / 0.45), 0 6px 14px rgba(0, 0, 0, 0.12);
}
.cg-chat-fab svg { width: 26px; height: 26px; }

@keyframes cg-pulse {
  0%, 100% { box-shadow: 0 10px 25px oklch(68% 0.19 32 / 0.35), 0 0 0 0 oklch(68% 0.19 32 / 0.5); }
  50%      { box-shadow: 0 10px 25px oklch(68% 0.19 32 / 0.35), 0 0 0 12px oklch(68% 0.19 32 / 0); }
}

/* ── Panel del chat ─────────────────────────────────────────────────────── */
.cg-chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 600px;
  max-height: calc(100vh - 48px);
  background: var(--cg-bg);
  border-radius: 20px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  transform-origin: bottom right;
  animation: cg-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.cg-chat-panel.cg-open { display: flex; }

@keyframes cg-pop {
  from { opacity: 0; transform: scale(0.85) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

@media (max-width: 480px) {
  .cg-chat-panel {
    bottom: 0; right: 0; left: 0; top: 0;
    width: 100vw; max-width: 100vw;
    height: 100vh; max-height: 100vh;
    border-radius: 0;
  }
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.cg-chat-header {
  background: linear-gradient(135deg, var(--cg-primary), var(--cg-primary-dark));
  color: #fff;
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.cg-chat-header-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.cg-chat-header-avatar svg { width: 20px; height: 20px; }
.cg-chat-header-text { flex: 1; min-width: 0; }
.cg-chat-header-title { font-size: 15px; font-weight: 700; line-height: 1.2; }
.cg-chat-header-sub { font-size: 12px; opacity: 0.85; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.cg-chat-header-sub::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: #4ade80; box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
  animation: cg-dot 1.8s ease-out infinite;
}
@keyframes cg-dot {
  0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7); }
  100% { box-shadow: 0 0 0 8px rgba(74, 222, 128, 0); }
}
.cg-chat-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s;
}
.cg-chat-close:hover { background: rgba(255, 255, 255, 0.25); }
.cg-chat-close svg { width: 16px; height: 16px; }

/* ── Mensajes ───────────────────────────────────────────────────────────── */
.cg-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: #fafbfc;
  /* Evita que el scroll se "escape" a la landing al llegar al tope/fondo. */
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.cg-chat-msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  animation: cg-msg-in 0.2s ease-out;
}
@keyframes cg-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cg-chat-msg.cg-user {
  align-self: flex-end;
  background: var(--cg-user-bg);
  color: var(--cg-user-fg);
  border-bottom-right-radius: 6px;
}
.cg-chat-msg.cg-bot {
  align-self: flex-start;
  background: var(--cg-bot-bg);
  color: var(--cg-bot-fg);
  border-bottom-left-radius: 6px;
}
.cg-chat-msg.cg-bot a { color: var(--cg-primary); text-decoration: underline; }

.cg-chat-typing {
  align-self: flex-start;
  background: var(--cg-bot-bg);
  padding: 14px 18px;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
  display: inline-flex;
  gap: 4px;
}
.cg-chat-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cg-muted);
  animation: cg-typing 1.2s ease-in-out infinite;
}
.cg-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.cg-chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cg-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Input ──────────────────────────────────────────────────────────────── */
.cg-chat-input-wrap {
  border-top: 1px solid var(--cg-border);
  padding: 12px 14px;
  background: #fff;
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.cg-chat-input {
  flex: 1;
  border: 1px solid var(--cg-border);
  border-radius: 14px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cg-chat-input:focus {
  border-color: var(--cg-primary);
  box-shadow: 0 0 0 3px oklch(68% 0.19 32 / 0.15);
}
.cg-chat-send {
  background: var(--cg-primary);
  color: #fff;
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}
.cg-chat-send:hover:not(:disabled) { background: var(--cg-primary-dark); }
.cg-chat-send:active:not(:disabled) { transform: scale(0.92); }
.cg-chat-send:disabled { opacity: 0.4; cursor: not-allowed; }
.cg-chat-send svg { width: 18px; height: 18px; }

/* Botón de voz (micrófono) */
.cg-chat-mic {
  background: var(--cg-bot-bg);
  color: var(--cg-muted);
  border: 1px solid var(--cg-border);
  width: 40px; height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.cg-chat-mic:hover:not(:disabled) { color: var(--cg-primary); border-color: var(--cg-primary); }
.cg-chat-mic:active:not(:disabled) { transform: scale(0.92); }
.cg-chat-mic svg { width: 18px; height: 18px; }
/* Grabando: rojo pulsante */
.cg-chat-mic.cg-recording {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
  animation: cg-mic-pulse 1.3s ease-in-out infinite;
}
@keyframes cg-mic-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  70%  { box-shadow: 0 0 0 9px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}
@media (prefers-reduced-motion: reduce) { .cg-chat-mic.cg-recording { animation: none; } }

.cg-chat-footer {
  text-align: center;
  font-size: 11px;
  color: var(--cg-muted);
  padding: 8px 14px 10px;
  background: #fff;
}
.cg-chat-footer a { color: var(--cg-primary); text-decoration: none; font-weight: 600; }
