/* =====================================================
   MGRI Research Methods Handbook — Shared Stylesheet
   University of Wisconsin–Madison, CCWT
   ===================================================== */

/* ---------- Google Fonts ---------- */
@import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:ital,opsz,wght@0,8..60,300;0,8..60,400;0,8..60,600;1,8..60,400&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --uw-red:      #c5050c;
  --uw-dark-red: #9b0000;
  --uw-gold:     #f7f0e0;
  --accent:      #c5050c;
  --text-main:   #1a1a1a;
  --text-muted:  #555;
  --text-light:  #777;
  --bg-page:     #fafaf8;
  --bg-sidebar:  #1e2328;
  --bg-sidebar-hover: #2d3340;
  --bg-sidebar-active: #c5050c;
  --sidebar-text: #d4d8e0;
  --sidebar-text-active: #ffffff;
  --border:      #ddd;
  --border-light: #e8e8e8;
  --code-bg:     #f4f4f2;
  --shadow:      0 2px 8px rgba(0,0,0,0.08);
  --shadow-md:   0 4px 16px rgba(0,0,0,0.12);
  --radius:      6px;
  --sidebar-w:   270px;
  --font-serif:  'Source Serif 4', Georgia, serif;
  --font-sans:   'IBM Plex Sans', system-ui, sans-serif;
  --font-mono:   'IBM Plex Mono', 'Courier New', monospace;
}

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

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

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text-main);
  background: var(--bg-page);
  display: flex;
  min-height: 100vh;
}

/* =====================================================
   SIDEBAR
   ===================================================== */
#sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  color: var(--sidebar-text);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: #444; border-radius: 2px; }

.sidebar-header {
  padding: 1.5rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.sidebar-logo .logo-badge {
  background: var(--uw-red);
  color: #fff;
  font-family: var(--font-serif);
  font-weight: 600;
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.sidebar-title {
  font-family: var(--font-serif);
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.35;
  margin-top: 0.5rem;
}

.sidebar-subtitle {
  font-size: 0.72rem;
  color: #8a9ab0;
  margin-top: 0.25rem;
  line-height: 1.4;
}

/* Navigation sections */
.nav-section {
  padding: 0.75rem 0;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #5a6680;
  padding: 0.5rem 1.25rem 0.3rem;
}

.nav-section + .nav-section {
  border-top: 1px solid rgba(255,255,255,0.06);
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.42rem 1.25rem;
  font-size: 0.82rem;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  line-height: 1.4;
  gap: 0.5rem;
}

.nav-link:hover {
  background: var(--bg-sidebar-hover);
  color: #fff;
}

.nav-link.active {
  background: var(--bg-sidebar-active);
  color: var(--sidebar-text-active);
  font-weight: 600;
}

.nav-link .step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  min-width: 18px;
  background: rgba(255,255,255,0.12);
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 600;
  flex-shrink: 0;
}

.nav-link.active .step-num {
  background: rgba(255,255,255,0.25);
}

/* Mobile toggle */
#sidebar-toggle {
  display: none;
  position: fixed;
  top: 1rem; left: 1rem;
  z-index: 200;
  background: var(--bg-sidebar);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
}

/* =====================================================
   MAIN CONTENT
   ===================================================== */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.content-wrapper {
  max-width: 860px;
  width: 100%;
  padding: 3rem 3.5rem;
  flex: 1;
}

/* =====================================================
   PAGE HEADER
   ===================================================== */
.page-header {
  margin-bottom: 2.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 2px solid var(--border-light);
}

.page-eyebrow {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--uw-red);
  margin-bottom: 0.4rem;
}

.page-title {
  font-family: var(--font-serif);
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.page-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* =====================================================
   TYPOGRAPHY
   ===================================================== */
h1, h2, h3, h4 {
  font-family: var(--font-serif);
  line-height: 1.3;
  color: var(--text-main);
}

h2 {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 2.5rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-light);
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.75rem 0 0.5rem;
  color: var(--text-main);
}

h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.25rem 0 0.4rem;
}

p {
  margin-bottom: 1rem;
}

a {
  color: var(--uw-red);
  text-decoration: underline;
  text-decoration-color: rgba(197,5,12,0.35);
  text-underline-offset: 2px;
}

a:hover {
  color: var(--uw-dark-red);
  text-decoration-color: var(--uw-dark-red);
}

ul, ol {
  margin: 0.5rem 0 1rem 1.5rem;
  line-height: 1.75;
}

li { margin-bottom: 0.25rem; }

/* =====================================================
   STEP BADGES
   ===================================================== */
.step-block {
  margin: 2rem 0 0.5rem;
}

.step-heading {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 0.6rem;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  background: var(--uw-red);
  color: #fff;
  font-family: var(--font-sans);
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 2px;
}

.step-badge.sub {
  width: 26px;
  height: 26px;
  min-width: 26px;
  background: #e0e4eb;
  color: var(--text-main);
  font-size: 0.75rem;
  margin-top: 3px;
}

.step-heading h3 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.4;
}

.step-content {
  padding-left: calc(34px + 0.85rem);
}

.step-content.sub {
  padding-left: calc(26px + 0.85rem);
}

/* =====================================================
   SCREENSHOT / FIGURE
   ===================================================== */
.figure-block {
  margin: 1.5rem 0;
}

.figure-block img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.figure-caption {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 0.4rem;
  font-style: italic;
  text-align: center;
}

/* Circled screenshot reference numbers (①②③...) */
.fig-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  background: var(--uw-red);
  color: #fff;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 700;
  margin-right: 0.3rem;
  vertical-align: middle;
}

