/* MAFS Coach widget — brand-locked palette (confirmed by Tina 2026-04-16).
   Rendered as isolated .mafs-coachbox shell so we don't collide with the classroom CSS. */

.mafs-coachbox,
.mafs-coachbox * {
  box-sizing: border-box;
}

.mafs-coachbox {
  --mc-cream: #f5f0e8;
  --mc-charcoal: #2d2a26;
  --mc-wisteria: #8b7da8;
  --mc-wisteria-dark: #6b5f8a;
  --mc-wisteria-soft: #e7e2ed;
  --mc-sage: #7d9b76;
  --mc-terracotta: #c0614a;
  --mc-line: #d9d2c5;
  --mc-ink-soft: #5a544c;
  --mc-shadow: 0 20px 60px rgba(45, 42, 38, 0.18);

  position: fixed;
  inset: 0 0 0 auto;
  width: min(440px, 100vw);
  background: var(--mc-cream);
  color: var(--mc-charcoal);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  z-index: 2147483646;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: var(--mc-shadow);
  border-left: 1px solid var(--mc-line);
}

.mafs-coachbox[data-open="true"] {
  transform: translateX(0);
}

.mafs-coachbox__backdrop {
  position: fixed;
  inset: 0;
  background: rgba(45, 42, 38, 0.18);
  z-index: 2147483645;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.mafs-coachbox__backdrop[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

.mafs-coachbox__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  background: linear-gradient(135deg, var(--mc-wisteria-dark), var(--mc-wisteria));
  color: #fff;
  flex-shrink: 0;
}

.mafs-coachbox__title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.mafs-coachbox__title b {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.mafs-coachbox__title span {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}

.mafs-coachbox__close {
  all: unset;
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 20px;
  line-height: 1;
  transition: background 0.15s ease;
}

.mafs-coachbox__close:hover,
.mafs-coachbox__close:focus-visible {
  background: rgba(255, 255, 255, 0.18);
}

.mafs-coachbox__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--mc-line) transparent;
}

.mafs-coachbox__body::-webkit-scrollbar {
  width: 8px;
}
.mafs-coachbox__body::-webkit-scrollbar-thumb {
  background: var(--mc-line);
  border-radius: 4px;
}

.mafs-coachbox__intro {
  background: var(--mc-wisteria-soft);
  border: 1px solid rgba(139, 125, 168, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 13px;
  color: var(--mc-charcoal);
}

.mafs-coachbox__intro b {
  color: var(--mc-wisteria-dark);
}

.mafs-coachbox__msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 94%;
}

.mafs-coachbox__msg[data-role="user"] {
  align-self: flex-end;
}

.mafs-coachbox__msg[data-role="assistant"] {
  align-self: flex-start;
}

.mafs-coachbox__bubble {
  padding: 10px 14px;
  border-radius: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.55;
}

.mafs-coachbox__msg[data-role="user"] .mafs-coachbox__bubble {
  background: var(--mc-wisteria);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.mafs-coachbox__msg[data-role="assistant"] .mafs-coachbox__bubble {
  background: #fff;
  border: 1px solid var(--mc-line);
  color: var(--mc-charcoal);
  border-bottom-left-radius: 4px;
}

.mafs-coachbox__bubble[data-kind="error"] {
  background: #fdf1ee !important;
  border: 1px solid var(--mc-terracotta);
  color: var(--mc-terracotta);
}

.mafs-coachbox__bubble[data-kind="rate"] {
  background: #fbf6eb !important;
  border: 1px solid #d9b86a;
  color: #7a5a14;
}

.mafs-coachbox__typing {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.mafs-coachbox__typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--mc-ink-soft);
  opacity: 0.6;
  animation: mafs-coach-pulse 1.2s infinite ease-in-out;
}
.mafs-coachbox__typing span:nth-child(2) {
  animation-delay: 0.15s;
}
.mafs-coachbox__typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes mafs-coach-pulse {
  0%, 100% { transform: translateY(0); opacity: 0.4; }
  50% { transform: translateY(-3px); opacity: 1; }
}

.mafs-coachbox__input {
  display: flex;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--mc-line);
  background: var(--mc-cream);
  flex-shrink: 0;
}

.mafs-coachbox__textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--mc-line);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  color: var(--mc-charcoal);
  background: #fff;
  max-height: 160px;
  min-height: 42px;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.15s ease;
}

.mafs-coachbox__textarea:focus {
  border-color: var(--mc-wisteria);
}

