/**
 * STUDENT HANDOUT STYLESHEET
 * ===========================
 * Navy (#1B2A4A) / Gold (#C4963C) — MA branding
 * Typography: Source Serif 4 (body), Source Sans 3 (UI/headers)
 * Extracted from handout-prototype.html and adapted for Pandoc template
 *
 * Author: Andrew Bland, MD, MBA, MS
 * Created: 2026-03-29
 */

:root {
  --navy: #1B2A4A;
  --navy-light: #2C3E6B;
  --navy-muted: #3D5289;
  --gold: #C4963C;
  --gold-light: #E8C777;
  --gold-pale: #FDF6E3;
  --pearl-bg: #EFF6F0;
  --pearl-border: #4A9B5E;
  --pearl-accent: #2D7A3F;
  --warning-bg: #FFF3E0;
  --warning-border: #E65100;
  --warning-accent: #BF360C;
  --keypoint-bg: #E8EAF6;
  --keypoint-border: #3949AB;
  --keypoint-accent: #283593;
  --body-bg: #FAFAF8;
  --text: #2C2C2C;
  --text-light: #5A5A5A;
  --text-lighter: #888;
  --sidebar-bg: #F3F2EF;
  --border: #E0DDD5;
  --link: #2C5F8A;
  --link-hover: #1B4A6E;
  --table-header: var(--navy);
  --table-stripe: #F5F5F2;
  --max-content: 780px;
  --sidebar-width: 260px;
}

/* ─── DARK MODE VARIABLES ─── */
[data-theme="dark"] {
  --navy: #8BADD4;
  --navy-light: #6B9AC4;
  --navy-muted: #7FAED8;
  --gold: #E8C777;
  --gold-light: #C4963C;
  --gold-pale: #2A2520;
  --pearl-bg: #1A2E1F;
  --pearl-border: #4A9B5E;
  --pearl-accent: #6FCF84;
  --warning-bg: #2E1E0E;
  --warning-border: #E65100;
  --warning-accent: #FF8A50;
  --keypoint-bg: #1A1C2E;
  --keypoint-border: #5C6BC0;
  --keypoint-accent: #9FA8DA;
  --body-bg: #121212;
  --text: #E0E0E0;
  --text-light: #B0B0B0;
  --text-lighter: #808080;
  --sidebar-bg: #1E1E1E;
  --border: #333333;
  --link: #7DB8E0;
  --link-hover: #A8D4F0;
  --table-header: #1B2A4A;
  --table-stripe: #1A1A1A;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  font-size: 17px;
  scroll-behavior: smooth;
  scroll-padding-top: 2rem;
}

body {
  font-family: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  color: var(--text);
  background-color: var(--body-bg);
  line-height: 1.72;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ─── TOP BAR ─── */
.top-bar {
  background: var(--navy);
  color: white;
  padding: 0.6rem 2rem;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.top-bar a { color: var(--gold-light); text-decoration: none; }
.top-bar a:hover { color: var(--gold); }

/* ─── HEADER ─── */
.header {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
  color: white;
  padding: 2.8rem 2rem 2.4rem;
  position: relative;
  overflow: hidden;
}
.header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--gold), var(--gold-light), var(--gold));
}
.header-inner {
  max-width: calc(var(--max-content) + var(--sidebar-width) + 4rem);
  margin: 0 auto;
}
.header-category {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--gold-light);
  margin-bottom: 0.8rem;
}
.header h1 {
  font-size: 2.1rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.6rem;
  max-width: var(--max-content);
}
.header-subtitle {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1rem;
  color: rgba(255,255,255,0.75);
  font-weight: 300;
  max-width: var(--max-content);
  line-height: 1.5;
}
.header-meta {
  margin-top: 1.4rem;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.82rem;
  color: rgba(255,255,255,0.6);
  display: flex;
  gap: 1.8rem;
  flex-wrap: wrap;
}
.header-meta span { display: flex; align-items: center; gap: 0.4rem; }
.header-meta svg { width: 14px; height: 14px; opacity: 0.7; }

