/* SWMM 5 Manuals — layout and reading styles on top of Pico CSS */

:root {
  --topbar-h: 3.5rem;
  --sidebar-w: 19rem;
  --measure: 46rem;
  --accent: #0b6e99;
  --accent-soft: rgba(11, 110, 153, 0.1);
  --hl: #ffe58a;
  --hl-text: #222;
  --figure-bg: #ffffff;
  --pico-font-size: 100%;
  --pico-primary: var(--accent);
  --pico-primary-background: var(--accent);
  --pico-primary-hover: #095a7d;
  --pico-primary-underline: rgba(11, 110, 153, 0.5);
}
[data-theme="dark"] {
  --accent: #5cb8e0;
  --accent-soft: rgba(92, 184, 224, 0.14);
  --hl: #8a6d00;
  --hl-text: #fff;
  --figure-bg: #f4f4f2;
  --pico-primary: var(--accent);
  --pico-primary-background: #2a86ad;
  --pico-primary-hover: #7cc8ea;
  --pico-primary-underline: rgba(92, 184, 224, 0.5);
}

html, body { height: 100%; }
body { margin: 0; }
svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.skip-link { position: absolute; left: -999px; top: 0.5rem; z-index: 2000; padding: 0.5rem 1rem; background: var(--pico-background-color); }
.skip-link:focus { left: 0.5rem; }

/* ---------- Top bar ---------- */
.topbar {
  color: var(--pico-color);
  position: fixed; inset: 0 0 auto 0; height: var(--topbar-h); z-index: 1000;
  display: flex; align-items: center; gap: 0.75rem; padding: 0 1rem;
  background: var(--pico-background-color);
  border-bottom: 1px solid var(--pico-muted-border-color);
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; color: var(--pico-color); text-decoration: none; white-space: nowrap; }
.brand-mark { color: var(--accent); fill: var(--accent-soft); width: 1.5rem; height: 1.5rem; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.5rem; height: 2.5rem; padding: 0; margin: 0; flex: none;
  background: transparent; border: 1px solid transparent; border-radius: 0.5rem; color: inherit; box-shadow: none;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu-btn { display: none; }
[data-theme="dark"] .icon-moon, :root:not([data-theme="dark"]) .icon-sun { display: none; }

/* ---------- Search ---------- */
.search { position: relative; flex: 1; max-width: 34rem; margin-left: auto; }
.search-icon { position: absolute; left: 0.75rem; top: 50%; transform: translateY(-50%); color: var(--pico-muted-color); pointer-events: none; }
.search input[type="search"] {
  margin: 0; height: 2.4rem; padding: 0 2.5rem 0 2.5rem; font-size: 0.95rem;
  border-radius: 0.6rem; background-image: none;
}
.search-kbd { position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%); font-size: 0.75rem; padding: 0.1rem 0.45rem; pointer-events: none; opacity: 0.7; }
.search input:focus ~ .search-kbd, .search input:not(:placeholder-shown) ~ .search-kbd { display: none; }
.search-results {
  position: absolute; top: calc(100% + 0.4rem); left: 0; right: 0; max-height: min(70vh, 34rem); overflow-y: auto;
  background: var(--pico-background-color); border: 1px solid var(--pico-muted-border-color);
  border-radius: 0.6rem; box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18); padding: 0.35rem;
}
.search-status { padding: 0.6rem 0.75rem; font-size: 0.85rem; color: var(--pico-muted-color); }
.search-result { display: block; padding: 0.55rem 0.75rem; border-radius: 0.45rem; cursor: pointer; text-decoration: none; color: var(--pico-color); }
.search-result[aria-selected="true"], .search-result:hover { background: var(--accent-soft); }
.search-result .r-path { font-size: 0.72rem; color: var(--pico-muted-color); text-transform: uppercase; letter-spacing: 0.03em; }
.search-result .r-title { font-weight: 600; font-size: 0.92rem; }
.search-result .r-snippet { font-size: 0.82rem; color: var(--pico-muted-color); line-height: 1.4; margin-top: 0.15rem; }
mark { background: var(--hl); color: var(--hl-text); padding: 0 0.1em; border-radius: 2px; }

/* ---------- Layout ---------- */
.layout { padding-top: var(--topbar-h); }
.sidebar {
  color: var(--pico-color);
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: var(--sidebar-w);
  overflow-y: auto; overscroll-behavior: contain; padding: 1rem 0.75rem 3rem;
  border-right: 1px solid var(--pico-muted-border-color); background: var(--pico-background-color);
  font-size: 0.875rem; z-index: 900;
}
main { margin-left: var(--sidebar-w); min-height: calc(100vh - var(--topbar-h)); }
.progress { position: fixed; top: var(--topbar-h); left: var(--sidebar-w); right: 0; height: 2px; background: var(--accent); transform-origin: 0 50%; transform: scaleX(0); z-index: 950; }
.scrim { position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(0, 0, 0, 0.45); z-index: 850; }

