/**
 * Learn Task Modal - Comprehensive Styling
 * P0-002: Complete modal design for Learn tasks
 * Includes: Header (Back/Title/Done), Content (Video/Explanation/Questions)
 */

/* ============================================
   HEADER SECTION
   ============================================ */

#topic-modal .task-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 64px;
}

/* Back Button (Left) */
#topic-modal .task-modal-back {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
  font-weight: 500;
}

#topic-modal .task-modal-back:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

#topic-modal .task-modal-back svg {
  width: 20px;
  height: 20px;
}

/* Title (Center) */
#topic-modal .task-modal-title {
  flex: 1;
  text-align: center;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 16px;
  padding: 0 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Done Button (Right) */
#topic-modal .task-modal-complete {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #22c55e;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(34, 197, 94, 0.2);
}

#topic-modal .task-modal-complete:hover {
  background: #16a34a;
  box-shadow: 0 4px 8px rgba(34, 197, 94, 0.3);
  transform: translateY(-1px);
}

#topic-modal .task-modal-complete:active {
  transform: translateY(0);
}

#topic-modal .task-modal-complete svg {
  width: 18px;
  height: 18px;
}

/* ============================================
   CONTENT SECTION
   ============================================ */

#topic-modal .task-modal-content {
  flex: 1;
  overflow-y: auto !important; /* Force scrolling */
  overflow-x: hidden;
  padding: 24px;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  background: var(--bg-primary);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* ============================================
   VIDEO SECTION
   ============================================ */

/* Video container */
#topic-modal .video-container,
#topic-modal .box-video,
#topic-modal .content-box:has(iframe),
#topic-modal .content-box:has(video) {
  margin-bottom: 32px;
  border-radius: 16px;
  overflow: hidden;
  background: #000 !important;
  border: 2px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  padding: 0 !important;
}

#topic-modal .video-container:hover,
#topic-modal .box-video:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}

/* Responsive video embed - catch ALL video elements */
#topic-modal iframe,
#topic-modal video,
#topic-modal .content-box iframe,
#topic-modal .content-box video {
  width: 100% !important;
  max-width: 100% !important;
  min-height: 400px !important;
  aspect-ratio: 16/9;
  border: none !important;
  display: block !important;
  background: #000 !important;
  border-radius: 8px !important;
  margin: 0 !important;
}

/* Video wrapper for aspect ratio */
#topic-modal .video-wrapper {
  position: relative;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
  height: 0;
  overflow: hidden;
  background: #000;
  border-radius: 14px;
}

#topic-modal .video-wrapper iframe,
#topic-modal .video-wrapper video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
}

/* ============================================
   CONTENT BOXES (Explanation Sections)
   ============================================ */

#topic-modal .content-box,
#topic-modal .box-story,
#topic-modal .box-deepdive,
#topic-modal .box-facts,
#topic-modal .box-tips,
#topic-modal .box-equation,
#topic-modal .box-diagram {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  transition: all 0.2s ease;
  /* Set base text color for all content */
  color: #e5e7eb !important;
}

/* Ensure ALL headings in content boxes have proper contrast */
#topic-modal .content-box h2,
#topic-modal .content-box h3,
#topic-modal .content-box h4,
#topic-modal .box-story h2,
#topic-modal .box-story h3,
#topic-modal .box-story h4,
#topic-modal .box-deepdive h2,
#topic-modal .box-deepdive h3,
#topic-modal .box-deepdive h4,
#topic-modal .box-facts h2,
#topic-modal .box-facts h3,
#topic-modal .box-facts h4,
#topic-modal .box-tips h2,
#topic-modal .box-tips h3,
#topic-modal .box-tips h4,
#topic-modal .box-equation h2,
#topic-modal .box-equation h3,
#topic-modal .box-equation h4,
#topic-modal .box-diagram h2,
#topic-modal .box-diagram h3,
#topic-modal .box-diagram h4 {
  color: #f9fafb !important; /* Near-white for maximum contrast */
  font-weight: 700 !important;
}

