/* =================================================================
   Alejandro Medina Sandín — Academic website
   Shared stylesheet
   ================================================================= */

/* ---------- Design tokens ---------- */
:root {
  --bg: #ffffff;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --hairline: #e6e6e6;
  --accent: #1b3a5c;
  --accent-hover: #2a527e;
  --accent-tint: #f4f6f9;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  --maxw: 760px;
  --gutter: 24px;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.65;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (min-width: 600px) {
  body { font-size: 18px; }
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid rgba(27, 58, 92, 0.28);
  transition: color 0.18s ease, border-color 0.18s ease;
}

a:hover {
  color: var(--accent-hover);
  border-bottom-color: var(--accent-hover);
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* ---------- Layout container ---------- */
.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 var(--gutter);
}

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--hairline);
}

.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  gap: 16px;
}

.brand {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.18rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  border-bottom: none;
  white-space: nowrap;
}

.brand:hover {
  color: var(--accent);
}

/* Hide the header name on Home (the name already appears large in the hero),
   while preserving layout so the nav stays in place. */
.brand--hidden {
  visibility: hidden;
}

.nav {
  display: flex;
  align-items: center;
  gap: 28px;
}

.nav a {
  font-size: 0.95rem;
  font-weight: 500;
  color: var(--ink);
  border-bottom: none;
  padding: 4px 0;
  position: relative;
}

.nav a::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: 1px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s ease;
}

.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--accent);
}

.nav a:hover::after,
.nav a[aria-current="page"]::after {
  transform: scaleX(1);
}

/* Hamburger toggle */
.nav-toggle {
  display: none;
  background: none;
  border: none;
  padding: 8px;
  margin: 0;
  cursor: pointer;
  color: var(--ink);
}

.nav-toggle svg {
  display: block;
}

/* ---------- Main ---------- */
main {
  padding: 56px 0 24px;
}

@media (min-width: 600px) {
  main { padding: 72px 0 32px; }
}

section + section {
  margin-top: 56px;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--ink);
  margin: 0 0 0.5em;
}

h1 { font-size: 2.1rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.18rem; }

@media (min-width: 600px) {
  h1 { font-size: 2.6rem; }
  h2 { font-size: 1.65rem; }
}

p { margin: 0 0 1.1em; }
p:last-child { margin-bottom: 0; }

.section-title {
  font-size: 1.05rem;
  font-family: var(--sans);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--hairline);
}

.muted { color: var(--muted); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.lead {
  font-size: 1.05rem;
  color: var(--ink);
}

/* ---------- Hero ---------- */
.hero {
  display: flex;
  flex-direction: column;
  gap: 28px;
  align-items: flex-start;
}

@media (min-width: 640px) {
  .hero {
    flex-direction: row-reverse;
    align-items: center;
    gap: 36px;
  }
}

.hero-photo {
  flex: 0 0 auto;
  width: 165px;
  height: 165px;
  border-radius: 4px;
  object-fit: cover;
  object-position: center 30%;
  border: 1px solid var(--hairline);
}

@media (min-width: 640px) {
  .hero-photo { width: 200px; height: 200px; }
}

.hero-photo--placeholder {
  width: 150px;
  height: 150px;
  border-radius: 4px;
  border: 1px solid var(--hairline);
  background-color: #f0f0f0;
  background-image: repeating-linear-gradient(
    45deg,
    #ececec 0,
    #ececec 8px,
    #f4f4f4 8px,
    #f4f4f4 16px
  );
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 10px;
  flex: 0 0 auto;
}

@media (min-width: 640px) {
  .hero-photo--placeholder { width: 184px; height: 184px; }
}

.hero-text { min-width: 0; }

.hero h1 {
  margin-bottom: 0.25em;
}

.hero-title {
  font-size: 1.12rem;
  font-weight: 500;
  margin-bottom: 0.35em;
}

.hero-affil {
  color: var(--muted);
  font-size: 0.98rem;
  margin-bottom: 0;
}

/* ---------- Primary links row ---------- */
.linkbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 28px;
  list-style: none;
  padding: 0;
}

