/* ==========================================================================
   CSES (Comparative Study of Election Surveys) Official Design System
   Minimalist, Academic, Airy & Clean (Inspired by Our World in Data)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,600;0,6..72,700;1,6..72,400&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* Official CSES Brand Colors from Logo */
  --cses-orange: #e86314;
  --cses-orange-hover: #d25409;
  --cses-orange-light: #fff5ed;
  --cses-orange-border: #fcd7be;
  
  --cses-blue: #5d7a9c;
  --cses-blue-dark: #3b5370;
  --cses-blue-light: #f0f4f8;
  --cses-blue-border: #d4e0eb;

  --cses-charcoal: #1c2024;
  --cses-charcoal-light: #2c3238;

  /* Surfaces & Clean Whitespace */
  --bg-body: #ffffff;
  --bg-subtle: #f9fafb;
  --bg-card: #ffffff;
  --border-subtle: #e5e7eb;
  --border-medium: #d1d5db;

  /* Text & Typography */
  --text-main: #1f2937;
  --text-muted: #4b5563;
  --text-light: #6b7280;

  --font-serif: 'Newsreader', Georgia, Cambria, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Radii & Shadows */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-full: 9999px;

  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.07);

  --container-width: 1140px;
  --container-narrow: 820px;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.7;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

a {
  color: var(--cses-orange);
  text-decoration: none;
  transition: color 0.15s ease;
}

a:hover {
  color: var(--cses-orange-hover);
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
}

/* --------------------------------------------------------------------------
   Containers & Spacing
   -------------------------------------------------------------------------- */
.container {
  width: 100%;
  max-width: var(--container-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: 2rem;
  padding-right: 2rem;
}

.container-narrow {
  max-width: var(--container-narrow);
}

/* --------------------------------------------------------------------------
   Clean Minimalist Header
   -------------------------------------------------------------------------- */
.site-header {
  background-color: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 5.5rem;
}

.brand-link {
  display: flex;
  align-items: center;
  text-decoration: none !important;
}

.brand-logo-img {
  height: 48px;
  width: auto;
  display: block;
}

/* Main Navigation */
.main-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-item {
  position: relative;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--cses-charcoal);
  border-radius: var(--radius-md);
  text-decoration: none !important;
  transition: all 0.15s ease;
}

.nav-link:hover, .nav-link.active {
  color: var(--cses-orange);
  background-color: var(--cses-orange-light);
}

.nav-link svg {
  color: var(--text-light);
  transition: transform 0.15s ease;
}

.nav-item:hover .nav-link svg {
  transform: rotate(180deg);
}

/* Dropdown */
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background-color: #ffffff;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.08);
  min-width: 250px;
  padding: 0.4rem 0;
  display: none;
  flex-direction: column;
  z-index: 60;
}

.nav-item:hover .dropdown-menu {
  display: flex;
}

.dropdown-item {
  padding: 0.6rem 1.2rem;
  font-size: 0.875rem;
  color: var(--cses-charcoal);
  text-decoration: none !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background-color 0.15s ease;
}

.dropdown-item:hover {
  background-color: var(--bg-subtle);
  color: var(--cses-orange);
}

.dropdown-item .badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  color: var(--text-light);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.search-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.85rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.search-btn:hover {
  border-color: var(--border-medium);
  background-color: #ffffff;
  color: var(--cses-charcoal);
}

.search-kbd {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  background-color: #ffffff;
  border: 1px solid var(--border-subtle);
  padding: 0.05rem 0.35rem;
  border-radius: var(--radius-sm);
  color: var(--text-light);
}

.btn-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background-color: var(--cses-orange);
  color: #ffffff !important;
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  text-decoration: none !important;
  transition: background-color 0.15s ease;
}

.btn-cta:hover {
  background-color: var(--cses-orange-hover);
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--cses-charcoal);
}

