/* ═══════════════════════════════════════════════════════════════════════
   ISCC SYSTEM MANUAL - DOCUMENTATION VIEWER STYLES
   ═══════════════════════════════════════════════════════════════════════ */

/* ── CSS VARIABLES & THEMES ──────────────────────────────────────────── */
:root {
    /* Spacing System */
    --spacing-xs: 0.25rem;    /* 4px */
    --spacing-sm: 0.5rem;     /* 8px */
    --spacing-md: 1rem;       /* 16px */
    --spacing-lg: 1.5rem;     /* 24px */
    --spacing-xl: 2rem;       /* 32px */
    --spacing-2xl: 2.5rem;    /* 40px */

    /* Document Spacing */
    --doc-font-size: 16px;
    --doc-line-height: 1.7;
    --doc-para-spacing: 1.4em;

    /* Font Families */
    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-serif: 'Merriweather', Georgia, serif;
    --font-source-serif: 'Noto Serif', Georgia, serif;
    --font-mono: 'JetBrains Mono', monospace;
    --font-doc: var(--font-serif);  /* Default to serif for documents */

    /* Print Theme Variables (Classic default) */
    --print-bg: #ffffff;
    --print-text: #1a1a1a;
    --print-heading: #0c0a09;
    --print-accent: #4f46e5;
    --print-border: #e7e5e4;
    --print-code-bg: #f8f8f7;
    --print-code-text: #1c1917;
    --print-code-border: #e7e5e4;
    --print-code-accent: #4f46e5;
    --print-blockquote-bg: #fafaf9;
    --print-blockquote-border: #78716c;

    /* Light Theme (Default) - Softened for better visual comfort */
    --bg-app: #fafbfc;
    --bg-header: #ffffff;
    --bg-sidebar: #fafbfc;
    --bg-sidebar-hover: #f0f2f5;
    --bg-content: #ffffff;
    --bg-card: #ffffff;
    --bg-code: #1e1e2e;

    --text-primary: #2d2d2d;
    --text-secondary: #7a828c;
    --text-muted: #a0a8b3;
    --text-heading: #1a1a1a;
    --text-code: #cdd6f4;

    --border-color: #e8ebf0;
    --border-light: #f0f3f6;

    --primary: #5b52e8;
    --primary-hover: #4f46e5;
    --primary-subtle: rgba(91, 82, 232, 0.12);
    --primary-light: rgba(91, 82, 232, 0.06);

    --success: #22c99e;
    --warning: #ffb020;
    --danger: #f87272;
    --info: #4dabf7;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 12px 20px rgba(0, 0, 0, 0.08);

    --header-height: 64px;
    --sidebar-width: 280px;
    --transition: 0.2s ease;
}

/* Dark Theme - Softened for better visual comfort */
body.theme-dark {
    --bg-app: #141414;
    --bg-header: #1c1c1e;
    --bg-sidebar: #1c1c1e;
    --bg-sidebar-hover: #2a2a2e;
    --bg-content: #1c1c1e;
    --bg-card: #242427;
    --bg-code: #0d0d0f;

    --text-primary: #e4e4e7;
    --text-secondary: #a1a1aa;
    --text-muted: #71717a;
    --text-heading: #fafafa;
    --text-code: #e4e4e7;

    --border-color: #2e2e33;
    --border-light: #25252a;

    --primary: #8b88f8;
    --primary-hover: #7a76f7;
    --primary-subtle: rgba(139, 136, 248, 0.18);
    --primary-light: rgba(139, 136, 248, 0.1);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 20px rgba(0, 0, 0, 0.45);
}

/* ── BASE STYLES ───────────────────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background var(--transition), color var(--transition);
}

a {
    color: var(--primary);
    text-decoration: none;
    transition: color var(--transition);
}

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

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

/* ── HEADER ─────────────────────────────────────────────────────────── */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 1000;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    /* Creates containing block for absolute children (scroll progress) */
    isolation: isolate;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}

.brand-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 0 1 auto;
}

.brand-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-heading);
    line-height: 1.2;
}

.brand-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.2;
}

.brand-section {
    font-size: 0.7rem;
    color: var(--primary);
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 0 auto;
    min-width: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.auditor-badge {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--primary-subtle);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

.control-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition);
    background: transparent;
}

.control-btn:hover {
    background: var(--primary-subtle);
    color: var(--primary);
    transform: translateY(-1px);
}

.logout-btn {
    border: 1px solid var(--border-color);
}

