/* ═══════════════════════════════════════════════════════════
   DLO Survey — Main Stylesheet
   Clean, academic, navigable design
   ═══════════════════════════════════════════════════════════ */

/* ─── Reset & Variables ──────────────────────────────────── */
:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --color-bg: #fafafa;
    --color-surface: #ffffff;
    --color-text: #1a1a2e;
    --color-text-secondary: #555;
    --color-text-light: #777;
    --color-primary: #2563eb;
    --color-primary-light: #dbeafe;
    --color-primary-dark: #1d4ed8;
    --color-accent: #7c3aed;
    --color-border: #e5e7eb;
    --color-border-light: #f0f0f0;

    --sidebar-width: 280px;
    --content-max-width: 860px;
    --nav-height: 56px;
    --radius: 8px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --transition: 0.2s ease;
}

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

html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--nav-height) + 20px);
}

body {
    font-family: var(--font-serif);
    font-size: 17px;
    line-height: 1.75;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

/* ─── Top Navigation ─────────────────────────────────────── */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--nav-height);
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--color-border);
    z-index: 1000;
    transition: box-shadow var(--transition);
}

.top-nav.scrolled {
    box-shadow: var(--shadow-sm);
}

.nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-title {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 18px;
    color: var(--color-primary);
    text-decoration: none;
    letter-spacing: -0.3px;
}

.nav-section-select {
    flex: 1;
    max-width: 320px;
    margin: 0 24px;
}

.nav-section-select select {
    width: 100%;
    padding: 6px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    transition: border-color var(--transition);
}

.nav-section-select select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.nav-links {
    display: flex;
    gap: 24px;
}

.nav-links a {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

.nav-links a:hover {
    color: var(--color-primary);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.nav-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--color-text);
    margin: 5px 0;
    transition: var(--transition);
}

/* ─── Hero Section ───────────────────────────────────────── */
.hero {
    margin-top: var(--nav-height);
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #7c3aed 100%);
    color: white;
    padding: 80px 24px 60px;
    text-align: center;
}

.hero-inner {
    max-width: 900px;
    margin: 0 auto;
}

.hero-journal {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    opacity: 0.8;
    margin-bottom: 20px;
}

.hero-title {
    font-family: var(--font-serif);
    font-size: clamp(28px, 4vw, 42px);
    font-weight: 600;
    line-height: 1.25;
    margin-bottom: 24px;
}

.hero-authors {
    font-family: var(--font-sans);
    font-size: 16px;
    font-weight: 400;
    opacity: 0.95;
    margin-bottom: 12px;
}

.hero-affiliations {
    font-family: var(--font-sans);
    font-size: 13px;
    opacity: 0.75;
    line-height: 1.6;
    max-width: 750px;
    margin: 0 auto;
}

.hero.hidden {
    display: none;
}

/* ─── Layout ─────────────────────────────────────────────── */
.layout {
    display: flex;
    max-width: 1400px;
    margin: 0 auto;
    padding-top: 32px;
}

/* Content area needs top margin when hero is hidden */
.hero.hidden + .layout {
    padding-top: calc(var(--nav-height) + 24px);
}

/* ─── Sidebar ────────────────────────────────────────────── */
.sidebar {
    position: sticky;
    top: calc(var(--nav-height) + 16px);
    width: var(--sidebar-width);
    height: calc(100vh - var(--nav-height) - 32px);
    flex-shrink: 0;
    padding: 0 16px;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-inner {
    padding-bottom: 40px;
}

.sidebar-title {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--color-text-light);
    margin-bottom: 16px;
    padding-left: 12px;
}

.toc-list {
    list-style: none;
    padding: 0;
}

.toc-list ul {
    list-style: none;
    padding: 0;
}

.toc-list li {
    margin: 0;
}

.toc-list li a {
    display: block;
    padding: 5px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--color-text-secondary);
    text-decoration: none;
    border-left: 2px solid transparent;
    border-radius: 0 4px 4px 0;
    transition: all var(--transition);
    line-height: 1.5;
}

.toc-list li a:hover {
    color: var(--color-primary);
    background: var(--color-primary-light);
}

.toc-list li a.active {
    color: var(--color-primary);
    border-left-color: var(--color-primary);
    font-weight: 500;
    background: var(--color-primary-light);
}

.toc-section a { font-weight: 500; }
.toc-subsection a { padding-left: 24px; font-size: 12.5px; }
.toc-subsubsection a { padding-left: 36px; font-size: 12px; color: var(--color-text-light); }

