/* ==========================================================================
   Docs page — two-column layout with a right-side sidebar.
   ========================================================================== */

:root {
  --bg-1:        #fbfaf4;
  --bg-2:        #eef6ee;
  --bg-3:        #e7f1f8;
  --ink:         #1f2a2e;
  --ink-soft:    #4d5a60;
  --muted:       #7d8a90;
  --line:        #d9e2dd;
  --sage:        #8bb89a;
  --sage-deep:   #4f8a64;
  --sky:         #7fb6d6;
  --sky-deep:    #3d7fa8;
  --peach:       #f4b893;
  --peach-deep:  #e0875a;
  --gold:        #e6c875;
  --rose:        #e8a3aa;
  --lilac:       #c5b3e0;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--ink);
  line-height: 1.65;
  background:
    radial-gradient(1200px 800px at 85% -10%, rgba(127,182,214,0.16), transparent 60%),
    radial-gradient(1000px 700px at -10% 110%, rgba(139,184,154,0.20), transparent 55%),
    var(--bg-1);
  min-height: 100vh;
}

.site-nav { max-width: 1280px; }

.docs-layout {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 5rem;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 2.5rem;
  align-items: start;
}

/* ---------- Main content column ---------- */
.docs-main {
  min-width: 0;
  background: rgba(255,255,255,0.78);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 2.5rem 2.8rem;
  box-shadow: 0 8px 28px rgba(31,42,46,0.06);
}

.docs-breadcrumbs {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.6em;
}
.docs-breadcrumbs a { color: var(--sage-deep); text-decoration: none; }
.docs-breadcrumbs a:hover { text-decoration: underline; }

.doc-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin-bottom: 1.6em;
}
.doc-tag {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.25em 0.7em;
  border-radius: 999px;
  background: rgba(127,182,214,0.18);
  color: var(--sky-deep);
}

/* Markdown body styles */
.doc-body h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.1;
  letter-spacing: -0.02em;
  margin: 0 0 0.5em;
  color: var(--ink);
}
.doc-body h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.6rem;
  margin: 2.2em 0 0.6em;
  color: var(--ink);
  letter-spacing: -0.01em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--line);
}
.doc-body h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.25rem;
  margin: 1.8em 0 0.5em;
  color: var(--ink);
}
.doc-body h4 {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin: 1.6em 0 0.4em;
}
.doc-body p { margin: 0 0 1em; color: var(--ink); }
.doc-body ul, .doc-body ol { margin: 0 0 1.2em; padding-left: 1.4em; }
.doc-body li { margin-bottom: 0.35em; }
.doc-body a { color: var(--sky-deep); text-decoration: underline; text-decoration-color: rgba(61,127,168,0.3); text-underline-offset: 2px; }
.doc-body a:hover { text-decoration-color: var(--sky-deep); }
.doc-body strong { color: var(--ink); font-weight: 600; }
.doc-body em { font-style: italic; color: var(--ink-soft); }

.doc-body code {
  font-family: 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: rgba(127,182,214,0.14);
  color: var(--sky-deep);
  padding: 0.12em 0.4em;
  border-radius: 4px;
}
.doc-body pre {
  background: #1f2a2e;
  color: #d9e2dd;
  padding: 1em 1.2em;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  margin: 1.2em 0;
}
.doc-body pre code { background: none; color: inherit; padding: 0; }

.doc-body blockquote {
  margin: 1.4em 0;
  padding: 0.9em 1.2em;
  border-left: 4px solid var(--sage);
  background: rgba(139,184,154,0.10);
  border-radius: 0 8px 8px 0;
  color: var(--ink-soft);
  font-style: italic;
}
.doc-body blockquote p:last-child { margin-bottom: 0; }

.doc-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.4em 0;
  font-size: 0.92rem;
  display: block;
  overflow-x: auto;
}
.doc-body table thead { background: rgba(139,184,154,0.14); }
.doc-body table th, .doc-body table td {
  padding: 0.6em 0.9em;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.doc-body table th {
  font-weight: 600;
  color: var(--ink);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}
.doc-body table tr:hover td { background: rgba(127,182,214,0.06); }

.doc-body hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 2.4em 0;
}

