body {
  font-family: "Georgia", "Times New Roman", serif;
  line-height: 1.6;
  margin: 1em;
  background-color: #fafafa;
  color: #222;
  overflow-x: auto;
  max-width: 100%;
}

/* Headings */
h1, h2, h3 {
  color: #1C7C54; /* NeuroGreen accent */
  font-weight: bold;
  margin-top: 1.2em;
  margin-bottom: 0.5em;
  text-align: center;
  page-break-inside: avoid;
  break-after: avoid-page;
  break-before: avoid-page;
}

/* Paragraphs */
p {
  margin-bottom: 0.8em;
}

/* Table wrapper */
.table-wrapper {
  overflow-x: auto;
  max-width: 100%;
  margin: 1.5em 0;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  background-color: #ffffff;
  page-break-inside: avoid;
}

/* Base table styling */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9em; /* smaller font for table text */
  border-spacing: 0;
  table-layout: fixed;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  page-break-inside: avoid;
  max-width: 100%;
  overflow-x: auto;
}

/* Header cells */
th {
  color: #000; /* black text */
  font-weight: bold;
  text-align: center;
  padding: 10px;
  background-color: transparent; /* keep transparent for pastel continuity */
  font-size: 1em;
  border: 1px solid #666; /* subtle border around header */
  border-bottom: 2px solid #444; /* slightly thicker bottom for definition */
}

/* Body cells */
td {
  border: 1px solid #aaa;
  padding: 8px;
  vertical-align: top;
  background-color: inherit; /* inherit column pastel */
  word-wrap: break-word;
  overflow-wrap: break-word;
  text-align: left;
  line-height: 1.5;
  font-size: 0.9em; /* smaller font for table text */
}

