/* ===== DESIGN SYSTEM & CSS VARIABLES ===== */
:root {
  /* Brand Colors */
  --brand-primary: #1a365d;
  --brand-secondary: #2d3748;
  --brand-accent: #3182ce;
  --brand-success: #38a169;
  --brand-warning: #d69e2e;
  --brand-danger: #e53e3e;
  --brand-info: #3182ce;

  /* Light Theme Colors */
  --color-text-primary: #1a202c;
  --color-text-secondary: #4a5568;
  --color-text-muted: #718096;
  --color-text-inverse: #ffffff;

  --color-bg-primary: #ffffff;
  --color-bg-secondary: #f7fafc;
  --color-bg-tertiary: #edf2f7;
  --color-bg-overlay: rgba(0, 0, 0, 0.6);

  --color-border-light: #e2e8f0;
  --color-border-medium: #cbd5e0;
  --color-border-dark: #a0aec0;

  --color-surface-raised: #ffffff;
  --color-surface-sunken: #f7fafc;
  --color-surface-highlight: #ebf8ff;

  /* Shadows */
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1),
    0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1),
    0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Typography */
  --font-family-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-family-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono",
    Consolas, "Courier New", monospace;

  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 1.875rem;
  --font-size-4xl: 2.25rem;

  --font-weight-normal: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.625;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;

  /* Border Radius */
  --radius-sm: 0.125rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-2xl: 1rem;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms ease-in-out;
  --transition-base: 250ms ease-in-out;
  --transition-slow: 350ms ease-in-out;

  /* Z-Index Scale */
  --z-dropdown: 1000;
  --z-sticky: 1020;
  --z-fixed: 1030;
  --z-modal-backdrop: 1040;
  --z-modal: 1050;
  --z-popover: 1060;
  --z-tooltip: 1070;
}

/* Dark Theme Variables - Enhanced for Better Contrast */
@media (prefers-color-scheme: dark) {
  :root {
    /* High contrast text colors */
    --color-text-primary: #ffffff;
    --color-text-secondary: #d1d5db;
    --color-text-muted: #9ca3af;
    --color-text-inverse: #000000;

    /* Dark theme backgrounds */
    --color-bg-primary: #111827;
    --color-bg-secondary: #1f2937;
    --color-bg-tertiary: #374151;
    --color-bg-overlay: rgba(0, 0, 0, 0.8);

    /* Dark theme borders */
    --color-border-light: #374151;
    --color-border-medium: #4b5563;
    --color-border-dark: #6b7280;

    /* Dark theme surfaces */
    --color-surface-raised: #1f2937;
    --color-surface-sunken: #111827;
    --color-surface-highlight: #1e40af;

    /* Enhanced shadows for dark mode */
    --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5), 0 1px 2px 0 rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5),
      0 2px 4px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5),
      0 4px 6px -2px rgba(0, 0, 0, 0.4);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6),
      0 10px 10px -5px rgba(0, 0, 0, 0.4);
  }
}

/* Manual Dark Mode Toggle - Enhanced for Better Contrast */
[data-theme="dark"] {
  /* High contrast text colors */
  --color-text-primary: #ffffff;
  --color-text-secondary: #d1d5db;
  --color-text-muted: #9ca3af;
  --color-text-inverse: #000000;

  /* Dark theme backgrounds */
  --color-bg-primary: #111827;
  --color-bg-secondary: #1f2937;
  --color-bg-tertiary: #374151;
  --color-bg-overlay: rgba(0, 0, 0, 0.8);

  /* Dark theme borders */
  --color-border-light: #374151;
  --color-border-medium: #4b5563;
  --color-border-dark: #6b7280;

  /* Dark theme surfaces */
  --color-surface-raised: #1f2937;
  --color-surface-sunken: #111827;
  --color-surface-highlight: #1e40af;

  /* Enhanced shadows for dark mode */
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.5), 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5),
    0 2px 4px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5),
    0 4px 6px -2px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6),
    0 10px 10px -5px rgba(0, 0, 0, 0.4);
}

/* ===== RESET & BASE STYLES ===== */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg-secondary);
  transition: background-color var(--transition-base),
    color var(--transition-base);
}

/* ===== LAYOUT COMPONENTS ===== */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-6);
}

/* ===== HEADER ===== */
header {
  background: linear-gradient(
    135deg,
    var(--brand-primary) 0%,
    var(--brand-secondary) 100%
  );
  color: var(--color-text-inverse);
  padding: var(--space-8) 0;
  margin-bottom: var(--space-8);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

header::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.1) 0%,
    transparent 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  pointer-events: none;
}

.header-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-6);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-6);
  position: relative;
  z-index: 1;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--space-5);
}

.header-logo {
  height: 64px;
  width: auto;
  max-width: 220px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

.header-text h1 {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin: 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.header-text p {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
  opacity: 0.9;
  margin: var(--space-1) 0 0;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Navigation */
nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.nav-link {
  color: var(--color-text-inverse);
  text-decoration: none;
  padding: var(--space-3) var(--space-5);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius-lg);
  font-weight: var(--font-weight-medium);
  font-size: var(--font-size-sm);
  transition: all var(--transition-base);
  backdrop-filter: blur(10px);
  background: rgba(255, 255, 255, 0.1);
  position: relative;
  overflow: hidden;
}

.nav-link::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.2),
    transparent
  );
  transition: left var(--transition-base);
}

.nav-link:hover::before {
  left: 100%;
}

