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

:root {
  --primary-color: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary-color: #64748b;
  --accent-color: #f59e0b;
  --background: #ffffff;
  --surface: #f8fafc;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --success: #10b981;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
  --primary-color: #6366f1;
  --primary-hover: #4f46e5;
  --secondary-color: #a1a1aa;
  --accent-color: #f59e0b;
  --background: #0a0a0f;
  --surface: #1a1a2e;
  --text-primary: #f8fafc;
  --text-secondary: #a1a1aa;
  --border: #27272a;
  --success: #10b981;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--background);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* Page Management */
.page {
  display: none;
  min-height: 100vh;
}

.page.active {
  display: block;
}

/* Header */
.header {
  padding: 1rem 0;
  background: var(--background);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* Topbar Navigation Buttons */
.nav-buttons {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.btn-primary-small {
  background: var(--primary-color);
  color: white;
  padding: 0.5rem 1.25rem;
  border-radius: 0.375rem;
  font-weight: 500;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary-small:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-outline-small {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.5rem 1.25rem;
  border-radius: 0.375rem;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-outline-small:hover {
  background: var(--surface);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Hero Section */
.hero {
  padding: 4rem 0;
  background: linear-gradient(
    135deg,
    var(--surface) 0%,
    var(--background) 100%
  );
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 80px);
}

.hero-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 800px;
  width: 100%;
  gap: 2rem;
}

.hero-title {
  font-size: 3.5rem;
  font-weight: 700;
  line-height: 1.1;
  margin-bottom: 1.5rem;
  background: linear-gradient(
    135deg,
    var(--text-primary) 0%,
    var(--primary-color) 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-description {
  font-size: 1.25rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  line-height: 1.7;
}

.hero-stats {
  display: flex;
  gap: 2rem;
  margin-bottom: 2rem;
  justify-content: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-color);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.hero-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

/* Learning Card Visual */
.hero-visual {
  display: flex;
  justify-content: center;
  align-items: center;
}

.learning-card {
  background: var(--background);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 300px;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.course-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
}

.course-info h4 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.course-info p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.progress-bar {
  background: var(--surface);
  height: 8px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress {
  background: linear-gradient(90deg, var(--primary-color), var(--success));
  height: 100%;
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Buttons */
.btn {
  padding: 0.75rem 2rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

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

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

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  background: var(--surface);
  border-color: var(--primary-color);
}

.btn-outline {
  background: transparent;
  color: var(--primary-color);
  border: 2px solid var(--primary-color);
}

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

/* Auth Pages */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--surface);
}

.auth-card {
  background: var(--background);
  border-radius: 1rem;
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 480px;
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.back-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  margin-bottom: 1rem;
  padding: 0.5rem;
  border-radius: 0.25rem;
  transition: all 0.2s ease;
}

.back-btn:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.auth-header h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.auth-header p {
  color: var(--text-secondary);
  font-size: 1rem;
}

/* Forms */
.auth-form {
  margin-bottom: 1.5rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  transition: all 0.2s ease;
  background: var(--background);
  color: var(--text-primary);
}

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

/* Added password hint styling */
.password-hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
  line-height: 1.4;
}

.auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.auth-footer {
  text-align: center;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.auth-footer a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* Courses Page Styles */
.courses-main {
  padding: 2rem 0;
  min-height: calc(100vh - 80px);
}

/* Added purchased courses section styling */
.purchased-courses-section {
  margin-bottom: 4rem;
}

.purchased-courses-grid {
  display: grid;
  /* exactly 3 columns per row */
  grid-template-columns: repeat(3, 1fr);
  gap: 2.5rem;
  margin-bottom: 2rem;
}

.purchased-course-card {
  background: var(--background);
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 2px solid var(--success);
  transition: all 0.3s ease;
  position: relative;
}

.purchased-course-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.purchased-badge {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--success);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  z-index: 1;
}

.purchased-course-card .course-purchase {
  background: var(--success);
  cursor: default;
}

.purchased-course-card .course-purchase:hover {
  background: var(--success);
  transform: none;
}

.available-courses-section {
  margin-top: 2rem;
}

.courses-header {
  text-align: center;
  margin-bottom: 3rem;
}

.courses-header h2 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text-primary);
}

.courses-header p {
  font-size: 1.125rem;
  color: var(--text-secondary);
}

.courses-grid {
  display: grid;
  /*  exactly 3 columns per row */
  grid-template-columns: repeat(3, 1fr);
  gap: 2.5rem;
  margin-bottom: 2rem;
}

.course-card {
  background: var(--background);
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: all 0.3s ease;
}

.course-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.course-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--accent-color)
  );
  object-position: center;
  display: block;
}

.course-content {
  padding: 1.5rem;
}

.course-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.course-description {
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
  margin-bottom: 1rem;
}

.course-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.course-creator {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.course-creator strong {
  color: var(--text-primary);
}

.course-price {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary-color);
}