/* ── APP CONTAINER ───────────────────────────────────────────────────── */
.app-container {
    display: flex;
    margin-top: var(--header-height);
    height: calc(100vh - var(--header-height));
}

/* ── SIDEBAR ───────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 900;
    transition: transform var(--transition);
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-toggle {
    display: none;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

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

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

/* ── NAVIGATION SECTIONS ─────────────────────────────────────────────── */
.nav-section {
    margin-bottom: 4px;
}

.nav-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    cursor: pointer;
    user-select: none;
    transition: background var(--transition);
}

.nav-section-header:hover {
    background: var(--bg-sidebar-hover);
}

.nav-section-header > i:first-child {
    width: 20px;
    text-align: center;
    color: var(--primary);
}

.nav-section-header > span {
    flex: 1;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.section-chevron {
    font-size: 0.75rem;
    color: var(--text-muted);
    transition: transform var(--transition);
}

.nav-section.collapsed .section-chevron {
    transform: rotate(-90deg);
}

.nav-section-content {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.nav-section.collapsed .nav-section-content {
    max-height: 0;
}

/* ── NAVIGATION ITEMS ────────────────────────────────────────────────── */
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px 10px 52px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: all var(--transition);
    position: relative;
    border-radius: 0;
}

.nav-item:hover {
    background: var(--primary-light);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--primary-subtle);
    color: var(--primary);
    font-weight: 500;
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary);
}

.nav-icon {
    font-size: 1rem;
}

.nav-ref {
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--primary);
    opacity: 0.8;
    min-width: 50px;
}

.nav-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── SIDEBAR FOOTER ─────────────────────────────────────────────────── */
.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-sidebar);
}

.footer-version,
.footer-review {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.footer-review {
    margin-top: 4px;
}

/* ── MAIN CONTENT ───────────────────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

.content-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 32px;
    background: var(--bg-content);
    border-bottom: 1px solid var(--border-light);
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
    flex-shrink: 0;
}

.mobile-menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.breadcrumb {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.content-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.meta-badge {
    padding: 6px 12px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

/* ── DOCUMENT WRAPPER ───────────────────────────────────────────────── */
.document-wrapper {
    flex: 1;
    padding: 32px;
    overflow-x: hidden;
    width: 100%;
}

.markdown-body {
    max-width: 850px;
    width: 100%;
    margin: 0 auto;
    padding: 48px 64px;
    background: var(--bg-content);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}

/* ── MARKDOWN CONTENT STYLES ─────────────────────────────────────────── */
.markdown-body {
    font-family: var(--font-doc);
    font-size: var(--doc-font-size);
    line-height: var(--doc-line-height);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
    font-family: var(--font-ui);
    font-weight: 600;
    color: var(--text-heading);
    margin-top: 2em;
    margin-bottom: 0.75em;
    line-height: 1.3;
}

.markdown-body h1 {
    font-size: 2rem;
    padding-bottom: 0.5em;
    border-bottom: 1px solid var(--border-light);
    margin-top: 0;
}

.markdown-body h1:first-child {
    border-bottom: none;
    margin-bottom: 1.5em;
}

.markdown-body h2 {
    font-size: 1.5rem;
    padding-bottom: 0.3em;
    border-bottom: 1px solid var(--border-light);
}

.markdown-body h3 {
    font-size: 1.25rem;
}

.markdown-body h4 {
    font-size: 1rem;
}

.markdown-body p {
    margin-bottom: 1.25em;
}

.markdown-body a {
    color: var(--primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.markdown-body a:hover {
    color: var(--primary-hover);
}

.markdown-body ul,
.markdown-body ol {
    margin-bottom: 1.25em;
    padding-left: 2em;
}

.markdown-body li {
    margin-bottom: 0.5em;
}

.markdown-body blockquote {
    margin: 1.5em 0;
    padding: 1em 1.5em;
    border-left: 4px solid var(--primary);
    background: var(--primary-light);
    color: var(--text-secondary);
    border-radius: 8px;
}

.markdown-body blockquote p {
    margin-bottom: 0;
}

.markdown-body hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2em 0;
}

.markdown-body code {
    font-family: var(--font-mono);
    font-size: 0.9em;
    padding: 0.2em 0.4em;
    background: var(--bg-code);
    color: var(--text-code);
    border-radius: 4px;
}

.markdown-body pre {
    margin: 1.5em 0;
    padding: 1.25em;
    background: var(--bg-code);
    border-radius: 8px;
    overflow-x: auto;
}

.markdown-body pre code {
    padding: 0;
    background: none;
}

.markdown-body table {
    width: 100%;
    margin: 1.5em 0;
    border-collapse: collapse;
    font-size: 0.9em;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.markdown-body th,
.markdown-body td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
}

.markdown-body th {
    background: var(--bg-sidebar-hover);
    font-weight: 600;
    color: var(--text-heading);
}

.markdown-body tr:last-child td {
    border-bottom: none;
}

.markdown-body tr:hover {
    background: var(--primary-light);
}

.markdown-body img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    margin: 1.5em auto;
    display: block;
}

/* ── LOADING INDICATOR ──────────────────────────────────────────────── */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 32px;
    color: var(--text-secondary);
    gap: 16px;
}

