/* ===== ProfScout Design System ===== */
/* Dark-mode-first, glassmorphism, premium feel */

:root {
  /* ===== Colors — light-first, minimal, single accent ===== */
  --bg-primary: #ffffff;
  --bg-secondary: #f6f7f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f9fafb;
  --bg-glass: rgba(15, 23, 42, 0.04);
  --border-subtle: #e5e7eb;
  --border-accent: #a5b4fc;

  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --text-accent: #4f46e5;

  /* One primary accent + one semantic success/danger pair. */
  --accent-1: #4f46e5; /* Indigo — the single brand accent */
  --accent-1-strong: #4338ca;
  --accent-success: #059669;
  --accent-danger: #dc2626;
  --accent-tint-1: rgba(79, 70, 229, 0.08);
  --accent-tint-2: rgba(79, 70, 229, 0.14);

  /* Back-compat aliases (older rules + inline styles reference these names). */
  --accent-2: var(--accent-1);
  --accent-3: var(--accent-1);
  --accent-4: var(--accent-success);
  --accent-5: var(--accent-1);
  --primary: var(--accent-1);
  --border: var(--border-subtle);
  --text: var(--text-primary);
  --bg-surface: var(--bg-card);
  --bg-alt: var(--bg-secondary);

  /* Gradient tokens repurposed to flat colors — no more gradient chrome. */
  --gradient-primary: var(--accent-1);
  --gradient-card: transparent;
  --gradient-accent: var(--accent-1);
  --gradient-warm: var(--accent-danger);

  /* Typography */
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Type scale */
  --text-xs: 0.75rem;    /* 12px */
  --text-sm: 0.875rem;   /* 14px */
  --text-base: 1rem;     /* 16px */
  --text-lg: 1.125rem;   /* 18px */
  --text-xl: 1.375rem;   /* 22px */
  --text-2xl: 1.75rem;   /* 28px */

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

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 64px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Shadows — subtle, flat */
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.05);
  --shadow-md: 0 2px 8px rgba(15,23,42,0.08);
  --shadow-lg: 0 8px 24px rgba(15,23,42,0.12);
  --shadow-glow: none; /* glow retired — neutralized everywhere it is referenced */

  /* Transitions */
  --transition-fast: 120ms ease;
  --transition-normal: 180ms ease;
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Dark mode — clean inversion, opt-in via data-theme ===== */
:root[data-theme="dark"] {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: #161b22;
  --bg-card-hover: #1c232c;
  --bg-glass: rgba(255, 255, 255, 0.05);
  --border-subtle: #262c36;
  --border-accent: #4f46e5;

  --text-primary: #e6edf3;
  --text-secondary: #9da7b3;
  --text-muted: #6e7781;
  --text-accent: #a5b4fc;

  --accent-1: #6366f1;
  --accent-1-strong: #818cf8;
  --accent-success: #10b981;
  --accent-danger: #f87171;
  --accent-tint-1: rgba(99, 102, 241, 0.12);
  --accent-tint-2: rgba(99, 102, 241, 0.2);

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

#app { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--text-accent); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-1-strong); }

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-subtle);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 var(--space-lg);
  height: 64px;
  display: flex;
  align-items: center;
  gap: var(--space-xl);
}

.logo {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary) !important;
  letter-spacing: -0.5px;
}

.logo-icon {
  width: 1.6rem;
  height: 1.6rem;
  color: var(--accent-1);
  flex: 0 0 auto;
  display: block;
}

.logo .accent {
  color: var(--accent-1);
}

.nav { display: flex; gap: var(--space-xs); flex: 1; }

.nav-link {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary) !important;
  transition: all var(--transition-normal);
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link:hover {
  color: var(--text-primary) !important;
  background: var(--bg-glass);
}

.nav-link.active {
  color: var(--text-primary) !important;
  background: rgba(99, 102, 241, 0.12);
  box-shadow: inset 0 -2px 0 var(--accent-1);
}

.nav-icon { width: 17px; height: 17px; flex: 0 0 auto; display: block; }
.theme-toggle .nav-icon { width: 18px; height: 18px; }

.header-stats { display: flex; align-items: center; gap: var(--space-sm); white-space: nowrap; }

.stat-badge {
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 4px 12px;
  border-radius: var(--radius-full);
  background: rgba(99,102,241,0.1);
  color: var(--text-accent);
  border: 1px solid var(--border-accent);
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-lg);
}