#topic-modal .content-box:hover,
#topic-modal .box-story:hover,
#topic-modal .box-deepdive:hover,
#topic-modal .box-facts:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Story Box (Engagement/Hook) */
#topic-modal .box-story {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(139, 92, 246, 0.1));
  border-color: rgba(99, 102, 241, 0.3);
  border-left: 4px solid #6366f1;
}

/* Deep Dive Box (Detailed Explanation) */
#topic-modal .box-deepdive {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.1), rgba(6, 182, 212, 0.1));
  border-color: rgba(14, 165, 233, 0.3);
  border-left: 4px solid #0ea5e9;
}

/* Facts Box (Key Points) */
#topic-modal .box-facts {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(16, 185, 129, 0.1));
  border-color: rgba(34, 197, 94, 0.3);
  border-left: 4px solid #22c55e;
}

/* Tips Box (Exam Tips) */
#topic-modal .box-tips {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.1), rgba(251, 191, 36, 0.1));
  border-color: rgba(245, 158, 11, 0.3);
  border-left: 4px solid #f59e0b;
}

/* Equation Box */
#topic-modal .box-equation {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.1), rgba(192, 132, 252, 0.1));
  border-color: rgba(168, 85, 247, 0.3);
  border-left: 4px solid #a855f7;
  text-align: center;
  font-size: 18px;
  font-family: var(--font-mono);
}

/* Diagram Box */
#topic-modal .box-diagram {
  background: var(--bg-card);
  text-align: center;
  padding: 24px;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

/* Headings */
#topic-modal h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 0;
  margin-bottom: 16px;
  line-height: 1.2;
}

#topic-modal h2 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 24px;
  margin-bottom: 12px;
  line-height: 1.3;
}

#topic-modal h3 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-top: 20px;
  margin-bottom: 10px;
  line-height: 1.4;
}

/* Paragraphs */
#topic-modal p {
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 12px;
  font-size: 15px;
}

/* CRITICAL: Fix paragraph contrast in content boxes for dark mode */
#topic-modal .content-box p,
#topic-modal .box-story p,
#topic-modal .box-deepdive p,
#topic-modal .box-facts p,
#topic-modal .box-tips p,
#topic-modal .box-equation p,
#topic-modal .box-diagram p {
  color: #e5e7eb !important; /* Light gray - high contrast for dark mode */
}

/* Lists */
#topic-modal ul,
#topic-modal ol {
  color: var(--text-secondary);
  margin-left: 24px;
  margin-bottom: 16px;
  line-height: 1.7;
}

#topic-modal li {
  margin-bottom: 8px;
}

#topic-modal ul li::marker {
  color: var(--accent);
}

/* CRITICAL: Fix list contrast in content boxes */
#topic-modal .content-box ul,
#topic-modal .content-box ol,
#topic-modal .content-box li,
#topic-modal .box-story ul,
#topic-modal .box-story ol,
#topic-modal .box-story li,
#topic-modal .box-deepdive ul,
#topic-modal .box-deepdive ol,
#topic-modal .box-deepdive li,
#topic-modal .box-facts ul,
#topic-modal .box-facts ol,
#topic-modal .box-facts li,
#topic-modal .box-tips ul,
#topic-modal .box-tips ol,
#topic-modal .box-tips li {
  color: #e5e7eb !important; /* Light gray - high contrast for dark mode */
}

/* Strong/Bold */
#topic-modal strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* Ensure strong text in content boxes is visible */
#topic-modal .content-box strong,
#topic-modal .box-story strong,
#topic-modal .box-deepdive strong,
#topic-modal .box-facts strong,
#topic-modal .box-tips strong {
  color: #f9fafb !important; /* Near-white for emphasis */
  font-weight: 700;
}

/* Catch-all for ANY text elements that might override */
#topic-modal .content-box *,
#topic-modal .box-story *,
#topic-modal .box-deepdive *,
#topic-modal .box-facts *,
#topic-modal .box-tips * {
  color: inherit !important;
}

