/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: 0.625rem 1.25rem;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  border: 2px solid transparent;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all var(--transition-base);
  text-decoration: none;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(255,255,255,0.3) 10%, transparent 10%);
  transform: scale(10);
  opacity: 0;
  transition: transform 0.5s, opacity 0.5s;
}

.btn:active::after {
  transform: scale(0);
  opacity: 1;
  transition: 0s;
}

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

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

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

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

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

.btn-accent:hover {
  background: var(--color-accent-light);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-colored-accent);
}

/* Button focus rings */
.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-ring);
}

.btn-accent:focus-visible {
  outline: none;
  box-shadow: var(--shadow-ring-accent);
}

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

.btn-ghost:hover {
  background: var(--color-border-light);
  color: var(--color-text);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: var(--text-xs);
}

.btn-lg {
  padding: 0.875rem 1.75rem;
  font-size: var(--text-base);
}

/* Cards */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  padding: var(--space-xl);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: transparent;
}

.card--flat:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--color-border);
}

/* Card with colored top accent line */
.card--accent-top::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient-primary);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
}

.card--accent-top.entry::before { background: var(--color-entry); }
.card--accent-top.representative::before { background: var(--color-representative); }
.card--accent-top.principal::before { background: var(--color-principal); }

/* Glass card variant */
.card--glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
}

/* Interactive card with colored shadow */
.card--interactive:hover {
  box-shadow: var(--shadow-colored-primary);
}

.card--interactive.entry:hover {
  box-shadow: 0 4px 14px -3px rgba(59, 130, 246, 0.25);
}

.card--interactive.representative:hover {
  box-shadow: 0 4px 14px -3px rgba(16, 185, 129, 0.25);
}

.card--interactive.principal:hover {
  box-shadow: 0 4px 14px -3px rgba(139, 92, 246, 0.25);
}

/* Mobile card optimizations */
@media (max-width: 768px) {
  .card {
    padding: var(--space-lg);
  }

  .card:hover {
    transform: none;
    box-shadow: var(--shadow-sm);
    border-color: var(--color-border);
  }

  .card:active {
    box-shadow: var(--shadow-md);
    background: var(--color-surface-sunken);
  }
}

.card__header {
  margin-bottom: var(--space-md);
}

.card__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-xs);
}

.card__subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.card__body {
  margin-bottom: var(--space-md);
}

.card__footer {
  padding-top: var(--space-md);
  border-top: 1px solid var(--color-border-light);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0.25rem 0.75rem;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
}

.badge-entry {
  background: var(--color-primary-bg);
  color: var(--color-entry);
  border-color: rgba(59, 130, 246, 0.15);
}

.badge-representative {
  background: var(--color-accent-bg);
  color: var(--color-representative);
  border-color: rgba(16, 185, 129, 0.15);
}

.badge-principal {
  background: var(--color-purple-bg);
  color: var(--color-principal);
  border-color: rgba(139, 92, 246, 0.15);
}

/* Badge with dot indicator */
.badge--dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Outline badge variant */
.badge--outline {
  background: transparent;
  border: 1.5px solid currentColor;
}

/* Badge sizes */
.badge--sm {
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
}

.badge--lg {
  padding: 0.375rem 1rem;
  font-size: var(--text-sm);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-success {
  background: var(--color-accent-bg);
  color: var(--color-accent-dark);
}

.badge-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

/* Accordion */
.accordion {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.accordion-item {
  border-bottom: 1px solid var(--color-border);
}

.accordion-item:last-child {
  border-bottom: none;
}

.accordion-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--color-surface);
  border: none;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  text-align: left;
  transition: background var(--transition-fast);
}

.accordion-trigger:hover {
  background: var(--color-border-light);
  padding-left: calc(var(--space-lg) + 4px);
}

.accordion-icon {
  width: 20px;
  height: 20px;
  transition: transform var(--transition-base);
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.accordion-item.active .accordion-icon {
  transform: rotate(180deg);
}

.accordion-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height var(--transition-slow) ease;
}

.accordion-item.active .accordion-content {
  max-height: 2000px;
}

.accordion-body {
  padding: 0 var(--space-lg) var(--space-lg);
}

/* Tabs */
.tabs {
  display: flex;
  gap: var(--space-xs);
  border-bottom: 2px solid var(--color-border);
  margin-bottom: var(--space-xl);
  overflow-x: auto;
}

.tab {
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition-fast);
  white-space: nowrap;
  font-family: var(--font-sans);
}

.tab:hover {
  color: var(--color-primary);
}

.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Progress bar */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--color-border-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
  transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 0;
  position: relative;
}

.progress-bar__fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.3) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 2s ease-in-out infinite;
  border-radius: var(--radius-full);
}

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

.progress-label {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-xs);
}

/* Weight bar (for topic percentages) */
.weight-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.weight-bar__track {
  flex: 1;
  height: 6px;
  background: var(--color-border-light);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.weight-bar__fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.weight-bar__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  min-width: 36px;
  text-align: right;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: calc(var(--space-xl) + env(safe-area-inset-bottom, 0));
  right: calc(var(--space-xl) + env(safe-area-inset-right, 0));
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

@media (max-width: 768px) {
  .toast-container {
    bottom: calc(56px + env(safe-area-inset-bottom, 0) + var(--space-sm));
    right: var(--space-md);
    left: var(--space-md);
  }

  .toast {
    max-width: 100%;
  }
}

.toast {
  background: var(--color-text);
  color: white;
  padding: var(--space-md) var(--space-lg);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  max-width: 360px;
}

.toast--success { background: var(--color-accent-dark); }
.toast--error { background: var(--color-danger); }
.toast--warning { background: var(--color-warning); color: var(--color-text); }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: var(--z-modal-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  z-index: var(--z-modal);
  max-width: 560px;
  width: calc(100% - 2rem);
  max-height: 85vh;
  max-height: 85dvh;
  overflow-y: auto;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal.active {
  opacity: 1;
  visibility: visible;
  transform: translate(-50%, -50%) scale(1);
}

/* Checkbox custom */
.checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
}

.checkbox input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  flex-shrink: 0;
}