/* =====================================================
   CODE BLOCKS
   ===================================================== */
pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--uw-red);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  overflow-x: auto;
  margin: 1rem 0 1.5rem;
  font-size: 0.83rem;
  line-height: 1.65;
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
}

pre code {
  font-size: inherit;
  background: none;
  border: none;
  padding: 0;
  color: #2d3748;
}

:not(pre) > code {
  background: var(--code-bg);
  border: 1px solid var(--border-light);
  border-radius: 3px;
  padding: 0.1em 0.35em;
  font-size: 0.85em;
  color: #b91c1c;
}

/* =====================================================
   TABLES
   ===================================================== */
.table-wrapper {
  overflow-x: auto;
  margin: 1.25rem 0 1.75rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  background: #fff;
}

thead th {
  background: var(--bg-sidebar);
  color: #fff;
  font-weight: 600;
  font-family: var(--font-sans);
  padding: 0.65rem 0.85rem;
  text-align: left;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
}

tbody tr:nth-child(even) { background: #f8f9fb; }
tbody tr:hover { background: #f0f2f7; }

td {
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
  line-height: 1.55;
}

td code {
  font-size: 0.82em;
  word-break: break-all;
}

/* =====================================================
   CALLOUT BOXES
   ===================================================== */
.callout {
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin: 1.25rem 0;
  border-left: 4px solid;
  font-size: 0.92rem;
  line-height: 1.65;
}

.callout-title {
  font-weight: 700;
  font-family: var(--font-sans);
  font-size: 0.8rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.callout.note {
  background: #eef4ff;
  border-color: #3b82f6;
  color: #1e3a5f;
}
.callout.note .callout-title { color: #2563eb; }

.callout.important {
  background: #fff8e1;
  border-color: #f59e0b;
  color: #4a3000;
}
.callout.important .callout-title { color: #b45309; }

.callout.tip {
  background: #f0fdf4;
  border-color: #22c55e;
  color: #14532d;
}
.callout.tip .callout-title { color: #16a34a; }

.callout.faq {
  background: #fdf4ff;
  border-color: #a855f7;
  color: #3b0764;
}
.callout.faq .callout-title { color: #9333ea; }

/* Placeholder / TODO highlight */
.placeholder {
  background: #fff3cd;
  border: 1px dashed #f0ad4e;
  border-radius: 3px;
  padding: 0.1em 0.4em;
  color: #856404;
  font-style: italic;
  font-size: 0.9em;
}

/* =====================================================
   PREV / NEXT NAVIGATION
   ===================================================== */
.page-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-light);
}

.page-nav a {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.85rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.88rem;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  max-width: 48%;
  min-width: 140px;
}

.page-nav a:hover {
  border-color: var(--uw-red);
  box-shadow: 0 0 0 3px rgba(197,5,12,0.08);
  background: #fff;
  color: var(--text-main);
}

.page-nav .nav-direction {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--uw-red);
}

.page-nav .nav-label {
  font-weight: 500;
  line-height: 1.35;
}

.page-nav .prev { margin-right: auto; }
.page-nav .next { margin-left: auto; text-align: right; }

/* =====================================================
   LANDING PAGE EXTRAS
   ===================================================== */
.hero {
  background: linear-gradient(135deg, var(--bg-sidebar) 0%, #2d3a50 100%);
  border-radius: var(--radius);
  padding: 2.5rem 2.5rem 2rem;
  color: #fff;
  margin-bottom: 2rem;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 180px; height: 180px;
  border-radius: 50%;
  background: rgba(197,5,12,0.18);
  pointer-events: none;
}

.hero-eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f4b8bb;
  margin-bottom: 0.6rem;
}

.hero-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.25;
  margin-bottom: 0.75rem;
  color: #fff;
}

.hero-meta {
  font-size: 0.85rem;
  color: #a0aec0;
  line-height: 1.6;
}

.toc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin: 1.5rem 0;
}

.toc-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text-main);
  font-size: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.toc-card:hover {
  border-color: var(--uw-red);
  box-shadow: 0 0 0 3px rgba(197,5,12,0.07);
  color: var(--text-main);
  text-decoration: none;
}

.toc-card .card-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  min-width: 28px;
  background: var(--code-bg);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--uw-red);
  flex-shrink: 0;
}

.toc-card .card-text {
  font-weight: 500;
  line-height: 1.4;
}

.toc-card .card-sub {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 0.15rem;
}

/* Section dividers in TOC */
.toc-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-light);
  margin: 1.75rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border-light);
}

/* =====================================================
   RESPONSIVE
   ===================================================== */
@media (max-width: 900px) {
  .toc-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 260px; }

  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-md);
  }

  #sidebar-toggle { display: block; }

  #main { margin-left: 0; }

  .content-wrapper { padding: 4.5rem 1.25rem 2rem; }

  .page-title { font-size: 1.5rem; }

  .hero { padding: 1.75rem 1.5rem; }
  .hero-title { font-size: 1.4rem; }

  .page-nav { flex-direction: column; }
  .page-nav a { max-width: 100%; }
}

@media (max-width: 480px) {
  .content-wrapper { padding: 4.5rem 1rem 2rem; }
  pre { font-size: 0.78rem; padding: 0.9rem 1rem; }
}

/* =====================================================
   PRINT
   ===================================================== */
@media print {
  #sidebar, #sidebar-toggle { display: none; }
  #main { margin-left: 0; }
  .content-wrapper { padding: 0; max-width: 100%; }
  .page-nav { display: none; }
  pre { page-break-inside: avoid; }
}