/* ============================================
   DSA Mastery - Main Stylesheet
   Mobile-first, Dark/Light mode, Bootstrap 5
   ============================================ */

/* --- CSS Variables (Light Mode Default) --- */
:root,
[data-bs-theme='light'] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #e9ecef;
  --bg-card: #ffffff;
  --bg-sidebar: #f8f9fa;
  --bg-code: #1e1e1e;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --border-color: #dee2e6;
  --border-light: #e9ecef;
  --accent: #0d6efd;
  --accent-light: #cfe2ff;
  --success: #198754;
  --warning: #ffc107;
  --danger: #dc3545;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --gradient-hero: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --navbar-bg: rgba(255, 255, 255, 0.85);
  --sidebar-width: 280px;
}

[data-bs-theme='dark'] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: #1c2128;
  --bg-sidebar: #161b22;
  --bg-code: #0d1117;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --border-color: #30363d;
  --border-light: #21262d;
  --accent: #58a6ff;
  --accent-light: #1f2a3a;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
  --gradient-hero: linear-gradient(
    135deg,
    #1a1a2e 0%,
    #16213e 50%,
    #0f3460 100%
  );
  --navbar-bg: rgba(13, 17, 23, 0.9);
}

/* --- Base Styles --- */
* {
  box-sizing: border-box;
}

body {
  font-family:
    'Segoe UI',
    system-ui,
    -apple-system,
    sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition:
    background 0.3s,
    color 0.3s;
  overflow-x: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* --- Theme Toggle --- */
.theme-toggle {
  position: fixed;
  bottom: 80px;
  right: 20px;
  z-index: 1050;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 2px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: all 0.3s;
}

.theme-toggle:hover {
  transform: scale(1.1);
  border-color: var(--accent);
}

/* --- Navbar --- */
#mainNav {
  background: var(--navbar-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  z-index: 1030;
}

.navbar-brand {
  color: var(--text-primary) !important;
  font-size: 1.25rem;
}

.brand-icon {
  background: var(--gradient-hero);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.navbar .nav-link {
  color: var(--text-secondary) !important;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.navbar .nav-link:hover,
.navbar .nav-link.active {
  color: var(--accent) !important;
  background: var(--accent-light);
}

/* Search Form */
.search-form {
  max-width: 360px;
  width: 100%;
}

.search-form .input-group {
  border: 1px solid var(--border-color);
  border-radius: 20px;
  overflow: hidden;
  transition: border-color 0.3s;
}

.search-form .input-group:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.search-form .form-control {
  border: none;
  color: var(--text-primary);
  font-size: 0.875rem;
  padding: 0.4rem 0.75rem;
}

.search-form .form-control:focus {
  box-shadow: none;
}

.search-form .input-group-text {
  border: none;
  color: var(--text-muted);
  padding-left: 0.75rem;
}

.progress-nav {
  display: flex;
  align-items: center;
}

/* --- Layout: Sidebar + Content --- */
.main-wrapper {
  display: flex;
  min-height: calc(100vh - 56px);
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
  overflow-y: auto;
  padding: 0.75rem 0;
  transition: transform 0.3s;
  z-index: 1020;
}

.sidebar-header {
  padding: 0.5rem 0;
}

.sidebar-category {
  padding: 0.5rem 1rem 0.25rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  margin: 1px 0.5rem;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  transition: all 0.15s;
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  text-decoration: none;
}

.sidebar-link.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-link .sidebar-icon {
  width: 20px;
  text-align: center;
  font-size: 0.9rem;
}

.sidebar-footer {
  border-top: 1px solid var(--border-color);
  margin-top: 0.5rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 1.5rem;
  max-width: calc(100% - var(--sidebar-width));
  min-width: 0;
}

/* --- Footer --- */
.site-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 3rem 1.5rem 1.5rem;
  color: var(--text-secondary);
}

.footer-brand {
  color: var(--text-primary);
  font-weight: 700;
}

.footer-link {
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 0.2rem 0;
  display: block;
  transition: color 0.2s;
}

.footer-link:hover {
  color: var(--accent);
  text-decoration: none;
}

.stats-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
}

/* --- Mobile Bottom Nav --- */
.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--navbar-bg);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  padding: 0.4rem 0;
  z-index: 1030;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: var(--text-muted);
  font-size: 1.25rem;
  padding: 0.25rem 0.5rem;
  text-decoration: none;
  transition: color 0.2s;
  border-radius: 8px;
}

.bottom-nav-item small {
  font-size: 0.65rem;
  margin-top: 2px;
}

.bottom-nav-item.active,
.bottom-nav-item:hover {
  color: var(--accent);
  text-decoration: none;
}

/* --- Hero Section --- */
.hero-section {
  background: var(--gradient-hero);
  color: white;
  padding: 4rem 1.5rem;
  border-radius: 20px;
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
}

.hero-section::before {
  content: '';
  position: absolute;
  top: -50%;
  right: -10%;
  width: 400px;
  height: 400px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 50%;
}

.hero-section::after {
  content: '';
  position: absolute;
  bottom: -30%;
  left: -5%;
  width: 300px;
  height: 300px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 50%;
}

.hero-section h1 {
  font-size: clamp(1.75rem, 5vw, 3rem);
  font-weight: 800;
  line-height: 1.2;
}