.nav-link:hover,
.nav-link:focus {
  background: var(--color-text-inverse);
  color: var(--brand-primary);
  border-color: var(--color-text-inverse);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* ===== HERO SECTION ===== */
.hero-section {
  background: linear-gradient(
    135deg,
    var(--brand-primary) 0%,
    var(--brand-secondary) 100%
  );
  padding: var(--space-32) 0;
  margin-bottom: var(--space-16);
  border-radius: var(--radius-2xl);
  position: relative;
  overflow: hidden;
}

.hero-section::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>');
  opacity: 0.3;
}

.hero-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-16);
  align-items: center;
  position: relative;
  z-index: 1;
}

.hero-title {
  font-size: clamp(2.5rem, 4vw, 4rem);
  font-weight: var(--font-weight-bold);
  line-height: 1.1;
  color: var(--color-text-inverse);
  margin-bottom: var(--space-8);
}

.hero-subtitle {
  font-size: var(--font-size-xl);
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: var(--space-12);
  line-height: 1.4;
}

.hero-cta {
  display: flex;
  gap: var(--space-6);
  flex-wrap: wrap;
}

.btn--large {
  padding: var(--space-6) var(--space-12);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}

.market-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-6);
}

.preview-card {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-lg);
  padding: var(--space-8);
  text-align: center;
  transition: all var(--transition-base);
}

.preview-card:hover {
  transform: translateY(-4px);
  background: rgba(255, 255, 255, 0.15);
}

.preview-label {
  display: block;
  font-size: var(--font-size-sm);
  color: rgba(255, 255, 255, 0.8);
  margin-bottom: var(--space-2);
}

.preview-value {
  display: block;
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-inverse);
}

/* ===== DASHBOARD LAYOUT ===== */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: var(--space-8);
}

/* ===== CARD COMPONENTS ===== */
.card,
.section-card,
.overview-stats,
.trends-section {
  background: var(--color-surface-raised);
  border-radius: var(--radius-xl);
  padding: var(--space-8);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border-light);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.card:hover,
.section-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.section-card {
  border-left: 4px solid var(--brand-accent);
}

/* Card Headers */
.card h2,
.section-card h2,
.overview-stats h2,
.trends-section h2 {
  color: var(--color-text-primary);
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.overview-stats h2 {
  text-align: center;
  justify-content: center;
}

/* ===== STATS GRID ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-6);
}

.stat-card {
  background: linear-gradient(
    135deg,
    var(--color-surface-highlight) 0%,
    var(--color-surface-raised) 100%
  );
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  border: 1px solid var(--color-border-light);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--brand-accent), var(--brand-success));
  opacity: 0;
  transition: opacity var(--transition-base);
}

.stat-card:hover::before {
  opacity: 1;
}

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

.stat-card h3 {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-3);
}

.stat-card .metric {
  font-size: var(--font-size-4xl);
  font-weight: var(--font-weight-bold);
  color: var(--brand-accent);
  margin: var(--space-4) 0;
  line-height: var(--line-height-tight);
}

.trend {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  margin: var(--space-3) 0;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  display: inline-block;
}

.trend.positive {
  color: var(--brand-success);
  background: rgba(56, 161, 105, 0.1);
}

.trend.negative {
  color: var(--brand-danger);
  background: rgba(229, 62, 62, 0.1);
}

.trend.neutral {
  color: var(--brand-warning);
  background: rgba(214, 158, 46, 0.1);
}

.stat-card small {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  display: block;
  margin-top: var(--space-2);
}

/* Enhanced Stat Card Interactions */
.stat-card-enhanced {
  position: relative;
  overflow: hidden;
  transition: all var(--transition-base);
  cursor: pointer;
}

.stat-card-enhanced::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  transition: left 0.6s ease;
}

.stat-card-enhanced:hover::before {
  left: 100%;
}

.stat-card-enhanced:hover {
  transform: translateY(-8px);
  box-shadow: var(--shadow-xl);
}

.stat-header {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.stat-icon {
  width: 48px;
  height: 48px;
  background: var(--color-surface-highlight);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-primary);
}

.stat-value {
  margin-bottom: var(--space-6);
}

.metric-large {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text-primary);
  line-height: 1.1;
}

.trend {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-sm);
  margin-top: var(--space-2);
}

.trend--positive {
  color: var(--brand-success);
}
.trend--negative {
  color: var(--brand-danger);
}
.trend--neutral {
  color: var(--brand-warning);
}

/* ===== FINANCING SECTION ===== */
.financing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-5);
  margin-bottom: var(--space-8);
}

.finance-metric {
  background: var(--color-surface-highlight);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-align: center;
  border: 1px solid var(--color-border-light);
  transition: all var(--transition-base);
}

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

.finance-metric h4 {
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.big-number {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  color: var(--brand-accent);
  margin: var(--space-3) 0;
  line-height: var(--line-height-tight);
}

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

/* ===== AFFORDABILITY ANALYSIS ===== */
.affordability-analysis {
  background: var(--color-surface-sunken);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  border: 1px solid var(--color-border-light);
  margin-top: var(--space-6);
}

.affordability-analysis h4 {
  color: var(--color-text-primary);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-5);
}

.affordability-stats {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.affordability-stats > div {
  padding: var(--space-4);
  background: var(--color-surface-raised);
  border-radius: var(--radius-md);
  border-left: 3px solid var(--brand-accent);
  transition: all var(--transition-base);
}

.affordability-stats > div:hover {
  transform: translateX(4px);
  box-shadow: var(--shadow-sm);
}

.affordability-index {
  background: var(--color-surface-highlight) !important;
  border-left-color: var(--brand-success) !important;
  font-weight: var(--font-weight-semibold);
}

/* ===== COSTS BREAKDOWN ===== */
.costs-breakdown {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-5);
  margin-bottom: var(--space-6);
}