/* ─── LAYOUT ─── */
.layout {
  max-width: calc(var(--max-content) + var(--sidebar-width) + 4rem);
  margin: 0 auto;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  gap: 3rem;
  padding: 2.5rem 2rem 4rem;
  align-items: start;
}

/* ─── SIDEBAR / TOC ─── */
.sidebar {
  position: sticky;
  top: 1.5rem;
  max-height: calc(100vh - 3rem);
  overflow-y: auto;
}
.toc {
  background: var(--sidebar-bg);
  border-radius: 8px;
  padding: 1.4rem 1.2rem;
  border: 1px solid var(--border);
}
.toc-title {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-lighter);
  margin-bottom: 0.9rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}
.toc ol {
  list-style: none;
  counter-reset: toc;
}
.toc li {
  counter-increment: toc;
  margin-bottom: 0.15rem;
}
.toc > ol > li > a {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--navy);
  text-decoration: none;
  display: block;
  padding: 0.35rem 0.5rem;
  border-radius: 4px;
  transition: all 0.15s;
  line-height: 1.35;
}
.toc > ol > li > a:hover {
  background: rgba(27, 42, 74, 0.06);
  color: var(--navy-light);
}
.toc > ol > li > a.active {
  background: rgba(27, 42, 74, 0.08);
  color: var(--navy);
}
.toc ol ol {
  margin-left: 0.9rem;
  margin-top: 0.1rem;
  border-left: 1.5px solid var(--border);
  padding-left: 0.7rem;
}
.toc ol ol a {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.79rem;
  font-weight: 400;
  color: var(--text-light);
  text-decoration: none;
  display: block;
  padding: 0.25rem 0.4rem;
  border-radius: 3px;
  transition: all 0.15s;
  line-height: 1.35;
}
.toc ol ol a:hover {
  color: var(--navy);
  background: rgba(27, 42, 74, 0.04);
}

.toc-download {
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.toc-download a {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1rem;
  border-radius: 5px;
  text-decoration: none;
  transition: background 0.15s;
}
.toc-download a:hover { background: var(--navy-light); }
.toc-download svg { width: 14px; height: 14px; }

/* ─── MAIN CONTENT ─── */
.content {
  max-width: var(--max-content);
  min-width: 0;
}

/* Hide the top-level H1 — title is already in the header block */
.content > section.level1 > h1:first-child,
.content > h1:first-child {
  display: none;
}

.content h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--navy);
  margin-top: 2.8rem;
  margin-bottom: 0.8rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--gold);
  line-height: 1.25;
}
.content h2:first-child { margin-top: 0; }

.content h3 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--navy-muted);
  margin-top: 2rem;
  margin-bottom: 0.5rem;
  letter-spacing: 0.01em;
}

.content h4 {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--navy-muted);
  margin-top: 1.5rem;
  margin-bottom: 0.4rem;
}

.content p {
  margin-bottom: 1rem;
}

.content a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: rgba(44, 95, 138, 0.3);
  text-underline-offset: 2px;
  transition: all 0.15s;
}
.content a:hover {
  color: var(--link-hover);
  text-decoration-color: var(--link-hover);
}

.content strong { font-weight: 700; color: var(--text); }
.content em { font-style: italic; }

.content ul, .content ol {
  margin-bottom: 1rem;
  padding-left: 1.3rem;
}
.content li {
  margin-bottom: 0.35rem;
}
.content li::marker {
  color: var(--navy-muted);
}

/* Nested lists */
.content li > ul,
.content li > ol {
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

/* Code blocks — ASCII diagrams in handouts */
.content pre {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.2rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--text);
}

.content code {
  font-family: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
  font-size: 0.88em;
}

.content p > code,
.content li > code {
  background: var(--sidebar-bg);
  padding: 0.12rem 0.4rem;
  border-radius: 3px;
  border: 1px solid var(--border);
  font-size: 0.85em;
}