.loading-indicator i {
    font-size: 2rem;
    color: var(--primary);
}

/* ── LOADING OVERLAY ─────────────────────────────────────────────────── */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-content);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.loading-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

.loading-container {
    text-align: center;
}

.loading-text {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: 0.3em;
    margin-bottom: 24px;
}

.loading-progress-bar {
    width: 300px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
}

.loading-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.1s linear;
}

/* ── PRINT STYLES ────────────────────────────────────────────────────── */
@media print {
    @page {
        margin: 1.5cm 2cm;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    html,
    body {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        background: var(--print-bg) !important;
        color: var(--print-text) !important;
    }

    /* Hide UI elements */
    .app-header,
    .sidebar,
    .content-header,
    .sidebar-overlay,
    .sidebar-search,
    .sidebar-footer,
    .mobile-menu-btn,
    ::-webkit-scrollbar {
        display: none !important;
    }

    /* Full width content */
    .main-content {
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
    }

    .document-wrapper {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
    }

    .markdown-body {
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        font-size: 11pt !important;
        line-height: 1.6 !important;
        background: var(--print-bg) !important;
        color: var(--print-text) !important;
        overflow: visible !important;
    }

    /* Remove transforms and positioning issues */
    .markdown-body *,
    .markdown-body *::before,
    .markdown-body *::after {
        transform: none !important;
        -webkit-transform: none !important;
        position: static !important;
    }

    /* Allow content to flow naturally */
    .markdown-body > * {
        overflow: visible !important;
        max-width: 100% !important;
        page-break-inside: auto;
    }

    /* Page break controls */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid !important;
        page-break-inside: avoid !important;
    }

    .markdown-body h1 {
        font-size: 20pt !important;
        margin-top: 1cm;
        margin-bottom: 0.5cm;
        padding-bottom: 4pt;
        border-bottom: 1pt solid var(--print-border) !important;
        color: var(--print-heading) !important;
    }

    .markdown-body h1:first-child {
        font-size: 24pt !important;
        margin-top: 0 !important;
        margin-bottom: 0.75cm !important;
    }

    .markdown-body h2 {
        font-size: 16pt !important;
        margin-top: 0.75cm;
        margin-bottom: 0.4cm;
        padding-bottom: 3pt;
        border-bottom: 0.5pt solid var(--print-border) !important;
        color: var(--print-heading) !important;
    }

    .markdown-body h3 {
        font-size: 13pt !important;
        margin-top: 0.5cm;
        margin-bottom: 0.25cm;
        color: var(--print-heading) !important;
    }

    .markdown-body p {
        margin-bottom: 0.5em !important;
        orphans: 3;
        widows: 3;
        text-align: left !important;
        color: var(--print-text) !important;
    }

    /* Code blocks for print */
    .markdown-body pre {
        page-break-inside: avoid !important;
        white-space: pre-wrap !important;
        word-break: break-word !important;
        font-size: 0.9em !important;
        padding: 0.75em !important;
        border: 1px solid var(--print-code-border) !important;
        border-left: 3px solid var(--print-code-accent) !important;
        background: var(--print-code-bg) !important;
        color: var(--print-code-text) !important;
        max-width: 100% !important;
        overflow: visible !important;
    }

    .markdown-body code {
        font-family: 'Courier New', monospace !important;
        font-size: 0.9em !important;
    }

    .markdown-body pre code {
        padding: 0 !important;
        background: none !important;
    }

    /* Tables for print */
    .markdown-body table {
        page-break-inside: auto !important;
        width: 100% !important;
        border: 1px solid var(--print-border) !important;
    }

    .markdown-body thead {
        display: table-header-group !important;
    }

    .markdown-body th,
    .markdown-body td {
        padding: 6px 10px !important;
        border-bottom: 1px solid var(--print-border) !important;
        color: var(--print-text) !important;
    }

    .markdown-body th {
        background: var(--print-code-bg) !important;
        font-weight: 600 !important;
    }

    .markdown-body tr {
        page-break-inside: avoid !important;
    }

    /* Blockquotes for print */
    .markdown-body blockquote {
        page-break-inside: avoid !important;
        background: var(--print-blockquote-bg) !important;
        border-left: 2px solid var(--print-blockquote-border) !important;
        color: var(--print-text) !important;
        padding: 1em 1.5em !important;
        margin: 1em 0 !important;
    }

    /* Images for print */
    .markdown-body img {
        page-break-inside: avoid !important;
        max-width: 100% !important;
        height: auto !important;
    }

    /* TOC styling for print */
    .document-toc {
        page-break-after: always !important;
        background: none !important;
        border: 1px solid var(--print-border) !important;
        padding: 1em !important;
        margin-bottom: 1em !important;
    }

    .toc-hr {
        display: none !important;
    }

    /* Hide interactive elements */
    .search-highlight,
    .nav-ref {
        background: none !important;
    }

    /* Show print user info in print mode */
    .print-user-info-header,
    .print-user-info-footer {
        display: block !important;
        text-align: center;
        font-family: Arial, sans-serif !important;
        font-size: 7pt !important;
        color: var(--print-text) !important;
        opacity: 0.7;
        margin: 0.5cm 0 !important;
    }

    .print-user-info-header {
        padding-bottom: 0.3cm !important;
        border-bottom: 1px solid var(--print-border) !important;
    }

    .print-user-info-footer {
        padding-top: 0.3cm !important;
        border-top: 1px solid var(--print-border) !important;
    }

    /* Print header and footer using pseudo elements */
    .markdown-body::before {
        content: "ISCC EU System Manual — PT Cahaya Energy Artha Abadi";
        display: block;
        font-size: 9pt;
        color: var(--print-heading) !important;
        margin-bottom: 0.5cm;
        padding-bottom: 0.3cm;
        border-bottom: 1px solid var(--print-border);
    }

    .markdown-body::after {
        content: "© 2026 PT Cahaya Energy Artha Abadi | Confidential — For authorized use only | compliance@cahaya-energy.com";
        display: block;
        font-size: 8pt;
        color: var(--print-text) !important;
        margin-top: 0.5cm;
        padding-top: 0.3cm;
        border-top: 1px solid var(--print-border);
    }
}

