/* =========================================================
   Soma3D — Textbook only
   Purpose:
   - isolate Textbook styling from the giant style.css
   - fix outer scrollbar / cut-off reliably
   - keep navbar visible; only TOC + reader content scroll
   ========================================================= */

/* --- Page shell: header + main, no page scroll --- */
html, body { height: 100%; }

body.textbook-page{
  height: 100vh;
  overflow: hidden;         /* IMPORTANT: remove far-right page scrollbar */
  display: flex;
  flex-direction: column;   /* menu-container above main */
  margin: 0;                /* just in case */
}

/* menu stays in normal flow; sticky handled by .site-header in style.css */
body.textbook-page #menu-container{
  flex: 0 0 auto;
}

/* main fills remaining height under the navbar */
body.textbook-page main#textbook-page{
  flex: 1 1 auto;
  min-height: 0;            /* CRITICAL for nested scrolling */
  display: flex;
  flex-direction: column;
  overflow: hidden;         /* main must NOT scroll */
}

/* Region header (the “Textbook” title block) takes natural height */
body.textbook-page main#textbook-page .region-header{
  flex: 0 0 auto;
  margin: 22px 0 14px 0;    /* calmer than huge vertical spacing */
}

/* The two-column layout fills the rest */
body.textbook-page .textbook-layout{
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 18px;
  align-items: stretch;
  overflow: hidden;         /* layout itself must NOT scroll */
  margin-bottom: 0;         /* prevent accidental extra height */
}

/* --- Sidebar (left) --- */
body.textbook-page .textbook-sidebar{
  flex: 0 0 320px;
  min-height: 0;
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 12px;
  overflow: hidden;

  /* OVERRIDE the sticky/calc-height rules from style.css */
  position: relative !important;
  top: auto !important;
  height: auto !important;
  align-self: stretch !important;

  display: flex;
  flex-direction: column;
}

body.textbook-page .textbook-sidebar-header{
  padding: 14px 14px 12px;
  border-bottom: 1px solid rgba(0,0,0,0.10);
}

body.textbook-page .textbook-sidebar-title{
  font-weight: 700;
  margin-bottom: 10px;
}

body.textbook-page .textbook-search{
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid rgba(0,0,0,0.16);
  background: #ffffff;
  font-family: inherit;
}

body.textbook-page #textbook-toc{
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;         /* TOC can scroll */
  padding: 12px 14px;
}

/* --- Reader (right) --- */
body.textbook-page .textbook-reader{
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  background: #ffffff;
  border: 1px solid rgba(0,0,0,0.10);
  border-radius: 12px;
  overflow: hidden;

  /* OVERRIDE the sticky/calc-height rules from style.css */
  position: relative !important;
  top: auto !important;
  height: auto !important;
  align-self: stretch !important;

  display: flex;
  flex-direction: column;
}

body.textbook-page #textbook-reader-bar{
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(0,0,0,0.10);
  background: #ffffff;
}

body.textbook-page .textbook-reader-controls{
  display: inline-flex;
  gap: 10px;
  align-items: center;
}

body.textbook-page .textbook-nav-button,
body.textbook-page .textbook-contents-button{
  border: 1px solid rgba(0,0,0,0.18);
  background: #ffffff;
  border-radius: 999px;
  padding: 8px 12px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
}

body.textbook-page .textbook-nav-button[disabled]{
  opacity: 0.55;
  cursor: not-allowed;
}

body.textbook-page #textbook-reader-status{
  font-size: 14px;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* This is the ONLY required scrollbar on the right side */
body.textbook-page #textbook-reader-content{
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px;
}

/* --- TOC rows (tree) --- */
body.textbook-page .tb-row{
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 10px 10px;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
  color: rgba(0,0,0,0.86);

  display: flex;
  align-items: center;
  gap: 10px;

  box-sizing: border-box;
}

