/* ========== CSS Variables ========== */
:root {
  --text: #1a1a1a;
  --muted: #666;
  --primary: #2c5aa0;
  --primary-hover: #1e3f70;
  --border: #e0e0e0;
  --bg-subtle: #fafafa;

  /* Spacing scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Breakpoints (for reference) */
  --breakpoint-tablet: 800px;
}

/* ========== Reset & Base ========== */
* { box-sizing: border-box; }
html {
  margin: 0;
  scrollbar-gutter: stable; /* Prevent layout shift when scrollbar appears/disappears */
}
body {
  margin: 0;
  font-family: "LM Roman 10", Georgia, Times, serif;
  font-weight: 400;
  font-size: 18px;
  color: var(--text);
  line-height: 1.7;
  background: #fff;
}

/* ========== Layout ========== */
.wrapper {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: var(--space-xl);
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ========== Sidebar ========== */
aside.sidebar {
  width: 300px; /* Match grid column definition */
  min-width: 300px; /* Prevent shrinking */
  padding: var(--space-xl) 0;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.name {
  font-size: 1.65rem;
  margin: 0 0 12px;
  font-weight: 600;
  color: var(--text);
}

.name a {
  color: var(--text);
  text-decoration: none;
  transition: color 0.2s ease;
}

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

.headshot {
  width: 100%;
  height: auto;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 0 0 12px;
  max-width: 100%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.tagline {
  margin: 3px 0;
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.5;
}

.quicklinks {
  list-style: none;
  padding: 0;
  margin: var(--space-md) 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quicklinks a {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  color: var(--primary);
  font-weight: 500;
  transition: color 0.2s ease;
}

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

.quicklinks a::before {
  content: '';
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  background-size: contain;
  background-repeat: no-repeat;
}

.quicklinks a[href*="mit.edu"]::before {
  background-image: url("../mit-econ-favicon.ico");
}

.quicklinks a[href^="mailto:"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232c5aa0'%3E%3Cpath d='M20 4H4c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z'/%3E%3C/svg%3E");
}

.quicklinks a[href$=".pdf"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%232c5aa0'%3E%3Cpath d='M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V8l-6-6zm4 18H6V4h7v5h5v11zM8 15h8v2H8v-2zm0-4h8v2H8v-2zm0-4h5v2H8V7z'/%3E%3C/svg%3E");
}

/* ========== Buttons (consolidated) ========== */
.cv-button,
.ph-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  width: 100%;
  text-align: center;
  padding: 14px 24px;
  margin-top: 20px;
  background: linear-gradient(135deg, var(--primary) 0%, #1e3f70 100%);
  color: #fff !important;
  border-radius: 10px;
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: 0.3px;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(44, 90, 160, 0.3);
  border: none;
  cursor: pointer;
  text-decoration: none;
}

.ph-button { margin-top: 12px; }

.cv-button:hover,
.ph-button:hover {
  background: linear-gradient(135deg, #1e3f70 0%, var(--primary) 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(44, 90, 160, 0.4);
  color: #fff !important;
}

.cv-button:active,
.ph-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 8px rgba(44, 90, 160, 0.3);
}

.cv-button::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

.ph-button::before {
  content: '';
  display: inline-block;
  width: 20px;
  height: 20px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.95-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
}

/* ========== Focus Styles (Accessibility) ========== */
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

button:focus-visible,
.paper-btn:focus-visible,
.cv-button:focus-visible,
.ph-button:focus-visible,
.course-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.top-nav button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ========== Links ========== */
a {
  color: var(--primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover { color: var(--primary-hover); }
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ========== Content ========== */
main.content {
  padding: var(--space-xl) 0;
  max-width: 760px;
  min-width: 0; /* Prevent content from affecting grid column width */
}

section {
  margin: 0 0 var(--space-lg);
  padding: var(--space-lg);
  background: var(--bg-subtle);
  border-radius: 8px;
  border: 1px solid var(--border);
}

h2 {
  font-size: 1.4rem;
  margin: 0 0 var(--space-md);
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

h2::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 24px;
  background: var(--primary);
  border-radius: 3px;
}

/* ========== Bio Section ========== */
.bio {
  background: none;
  border: none;
  padding: 0 var(--space-lg);
  margin: 0 0 var(--space-lg);
}

.bio p {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.bio p:last-child { margin-bottom: 0; }
.bio strong { color: var(--primary); font-weight: 600; }

/* ========== Papers/Publications ========== */
.papers {
  list-style: none;
  padding: 0;
  margin: 0;
}

.paper {
  margin: var(--space-md) 0 20px;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.paper:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.paper-title {
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.5;
}

.paper-meta {
  color: var(--muted);
  margin-left: 0;
  display: block;
  margin-top: 4px;
  font-size: .93rem;
}

details { margin-top: var(--space-sm); }

details > summary {
  cursor: pointer;
  list-style: none;
  display: inline-block;
  user-select: none;
  color: var(--primary);
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

details > summary:hover { background: rgba(44, 90, 160, 0.08); }
details > summary::after { content: " ▾"; color: var(--muted); margin-left: 4px; }
details[open] > summary::after { content: " ▴"; }

details .abs {
  margin: 12px 0 0;
  padding: 12px;
  background: #fff;
  border-left: 3px solid var(--primary);
  color: var(--text);
  line-height: 1.7;
  border-radius: 4px;
}

/* ========== Paper Buttons ========== */
.paper-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: 10px;
}

.paper-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  min-height: 44px;
  font-size: .9rem;
  font-weight: 500;
  color: var(--primary);
  background: #fff;
  border: 1px solid var(--primary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: inherit;
}

.paper-btn:hover {
  background: var(--primary);
  color: #fff;
}

.paper-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* ========== Citation Modal ========== */
.cite-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
}

.cite-modal.active { display: flex; }

.cite-modal-content {
  background: #fff;
  border-radius: 10px;
  max-width: 600px;
  width: 90%;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}

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

.cite-modal-header h3 { margin: 0; font-size: 1.1rem; }

.cite-modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
}

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

.cite-modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: calc(80vh - 120px);
}

.cite-modal-body pre {
  background: var(--bg-subtle);
  padding: var(--space-md);
  border-radius: 6px;
  overflow-x: auto;
  font-size: .85rem;
  line-height: 1.5;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.cite-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

/* ========== Footer ========== */
footer.site {
  border-top: 1px solid var(--border);
  margin-top: var(--space-xl);
  padding-top: var(--space-md);
  color: var(--muted);
  font-size: .9rem;
}

/* ========== Public Health Publications ========== */
#public-health-publications details > summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--border);
  padding-bottom: var(--space-sm);
  margin-bottom: var(--space-md);
}

#public-health-publications details > summary::-webkit-details-marker { display: none; }

#public-health-publications details > summary h2 {
  margin: 0;
  flex-grow: 1;
}

#public-health-publications details > summary h2::before { display: inline-block; }

#public-health-publications details > summary::after {
  content: "+";
  font-size: 2rem;
  font-weight: bold;
  color: var(--text);
  line-height: 1;
  flex-shrink: 0;
  margin-left: var(--space-md);
}

#public-health-publications details[open] > summary::after { content: "−"; }
#public-health-publications details > summary:hover { opacity: 0.7; }
#public-health-publications .papers { margin-top: 20px; }

/* ========== Contact Section ========== */
#contact { background: var(--bg-subtle); }

/* ========== Navigation Tabs ========== */
.top-nav {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-lg);
  padding: var(--space-md) 0;
  margin-bottom: var(--space-sm);
}

.top-nav button {
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s ease;
}

.top-nav button:hover { color: var(--primary); }
.top-nav button.active { color: var(--primary); border-bottom: 2px solid var(--primary); padding-bottom: 2px; }

/* ========== Tab Content ========== */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== Teaching/Courses ========== */
.courses {
  list-style: none;
  padding: 0;
  margin: 0;
}

.course {
  margin: var(--space-md) 0 20px;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.course:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.course-title {
  font-weight: 600;
  font-size: 1.05rem;
  line-height: 1.5;
}

.course-meta {
  color: var(--muted);
  display: block;
  margin-top: 4px;
  font-size: .93rem;
}

.course-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-top: 12px;
}

.course-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-size: .9rem;
  font-weight: 500;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

.course-btn:hover {
  background: var(--primary-hover);
  color: #fff;
  transform: translateY(-1px);
}

.course-btn svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.course-btn.outline {
  background: #fff;
  color: var(--primary);
  border: 1px solid var(--primary);
}

.course-btn.outline:hover {
  background: var(--primary);
  color: #fff;
}

/* ========== Responsive ========== */
@media (max-width: 800px) {
  .wrapper {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 0 var(--space-md);
    max-width: 720px;
  }

  aside.sidebar {
    width: auto;
    min-width: 0;
    position: relative;
    top: auto;
    height: auto;
    padding: var(--space-md) 0 0;
    align-items: center;
    text-align: center;
  }

  .name { font-size: 1.4rem; margin: 0 0 var(--space-sm); }
  .headshot { width: min(65vw, 280px); margin: 4px 0 10px; }
  .tagline { font-size: .9rem; margin: 2px 0; }
  .quicklinks { align-items: center; }

  main.content { padding: var(--space-sm) 0 20px; max-width: unset; }
  section { margin: 0 0 var(--space-md); padding: var(--space-md); }
  h2 { font-size: 1.2rem; margin: 0 0 12px; }
  .paper { margin: 12px 0 var(--space-md); }
  footer.site { text-align: center; }

  /* Mobile tabs */
  .top-nav {
    justify-content: center;
    gap: 6px;
    padding: 12px 0;
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
  }

  .top-nav button {
    padding: 8px 14px;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: .85rem;
  }

  .top-nav button.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
  }

  .top-nav button:hover { border-color: var(--primary); }
}

/* Prevent layout breaking */
.paper-title, .paper-meta, .bio, #contact p {
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
