/**
 * GCSE Revision Hub - Component Library v2
 *
 * Feature: F-032.2 Component Library (Buttons, Cards, Badges)
 * Version: 1.0
 * Created: 2026-01-20
 *
 * This file contains all reusable UI components for the modern UI redesign.
 * All components use design tokens from design-system.css.
 *
 * DEPENDENCIES:
 * - css/design-system.css (MUST be loaded first)
 *
 * USAGE:
 * - All components work in both light and dark themes
 * - All components respect prefers-reduced-motion
 * - All components meet WCAG AA accessibility standards
 */

/* ============================================================================
   BUTTONS
   ============================================================================ */

/* --------------------------------------------------------------------------
   Base Button
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  min-height: 44px; /* WCAG touch target */
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  user-select: none;
  transition: var(--transition-transform), var(--transition-shadow);
  position: relative;
  overflow: hidden;
}

.btn:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Button Variants
   -------------------------------------------------------------------------- */

.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), #2563eb);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

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

.btn-primary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: linear-gradient(135deg, var(--color-secondary), #7c3aed);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

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

.btn-secondary:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-success {
  background: linear-gradient(135deg, var(--color-success), #16a34a);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

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

.btn-success:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-danger {
  background: linear-gradient(135deg, var(--color-error), #dc2626);
  color: var(--text-inverse);
  box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-error);
}

.btn-danger:active {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 2px solid var(--border-default);
  box-shadow: none;
}

.btn-outline:hover {
  background: var(--bg-interactive);
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  box-shadow: none;
}

.btn-ghost:hover {
  background: var(--bg-interactive);
  color: var(--text-primary);
}

.btn-ghost:active {
  transform: scale(0.98);
}

/* --------------------------------------------------------------------------
   Button Sizes
   -------------------------------------------------------------------------- */

.btn-sm {
  min-height: 32px;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
}

/* M2-002: Touch target enhancement for small buttons on touch devices */
@media (hover: none) and (pointer: coarse) {
  .btn-sm {
    min-height: 44px; /* WCAG AA touch target */
    padding: var(--space-3) var(--space-4);
  }
}

.btn-md {
  /* Default size - already defined in .btn */
}

.btn-lg {
  min-height: 52px;
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-base);
}

/* --------------------------------------------------------------------------
   Button States
   -------------------------------------------------------------------------- */

.btn:disabled,
.btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
  transform: none !important;
  box-shadow: none !important;
}

.btn.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

.btn.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --------------------------------------------------------------------------
   Button Icon Support
   -------------------------------------------------------------------------- */

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn-lg svg {
  width: 20px;
  height: 20px;
}

/* ============================================================================
   CARDS
   ============================================================================ */

/* --------------------------------------------------------------------------
   Base Card (with Glassmorphism)
   -------------------------------------------------------------------------- */

.card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur)); /* Safari support */
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-md);
  transition: var(--transition-all);
}

/* --------------------------------------------------------------------------
   Card Sections
   -------------------------------------------------------------------------- */

.card-header {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--glass-border);
  margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) var(--space-4);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0;
}

.card-body {
  padding: var(--space-5);
  color: var(--text-secondary);
  line-height: var(--leading-relaxed);
}

.card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--glass-border);
  background: var(--bg-subtle);
  margin: var(--space-4) calc(-1 * var(--space-4)) calc(-1 * var(--space-4));
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* --------------------------------------------------------------------------
   Card Variants
   -------------------------------------------------------------------------- */

.card-interactive {
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}

.card-interactive:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-strong);
}

.card-interactive:active {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* --------------------------------------------------------------------------
   Action Cards (Flashcards/Quiz Style)
   -------------------------------------------------------------------------- */

.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-6);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  text-align: center;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition: var(--transition-all);
  min-height: 200px;
  justify-content: center;
}

.action-card__icon {
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-4);
  flex-shrink: 0;
}

.action-card__icon svg {
  width: 32px;
  height: 32px;
}

.action-card__content {
  width: 100%;
}

.action-card__title {
  font-size: var(--text-xl);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0 0 var(--space-2) 0;
}

.action-card__count {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin: 0;
}

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

/* Feature-colored glass tints */
.action-card--flashcards {
  background: rgba(139, 92, 246, 0.05); /* Purple tint */
}

.action-card--flashcards .action-card__icon {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(139, 92, 246, 0.05));
  color: var(--color-secondary);
}

.action-card--flashcards:hover {
  border-color: var(--color-secondary);
  box-shadow: var(--shadow-secondary);
}

.action-card--quiz {
  background: rgba(59, 130, 246, 0.05); /* Blue tint */
}