/* ─── CALLOUT BOXES ─── */
.callout {
  border-radius: 6px;
  padding: 1.1rem 1.3rem;
  margin: 1.5rem 0;
  border-left: 4px solid;
  position: relative;
}
.callout-header {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.callout-header svg { width: 16px; height: 16px; flex-shrink: 0; }
.callout p { font-size: 0.95rem; margin-bottom: 0.4rem; line-height: 1.6; }
.callout p:last-child { margin-bottom: 0; }

.callout-pearl {
  background: var(--pearl-bg);
  border-color: var(--pearl-border);
}
.callout-pearl .callout-header { color: var(--pearl-accent); }

.callout-warning {
  background: var(--warning-bg);
  border-color: var(--warning-border);
}
.callout-warning .callout-header { color: var(--warning-accent); }

.callout-key {
  background: var(--keypoint-bg);
  border-color: var(--keypoint-border);
}
.callout-key .callout-header { color: var(--keypoint-accent); }

/* ─── TABLES ─── */
.content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 1.5rem 0;
  font-size: 0.9rem;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.content thead th {
  background: var(--table-header);
  color: white;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.7rem 1rem;
  text-align: left;
}
.content tbody td {
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.content tbody tr:nth-child(even) { background: var(--table-stripe); }
.content tbody tr:last-child td { border-bottom: none; }
.content tbody tr:hover { background: var(--gold-pale); }

/* ─── INLINE REFERENCES ─── */
.ref {
  color: var(--link);
  font-size: 0.78em;
  vertical-align: super;
  text-decoration: none;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 600;
  cursor: pointer;
}
.ref:hover { color: var(--navy); }

/* ─── REFERENCES SECTION ─── */
.references {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--navy);
}
.references h2 {
  border-bottom: none;
  margin-top: 0;
  font-size: 1.2rem;
}
.ref-list {
  list-style: none;
  padding: 0;
  counter-reset: refs;
}
.ref-list li {
  counter-increment: refs;
  font-size: 0.85rem;
  line-height: 1.55;
  padding: 0.5rem 0 0.5rem 2.4rem;
  position: relative;
  border-bottom: 1px solid rgba(0,0,0,0.04);
  font-family: 'Source Sans 3', sans-serif;
  color: var(--text-light);
}
.ref-list li::before {
  content: counter(refs) ".";
  position: absolute;
  left: 0;
  font-weight: 700;
  color: var(--navy-muted);
  width: 2rem;
  text-align: right;
}
.ref-list li:last-child { border-bottom: none; }
.ref-list .ref-authors { font-weight: 500; color: var(--text); }
.ref-list .ref-title { font-style: italic; }
.ref-list .ref-journal { font-weight: 400; }
.ref-list .pubmed-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: white;
  background: var(--navy-muted);
  padding: 0.15rem 0.55rem;
  border-radius: 3px;
  text-decoration: none;
  margin-left: 0.4rem;
  vertical-align: middle;
  transition: background 0.15s;
}
.ref-list .pubmed-link:hover { background: var(--navy); }

/* ─── HORIZONTAL RULES ─── */
.content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2rem 0;
}

/* ─── FOOTER ─── */
.footer {
  background: var(--navy);
  color: rgba(255,255,255,0.55);
  padding: 1.8rem 2rem;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.78rem;
  text-align: center;
  line-height: 1.6;
}
.footer strong { color: rgba(255,255,255,0.8); font-weight: 600; }
.footer a { color: rgba(255,255,255,0.7); text-decoration: none; }
.footer a:hover { color: white; }

/* ─── EDUCATION DISCLAIMER BAR ─── */
.edu-disclaimer {
  background: var(--gold-pale);
  border-bottom: 1px solid rgba(196, 150, 60, 0.3);
  padding: 0.45rem 2rem;
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--navy-muted);
  text-align: center;
  letter-spacing: 0.04em;
}
.edu-disclaimer svg {
  width: 12px; height: 12px;
  vertical-align: -1px;
  margin-right: 0.3rem;
  opacity: 0.7;
}