/* Column pastel background colors (shared by header and body) */
table tr > *:nth-child(1) { background-color: #E8F5EE; }  /* pastel green */
table tr > *:nth-child(2) { background-color: #FFF2EC; }  /* pastel peach */
table tr > *:nth-child(3) { background-color: #ECF3FF; }  /* pastel blue */
table tr > *:nth-child(4) { background-color: #FFFBEA; }  /* pastel yellow */
table tr > *:nth-child(5) { background-color: #FDEBF4; }  /* pastel pink */

/* Alternate row subtle shading */
tr:nth-child(even) td {
  filter: brightness(0.98);
}

/* Remove bullets and adjust lists in tables */
td ul, td ol {
  list-style-type: none;
  padding-left: 0;
  margin: 0;
}

td li {
  margin-bottom: 0.4em;
  text-indent: 0;
}

/* Caption styling */
caption {
  caption-side: top;
  font-weight: bold;
  font-size: 1em;
  color: #003366;
  margin-bottom: 0.3em;
  text-align: center;
}

/* Ensure tables stay within EPUB/HTML bounds */
table, th, td {
  box-sizing: border-box;
  max-width: 100%;
}

/* Blockquotes */
blockquote {
  color: #555;
  margin-left: 1em;
  padding-left: 0.5em;
  border-left: 3px solid #1C7C54;
  font-style: italic;
  background-color: #f9f9f9;
  border-radius: 4px;
}

/* Section headers for clarity */
.section-header {
  background-color: #1C7C54;
  color: white;
  padding: 6px;
  font-weight: bold;
  border-radius: 3px;
}

/* Prevent page overlap in EPUB readers */
@media (prefers-color-scheme: light), (prefers-color-scheme: dark) {
  table { page-break-inside: avoid; }
}

/* ============================= */
/* MULTIPLE-CHOICE FIX SECTION   */
/* ============================= */
/* MCQ styling scoped to .mcq to avoid changing other ordered lists */
.mcq ol {
  list-style-type: upper-alpha;
  margin-left: 1.2em;
  margin-bottom: 0;
  padding-left: 0;
}

.mcq ol li {
  margin-bottom: 0; /* compact lines */
  padding-left: 0.25em;
}

/* ensure nested ordered lists (rare) keep numeric style */
.mcq ol ol {
  list-style-type: decimal;
}

/* Answer paragraph inside MCQ blocks */
.mcq .mcq-answer {
  margin-top: 0.8em; /* a single small space above the answer */
  font-weight: 600;
}
/* ======================================= */
/* RESPONSIVE TOC FIX FOR MOBILE/TABLETS   */
/* ======================================= */

/* Ensure TOC stays visible and moves above content in portrait mode */
@media (max-width: 992px) {
  .toc, .sidebar {
    position: relative !important;
    width: 100% !important;
    max-width: none !important;
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(15px);
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    color: #000;
  }

  .toc-title {
    text-align: center;
    font-weight: 600;
    margin-bottom: 10px;
  }

  .page-content {
    width: 100% !important;
  }
}
/* ================================================== */
/* GLOBAL PASTEL TABLE STYLING (applies to all tables) */
/* ================================================== */

table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.95em;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  overflow: hidden;
  table-layout: fixed;
}

table th,
table td {
  border: 1px solid #ccc;
  padding: 6px;
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.4;
}

/* Header cells */
table thead th {
  text-align: center;
  font-weight: bold;
  color: #000;
  border-bottom: 2px solid #444;
}

/* Column pastel colors (matching atozneurology.sty LaTeX colors) */
table td:nth-child(1),
table th:nth-child(1) {
  background-color: #E9F3FF; /* LightBlue */
}

table td:nth-child(2),
table th:nth-child(2) {
  background-color: #E9FFF0; /* LightGreen */
}

table td:nth-child(3),
table th:nth-child(3) {
  background-color: #FFFBE6; /* LightYellow */
}

table td:nth-child(4),
table th:nth-child(4) {
  background-color: #FFE6EC; /* LightPink */
}

table td:nth-child(5),
table th:nth-child(5) {
  background-color: #F3E9FF; /* LightPurple */
}

/* Alternate row subtle shading */
table tr:nth-child(even) td {
  filter: brightness(0.98);
}

/* Caption styling */
table caption {
  caption-side: top;
  font-weight: bold;
  font-size: 1em;
  color: #1C7C54;
  margin-bottom: 0.5em;
  text-align: center;
}
/* ===================== */
/* REFERENCES COMPACTING */
/* ===================== */

h2[id^="references"],
h3[id^="references"],
h4[id^="references"] {
  text-align: left;
  margin-top: 1.4em;
  margin-bottom: 0.4em;
}

h2[id^="references"] + ul,
h3[id^="references"] + ul,
h4[id^="references"] + ul,
h2[id^="references"] + ol,
h3[id^="references"] + ol,
h4[id^="references"] + ol {
  margin-top: 0.15em;
  margin-bottom: 0.8em;
  padding-left: 1.25em;
}

h2[id^="references"] + ul li,
h3[id^="references"] + ul li,
h4[id^="references"] + ul li,
h2[id^="references"] + ol li,
h3[id^="references"] + ol li,
h4[id^="references"] + ol li {
  margin-bottom: 0.25em;
}

h2[id^="references"] + ul li p,
h3[id^="references"] + ul li p,
h4[id^="references"] + ul li p,
h2[id^="references"] + ol li p,
h3[id^="references"] + ol li p,
h4[id^="references"] + ol li p {
  margin: 0;
}

/* ===================== */
/* MCQ BLOCKS            */
/* ===================== */

.mcq {
  border-left: 4px solid #1C7C54;
  background: #f4f9f6;
  padding: 0.85em 1em;
  margin: 1.2em 0;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.mcq h3 {
  text-align: left;
  margin-top: 0;
}

.mcq ol {
  margin: 0.75em 0 0 1.25em;
  padding: 0;
  list-style-type: upper-alpha;
}

.mcq ol li {
  margin-bottom: 0.35em;
  line-height: 1.5;
}

.mcq-options-list {
  margin: 0.75em 0 0 1.25em;
  padding-left: 1.25em;
  list-style-type: upper-alpha;
}

.mcq-options-list li {
  margin-bottom: 0.35em;
  line-height: 1.5;
}

.mcq p:last-child {
  margin-bottom: 0;
}
/* ========================================================= */
/* MOBILE TOC COLLAPSIBLE TOGGLE (for phones & tablets)      */
/* ========================================================= */

@media (max-width: 992px) {
  /* Hide the default TOC initially */
  nav#TOC, .toc, .sidebar {
    display: none;
    margin-bottom: 10px;
  }

  /* Style for the toggle button */
  #toc-toggle {
    display: block;
    background-color: #1C7C54;
    color: white;
    font-weight: bold;
    text-align: center;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  }

  #toc-toggle:hover {
    background-color: #166A47;
  }

  /* When TOC is visible */
  .toc-open nav#TOC,
  .toc-open .toc,
  .toc-open .sidebar {
    display: block !important;
    background: rgba(255, 255, 255, 0.95);
    padding: 12px;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    animation: fadeIn 0.3s ease-in-out;
  }

  /* Smooth fade-in effect */
  @keyframes fadeIn {
    from { opacity: 0; transform: scaleY(0.9); }
    to { opacity: 1; transform: scaleY(1); }
  }
}

/* JS for TOC Toggle (inserted automatically in HTML builds) */
@media (max-width: 992px) {
  body::after {
    content: "";
    display: none;
  }
}
/* --- Keep TOC visible or collapsible on smaller screens --- */
@media (max-width: 991px) {
  /* Make TOC appear as a floating collapsible sidebar */
  .quarto-sidebar {
    display: block !important;
    position: fixed !important;
    top: 0;
    left: 0;
    height: 100%;
    width: 260px;
    z-index: 1000;
    background-color: #f8f9fa;
    transform: translateX(-260px);
    transition: transform 0.3s ease;
    overflow-y: auto;
    border-right: 1px solid #ddd;
  }

  .quarto-sidebar.open {
    transform: translateX(0);
  }

  /* Add a toggle button */
  .toc-toggle {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 1100;
    background-color: #1C7C54;
    color: white;
    border: none;
    padding: 8px 10px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
  }

  /* Shift content when TOC is open */
  body.toc-open .page-content {
    margin-left: 260px;
    transition: margin-left 0.3s ease;
  }
}
/* ============================== */
/* ICON HEADER TEMPLATE SYSTEM    */
/* ============================== */

.icon-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
}

.icon-header img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  display: inline-block;
}

