/* ===========================
   CSS Variables & Reset
   =========================== */
:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #10b981;
  --background-color: #f8fafc;
  --surface-color: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --error-color: #ef4444;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --transition: all 0.3s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--background-color);
  color: var(--text-primary);
  line-height: 1.6;
  font-size: 16px;
}

/* ===========================
   Layout - Mobile First
   =========================== */
.app-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-hover));
  color: white;
  padding: 1.5rem 1rem;
  text-align: center;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header h1 {
  font-size: 1.75rem;
  margin-bottom: 0.25rem;
  font-weight: 700;
}

.subtitle {
  font-size: 0.875rem;
  opacity: 0.9;
  font-weight: 300;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ===========================
   Sidebar - Mobile First
   =========================== */
.sidebar {
  background: var(--surface-color);
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.search-container {
  margin-bottom: 1rem;
}

#searchInput {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  transition: var(--transition);
}

#searchInput:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.category-filter {
  margin-bottom: 1rem;
}

.category-filter label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

#categorySelect {
  width: 100%;
  padding: 0.625rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  background-color: white;
  cursor: pointer;
  transition: var(--transition);
}

#categorySelect:focus {
  outline: none;
  border-color: var(--primary-color);
}

.topics-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 300px;
  overflow-y: auto;
}

.topic-item {
  display: block;
  padding: 0.875rem;
  background: var(--background-color);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-primary);
  transition: var(--transition);
  cursor: pointer;
}

.topic-item:hover {
  border-color: var(--primary-color);
  background: white;
  transform: translateX(4px);
}

.topic-item.active {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.topic-item-title {
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 0.25rem;
}

.topic-item-category {
  font-size: 0.75rem;
  opacity: 0.7;
}

/* ===========================
   Topic Detail View
   =========================== */
.topic-detail {
  flex: 1;
  padding: 1.5rem 1rem;
  background: var(--surface-color);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.empty-state h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.topic-header {
  margin-bottom: 2rem;
}

#topicTitle {
  font-size: 1.75rem;
  margin-bottom: 1rem;
  color: var(--primary-color);
}

.topic-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.topic-category {
  display: inline-block;
  padding: 0.375rem 0.75rem;
  background: var(--primary-color);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
}

.topic-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  padding: 0.25rem 0.625rem;
  background: var(--background-color);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ===========================
   Accordion
   =========================== */
.accordion {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.accordion-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: white;
  box-shadow: var(--shadow-sm);
}

.accordion-header {
  width: 100%;
  padding: 1rem;
  background: var(--background-color);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: var(--transition);
  text-align: left;
}

.accordion-header:hover {
  background: var(--primary-color);
  color: white;
}

.accordion-header[aria-expanded="true"] {
  background: var(--primary-color);
  color: white;
}

.accordion-icon {
  font-size: 1.25rem;
}

.accordion-header span:nth-child(2) {
  flex: 1;
}

.accordion-toggle {
  font-size: 1.5rem;
  font-weight: 300;
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 1rem;
}

.accordion-content.active {
  max-height: 2000px;
  padding: 1rem;
}

.accordion-content ul {
  list-style: none;
  padding: 0;
}

.accordion-content li {
  padding: 0.625rem;
  margin-bottom: 0.5rem;
  background: var(--background-color);
  border-left: 3px solid var(--primary-color);
  border-radius: var(--radius-sm);
}

/* ===========================
   Mistakes Section
   =========================== */
.mistake-item {
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: var(--background-color);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--error-color);
}