.cost-category {
  background: linear-gradient(
    135deg,
    var(--color-surface-raised) 0%,
    var(--color-surface-highlight) 100%
  );
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-align: center;
  border: 1px solid var(--color-border-light);
  transition: all var(--transition-base);
}

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

.cost-category h4 {
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-3);
}

.cost-amount {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--brand-danger);
  margin: var(--space-3) 0;
  line-height: var(--line-height-tight);
}

.total-costs {
  background: var(--brand-secondary);
  color: var(--color-text-inverse);
  padding: var(--space-5);
  border-radius: var(--radius-lg);
  text-align: center;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  box-shadow: var(--shadow-md);
}

/* ===== SCHOOL DISTRICT ===== */
.school-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.district-overview {
  background: var(--color-surface-highlight);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
}

.district-overview h4 {
  color: var(--color-text-primary);
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-3);
}

.school-ranking {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-bold);
  color: var(--brand-success);
  margin: var(--space-3) 0;
}

.test-scores {
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-semibold);
  font-size: var(--font-size-base);
}

.schools-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-4);
}

.school {
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-align: center;
  transition: all var(--transition-base);
}

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

.school strong {
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
  display: block;
  margin-bottom: var(--space-2);
}

.school .ranking {
  color: var(--brand-success);
  font-weight: var(--font-weight-bold);
  margin: var(--space-2) 0;
}

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

.school-premium {
  background: var(--brand-success);
  color: var(--color-text-inverse);
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  text-align: center;
  font-weight: var(--font-weight-semibold);
  margin-top: var(--space-4);
}

/* ===== TRANSPORTATION ===== */
.transport-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-5);
}

.transport-option {
  background: linear-gradient(
    135deg,
    var(--color-surface-raised) 0%,
    var(--color-surface-highlight) 100%
  );
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  border: 1px solid var(--color-border-light);
  transition: all var(--transition-base);
}

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

.transport-option h4 {
  color: var(--color-text-primary);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-4);
}

.transport-option > div {
  margin: var(--space-2) 0;
  font-weight: var(--font-weight-medium);
}

.transport-option strong {
  color: var(--brand-accent);
  font-weight: var(--font-weight-bold);
}

.transport-option small {
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  display: block;
  margin-top: var(--space-2);
}

/* ===== METRICS GRID ===== */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: var(--space-6);
}

.chart-container {
  height: 320px;
  margin: var(--space-5) 0;
  position: relative;
}

/* ===== NEIGHBORHOOD LIST ===== */
.neighborhood-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.neighborhood-item {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  align-items: center;
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border-light);
  background: var(--color-surface-raised);
  transition: all var(--transition-base);
}

.neighborhood-item:hover {
  transform: translateX(4px);
  box-shadow: var(--shadow-md);
}

.neighborhood-item .name {
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
}

.neighborhood-item .price {
  font-weight: var(--font-weight-bold);
  color: var(--brand-accent);
  text-align: right;
}

.neighborhood-item .premium {
  font-weight: var(--font-weight-bold);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  text-align: center;
  min-width: 70px;
}

.premium-high .premium {
  background: var(--brand-danger);
  color: var(--color-text-inverse);
}

.premium-med .premium {
  background: var(--brand-warning);
  color: var(--color-text-inverse);
}

.premium-low .premium {
  background: var(--brand-success);
  color: var(--color-text-inverse);
}

.baseline .premium {
  background: var(--color-text-muted);
  color: var(--color-text-inverse);
}

.discount .premium {
  background: var(--brand-info);
  color: var(--color-text-inverse);
}

/* ===== ECONOMIC STATS ===== */
.economic-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-5);
}

.econ-metric {
  background: var(--color-surface-highlight);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  text-align: center;
  transition: all var(--transition-base);
}

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

.econ-metric h4 {
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-3);
}

.econ-metric .big-number {
  color: var(--brand-success);
}

.industries {
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  font-weight: var(--font-weight-semibold);
  background: var(--color-surface-raised);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  margin-top: var(--space-3);
}

/* ===== TRENDS SECTION ===== */
.trends-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: var(--space-6);
}

.trend-card {
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  border: 2px solid;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.trend-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  opacity: 0.3;
  transition: opacity var(--transition-base);
}

.trend-card:hover::before {
  opacity: 0.6;
}

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

.trend-card.positive {
  background: linear-gradient(
    135deg,
    rgba(56, 161, 105, 0.05) 0%,
    var(--color-surface-raised) 100%
  );
  border-color: var(--brand-success);
}

.trend-card.positive::before {
  background: var(--brand-success);
}

.trend-card.neutral {
  background: linear-gradient(
    135deg,
    rgba(214, 158, 46, 0.05) 0%,
    var(--color-surface-raised) 100%
  );
  border-color: var(--brand-warning);
}

.trend-card.neutral::before {
  background: var(--brand-warning);
}

.trend-card.opportunity {
  background: linear-gradient(
    135deg,
    rgba(49, 130, 206, 0.05) 0%,
    var(--color-surface-raised) 100%
  );
  border-color: var(--brand-accent);
}

.trend-card.opportunity::before {
  background: var(--brand-accent);
}

.trend-card h3 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  margin-bottom: var(--space-4);
  line-height: var(--line-height-tight);
}

.trend-card.positive h3 {
  color: var(--brand-success);
}
.trend-card.neutral h3 {
  color: var(--brand-warning);
}
.trend-card.opportunity h3 {
  color: var(--brand-accent);
}

.trend-card ul {
  list-style: none;
  padding: 0;
}

.trend-card li {
  margin: var(--space-3) 0;
  padding-left: var(--space-5);
  position: relative;
  line-height: var(--line-height-relaxed);
}

.trend-card li::before {
  content: "●";
  position: absolute;
  left: 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
  top: 0;
}

