/* chat.css — Panel del tutor: burbujas de chat, citas, quiz, campo de entrada y estados (pensando, error). */

.chat-shell {
  display: flex; flex-direction: column;
  width: calc(100% - 32px); max-width: var(--chatw);
  margin: 8px auto 0;
  padding: 18px 20px 14px;
  background: var(--bg); color: var(--text);
  border-radius: 12px;
  box-shadow: 0 20px 50px rgb(0 0 0 / 0.35);
  border-top: 5px solid var(--orange);
}

.chat-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
}

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
}
.segmented__btn {
  border: 0; background: transparent; color: var(--text-muted);
  font: inherit; font-size: 0.875rem; font-weight: 600;
  padding: 6px 14px; border-radius: 4px; cursor: pointer;
}
.segmented__btn:hover { color: var(--text); }
.segmented__btn[aria-pressed="true"] { background: var(--orange); color: var(--cream); }

.mode-banner {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 5px 12px;
  font-size: 0.875rem; color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
}
.mode-banner strong { color: var(--text); }
.mode-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
body[data-mode="quiz"] .mode-dot { background: var(--mode-quiz); }
body[data-mode="free"] .mode-dot { background: var(--olive); }

.disclaimer { margin: 6px 0 0; font-size: 0.78rem; color: var(--text-muted); text-align: center; }

.chat-log {
  height: min(64vh, 620px);
  min-height: 320px;
  overflow-y: auto;
  position: relative; /* offsetTop de los mensajes relativo al registro */
  padding: 8px 2px 16px;
  overscroll-behavior: contain;
}

/* ------------------------------ mensajes ------------------------------ */

.msg {
  display: flex; gap: 10px; align-items: flex-start;
  margin: 14px 0;
  animation: msg-in 0.22s ease-out;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg__avatar {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 50%;
  font-weight: 700; font-size: 0.85rem;
  background: var(--accent-soft); color: var(--accent);
}
.msg__body { min-width: 0; max-width: min(640px, 100%); display: flex; flex-direction: column; }
.msg__role { font-size: 0.75rem; font-weight: 600; color: var(--text-muted); margin: 0 4px 3px; }

.bubble {
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px var(--radius) var(--radius) var(--radius);
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
}
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble p { margin: 0.45em 0; }

/* estudiante: a la derecha */
.msg--student { flex-direction: row-reverse; }
.msg--student .msg__body { align-items: flex-end; }
.msg--student .msg__avatar { background: var(--olive-soft); color: var(--olive); }
.msg--student .bubble {
  background: var(--accent); color: var(--accent-contrast); border-color: var(--accent);
  border-radius: var(--radius) 4px var(--radius) var(--radius);
  white-space: pre-wrap;
}

/* estados del tutor */
.msg--no_support .bubble,
.msg--graded_task .bubble { border-left: 4px solid var(--warn); }
.msg--ambiguous .bubble,
.msg--clarify .bubble { border-left: 4px solid var(--mode-quiz); }
.msg--role .bubble { border-left: 4px solid var(--olive); }
.msg--welcome .bubble,
.msg--summary .bubble { background: var(--bg-elev); }
.msg--question .bubble { border-top: 3px solid var(--mode-quiz); }

.card-title { margin: 0 0 6px; font-size: 1.2rem; }

.system-note {
  margin: 10px auto; padding: 4px 12px; width: fit-content; max-width: 100%;
  font-size: 0.8rem; color: var(--text-muted); text-align: center;
  background: var(--surface-2); border-radius: 999px;
}

/* ------------------------------ contenido ------------------------------ */

.quote {
  margin: 8px 0; padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-family: var(--font-serif);
}

.cite {
  display: inline-flex; align-items: center;
  padding: 0 6px; margin-left: 2px;
  font: 700 0.8rem/1.6 var(--font-sans);
  color: var(--accent-strong); background: var(--surface);
  border: 1px solid var(--accent); border-radius: 6px;
  cursor: pointer; vertical-align: baseline;
}
.cite:hover { background: var(--accent); color: var(--accent-contrast); }

.readings { margin: 8px 0; padding-left: 22px; }
.readings li { margin: 6px 0; }
.readings li::marker { font-weight: 700; color: var(--mode-quiz); }

.note {
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--warn-soft); border: 1px dashed var(--warn);
  font-size: 0.925rem;
}

