/* ============================================================
   AI TUTOR — in-quiz floating chat widget
   Practice mode only. Styled with UPDC design tokens.
   ============================================================ */

/* The `hidden` attribute must win over the flex/inline-flex display below. */
.tutor-launcher[hidden],
.tutor-panel[hidden] { display: none !important; }

/* Launcher (collapsed) ------------------------------------- */
.tutor-launcher {
  position: fixed;
  right: var(--space-6);
  bottom: 88px;                 /* clear the fixed quiz bottom-nav */
  z-index: 250;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-body-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--color-white);
  background: var(--color-green);
  border: 2px solid var(--color-green);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-clay-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.tutor-launcher:hover {
  background: var(--color-blue);
  border-color: var(--color-blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow-clay-lg);
}
.tutor-launcher:focus-visible {
  outline: 3px solid var(--color-green);
  outline-offset: 2px;
}
.tutor-launcher__icon { display: inline-flex; }
.tutor-launcher__icon svg { width: 20px; height: 20px; }
.tutor-launcher__avatar { flex-shrink: 0; }

/* Panel (expanded) ----------------------------------------- */
.tutor-panel {
  position: fixed;
  right: var(--space-6);
  bottom: 88px;
  z-index: 260;
  display: flex;
  flex-direction: column;
  width: 384px;
  max-width: calc(100vw - 2 * var(--space-4));
  height: min(72vh, 620px);
  background: var(--color-surface-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-clay-xl);
  overflow: hidden;
  animation: tutorPop var(--duration-normal) var(--easing-smooth);
}
@keyframes tutorPop {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.tutor-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}
.tutor-panel__title {
  display: flex;
  align-items: center;
  font-family: var(--font-display);
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-heading-sm);
  color: var(--color-text-primary);
}
.tutor-panel__title svg { width: 20px; height: 20px; color: var(--color-green); }
.tutor-panel__title updc-avatar { flex-shrink: 0; }

/* Header avatar slot: empty in the intro state (avatar shows only in the middle);
   expands and pushes the title text aside once the avatar docks after "Explain". */
.tutor-head-slot {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  width: 0;
  margin-right: 0;
  overflow: hidden;
  transition: width 480ms var(--easing-smooth), margin-right 480ms var(--easing-smooth);
}
.tutor-panel.is-chat .tutor-head-slot { width: 28px; margin-right: var(--space-2); }
@media (prefers-reduced-motion: reduce) { .tutor-head-slot { transition: none; } }
.tutor-panel__sub {
  margin-top: 2px;
  font-size: var(--text-body-xs);
  color: var(--color-text-muted);
}
.tutor-panel__close {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.tutor-panel__close:hover { background: var(--color-surface-secondary); color: var(--color-text-primary); }
.tutor-panel__close svg { width: 18px; height: 18px; }

/* Messages area ------------------------------------------- */
.tutor-panel__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-surface);
}

.tutor-msg {
  max-width: 88%;
  padding: var(--space-3) var(--space-3-5);
  border-radius: var(--radius-lg);
  font-size: var(--text-body-sm);
  line-height: var(--line-height-relaxed);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tutor-msg--user {
  align-self: flex-end;
  background: var(--color-green);
  color: var(--color-white);
  border-bottom-right-radius: var(--radius-sm);
}
.tutor-msg--bot {
  align-self: flex-start;
  background: var(--color-surface-card);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: var(--radius-sm);
}
.tutor-msg--error {
  align-self: stretch;
  max-width: 100%;
  background: var(--color-error-bg);
  color: var(--color-error-text);
  border: 1px solid var(--color-error);
}

/* Empty / intro state ------------------------------------- */
.tutor-empty {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  text-align: center;
}
.tutor-empty__avatar { margin-bottom: var(--space-1); }
.tutor-empty__title {
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-body-md);
  color: var(--color-text-primary);
}
.tutor-empty__text {
  font-size: var(--text-body-sm);
  color: var(--color-text-secondary);
  max-width: 42ch;
}

/* Typing indicator ---------------------------------------- */
.tutor-typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.tutor-typing i {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--color-text-muted);
  animation: tutorBlink 1.2s infinite ease-in-out both;
}
.tutor-typing i:nth-child(2) { animation-delay: 0.15s; }
.tutor-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes tutorBlink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

/* Input row ------------------------------------------------ */
.tutor-panel__input {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface-card);
}
.tutor-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: var(--space-2-5) var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-body-sm);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background: var(--color-surface-card);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  resize: none;
  transition: all var(--transition-fast);
}
.tutor-input:focus { outline: none; border-color: var(--color-green); box-shadow: var(--shadow-focus); }
.tutor-input:disabled { opacity: 0.6; cursor: not-allowed; }

.tutor-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-green);
  color: var(--color-white);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.tutor-send:hover:not(:disabled) { background: var(--color-blue); }
.tutor-send:disabled { opacity: 0.5; cursor: not-allowed; }
.tutor-send svg { width: 20px; height: 20px; }

/* Mobile: dock as a bottom sheet -------------------------- */
@media (max-width: 480px) {
  .tutor-panel {
    right: 0; left: 0; bottom: 0;
    width: 100%;
    max-width: 100%;
    height: 82vh;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  }
  .tutor-launcher { right: var(--space-4); bottom: 76px; }
}

@media (prefers-reduced-motion: reduce) {
  .tutor-panel { animation: none; }
  .tutor-typing i { animation: none; opacity: 0.5; }
}
