/* ==========================================================================
   OgbonMath — Inline Conversational Tutor (Phase 4)
   --------------------------------------------------------------------------
   The welcome screen's Ask band, evolved. A compact multi-turn chat that
   lives under the Continue hero. Lesson-aware, Claude-styled, uses
   window.TutorAI under the hood.

   Scope: mounts inside any container (typically .wv2) via InlineTutor.mount().
   ========================================================================== */

.itr {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  font-family: var(--font-sans);
}

/* ==========================================================================
   Prompt bar — the always-visible input row at the top
   ==========================================================================
*/
.itr-bar {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: 12px 14px 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--bdr);
  border-radius: var(--radius-lg);
  transition: border-color var(--dur-fast) var(--ease-calm),
              box-shadow var(--dur) var(--ease-calm);
}

.itr-bar:focus-within {
  border-color: var(--ac);
  box-shadow: 0 0 0 3px var(--ac-ring);
}

.itr-bar-icon {
  color: var(--tx2);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  padding-bottom: 6px;
}

.itr-input {
  flex: 1;
  min-width: 0;
  background: transparent !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  padding: 4px 0 !important;
  margin: 0;
  font-family: var(--font-sans) !important;
  font-size: var(--fs-base) !important;
  line-height: var(--lh-normal) !important;
  color: var(--tx) !important;
  resize: none;
  overflow-y: auto;
  max-height: 160px;
}

.itr-input::placeholder {
  color: var(--tx3);
}

.itr-submit {
  background: var(--ac);
  color: var(--ac-tx);
  border: none;
  border-radius: var(--radius-md);
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--dur-fast), transform var(--dur-fast);
}

.itr-submit:hover { background: var(--ac2); }
.itr-submit:active { transform: scale(var(--active-scale)); }
.itr-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ==========================================================================
   Context chip — "Scoped to: [lesson]" shown above the bar when applicable
   ==========================================================================
*/
.itr-context {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 6px;
  background: var(--ac-soft);
  border: 1px solid var(--ac);
  border-radius: var(--radius-full);
  color: var(--ac);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  font-family: var(--font-sans);
  align-self: flex-start;
  line-height: 1.4;
  max-width: 100%;
}

.itr-context-icon {
  font-size: 12px;
  line-height: 1;
}

.itr-context-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   Thread — the conversation itself
   ==========================================================================
*/
.itr-thread {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding-top: var(--sp-2);
}

.itr-thread:empty { display: none; }

/* ==========================================================================
   Message — shared container for user + AI
   ==========================================================================
*/
.itr-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 85%;
  animation: itr-msg-in var(--dur) var(--ease-calm);
}

@keyframes itr-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.itr-msg-role {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-widest);
  text-transform: uppercase;
  color: var(--tx3);
  padding: 0 2px;
}

.itr-msg-body {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-family: var(--font-serif);
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
  color: var(--tx);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.itr-msg-body > p { margin: 0 0 0.6em; }
.itr-msg-body > p:last-child { margin-bottom: 0; }

/* User message — right-aligned, warm accent tint */
.itr-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.itr-msg-user .itr-msg-role { text-align: right; color: var(--ac); }

.itr-msg-user .itr-msg-body {
  background: var(--ac-soft);
  border: 1px solid var(--ac);
  color: var(--tx);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: var(--lh-normal);
}

/* AI message — left-aligned, paper card */
.itr-msg-ai {
  align-self: flex-start;
}

.itr-msg-ai .itr-msg-body {
  background: var(--bg2);
  border: 1px solid var(--bdr);
}

.itr-msg-ai .itr-msg-body strong { font-weight: var(--fw-semibold); }
.itr-msg-ai .itr-msg-body em { font-style: italic; }
.itr-msg-ai .itr-msg-body code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg3);
  padding: 1px 5px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--bdr);
}

.itr-msg-ai .katex { color: var(--tx); }
.itr-msg-ai .katex-display {
  margin: 0.6em 0;
  padding: 0;
  background: transparent;
}

/* Error state — muted red-tinted AI message */
.itr-msg-error .itr-msg-body {
  background: var(--rd-bg);
  border-color: var(--rd);
  color: var(--tx);
  font-family: var(--font-sans);
}

/* ==========================================================================
   Typing indicator — three bouncing dots while AI thinks
   ==========================================================================
*/
.itr-msg-typing .itr-msg-body {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 14px 16px;
}

.itr-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tx2);
  animation: itr-typing 1.2s var(--ease-calm) infinite;
}

.itr-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.itr-typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes itr-typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ==========================================================================
   Message actions — Copy, Open in full tutor, etc.
   ==========================================================================
*/
.itr-msg-actions {
  display: flex;
  gap: var(--sp-1);
  padding-top: 4px;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-calm);
}

.itr-msg-ai:hover .itr-msg-actions,
.itr-msg-ai:focus-within .itr-msg-actions {
  opacity: 1;
}

.itr-msg-action {
  background: transparent;
  border: 1px solid var(--bdr);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  color: var(--tx2);
  cursor: pointer;
  transition: color var(--dur-fast), border-color var(--dur-fast), background var(--dur-fast);
}

.itr-msg-action:hover {
  color: var(--ac);
  border-color: var(--ac);
  background: var(--ac-soft);
}

/* ==========================================================================
   Thread footer — visible when thread has messages
   ==========================================================================
*/
.itr-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) 2px 0;
  font-size: var(--fs-xs);
  color: var(--tx3);
  font-family: var(--font-sans);
}

.itr-foot:empty { display: none; }

.itr-foot-btn {
  background: transparent;
  border: none;
  color: var(--tx2);
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: color var(--dur-fast), background var(--dur-fast);
}

.itr-foot-btn:hover {
  color: var(--ac);
  background: var(--ac-soft);
}

/* ==========================================================================
   Not-configured state — soft hint when AI isn't wired up
   ==========================================================================
*/
.itr-disabled-hint {
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px dashed var(--bdr);
  border-radius: var(--radius-md);
  color: var(--tx2);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  text-align: center;
}

.itr-disabled-hint a {
  color: var(--ac);
  text-decoration: none;
  font-weight: var(--fw-semibold);
  cursor: pointer;
}

.itr-disabled-hint a:hover { text-decoration: underline; }

/* ==========================================================================
   Mobile
   ==========================================================================
*/
@media (max-width: 560px) {
  .itr-msg { max-width: 95%; }
  .itr-msg-actions { opacity: 1; } /* always show on mobile (no hover) */
  .itr-input { font-size: var(--fs-base) !important; }
  .itr-msg-body { font-size: var(--fs-sm); }
}
