/* =====================================================================
   Global Opportunities — stylesheet
   Product-first layout: search lives in the header, filters are a
   faceted sidebar with live counts, results are a dense scannable
   list. Color only where it carries meaning (opportunity type,
   deadline urgency). No marketing hero — the product is the page.
   ===================================================================== */

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

:root {
  --accent:        #4f46e5;
  --accent-soft:   #eef2ff;
  --scholarship:   #2563eb;
  --scholarship-bg:#eff6ff;
  --fellowship:    #7c3aed;
  --fellowship-bg: #f5f3ff;
  /* Darkened from the original #059669/#d97706 — those failed WCAG AA
     4.5:1 contrast both as white-on-solid button text and as text on
     their own *-bg tint (an axe-core audit measured ~3.2-3.8:1). */
  --grant:         #047857;
  --grant-bg:      #ecfdf5;
  --job:           #b45309;
  --job-bg:        #fffbeb;
  --bg:            #fafaf9;
  --surface:       #ffffff;
  --border:        #e7e5e4;
  --border-soft:   #f0efee;
  --text:          #1c1917;
  --muted:         #78716c;
  --faint:         #a8a29e;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow-hover:  0 6px 20px -6px rgba(28,25,23,.1), 0 1px 4px rgba(28,25,23,.04);
  --ease:          0.15s ease;
  --font-display:  'Sora', 'Inter', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

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

/* ------- Header (brand · search · actions) ------- */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 200;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  text-decoration: none;
}

.brand-mark {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  color: var(--accent);
  display: inline-flex;
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
  white-space: nowrap;
}

.header-search {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px 3px 3px 12px;
  transition: border-color var(--ease), box-shadow var(--ease), background var(--ease);
}

.header-search:focus-within {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,70,229,.1);
}

.search-icon { width: 16px; height: 16px; color: var(--faint); flex-shrink: 0; }

.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: .875rem;
  color: var(--text);
  background: transparent;
  min-width: 0;
  padding: 6px 0;
}

.search-input::placeholder { color: var(--faint); }
.search-input::-webkit-search-cancel-button { -webkit-appearance: none; }

.search-submit {
  background: var(--text);
  color: var(--surface);
  border: none;
  padding: 7px 16px;
  border-radius: 7px;
  font-family: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--ease);
  flex-shrink: 0;
}

.search-submit:hover { opacity: .85; }

.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ------- Buttons ------- */
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--ease);
  white-space: nowrap;
}

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

.btn-solid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--ease);
  white-space: nowrap;
}

.btn-solid:hover { opacity: .88; }
.btn-solid:disabled { opacity: .4; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ------- Page head ------- */
.page-head { padding: 36px 0 8px; }

.page-title {
  font-family: var(--font-display);
  font-size: clamp(1.4rem, 3.4vw, 2.1rem);
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 8px;
}

.page-sub {
  font-size: .92rem;
  color: var(--muted);
  max-width: 640px;
  margin-bottom: 14px;
}

.page-meta {
  font-size: .76rem;
  font-weight: 500;
  color: var(--muted);
  min-height: 18px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  padding: 5px 12px 5px 10px;
  border-radius: 99px;
}

/* Live pulse dot in front of the freshness line */
.page-meta::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--grant);
  box-shadow: 0 0 0 0 rgba(5,150,105,.5);
  animation: pulse-dot 2.4s ease-out infinite;
}

@keyframes pulse-dot {
  0%   { box-shadow: 0 0 0 0 rgba(5,150,105,.45); }
  70%  { box-shadow: 0 0 0 6px rgba(5,150,105,0); }
  100% { box-shadow: 0 0 0 0 rgba(5,150,105,0); }
}

/* ------- Layout: sidebar + results ------- */
.main { padding: 20px 0 72px; }

.layout {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 36px;
  align-items: start;
}

