:root {
  --bs-primary: #0d6efd;
  --bs-secondary: #6c757d;
  --bs-success: #198754;
  --bs-info: #0dcaf0;
  --bs-warning: #ffc107;
  --bs-danger: #dc3545;
  --bs-light: #f8f9fa;
  --bs-dark: #212529;
  --bs-font-sans-serif: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
  --bs-body-bg: #f8f9fa;
  --bs-border-color-light: #dee2e6; /* Custom light border color */

  /* Chat Specific Colors */
  --chat-user-bg: #e0f2fe; /* Light blue for user messages */
  --chat-user-text: #0d47a1; /* Darker blue for user text */
  --chat-ai-bg: #f0f4f8; /* Off-white/light gray for AI messages */
  --chat-ai-text: #212529; /* Dark for AI text */
  --chat-timestamp-text: #6c757d; /* Muted gray for timestamps */
  --chat-system-bg: #e9ecef; /* Light gray for system messages/notifications */
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: transparent; /* Changed to allow canvas background to show */
  overflow-x: hidden; /* Prevent horizontal scrollbar from animations */
}

main {
  flex-grow: 1;
  /* Page load animation */
  animation: fadeInUp 0.5s ease-in-out forwards;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  border: none;
  box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.075);
  transition: box-shadow .2s ease-in-out, transform .2s ease-in-out;
}

.card-hover:hover {
  box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.1);
  transform: translateY(-5px);
}

.navbar {
  background-color: #fff !important;
  box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
}

.hero-gradient {
  background: linear-gradient(135deg, #0d6efd, #6f42c1);
}

/* Button and Input animations */
.btn {
  transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
}
.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.btn:active {
  transform: translateY(0px);
  box-shadow: none;
}
.form-control:focus {
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
.form-control, .form-select {
  transition: box-shadow .2s ease-in-out;
}

/* Responsive display headings */
.display-responsive {
  font-size: calc(1.4rem + 1.5vw); /* Responsive font size */
  font-weight: 300;
  line-height: 1.2;
}

@media (min-width: 1200px) {
  .display-responsive {
    font-size: 2.5rem; /* Max font size for large desktops */
  }
}

/* --- NEW AI CHAT UI STYLES --- */

/* Main container to manage height */
.chat-page-container {
  display: flex;
  flex-direction: column;
  /* Approx height of viewport minus nav and footer */
  height: calc(100vh - 150px);
  max-width: 960px;
  margin: 0 auto;
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.1);
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e9ecef;
}

/* Scrollable message area */
.chat-window {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
}

.chat-history {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chat-bubble {
  display: flex;
  max-width: 85%;
  animation: slideIn 0.4s ease-out forwards;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-bubble-content {
  padding: 0.75rem 1.25rem;
  border-radius: 1.25rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

.chat-bubble.user {
  align-self: flex-end;
}

.chat-bubble.user .chat-bubble-content {
  background-color: var(--bs-primary);
  color: white;
  border-bottom-right-radius: 0.25rem;
}

.chat-bubble.ai {
  align-self: flex-start;
}

.chat-bubble.ai .chat-bubble-content {
  background-color: #e9ecef;
  color: var(--bs-dark);
  border-bottom-left-radius: 0.25rem;
  width: 100%; /* Allow bubble to expand for charts */
}

/* Fixed input area at the bottom */
.chat-input-area {
  padding: 1rem;
  background-color: #fff;
  border-top: 1px solid #e9ecef;
}

.prompt-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.chat-form textarea {
  flex-grow: 1;
  border-radius: 1.5rem;
  padding: 0.5rem 1rem;
  max-height: 150px;
  resize: none;
}

.chat-form .btn {
  flex-shrink: 0;
  border-radius: 50%;
  width: 44px;
  height: 44px;
}

.thinking-cursor {
  display: inline-block;
  width: 9px;
  height: 1.1em;
  background-color: var(--bs-dark);
  animation: blink 1s step-end infinite;
  margin-left: 4px;
}

@keyframes blink {
  from, to { background-color: transparent; }
  50% { background-color: var(--bs-dark); }
}


/* Legacy chat styles for other pages, can be removed if not needed */
.chat-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 800px;
  margin: 0 auto;
}

/* Background canvas */
#bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    opacity: 0.8;
}

/* Chat page two-column layout */
.chat-columns-container {
  display: flex;
  flex-direction: column; /* Stack on mobile */
  height: calc(100vh - 150px); /* Adjust height as needed */
  max-width: 1200px;
  margin: 0 auto;
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 0.5rem 1.5rem rgba(0,0,0,0.1);
  overflow: hidden;
  position: relative; /* For scroll-to-bottom button */
}

@media (min-width: 768px) { /* Two columns on medium and larger screens */
  .chat-columns-container {
    flex-direction: row;
  }
}

.chat-sidebar {
  flex-shrink: 0;
  width: 100%; /* Full width on mobile */
  border-bottom: 1px solid var(--bs-border-color-light);
}

@media (min-width: 768px) {
  .chat-sidebar {
    width: 300px; /* Fixed width sidebar on desktop */
    border-right: 1px solid var(--bs-border-color-light);
    border-bottom: none;
  }
}

.chat-main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
}

.chat-main-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--bs-border-color-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 56px; /* Ensure consistent height */
}