/* ── RESPONSIVE DESIGN ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    :root {
        --header-height: 116px;
    }

    .app-header {
        height: auto;
        min-height: var(--header-height);
        padding: 12px 18px;
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 10px 16px;
        overflow: visible;
    }

    .header-brand {
        width: 100%;
        flex: 1 1 100%;
    }

    .header-controls {
        width: 100%;
        justify-content: flex-start;
        gap: 8px;
    }

    .header-select {
        flex: 1 1 150px;
        min-width: 130px;
    }

    .auditor-badge {
        flex: 1 1 100%;
        min-height: 0;
        padding: 8px 12px;
        white-space: normal;
        line-height: 1.35;
        order: 10;
    }

    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }

    .mobile-menu-btn {
        display: flex;
    }

    .sidebar-toggle {
        display: flex;
    }

    .content-header {
        gap: 12px;
        padding: 12px 20px;
    }

    .document-wrapper {
        padding: 20px;
    }

    .markdown-body {
        padding: 32px 28px;
    }
}

@media (max-width: 640px) {
    :root {
        --header-height: 152px;
    }

    .app-header {
        padding: 10px 12px 12px;
    }

    .brand-title {
        font-size: 0.875rem;
    }

    .brand-subtitle {
        display: none;
    }

    .brand-section {
        max-width: none;
    }

    .header-controls {
        gap: 6px;
    }

    .header-select {
        flex: 1 1 calc(50% - 6px);
        min-width: 0;
    }

    .control-btn {
        width: 38px;
        height: 38px;
    }

    .content-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .document-wrapper {
        padding: 16px;
    }

    .markdown-body {
        padding: 24px 16px;
        border-radius: 10px;
    }

    .breadcrumb {
        order: 10;
        width: 100%;
        font-size: 0.8rem;
    }

    .content-meta {
        width: 100%;
    }

    .meta-badge {
        max-width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }
}

@media (max-width: 420px) {
    :root {
        --header-height: 188px;
    }

    .logo-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .header-controls {
        width: 100%;
    }

    .header-select {
        flex: 1 1 100%;
    }

    .login-page-shell {
        padding: max(16px, env(safe-area-inset-top)) 12px max(16px, env(safe-area-inset-bottom));
    }

    .login-card {
        padding: 20px 16px;
    }
}

/* ─── OVERLAY FOR MOBILE SIDEBAR ─────────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 899;
}

.sidebar-overlay.active {
    display: block;
}

/* ─── DARK MODE TRANSITION ─────────────────────────────────────────────── */
body {
    transition: background-color 0.3s ease, color 0.3s ease;
}