/* ---------- Sidebar TOC ---------- */
/* Pico lays out nav lists horizontally; the sidebar needs plain vertical lists */
.sidebar, .sidebar ul, .sidebar li { display: block; }
.sidebar ul { margin: 0; padding: 0; align-items: initial; }
.sidebar li { padding: 0; }
.sidebar ul:first-of-type, .sidebar ul:last-of-type { margin-inline: 0; }
.sidebar a { margin: 0; }
nav.breadcrumb, nav.pager { margin-inline: 0; }
.toc, .toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { list-style: none; margin: 0; padding: 0; }
.toc .manual { margin-bottom: 0.25rem; }
.toc .manual-toggle {
  display: flex; align-items: center; gap: 0.4rem; width: 100%; margin: 0; padding: 0.5rem 0.6rem;
  background: none; border: 0; border-radius: 0.45rem; color: inherit; box-shadow: none;
  font-size: 0.875rem; font-weight: 650; text-align: left; line-height: 1.3;
}
.toc .manual-toggle:hover { background: var(--accent-soft); }
.toc .manual-toggle:focus-visible { outline: 2px solid var(--accent); }
.toc .chev { width: 0.9rem; height: 0.9rem; flex: none; transition: transform 0.15s ease; color: var(--pico-muted-color); }
.toc .manual-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.toc .chapters { padding: 0.1rem 0 0.4rem 0.65rem; margin-left: 0.9rem; border-left: 1px solid var(--pico-muted-border-color); }
.toc .chapters[hidden] { display: none; }
.toc a {
  display: block; padding: 0.3rem 0.6rem; border-radius: 0.4rem; text-decoration: none;
  color: var(--pico-muted-color); line-height: 1.35;
}
.toc a:hover { color: var(--pico-color); background: var(--accent-soft); }
.toc a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.toc .sections { margin: 0.1rem 0 0.35rem 0.6rem; }
.toc .sections a { font-size: 0.8rem; padding: 0.2rem 0.6rem; }
.toc .sections a.l3 { padding-left: 1.4rem; }
.toc .sections a.active { color: var(--accent); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); border-radius: 0 0.4rem 0.4rem 0; }

/* ---------- Content ---------- */
.content { background: none; box-shadow: none; border-radius: 0; margin-bottom: 0;
  max-width: var(--measure); margin: 0 auto; padding: 2rem 2rem 4rem; line-height: 1.65; outline: none; }
