/*
 * WHOLISTIC site stylesheet.
 * Typography and palette follow the Ruetten lab site (ruettenlab-site/src/styles/site.css):
 * system sans, near-black on warm off-white, orange accent, no card chrome.
 * Bootstrap 4 is still loaded for its grid; this file overrides its visual defaults.
 */

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    --fg: #1c1c1c;
    --bg: #f7f7f6;
    --muted: color-mix(in srgb, var(--fg) 72%, var(--bg));
    --rule: color-mix(in srgb, var(--fg) 16%, transparent);
    --accent: #c45c12;
    --surface: color-mix(in srgb, var(--fg) 4%, var(--bg));
    --inset: clamp(1rem, 4vw, 4.5rem);
    --measure: 68ch;
    --nav-h: 3.75rem;
    color-scheme: light;
}

html.dark-mode {
    --fg: #f7f7f6;
    --bg: #0b0c0c;
    /* 62% grey read as too dim on near-black; secondary text sits closer to the foreground here. */
    --muted: color-mix(in srgb, var(--fg) 86%, var(--bg));
    --rule: color-mix(in srgb, var(--fg) 24%, transparent);
    --accent: #f58025;
    color-scheme: dark;
}

html,
body {
    margin: 0;
    color: var(--fg);
    background: var(--bg);
    overflow-x: clip;
}

/* Root size grows with the window (16px at <=1170px wide, 20px at >=2500px), so rem-based
   type, spacing and grid minimums scale together on large screens. */
html {
    font-size: clamp(16px, 0.3vw + 12.5px, 20px);
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-top: var(--nav-h);
    font-family: system-ui, sans-serif;
    font-size: 1.0625rem;
    line-height: 1.6;
}

/* Bootstrap sets its own font stack on body and headings; restore the system stack everywhere. */
body,
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
button, input, select, textarea,
.tooltip, .popover {
    font-family: system-ui, sans-serif;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--fg);
    line-height: 1.15;
    text-wrap: balance;
}

h1, .h1 {
    font-size: clamp(2rem, 3.4vw, 3.25rem);
    font-weight: 500;
    letter-spacing: -0.01em;
}

h2, .h2 {
    font-size: clamp(1.4rem, 1.8vw, 1.85rem);
    font-weight: 600;
}

h3, .h3 {
    font-size: 1.2rem;
    font-weight: 650;
}

h4, h5, h6,
.h4, .h5, .h6 {
    font-size: 1rem;
    font-weight: 650;
}

p, li, dd {
    color: inherit;
}

small,
.small,
.text-muted {
    color: var(--muted) !important;
}

hr {
    border: 0;
    border-top: 1px solid var(--rule);
}

/* Links: inherit colour, underline on hover only (lab-site behaviour). */
a,
a:visited {
    color: inherit;
    font-weight: inherit;
    text-decoration: none;
}

a:hover,
a:focus-visible {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 0.14em;
}

/* Links inside running text stay visible without hover. */
.prose a,
.blog-detail .content a,
.caption a {
    color: var(--accent);
}

a:focus-visible,
button:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
}

img,
video {
    max-width: 100%;
    height: auto;
}

/* Figures exported with transparent backgrounds carry black labels and axes; in dark mode they
   would sit black-on-black, so content images get a light plate. Opaque photos are unaffected. */
html.dark-mode .main-content img {
    background: #f7f7f6;
}

html.dark-mode .main-content .logos img {
    background: transparent;
}

/* ---------- Header ---------- */

.site-header {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1030;
    height: var(--nav-h);
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding-inline: var(--inset);
    background: var(--bg);
    border-bottom: 1px solid var(--rule);
}