/* ─── Main Content ───────────────────────────────────────── */
.content {
    flex: 1;
    max-width: var(--content-max-width);
    padding: 0 32px 80px;
    min-width: 0;
}

/* ─── Abstract ───────────────────────────────────────────── */
.abstract-section {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 32px;
    margin-bottom: 32px;
    box-shadow: var(--shadow-sm);
}

.abstract-text {
    font-size: 16px;
    color: var(--color-text-secondary);
    text-align: justify;
}

/* ─── Section Headings ───────────────────────────────────── */
.section-heading {
    font-family: var(--font-sans);
    color: var(--color-text);
    margin-top: 48px;
    margin-bottom: 20px;
    scroll-margin-top: calc(var(--nav-height) + 20px);
}

h2.section-heading {
    font-size: 28px;
    font-weight: 700;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--color-primary);
    margin-top: 56px;
}

h3.section-heading {
    font-size: 22px;
    font-weight: 600;
    margin-top: 40px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border);
}

h4.section-heading {
    font-size: 18px;
    font-weight: 600;
    margin-top: 32px;
    color: var(--color-text-secondary);
}

h5.section-heading {
    font-size: 16px;
    font-weight: 600;
    margin-top: 24px;
}

.sec-num {
    color: var(--color-primary);
    margin-right: 4px;
}

.section-divider {
    border: none;
    height: 1px;
    background: var(--color-border);
    margin: 48px 0;
}

/* ─── Body text ──────────────────────────────────────────── */
.section-body {
    margin-bottom: 16px;
}

.section-body p {
    margin-bottom: 14px;
    text-align: justify;
    hyphens: auto;
}

.section-body ul, .section-body ol {
    margin: 12px 0 12px 24px;
}

.section-body li {
    margin-bottom: 8px;
}

/* ─── Citations ──────────────────────────────────────────── */
.citation {
    color: var(--color-primary);
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 14px;
    cursor: pointer;
    transition: color var(--transition);
}

.citation:hover {
    color: var(--color-primary-dark);
    text-decoration: underline;
}

.citation.missing {
    color: #e74c3c;
    font-style: italic;
}

/* ─── Figures ────────────────────────────────────────────── */
.survey-figure {
    margin: 20px 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    text-align: center;
}

/* Place figures near the top of sections when possible */
.section-heading + .section-body > .survey-figure:first-child,
.section-body > .survey-figure:first-child {
    margin-top: 8px;
}

.survey-figure img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin-bottom: 12px;
}

.survey-figure figcaption {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--color-text-secondary);
    line-height: 1.6;
    text-align: left;
    padding-top: 12px;
    border-top: 1px solid var(--color-border-light);
}

.figure-placeholder {
    padding: 40px 20px;
    background: var(--color-surface);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text-secondary);
    font-style: italic;
    font-size: 14px;
}

.subfigures {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: center;
    margin-bottom: 12px;
}

.subfigure {
    flex: 1 1 200px;
    max-width: 350px;
    text-align: center;
}

.subfigure img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.subfig-caption {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--color-text-light);
    margin-top: 4px;
}

/* ─── Tables ─────────────────────────────────────────────── */
.table-container {
    margin: 32px 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.table-caption {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--color-text-secondary);
    margin-bottom: 16px;
    line-height: 1.6;
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.survey-table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.5;
}

.survey-table thead {
    background: var(--color-primary);
    color: white;
}

.survey-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    white-space: nowrap;
}

.survey-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border-light);
}

.survey-table tbody tr:nth-child(even) {
    background: #f9fafb;
}

.survey-table tbody tr:hover {
    background: var(--color-primary-light);
}

/* ─── Math ───────────────────────────────────────────────── */
.math.display {
    margin: 20px 0;
    overflow-x: auto;
    padding: 8px 0;
}

.math.inline {
    font-size: 0.95em;
}

/* ─── References ─────────────────────────────────────────── */
.references-section {
    margin-top: 48px;
}

.references-search {
    margin-bottom: 20px;
}

.ref-search-input {
    width: 100%;
    max-width: 400px;
    padding: 10px 16px;
    font-family: var(--font-sans);
    font-size: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    transition: border-color var(--transition);
}

.ref-search-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.references-list {
    counter-reset: ref-counter;
}

.reference-entry {
    counter-increment: ref-counter;
    font-family: var(--font-sans);
    font-size: 13px;
    line-height: 1.7;
    padding: 8px 12px;
    margin-bottom: 4px;
    border-radius: 4px;
    scroll-margin-top: calc(var(--nav-height) + 20px);
    transition: background var(--transition);
}