.action-card--quiz .action-card__icon {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
  color: var(--color-primary);
}

.action-card--quiz:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-primary);
}

.action-card--disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   Subject Cards
   -------------------------------------------------------------------------- */

.subject-card {
  display: flex;
  flex-direction: column;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-left: 4px solid var(--subject-color, var(--color-primary));
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-decoration: none;
  color: inherit;
  transition: var(--transition-all);
  min-width: 280px;
}

.subject-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--subject-color, var(--color-primary));
}

.subject-card__illustration {
  height: 120px;
  background: linear-gradient(135deg,
    rgba(var(--subject-color-rgb, 59, 130, 246), 0.1),
    rgba(var(--subject-color-rgb, 59, 130, 246), 0.05));
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.subject-card__illustration img {
  max-height: 80%;
  max-width: 80%;
  object-fit: contain;
}

.subject-card__content {
  padding: var(--space-4);
}

.subject-card__name {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0 0 var(--space-2) 0;
}

.subject-card__stats {
  display: flex;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.subject-card__stat {
  display: flex;
  flex-direction: column;
}

.subject-card__stat-value {
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.subject-card__stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}

.subject-card__progress {
  height: 4px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.subject-card__progress-bar {
  height: 100%;
  background: var(--subject-color, var(--color-primary));
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

.subject-card__actions {
  display: flex;
  border-top: 1px solid var(--glass-border);
}

.subject-card__action {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-3);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  cursor: pointer;
  transition: var(--transition-colors);
}

.subject-card__action:first-child {
  border-right: 1px solid var(--glass-border);
}

.subject-card__action svg {
  width: 20px;
  height: 20px;
}

.subject-card__action--flashcards:hover {
  color: var(--color-secondary);
  background: rgba(139, 92, 246, 0.05);
}

.subject-card__action--quiz:hover {
  color: var(--color-primary);
  background: rgba(59, 130, 246, 0.05);
}

/* --------------------------------------------------------------------------
   Task Cards
   -------------------------------------------------------------------------- */

.task-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  min-width: 280px;
  cursor: pointer;
  transition: var(--transition-all);
}

.task-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.task-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.task-card__icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.task-card__icon svg {
  width: 20px;
  height: 20px;
}

.task-card--learn .task-card__icon {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
  color: var(--feature-learn);
}

.task-card--review .task-card__icon {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(139, 92, 246, 0.05));
  color: var(--feature-review);
}

.task-card--test .task-card__icon {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.05));
  color: var(--feature-test);
}

.task-card__type {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-muted);
}

.task-card__title {
  font-size: var(--text-base);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0;
}

.task-card__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.task-card__xp {
  color: var(--color-warning);
  font-weight: var(--font-semibold);
}

/* ============================================================================
   PROGRESS INDICATORS
   ============================================================================ */

/* --------------------------------------------------------------------------
   Linear Progress Bar
   -------------------------------------------------------------------------- */

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), #2563eb);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

/* Progress bar sizes */
.progress-bar--sm {
  height: 4px;
}

.progress-bar--md {
  height: 8px;
}

.progress-bar--lg {
  height: 12px;
}