/* ─── WATERMARK ─── */
.watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-35deg);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 5rem;
  font-weight: 800;
  color: rgba(27, 42, 74, 0.03);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 0;
  user-select: none;
}

/* ─── PRINT STYLES ─── */
@media print {
  .top-bar, .sidebar, .footer, .toc-download, .edu-disclaimer { display: none; }
  .layout { grid-template-columns: 1fr; padding: 0; }
  .header { padding: 1.5rem; }
  .header::after { display: none; }
  .content { max-width: 100%; }
  .callout { break-inside: avoid; }
  body { font-size: 11pt; }

  .watermark {
    position: fixed;
    color: rgba(27, 42, 74, 0.06);
    font-size: 4.5rem;
  }

  @page {
    margin: 0.75in;
  }

  .print-footer {
    display: block !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    text-align: center;
    font-family: 'Source Sans 3', sans-serif;
    font-size: 0.65rem;
    color: var(--navy-muted);
    padding: 0.5rem;
    border-top: 1px solid var(--border);
  }
}

/* ─── MOBILE ─── */
@media (max-width: 900px) {
  html { font-size: 16px; }
  .layout {
    grid-template-columns: 1fr;
    padding: 1.5rem 1.2rem 3rem;
    gap: 0;
  }
  .sidebar {
    position: relative;
    top: 0;
    max-height: none;
    margin-bottom: 2rem;
  }
  .header { padding: 2rem 1.2rem; }
  .header h1 { font-size: 1.6rem; }
  .header-meta { gap: 1rem; }
}

/* ─── THEME TOGGLE BUTTON ─── */
.theme-toggle {
  position: fixed;
  top: 0.6rem;
  right: 1rem;
  z-index: 1000;
  background: var(--navy);
  color: white;
  border: 2px solid var(--gold);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.theme-toggle:hover {
  transform: scale(1.1);
  background: var(--navy-light);
}

/* ─── DARK MODE — COMPONENT OVERRIDES ─── */
[data-theme="dark"] .header {
  background: linear-gradient(135deg, #0D1520 0%, #1B2A4A 100%);
}
[data-theme="dark"] .header-category {
  color: var(--gold);
}
[data-theme="dark"] .top-bar {
  background: #0A0F18;
}
[data-theme="dark"] .footer {
  background: #0A0F18;
}
[data-theme="dark"] .edu-disclaimer {
  background: #1E1A12;
  border-color: rgba(196, 150, 60, 0.2);
  color: var(--gold);
}
[data-theme="dark"] .watermark {
  color: rgba(139, 173, 212, 0.04);
}
[data-theme="dark"] .callout-pearl {
  background: var(--pearl-bg);
}
[data-theme="dark"] .callout-warning {
  background: var(--warning-bg);
}
[data-theme="dark"] .callout-key {
  background: var(--keypoint-bg);
}
[data-theme="dark"] .toc {
  background: var(--sidebar-bg);
  border-color: var(--border);
}
[data-theme="dark"] .toc > ol > li > a {
  color: var(--navy);
}
[data-theme="dark"] .toc ol ol a {
  color: var(--text-light);
}
[data-theme="dark"] .toc-download a {
  background: #1B2A4A;
}
[data-theme="dark"] .content tbody tr:hover {
  background: #2A2520;
}
[data-theme="dark"] .ref-list li {
  border-bottom-color: rgba(255,255,255,0.05);
}
[data-theme="dark"] .content pre {
  background: #1A1A1A;
  border-color: var(--border);
}
[data-theme="dark"] .content p > code,
[data-theme="dark"] .content li > code {
  background: #1A1A1A;
  border-color: var(--border);
}

/* ─── SCROLL SPY ACTIVE STATE ─── */
.toc a.active {
  background: rgba(196, 150, 60, 0.1) !important;
  color: var(--navy) !important;
  font-weight: 700 !important;
}
