/* Tutor Interface - Glassmorphism & Modern UI */

:root {
  --tutor-bg: #f8fafc;
  --tutor-card-bg: rgba(255, 255, 255, 0.85);
  --tutor-glass-border: 1px solid rgba(255, 255, 255, 0.5);
  --tutor-blur: 12px;
  --tutor-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --primary-gradient: linear-gradient(135deg, #6366f1, #a855f7);
  --primary-color: #6366f1;
  --text-dark: #1e293b;
  --text-gray: #64748b;
}

.tutor-container {
  display: grid;
  grid-template-columns: 1fr 400px; /* Split view: Content | Chat */
  gap: 1.5rem;
  height: 85vh;
  padding: 1rem;
  font-family: 'Inter', sans-serif;
  color: var(--text-dark);
}

/* Left Panel: Content / Whiteboard */
.tutor-content-panel {
  background: var(--tutor-card-bg);
  backdrop-filter: blur(var(--tutor-blur));
  -webkit-backdrop-filter: blur(var(--tutor-blur));
  border: var(--tutor-glass-border);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--tutor-shadow);
  overflow-y: auto;
  position: relative;
  transition: all 0.3s ease;
}

/* Question Styling */
.question-header {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.question-text {
  font-size: 1.1rem;
  line-height: 1.6;
  color: #334155;
  margin-bottom: 1.5rem;
}

/* Right Panel: Chat Interface */
.tutor-chat-panel {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-radius: 20px;
  box-shadow: var(--tutor-shadow);
  overflow: hidden;
  border: 1px solid #e2e8f0;
}

.chat-header {
  padding: 1rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
}

.bot-status {
  font-size: 0.85rem;
  color: var(--text-gray);
}
.bot-status.thinking {
  color: #a855f7;
  animation: pulse 1.5s infinite;
}

.chat-log {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  background: #fdfdfd;
  scroll-behavior: smooth;
}

/* Messages */
.message {
  margin-bottom: 1rem;
  max-width: 85%;
  animation: slideIn 0.3s ease-out;
}

.message.bot {
  align-self: flex-start;
}

.message.user {
  align-self: flex-end;
  margin-left: auto;
}

.msg-bubble {
  padding: 0.8rem 1.2rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.5;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.message.bot .msg-bubble {
  background: #f1f5f9;
  color: #334155;
  border-bottom-left-radius: 4px;
}

.message.user .msg-bubble {
  background: var(--primary-gradient);
  color: white;
  border-bottom-right-radius: 4px;
}

/* Interactive Elements (Envelopes) */
.tutor-card,
.tutor-mcq-card,
.tutor-timed-card,
.tutor-fillblank-card,
.tutor-incdec-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
  margin-top: 0.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.tutor-card-lead {
  margin-bottom: 0.85rem;
  color: #334155;
  font-weight: 600;
}

.tutor-card-body {
  color: #334155;
}

.tutor-choice-stack,
.tutor-choice-grid {
  display: grid;
  gap: 0.6rem;
}

.tutor-choice-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tutor-choice-btn,
.tutor-submit-btn {
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  background: white;
  padding: 0.8rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1e293b;
  transition: all 0.2s;
}

.tutor-choice-btn:hover,
.tutor-submit-btn:hover {
  border-color: var(--primary-color);
  background: #f5f3ff;
}

.tutor-choice-btn.selected,
.tutor-submit-btn:disabled {
  background: #eef2ff;
  border-color: #818cf8;
}

.tutor-choice-btn.disabled,
.tutor-choice-btn:disabled,
.tutor-submit-btn:disabled {
  opacity: 0.68;
  cursor: not-allowed;
  color: #64748b;
}

.mcq-btn {
  display: block;
  width: 100%;
  padding: 0.75rem;
  margin-top: 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: white;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
}

.mcq-btn:hover {
  border-color: var(--primary-color);
  background: #f5f3ff;
}

.mcq-btn.selected {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border-color: #6366f1;
  transform: scale(1.02);
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.mcq-btn.selected .mcq-label {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}

.mcq-btn.disabled,
.mcq-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
  background: #f1f5f9;
}

.mcq-btn.disabled:not(.selected),
.mcq-btn:disabled:not(.selected) {
  border-color: #e2e8f0;
  color: #94a3b8;
}

.chat-jump-latest {
  position: absolute;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  border: none;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  color: white;
  padding: 0.55rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.24);
  z-index: 6;
}

.chat-jump-latest.hidden {
  display: none;
}

/* True/False disabled states */
.tf-btn.selected {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: white;
  border-color: #6366f1;
}

.tf-btn.disabled,
.tf-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}