.trend-card.positive li::before {
  color: var(--brand-success);
}
.trend-card.neutral li::before {
  color: var(--brand-warning);
}
.trend-card.opportunity li::before {
  color: var(--brand-accent);
}

/* ===== MOBILE NAVIGATION SYSTEM ===== */
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: space-around;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  z-index: 1001;
  transition: all var(--transition-base);
  position: relative;
}

.hamburger-line {
  width: 100%;
  height: 3px;
  background-color: var(--color-text-inverse);
  border-radius: 2px;
  transition: all var(--transition-base);
  transform-origin: center;
}

.mobile-menu-toggle.active .hamburger-line:nth-child(1) {
  transform: rotate(45deg) translate(7px, 7px);
}

.mobile-menu-toggle.active .hamburger-line:nth-child(2) {
  opacity: 0;
}

.mobile-menu-toggle.active .hamburger-line:nth-child(3) {
  transform: rotate(-45deg) translate(7px, -7px);
}

.main-nav {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  position: relative;
}

.main-nav .nav-link {
  position: relative;
  overflow: hidden;
  transition: all var(--transition-base);
}

.main-nav .nav-link::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: var(--color-text-inverse);
  transition: all var(--transition-base);
  transform: translateX(-50%);
}

.main-nav .nav-link:hover::after {
  width: 100%;
}

.mobile-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.mobile-menu-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Large Desktop */
@media (min-width: 1400px) {
  .container {
    padding: 0 var(--space-8);
  }

  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop */
@media (max-width: 1200px) {
  .container {
    padding: 0 var(--space-5);
  }

  .stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  }

  .trends-grid {
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
  }

  .metrics-grid {
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  }
}