.chat-main-body {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1rem;
  background-color: #f8fafc; /* Lighter background for chat area */
  position: relative; /* For notifications & scroll-to-bottom button */
}

.chat-main-footer {
  padding: 1rem;
  border-top: 1px solid var(--bs-border-color-light);
  background-color: #fff;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-main-footer .form-control {
  flex-grow: 1;
  border-radius: 1.25rem;
  padding: 0.75rem 1rem;
  max-height: 120px;
  resize: none;
  font-size: 0.9rem;
}

.chat-main-footer .btn {
  flex-shrink: 0;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

/* New chat bubble styling */
.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: 0.8rem;
  max-width: 75%;
  position: relative;
  font-size: 0.92rem;
  line-height: 1.4;
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  animation: messageFadeIn 0.3s ease-out forwards;
}

.message-bubble.user {
  background-color: var(--chat-user-bg);
  color: var(--chat-user-text);
  margin-left: auto;
  border-bottom-right-radius: 0.2rem;
}

.message-bubble.other {
  background-color: var(--chat-ai-bg);
  color: var(--chat-ai-text);
  margin-right: auto;
  border-bottom-left-radius: 0.2rem;
}

/* Chat bubble tail */
.message-bubble::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  top: 0;
}

.message-bubble.user::before {
  border-top-color: var(--chat-user-bg);
  border-right-color: var(--chat-user-bg);
  right: -5px;
  border-top-right-radius: 6px;
  transform: rotate(10deg);
}

.message-bubble.other::before {
  border-top-color: var(--chat-ai-bg);
  border-left-color: var(--chat-ai-bg);
  left: -5px;
  border-top-left-radius: 6px;
  transform: rotate(-10deg);
}

.message-info {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 0.5rem;
  font-size: 0.75rem;
  color: var(--chat-timestamp-text);
}

.message-status {
  display: flex;
  align-items: center;
  gap: 4px;
}

.message-status i {
  font-size: 0.9rem;
}

.message-content img, .message-content video, .message-content audio {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
  margin-top: 0.5rem;
  display: block;
}

.message-content a[target="_blank"] {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background-color: rgba(0,0,0,0.05);
  border-radius: 0.25rem;
  margin-top: 0.5rem;
  text-decoration: none;
  color: var(--bs-dark);
}
.message-content a[target="_blank"]:hover {
  background-color: rgba(0,0,0,0.1);
}
.message-content a[target="_blank"] i {
  font-size: 1rem;
}