/* ===== Loading Screen ===== */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  gap: var(--space-lg);
}

.loading-spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-1);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

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

.loading-bar {
  width: 200px; height: 3px;
  background: var(--border-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  background: var(--gradient-accent);
  border-radius: var(--radius-full);
  width: 0%;
  transition: width 0.3s ease;
}

/* ===== Page Layout ===== */
.page-header {
  margin-bottom: var(--space-xl);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: -0.02em;
  color: var(--text-primary);
  margin-bottom: var(--space-xs);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

/* ===== Search Bar ===== */
.search-container {
  position: relative;
  margin-bottom: var(--space-lg);
}

.search-input {
  width: 100%;
  padding: 14px 20px 14px 48px;
  font-size: 1rem;
  font-family: var(--font-body);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  color: var(--text-primary);
  transition: all var(--transition-normal);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent-1);
  box-shadow: var(--shadow-glow);
  background: var(--bg-card-hover);
}

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

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.2rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-count {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* ===== Two-Column Layout ===== */
.discover-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-lg);
  align-items: start;
}

@media (max-width: 900px) {
  .discover-layout { grid-template-columns: 1fr; }
}

/* ===== Filter Panel ===== */
.filter-panel {
  position: sticky;
  top: 80px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}

.filter-panel::-webkit-scrollbar { width: 4px; }
.filter-panel::-webkit-scrollbar-track { background: transparent; }
.filter-panel::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 2px; }

.filter-section {
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
}

.filter-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.filter-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.filter-title::after {
  content: '\25BC';
  font-size: 0.6rem;
  transition: transform var(--transition-fast);
}

.filter-title.collapsed::after { transform: rotate(-90deg); }

.filter-options { display: flex; flex-direction: column; gap: 2px; }
.filter-options.collapsed { display: none; }

.filter-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.filter-option:hover { background: var(--bg-glass); color: var(--text-primary); }
.filter-option input[type="checkbox"] { accent-color: var(--accent-1); cursor: pointer; }
.filter-option .count { margin-left: auto; font-size: 0.7rem; font-family: var(--font-mono); color: var(--text-muted); }

/* Range slider */
.range-container { padding: 4px 8px; }
.range-slider {
  width: 100%;
  accent-color: var(--accent-1);
  cursor: pointer;
}
.range-value {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-accent);
  text-align: center;
  margin-top: 4px;
}

/* ===== Professor Cards ===== */
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

.results-count {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.results-count strong { color: var(--text-primary); font-family: var(--font-mono); }

.sort-select {
  font-size: 0.85rem;
  font-family: var(--font-body);
  padding: 6px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
}

.sort-select:focus { border-color: var(--accent-1); }

.professor-list { display: flex; flex-direction: column; gap: var(--space-sm); }

.prof-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  transition: all var(--transition-normal);
  cursor: default;
}

.prof-card:hover {
  border-color: var(--border-accent);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.prof-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-sm);
}

.prof-name {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
}
a.prof-name-link { display: inline-flex; align-items: baseline; gap: 4px; }
a.prof-name-link:hover { color: var(--accent-1); }
.prof-name-ext { font-size: 0.7em; color: var(--text-muted); }
a.prof-name-link:hover .prof-name-ext { color: var(--accent-1); }

.prof-affiliation {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.prof-country {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(99,102,241,0.1);
  color: var(--text-accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.prof-areas {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: var(--space-sm);
}

.area-tag {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--accent-tint-1);
  color: var(--text-accent);
  border: 1px solid var(--accent-tint-2);
  white-space: nowrap;
}

.prof-stats {
  display: flex;
  gap: var(--space-lg);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.prof-stat strong {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 600;
}

.prof-links {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

.prof-link {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary) !important;
  transition: all var(--transition-fast);
}

.prof-link:hover {
  border-color: var(--accent-1);
  color: var(--text-accent) !important;
  background: var(--accent-tint-1);
}

.prof-link-stipend {
  border-color: rgba(5,150,105,0.35) !important;
  color: var(--accent-success) !important;
}
.prof-link-stipend:hover {
  border-color: var(--accent-success) !important;
  background: rgba(5,150,105,0.1);
}

/* ===== Load More ===== */
.load-more-btn {
  display: block;
  width: 100%;
  padding: var(--space-md);
  margin-top: var(--space-md);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-accent);
  background: var(--bg-card);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.load-more-btn:hover {
  background: rgba(99,102,241,0.1);
  box-shadow: var(--shadow-glow);
}

/* ===== Stipend Page ===== */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
  transition: all var(--transition-normal);
}

.stat-card:hover { border-color: var(--border-accent); box-shadow: var(--shadow-glow); }

.stat-card-value {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.stat-card-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Stipend Chart ===== */
.chart-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-xl);
  overflow-x: auto;
}

.chart-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: var(--space-lg);
  color: var(--text-primary);
}