.linkbar li { margin: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 500;
  padding: 8px 15px;
  border: 1px solid var(--hairline);
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  transition: border-color 0.18s ease, background 0.18s ease, color 0.18s ease;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-tint);
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.btn--muted[aria-disabled="true"] {
  color: var(--muted);
  cursor: default;
  opacity: 0.7;
}

.btn--muted[aria-disabled="true"]:hover {
  border-color: var(--hairline);
  color: var(--muted);
  background: #fff;
}

/* ---------- Research fields ---------- */
.fields {
  display: grid;
  gap: 18px;
}

@media (min-width: 560px) {
  .fields { grid-template-columns: 1fr 1fr; gap: 28px; }
}

.field-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

.field-body { margin: 0; }

/* ---------- Job market paper box ---------- */
.jmp-box {
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 24px 26px;
  background: var(--accent-tint);
}

.jmp-tag,
.tag {
  display: inline-block;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--accent);
  background: #fff;
  border: 1px solid rgba(27, 58, 92, 0.25);
  border-radius: 4px;
  padding: 3px 9px;
  margin-bottom: 12px;
}

.jmp-box h3 {
  font-size: 1.28rem;
  margin-bottom: 0.4em;
}

.jmp-box .jmp-links {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  font-size: 0.95rem;
}

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

.paper {
  padding: 30px 0;
  border-top: 1px solid var(--hairline);
}

.paper:first-child { border-top: none; padding-top: 0; }

.paper--jmp {
  background: var(--accent-tint);
  border: 1px solid var(--hairline);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 26px;
  margin-bottom: 8px;
}

.paper--jmp + .paper { border-top: none; }

/* Two-column layout: figure beside content */
.paper-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 640px) {
  .paper-grid {
    grid-template-columns: 360px 1fr;
    gap: 34px;
    align-items: start;
  }
}

/* Working-papers rows break out wider than the 760px reading column
   on large screens, so the abstract sits compactly beside the figure. */
@media (min-width: 1080px) {
  .section--wide {
    width: 1060px;
    margin-left: 50%;
    transform: translateX(-50%);
  }
}

.paper-content { min-width: 0; }

/* Figure / chart slot */
.paper-figure {
  margin: 0;
}

.paper-figure img {
  width: 100%;
  height: auto;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background: #fff;
}

.paper-figure figcaption {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}

.figure-placeholder {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  background-color: #f6f6f6;
  background-image: repeating-linear-gradient(
    45deg,
    #ececec 0,
    #ececec 8px,
    #f6f6f6 8px,
    #f6f6f6 16px
  );
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.paper-title {
  font-family: var(--serif);
  font-weight: 700;
  font-size: 1.2rem;
  line-height: 1.3;
  margin: 0 0 8px;
}

.paper-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  font-size: 0.92rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.paper-status {
  font-style: italic;
}

.paper-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.92rem;
  margin-top: 6px;
}

/* ---------- Abstract (always visible, compact) ---------- */
.abstract-label {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 16px 0 6px;
}

.abstract-body {
  margin: 0;
  font-size: 0.9rem;
  color: #333;
  line-height: 1.55;
  text-align: justify;
  hyphens: auto;
}

/* Legacy collapsible styles (kept for safety) */
.abstract {
  margin-top: 14px;
}

.abstract summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--accent);
  list-style: none;
  user-select: none;
  padding: 2px 0;
}

.abstract summary::-webkit-details-marker { display: none; }

.abstract summary .chev {
  transition: transform 0.2s ease;
  display: inline-block;
  font-size: 0.7rem;
}

.abstract[open] summary .chev { transform: rotate(90deg); }

.abstract-body--narrow {
  max-width: 70ch;
}

/* ---------- Conference list ---------- */
.conf-group { margin-bottom: 22px; }
.conf-group:last-child { margin-bottom: 0; }

.conf-year {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--accent);
  margin-bottom: 6px;
}

.conf-list {
  margin: 0;
  padding-left: 1.1em;
}

