/* ==========================================================================
   Design Tokens & Theme Variables
   ========================================================================== */
:root {
    --bg-canvas: #ffffff;
    --bg-surface: #f8fafc;
    --bg-card: rgba(248, 250, 252, 0.7);
    --bg-card-hover: #f1f5f9;
    --border-main: rgba(226, 232, 240, 0.8);
    --border-subtle: rgba(226, 232, 240, 0.5);
    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    --accent: #4f46e5;
    --tag-bg: #f1f5f9;
    --tag-border: #e2e8f0;
}

html.dark {
    --bg-canvas: #0b0f17;
    --bg-surface: #0b0f17;
    --bg-card: rgba(22, 27, 34, 0.6);
    --bg-card-hover: rgba(30, 36, 46, 0.8);
    --border-main: rgba(48, 54, 61, 0.8);
    --border-subtle: rgba(48, 54, 61, 0.5);
    --text-main: #f0f6fc;
    --text-muted: #8b949e;
    --text-faint: #6e7681;
    --accent: #818cf8;
    --tag-bg: rgba(22, 27, 34, 0.9);
    --tag-border: rgba(48, 54, 61, 0.8);
}

/* ==========================================================================
   Sepia / Digital Library Theme Mode (Harmonious & Natural Paper Aesthetic)
   ========================================================================== */
html.sepia-mode {
    --bg-canvas: #f6f1e5;          /* Warm soft book paper */
    --bg-surface: #f0e9d6;         /* Refined parchment for sidebar/header */
    --bg-card: rgba(60, 44, 28, 0.04); /* Subtle natural paper depression */
    --bg-card-hover: rgba(60, 44, 28, 0.08);
    --border-main: rgba(60, 44, 28, 0.12); /* Soft organic parchment line */
    --border-subtle: rgba(60, 44, 28, 0.07);
    --text-main: #241a12;          /* Deep espresso text */
    --text-muted: #574636;         /* Rich book ink tone */
    --text-faint: #8a7662;         /* Muted leather tone */
    --accent: #9a3412;             /* Terracotta / warm rust */
    --tag-bg: rgba(60, 44, 28, 0.05);
    --tag-border: rgba(60, 44, 28, 0.12);
}

html.sepia-mode,
html.sepia-mode body {
    background-color: var(--bg-canvas) !important;
    color: var(--text-main) !important;
}

html.sepia-mode header,
html.sepia-mode aside {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-main) !important;
}

html.sepia-mode main {
    background-color: var(--bg-canvas) !important;
}

/* Cards & Widgets in Sepia */
html.sepia-mode .wiki-meta-card,
html.sepia-mode .wiki-sidebar-widget,
html.sepia-mode .wiki-card,
html.sepia-mode #search-trigger,
html.sepia-mode #search-modal > div {
    background-color: var(--bg-card) !important;
    border-color: var(--border-main) !important;
    box-shadow: none !important;
}

html.sepia-mode #search-modal {
    background-color: rgba(36, 26, 18, 0.6) !important;
}

html.sepia-mode #search-modal > div {
    background-color: var(--bg-surface) !important;
}

html.sepia-mode .wiki-tag-pill {
    background-color: var(--tag-bg) !important;
    border-color: var(--tag-border) !important;
    color: var(--text-muted) !important;
}

html.sepia-mode input {
    color: var(--text-main) !important;
}

html.sepia-mode input::placeholder {
    color: var(--text-faint) !important;
}

html.sepia-mode .text-slate-900,
html.sepia-mode .text-slate-800,
html.sepia-mode .text-slate-700 {
    color: var(--text-main) !important;
}

html.sepia-mode header span.text-white,
html.sepia-mode aside span.text-white,
html.sepia-mode h1.text-white:not(.wiki-hero-banner *),
html.sepia-mode h2.text-white:not(.wiki-hero-banner *) {
    color: var(--text-main) !important;
}

html.sepia-mode .text-slate-600,
html.sepia-mode .text-slate-500,
html.sepia-mode .text-slate-400 {
    color: var(--text-muted) !important;
}