/* Then re-apply specific colors for headings */
#topic-modal .content-box h1,
#topic-modal .content-box h2,
#topic-modal .content-box h3,
#topic-modal .content-box h4,
#topic-modal .content-box h5,
#topic-modal .content-box h6,
#topic-modal .box-story h1,
#topic-modal .box-story h2,
#topic-modal .box-story h3,
#topic-modal .box-deepdive h1,
#topic-modal .box-deepdive h2,
#topic-modal .box-deepdive h3,
#topic-modal .box-facts h1,
#topic-modal .box-facts h2,
#topic-modal .box-facts h3 {
  color: #f9fafb !important;
}

/* Links */
#topic-modal a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.2s ease;
}

#topic-modal a:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

/* ============================================
   QUESTIONS SECTION
   ============================================ */

#topic-modal .box-questions {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-top: 24px;
  margin-bottom: 20px;
}

#topic-modal .box-questions h2,
#topic-modal .box-questions h3 {
  color: var(--text-primary);
  margin-top: 0;
}

/* Question details/summary */
#topic-modal details.question {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#topic-modal details.question:hover {
  background: var(--bg-card);
  border-color: var(--accent);
}

#topic-modal details.question summary {
  font-weight: 500;
  color: var(--text-primary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
}

#topic-modal details.question summary::before {
  content: "▶";
  color: var(--accent);
  transition: transform 0.2s ease;
}

#topic-modal details.question[open] summary::before {
  transform: rotate(90deg);
}

#topic-modal details.question[open] {
  background: var(--bg-card);
  padding-bottom: 16px;
}

/* Question content */
#topic-modal .question-content {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ============================================
   CODE BLOCKS & TECHNICAL CONTENT
   ============================================ */

#topic-modal code {
  background: var(--bg-hover);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--text-primary);
}

#topic-modal pre {
  background: var(--bg-hover);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--border);
}

#topic-modal pre code {
  background: none;
  padding: 0;
  font-size: 14px;
}

/* ============================================
   IMAGES & DIAGRAMS
   ============================================ */

#topic-modal img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 16px 0;
  display: block;
}

#topic-modal figure {
  margin: 20px 0;
  text-align: center;
}

#topic-modal figcaption {
  margin-top: 8px;
  font-size: 14px;
  color: var(--text-muted);
  font-style: italic;
}

/* ============================================
   TABLES
   ============================================ */

#topic-modal table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  background: var(--bg-card);
  border-radius: 8px;
  overflow: hidden;
}

#topic-modal th,
#topic-modal td {
  padding: 12px;
  border: 1px solid var(--border);
  text-align: left;
}

#topic-modal th {
  background: var(--bg-hover);
  color: var(--text-primary);
  font-weight: 600;
}

#topic-modal td {
  color: var(--text-secondary);
}

#topic-modal tr:hover {
  background: var(--bg-hover);
}

/* ============================================
   BLOCKQUOTES
   ============================================ */

#topic-modal blockquote {
  border-left: 4px solid var(--accent);
  padding-left: 16px;
  margin: 16px 0;
  color: var(--text-secondary);
  font-style: italic;
  background: var(--bg-hover);
  padding: 16px;
  padding-left: 20px;
  border-radius: 0 8px 8px 0;
}

/* ============================================
   FOOTER SECTION (REMOVED - was sticky and intrusive)
   ============================================ */

#topic-modal .task-modal-footer {
  display: none !important;
}

#topic-modal .view-full-link {
  display: none !important;
}

/* ============================================
   LOADING STATE
   ============================================ */

#topic-modal .task-modal-content p[style*="text-align: center"] {
  color: var(--text-muted);
  padding: 40px;
  font-size: 16px;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
  #topic-modal .task-modal-header {
    padding: 12px 16px;
  }

  #topic-modal .task-modal-title {
    font-size: 14px;
  }

  #topic-modal .task-modal-content {
    padding: 16px;
  }

  #topic-modal h1 {
    font-size: 24px;
  }

  #topic-modal h2 {
    font-size: 20px;
  }

  #topic-modal .task-modal-complete {
    padding: 8px 12px;
    font-size: 13px;
  }

  #topic-modal .task-modal-back {
    padding: 6px 10px;
    font-size: 13px;
  }
}