.course-purchase {
  width: 100%;
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 0.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.course-purchase:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.user-greeting {
  font-weight: 500;
  color: var(--text-primary);
  margin-right: 1rem;
}

/* Added toggle button styles for switching between course views */
.courses-toggle {
  display: flex;
  justify-content: center;
  margin-bottom: 3rem;
  background: var(--surface);
  border-radius: 0.75rem;
  padding: 0.5rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.toggle-btn {
  flex: 1;
  padding: 0.75rem 1.5rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 500;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-btn.active {
  background: var(--primary-color);
  color: white;
  box-shadow: var(--shadow);
}

.toggle-btn:hover:not(.active) {
  background: var(--background);
  color: var(--text-primary);
}

/* Added section visibility styles for toggle functionality */
.purchased-courses-section,
.available-courses-section {
  display: none;
}

.purchased-courses-section.active,
.available-courses-section.active {
  display: block;
}

/* Admin Dashboard Styles */
.admin-main {
  padding: 2rem 0;
  min-height: calc(100vh - 80px);
}

.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.admin-header h2 {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.admin-courses-section {
  margin-top: 2rem;
}

.admin-courses-grid {
  display: grid;
  /*  exactly 3 columns per row */
  grid-template-columns: repeat(3, 1fr);
  gap: 2.5rem;
}

.admin-course-card {
  background: var(--background);
  border-radius: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: all 0.3s ease;
  position: relative;
}

.admin-course-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.admin-course-actions {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.admin-course-card:hover .admin-course-actions {
  opacity: 1;
}

.action-btn {
  padding: 0.5rem;
  border: none;
  border-radius: 0.375rem;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

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

.edit-btn:hover {
  background: var(--primary-hover);
}

.delete-btn {
  background: #ef4444;
  color: white;
}

.delete-btn:hover {
  background: #dc2626;
}

/* Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--background);
  border-radius: 1rem;
  padding: 2rem;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text-primary);
}

.close-btn {
  background: none;
  border: none;
  font-size: 2rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: var(--surface);
  color: var(--text-primary);
}

.course-form {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.course-form textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 0.5rem;
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
  transition: all 0.2s ease;
  background: var(--background);
  color: var(--text-primary);
}

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

.modal-buttons {
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* Responsive Design */
@media (max-width: 1024px) and (min-width: 769px) {
  .courses-grid,
  .purchased-courses-grid,
  .admin-courses-grid {
    grid-template-columns: repeat(2, 1fr);
    /* Reduced gap for mobile devices */
    gap: 1.5rem;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 0 1rem;
  }

  .hero-content {
    gap: 2rem;
    text-align: center;
  }

  .hero-title {
    font-size: 2.5rem;
  }

  .hero-description {
    font-size: 1.125rem;
  }

  .hero-stats {
    justify-content: center;
  }

  .hero-actions {
    flex-direction: column;
    align-items: center;
  }

  .btn {
    width: 100%;
    max-width: 280px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 2rem;
    margin: 1rem;
  }

  .auth-buttons {
    gap: 0.75rem;
  }

  /* Responsive styles for topbar buttons */
  .nav-buttons {
    gap: 0.5rem;
  }

  .btn-primary-small,
  .btn-outline-small {
    padding: 0.375rem 1rem;
    font-size: 0.8125rem;
  }

  .courses-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .courses-header h2 {
    font-size: 2rem;
  }

  .course-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .course-image {
    height: 180px;
  }
}

@media (max-width: 480px) {
  .hero {
    padding: 2rem 0;
  }

  .hero-title {
    font-size: 2rem;
  }

  .hero-stats {
    flex-direction: column;
    gap: 1rem;
  }

  .auth-container {
    padding: 1rem;
  }

  .auth-card {
    padding: 1.5rem;
  }

  /* Hide nav buttons on very small screens to save space */
  .nav-buttons {
    display: none;
  }

  .courses-main {
    padding: 1rem 0;
  }

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

  .course-content {
    padding: 1rem;
  }

  .user-greeting {
    display: none;
  }

  .admin-main {
    padding: 1rem 0;
  }

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

  .admin-header h2 {
    font-size: 1.75rem;
  }

  .admin-courses-grid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .modal-content {
    padding: 1rem;
  }

  .modal-buttons {
    flex-direction: column;
  }

  .course-image {
    height: 160px;
  }
}

/* Added theme toggle button styles */
.theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.5rem;
  border-radius: 0.375rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
}

.theme-toggle:hover {
  background: var(--background);
  border-color: var(--primary-color);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

/* General image auto-resize rules for all course images */
.course-card img,
.admin-course-card img,
.purchased-course-card img {
  width: 100%;
  height: 200px;
  max-width: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
}

/* Ensure images in modals also resize properly */
.course-modal img {
  max-width: 100%;
  height: auto;
  border-radius: 0.5rem;
}