.file-attachment-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background-color: var(--chat-system-bg);
  border-radius: 0.5rem;
  margin-top: 0.5rem;
  width: fit-content;
  max-width: 100%;
}
.file-attachment-preview i {
  font-size: 1.5rem;
  color: var(--bs-primary);
}
.file-attachment-preview .file-details {
  display: flex;
  flex-direction: column;
}
.file-attachment-preview .file-name {
  font-weight: 500;
  word-break: break-all;
}
.file-attachment-preview .file-size {
  font-size: 0.8rem;
  color: var(--chat-timestamp-text);
}

.pending-upload .progress {
  height: 8px;
  margin-top: 0.5rem;
}
.pending-upload .progress-bar {
  background-color: var(--bs-primary);
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  background-color: var(--chat-system-bg);
  border-radius: 1rem;
  width: fit-content;
  margin-top: 1rem;
  margin-left: 10px;
  animation: fadeIn 0.3s ease-out;
}

.typing-indicator .dot {
  width: 8px;
  height: 8px;
  background-color: var(--bs-gray-600);
  border-radius: 50%;
  animation: bubble-pulse 1.4s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(1) { animation-delay: 0s; }
.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bubble-pulse {
  0%, 80%, 100% { transform: scale(0); opacity: 0; }
  40% { transform: scale(1); opacity: 1; }
}

@keyframes messageFadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Scroll to Bottom Button */
#scrollToBottomBtn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 10;
  display: none; /* Hidden by default */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: fadeInScale 0.3s ease-out;
}

@keyframes fadeInScale {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}

/* Voice Chat UI Enhancements */
#voiceChatBtn {
  position: relative;
  overflow: visible;
}

#voicePulseIndicator {
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  50% {
    opacity: 0.7;
    transform: translate(-50%, -50%) scale(1.2);
  }
}

.audio-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 16px;
}

.audio-bar {
  width: 3px;
  background: #28a745;
  border-radius: 2px;
  animation: audioWave 1.2s ease-in-out infinite;
}

.audio-bar:nth-child(1) { animation-delay: 0s; height: 8px; }
.audio-bar:nth-child(2) { animation-delay: 0.1s; height: 12px; }
.audio-bar:nth-child(3) { animation-delay: 0.2s; height: 16px; }
.audio-bar:nth-child(4) { animation-delay: 0.3s; height: 10px; }

@keyframes audioWave {
  0%, 100% { transform: scaleY(0.5); opacity: 0.7; }
  50% { transform: scaleY(1); opacity: 1; }
}

.audio-visualizer {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
}

.viz-bar {
  width: 4px;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 2px;
  animation: vizWave 1s ease-in-out infinite;
}

.viz-bar:nth-child(1) { animation-delay: 0s; height: 8px; }
.viz-bar:nth-child(2) { animation-delay: 0.1s; height: 14px; }
.viz-bar:nth-child(3) { animation-delay: 0.2s; height: 20px; }
.viz-bar:nth-child(4) { animation-delay: 0.3s; height: 12px; }
.viz-bar:nth-child(5) { animation-delay: 0.4s; height: 16px; }

@keyframes vizWave {
  0%, 100% { transform: scaleY(0.4); opacity: 0.6; }
  50% { transform: scaleY(1); opacity: 1; }
}

#voiceChatStatus {
  transition: all 0.3s ease;
}

#voiceChatPanel {
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#voiceChatBtn.btn-success {
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  border: none;
  color: white;
  box-shadow: 0 4px 15px rgba(40, 167, 69, 0.3);
}

#voiceChatBtn.btn-success:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(40, 167, 69, 0.4);
}

#voiceMuteBtn.btn-danger {
  background: linear-gradient(135deg, #dc3545 0%, #c82333 100%);
  border: none;
  color: white;
  box-shadow: 0 4px 15px rgba(220, 53, 69, 0.3);
}

#voiceMuteBtn.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(220, 53, 69, 0.4);
}

#remoteSpeakingIndicator {
  animation: speakingPulse 1.5s ease-in-out infinite;
}

@keyframes speakingPulse {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 1; }
}