body.textbook-page .tb-row:hover{
  background: rgba(0,0,0,0.05);
}

body.textbook-page .tb-row:disabled{
  opacity: 0.5;
  cursor: not-allowed;
}

body.textbook-page .tb-label{
  flex: 1;
  min-width: 0;
}

body.textbook-page .tb-region-row{
  font-weight: 800;
}

body.textbook-page .tb-section-row{
  margin-top: 4px;
  font-weight: 700;
  padding-left: 24px !important;
}

body.textbook-page .tb-sub-row{
  font-weight: 600;
  padding-left: 44px !important;
  opacity: 0.90;
}

/* Region collapse */
body.textbook-page .tb-region .tb-sections{
  display: none;
  margin-top: 6px;
  padding-bottom: 8px;
}
body.textbook-page .tb-region.open .tb-sections{
  display: block;
}

/* Section collapse (Option B: only active section shows subsections) */
body.textbook-page .tb-subs{ display: none; }
body.textbook-page .tb-section.open .tb-subs{ display: block; }

/* Chevrons */
body.textbook-page .tb-chevron{
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-left: 6px solid currentColor;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  opacity: 0.65;
  transform: rotate(0deg);
  transition: transform 140ms ease, opacity 140ms ease;
}

body.textbook-page .tb-region.open > .tb-region-row .tb-chevron{
  transform: rotate(90deg);
  opacity: 0.80;
}
body.textbook-page .tb-section.open > .tb-section-row .tb-chevron{
  transform: rotate(90deg);
  opacity: 0.80;
}

/* Active highlight (filled, calm) */
body.textbook-page .tb-row[data-active="1"]{
  box-shadow: none !important;
  background: rgba(0, 119, 204, 0.10) !important;
}

/* --- Content style (Option A: calm documentation) --- */
body.textbook-page #textbook-reader-content{
  line-height: 1.65;
}

body.textbook-page #textbook-reader-content h1{
  font-size: 1.7rem;
  letter-spacing: .2px;
  margin: 8px 0 12px;
}

body.textbook-page #textbook-reader-content h2{
  font-size: 1.2rem;
  margin: 26px 0 10px;
  padding-left: 12px;
  border-left: 4px solid rgba(64,156,255,.85);
}

body.textbook-page #textbook-reader-content p{
  margin: 10px 0;
}

body.textbook-page #textbook-reader-content ul{
  margin: 8px 0 12px 20px;
}

body.textbook-page #textbook-reader-content iframe{
  border-radius: 14px;
  margin: 14px 0 6px;
}

/* --- Mobile fallback: stack (drawer later) --- */
@media (max-width: 900px){
  body.textbook-page .textbook-layout{
    flex-direction: column;
  }

  /* On mobile, allow the whole main area to scroll if you prefer.
     For now keep inner scroll behavior consistent. */
  body.textbook-page #textbook-reader-status{
    display: none;
  }
}
/* ===== Textbook: prevent shrink-to-fit when no chapter loaded ===== */

body.textbook-page main#textbook-page{
  width: 100%;
}

body.textbook-page .textbook-layout{
  width: 100%;
  display: flex !important;   /* in case some legacy rule makes it inline-flex */
  justify-content: stretch;
}

body.textbook-page .textbook-reader{
  flex: 1 1 0;                /* force it to actually take remaining space */
  min-width: 0;
}

/* Space between textbook sections */
.textbook-article section {
  margin-top: 3.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

/* First section should not have a divider */
.textbook-article section:first-of-type {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

/* TEMP: hide 3D placeholders until thorax models exist */
.viewer-placeholder {
  display: none;
}

/* Textbook: hide 3D viewer placeholders until models exist */
.textbook-article .viewer-placeholder {
  display: none !important;
}


/* Allow headings near the end to scroll to the top when jumped-to */
.textbook-article::after {
  content: "";
  display: block;
  height: 65vh; /* tune: 40–80vh feels good */
}