/* Input Area */
.chat-input-area {
  padding: 1rem;
  background: white;
  border-top: 1px solid #f1f5f9;
  display: flex;
  gap: 0.8rem;
  align-items: center;
}

.chat-input {
  flex: 1;
  padding: 0.8rem;
  border: 1px solid #e2e8f0;
  border-radius: 99px;
  background: #f8fafc;
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: #6366f1;
  background: white;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary-gradient);
  border: none;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.send-btn:hover {
  transform: scale(1.05);
}

/* Animations */
@keyframes slideIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0% { opacity: 0.6; }
  50% { opacity: 1; }
  100% { opacity: 0.6; }
}

/* Whiteboard Toggle */
.whiteboard-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 10;
}

/* ============================================
   RESIZABLE PANEL STYLES
   ============================================ */

#right-panel {
  transition: width 0.15s ease-out, transform 0.3s ease;
  will-change: width;
  position: relative;
}

#right-panel.collapsed {
  width: 0 !important;
  min-width: 0;
  border-left: none;
}

#right-panel.collapsed > *:not(.resize-handle) {
  opacity: 0;
  pointer-events: none;
}

.resize-handle:hover {
  background: linear-gradient(to right, rgba(99, 102, 241, 0.3), transparent) !important;
}

.resize-handle:active {
  background: linear-gradient(to right, rgba(99, 102, 241, 0.5), transparent) !important;
}

/* ============================================
   MOBILE STYLES (< 768px)
   ============================================ */

@media (max-width: 767px) {
  /* Right panel becomes full-width overlay on mobile */
  #right-panel {
    position: fixed !important;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    max-width: 100vw;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.2);
  }

  #right-panel:not(.translate-x-full) {
    transform: translateX(0);
  }

  /* Hide resize handle on mobile */
  #right-panel .resize-handle {
    display: none;
  }

  /* Mobile backdrop */
  .mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
  }

  .mobile-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* Left panel mobile */
  #left-panel {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80% !important;
    max-width: 320px;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 10px 0 40px rgba(0, 0, 0, 0.2);
  }

  #left-panel:not(.hidden):not(.-translate-x-full) {
    transform: translateX(0);
  }

  /* Improve touch targets */
  .list-group-item,
  .tutor-style-chip,
  button,
  .hint-btn {
    min-height: 44px;
    min-width: 44px;
  }

  /* Larger input for mobile */
  #chat-input {
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 14px 48px 14px 16px;
  }

  #chat-log {
    padding: 0.85rem;
  }

  .message {
    max-width: 92%;
  }

  .msg-bubble {
    font-size: 0.88rem;
    line-height: 1.4;
    padding: 0.72rem 0.88rem;
  }

  .tutor-card,
  .tutor-mcq-card,
  .tutor-timed-card,
  .tutor-fillblank-card,
  .tutor-incdec-card {
    padding: 0.8rem;
  }

  .tutor-card-lead,
  .tutor-card-body,
  .fill-blank-sentence {
    font-size: 0.92rem;
    line-height: 1.45;
  }

  .tutor-choice-grid {
    grid-template-columns: 1fr;
  }

  .tutor-choice-btn,
  .tutor-submit-btn,
  .mcq-btn {
    font-size: 0.9rem;
    padding: 0.72rem 0.85rem;
  }

  .chat-jump-latest {
    bottom: 96px;
    font-size: 0.75rem;
    padding: 0.5rem 0.8rem;
  }

  /* Full-width buttons */
  .puk-answer-controls {
    flex-direction: column;
  }

  .puk-answer-controls button {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
  }
}

/* ============================================
   TABLET STYLES (768px - 1024px)
   ============================================ */

@media (min-width: 768px) and (max-width: 1024px) {
  #right-panel {
    width: 320px;
    min-width: 280px;
    max-width: 400px;
  }
}

/* ============================================
   TOUCH IMPROVEMENTS
   ============================================ */

@media (pointer: coarse) {
  /* Touch-friendly scrolling */
  .overflow-y-auto {
    -webkit-overflow-scrolling: touch;
  }

  /* Larger touch targets */
  .mcq-btn,
  .wb-btn,
  .puk-btn-add-text,
  .puk-btn-add-math,
  .puk-btn-add-drawing {
    padding: 14px 16px;
    font-size: 1rem;
  }
}