/* ------- Sidebar facets ------- */
.sidebar {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.facet-title {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.facet-list { display: flex; flex-direction: column; gap: 2px; }

.facet {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  background: none;
  border: none;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .85rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--muted);
  text-align: left;
  transition: all var(--ease);
}

.facet:hover { background: rgba(28,25,23,.05); color: var(--text); }
.facet.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.facet-count {
  font-size: .72rem;
  font-weight: 600;
  color: var(--muted);
  background: rgba(28,25,23,.05);
  padding: 1px 8px;
  border-radius: 99px;
  font-variant-numeric: tabular-nums;
}

.facet.active .facet-count { background: rgba(79,70,229,.12); color: var(--accent); }

.fselect {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .84rem;
  color: var(--text);
  cursor: pointer;
  outline: none;
  transition: border-color var(--ease);
}

.fselect:focus { border-color: var(--accent); }

.fselect-sm { width: auto; padding: 5px 8px; font-size: .78rem; color: var(--muted); }

/* ------- Results ------- */
.results-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-height: 30px;
}

.results-meta { font-size: .8rem; color: var(--muted); }

.sort-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .78rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ------- Loading ------- */
.loading { text-align: center; padding: 70px 0; color: var(--muted); }

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 14px;
}

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

/* ------- Empty state ------- */
.empty { text-align: center; padding: 80px 0; }
.empty h3 { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; letter-spacing: -.01em; margin-bottom: 8px; }
.empty p { color: var(--muted); margin-bottom: 24px; max-width: 440px; margin-inline: auto; font-size: .9rem; }

/* ------- Listing rows ------- */
.rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 36px;
}

.row {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  transition: border-color var(--ease), box-shadow var(--ease);
}

.row:hover { border-color: var(--border); box-shadow: var(--shadow-hover); }

.row-main { flex: 1; min-width: 0; }

.row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: .66rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge-scholarship { background: var(--scholarship-bg); color: var(--scholarship); }
.badge-fellowship  { background: var(--fellowship-bg);  color: var(--fellowship);  }
.badge-grant       { background: var(--grant-bg);       color: var(--grant);       }
.badge-job         { background: var(--job-bg);         color: var(--job);         }
.badge-other       { background: var(--accent-soft);    color: var(--accent);      }

.row-title {
  font-family: var(--font-display);
  font-size: .96rem;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -.01em;
  margin-bottom: 4px;
}

.row-meta {
  font-size: .76rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.row-desc {
  font-size: .84rem;
  color: var(--muted);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  flex-shrink: 0;
  min-width: 96px;
}

/* Deadline chip (shares .tag base for urgency variants) */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: 99px;
  font-size: .72rem;
  color: var(--muted);
  white-space: nowrap;
}

.tag-deadline { background: #fff7ed; border-color: #fed7aa; color: #c2410c; }

/* Deadline urgency variants — so people don't have to read a date and
   do the math themselves. */
.tag-deadline-urgent  { background: #fef2f2; border-color: #fecaca; color: #b91c1c; font-weight: 600; }
.tag-deadline-soon    { background: #fffbeb; border-color: #fde68a; color: #b45309; }
.tag-deadline-passed  { background: #f5f5f4; border-color: var(--border); color: var(--muted); text-decoration: line-through; }
.tag-deadline-rolling { background: var(--grant-bg); border-color: #a7f3d0; color: var(--grant); }
.tag-deadline-unknown { background: var(--bg); border-color: var(--border-soft); color: var(--muted); }

.btn-apply {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: .78rem;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity var(--ease);
  white-space: nowrap;
}

.btn-apply:hover { opacity: .85; }

.btn-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: .78rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--ease);
  white-space: nowrap;
}

.btn-save:hover { border-color: var(--text); color: var(--text); }

.apply-scholarship { background: var(--scholarship); }
.apply-fellowship  { background: var(--fellowship);  }
.apply-grant       { background: var(--grant);       }
.apply-job         { background: var(--job);         }
.apply-other       { background: var(--accent);      }

/* ------- Pagination ------- */
.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: .82rem;
  font-family: inherit;
  color: var(--muted);
  transition: all var(--ease);
  padding: 0 12px;
}

.page-btn:hover { border-color: var(--text); color: var(--text); }
.page-btn.active { background: var(--text); border-color: var(--text); color: var(--bg); }
.page-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ------- Modal ------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28,25,23,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 36px 32px;
  max-width: 430px;
  width: 90%;
  text-align: center;
  box-shadow: 0 24px 64px -12px rgba(28,25,23,.25);
}

.modal-box h3 { font-family: var(--font-display); font-size: 1.15rem; font-weight: 600; letter-spacing: -.01em; margin-bottom: 8px; }
.modal-box p { color: var(--muted); margin-bottom: 20px; font-size: .88rem; }

.email-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.email-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: .88rem;
  color: var(--text);
  min-width: 0;
}