/* Progress bar variants */
.progress-bar--success .progress-bar__fill {
  background: linear-gradient(90deg, var(--color-success), #16a34a);
}

.progress-bar--warning .progress-bar__fill {
  background: linear-gradient(90deg, var(--color-warning), #d97706);
}

.progress-bar--error .progress-bar__fill {
  background: linear-gradient(90deg, var(--color-error), #dc2626);
}

.progress-bar--gradient .progress-bar__fill {
  background: linear-gradient(90deg, #ef4444 0%, #f59e0b 50%, #22c55e 100%);
}

/* --------------------------------------------------------------------------
   Circular Progress (Mastery Ring)
   -------------------------------------------------------------------------- */

.progress-circle {
  position: relative;
  width: 48px;
  height: 48px;
}

.progress-circle svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.progress-circle__bg {
  fill: none;
  stroke: var(--bg-subtle);
  stroke-width: 3;
}

.progress-circle__fill {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: calc(100 - var(--progress, 0));
  transition: stroke-dashoffset var(--duration-slow) var(--ease-out);
}

.progress-circle__value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

/* Mastery ring alias */
.mastery-ring {
  position: relative;
  width: 48px;
  height: 48px;
}

.mastery-ring svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.mastery-ring__bg {
  fill: none;
  stroke: var(--bg-subtle);
  stroke-width: 3;
}

.mastery-ring__fill {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: calc(100 - var(--progress, 0));
  transition: stroke-dashoffset var(--duration-slow) var(--ease-out);
}

.mastery-ring__value {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  color: var(--text-primary);
}

/* ============================================================================
   BADGES & TAGS
   ============================================================================ */

/* --------------------------------------------------------------------------
   Base Badge
   -------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-2xs);
  font-weight: var(--font-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Badge Variants
   -------------------------------------------------------------------------- */

.badge--default {
  background: var(--bg-subtle);
  color: var(--text-secondary);
}

.badge--primary {
  background: rgba(59, 130, 246, 0.15);
  color: var(--color-primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge--secondary {
  background: rgba(139, 92, 246, 0.15);
  color: var(--color-secondary);
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.badge--success {
  background: rgba(34, 197, 94, 0.15);
  color: var(--color-success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge--warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--color-warning);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge--error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-error);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge--info {
  background: rgba(59, 130, 246, 0.15);
  color: var(--color-primary);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

/* --------------------------------------------------------------------------
   Special Badges
   -------------------------------------------------------------------------- */

/* Level Badge */
.level-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: var(--text-inverse);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
}

.level-badge__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.level-badge__text {
  line-height: 1;
}

/* Streak Badge */
.streak-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: var(--text-inverse);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
}

.streak-badge__icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.streak-badge__count {
  line-height: 1;
}

.streak-badge__label {
  font-weight: var(--font-normal);
  opacity: 0.9;
  line-height: 1;
}

.streak-badge__multiplier {
  margin-left: var(--space-1);
  padding-left: var(--space-2);
  border-left: 1px solid rgba(255, 255, 255, 0.3);
  line-height: 1;
}

/* ============================================================================
   FORM ELEMENTS
   ============================================================================ */

/* --------------------------------------------------------------------------
   Text Input
   -------------------------------------------------------------------------- */

.form-input,
.input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  min-height: 44px; /* WCAG touch target */
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  transition: var(--transition-all);
}

.form-input::placeholder,
.input::placeholder {
  color: var(--text-muted);
}

.form-input:hover,
.input:hover {
  border-color: var(--border-strong);
}

.form-input:focus,
.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-input:disabled,
.input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-subtle);
}

/* Input states */
.form-input.error,
.input.error {
  border-color: var(--color-error);
}

.form-input.error:focus,
.input.error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.15);
}

.form-input.success,
.input.success {
  border-color: var(--color-success);
}

.form-input.success:focus,
.input.success:focus {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

/* --------------------------------------------------------------------------
   Select Dropdown
   -------------------------------------------------------------------------- */

.form-select,
.select {
  appearance: none;
  width: 100%;
  padding: var(--space-3) var(--space-10) var(--space-3) var(--space-4);
  min-height: 44px;
  background: var(--bg-surface);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 16px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  cursor: pointer;
  transition: var(--transition-all);
}

.form-select:hover,
.select:hover {
  border-color: var(--border-strong);
}

.form-select:focus,
.select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-select:disabled,
.select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background-color: var(--bg-subtle);
}

/* --------------------------------------------------------------------------
   Textarea
   -------------------------------------------------------------------------- */

.form-textarea,
.textarea {
  width: 100%;
  min-height: 120px;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  resize: vertical;
  transition: var(--transition-all);
}

.form-textarea::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.form-textarea:hover,
.textarea:hover {
  border-color: var(--border-strong);
}

.form-textarea:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-textarea:disabled,
.textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-subtle);
}

/* --------------------------------------------------------------------------
   Form Labels
   -------------------------------------------------------------------------- */

.form-label,
.label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.form-label--required::after,
.label--required::after {
  content: '*';
  margin-left: var(--space-1);
  color: var(--color-error);
}

/* --------------------------------------------------------------------------
   Form Groups
   -------------------------------------------------------------------------- */

.form-group {
  margin-bottom: var(--space-5);
}

.form-hint {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.form-error {
  display: block;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-error);
}

/* ============================================================================
   ACCESSIBILITY: REDUCED MOTION SUPPORT
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .btn,
  .card,
  .card-interactive,
  .action-card,
  .subject-card,
  .task-card {
    transition: none;
  }

  .btn:hover,
  .card-interactive:hover,
  .action-card:hover,
  .subject-card:hover,
  .task-card:hover {
    transform: none;
  }

  .btn:active,
  .card-interactive:active,
  .action-card:active {
    transform: none;
  }

  .progress-bar__fill,
  .progress-circle__fill,
  .mastery-ring__fill,
  .subject-card__progress-bar {
    transition: none;
  }
}

/* ============================================================================
   RESPONSIVE UTILITIES
   ============================================================================ */