/* Callouts using GitHub-style blockquote prefixes */
.doc-body .callout {
  margin: 1.4em 0;
  padding: 1em 1.2em;
  border-radius: 10px;
  border-left: 4px solid var(--sage);
  background: rgba(139,184,154,0.12);
}
.doc-body .callout.note    { border-left-color: var(--sky); background: rgba(127,182,214,0.10); }
.doc-body .callout.tip     { border-left-color: var(--sage-deep); background: rgba(79,138,100,0.10); }
.doc-body .callout.warn    { border-left-color: var(--peach-deep); background: rgba(224,135,90,0.10); }
.doc-body .callout-title {
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 0.78rem;
  margin-bottom: 0.4em;
  color: var(--ink-soft);
}

.doc-footer-nav {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  margin-top: 3em;
  padding-top: 1.6em;
  border-top: 1px solid var(--line);
}
.doc-footer-nav a {
  flex: 1;
  padding: 0.9em 1.1em;
  border: 1px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink);
  background: rgba(255,255,255,0.6);
  transition: transform .15s, box-shadow .2s, border-color .2s;
}
.doc-footer-nav a:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm, 0 4px 12px rgba(31,42,46,0.08)); border-color: var(--sage); }
.doc-footer-nav a.next  { text-align: right; }
.doc-footer-nav .label  { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); display: block; margin-bottom: 0.2em; }
.doc-footer-nav .title  { font-weight: 600; color: var(--ink); }

/* ---------- Sidebar (RIGHT) ---------- */
.docs-sidebar {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  background: rgba(255,255,255,0.82);
  backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1.2em 1em 1em;
  box-shadow: 0 8px 28px rgba(31,42,46,0.06);
}

.docs-sidebar-title {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.05rem;
  margin: 0 0 0.7em;
  padding: 0 0.4em;
  color: var(--ink);
}

.docs-search {
  position: relative;
  margin-bottom: 0.8em;
}
.docs-search input {
  width: 100%;
  padding: 0.6em 0.8em 0.6em 2em;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  background: rgba(255,255,255,0.9);
  color: var(--ink);
  transition: border-color .15s, box-shadow .2s;
}
.docs-search input:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(139,184,154,0.18);
}
.docs-search::before {
  content: "🔍";
  position: absolute;
  left: 0.6em;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
  opacity: 0.6;
  pointer-events: none;
}

.docs-nav {
  flex: 1;
  overflow-y: auto;
  margin: 0 -0.5em;
  padding: 0 0.5em;
}
.docs-nav .nav-category {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 1em 0 0.4em;
  padding: 0 0.4em;
}
.docs-nav .nav-category:first-child { margin-top: 0.2em; }

.docs-nav a {
  display: block;
  padding: 0.45em 0.7em;
  border-radius: 8px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.9rem;
  line-height: 1.35;
  transition: background .12s, color .12s;
}
.docs-nav a:hover {
  background: rgba(139,184,154,0.14);
  color: var(--ink);
}
.docs-nav a.active {
  background: rgba(79,138,100,0.16);
  color: var(--sage-deep);
  font-weight: 600;
}
.docs-nav .nav-summary {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  margin-top: 0.15em;
  line-height: 1.3;
  font-weight: 400;
}
.docs-nav a.active .nav-summary { color: var(--ink-soft); }

.docs-search-empty {
  padding: 1.2em 0.4em;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  font-style: italic;
}

/* Mobile sidebar toggle (hidden on desktop, shown on mobile via media query). */
.sidebar-toggle {
  display: none;
  width: 100%;
  padding: 0.7em 0.9em;
  border: 1px solid var(--sage);
  border-radius: 10px;
  background: rgba(239,246,239,0.65);
  font: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--sage-deep);
  cursor: pointer;
  text-align: left;
  margin: 0 0 0.6em;
  position: relative;
}
.sidebar-toggle::after {
  content: "▾";
  position: absolute;
  right: 1em;
  top: 50%;
  transform: translateY(-50%);
  transition: transform 0.2s ease;
}
.docs-sidebar.expanded .sidebar-toggle::after { transform: translateY(-50%) rotate(180deg); }