.bar-chart { display: flex; flex-direction: column; gap: 6px; }

.bar-row {
  display: grid;
  grid-template-columns: 220px 1fr 80px;
  align-items: center;
  gap: var(--space-md);
  font-size: 0.8rem;
}

.bar-label {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}

.bar-track {
  height: 24px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius-sm);
  overflow: hidden;
  position: relative;
}

.bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  transition: width var(--transition-slow);
  min-width: 2px;
}

.bar-fill.positive { background: var(--gradient-accent); }
.bar-fill.negative { background: var(--gradient-warm); }

.bar-value {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.75rem;
  text-align: right;
}

.bar-value.positive { color: var(--accent-4); }
.bar-value.negative { color: var(--accent-danger); }

/* ===== Stipend Table ===== */
.stipend-table-container {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.stipend-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.stipend-table th {
  padding: var(--space-md);
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: color var(--transition-fast);
  user-select: none;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.stipend-table th:hover { color: var(--text-accent); }
.stipend-table th.sorted { color: var(--accent-1); }
.stipend-table th .sort-arrow { font-size: var(--text-xs); margin-left: 4px; }

.stipend-table td {
  padding: 10px var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.stipend-table tr:hover td { background: var(--accent-tint-1); color: var(--text-primary); }

.stipend-table .money { font-family: var(--font-mono); font-weight: var(--weight-medium); }
.stipend-table .positive { color: var(--accent-success); }
.stipend-table .negative { color: var(--accent-danger); }

.type-badge {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
}

.type-badge.private { background: var(--accent-tint-1); color: var(--text-accent); }
.type-badge.public { background: rgba(5,150,105,0.12); color: var(--accent-success); }

.summer-badge { font-size: 0.85rem; }

/* ===== Match Page ===== */
.interest-selector {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-xl);
}

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

.interest-category-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
}

.interest-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.interest-tag {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--bg-glass);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-normal);
  user-select: none;
}

.interest-tag:hover {
  border-color: var(--accent-2);
  color: var(--text-primary);
}

.interest-tag.selected {
  background: rgba(99,102,241,0.15);
  border-color: var(--accent-1);
  color: var(--text-primary);
  box-shadow: 0 0 12px rgba(99,102,241,0.2);
}

.match-controls {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.match-btn {
  padding: 10px 24px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 700;
  color: white;
  background: var(--gradient-primary);
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-normal);
}

.match-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-glow); }
.match-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.match-score {
  font-size: var(--text-lg);
  font-weight: var(--weight-bold);
  font-family: var(--font-mono);
  color: var(--accent-1);
  white-space: nowrap;
}

.match-areas-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.match-stipend {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.match-stipend strong { font-family: var(--font-mono); }

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: var(--space-xl) var(--space-lg);
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  margin-top: var(--space-2xl);
}

.app-footer a { color: var(--text-secondary); }
.app-footer a:hover { color: var(--text-accent); }

/* ===== Empty / No Results ===== */
.empty-state {
  text-align: center;
  padding: var(--space-3xl) var(--space-lg);
  color: var(--text-muted);
}

.empty-state-icon { font-size: 3rem; margin-bottom: var(--space-md); opacity: 0.4; }
.empty-state-text { font-size: var(--text-lg); font-weight: var(--weight-medium); }
.empty-state-hint { font-size: var(--text-sm); margin-top: var(--space-sm); }

/* Card grid (Mail page) */
.tracker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}
.tracker-grid .empty-state { grid-column: 1 / -1; padding: var(--space-xl); }

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in { animation: fadeIn 0.3s ease forwards; }

