/*==============================================================================
 * plan-content.css — Page-level reader layout for imported/Idea plan content.
 * -----------------------------------------------------------------------------
 * Scoped ONLY to `.ipc-*` classes plus the two dedicated purchase/detail
 * readers (#ideaDetailRoot / #myPurchasesRoot). Never trusts imported HTML/CSS
 * as site-wide styling.
 *
 * Layout model:
 *   .ipc-read (reader shell) -> [left TOC sidebar] [reading column] [rail]
 *   - Wide desktop (>=1280px): page shell up to min(100% - 40px, 1560px),
 *     sticky left TOC, affiliate rail hidden until real data exists.
 *   - Tablet/mobile (<1280px) and all homepage modals: compact sticky
 *     "विषय-सूची / Contents" disclosure button (no long pill rows).
 *
 * Palette (tokens win, brand hexes fall back):
 *   navy #12213A · gold #A9812E · teal #209B98 · warm cream #FAF9F5.
 *============================================================================*/

/* ---- 1. Containment (applies to every plan-content frame) ---------------- */
.ipc-frame, .ipc-frame * { box-sizing: border-box; }
.ipc-frame { min-width: 0; max-width: 100%; }

.ipc-frame img, .ipc-frame svg, .ipc-frame video, .ipc-frame canvas,
.ipc-frame picture, .ipc-frame object, .ipc-frame embed {
  max-width: 100%; height: auto; display: inline-block; vertical-align: middle;
}
.ipc-frame figure { max-width: 100%; margin: 14px auto; }
.ipc-frame figure img { display: block; margin: 0 auto; }
.ipc-frame figcaption { color: var(--muted, #5c6273); font-size: 0.85em; margin-top: 6px; text-align: center; }

.ipc-frame p, .ipc-frame li, .ipc-frame dt, .ipc-frame dd, .ipc-frame td,
.ipc-frame th, .ipc-frame h1, .ipc-frame h2, .ipc-frame h3, .ipc-frame h4,
.ipc-frame h5, .ipc-frame h6, .ipc-frame blockquote, .ipc-frame pre,
.ipc-frame code, .ipc-frame caption { overflow-wrap: break-word; }
.ipc-frame a { word-break: break-word; }
.ipc-frame pre, .ipc-frame code { max-width: 100%; overflow-x: auto; }

/* Tables: the JS wrapper `.ipc-table-wrap` is the independently scrollable box */
.ipc-table-wrap { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ipc-table-wrap table { max-width: 100%; }
.ipc-frame table { max-width: 100%; }

/* ---- 2. Wide page shell (only the two purchase readers) ----------------- */
/* Overrides the shared `.idea-detail { max-width:1080px }` narrow shell so the
   business plan gets a real page layout with the TOC beside it, not a thin
   centered column with empty margins on both sides. */
#ideaDetailRoot.idea-detail,
#myPurchasesRoot.idea-detail {
  max-width: min(100% - 40px, 1560px);
  margin-inline: auto;
}

/* ---- 3. Imported reading surface (light document on the dark pages) ------ */
.ipc-frame.ipc-imported {
  background: var(--paper, #faf9f5);
  color: var(--navy, #12213a);
  border: 1px solid rgba(18, 33, 58, 0.12);
  border-radius: clamp(12px, 1.2vw, 18px);
  padding: clamp(18px, 2.6vw, 34px);
  box-shadow: 0 1px 2px rgba(16, 29, 51, 0.06), 0 6px 18px rgba(16, 29, 51, 0.1);
}
.ipc-frame.ipc-imported h1, .ipc-frame.ipc-imported h2,
.ipc-frame.ipc-imported h3, .ipc-frame.ipc-imported h4,
.ipc-frame.ipc-imported h5, .ipc-frame.ipc-imported h6 {
  color: var(--navy, #12213a); line-height: 1.32; margin: 1.05em 0 0.5em;
}
.ipc-frame.ipc-imported .ipc-sec-heading {
  color: var(--navy, #12213a); font-size: 1.12rem; font-weight: 700;
  line-height: 1.35; margin: 1.1em 0 0.55em;
}
.ipc-frame.ipc-imported h2 { font-size: 1.35rem; border-bottom: 1px solid rgba(18, 33, 58, 0.16); padding-bottom: 4px; }
.ipc-frame.ipc-imported h1 { font-size: 1.6rem; }
.ipc-frame.ipc-imported a {
  color: var(--teal, #209b98); font-weight: 600; text-decoration: underline;
  text-decoration-thickness: 1px; text-underline-offset: 3px;
}
.ipc-frame.ipc-imported a:hover { color: var(--navy, #12213a); }
.ipc-frame.ipc-imported strong { color: var(--navy, #12213a); font-weight: 700; }
.ipc-frame.ipc-imported em { color: inherit; }
.ipc-frame.ipc-imported table { width: 100%; max-width: 100%; border-collapse: collapse; font-size: 0.92em; }
.ipc-frame.ipc-imported th {
  background: rgba(169, 129, 46, 0.12); color: var(--navy, #12213a);
  border: 1px solid rgba(18, 33, 58, 0.24); padding: 8px 12px;
  text-align: left; font-weight: 700;
}
.ipc-frame.ipc-imported td {
  border: 1px solid rgba(18, 33, 58, 0.24); padding: 8px 12px; vertical-align: top;
}
.ipc-frame.ipc-imported tbody tr:nth-child(even) td { background: rgba(18, 33, 58, 0.035); }
.ipc-frame.ipc-imported blockquote {
  border-left: 3px solid var(--gold, #a9812e); margin: 14px 0; padding: 10px 14px;
  background: rgba(18, 33, 58, 0.03); color: var(--navy, #12213a);
}
.ipc-frame.ipc-imported ul, .ipc-frame.ipc-imported ol { padding-left: 1.4em; margin: 8px 0; }
.ipc-frame.ipc-imported li { margin-bottom: 4px; }
.ipc-frame.ipc-imported hr { border: 0; border-top: 1px solid rgba(18, 33, 58, 0.2); margin: 18px 0; }
.ipc-frame.ipc-imported .ipc-original-toc { display: none; }

/* ---- 4. Reader shell (page-level, TOC outside the business-plan HTML) ---- */
.ipc-read {
  display: grid;
  grid-template-columns: minmax(220px, 250px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
  min-width: 0;
}
.ipc-read > .ipc-toc { grid-column: 1; }
.ipc-read > .ipc-read-main { grid-column: 2; min-width: 0; }

/* Text stays comfortably readable even in the wider shell: cap the reading
   surface and centre it inside the reading column. */
.ipc-read .ipc-frame.ipc-imported {
  max-width: min(100%, 900px);
  margin-inline: auto;
}

/* ---- 5. Desktop: left sticky TOC (default state) ----------------------- */
.ipc-toc {
  position: sticky;
  top: var(--ipc-toc-top, 62px);
  max-height: calc(100vh - var(--ipc-toc-top, 62px) - 18px);
  overflow-y: auto;
  overscroll-behavior: contain;
  align-self: start;
  background: var(--paper, #faf9f5);
  border: 1px solid rgba(18, 33, 58, 0.16);
  border-radius: 14px;
  padding: 16px 18px;
}
/* On the desktop sidebar the disclosure button is never shown; the panel is
   simply the always-visible list. (The button/panel collapsed states below
   are applied only by the narrow-width / modal rules further down.) */
.ipc-toc-btn { display: none; }
.ipc-toc-title {
  font-size: 0.72rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--gold, #a9812e); margin: 0 0 10px;
  display: flex; align-items: center; gap: 6px;
}
.ipc-toc-title::before { content: ""; width: 10px; height: 10px; border-radius: 3px; background: var(--gold, #a9812e); flex: none; }
.ipc-toc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.ipc-link {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 7px 10px; border-radius: 9px;
  color: var(--navy, #12213a); text-decoration: none;
  font-size: 0.85rem; line-height: 1.35;
}
.ipc-link:hover { background: rgba(18, 33, 58, 0.06); }
.ipc-link:focus-visible { outline: 2px solid var(--gold, #a9812e); outline-offset: 1px; border-radius: 9px; }
.ipc-link .ipc-link-num {
  flex: none; min-width: 22px; color: var(--teal, #209b98);
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.78rem;
}
.ipc-link.active {
  background: linear-gradient(90deg, rgba(169, 129, 46, 0.16), rgba(169, 129, 46, 0.04));
  box-shadow: inset 3px 0 0 var(--gold, #a9812e);
}

/* ---- 6. Right rail (affiliate / relevant links) — data-gated -------------
   No Idea/Plan -> product association exists in the data model today
   (shop_products has no idea/plan linkage), so the rail ships hidden: the
   reading column simply uses the full width. When a real association lands,
   populate an <aside class="ipc-aff"> and add .has-affiliate to .ipc-read —
   the third column, sticky behaviour and compact card styling are already
   defined here so no fake cards and no second catalogue are ever produced. */
.ipc-aff { display: none; }
.ipc-read.has-affiliate,
.ipc-read.ipc-has-affiliate {
  grid-template-columns: minmax(220px, 250px) minmax(0, 1fr) minmax(250px, 300px);
}
.ipc-aff:not([hidden]) {
  display: block;
  position: sticky;
  top: var(--ipc-toc-top, 62px);
  max-height: calc(100vh - var(--ipc-toc-top, 62px) - 18px);
  overflow-y: auto;
  overscroll-behavior: contain;
  align-self: start;
}
.ipc-aff-title {
  font-size: 0.72rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--gold, #a9812e); margin: 0 0 12px;
}
.ipc-aff-card {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--paper, #faf9f5);
  border: 1px solid rgba(18, 33, 58, 0.14);
  border-radius: 12px; padding: 10px 12px;
}
.ipc-aff-card img {
  width: 56px; height: 56px; object-fit: contain; flex: none;
  background: var(--surface-2, #f3f1ea); border-radius: 8px;
}
.ipc-aff-card .ipc-aff-info { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.ipc-aff-card .ipc-aff-name { font-weight: 700; font-size: 0.85rem; color: var(--navy, #12213a); line-height: 1.3; }
.ipc-aff-card a {
  color: var(--teal, #209b98); font-weight: 600; font-size: 0.8rem;
  text-decoration: none;
}
.ipc-aff-card a:hover, .ipc-aff-card a:focus-visible { text-decoration: underline; }

/* ---- 7. Disclosure control: homepage modals (dropdown at every width) ---- */
/* The tight modal card never fits a 3-column page layout, so modals always
   use the "विषय-सूची / Contents" disclosure control regardless of viewport. */
.ipc-in-modal .ipc-read { display: block; }
.ipc-in-modal .ipc-toc {
  position: sticky;
  top: 8px;
  z-index: 19;
  display: block;
  max-height: none;
  margin: 0 0 12px;
  background: transparent;
  border: 0;
  padding: 0;
}
.ipc-in-modal .ipc-toc-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; padding: 12px 16px; font-weight: 800; text-align: left; cursor: pointer;
  background: var(--paper, #faf9f5); color: var(--navy, #12213a);
  border: 1px solid rgba(18, 33, 58, 0.2); border-radius: 12px;
  font-size: 0.92rem;
}
.ipc-in-modal .ipc-toc-btn .ipc-toc-btn-label { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1 1 auto; }
.ipc-in-modal .ipc-toc-btn .ipc-toc-btn-label svg { width: 18px; height: 18px; flex: none; }
.ipc-in-modal .ipc-toc-btn .ipc-toc-btn-text {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.ipc-in-modal .ipc-toc-btn .ipc-toc-chev { width: 16px; height: 16px; flex: none; transition: transform 0.18s ease; }
.ipc-in-modal .ipc-toc-btn[aria-expanded="true"] .ipc-toc-chev { transform: rotate(180deg); }
.ipc-in-modal .ipc-toc-btn:focus-visible { outline: 2px solid var(--gold, #a9812e); outline-offset: 2px; }

.ipc-in-modal .ipc-toc-panel.ipc-open {
  max-height: min(60vh, 440px); overflow-y: auto;
  background: var(--paper, #faf9f5);
  border: 1px solid rgba(18, 33, 58, 0.16); border-radius: 12px;
  padding: 10px 12px; margin: 6px 0 0;
  box-shadow: 0 6px 18px rgba(16, 29, 51, 0.12);
}
.ipc-in-modal .ipc-toc-panel:not(.ipc-open) {
  max-height: 0; overflow: hidden; padding: 0; border: 0; margin: 0;
  visibility: hidden;
}
.ipc-in-modal .ipc-frame.ipc-imported { margin: 0; max-width: 100%; }

/* ---- 8. Tablet / mobile: dropdown replaces the sidebar and pills -------- */
@media (max-width: 1279px) {
  .ipc-read { display: block; }
  .ipc-toc {
    position: sticky;
    top: var(--ipc-drop-top, 54px);
    z-index: 19;
    display: block;
    max-height: none;
    margin: 0 0 14px;
    background: transparent;
    border: 0;
    padding: 0;
  }
  .ipc-toc-btn {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    width: 100%; padding: 12px 16px; font-weight: 800; text-align: left; cursor: pointer;
    background: var(--paper, #faf9f5); color: var(--navy, #12213a);
    border: 1px solid rgba(18, 33, 58, 0.2); border-radius: 12px;
    font-size: 0.92rem;
  }
  .ipc-toc-btn .ipc-toc-btn-label { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1 1 auto; }
  .ipc-toc-btn .ipc-toc-btn-label svg { width: 18px; height: 18px; flex: none; }
  .ipc-toc-btn .ipc-toc-btn-text {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
  }
  .ipc-toc-btn .ipc-toc-chev { width: 16px; height: 16px; flex: none; transition: transform 0.18s ease; }
  .ipc-toc-btn[aria-expanded="true"] .ipc-toc-chev { transform: rotate(180deg); }
  .ipc-toc-btn:focus-visible { outline: 2px solid var(--gold, #a9812e); outline-offset: 2px; }

  .ipc-toc-panel.ipc-open {
    max-height: min(60vh, 440px); overflow-y: auto;
    background: var(--paper, #faf9f5);
    border: 1px solid rgba(18, 33, 58, 0.16); border-radius: 12px;
    padding: 10px 12px; margin: 6px 0 0;
    box-shadow: 0 6px 18px rgba(16, 29, 51, 0.12);
  }
  .ipc-toc-panel:not(.ipc-open) {
    max-height: 0; overflow: hidden; padding: 0; border: 0; margin: 0;
    visibility: hidden;
  }
  .ipc-toc-list { gap: 0; }
  .ipc-link {
    padding: 10px 12px; border-radius: 10px; font-size: 0.9rem;
  }
  .ipc-link .ipc-link-num { min-width: 20px; }
  .ipc-read .ipc-frame.ipc-imported { margin: 0; max-width: 100%; }
}

/* ---- 9. Scroll offset: headings must clear the sticky header + nav ------ */
.ipc-frame.ipc-imported h1, .ipc-frame.ipc-imported h2,
.ipc-frame.ipc-imported h3, .ipc-frame.ipc-imported h4,
.ipc-frame.ipc-imported h5, .ipc-frame.ipc-imported h6,
.ipc-frame.ipc-imported .ipc-sec-heading {
  scroll-margin-top: var(--ipc-scroll-margin, 84px);
}
.ipc-in-modal .ipc-frame.ipc-imported h2,
.ipc-in-modal .ipc-frame.ipc-imported h3,
.ipc-in-modal .ipc-frame.ipc-imported .ipc-sec-heading { scroll-margin-top: 16px; }
@media (max-width: 1279px) {
  .ipc-frame.ipc-imported h2, .ipc-frame.ipc-imported h3,
  .ipc-frame.ipc-imported .ipc-sec-heading { scroll-margin-top: 124px; }
  .ipc-in-modal .ipc-frame.ipc-imported h2,
  .ipc-in-modal .ipc-frame.ipc-imported .ipc-sec-heading { scroll-margin-top: 74px; }
}

@media (prefers-reduced-motion: reduce) {
  .ipc-toc-btn .ipc-toc-chev { transition: none; }
  .ipc-toc, .ipc-link { scroll-behavior: auto; }
}