.mafs-coachbox__textarea::placeholder {
  color: var(--mc-ink-soft);
  opacity: 0.7;
}

.mafs-coachbox__send {
  all: unset;
  cursor: pointer;
  padding: 0 18px;
  border-radius: 12px;
  background: var(--mc-wisteria);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  min-height: 42px;
  transition: background 0.15s ease, transform 0.1s ease;
  display: grid;
  place-items: center;
  user-select: none;
}

.mafs-coachbox__send:hover:not([disabled]) {
  background: var(--mc-wisteria-dark);
}
.mafs-coachbox__send:active:not([disabled]) {
  transform: translateY(1px);
}

.mafs-coachbox__send[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.mafs-coachbox__footnote {
  font-size: 11px;
  color: var(--mc-ink-soft);
  text-align: center;
  padding: 0 20px 10px;
  background: var(--mc-cream);
  flex-shrink: 0;
}

@media (max-width: 520px) {
  .mafs-coachbox {
    width: 100vw;
    max-width: 100vw;
  }
}

/* ─── Voice UI ────────────────────────────────────────────────────────── */
.mafs-coachbox__headbtns {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.mafs-coachbox__mic {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  border: 1px solid rgba(255, 255, 255, 0.24);
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.mafs-coachbox__mic:hover,
.mafs-coachbox__mic:focus-visible {
  background: rgba(255, 255, 255, 0.28);
}

.mafs-coachbox__mic:active {
  transform: translateY(1px);
}

.mafs-coachbox__mic-dot {
  display: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ff4d4d;
  box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.7);
}

.mafs-coachbox__mic[data-state="active"] {
  background: rgba(192, 97, 74, 0.9);
  border-color: rgba(255, 255, 255, 0.45);
}

.mafs-coachbox__mic[data-state="active"] .mafs-coachbox__mic-dot {
  display: inline-block;
  animation: mafs-coach-pulsedot 1.2s infinite ease-out;
}

.mafs-coachbox__mic[data-state="active"] .mafs-coachbox__mic-icon {
  display: none;
}

.mafs-coachbox__mic[data-state="starting"],
.mafs-coachbox__mic[data-state="ending"] {
  opacity: 0.75;
  pointer-events: none;
}

.mafs-coachbox__mic-icon {
  font-size: 14px;
  line-height: 1;
}

.mafs-coachbox__mic-label {
  font-family: inherit;
}

@keyframes mafs-coach-pulsedot {
  0%   { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0.8); }
  70%  { box-shadow: 0 0 0 8px rgba(255, 77, 77, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 77, 77, 0); }
}

/* Voice indicator row — sits below header, above body */
.mafs-coachbox__voice {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 20px;
  background: var(--mc-wisteria-soft);
  border-bottom: 1px solid var(--mc-line);
  font-size: 12.5px;
  color: var(--mc-wisteria-dark);
  font-weight: 600;
  flex-shrink: 0;
}

.mafs-coachbox__voice[data-state="user"],
.mafs-coachbox__voice[data-state="ai"] {
  display: flex;
}

.mafs-coachbox__voice-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  animation: mafs-coach-voice-breathe 1.6s infinite ease-in-out;
}

.mafs-coachbox__voice[data-state="user"] .mafs-coachbox__voice-dot {
  background: var(--mc-sage);
  box-shadow: 0 0 0 0 rgba(125, 155, 118, 0.6);
}

.mafs-coachbox__voice[data-state="ai"] .mafs-coachbox__voice-dot {
  background: var(--mc-wisteria);
  box-shadow: 0 0 0 0 rgba(139, 125, 168, 0.6);
}

@keyframes mafs-coach-voice-breathe {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50%      { transform: scale(1.35); opacity: 1; box-shadow: 0 0 0 6px rgba(139, 125, 168, 0); }
}

/* Inline toast — subtle, auto-hides */
.mafs-coachbox__toast {
  position: absolute;
  left: 50%;
  bottom: 82px;
  transform: translateX(-50%) translateY(12px);
  max-width: 88%;
  background: var(--mc-charcoal);
  color: var(--mc-cream);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  z-index: 2;
  text-align: center;
}

.mafs-coachbox__toast[data-visible="true"] {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Hide mic label on very narrow panels to keep header tidy */
@media (max-width: 380px) {
  .mafs-coachbox__mic-label { display: none; }
  .mafs-coachbox__mic { padding: 6px 9px; }
}