.reference-entry::before {
    content: counter(ref-counter) ". ";
    font-weight: 600;
    color: var(--color-primary);
}

.reference-entry:target,
.reference-entry:hover {
    background: var(--color-primary-light);
}

.ref-link {
    font-size: 12px;
    font-weight: 500;
    color: var(--color-primary);
    text-decoration: none;
}

.ref-link:hover {
    text-decoration: underline;
}

/* ─── Footnotes ──────────────────────────────────────────── */
.footnote {
    font-family: var(--font-sans);
    font-size: 11px;
    color: var(--color-primary);
    cursor: help;
}

/* ─── Back to Top ────────────────────────────────────────── */
.back-to-top {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--color-primary);
    color: white;
    border: none;
    cursor: pointer;
    font-size: 20px;
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition);
    z-index: 100;
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.back-to-top:hover {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
}

/* ─── Section Cross-ref links ─────────────────────────────── */
.secref, .figref, .tabref, .ref, .eqref {
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 500;
}

.secref:hover, .figref:hover, .tabref:hover, .ref:hover, .eqref:hover {
    text-decoration: underline;
}

/* ─── Sidebar References Link ─────────────────────────────── */
.sidebar-refs {
    margin-top: 20px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border-light);
}

.sidebar-refs-link {
    display: block;
    padding: 8px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-secondary);
    text-decoration: none;
    border-radius: 4px;
    transition: all var(--transition);
}

.sidebar-refs-link:hover {
    color: var(--color-primary);
    background: var(--color-primary-light);
}

/* ─── Page Navigation (Prev/Next) ─────────────────────────── */
.page-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 60px;
    padding-top: 24px;
    border-top: 2px solid var(--color-border);
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    padding: 12px 20px;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    color: var(--color-primary);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    text-decoration: none;
    transition: all var(--transition);
    max-width: 50%;
}

.nav-btn:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.prev-btn {
    margin-right: auto;
}

.next-btn {
    margin-left: auto;
    text-align: right;
}

/* ─── Overview / Sections List (index page) ───────────────── */
.overview-list {
    list-style: none;
    padding: 0;
    margin: 16px 0;
}

.overview-list li {
    margin-bottom: 0;
}

.overview-list li a {
    display: block;
    padding: 14px 20px;
    font-family: var(--font-sans);
    font-size: 15px;
    color: var(--color-text);
    text-decoration: none;
    border-radius: var(--radius);
    border: 1px solid var(--color-border-light);
    margin-bottom: 8px;
    transition: all var(--transition);
}

.overview-list li a:hover {
    background: var(--color-primary-light);
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
}

.overview-list li a strong {
    color: var(--color-primary);
}

/* ─── Responsive Design ──────────────────────────────────── */
@media (max-width: 1100px) {
    .sidebar {
        display: none;
    }

    .layout {
        padding-top: 16px;
    }

    .content {
        max-width: 100%;
        padding: 0 20px 60px;
    }
}

@media (max-width: 768px) {
    .hero {
        padding: 60px 16px 40px;
    }

    .hero-title {
        font-size: 24px;
    }

    .nav-links {
        display: none;
    }

    .nav-links.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: var(--nav-height);
        left: 0;
        right: 0;
        background: white;
        padding: 16px 24px;
        border-bottom: 1px solid var(--color-border);
        box-shadow: var(--shadow-md);
    }

    .nav-section-select {
        max-width: 180px;
        margin: 0 8px;
    }

    .nav-toggle {
        display: block;
    }

    h2.section-heading { font-size: 22px; }
    h3.section-heading { font-size: 18px; }
    h4.section-heading { font-size: 16px; }

    .survey-figure { padding: 12px; }

    .subfigures {
        flex-direction: column;
        align-items: center;
    }

    .subfigure {
        max-width: 100%;
    }

    .table-container { padding: 12px; }

    .abstract-section { padding: 20px; }

    .page-nav {
        flex-direction: column;
    }

    .nav-btn {
        max-width: 100%;
        text-align: center;
        justify-content: center;
    }
}

/* ─── Print Styles ───────────────────────────────────────── */
@media print {
    .top-nav, .sidebar, .back-to-top, .references-search { display: none; }
    .hero { padding: 20px; }
    .content { max-width: 100%; padding: 0; }
    .survey-figure, .table-container { break-inside: avoid; }
}

/* ─── Scrollbar styling ──────────────────────────────────── */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-light);
}