/* --------------------------------------------------------------------------
   Minimalist & Airy Hero Section
   -------------------------------------------------------------------------- */
.hero {
  padding: 5rem 0 4rem 0;
  border-bottom: 1px solid var(--border-subtle);
  background: radial-gradient(circle at 80% 20%, #fffbf7 0%, #ffffff 70%);
}

.hero-content {
  max-width: 860px;
}

.hero-tag {
  display: inline-block;
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cses-orange);
  margin-bottom: 1rem;
}

.hero-title {
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 3.25rem;
  line-height: 1.15;
  color: var(--cses-charcoal);
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
}

.hero-desc {
  font-size: 1.2rem;
  color: var(--text-muted);
  line-height: 1.65;
  margin-bottom: 2.25rem;
  font-weight: 400;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-medium);
  color: var(--cses-charcoal) !important;
  font-weight: 500;
  font-size: 0.9375rem;
  text-decoration: none !important;
  transition: all 0.15s ease;
  background-color: #ffffff;
}

.btn-outline:hover {
  border-color: var(--cses-charcoal);
  background-color: var(--bg-subtle);
}

/* Key Metrics Line */
.stats-line {
  display: flex;
  gap: 3rem;
  margin-top: 3.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

.stat-block {
  display: flex;
  flex-direction: column;
}

.stat-num {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 700;
  color: var(--cses-charcoal);
  line-height: 1.1;
}

.stat-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* --------------------------------------------------------------------------
   Sections & Module Grid (OWID-Inspired Topic Cards)
   -------------------------------------------------------------------------- */
.section {
  padding: 4.5rem 0;
}

.section-head {
  margin-bottom: 2.5rem;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  color: var(--cses-charcoal);
  letter-spacing: -0.01em;
  margin-bottom: 0.5rem;
}

.section-subtitle {
  font-size: 1.05rem;
  color: var(--text-muted);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 2rem;
}

.module-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

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

.module-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.module-tag {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cses-orange);
}

.module-year {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 500;
}

.module-heading {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--cses-charcoal);
  line-height: 1.3;
  margin-bottom: 0.75rem;
}

.module-heading a {
  color: var(--cses-charcoal);
  text-decoration: none;
}

.module-heading a:hover {
  color: var(--cses-orange);
}

.module-summary {
  font-size: 0.9375rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 1.5rem;
}

.module-footer {
  border-top: 1px solid var(--border-subtle);
  padding-top: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.format-tags {
  display: flex;
  gap: 0.35rem;
}

.format-tag {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  background-color: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
}

.link-arrow {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--cses-orange);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.link-arrow:hover {
  color: var(--cses-orange-hover);
}

/* --------------------------------------------------------------------------
   Data Downloads Matrix
   -------------------------------------------------------------------------- */
.data-table-container {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  background-color: #ffffff;
  overflow: hidden;
  box-shadow: var(--shadow-subtle);
}

.data-table-toolbar {
  padding: 1.25rem 1.75rem;
  background-color: var(--bg-subtle);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.data-search {
  width: 320px;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-family: var(--font-sans);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  padding: 0.9rem 1.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  background-color: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 1.25rem 1.75rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  font-size: 0.9375rem;
}

.data-table tr:hover td {
  background-color: #fdfdfd;
}

.btn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.6rem;
  border-radius: var(--radius-sm);
  background-color: var(--bg-subtle);
  color: var(--cses-charcoal);
  border: 1px solid var(--border-subtle);
  text-decoration: none !important;
  transition: all 0.15s ease;
}

.btn-chip:hover {
  background-color: var(--cses-orange);
  color: #ffffff;
  border-color: var(--cses-orange);
}

/* --------------------------------------------------------------------------
   Clean Reading Prose (Articles & Documentation)
   -------------------------------------------------------------------------- */
.reading-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 4rem;
  align-items: start;
  padding: 4rem 0;
}

.reading-main {
  max-width: 760px;
}