.conf-list li {
  margin-bottom: 5px;
  color: #333;
}

/* Detailed, Moramarco-style entries */
.conf-detailed {
  list-style: none;
  margin: 0;
  padding: 0;
}

.conf-detailed li {
  position: relative;
  padding-left: 22px;
  margin-bottom: 14px;
  color: #333;
  line-height: 1.5;
}

.conf-detailed li::before {
  content: "▪";
  position: absolute;
  left: 0;
  top: 0;
  color: var(--accent);
  font-size: 0.85em;
}

.conf-detailed .conf-name {
  font-weight: 500;
  color: var(--ink);
}

.conf-detailed .conf-theme {
  font-style: italic;
}

.conf-detailed .conf-place {
  color: var(--muted);
}

.conf-detailed .conf-todo {
  color: var(--accent);
  font-style: italic;
}

/* ---------- CV ---------- */
.cv-section { margin-bottom: 40px; }
.cv-section:last-child { margin-bottom: 0; }

.cv-item {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px 24px;
  padding: 12px 0;
  border-top: 1px solid var(--hairline);
}

.cv-section .cv-item:first-of-type { border-top: none; }

@media (min-width: 600px) {
  .cv-item {
    grid-template-columns: 110px 1fr;
  }
}

.cv-date {
  color: var(--muted);
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
}

.cv-body { margin: 0; }
.cv-body strong { font-weight: 600; }
.cv-body .cv-sub { color: var(--muted); font-size: 0.95rem; display: block; }

.cv-inline {
  margin: 0;
  line-height: 1.8;
}

.cv-inline .label {
  font-weight: 600;
}

.cv-refs {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 600px) {
  .cv-refs { grid-template-columns: repeat(3, 1fr); }
}

.cv-ref p { margin: 0; line-height: 1.6; }

/* ---------- Contact ---------- */
.contact-grid {
  display: grid;
  gap: 8px 18px;
  grid-template-columns: 1fr;
}

@media (min-width: 560px) {
  .contact-grid { grid-template-columns: 130px 1fr; }
}

.contact-grid dt {
  font-weight: 600;
  color: var(--ink);
}

.contact-grid dd {
  margin: 0;
  color: #333;
}

.contact-grid dd + dt { margin-top: 10px; }

@media (min-width: 560px) {
  .contact-grid dd + dt { margin-top: 0; }
  .contact-grid dt { margin-top: 0; }
}

.ref-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.ref-list li {
  padding: 12px 0;
  border-top: 1px solid var(--hairline);
}

.ref-list li:first-child { border-top: none; }

.ref-name { font-weight: 600; }
.ref-affil { color: var(--muted); font-size: 0.95rem; }

/* ---------- Footer ---------- */
.site-footer {
  margin-top: 80px;
  border-top: 1px solid var(--hairline);
  padding: 32px 0 48px;
  font-size: 0.9rem;
  color: var(--muted);
}

.site-footer .footer-name {
  color: var(--ink);
  font-weight: 500;
}

.footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 12px 0 16px;
  list-style: none;
  padding: 0;
}

.footer-links a {
  color: var(--muted);
  border-bottom-color: transparent;
}

.footer-links a:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.footer-copy { font-size: 0.86rem; }

/* ---------- Fade-in on scroll (very subtle) ---------- */
.reveal {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.reveal.is-visible {
  opacity: 1;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .reveal { opacity: 1; transform: none; transition: none; }
  .abstract summary .chev { transition: none; }
}

/* ---------- Mobile nav ---------- */
@media (max-width: 639px) {
  .nav-toggle { display: inline-flex; }

  .nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    background: #fff;
    border-bottom: 1px solid var(--hairline);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.04);
    padding: 6px 0;
    display: none;
  }

  .nav.is-open { display: flex; }

  .nav a {
    padding: 12px var(--gutter);
    font-size: 1rem;
  }

  .nav a::after { display: none; }

  .nav a:hover,
  .nav a[aria-current="page"] {
    background: var(--accent-tint);
  }
}