/* Interactive widgets embedded in docs */
.doc-body .doc-widget {
  margin: 2em 0;
  padding: 1.4em 1.6em;
  background: linear-gradient(135deg, rgba(239,246,239,0.7), rgba(231,241,248,0.7));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 4px 16px rgba(31,42,46,0.05);
}
.doc-body .doc-widget .widget-header {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.1rem;
  margin-bottom: 0.2em;
  color: var(--ink);
}
.doc-body .doc-widget .widget-subhead {
  font-size: 0.85rem;
  color: var(--ink-soft);
  margin-bottom: 1em;
}
.doc-body .doc-widget .widget-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1em 1.4em;
  margin-bottom: 1em;
}
.doc-body .doc-widget label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
  margin-bottom: 0.3em;
}
.doc-body .doc-widget input[type="number"] {
  width: 100%;
  padding: 0.5em 0.7em;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,0.85);
  color: var(--ink);
}
.doc-body .doc-widget input[type="number"]:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 3px rgba(139,184,154,0.2);
}
.doc-body .doc-widget input[type="range"] {
  width: 100%;
  accent-color: var(--sage-deep);
  margin-top: 0.6em;
}
.doc-body .doc-widget .widget-range-row {
  display: flex; align-items: baseline; justify-content: space-between;
}
.doc-body .doc-widget .widget-range-row .range-value {
  font-size: 1.2rem; font-weight: 700; color: var(--sage-deep);
}
.doc-body .doc-widget .widget-results {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8em;
  margin-bottom: 1em;
}
.doc-body .doc-widget .result-card {
  background: rgba(255,255,255,0.7);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9em 1em;
}
.doc-body .doc-widget .result-card .label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.2em;
}
.doc-body .doc-widget .result-card .value {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--sage-deep);
  line-height: 1.1;
}
.doc-body .doc-widget .result-card .sub {
  font-size: 0.78rem;
  color: var(--ink-soft);
  margin-top: 0.15em;
}
.doc-body .doc-widget .widget-chart {
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.6em;
  margin-top: 0.4em;
  position: relative;
  height: 260px;
}
.doc-body .doc-widget .widget-chart canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.doc-body .doc-widget .widget-chart svg {
  display: block; width: 100%; height: auto;
}
.doc-body .doc-widget .widget-foot {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.5em;
  text-align: center;
  font-style: italic;
}
@media (max-width: 600px) {
  .doc-body .doc-widget .widget-controls,
  .doc-body .doc-widget .widget-results {
    grid-template-columns: 1fr;
  }
}