/* ============================================
   SWIPE INDICATOR
   ============================================ */

.swipe-indicator {
  position: absolute;
  top: 50%;
  left: 8px;
  transform: translateY(-50%);
  width: 4px;
  height: 40px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s;
}

.mobile-tutor-pill {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: white;
  padding: 0.85rem 1rem;
  font-size: 0.92rem;
  font-weight: 700;
  box-shadow: 0 18px 36px rgba(79, 70, 229, 0.32);
  z-index: 110;
}

.mobile-tutor-pill.hidden {
  display: none !important;
}

#right-panel:not(.translate-x-full) .swipe-indicator {
  opacity: 1;
}

/* ============================================
   DARK MODE SUPPORT (Optional)
   ============================================ */

@media (prefers-color-scheme: dark) {
  /* Future: Add dark mode variables here */
}

/* ============================================
   SCROLL CONTAINMENT
   ============================================ */

#chat-log {
  overscroll-behavior: contain;
}

#question-container {
  overscroll-behavior: contain;
}

/* No scrollbar on hint buttons */
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.no-scrollbar::-webkit-scrollbar {
  display: none;
}

/* ============================================
   ACTIVE QUESTION PART STYLING
   Premium XamAI purple theme
   ============================================ */

.question-part-wrapper {
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.question-part-wrapper.active-part {
  position: relative;
  background: linear-gradient(135deg, 
    rgba(95, 44, 130, 0.03) 0%, 
    rgba(79, 70, 229, 0.05) 50%,
    rgba(95, 44, 130, 0.03) 100%
  );
  border-color: rgba(95, 44, 130, 0.2) !important;
  box-shadow: 
    0 0 0 1px rgba(95, 44, 130, 0.1),
    0 4px 20px -4px rgba(95, 44, 130, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.question-part-wrapper.active-part::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, 
    #5f2c82 0%, 
    #4f46e5 50%, 
    #5f2c82 100%
  );
  border-radius: 6px 0 0 6px;
}

.question-part-wrapper.active-part::after {
  content: '✨ Active';
  position: absolute;
  top: 12px;
  right: 12px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #5f2c82;
  background: linear-gradient(135deg, rgba(95, 44, 130, 0.08), rgba(79, 70, 229, 0.08));
  padding: 4px 10px;
  border-radius: 9999px;
  border: 1px solid rgba(95, 44, 130, 0.15);
  animation: pulse-glow 2s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(95, 44, 130, 0.2);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(95, 44, 130, 0.1);
  }
}

/* Active part header styling */
.question-part-wrapper.active-part > div:first-child {
  background: linear-gradient(135deg, 
    rgba(95, 44, 130, 0.05) 0%, 
    rgba(79, 70, 229, 0.08) 100%
  ) !important;
}

/* Tutor panel indicator */
.tutor-active-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0 12px 12px 12px;
  background: linear-gradient(135deg, rgba(95, 44, 130, 0.05), rgba(79, 70, 229, 0.05));
  border: 1px solid rgba(95, 44, 130, 0.15);
  border-radius: 12px;
  font-size: 0.75rem;
  color: #5f2c82;
  font-weight: 500;
}

.tutor-active-indicator .part-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: linear-gradient(135deg, #5f2c82, #4f46e5);
  color: white;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.7rem;
}

/* ============================================
   NEW INTERACTIVE ELEMENT STYLES
   ============================================ */

/* Generic Card Wrapper */
.tutor-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem;
  margin-top: 0.8rem;
  box-shadow: 0 2px 4px rgba(0,0,0,0.02);
  transition: all 0.2s;
}

.tutor-card.disabled-card {
  opacity: 0.6;
  pointer-events: none;
}

/* MCQ Enhanced */
.mcq-label {
  display: inline-block;
  background: #f1f5f9;
  color: #64748b;
  font-weight: bold;
  padding: 2px 8px;
  border-radius: 6px;
  margin-right: 8px;
}

.mcq-btn:hover .mcq-label {
  background: white;
}

/* True/False Buttons */
.tf-btn {
  text-align: center;
  font-weight: bold;
  padding: 12px;
}

/* Fill in the Blank */
.fill-blank-sentence {
  font-size: 1.05rem;
  line-height: 2;
}

.tutor-input-inline {
  border: none;
  border-bottom: 2px dashed #a855f7;
  width: 112px;
  text-align: center;
  font-weight: bold;
  color: #4f46e5;
  background: rgba(168, 85, 247, 0.05);
  margin: 0 4px;
  border-radius: 4px;
  outline: none;
  transition: all 0.2s;
}