html.sepia-mode .border-slate-100,
html.sepia-mode .border-slate-200,
html.sepia-mode .border-slate-300,
html.sepia-mode .border-slate-700,
html.sepia-mode .border-slate-800 {
    border-color: var(--border-main) !important;
}

html.sepia-mode .hover\:bg-slate-50:hover,
html.sepia-mode .hover\:bg-slate-100:hover,
html.sepia-mode .hover\:bg-slate-200:hover,
html.sepia-mode .hover\:bg-slate-800:hover,
html.sepia-mode .hover\:bg-slate-900:hover,
html.sepia-mode .tree-row:hover {
    background-color: var(--bg-card-hover) !important;
}

html.sepia-mode .toc-item.active {
    background-color: var(--bg-card-hover) !important;
    color: var(--text-main) !important;
    font-weight: 600;
}

html.sepia-mode .callout {
    background-color: var(--bg-card) !important;
    border-color: var(--border-main) !important;
}

/* ==========================================================================
   Hero Banner Styling (Light, Dark, Sepia)
   ========================================================================== */
.wiki-hero-banner {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    border-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.wiki-hero-banner h1 {
    color: #ffffff !important;
    font-weight: 700;
}

.wiki-hero-banner p {
    color: #cbd5e1 !important;
}

.wiki-hero-banner button,
.wiki-hero-banner a {
    color: #ffffff !important;
}

html.sepia-mode .wiki-hero-banner {
    background: linear-gradient(135deg, #2c2014 0%, #3d2e1f 50%, #2c2014 100%) !important;
    border-color: #4a3a2a !important;
    box-shadow: 0 4px 14px rgba(44, 32, 20, 0.15) !important;
}

html.sepia-mode .wiki-hero-banner h1 {
    color: #ffffff !important;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4) !important;
}

html.sepia-mode .wiki-hero-banner p {
    color: #f1ede6 !important;
    opacity: 0.95 !important;
}

html.sepia-mode .wiki-hero-banner button {
    background-color: rgba(255, 255, 255, 0.15) !important;
    border-color: rgba(255, 255, 255, 0.25) !important;
    color: #ffffff !important;
}

html.sepia-mode .wiki-hero-banner button:hover {
    background-color: rgba(255, 255, 255, 0.22) !important;
}

html.sepia-mode .wiki-hero-banner a {
    background-color: #6366f1 !important;
    color: #ffffff !important;
}

/* ==========================================================================
   Sidebar Collapse & Transition Styles
   ========================================================================== */
#sidebar {
    transition: width 0.2s cubic-bezier(0.4, 0, 0.2, 1), 
                transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.15s ease,
                border-color 0.15s ease;
}

@media (min-width: 1024px) {
    #sidebar.sidebar-collapsed {
        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
        padding: 0 !important;
        border-right-width: 0 !important;
        border-right-color: transparent !important;
        overflow: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
}

/* ==========================================================================
   Custom Scrollbar
   ========================================================================== */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

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

::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.35);
    border-radius: 9999px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.6);
}

html.sepia-mode ::-webkit-scrollbar-thumb {
    background: rgba(60, 44, 28, 0.2);
}

html.sepia-mode ::-webkit-scrollbar-thumb:hover {
    background: rgba(60, 44, 28, 0.4);
}

/* ==========================================================================
   Markdown Wiki Typography Enhancements
   ========================================================================== */
.wiki-content {
    font-size: 0.9375rem;
    line-height: 1.8;
}

.wiki-content p {
    margin-top: 1.2em;
    margin-bottom: 1.2em;
    word-break: keep-all;
    overflow-wrap: break-word;
}

.wiki-content h1, 
.wiki-content h2, 
.wiki-content h3, 
.wiki-content h4 {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: inherit;
}

.wiki-content h1 {
    font-size: 1.6rem;
    margin-top: 2rem;
    margin-bottom: 0.9rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-subtle, rgba(156, 163, 175, 0.2));
}

.wiki-content h2 {
    font-size: 1.3rem;
    margin-top: 1.75rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--border-subtle, rgba(156, 163, 175, 0.15));
}