/* Editable debts table inside debt-payoff widget */
.doc-body .doc-widget .widget-debts {
  margin-bottom: 1em;
  padding: 0.9em 1em;
  background: rgba(255,255,255,0.55);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.doc-body .doc-widget .debts-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6em;
}
.doc-body .doc-widget .debts-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}
.doc-body .doc-widget .debts-btn {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35em 0.7em;
  margin-left: 0.4em;
  border-radius: 6px;
  border: 1px solid var(--sage);
  background: rgba(239,246,239,0.7);
  color: var(--sage-deep);
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.doc-body .doc-widget .debts-btn:hover { background: rgba(139,184,154,0.25); }
.doc-body .doc-widget .debts-btn:active { transform: translateY(1px); }
.doc-body .doc-widget .debts-table {
  display: flex;
  flex-direction: column;
  gap: 0.35em;
}
.doc-body .doc-widget .debt-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr 0.7fr 0.9fr 28px;
  gap: 0.5em;
  align-items: center;
}
.doc-body .doc-widget .debt-row-header {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 0.3em;
}
.doc-body .doc-widget .debt-row input {
  width: 100%;
  padding: 0.4em 0.55em;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255,255,255,0.95);
  color: var(--ink);
}
.doc-body .doc-widget .debt-row input:focus {
  outline: none;
  border-color: var(--sage);
  box-shadow: 0 0 0 2px rgba(139,184,154,0.18);
}
.doc-body .doc-widget .debt-remove {
  font: inherit;
  font-size: 1rem;
  width: 26px; height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.doc-body .doc-widget .debt-remove:hover {
  color: var(--peach-deep);
  background: rgba(244,184,147,0.18);
  border-color: var(--peach);
}
.doc-body .doc-widget .debts-totals {
  margin-top: 0.7em;
  padding-top: 0.6em;
  border-top: 1px dashed var(--line);
  font-size: 0.85rem;
  color: var(--ink-soft);
  text-align: right;
}
.doc-body .doc-widget .debts-totals strong { color: var(--ink); }
@media (max-width: 600px) {
  .doc-body .doc-widget .debt-row,
  .doc-body .doc-widget .debt-row-header {
    grid-template-columns: 1fr 1fr 1fr 1fr 28px;
    font-size: 0.78rem;
  }
  .doc-body .doc-widget .debt-row input { font-size: 0.82rem; padding: 0.35em 0.45em; }
}

/* Mermaid diagram container */
.doc-body .doc-mermaid {
  margin: 1.8em auto;
  padding: 1.2em;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: center;
  overflow-x: auto;
}
.doc-body .doc-mermaid svg { max-width: 100%; height: auto; }

/* Static Chart.js charts hosted inside a .money-flow container */
.doc-body .money-flow.chart-host {
  padding: 1.2em 1em 1em;
}
.doc-body .money-flow.chart-host > canvas {
  display: block;
  width: 100% !important;
  height: 320px !important;
  max-height: 60vh;
}
@media (max-width: 600px) {
  .doc-body .money-flow.chart-host > canvas { height: 260px !important; }
}

/* Custom money-flow illustration */
.doc-body .money-flow {
  margin: 2em auto;
  padding: 1.6em 1.2em;
  background: linear-gradient(135deg, rgba(239,246,239,0.6), rgba(231,241,248,0.6));
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}
.doc-body .money-flow svg {
  display: block;
  margin: 0 auto;
  max-width: 100%;
  height: auto;
}
.doc-body .money-flow .flow-caption {
  margin-top: 0.8em;
  font-size: 0.82rem;
  color: var(--ink-soft);
  text-align: center;
  font-style: italic;
}

@keyframes money-pulse {
  0%, 100% { opacity: 1; transform: translateX(0); }
  50%      { opacity: 0.55; }
}
@keyframes money-flow-1 {
  0%   { offset-distance: 0%;  opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { offset-distance: 100%; opacity: 0; }
}
.money-flow .coin {
  fill: var(--gold, #e6c875);
  stroke: #b8973f;
  stroke-width: 1.2;
  offset-rotate: 0deg;
  animation: money-flow-1 4s linear infinite;
}
.money-flow .coin.delay-1 { animation-delay: 1.3s; }
.money-flow .coin.delay-2 { animation-delay: 2.6s; }
.money-flow .coin.path-a { offset-path: path('M 90 110 C 180 110, 220 110, 310 110'); }
.money-flow .coin.path-b { offset-path: path('M 410 110 C 500 110, 540 110, 630 110'); }
.docs-loading {
  padding: 4em 1em;
  text-align: center;
  color: var(--muted);
  font-style: italic;
}
.docs-error {
  padding: 2em;
  border-radius: 12px;
  background: rgba(232,163,170,0.16);
  border-left: 4px solid var(--rose);
  color: var(--ink);
}
.docs-error h2 {
  font-family: 'Fraunces', Georgia, serif;
  margin: 0 0 0.4em;
}

/* ---------- Mobile / tablet ---------- */
@media (max-width: 1100px) {
  .docs-layout {
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 1.6em;
  }
}

@media (max-width: 920px) {
  .docs-layout {
    grid-template-columns: 1fr;
    gap: 1em;
    padding: 0.8rem 0.9rem 4rem;
  }
  .docs-sidebar {
    position: static;
    max-height: none;
    padding: 1em 0.9em 0.9em;
  }
  .sidebar-toggle { display: block; }
  /* Collapsed by default on mobile — JS toggles .expanded. */
  .docs-sidebar:not(.expanded) .docs-search,
  .docs-sidebar:not(.expanded) .docs-nav {
    display: none;
  }
  .docs-sidebar.expanded .docs-nav {
    max-height: 60vh;
  }
  .docs-main { padding: 1.4em 1.2em; }
  .doc-body h1 { font-size: clamp(1.7rem, 6vw, 2.2rem); }
  .doc-body h2 { font-size: 1.35rem; margin-top: 1.6em; }
  .doc-body h3 { font-size: 1.1rem; }
  .doc-body table { font-size: 0.85rem; }
  .doc-body table th, .doc-body table td { padding: 0.45em 0.6em; }
  /* Bigger tap targets in sidebar nav. */
  .docs-nav a { padding: 0.65em 0.7em; }
  /* Mermaid scroll on narrow screens. */
  .doc-body .doc-mermaid { padding: 0.6em; }
}

@media (max-width: 480px) {
  .docs-layout { padding: 0.6rem 0.7rem 3rem; }
  .docs-main { padding: 1.1em 0.95em; border-radius: 14px; }
  .doc-body { font-size: 0.97rem; }
  .doc-body h2 { font-size: 1.25rem; padding-bottom: 0.25em; }
  .doc-body pre { padding: 0.8em 0.9em; font-size: 0.78rem; }
  .doc-body blockquote { padding: 0.7em 0.9em; }
  .docs-breadcrumbs { font-size: 0.7rem; }
  /* Stack prev/next nav at the bottom of each doc. */
  .doc-footer-nav { flex-direction: column; }
  .doc-footer-nav a.next { text-align: left; }
}