.page-category {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--cses-orange);
  margin-bottom: 0.75rem;
}

.page-title {
  font-family: var(--font-serif);
  font-size: 2.75rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--cses-charcoal);
  letter-spacing: -0.02em;
  margin-bottom: 1.5rem;
}

.prose {
  font-size: 1.125rem;
  line-height: 1.8;
  color: #2c3238;
}

.prose h2 {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--cses-charcoal);
  margin-top: 2.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-subtle);
}

.prose h3 {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--cses-charcoal);
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

.prose p {
  margin-bottom: 1.5rem;
}

.prose ul, .prose ol {
  margin-bottom: 1.5rem;
  padding-left: 1.5rem;
}

.prose li {
  margin-bottom: 0.5rem;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 2rem 0;
  font-size: 0.95rem;
}

.prose th {
  background-color: var(--bg-subtle);
  padding: 0.75rem 1rem;
  font-weight: 600;
  border-bottom: 2px solid var(--border-medium);
  text-align: left;
}

.prose td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

/* Sticky Minimalist TOC Sidebar */
.sidebar-toc {
  position: sticky;
  top: 7rem;
  border-left: 1px solid var(--border-subtle);
  padding-left: 1.5rem;
}

.toc-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 1rem;
}

.toc-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.toc-link {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-decoration: none !important;
  transition: color 0.15s ease;
}

.toc-link:hover, .toc-link.active {
  color: var(--cses-orange);
  font-weight: 500;
}

/* --------------------------------------------------------------------------
   Minimalist Clean Footer
   -------------------------------------------------------------------------- */
.site-footer {
  background-color: var(--bg-subtle);
  border-top: 1px solid var(--border-subtle);
  padding: 4.5rem 0 3rem 0;
  margin-top: auto;
}

.footer-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 3rem;
  margin-bottom: 3.5rem;
}

.footer-logo {
  height: 38px;
  width: auto;
  margin-bottom: 1rem;
}

.footer-about {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.65;
  max-width: 380px;
}

.footer-col-title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--cses-charcoal);
  margin-bottom: 1.25rem;
}

.footer-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.footer-nav a {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-decoration: none;
  transition: color 0.15s ease;
}

.footer-nav a:hover {
  color: var(--cses-orange);
}

.footer-bottom {
  padding-top: 2rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  color: var(--text-light);
  flex-wrap: wrap;
  gap: 1rem;
}

/* --------------------------------------------------------------------------
   Search Modal
   -------------------------------------------------------------------------- */
.search-modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(28, 32, 36, 0.4);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 12vh;
}

.search-modal-backdrop.open {
  display: flex;
}

.search-modal {
  background-color: #ffffff;
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 35px -5px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  border: 1px solid var(--border-medium);
}

.search-modal-header {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  gap: 0.75rem;
}

.search-modal-input {
  width: 100%;
  border: none;
  outline: none;
  font-size: 1.125rem;
  font-family: var(--font-sans);
  color: var(--cses-charcoal);
}

.search-results-list {
  max-height: 400px;
  overflow-y: auto;
  padding: 0.5rem;
}

.search-result-item {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  text-decoration: none !important;
  color: var(--cses-charcoal);
  transition: background-color 0.15s ease;
}

.search-result-item:hover {
  background-color: var(--bg-subtle);
}

.search-result-title {
  font-weight: 600;
  color: var(--cses-charcoal);
}

.search-result-type {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* --------------------------------------------------------------------------
   Responsive Rules
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .reading-layout {
    grid-template-columns: 1fr;
  }
  .sidebar-toc {
    display: none;
  }
  .footer-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .main-nav {
    display: none;
  }
  .mobile-toggle {
    display: block;
  }
  .hero-title {
    font-size: 2.25rem;
  }
  .stats-line {
    gap: 1.5rem;
  }
  .footer-grid {
    grid-template-columns: 1fr;
  }
}