.tutor-input-inline:focus {
  background: rgba(168, 85, 247, 0.1);
  border-bottom-style: solid;
  width: 100px;
}

/* Explicit tutor part selection states */
.question-part-wrapper.active-part::after {
  content: 'Tutor Focus';
}

.part-nav-button {
  border: 1px solid transparent;
}

.part-nav-button.active-part-nav {
  background: linear-gradient(135deg, rgba(95, 44, 130, 0.08), rgba(79, 70, 229, 0.08));
  border-color: rgba(95, 44, 130, 0.18);
  color: #4338ca;
  box-shadow: inset 0 0 0 1px rgba(95, 44, 130, 0.06);
}

.part-nav-button.active-part-nav span:first-child {
  background: linear-gradient(135deg, #5f2c82, #4f46e5);
  color: #fff;
}

.question-rich-text {
  color: #334155;
}

.question-rich-text > :last-child {
  margin-bottom: 0;
}

.question-rich-text .math-display {
  overflow-x: auto;
  padding: 0.35rem 0;
}

.question-rich-text p { margin-bottom: 0.75rem; }
.question-rich-text p:last-child { margin-bottom: 0; }
.question-rich-text h2 { font-size: 1.25rem; font-weight: 700; margin: 1rem 0 0.5rem; }
.question-rich-text h3 { font-size: 1.1rem; font-weight: 600; margin: 0.75rem 0 0.5rem; }
.question-rich-text strong { font-weight: 700; }
.question-rich-text em { font-style: italic; }
.question-rich-text sub { font-size: 0.8em; vertical-align: sub; }
.question-rich-text sup { font-size: 0.8em; vertical-align: super; }
.question-rich-text ul, .question-rich-text ol { margin: 0.5rem 0 0.75rem 1.5rem; }
.question-rich-text li { margin-bottom: 0.25rem; }
.question-rich-text blockquote { border-left: 3px solid #94a3b8; padding-left: 1rem; margin: 0.75rem 0; color: #64748b; font-style: italic; }
.question-rich-text .ql-formula { background: #f8fafc; border-radius: 0.375rem; padding: 0.1rem 0.35rem; }
.question-rich-text .katex-display { margin: 0.5rem 0; overflow-x: auto; }
.question-rich-text table { border-collapse: collapse; width: 100%; margin: 0.75rem 0; }
.question-rich-text th, .question-rich-text td { border: 1px solid #e2e8f0; padding: 0.5rem 0.75rem; text-align: left; }
.question-rich-text th { background: #f8fafc; font-weight: 600; }

.msg-bubble p { margin-bottom: 0.5rem; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { font-weight: 700; }
.msg-bubble em { font-style: italic; }
.msg-bubble ul, .msg-bubble ol { margin: 0.25rem 0 0.5rem 1.25rem; }
.msg-bubble li { margin-bottom: 0.15rem; }
.msg-bubble code { background: rgba(0,0,0,0.08); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; }
.msg-bubble pre { background: rgba(0,0,0,0.08); padding: 0.5rem; border-radius: 6px; overflow-x: auto; margin: 0.5rem 0; }
.msg-bubble .katex-display { margin: 0.5rem 0; }

/* Slider */
.slider-val {
  font-size: 1.5rem;
  font-weight: 800;
}

/* Confidence RAG */
.rag-btn {
  font-size: 1.4rem;
  padding: 8px 20px;
  border-radius: 50px;
  transition: transform 0.2s;
}

.rag-btn:hover {
  transform: scale(1.1);
}

/* Hint Blur */
.hint-blur-content {
  filter: blur(8px);
  opacity: 0.5;
  user-select: none;
  transition: all 0.5s ease;
  background: #f8fafc;
  padding: 8px;
  border-radius: 8px;
}

/* Timed Challenge */
.timer-countdown {
  font-family: monospace;
  font-size: 1.1rem;
}

.tutor-timed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  color: #991b1b;
  margin-bottom: 0.75rem;
}

.tutor-timed-progress {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #fee2e2;
  overflow: hidden;
  margin-top: 0.9rem;
}

.tutor-timed-progress-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #ef4444, #f97316);
  transition: width 0.1s linear;
}

/* Sequence List */
.sortable-list .list-group-item {
  cursor: grab;
  border-left: 4px solid transparent;
}

.sortable-list .list-group-item:hover {
  border-left-color: #a855f7;
  background: #f8fafc;
}