/* Tablet */
@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex !important;
  }

  .hero-content {
    grid-template-columns: 1fr;
    text-align: center;
  }

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

  .market-preview {
    grid-template-columns: 1fr;
    max-width: 300px;
    margin: 0 auto;
  }

  .enhanced-stats-grid {
    grid-template-columns: 1fr;
    gap: var(--space-6);
  }

  .financing-grid,
  .costs-breakdown,
  .transport-grid {
    grid-template-columns: 1fr;
  }

  .header-content {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-5);
    padding: 0 var(--space-4);
  }

  .header-brand {
    flex-direction: column;
    text-align: left;
    gap: var(--space-4);
    flex: 1;
  }

  .header-logo {
    height: 56px;
    max-width: 200px;
  }

  .header-text h1 {
    font-size: var(--font-size-2xl);
    line-height: var(--line-height-tight);
  }

  .header-text p {
    font-size: var(--font-size-base);
  }

  .main-nav {
    position: fixed;
    top: 0;
    right: -100%;
    width: 280px;
    height: 100vh;
    background: linear-gradient(
      135deg,
      var(--brand-primary) 0%,
      var(--brand-secondary) 100%
    );
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 80px 20px 20px;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    transform: translateX(100%);
    transition: transform var(--transition-slow) var(--ease-out);
    z-index: 1000;
    overflow-y: auto;
  }

  .main-nav.active {
    transform: translateX(0);
  }

  .main-nav .nav-link {
    opacity: 0;
    transform: translateX(20px);
    transition: all var(--transition-base);
  }

  .main-nav.active .nav-link {
    opacity: 1;
    transform: translateX(0);
  }

  .main-nav.active .nav-link:nth-child(1) {
    transition-delay: 0.1s;
  }
  .main-nav.active .nav-link:nth-child(2) {
    transition-delay: 0.2s;
  }
  .main-nav.active .nav-link:nth-child(3) {
    transition-delay: 0.3s;
  }
  .main-nav.active .nav-link:nth-child(4) {
    transition-delay: 0.4s;
  }
  .main-nav.active .nav-link:nth-child(5) {
    transition-delay: 0.5s;
  }

  .main-nav .nav-link {
    width: 100%;
    text-align: center;
    padding: var(--space-4) var(--space-5);
    margin: var(--space-2) 0;
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    transition: all var(--transition-base);
    color: var(--color-text-inverse);
    text-decoration: none;
  }

  .main-nav .nav-link:hover,
  .main-nav .nav-link:focus {
    background: var(--color-text-inverse);
    color: var(--brand-primary);
    transform: translateX(-4px);
    border-color: var(--color-text-inverse);
  }

  .stats-grid,
  .financing-grid,
  .costs-breakdown,
  .schools-grid,
  .transport-grid,
  .metrics-grid,
  .economic-stats,
  .trends-grid {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .neighborhood-item {
    grid-template-columns: 1fr;
    text-align: center;
    gap: var(--space-2);
    padding: var(--space-4);
  }

  .container {
    padding: 0 var(--space-4);
  }

  .section-card,
  .overview-stats,
  .trends-section,
  .card {
    padding: var(--space-5);
    margin-bottom: var(--space-5);
  }

  .section-card h2,
  .card h2 {
    font-size: var(--font-size-xl);
    text-align: center;
    justify-content: center;
  }

  .affordability-stats {
    gap: var(--space-3);
  }

  .affordability-stats > div {
    padding: var(--space-3);
  }

  .chart-container {
    height: 280px;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .hero-title {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: var(--font-size-lg);
  }

  .btn--large {
    padding: var(--space-4) var(--space-8);
    font-size: var(--font-size-base);
  }

  .header-logo {
    height: 48px;
    max-width: 180px;
  }

  .header-text h1 {
    font-size: var(--font-size-xl);
  }

  .header-text p {
    font-size: var(--font-size-sm);
  }

  .stat-card .metric,
  .big-number {
    font-size: var(--font-size-2xl);
  }

  .stat-card {
    padding: var(--space-4);
  }

  .stat-card h3 {
    font-size: var(--font-size-xs);
  }

  .nav-link {
    padding: var(--space-3);
    font-size: var(--font-size-sm);
  }

  .section-card,
  .overview-stats,
  .trends-section,
  .card {
    padding: var(--space-4);
  }

  .section-card h2,
  .card h2 {
    font-size: var(--font-size-lg);
  }

  .finance-metric,
  .cost-category,
  .econ-metric {
    padding: var(--space-4);
  }

  .finance-metric h4,
  .cost-category h4,
  .econ-metric h4 {
    font-size: var(--font-size-xs);
  }

  .trend-card {
    padding: var(--space-4);
  }

  .trend-card h3 {
    font-size: var(--font-size-lg);
  }

  .neighborhood-item .name {
    font-size: var(--font-size-sm);
  }

  .neighborhood-item .price {
    font-size: var(--font-size-base);
  }

  .premium {
    font-size: var(--font-size-xs);
    min-width: 60px;
    padding: var(--space-1) var(--space-2);
  }

  .chart-container {
    height: 240px;
  }
}

/* Small Mobile */
@media (max-width: 320px) {
  .container {
    padding: 0 var(--space-3);
  }

  .header-logo {
    height: 40px;
    max-width: 150px;
  }

  .header-text h1 {
    font-size: var(--font-size-lg);
  }

  .stat-card .metric,
  .big-number {
    font-size: var(--font-size-xl);
  }

  .section-card,
  .overview-stats,
  .trends-section,
  .card {
    padding: var(--space-3);
  }

  .nav-link {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
  }

  .chart-container {
    height: 200px;
  }
}

/* ===== ACCESSIBILITY & INTERACTION ===== */

/* Touch Targets */
@media (hover: none) and (pointer: coarse) {
  .nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  button,
  .btn-view,
  .btn-pdf {
    min-height: 44px;
    min-width: 44px;
  }

  .stat-card,
  .trend-card,
  .section-card {
    transition: none;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  :root {
    /* Light mode high contrast */
    --color-text-primary: #000000;
    --color-text-secondary: #000000;
    --color-text-muted: #333333;
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #ffffff;
    --color-surface-raised: #ffffff;
    --color-border-light: #000000;
    --color-border-medium: #000000;
    --shadow-sm: 0 0 0 1px #000000;
    --shadow-md: 0 0 0 2px #000000;
    --shadow-lg: 0 0 0 3px #000000;
  }

  [data-theme="dark"] {
    /* Dark mode high contrast */
    --color-text-primary: #ffffff;
    --color-text-secondary: #ffffff;
    --color-text-muted: #cccccc;
    --color-bg-primary: #000000;
    --color-bg-secondary: #000000;
    --color-surface-raised: #000000;
    --color-border-light: #ffffff;
    --color-border-medium: #ffffff;
  }

  .stat-card,
  .section-card,
  .trend-card,
  .card {
    border: 2px solid currentColor;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .header-logo {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  * {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }

  header {
    background: white !important;
    color: black !important;
    border: 2px solid black !important;
  }

  .nav-link {
    display: none !important;
  }

  .section-card,
  .overview-stats,
  .trends-section,
  .card {
    border: 1px solid black !important;
    page-break-inside: avoid;
    margin-bottom: var(--space-4) !important;
  }

  .trend-card {
    border: 1px solid black !important;
  }

  .header-logo {
    max-height: 40px !important;
  }

  .chart-container {
    display: none !important;
  }
}

/* ===== UTILITY CLASSES ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.focus-visible:focus {
  outline: 2px solid var(--brand-accent);
  outline-offset: 2px;
}

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

.font-bold {
  font-weight: var(--font-weight-bold);
}
.font-semibold {
  font-weight: var(--font-weight-semibold);
}
.font-medium {
  font-weight: var(--font-weight-medium);
}

.text-primary {
  color: var(--color-text-primary);
}
.text-secondary {
  color: var(--color-text-secondary);
}
.text-muted {
  color: var(--color-text-muted);
}

/* ===== ENHANCED CONTRAST FIXES ===== */

/* Ensure all text has proper contrast in all scenarios */
.notification {
  background: var(--color-surface-raised);
  color: var(--color-text-primary);
  border-left: 4px solid var(--brand-accent);
}

.notification.success {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-left-color: var(--brand-success);
}

.notification.error {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-left-color: var(--brand-danger);
}

.notification.warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border-left-color: var(--brand-warning);
}

/* Enhanced modal contrast */
.modal-content {
  background: var(--color-surface-raised);
  color: var(--color-text-primary);
}

.modal-header {
  color: var(--color-text-primary);
  border-bottom-color: var(--color-border-medium);
}

.modal-header h3 {
  color: var(--color-text-primary);
}

.modal-close {
  color: var(--color-text-secondary);
}

.modal-close:hover {
  color: var(--brand-danger);
}

/* Enhanced button contrast */
.btn {
  background-color: var(--color-surface);
  color: var(--color-text-primary);
  border-color: var(--color-border-medium);
}

.btn-primary {
  background-color: var(--brand-primary);
  color: var(--color-text-inverse);
  border-color: var(--brand-primary);
}

.btn-secondary {
  background-color: var(--brand-secondary);
  color: var(--color-text-inverse);
  border-color: var(--brand-secondary);
}

.btn-success {
  background-color: var(--brand-success);
  color: var(--color-text-inverse);
  border-color: var(--brand-success);
}

.btn-danger {
  background-color: var(--brand-danger);
  color: var(--color-text-inverse);
  border-color: var(--brand-danger);
}

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

.btn-outline:hover {
  background-color: var(--brand-primary);
  color: var(--color-text-inverse);
}

/* Enhanced card contrast */
.card,
.section-card,
.overview-stats,
.trends-section {
  background: var(--color-surface-raised);
  color: var(--color-text-primary);
  border-color: var(--color-border-light);
}

.card h2,
.section-card h2,
.overview-stats h2,
.trends-section h2 {
  color: var(--color-text-primary);
}

/* Enhanced alert contrast */
.alert-box {
  background: var(--color-surface-raised);
  color: var(--color-text-primary);
  border-color: var(--color-border-medium);
}

.alert-box.critical {
  background: var(--color-danger-bg);
  color: var(--color-danger-text);
  border-color: var(--brand-danger);
}

.alert-box.warning {
  background: var(--color-warning-bg);
  color: var(--color-warning-text);
  border-color: var(--brand-warning);
}

.alert-box.positive {
  background: var(--color-success-bg);
  color: var(--color-success-text);
  border-color: var(--brand-success);
}

/* Enhanced high contrast mode */
.high-contrast {
  --color-text-primary: #000000;
  --color-text-secondary: #000000;
  --color-text-muted: #333333;
  --color-bg-primary: #ffffff;
  --color-bg-secondary: #ffffff;
  --color-surface-raised: #ffffff;
  --color-border-light: #000000;
  --color-border-medium: #000000;
  --brand-primary: #0000ff;
  --brand-success: #008000;
  --brand-warning: #ff8c00;
  --brand-danger: #ff0000;
}

.high-contrast [data-theme="dark"] {
  --color-text-primary: #ffffff;
  --color-text-secondary: #ffffff;
  --color-text-muted: #cccccc;
  --color-bg-primary: #000000;
  --color-bg-secondary: #000000;
  --color-surface-raised: #000000;
  --color-border-light: #ffffff;
  --color-border-medium: #ffffff;
  --brand-primary: #ffffff;
  --brand-success: #ffffff;
  --brand-warning: #ffffff;
  --brand-danger: #ffffff;
}

/* Enhanced dark mode contrast */
@media (prefers-color-scheme: dark) {
  .notification {
    background: var(--color-surface-raised);
    color: var(--color-text-primary);
  }

  .modal-content {
    background: var(--color-surface-raised);
    color: var(--color-text-primary);
  }

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

  .card,
  .section-card,
  .overview-stats,
  .trends-section {
    background: var(--color-surface-raised);
    color: var(--color-text-primary);
  }
}

[data-theme="dark"] {
  .notification {
    background: var(--color-surface-raised);
    color: var(--color-text-primary);
  }

  .modal-content {
    background: var(--color-surface-raised);
    color: var(--color-text-primary);
  }

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

  .card,
  .section-card,
  .overview-stats,
  .trends-section {
    background: var(--color-surface-raised);
    color: var(--color-text-primary);
  }
}

/* Enhanced accessibility focus indicators */
*:focus-visible {
  outline: 2px solid var(--brand-accent);
  outline-offset: 2px;
}

/* Enhanced print styles */
@media print {
  .notification,
  .modal,
  .btn {
    background: white !important;
    color: black !important;
    border: 1px solid black !important;
  }

  .card,
  .section-card,
  .overview-stats,
  .trends-section {
    background: white !important;
    color: black !important;
    border: 1px solid black !important;
  }
}

/* ===== OVERRIDE INLINE WHITE TEXT STYLES ===== */

/* Override inline white text on light backgrounds */
[style*="color: white"],
[style*="color: #fff"],
[style*="color: #ffffff"],
[style*="color: white !important"],
[style*="color: #fff !important"],
[style*="color: #ffffff !important"] {
  color: var(--color-text-primary) !important;
}

/* Override white text in headers */
header[style*="color: white"],
header[style*="color: #fff"],
header[style*="color: #ffffff"],
nav[style*="color: white"],
nav[style*="color: #fff"],
nav[style*="color: #ffffff"] {
  color: var(--color-text-primary) !important;
}

/* Override white text in buttons */
button[style*="color: white"],
button[style*="color: #fff"],
button[style*="color: #ffffff"],
.btn[style*="color: white"],
.btn[style*="color: #fff"],
.btn[style*="color: #ffffff"] {
  color: var(--color-text-primary) !important;
}

/* Override white text in cards and sections */
.card[style*="color: white"],
.card[style*="color: #fff"],
.card[style*="color: #ffffff"],
.section-card[style*="color: white"],
.section-card[style*="color: #fff"],
.section-card[style*="color: #ffffff"] {
  color: var(--color-text-primary) !important;
}

/* Override white text in alerts and notifications */
.alert[style*="color: white"],
.alert[style*="color: #fff"],
.alert[style*="color: #ffffff"],
.notification[style*="color: white"],
.notification[style*="color: #fff"],
.notification[style*="color: #ffffff"] {
  color: var(--color-text-primary) !important;
}

/* Override white text in modals */
.modal[style*="color: white"],
.modal[style*="color: #fff"],
.modal[style*="color: #ffffff"],
.modal-content[style*="color: white"],
.modal-content[style*="color: #fff"],
.modal-content[style*="color: #ffffff"] {
  color: var(--color-text-primary) !important;
}

/* Override white text in any element with light background */
[style*="background-color: white"][style*="color: white"],
[style*="background-color: #fff"][style*="color: white"],
[style*="background-color: #ffffff"][style*="color: white"],
[style*="background: white"][style*="color: white"],
[style*="background: #fff"][style*="color: white"],
[style*="background: #ffffff"][style*="color: white"] {
  color: var(--color-text-primary) !important;
}

/* Enhanced contrast for graph backgrounds */
.chart-container[style*="color: white"],
.chart-container[style*="color: #fff"],
.chart-container[style*="color: #ffffff"] {
  color: var(--color-text-primary) !important;
}

/* Override any remaining white text issues */
*[style*="color: white"]:not([style*="background-color: #1a365d"]):not(
    [style*="background-color: #2d3748"]
  ):not([style*="background-color: #3182ce"]):not(
    [style*="background-color: #38a169"]
  ):not([style*="background-color: #e53e3e"]):not(
    [style*="background-color: #d69e2e"]
  ) {
  color: var(--color-text-primary) !important;
}

/* Ensure proper contrast in dark mode */
[data-theme="dark"] [style*="color: white"] {
  color: var(--color-text-primary) !important;
}

@media (prefers-color-scheme: dark) {
  [style*="color: white"] {
    color: var(--color-text-primary) !important;
  }
}

/* High contrast mode overrides */
@media (prefers-contrast: high) {
  [style*="color: white"] {
    color: #000000 !important;
  }

  [data-theme="dark"] [style*="color: white"] {
    color: #ffffff !important;
  }
}

/* Enhanced Alert and Notification Contrast Fixes */

/* Ensure all alert and notification messages have proper contrast */
.alert,
.notification,
.message,
.toast,
.popup {
  background: var(--color-surface-raised) !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border-medium) !important;
}

/* Success alerts - dark text on light green background */
.alert-success,
.notification-success,
.message-success,
.toast-success {
  background: #d1fae5 !important;
  color: #065f46 !important;
  border-color: #10b981 !important;
}

/* Error alerts - dark text on light red background */
.alert-error,
.notification-error,
.message-error,
.toast-error,
.alert-danger {
  background: #fee2e2 !important;
  color: #991b1b !important;
  border-color: #ef4444 !important;
}

/* Warning alerts - dark text on light yellow background */
.alert-warning,
.notification-warning,
.message-warning,
.toast-warning {
  background: #fef3c7 !important;
  color: #92400e !important;
  border-color: #f59e0b !important;
}

/* Info alerts - dark text on light blue background */
.alert-info,
.notification-info,
.message-info,
.toast-info {
  background: #dbeafe !important;
  color: #1e40af !important;
  border-color: #3b82f6 !important;
}

/* Override any inline white text on light backgrounds */
[style*="color: white"][style*="background-color: white"],
[style*="color: white"][style*="background-color: #fff"],
[style*="color: white"][style*="background-color: #ffffff"],
[style*="color: #fff"][style*="background-color: white"],
[style*="color: #fff"][style*="background-color: #fff"],
[style*="color: #fff"][style*="background-color: #ffffff"],
[style*="color: #ffffff"][style*="background-color: white"],
[style*="color: #ffffff"][style*="background-color: #fff"],
[style*="color: #ffffff"][style*="background-color: #ffffff"] {
  color: var(--color-text-primary) !important;
}

/* Ensure JavaScript-generated alerts have proper contrast */
.alert-box,
.alert-message,
.alert-popup,
.notification-box,
.notification-message,
.notification-popup {
  background: var(--color-surface-raised) !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border-medium) !important;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
}

/* Tournament-specific alert fixes */
.tournament-alert,
.tournament-notification,
.tournament-message {
  background: var(--color-surface-raised) !important;
  color: var(--color-text-primary) !important;
  border: 1px solid var(--color-border-medium) !important;
}

/* High contrast mode for alerts */
@media (prefers-contrast: high) {
  .alert,
  .notification,
  .message,
  .toast,
  .popup,
  .alert-box,
  .alert-message,
  .alert-popup,
  .notification-box,
  .notification-message,
  .notification-popup {
    background: #ffffff !important;
    color: #000000 !important;
    border: 2px solid #000000 !important;
  }

  [data-theme="dark"] .alert,
  [data-theme="dark"] .notification,
  [data-theme="dark"] .message,
  [data-theme="dark"] .toast,
  [data-theme="dark"] .popup,
  [data-theme="dark"] .alert-box,
  [data-theme="dark"] .alert-message,
  [data-theme="dark"] .alert-popup,
  [data-theme="dark"] .notification-box,
  [data-theme="dark"] .notification-message,
  [data-theme="dark"] .notification-popup {
    background: #000000 !important;
    color: #ffffff !important;
    border: 2px solid #ffffff !important;
  }
}

/* ===== LOADING STATES & SKELETON SCREENS ===== */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-surface-muted) 25%,
    var(--color-surface-subtle) 50%,
    var(--color-surface-muted) 75%
  );
  background-size: 200% 100%;
  animation: loading-skeleton 1.5s infinite;
}