.email-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }

.progress-track {
  background: var(--border-soft);
  border-radius: 10px;
  height: 5px;
  margin-bottom: 14px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 10px;
  animation: pulse-progress 2.4s ease-in-out infinite;
}

@keyframes pulse-progress {
  0%   { width: 5%;  }
  50%  { width: 80%; }
  100% { width: 5%;  }
}

.modal-note { font-size: .76rem; margin-bottom: 20px; }

/* ------- Toast ------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: .84rem;
  box-shadow: var(--shadow-hover);
  animation: slideUp .3s ease, fadeAway .3s ease 2.7s forwards;
  z-index: 2000;
  max-width: 360px;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

@keyframes fadeAway {
  to { opacity: 0; transform: translateY(20px); }
}

/* ------- Footer ------- */
.footer {
  border-top: 1px solid var(--border-soft);
  background: var(--surface);
  color: var(--muted);
  padding: 26px 0;
  font-size: .8rem;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.footer strong { color: var(--text); font-family: var(--font-display); font-weight: 600; }
.footer-note { font-size: .74rem; color: var(--muted); }
/* Underlined, not just colored — the accent color alone doesn't reach
   3:1 contrast against the surrounding text, so color can't be the
   only thing distinguishing this as a link (WCAG 1.4.1). */
.footer-note a { color: var(--accent); text-decoration: underline; }

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
  padding: 2px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  font-family: inherit;
  font-size: .7rem;
  cursor: pointer;
  transition: border-color var(--ease), color var(--ease);
}

.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.is-copied { border-color: var(--accent); color: var(--accent); }

/* ------- Search autocomplete ------- */
.search-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,.12);
  max-height: 280px;
  overflow-y: auto;
}

.search-suggestion {
  padding: 8px 10px;
  border-radius: 7px;
  font-size: .83rem;
  color: var(--text);
  cursor: pointer;
}

.search-suggestion:hover,
.search-suggestion.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ------- Responsive ------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; gap: 20px; }

  .sidebar {
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 14px;
  }

  .facet-group { min-width: 150px; flex: 1; }
  .facet-list { flex-direction: row; flex-wrap: wrap; }
  .facet { width: auto; }

  /* Below this width, brand + search + "Find new" no longer fit on one
     line — wrap the search bar onto its own full-width row instead of
     letting it overflow. */
  .header-inner { flex-wrap: wrap; gap: 10px; }
  .header-search { order: 3; flex-basis: 100%; max-width: none; }
  .header-actions { margin-left: auto; }
  .page-head { padding-top: 24px; }
}

@media (max-width: 720px) {
  .brand-name { display: none; }
}

@media (max-width: 560px) {
  .row { flex-direction: column; gap: 12px; }
  .row-actions { flex-direction: row; width: 100%; }
  .row-actions .btn-apply { flex: 1; }
  .email-form { flex-direction: column; }
  .modal-box { padding: 28px 20px; }
}

/* ------- Touch targets ------- */
/* (pointer: coarse) matches touchscreens specifically, so mouse/trackpad
   users keep the tighter desktop density — only touch input gets the
   larger tap area (~44px, the standard mobile a11y guideline). */
@media (pointer: coarse) {
  .btn-solid, .btn-ghost, .search-submit, .btn-apply, .page-btn,
  .facet, .fselect {
    min-height: 44px;
  }

  .btn-save { min-height: 40px; }
  .copy-btn { min-height: 36px; padding-top: 6px; padding-bottom: 6px; }
}

/* ------- Accessibility: visible focus states for keyboard navigation ------- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
  html { scroll-behavior: auto; }
}