.markdown-body,
.sidebar,
.app-header,
.content-header {
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

/* ─── SCROLLBAR STYLING ───────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--bg-app);
}

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

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── ERROR MESSAGE ─────────────────────────────────────────────────────── */
.error-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 32px;
    text-align: center;
    gap: 16px;
}

.error-message i {
    font-size: 3rem;
    color: var(--danger);
}

.error-message h2 {
    font-size: 1.5rem;
    color: var(--text-heading);
    margin: 0;
}

.error-message p {
    color: var(--text-secondary);
    margin: 0;
}

/* ── SEARCH INPUT ─────────────────────────────────────────────────────── */
.sidebar-search {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.sidebar-search input {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-app);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all var(--transition);
}

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

.sidebar-search input::placeholder {
    color: var(--text-muted);
}

.sidebar-search i {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.875rem;
    pointer-events: none;
}

/* ── DOCUMENT TOC ──────────────────────────────────────────────────────── */
.document-toc {
    background: var(--primary-light);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px 20px;
    margin: 24px 0;
}

.document-toc h4 {
    margin: 0 0 12px 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-heading);
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.document-toc li {
    margin-bottom: 6px;
}

.document-toc a {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
    display: block;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background var(--transition);
}

.document-toc a:hover {
    background: var(--primary-subtle);
}

.toc-hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 24px 0;
}

/* ── CONTENT FADE IN ANIMATION ───────────────────────────────────────────── */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.markdown-body {
    animation: fadeIn 0.3s ease;
}

/* ── KEYBOARD SHORTCUT BADGE ─────────────────────────────────────────── */
kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    background: var(--bg-sidebar-hover);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    margin-left: 4px;
}

/* ── SCROLL PROGRESS INDICATOR ───────────────────────────────────────── */
.scroll-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: var(--primary);
    width: 0%;
    transition: width 0.1s ease;
    pointer-events: none;
}

/* ── HEADER SELECT STYLES ────────────────────────────────────────────── */
.header-select {
    background: var(--bg-app);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 24px 4px 8px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
    appearance: none;
    font-family: var(--font-ui);
    transition: border-color 0.15s, background 0.15s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236c757d' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    background-size: 10px;
    height: 32px;
}

.header-select:hover {
    border-color: var(--primary);
}

.header-select:focus-visible {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-subtle);
}

/* ── EXTERNAL LINK INDICATOR ─────────────────────────────────────────── */
.markdown-body a.external-link::after {
    content: '↗';
    font-size: 0.8em;
    margin-left: 2px;
    opacity: 0.6;
    vertical-align: super;
}

.markdown-body a.external-link:hover::after {
    opacity: 1;
}

/* Internal document links (hash refs) */
.markdown-body a[href^="#"] {
    font-weight: 500;
    color: var(--primary);
}

/* Internal navigation links */
.markdown-body a[data-doc] {
    font-weight: 500;
}

.markdown-body a[href^="#"]:hover {
    text-decoration: underline;
}

/* ── ENHANCED LINK STYLING ───────────────────────────────────────────── */
.markdown-body a {
    color: var(--primary);
    text-decoration: none;
    text-underline-offset: 2px;
    transition: color var(--transition);
}

.markdown-body a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* ── DOWNLOAD LINK STYLING ────────────────────────────────────────────── */
.markdown-body a[href$=".xlsx"],
.markdown-body a[href$=".xls"] {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: #1d6f42; /* Excel green */
    color: white !important;
    border-radius: 6px;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--transition);
}

.markdown-body a[href$=".xlsx"]:hover,
.markdown-body a[href$=".xls"]:hover {
    background: #165a34;
    color: white !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.markdown-body a[href$=".xlsx"]::after,
.markdown-body a[href$=".xls"]::after {
    content: none; /* Remove external link indicator */
}

/* ── SIGN-IN MODAL ───────────────────────────────────────────────────── */
.signin-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #dceee4 0%, #f3f0e8 52%, #f8fafc 100%);
}