/* Staggered card animation */
.prof-card { opacity: 0; animation: fadeIn 0.3s ease forwards; }
.prof-card:nth-child(1) { animation-delay: 0.02s; }
.prof-card:nth-child(2) { animation-delay: 0.04s; }
.prof-card:nth-child(3) { animation-delay: 0.06s; }
.prof-card:nth-child(4) { animation-delay: 0.08s; }
.prof-card:nth-child(5) { animation-delay: 0.10s; }
.prof-card:nth-child(6) { animation-delay: 0.12s; }
.prof-card:nth-child(7) { animation-delay: 0.14s; }
.prof-card:nth-child(8) { animation-delay: 0.16s; }
.prof-card:nth-child(9) { animation-delay: 0.18s; }
.prof-card:nth-child(10) { animation-delay: 0.20s; }

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

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

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  transition: color var(--transition-fast);
}

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

.modal-body {
  padding: var(--space-lg);
  overflow-y: auto;
}

.modal-footer {
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-sm);
}

.btn {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
}
.btn-primary:hover { box-shadow: var(--shadow-glow); }

.btn-secondary {
  background: var(--bg-card);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--bg-card-hover); }

/* ===== Templates Page ===== */
.templates-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-lg);
  align-items: start;
  height: calc(100vh - 200px);
}

.templates-sidebar {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.templates-sidebar-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.templates-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.template-item {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition-fast);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.template-item:hover { background: var(--bg-glass); }
.template-item.active {
  background: rgba(99, 102, 241, 0.1);
  border-left: 3px solid var(--accent-1);
}

.template-item-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}
.template-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 0.65rem;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent-1);
  background: var(--accent-tint-1);
  border-radius: var(--radius-full);
  vertical-align: middle;
}

.template-delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}
.template-delete-btn:hover { color: var(--accent-danger); }

.template-editor {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.form-input, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 0.95rem;
}

.form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent-1);
}

.form-textarea {
  resize: none;
  flex: 1;
  min-height: 300px;
}

.merge-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
  margin-top: 4px;
}

.merge-tag-help { font-size: var(--text-xs); color: var(--text-muted); margin-top: var(--space-sm); }
.merge-tag-group { margin-top: var(--space-sm); }
.merge-tag-group-label {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

/* Settings profile grid */
.settings-section-title {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: 4px;
}
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}
@media (max-width: 560px) { .settings-grid { grid-template-columns: 1fr; } }

.merge-tag {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  padding: 4px 8px;
  background: var(--accent-tint-1);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-sm);
  color: var(--text-accent);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.merge-tag:hover {
  background: var(--accent-1);
  color: white;
}

/* ===== Tracker Page ===== */
.kanban-board {
  display: flex;
  gap: var(--space-md);
  overflow-x: auto;
  padding-bottom: var(--space-md);
  height: calc(100vh - 200px);
}

.kanban-column {
  flex: 0 0 300px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

.kanban-column-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kanban-count {
  font-size: 0.8rem;
  background: var(--bg-secondary);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  color: var(--text-muted);
}

.kanban-cards {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.kanban-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  cursor: grab;
}

.kanban-card:active { cursor: grabbing; }

.kanban-card-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.kanban-card-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
}

.kanban-card-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--space-sm);
  margin-top: var(--space-sm);
}

.status-select {
  font-size: var(--text-xs);
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px 4px;
}

.discover-head { display: flex; justify-content: space-between; align-items: flex-end; gap: var(--space-md); flex-wrap: wrap; }
.mode-toggle { display: flex; gap: 2px; background: var(--bg-secondary); padding: 3px; border-radius: var(--radius-md); border: 1px solid var(--border-subtle); }
.mode-btn {
  padding: 6px 14px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.mode-btn.active { background: var(--accent-1); color: #fff; }
.mode-btn:not(.active):hover { color: var(--text-primary); }

.tracker-header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-md); flex-wrap: wrap; }
.kanban-card-main { display: flex; align-items: flex-start; gap: var(--space-sm); }
.kanban-card-main input[type="checkbox"] { margin-top: 3px; }
.kanban-empty { color: var(--text-muted); font-size: var(--text-xs); text-align: center; padding: var(--space-md); border: 1px dashed var(--border-subtle); border-radius: var(--radius-md); }
.kanban-cards.drag-over { background: var(--accent-tint-1); }

/* Card Actions inside Professor Cards */
.prof-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-sm);
}

/* Section headings (Mail page etc.) */
.section-heading {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: var(--space-sm);
  margin: var(--space-lg) 0 var(--space-md);
}

/* Mail cards */
.email-card-addr { color: var(--text-muted); font-size: var(--text-sm); margin-bottom: var(--space-sm); }
.email-card-subject { color: var(--text-primary); font-size: var(--text-sm); margin-bottom: var(--space-sm); }
.email-card-meta { font-size: var(--text-sm); color: var(--text-muted); margin-bottom: var(--space-md); }
.email-card-meta .positive { color: var(--accent-success); font-weight: var(--weight-semibold); }