.followup {
  margin-top: 10px; padding: 10px 12px;
  background: var(--olive-soft); border-radius: var(--radius-sm);
}
.followup__label {
  display: block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--olive);
}
.followup p { margin: 2px 0 0; }

.topics { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; padding: 0; margin: 8px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; font: inherit; font-size: 0.875rem; text-align: left;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; cursor: pointer;
}
.chip:hover { border-color: var(--accent); }
.chip__id { font-weight: 700; color: var(--accent-strong); }

/* fragmentos de respaldo (expandibles) */
.sources {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px dashed var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.sources__label { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.source { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev); }
.source summary {
  cursor: pointer; padding: 6px 10px; font-size: 0.875rem;
  list-style: none; display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.source summary::-webkit-details-marker { display: none; }
.source summary::before { content: "▸"; color: var(--text-muted); transition: transform 0.15s; }
.source[open] summary::before { transform: rotate(90deg); }
.source__id {
  font-weight: 700; color: var(--accent-contrast); background: var(--accent);
  border-radius: 6px; padding: 0 6px; font-size: 0.8rem;
}
.source__tag {
  font-size: 0.72rem; padding: 0 6px; border-radius: 6px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn);
}
.source__body { padding: 2px 12px 10px; font-size: 0.9rem; color: var(--text); }
.source__caption { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; color: var(--text-muted); margin-bottom: 0; }

/* ------------------------------ quiz ------------------------------ */

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700;
  background: var(--mode-quiz-soft); color: var(--mode-quiz);
}
.question { font-size: 1.05rem; font-weight: 600; }

.options { display: grid; gap: 8px; margin: 10px 0 4px; }
.option {
  display: flex; align-items: flex-start; gap: 10px; width: 100%;
  padding: 10px 12px; text-align: left; font: inherit; font-size: 0.95rem;
  color: var(--text); background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
}
.option:hover:not(:disabled) { border-color: var(--mode-quiz); background: var(--mode-quiz-soft); }
.option:disabled { cursor: default; opacity: 0.6; }
.option--chosen:disabled { opacity: 1; border-color: var(--mode-quiz); background: var(--mode-quiz-soft); }
.option__key {
  flex: none; display: grid; place-items: center;
  width: 24px; height: 24px; border-radius: 6px;
  font-size: 0.8rem; font-weight: 700;
  background: var(--surface-2); color: var(--text-muted);
}

.verdict { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.verdict::before {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  font-size: 0.8rem;
}
.verdict--correct { color: var(--ok); }
.verdict--correct::before { content: "✓"; background: var(--ok-soft); }
.verdict--partial { color: var(--warn); }
.verdict--partial::before { content: "½"; background: var(--warn-soft); }
.verdict--incorrect { color: var(--bad); }
.verdict--incorrect::before { content: "✕"; background: var(--bad-soft); }
.verdict--skipped { color: var(--text-muted); }
.verdict--skipped::before { content: "→"; background: var(--surface-2); }

.score { margin: 8px 0; }
.score__meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.score__meter span { display: block; height: 100%; background: linear-gradient(90deg, var(--olive), var(--ok)); border-radius: inherit; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; max-width: 360px; }
.field label { font-size: 0.85rem; font-weight: 600; }

/* ------------------------------ pensando ------------------------------ */

.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted);
  animation: blink 1.1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* ------------------------------ campo de entrada ------------------------------ */

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px; margin-top: 4px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 22px;
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer__input {
  flex: 1; resize: none; min-height: 40px; max-height: 160px;
  padding: 9px 10px; border: 0; background: transparent;
  font: inherit; color: var(--text);
}
.composer__input:focus { outline: none; }
.composer__input::placeholder { color: var(--text-muted); }
.composer__send { flex: none; }
.composer__hint { margin: 4px 12px 0; }

@media (max-width: 720px) {
  .msg__body { max-width: calc(100% - 42px); }
  .composer__send span { display: none; }
  .composer__send { width: 44px; padding: 0; }
  .composer__hint { display: none; }
}