.wiki-content h3 {
    font-size: 1.125rem;
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.wiki-content ul {
    list-style-type: disc;
    padding-left: 1.4rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

.wiki-content ol {
    list-style-type: decimal;
    padding-left: 1.4rem;
    margin-top: 0.75rem;
    margin-bottom: 0.75rem;
}

.wiki-content li {
    margin-top: 0.3rem;
    margin-bottom: 0.3rem;
}

.wiki-content hr {
    margin-top: 2rem;
    margin-bottom: 2rem;
    border-color: var(--border-subtle, rgba(156, 163, 175, 0.2));
}

.wiki-content blockquote:not(.callout) {
    border-left-width: 3px;
    border-color: var(--accent, #6366f1);
    padding-left: 1rem;
    font-style: normal;
    color: inherit;
    opacity: 0.9;
    margin-top: 1.25rem;
    margin-bottom: 1.25rem;
}

/* Tables */
.wiki-content table {
    width: 100%;
    margin-top: 1.5rem;
    margin-bottom: 1.5rem;
    border-collapse: collapse;
    font-size: 0.85rem;
    display: block;
    overflow-x: auto;
}

.wiki-content th, 
.wiki-content td {
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border-main, rgba(156, 163, 175, 0.2));
}

.wiki-content th {
    background-color: var(--bg-card, rgba(156, 163, 175, 0.08));
    font-weight: 600;
}

/* Active TOC Highlight */
.toc-item.active {
    font-weight: 600;
    color: var(--accent, #4f46e5) !important;
    background-color: var(--bg-card-hover, rgba(99, 102, 241, 0.1));
}

.dark .toc-item.active {
    color: #818cf8 !important;
    background-color: rgba(99, 102, 241, 0.15);
}

/* ==========================================================================
   Print & PDF Export Styling (@media print)
   ========================================================================== */
@media print {
    @page {
        size: A4 portrait;
        margin: 15mm 20mm 20mm 20mm;
    }

    /* Force Clean White Paper & Black Text */
    *, html, body, main, article, .wiki-content {
        background: #ffffff !important;
        color: #000000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }

    /* Hide Web Navigation & Interactive Widgets */
    header,
    aside,
    #sidebar,
    #sidebar-backdrop,
    #search-modal,
    #theme-menu,
    #note-bookmark-btn,
    .wiki-sidebar-widget,
    details.lg\:hidden,
    button,
    a[href^="obsidian://"],
    .no-print {
        display: none !important;
    }

    /* Full Width Content */
    body, main, article {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .grid {
        display: block !important;
    }

    /* Typography & Spacing */
    .wiki-content {
        font-size: 11pt !important;
        line-height: 1.6 !important;
    }

    .wiki-content h1 {
        font-size: 20pt !important;
        border-bottom: 1.5pt solid #000000 !important;
        margin-top: 15pt !important;
        margin-bottom: 8pt !important;
    }

    .wiki-content h2 {
        font-size: 15pt !important;
        border-bottom: 1pt solid #444444 !important;
        margin-top: 12pt !important;
        margin-bottom: 6pt !important;
    }

    .wiki-content h3 {
        font-size: 13pt !important;
        margin-top: 10pt !important;
        margin-bottom: 4pt !important;
    }

    /* Metadata Card in Print */
    .wiki-meta-card {
        border: 1pt solid #cccccc !important;
        padding: 10pt !important;
        margin-bottom: 15pt !important;
        border-radius: 4pt !important;
    }

    /* Table, Code & Blockquote Protection */
    table, pre, code, .callout, blockquote, img, .wiki-meta-card {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    table {
        border: 1pt solid #333333 !important;
    }

    th, td {
        border: 0.5pt solid #666666 !important;
        padding: 4pt 8pt !important;
    }

    th {
        background-color: #f0f0f0 !important;
    }

    /* Callout in Print */
    .callout {
        border-left: 3pt solid #333333 !important;
        border-top: 0.5pt solid #cccccc !important;
        border-right: 0.5pt solid #cccccc !important;
        border-bottom: 0.5pt solid #cccccc !important;
        padding: 8pt !important;
    }

    /* Backlinks at Bottom */
    section {
        border-top: 1pt solid #888888 !important;
        margin-top: 20pt !important;
        padding-top: 10pt !important;
    }
}