.mistake-wrong {
  display: block;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  background: #fee;
  color: var(--error-color);
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.mistake-correct {
  display: block;
  margin-bottom: 0.5rem;
  padding: 0.5rem;
  background: #efe;
  color: var(--success-color);
  border-radius: var(--radius-sm);
  font-weight: 500;
}

.mistake-explanation {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-style: italic;
}

/* ===========================
   Quiz Section
   =========================== */
.quiz-question {
  margin-bottom: 2rem;
  padding: 1rem;
  background: var(--background-color);
  border-radius: var(--radius-md);
  border: 2px solid var(--border-color);
}

.quiz-question-text {
  font-weight: 600;
  margin-bottom: 1rem;
  font-size: 1.0625rem;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  margin-bottom: 1rem;
}

.quiz-option {
  padding: 0.75rem;
  background: white;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
}

.quiz-option:hover {
  border-color: var(--primary-color);
  background: var(--background-color);
}

.quiz-option.selected {
  border-color: var(--primary-color);
  background: rgba(37, 99, 235, 0.1);
}

.quiz-option.correct {
  border-color: var(--success-color);
  background: rgba(16, 185, 129, 0.1);
}

.quiz-option.incorrect {
  border-color: var(--error-color);
  background: rgba(239, 68, 68, 0.1);
}

.quiz-explanation {
  padding: 0.875rem;
  background: rgba(37, 99, 235, 0.05);
  border-left: 3px solid var(--primary-color);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-top: 0.75rem;
  display: none;
}

.quiz-explanation.show {
  display: block;
}

.quiz-submit {
  margin-top: 1rem;
}

/* ===========================
   Notes Section
   =========================== */
.notes-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.notes-section h4 {
  color: var(--primary-color);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.notes-section textarea {
  width: 100%;
  padding: 0.75rem;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9375rem;
  resize: vertical;
  transition: var(--transition);
}

.notes-section textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.notes-info {
  padding: 0.75rem;
  background: rgba(37, 99, 235, 0.05);
  border-radius: var(--radius-sm);
  text-align: center;
  color: var(--text-secondary);
}

/* ===========================
   Buttons
   =========================== */
.btn {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active {
  transform: translateY(0);
}

/* ===========================
   Mobile Menu Toggle
   =========================== */
.mobile-menu-toggle {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.mobile-menu-toggle:hover {
  background: var(--primary-hover);
  transform: scale(1.1);
}

.mobile-menu-toggle:active {
  transform: scale(0.95);
}

/* ===========================
   Footer
   =========================== */
.app-footer {
  background: var(--surface-color);
  padding: 1.5rem 1rem;
  text-align: center;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ===========================
   Scrollbar Styling
   =========================== */
.topics-list::-webkit-scrollbar {
  width: 8px;
}

.topics-list::-webkit-scrollbar-track {
  background: var(--background-color);
  border-radius: var(--radius-sm);
}

.topics-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-sm);
}

.topics-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* ===========================
   Responsive Design - Tablet
   =========================== */
@media (min-width: 768px) {
  .app-header h1 {
    font-size: 2.25rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  .main-content {
    flex-direction: row;
  }

  .sidebar {
    width: 320px;
    min-width: 320px;
    border-right: 1px solid var(--border-color);
    border-bottom: none;
    position: sticky;
    top: 0;
    height: calc(100vh - 120px);
    overflow-y: auto;
  }

  .topics-list {
    max-height: none;
  }

  .topic-detail {
    padding: 2rem;
  }

  #topicTitle {
    font-size: 2.25rem;
  }

  .mobile-menu-toggle {
    display: none;
  }
}

/* ===========================
   Responsive Design - Desktop
   =========================== */
@media (min-width: 1024px) {
  .sidebar {
    width: 380px;
    min-width: 380px;
  }

  .topic-detail {
    padding: 2.5rem 3rem;
  }

  .accordion-content li {
    font-size: 1rem;
  }
}

/* ===========================
   Mobile-Specific Styles
   =========================== */
@media (max-width: 767px) {
  .mobile-menu-toggle {
    display: flex;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    width: 85%;
    max-width: 320px;
    height: 100vh;
    z-index: 999;
    transition: left 0.3s ease;
    overflow-y: auto;
    padding-top: 1rem;
  }

  .sidebar.active {
    left: 0;
  }

  .topics-list {
    max-height: calc(100vh - 200px);
  }
}

/* ===========================
   Print Styles
   =========================== */
@media print {
  .app-header,
  .app-footer,
  .sidebar,
  .mobile-menu-toggle {
    display: none;
  }

  .topic-detail {
    padding: 0;
  }

  .accordion-content {
    max-height: none !important;
    padding: 1rem !important;
  }
}

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

.topic-content {
  animation: fadeIn 0.4s ease;
}

/* ===========================
   Utility Classes
   =========================== */
.hidden {
  display: none;
}

.text-center {
  text-align: center;
}

.mt-1 {
  margin-top: 0.5rem;
}

.mt-2 {
  margin-top: 1rem;
}

.mb-1 {
  margin-bottom: 0.5rem;
}

.mb-2 {
  margin-bottom: 1rem;
}