.badge.bg-success {
  padding: 4px 8px;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

#voiceNotifications {
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.voice-notification {
  background: rgba(0, 0, 0, 0.9);
  color: white;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.3s ease-out, fadeOut 0.3s ease-out 2.7s forwards;
  min-width: 220px;
  max-width: 280px;
  pointer-events: auto;
  position: relative;
}

.voice-notification.join {
  border-left: 3px solid #28a745;
}

.voice-notification.leave {
  border-left: 3px solid #dc3545;
}

.voice-notification.mute {
  border-left: 3px solid #ffc107;
}

.voice-notification.unmute {
  border-left: 3px solid #17a2b8;
}

.voice-notification.info {
  border-left: 3px solid #17a2b8;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

.voice-notification i {
  font-size: 1.2rem;
}

.voice-notification.join i {
  color: #28a745;
}

.voice-notification.leave i {
  color: #dc3545;
}

.voice-notification.mute i {
  color: #ffc107;
}

.voice-notification.unmute i {
  color: #17a2b8;
}

.chat-sidebar .list-group-item:hover {
  background-color: var(--bs-primary-bg-subtle);
  color: var(--bs-primary);
}
.chat-sidebar .list-group-item.active {
  background-color: var(--bs-primary);
  border-color: var(--bs-primary);
  color: white;
}
.chat-sidebar .list-group-item.active .text-muted {
  color: rgba(255,255,255,0.7) !important;
}

.learndesk-wrapper.iframe-mode,
.teachdesk-wrapper.iframe-mode {
  max-width: none;
  margin: 0;
  padding: 10px; /* Reduced padding for embedded view */
  box-shadow: none; /* Remove shadow to make it blend better */
  border-radius: 0; /* Remove border-radius */
}

/* Ensure embedded headers/footers also fit */
.learndesk-wrapper.iframe-mode .ld-header,
.teachdesk-wrapper.iframe-mode .td-header {
  margin-bottom: 15px; /* Adjust spacing */
  padding: 0 10px; /* Add some internal padding */
  background: var(--bs-light);
  border-radius: 0.3rem;
  box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
}

.learndesk-wrapper.iframe-mode .syllabus-list,
.teachdesk-wrapper.iframe-mode .course-card {
  padding: 15px; /* Adjust internal padding */
  box-shadow: none; /* Remove shadow to blend better */
}

.learndesk-wrapper.iframe-mode .syllabus-list .section-heading,
.teachdesk-wrapper.iframe-mode .course-card h2 {
  font-size: 1.5rem; /* Make headings slightly smaller */
  margin-bottom: 1rem;
}

.learndesk-wrapper.iframe-mode .course-grid {
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); /* Adjust grid for smaller space */
  gap: 15px;
}

.learndesk-wrapper.iframe-mode .course-card {
  padding: 15px;
  border-radius: 0.5rem;
}

.teachdesk-wrapper.iframe-mode .navbar {
  margin-bottom: 15px;
  padding: 8px 15px;
}

.teachdesk-wrapper.iframe-mode .weeks-section {
  padding: 0;
  gap: 15px;
}

.teachdesk-wrapper.iframe-mode .week-card {
  padding: 15px;
  border-radius: 0.5rem;
}

.teachdesk-wrapper.iframe-mode .summary-card {
  padding: 15px;
  border-radius: 0.5rem;
  box-shadow: none;
}

/* --- PWA & Android WebView Mobile Optimizations --- */

html, body {
  /* Prevent pull-to-refresh on some webviews and ensure smooth scrolling */
  overscroll-behavior-y: none;
}

/* Touch friendly targets */
button, .btn, .nav-link, select, input, .dropdown-item {
  min-height: 48px; /* High mobile tap target size */
  touch-action: manipulation;
}

/* Enhancing top nav for an app-like feel on mobile */
@media (max-width: 991.98px) {
  .navbar {
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
  }
  
  /* Make navbar brand bigger and centered like a native app header */
  .navbar-brand {
    font-size: 1.3rem; 
  }
  
  main.container {
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }
}