/* Mobile adjustments */
@media (max-width: 640px) {
  .btn-lg {
    min-height: 48px;
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-sm);
  }

  .action-card {
    min-height: 160px;
    padding: var(--space-5);
  }

  .action-card__icon {
    width: 48px;
    height: 48px;
  }

  .action-card__icon svg {
    width: 24px;
    height: 24px;
  }

  .subject-card {
    min-width: 240px;
  }

  .task-card {
    min-width: 240px;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .btn,
  .form-input,
  .form-select,
  .form-textarea {
    min-height: 48px; /* Larger touch targets on mobile */
  }
}

/* ============================================================================
   SITE HEADER (STICKY NAVIGATION)
   ============================================================================ */

.site-header {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 300;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  justify-content: center;
}

.site-header-inner {
  width: 100%;
  max-width: 800px;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

/* Left section: brand/logo */
.site-header .header-left {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.header-brand {
  font-weight: var(--font-semibold);
  font-size: var(--text-base);
  color: var(--text-primary);
  white-space: nowrap;
}

/* Center section: search bar */
.site-header .header-center {
  flex: 1;
  max-width: 500px;
  margin: 0 auto;
}

.header-search-wrapper {
  position: relative;
  width: 100%;
}

.header-search-input {
  width: 100%;
  padding: var(--space-2) var(--space-2) var(--space-2) 36px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: all var(--duration-fast);
}

.header-search-input::placeholder {
  color: var(--text-muted);
}

.header-search-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.header-search-icon {
  position: absolute;
  left: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.header-search-shortcut {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  padding: 2px 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  font-size: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

/* Right section: theme toggle + profile + sign out */
.site-header .header-right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.header-theme-toggle,
.header-sign-out {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--duration-fast);
}

.header-theme-toggle:hover,
.header-sign-out:hover {
  background: var(--bg-interactive);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.header-theme-toggle:active,
.header-sign-out:active {
  transform: scale(0.95);
}

/* A3-001: Focus states for keyboard navigation (WCAG AA) */
.header-theme-toggle:focus-visible,
.header-sign-out:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-color: var(--color-primary);
}

/* Mobile responsive - M2-001: Header mobile optimization */
@media (max-width: 600px) {
  .site-header-inner {
    padding: var(--space-2) var(--space-3);
    gap: var(--space-2);
  }

  .site-header .header-center {
    max-width: none;
    /* Reduce min-width to prevent cramping buttons */
    min-width: 0;
  }

  /* Ensure adequate touch targets on mobile (WCAG) */
  .header-theme-toggle,
  .header-sign-out {
    width: 40px;
    height: 40px;
    min-width: 40px; /* Prevent shrinking */
    flex-shrink: 0;
  }

  /* Better spacing for right buttons on mobile */
  .site-header .header-right {
    gap: var(--space-1);
  }

  .header-search-shortcut {
    display: none;
  }

  /* Compact search input on mobile */
  .header-search-input {
    font-size: var(--text-xs);
    padding: var(--space-2) var(--space-2) var(--space-2) 32px;
  }
}

/* Extra small screens - hide search, prioritize actions */
@media (max-width: 400px) {
  .site-header .header-center {
    display: none;
  }

  .site-header .header-left {
    flex: 1;
  }

  /* Restore proper spacing when search is hidden */
  .site-header .header-right {
    gap: var(--space-2);
  }
}

/* ============================================================================
   PAGE CONTENT CONTAINER (800px MAX-WIDTH)
   ============================================================================ */

.homepage-content,
.page-content {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
}

/* All sections within the content should respect the container */
.homepage-content section,
.page-content section {
  margin-bottom: var(--space-8);
}

/* Mobile responsive */
@media (max-width: 600px) {
  .homepage-content,
  .page-content {
    padding: var(--space-4) var(--space-3);
  }

  .homepage-content section,
  .page-content section {
    margin-bottom: var(--space-6);
  }
}

/* ============================================================================
   SECTION OVERRIDES FOR 800PX BOUNDARY
   ============================================================================ */

/* Remove excessive padding from subjects section */
.subjects-section {
  margin: var(--space-8) 0 !important;
  padding: 0 !important;
}

/* Ensure section titles are within container */
.section-title,
.subjects-section-title,
.session-scroll-title {
  padding: 0 var(--space-4);
  margin-bottom: var(--space-4);
}

/* Practice cards should stay within boundary */
.practice-section {
  padding: 0;
}

.practice-cards-grid {
  padding: 0 var(--space-4);
}