@media (max-width: 768px) {
  .icon-header img {
    width: 28px;
    height: 28px;
  }
}

/* =================================== */
/* Image + Heading inline layout (CSS only) */
/* =================================== */

/* Float image left with fixed size */
img {
  float: left;
  width: 110px;
  height: 110px;
  object-fit: cover;
  margin-right: 15px;
  margin-bottom: 8px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  border: 2px solid #e0e0e0;
}

/* Make H1/H2 align horizontally with image */
h1, h2 {
  display: inline-block;       /* sits inline with floated image */
  vertical-align: top;         /* aligns with top of image */
  margin-top: 0;               /* removes spacing pushing title down */
  padding-top: 0;
  line-height: 1.1;
  max-width: calc(100% - 140px); /* prevents overlap in narrow screens */
  text-align: left;            /* critical: no more centered wandering */
}

/* Underline stays aligned */
h1 {
  border-bottom: 2px solid #ccc;
  padding-bottom: 4px;
  margin-bottom: 8px;
}

/* Fix EPUB & small screens */
@media (max-width: 600px) {
  img {
    float: none;
    display: block;
    margin: 0 auto 10px auto;
    max-width: 80%;
  }

  h1, h2 {
    display: block;
    max-width: 100%;
    text-align: center;
  }
}

/* PDF fallback */
@media print {
  img {
    border-radius: 0;
    box-shadow: none;
  }
}

/* Protect video thumbnails even if more img rules exist */
.figure img[alt*="Video"],
.figure img[src*="thumbnail"],
.figure img[src*="thumb"],
.callout-note img {
  all: unset !important;
  display: block !important;
  margin: 0 auto !important;
  max-width: 100% !important;
  border: none !important;
  box-shadow: none !important;
}