.hero-section .lead {
  font-size: clamp(1rem, 2vw, 1.2rem);
  opacity: 0.9;
}

/* --- Cards --- */
.dsa-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  transition: all 0.3s;
  box-shadow: var(--shadow-sm);
}

.dsa-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.dsa-card .card-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  margin-bottom: 1rem;
}

.icon-blue {
  background: #cfe2ff;
  color: #0d6efd;
}
.icon-green {
  background: #d1e7dd;
  color: #198754;
}
.icon-purple {
  background: #e2d9f3;
  color: #6f42c1;
}
.icon-orange {
  background: #ffe5ca;
  color: #fd7e14;
}
.icon-red {
  background: #f8d7da;
  color: #dc3545;
}
.icon-teal {
  background: #cff4fc;
  color: #0dcaf0;
}

/* --- Topic Content --- */
.topic-content h2 {
  font-weight: 700;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-light);
}

.topic-content h3 {
  font-weight: 600;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.topic-content h4 {
  font-weight: 600;
  margin-top: 1.5rem;
  color: var(--text-secondary);
}

/* Code Block */
.code-block {
  background: var(--bg-code);
  border-radius: 12px;
  overflow: hidden;
  margin: 1.25rem 0;
  border: 1px solid var(--border-color);
}

.code-block pre {
  margin: 0;
  padding: 1.25rem;
  overflow-x: auto;
}

.code-block pre code {
  font-family:
    'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.7;
}

/* Info Cards */
.info-card {
  background: var(--bg-secondary);
  border-left: 4px solid var(--accent);
  border-radius: 0 12px 12px 0;
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
}

.info-card.warning {
  border-left-color: var(--warning);
}

.info-card.success {
  border-left-color: var(--success);
}

.info-card.danger {
  border-left-color: var(--danger);
}

/* Complexity Table */
.complexity-table {
  font-size: 0.9rem;
}

.complexity-table th {
  background: var(--bg-tertiary);
  font-weight: 600;
}

/* Step cards */
.step-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}

.step-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  margin-right: 0.75rem;
}

/* Quiz */
.quiz-question {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.quiz-option {
  display: block;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border-color);
  border-radius: 10px;
  margin-bottom: 0.5rem;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-primary);
}

.quiz-option:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.quiz-option input[type='radio'] {
  margin-right: 0.5rem;
}

.quiz-option.correct {
  border-color: var(--success) !important;
  background: #d1e7dd !important;
}

.quiz-option.incorrect {
  border-color: var(--danger) !important;
  background: #f8d7da !important;
}

/* Progress Tracker */
.progress-tracker {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
}

/* Search Results */
.search-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1050;
}

.search-results-panel {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 600px;
  max-height: 70vh;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  z-index: 1051;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
  transition: background 0.2s;
}

.search-result-item:hover {
  background: var(--bg-secondary);
  text-decoration: none;
}

.search-result-item:last-child {
  border-bottom: none;
}

/* Breadcrumb-like topic nav */
.topic-nav {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}

.topic-nav .badge {
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
}

/* Accordion customization */
.accordion-button:not(.collapsed) {
  background: var(--accent-light);
  color: var(--accent);
}

.accordion-button:focus {
  box-shadow: none;
  border-color: var(--accent);
}

/* Practice problem */
.problem-card {
  border-left: 4px solid var(--accent);
  background: var(--bg-card);
  border-radius: 0 12px 12px 0;
  padding: 1.25rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border-color);
  border-left-width: 4px;
}

.problem-card.easy {
  border-left-color: var(--success);
}
.problem-card.medium {
  border-left-color: var(--warning);
}
.problem-card.hard {
  border-left-color: var(--danger);
}

/* Tags / Pills */
.tag-pill {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  margin: 0.15rem;
}

/* Back to top */
.back-to-top {
  position: fixed;
  bottom: 130px;
  right: 20px;
  z-index: 1040;
}

/* Toast / Flash message */
.flash-message {
  position: fixed;
  top: 70px;
  right: 20px;
  z-index: 1060;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100px);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* --- Responsive --- */
@media (max-width: 991.98px) {
  .sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    height: calc(100vh - 56px);
    transform: translateX(-100%);
    z-index: 1040;
  }

  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .main-content {
    max-width: 100%;
    padding: 1rem;
  }

  .hero-section {
    padding: 2.5rem 1rem;
    border-radius: 12px;
  }

  .search-form {
    max-width: 100%;
  }

  .mobile-bottom-nav {
    display: flex;
  }

  body {
    padding-bottom: 70px;
  }

  .theme-toggle {
    bottom: 90px;
  }
}

@media (max-width: 575.98px) {
  .main-content {
    padding: 0.75rem;
  }

  .hero-section h1 {
    font-size: 1.5rem;
  }

  .dsa-card {
    padding: 1rem;
  }

  .topic-content h2 {
    font-size: 1.35rem;
  }

  .topic-content h3 {
    font-size: 1.15rem;
  }
}

/* Print Styles */
@media print {
  .sidebar,
  .mobile-bottom-nav,
  .theme-toggle,
  #mainNav {
    display: none !important;
  }
  .main-content {
    max-width: 100% !important;
    padding: 0 !important;
  }
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-in {
  animation: fadeInUp 0.5s ease forwards;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