@keyframes loading-skeleton {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 1em;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-2);
}

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-card {
  padding: var(--space-8);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
}

.skeleton-card .skeleton-text:nth-child(1) {
  width: 40%;
}
.skeleton-card .skeleton-text:nth-child(2) {
  width: 80%;
}
.skeleton-card .skeleton-text:nth-child(3) {
  width: 60%;
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */
/* Optimize for paint and layout */
.stat-card-enhanced,
.preview-card,
.nav-link {
  will-change: transform;
}

/* Reduce layout shifts */
.chart-container {
  aspect-ratio: 16/9;
  min-height: 300px;
}

/* Optimize animations */
@media (prefers-reduced-motion: reduce) {
  .stat-card-enhanced:hover {
    transform: none;
  }

  .preview-card:hover {
    transform: none;
  }
}

/* ===== ENHANCED ACCESSIBILITY ===== */
/* Focus indicators */
*:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* High contrast mode */
.high-contrast {
  --color-text-primary: #000000 !important;
  --color-text-secondary: #000000 !important;
  --color-surface: #ffffff !important;
  --color-border: #000000 !important;
  --color-border-light: #000000 !important;
  --brand-primary: #0000ff !important;
  --brand-success: #008000 !important;
  --brand-warning: #ff8c00 !important;
  --brand-danger: #ff0000 !important;
}

.high-contrast * {
  color: var(--color-text-primary) !important;
  background-color: var(--color-surface) !important;
  border-color: var(--color-border) !important;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Skip to main content */
.skip-link {
  position: absolute;
  top: -40px;
  left: 6px;
  background: var(--brand-primary);
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  border-radius: var(--radius-sm);
  z-index: 10001;
  transition: top 0.3s ease;
}

.skip-link:focus {
  top: 6px;
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .toast {
    transition: none !important;
  }

  .skeleton-title::after,
  .skeleton-text::after,
  .skeleton-image::after {
    animation: none !important;
  }
}

/* ===== MOBILE OPTIMIZATIONS ===== */
@media (max-width: 768px) {
  .notification-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }

  .toast {
    padding: 12px;
  }

  .toast-content {
    gap: 8px;
  }

  .toast-icon {
    font-size: 18px;
  }

  .toast-message {
    font-size: var(--font-size-xs);
  }

  .skeleton-container {
    padding: 16px;
    margin: 10px;
    max-width: calc(100vw - 20px);
  }

  .skeleton-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .skeleton-card {
    padding: 16px;
  }

  .skeleton-image {
    height: 150px;
  }
}

/* ===== DARK MODE SUPPORT ===== */
@media (prefers-color-scheme: dark) {
  .toast {
    background: var(--color-surface-dark, #1a202c);
    border-color: var(--color-border-dark, #2d3748);
  }

  .toast-error {
    background: linear-gradient(135deg, #2d1b1b, #2d1b1b);
  }

  .toast-success {
    background: linear-gradient(135deg, #1b2d1b, #1b2d1b);
  }

  .toast-warning {
    background: linear-gradient(135deg, #2d2b1b, #2d2b1b);
  }

  .toast-info {
    background: linear-gradient(135deg, #1b1b2d, #1b1b2d);
  }

  .skeleton-container {
    background: var(--color-surface-dark, #1a202c);
  }

  .skeleton-card {
    background: var(--color-surface-dark, #1a202c);
    border-color: var(--color-border-dark, #2d3748);
  }

  .skeleton-image,
  .skeleton-title,
  .skeleton-text {
    background: var(--color-border-dark, #2d3748);
  }
}

[data-theme="dark"] {
  .toast {
    background: var(--color-surface-dark, #1a202c);
    border-color: var(--color-border-dark, #2d3748);
  }

  .toast-error {
    background: linear-gradient(135deg, #2d1b1b, #2d1b1b);
  }

  .toast-success {
    background: linear-gradient(135deg, #1b2d1b, #1b2d1b);
  }

  .toast-warning {
    background: linear-gradient(135deg, #2d2b1b, #2d2b1b);
  }

  .toast-info {
    background: linear-gradient(135deg, #1b1b2d, #1b1b2d);
  }

  .skeleton-container {
    background: var(--color-surface-dark, #1a202c);
  }

  .skeleton-card {
    background: var(--color-surface-dark, #1a202c);
    border-color: var(--color-border-dark, #2d3748);
  }

  .skeleton-image,
  .skeleton-title,
  .skeleton-text {
    background: var(--color-border-dark, #2d3748);
  }
}

/* ===== BROWSER COMPATIBILITY ===== */
@supports not (display: grid) {
  .skeleton-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
  }

  .skeleton-grid > * {
    flex: 1 1 300px;
  }
}

/* ===== PRINT STYLES ===== */
@media print {
  .notification-container,
  .skeleton-container,
  .toast,
  .skeleton-card {
    display: none !important;
  }
}

/* ===== ENHANCED NOTIFICATION SYSTEM ===== */
.notification-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 400px;
  pointer-events: none;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
  max-width: 100%;
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.toast-icon {
  font-size: 20px;
  flex-shrink: 0;
  margin-top: 2px;
}

.toast-message {
  flex: 1;
  color: var(--color-text-primary);
  font-size: var(--font-size-sm);
  line-height: 1.4;
  word-wrap: break-word;
}

.toast-close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.toast-close:hover {
  background: var(--color-border-light);
  color: var(--color-text-primary);
}

/* Toast variants */
.toast-error {
  border-left: 4px solid var(--brand-danger);
  background: linear-gradient(135deg, #fef2f2, #fef2f2);
}

.toast-success {
  border-left: 4px solid var(--brand-success);
  background: linear-gradient(135deg, #f0fdf4, #f0fdf4);
}

.toast-warning {
  border-left: 4px solid var(--brand-warning);
  background: linear-gradient(135deg, #fffbeb, #fffbeb);
}

.toast-info {
  border-left: 4px solid var(--brand-primary);
  background: linear-gradient(135deg, #eff6ff, #eff6ff);
}

/* ===== ENHANCED SKELETON LOADING ===== */
.skeleton-container {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 9999;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-xl);
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
}

.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 20px;
}

.skeleton-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.skeleton-image {
  width: 100%;
  height: 200px;
  background: var(--color-border-light);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}

.skeleton-image::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.4),
    transparent
  );
  animation: shimmer 1.5s infinite;
}

.skeleton-content {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.skeleton-title {
  height: 24px;
  background: var(--color-border-light);
  border-radius: var(--radius-sm);
  width: 60%;
  position: relative;
  overflow: hidden;
}

.skeleton-text {
  height: 16px;
  background: var(--color-border-light);
  border-radius: var(--radius-sm);
  width: 100%;
  position: relative;
  overflow: hidden;
}

.skeleton-title::after,
.skeleton-text::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.4),
    transparent
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}