.content > :first-child { margin-top: 0; }
.content nav.breadcrumb { justify-content: flex-start; }
.breadcrumb { font-size: 0.8rem; color: var(--pico-muted-color); margin-bottom: 1.25rem; display: flex; flex-wrap: wrap; gap: 0.35rem; align-items: center; }
.breadcrumb a { color: var(--pico-muted-color); }
.content h1 { font-size: 1.9rem; line-height: 1.25; margin: 2.2rem 0 1rem; }
.content h2 { font-size: 1.45rem; line-height: 1.3; margin: 2rem 0 0.75rem; padding-top: 0.5rem; border-top: 1px solid var(--pico-muted-border-color); }
.content h1 + h2 { border-top: 0; }
.content h3 { font-size: 1.15rem; margin: 1.6rem 0 0.6rem; }
.content h4, .content h5, .content h6 { font-size: 1rem; margin: 1.3rem 0 0.5rem; }
.content :is(h1, h2, h3, h4) { scroll-margin-top: calc(var(--topbar-h) + 1rem); position: relative; }
.heading-anchor { margin-left: 0.4rem; opacity: 0; text-decoration: none; color: var(--pico-muted-color); font-weight: 400; }
.content :is(h1, h2, h3, h4):hover .heading-anchor, .heading-anchor:focus { opacity: 1; }
.content p, .content li { font-size: 1rem; }
.content img { max-width: 100%; height: auto; }
.content figure, .content p > img:only-child { display: block; margin: 1.5rem auto; text-align: center; }
.content figure img, .content p > img { background: var(--figure-bg); border-radius: 4px; cursor: zoom-in; }
.content figcaption { font-size: 0.85rem; color: var(--pico-muted-color); margin-top: 0.5rem; }
.table-wrap { overflow-x: auto; margin: 1.25rem 0; border: 1px solid var(--pico-muted-border-color); border-radius: 0.5rem; }
.table-wrap table { margin: 0; font-size: 0.875rem; }
.table-wrap th, .table-wrap td { vertical-align: top; }
.table-wrap td img { cursor: zoom-in; background: var(--figure-bg); }
.content pre { padding: 1rem; border-radius: 0.5rem; font-size: 0.85rem; }
.content blockquote { margin: 1.25rem 0; }
.math.display { display: block; overflow-x: auto; overflow-y: hidden; }
mjx-container[display="true"] { margin: 0.6em 0 !important; }
p.equation { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
p.equation .math.display { flex: 1; min-width: 0; }
p.equation .eq-num { flex: none; color: var(--pico-muted-color); font-size: 0.9rem; }
.math-error { color: #c0392b; font-family: var(--pico-font-family-monospace); font-size: 0.85em; }

.pager { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--pico-muted-border-color); }
.pager a { display: block; margin: 0; padding: 0.85rem 1rem; border: 1px solid var(--pico-muted-border-color); border-radius: 0.6rem; text-decoration: none; }
.pager a:hover { border-color: var(--accent); background: var(--accent-soft); }
.pager small { display: block; color: var(--pico-muted-color); font-size: 0.75rem; }
.pager .next { text-align: right; grid-column: 2; }

.content.loading { opacity: 0.55; transition: opacity 0.2s; }
.error-box { border: 1px solid #c0392b; border-radius: 0.5rem; padding: 1rem 1.25rem; }

/* ---------- Home ---------- */
.home h1 { margin-top: 0.5rem; }
.home .lede { font-size: 1.1rem; color: var(--pico-muted-color); max-width: 38rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 1rem; margin: 2rem 0; }
.card { display: flex; flex-direction: column; padding: 1.1rem 1.2rem; border: 1px solid var(--pico-muted-border-color); border-radius: 0.75rem; text-decoration: none; color: var(--pico-color); transition: border-color 0.15s, transform 0.15s; }
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card h3 { font-size: 1.05rem; margin: 0 0 0.4rem; color: var(--accent); }
.card p { font-size: 0.9rem; color: var(--pico-muted-color); margin: 0 0 0.75rem; flex: 1; }
.card small { font-size: 0.75rem; color: var(--pico-muted-color); }
.home .tips { font-size: 0.9rem; color: var(--pico-muted-color); }

.to-top { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 800; background: var(--pico-background-color); border: 1px solid var(--pico-muted-border-color); box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12); border-radius: 50%; }

/* ---------- Lightbox ---------- */
#lightbox[open] { flex-direction: column; gap: 0.75rem; padding: 2rem 1rem; background-color: rgba(0, 0, 0, 0.82); backdrop-filter: blur(2px); }
#lightbox img { display: block; max-width: 92vw; max-height: 82vh; object-fit: contain; background: var(--figure-bg); border-radius: 4px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4); }
.lightbox-caption { margin: 0; max-width: 60rem; text-align: center; font-size: 0.9rem; color: #e8e8e8; }
.lightbox-close { position: absolute; top: 1rem; right: 1rem; color: #fff; }
.lightbox-close:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .menu-btn { display: inline-flex; }
  .sidebar { transform: translateX(-100%); transition: transform 0.2s ease; width: min(85vw, var(--sidebar-w)); box-shadow: 4px 0 18px rgba(0, 0, 0, 0.15); }
  body.nav-open .sidebar { transform: none; }
  main { margin-left: 0; }
  .progress { left: 0; }
  .toc a, .toc .manual-toggle { min-height: 2.5rem; display: flex; align-items: center; }
}
@media (max-width: 600px) {
  .topbar { gap: 0.4rem; padding: 0 0.5rem; }
  .brand span { display: none; }
  .content { padding: 1.25rem 1rem 3rem; }
  .content h1 { font-size: 1.5rem; }
  .content h2 { font-size: 1.25rem; }
  .pager { grid-template-columns: 1fr; }
  .pager .next { grid-column: 1; }
  .search-results { position: fixed; top: calc(var(--topbar-h) + 0.25rem); left: 0.5rem; right: 0.5rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* ---------- Print ---------- */
@media print {
  .topbar, .sidebar, .scrim, .to-top, .pager, .progress, .heading-anchor, .breadcrumb { display: none !important; }
  .layout { padding: 0; }
  main { margin: 0; }
  .content { max-width: none; padding: 0; }
  .content h2 { break-after: avoid; }
  .content img, .table-wrap { break-inside: avoid; }
}