.login-page-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 520px) minmax(260px, 360px);
    justify-content: center;
    align-items: center;
    gap: 28px;
    padding: 40px 20px;
}

.signin-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.signin-container {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.login-card {
    width: min(100%, 520px);
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid rgba(15, 118, 110, 0.12);
    border-radius: 24px;
    padding: 32px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.14);
    backdrop-filter: blur(14px);
}

.login-header {
    margin-bottom: 24px;
}

.login-kicker {
    margin: 0 0 10px;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-align: center;
    text-transform: uppercase;
}

.login-notice {
    margin-bottom: 24px;
    padding: 14px 16px;
    border-radius: 12px;
    background: #eff8f4;
    border: 1px solid #cce8db;
    color: #175940;
    font-size: 0.875rem;
    line-height: 1.5;
}

.login-side-note {
    display: flex;
}

.login-side-card {
    align-self: stretch;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 14px;
    padding: 28px;
    border-radius: 24px;
    background: linear-gradient(160deg, rgba(15, 118, 110, 0.92), rgba(20, 83, 45, 0.96));
    color: #ecfdf5;
    box-shadow: 0 24px 60px rgba(20, 83, 45, 0.18);
}

.login-side-card i {
    font-size: 1.5rem;
}

.login-side-card h2 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 700;
}

.login-side-card p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.6;
    color: rgba(236, 253, 245, 0.88);
}

.signin-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 28px;
    margin: 0 auto 24px;
}

.signin-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-heading);
    text-align: center;
    margin: 0 0 8px;
}

.signin-subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    text-align: center;
    margin: 0 0 32px;
}

.signin-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.form-row .form-group {
    flex: 1;
}

.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
    background: #fff;
    box-sizing: border-box;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    margin-top: 2px;
    flex-shrink: 0;
}

.checkbox-label .link {
    color: var(--primary);
    text-decoration: underline;
}

.form-error {
    min-height: 1.25rem;
    margin: -4px 0 0;
    color: #b42318;
    font-size: 0.875rem;
    font-weight: 500;
}

.signin-btn {
    width: 100%;
    padding: 14px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 8px;
}

.signin-btn:hover {
    background: var(--primary-hover);
}

.signin-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.signin-footer {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    margin: 24px 0 0;
    line-height: 1.5;
}

@media (max-width: 900px) {
    .login-page-shell {
        grid-template-columns: minmax(0, 560px);
        gap: 18px;
        padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
    }

    .login-side-note {
        display: none;
    }
}

@media (max-width: 640px) {
    .login-card {
        padding: 24px 18px;
        border-radius: 18px;
    }

    .form-row {
        flex-direction: column;
        gap: 20px;
    }

    .signin-title {
        font-size: 1.35rem;
    }

    .signin-subtitle {
        margin-bottom: 24px;
    }
}

/* ── CONTENT MODAL (Privacy/Terms) ───────────────────────────────────── */
.content-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.content-modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-container {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
}

.modal-close {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-sidebar-hover);
    border-radius: 8px;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--border-color);
}

.modal-content {
    padding: 24px;
    overflow-y: auto;
}

/* Hide main app when sign-in is shown */
.signin-modal:not(.hidden) ~ * {
    display: none;
}

/* ── TEMPLATE MODAL ─────────────────────────────────────────────────── */
.template-modal {
    z-index: 2200;
}

.modal-large {
    max-width: 900px;
}

.modal-title-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.back-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-sidebar-hover);
    border-radius: 8px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.back-btn:hover {
    background: var(--border-color);
}

.template-modal .modal-content {
    padding: 32px;
    max-height: calc(80vh - 80px);
    overflow-y: auto;
}

/* Template content styling */
.template-modal .modal-content h1:first-child {
    margin-top: 0;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--border-color);
}

.template-modal .modal-content h2 {
    margin-top: 32px;
}

/* Loading state for template */
.template-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 64px 32px;
    color: var(--text-secondary);
}

.template-loading i {
    font-size: 2rem;
    margin-bottom: 16px;
}

/* Template links */
.markdown-body a.template-link {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.markdown-body a.template-link::before {
    content: '📄';
    font-size: 0.9em;
}

.markdown-body a.template-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.markdown-body a.template-link::after {
    content: none; /* Remove external link indicator */
}