.checkbox input[type="checkbox"]:checked {
  background: var(--color-accent);
  border-color: var(--color-accent);
}

.checkbox input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 5px;
  top: 1px;
  width: 6px;
  height: 11px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Tooltip */
.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);
  background: var(--color-text);
  color: white;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  pointer-events: none;
}

.tooltip:hover::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(-8px);
}

/* Stat card */
.stat {
  text-align: center;
  padding: var(--space-lg);
}

.stat__value {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  color: var(--color-primary);
  margin-bottom: var(--space-xs);
}

.stat__label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Quick facts */
.quick-facts {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
}

.quick-facts__item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--color-border-light);
  font-size: var(--text-sm);
}

.quick-facts__item:last-child {
  border-bottom: none;
}

.quick-facts__label {
  color: var(--color-text-muted);
}

.quick-facts__value {
  font-weight: var(--weight-semibold);
  color: var(--color-text);
}

/* Divider */
.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-xl) 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-xl);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-xl);
}

.empty-state__icon {
  font-size: 3rem;
  opacity: 0.3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  margin: 0 auto var(--space-lg);
  background: var(--color-border-light);
  border-radius: var(--radius-full);
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--color-text);
  margin-bottom: var(--space-sm);
}

.empty-state__desc {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 360px;
  margin: 0 auto var(--space-lg);
}

/* Inline quiz answer buttons */
.answer-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-md) var(--space-lg);
  margin-bottom: var(--space-sm);
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--color-text);
  transition: all var(--transition-fast);
}

.answer-btn:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-bg);
}

.answer-btn--correct {
  border-color: var(--color-accent);
  background: var(--color-accent-bg);
  color: var(--color-accent-dark);
}

.answer-btn--incorrect {
  border-color: var(--color-danger);
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.answer-btn--correct::before { content: '\2713  '; font-weight: bold; }
.answer-btn--incorrect::before { content: '\2717  '; font-weight: bold; }

.answer-btn--disabled {
  pointer-events: none;
  opacity: 0.7;
  cursor: default;
}

.answer-btn--disabled:hover {
  border-color: var(--color-border);
  background: var(--color-surface);
}

.answer-btn--revealed {
  opacity: 1;
}

.answer-btn--shake {
  animation: shake 0.5s ease;
}

/* ===== Input Focus Glow ===== */
select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.1);
}

/* ===== Skeleton Loading ===== */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--color-border-light);
  border-radius: var(--radius-md);
}

.skeleton::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.5) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}

.skeleton--text {
  height: 16px;
  width: 80%;
  margin-bottom: var(--space-sm);
}

.skeleton--text-short {
  height: 16px;
  width: 50%;
  margin-bottom: var(--space-sm);
}

.skeleton--title {
  height: 24px;
  width: 60%;
  margin-bottom: var(--space-md);
}

.skeleton--circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton--card {
  height: 200px;
  border-radius: var(--radius-xl);
  margin-bottom: var(--space-lg);
}

.skeleton--badge {
  height: 24px;
  width: 72px;
  border-radius: var(--radius-full);
}

.skeleton--btn {
  height: 44px;
  width: 140px;
  border-radius: var(--radius-lg);
}

/* ===== Loading Spinner ===== */
.spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner--sm {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

.spinner--lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

/* ===== Progress Circle ===== */
.progress-circle {
  position: relative;
  width: 120px;
  height: 120px;
}

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

.progress-circle__track {
  fill: none;
  stroke: var(--color-border-light);
  stroke-width: 8;
}

.progress-circle__fill {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 8;
  stroke-linecap: round;
  transition: stroke-dashoffset 1.2s var(--ease-out-expo);
}

.progress-circle__label {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.progress-circle__value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--color-text);
  line-height: 1;
}

.progress-circle__caption {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ===== Stat Card with Icon ===== */
.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  transition: all var(--transition-base);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

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

.stat-card__icon--primary {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

.stat-card__icon--accent {
  background: var(--color-accent-bg);
  color: var(--color-accent);
}

.stat-card__icon--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.stat-card__icon--purple {
  background: var(--color-purple-bg);
  color: var(--color-purple);
}

/* ===== Mobile Touch Target Fixes ===== */
@media (max-width: 768px) {
  .tab {
    padding: var(--space-md);
    min-height: var(--touch-target-min);
  }

  .btn-sm {
    padding: 0.625rem 1rem;
    min-height: var(--touch-target-min);
  }

  .checkbox {
    min-height: var(--touch-target-min);
    padding: var(--space-xs) 0;
  }

  .checkbox input[type="checkbox"] {
    width: 24px;
    height: 24px;
  }

  .accordion-trigger {
    min-height: var(--touch-target-min);
    padding: var(--space-md) var(--space-lg);
  }

  .answer-btn {
    min-height: var(--touch-target-min);
    padding: var(--space-md) var(--space-lg);
  }
}

/* ===== Reduced Motion for Skeletons ===== */
@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
  }

  .spinner {
    animation-duration: 1.5s;
  }

  .progress-bar__fill::after {
    animation: none;
  }
}