.site-header .brand {
    font-weight: 650;
    font-size: 1.05rem;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.site-header .brand:hover {
    text-decoration: none;
    color: var(--accent);
}

.site-nav {
    margin-left: auto;
}

.site-nav ul {
    display: flex;
    align-items: center;
    gap: 0 1.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.site-nav a {
    display: inline-block;
    white-space: nowrap;
    padding-block: 0.45rem;
    font-size: 0.95rem;
    line-height: 1.2;
}

.site-nav a[aria-current='page'] {
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 0.3em;
}

.site-nav .external::after {
    content: '\2197';
    margin-left: 0.2em;
    font-size: 0.8em;
}

.theme,
.menu-toggle {
    display: grid;
    place-items: center;
    min-width: 2rem;
    min-height: 2rem;
    padding: 0.25rem;
    font: inherit;
    color: inherit;
    background: transparent;
    border: 1px solid currentColor;
    cursor: pointer;
}

.theme svg,
.menu-toggle svg {
    width: 1rem;
    height: 1rem;
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

html.dark-mode .theme .sun,
html:not(.dark-mode) .theme .moon {
    display: none;
}

.menu-toggle {
    display: none;
}

/* Between the phone menu and a wide desktop the full nav still fits with tighter spacing. */
@media (max-width: 991.98px) {
    .site-nav ul {
        gap: 0 1rem;
    }
}

@media (max-width: 759.98px) {
    .menu-toggle {
        display: grid;
        margin-left: auto;
    }

    .site-nav {
        position: fixed;
        inset: var(--nav-h) 0 auto 0;
        display: none;
        padding: 0.5rem var(--inset) 1.25rem;
        background: var(--bg);
        border-bottom: 1px solid var(--rule);
    }

    .site-header.is-open .site-nav {
        display: block;
    }

    .site-nav ul {
        flex-direction: column;
        align-items: flex-start;
    }

    .site-nav li.theme-item {
        margin-top: 0.5rem;
    }
}

/* ---------- Main + footer ---------- */

.main-content {
    flex: 1 0 auto;
    width: 100%;
    max-width: none !important;
    padding: clamp(1.5rem, 4vh, 3rem) var(--inset) clamp(2rem, 6vh, 4rem) !important;
    margin: 0 !important;
}

/* Templates nest Bootstrap `.container` inside main; neutralise its max-width and side padding. */
.main-content .container,
.main-content .container-fluid {
    max-width: none !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

.site-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem 2rem;
    padding: 1.5rem var(--inset) calc(1.5rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--rule);
    font-size: 0.9rem;
    color: var(--muted);
}

.site-footer p {
    margin: 0;
}

.site-footer ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.site-footer a:hover {
    color: var(--fg);
}

/* ---------- Shared content patterns ---------- */

.page-title {
    margin: 0 0 clamp(1.5rem, 4vh, 2.5rem);
}

.lede {
    max-width: var(--measure);
    font-size: 1.15em;
    color: var(--muted);
}

.prose p,
.prose li {
    max-width: var(--measure);
}

.caption,
figcaption {
    font-size: 0.95rem;
    line-height: 1.45;
    color: var(--muted);
}

.caption strong,
figcaption strong {
    color: var(--fg);
    font-weight: 650;
}

.eyebrow {
    margin: 0 0 0.35rem;
    font-size: 0.75rem;
    font-weight: 650;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}

.rule-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.rule-list > li {
    padding-block: 1.25rem;
    border-top: 1px solid var(--rule);
}

.rule-list > li:last-child {
    border-bottom: 1px solid var(--rule);
}

.link-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.5rem;
    margin: 0.35rem 0 0;
    padding: 0;
    list-style: none;
    font-size: 0.9rem;
}

.link-row a {
    color: var(--accent);
}

.link-row a::after {
    content: ' \2192';
}

/* Files open or download rather than navigate: a down arrow instead of the right arrow. */
.link-row a[href$='.pdf']::after {
    content: ' \2193';
}

/* Legacy colour helper used by several templates. */
.dynamic-color {
    color: var(--fg);
}

/* ---------- Table of contents (article pages) ---------- */

#toc,
.toc {
    position: sticky;
    top: calc(var(--nav-h) + 1.5rem);
    max-height: calc(100vh - var(--nav-h) - 3rem);
    overflow-y: auto;
    padding: 0 0 0 1.25rem;
    background: transparent;
    color: var(--muted);
    border: 0;
}

#toc ul,
.toc ul {
    list-style: none;
    margin: 0;
    padding-left: 0;
}

#toc a,
#toc .nav-link,
.toc a {
    display: block;
    padding: 0.2rem 0;
    font-size: 0.9rem;
    font-weight: normal;
    line-height: 1.35;
    color: var(--muted);
    text-decoration: none;
}

#toc a:hover,
#toc .nav-link:hover,
.toc a:hover {
    color: var(--fg);
    text-decoration: none;
}

#toc a.active,
#toc .nav-link.active {
    color: var(--fg);
    font-weight: 650;
}

.content-divider,
.small_content-divider {
    border-left: 1px solid var(--rule);
    min-height: 0;
}

.blog-detail h1,
.blog-detail h2,
.blog-detail h3,
.blog-detail h4 {
    margin-top: 2.5rem;
    margin-bottom: 0.6rem;
}

.blog-detail h1:first-child,
.blog-detail h2:first-child {
    margin-top: 0;
}

/* ---------- Module prev/next ---------- */

.nav-container {
    position: sticky;
    top: calc(var(--nav-h) + 1.5rem);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.pre-module-nav,
.next-module-nav {
    padding: 0;
    margin: 0;
    background: transparent;
    border: 0;
}

.pre-module-nav a,
.next-module-nav a {
    display: block;
    font-weight: 600;
    color: var(--fg);
}

/* ---------- Bootstrap chrome, flattened ---------- */

.card {
    width: auto;
    height: auto;
    color: var(--fg);
    background: transparent;
    border: 0;
    border-radius: 0;
}

.card-body {
    padding: 0.75rem 0 0;
}

.card-footer,
.card-header {
    background: transparent;
    border: 0;
    padding: 0;
}

.card-img-top {
    border-radius: 0;
}

.list-group-item {
    background: transparent;
    color: var(--fg);
    border: 0;
    border-top: 1px solid var(--rule);
    border-radius: 0 !important;
    padding-inline: 0;
    font-weight: 600;
    font-size: 1rem;
}

.list-group-item:last-child {
    border-bottom: 1px solid var(--rule);
}

.btn {
    border-radius: 0;
}

/* ---------- Video helpers kept from the previous stylesheet ---------- */

.video-container {
    max-width: 100%;
    margin: 0;
    text-align: left;
}

.video-container video {
    width: 100%;
    height: auto;
    border-radius: 0;
}

.embed-responsive {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    overflow: hidden;
}

.embed-responsive::before {
    content: '';
    display: block;
    padding-top: 56.25%;
}

.embed-responsive .embed-responsive-item,
.embed-responsive iframe,
.embed-responsive video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* ---------- MathJax / citations ---------- */

.citation,
.citation-link {
    color: var(--accent);
}

.reference-item {
    margin-bottom: 0.6rem;
    line-height: 1.5;
    font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
    * {
        scroll-behavior: auto !important;
    }
}