.btn-sm { font-size: var(--text-xs); padding: 4px 10px; text-decoration: none; }

.action-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  background: var(--bg-glass);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.action-btn:hover {
  background: rgba(99,102,241,0.1);
  border-color: var(--border-accent);
  color: var(--text-accent);
}

.action-btn.tracked {
  background: rgba(16,185,129,0.1);
  border-color: rgba(16,185,129,0.3);
  color: #6ee7b7;
}

.ai-btn {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { padding: 0 var(--space-md); gap: var(--space-sm); }
  .nav-link .nav-icon { display: none; }
  .header-stats { display: none; }
  .main-content { padding: var(--space-md); }
  .page-title { font-size: 1.4rem; }
  .bar-row { grid-template-columns: 140px 1fr 60px; font-size: 0.7rem; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .nav-link { font-size: 0.8rem; padding: var(--space-xs) var(--space-sm); }
  .logo-text { display: none; }
}

/* ===== Accessibility ===== */
:focus-visible {
  outline: 2px solid var(--accent-1);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.search-input:focus-visible,
.form-input:focus-visible,
.form-textarea:focus-visible,
.sort-select:focus-visible {
  outline: 2px solid var(--accent-1);
  outline-offset: 0;
  border-color: var(--accent-1);
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .prof-card { opacity: 1 !important; }
}

/* ===== Form hint (compose / settings helper text) ===== */
.form-hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* ===== Bulk compose rows ===== */
.bulk-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-height: 40vh;
  overflow-y: auto;
  margin: var(--space-sm) 0;
}
.bulk-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  align-items: center;
  padding: var(--space-sm);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}
.bulk-row-name { font-weight: var(--weight-semibold); font-size: var(--text-sm); }
.bulk-row-univ { font-size: var(--text-xs); color: var(--text-muted); }

/* ===== Toasts (non-blocking feedback) ===== */
.toast-stack {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: 4000; /* above modal overlay (1000) so errors are never hidden behind it */
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  max-width: min(380px, calc(100vw - 2 * var(--space-lg)));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--accent-1);
  border-radius: var(--radius-md);
  padding: 10px var(--space-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  line-height: 1.45;
  transition: opacity var(--transition-normal) ease;
  animation: toastIn var(--transition-normal) ease;
  pointer-events: auto; /* re-enable so the close button is clickable */
}
.toast-msg { flex: 1; }
.toast-close {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.toast-close:hover { color: var(--text-primary); }
.toast.success { border-left-color: var(--accent-success); }
.toast.error { border-left-color: var(--accent-danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== Onboarding welcome ===== */
.welcome-banner {
  background: var(--accent-tint-1);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}
.welcome-banner h2 { font-size: var(--text-xl); margin-bottom: var(--space-sm); }
.welcome-banner p { color: var(--text-secondary); font-size: var(--text-sm); margin-bottom: var(--space-md); }
.welcome-banner .welcome-actions { display: flex; gap: var(--space-sm); flex-wrap: wrap; }

/* ===== Header sync indicator ===== */
.sync-indicator {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
}
.sync-indicator.ok { color: var(--accent-success); }
.sync-indicator.err { color: var(--accent-danger); }

/* ===== Theme toggle & auth (moved out of inline styles) ===== */
.theme-toggle {
  background: transparent;
  border: none;
  box-shadow: none;
  font-size: 1.2rem;
  padding: 0 var(--space-sm);
  cursor: pointer;
  color: var(--text-secondary);
}
.header-auth { margin-left: auto; margin-right: var(--space-md); }
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 7px 14px;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  white-space: nowrap;
}
.btn-google .g-logo { flex: 0 0 auto; display: block; }

/* Signed-in pill: avatar + name + logout glyph */
.btn-google.signed-in {
  padding: 4px 10px 4px 4px;
  border-radius: var(--radius-full);
  gap: 6px;
}
.auth-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}
.auth-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-1);
  color: #fff;
}
.auth-avatar-fallback svg { width: 16px; height: 16px; }
.auth-name {
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.auth-signout {
  display: inline-flex;
  align-items: center;
  color: var(--text-muted);
  padding-left: 2px;
}
.btn-google.signed-in:hover .auth-signout { color: var(--accent-danger); }
