/* Fabi-SC ID Documentation Theme - Custom Overrides */
/* Only applies to screen, not print */

/* Override mdBook's prefers-color-scheme dark mode detection */
/* Force light theme values even when system prefers dark */
@media (prefers-color-scheme: dark) {
    .light, :root {
        --bg: hsl(0, 0%, 100%) !important;
        --fg: hsl(0, 0%, 0%) !important;
        --sidebar-bg: #fafafa !important;
        --sidebar-fg: hsl(0, 0%, 0%) !important;
        --sidebar-non-existant: #aaaaaa !important;
        --sidebar-active: #1f1fff !important;
        --sidebar-spacer: #f4f4f4 !important;
        --scrollbar: #8F8F8F !important;
        --icons: #747474 !important;
        --icons-hover: #000000 !important;
        --links: #20609f !important;
        --inline-code-color: #301900 !important;
        --theme-popup-bg: #fafafa !important;
        --theme-popup-border: #cccccc !important;
        --theme-hover: #e6e6e6 !important;
        --quote-bg: hsl(197, 37%, 96%) !important;
        --quote-border: hsl(197, 37%, 91%) !important;
        --warning-border: #ff8e00 !important;
        --table-border-color: hsl(0, 0%, 95%) !important;
        --table-header-bg: hsl(0, 0%, 80%) !important;
        --table-alternate-bg: hsl(0, 0%, 97%) !important;
        --searchbar-border-color: #aaa !important;
        --searchbar-bg: #fafafa !important;
        --searchbar-fg: #000 !important;
        --searchbar-shadow-color: #aaa !important;
        --searchresults-header-fg: #666 !important;
        --searchresults-border-color: #888 !important;
        --searchresults-li-bg: #e4f2fe !important;
        --search-mark-bg: #a2cff5 !important;
        --color-scheme: light !important;
        color-scheme: light !important;
    }
}

@media screen {
    /* Force light color-scheme */
    :root, html, body {
        --color-scheme: light !important;
        color-scheme: light !important;
    }

    /* Fix sticky menu bar - overflow clips break sticky positioning */
    html {
        overflow-x: visible !important;
    }

    .page-wrapper {
        overflow-x: visible !important;
    }

    .page {
        overflow-x: visible !important;
        margin-block-start: 0 !important;
    }

    :root {
        /* Primary Colors from Logo */
        --color-navy: #1a365d;
        --color-blue: #3182ce;
        --color-cyan: #00bcd4;

        /* Background Colors */
        --bg-primary: #ffffff;
        --bg-secondary: #f8fafc;
        --bg-tertiary: #f1f5f9;

        /* Text Colors */
        --text-primary: #1e293b;
        --text-secondary: #64748b;
        --text-muted: #94a3b8;

        /* Border Colors */
        --border-light: #e2e8f0;
        --border-medium: #cbd5e1;

        /* Shadows */
        --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
        --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

        /* Remove sidebar resize indicator gap */
        --sidebar-resize-indicator-width: 0px;
    }

    /* Override mdBook light theme variables */
    .light {
        --bg: var(--bg-secondary);
        --fg: var(--text-primary);
        --sidebar-bg: var(--bg-primary);
        --sidebar-fg: var(--text-secondary);
        --sidebar-non-existant: var(--text-muted);
        --sidebar-active: var(--color-blue);
        --sidebar-spacer: var(--border-light);
        --scrollbar: var(--border-medium);
        --icons: var(--text-secondary);
        --icons-hover: var(--color-blue);
        --links: var(--color-blue);
        --inline-code-color: var(--color-navy);
        --theme-popup-bg: var(--bg-primary);
        --theme-popup-border: var(--border-light);
        --theme-hover: var(--bg-tertiary);
        --quote-bg: var(--bg-tertiary);
        --quote-border: var(--color-blue);
        --table-border-color: var(--border-light);
        --table-header-bg: var(--bg-tertiary);
        --table-alternate-bg: var(--bg-secondary);
        --searchbar-border-color: var(--border-light);
        --searchbar-bg: var(--bg-primary);
        --searchbar-fg: var(--text-primary);
        --searchbar-shadow: var(--shadow-sm);
        --searchresults-header-fg: var(--text-muted);
        --searchresults-border-color: var(--border-light);
        --searchresults-li-bg: var(--bg-primary);
        --search-mark-bg: rgba(0, 188, 212, 0.3);
    }

    /* Font family */
    html {
        font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    }

    /* Content wrapper - center the document */
    .content {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 1rem;
        overflow-x: hidden;
    }

    .content main {
        max-width: 900px;
        width: 100%;
        padding: 1rem;
    }

    /* Navigation wrapper */
    .content .nav-wrapper {
        max-width: 900px;
        width: 100%;
    }

    /* Card design only on desktop */
    @media only screen and (min-width: 1020px) {
        .content {
            padding: 2rem;
        }

        .content main {
            background: var(--bg-primary);
            padding: 2.5rem 3rem;
            border-radius: 0.75rem;
            box-shadow: var(--shadow-md);
        }
    }

    /* Headings */
    .content h1 {
        color: var(--color-navy);
        font-weight: 600;
        margin-top: 0;
        padding-bottom: 0.75rem;
        border-bottom: 2px solid var(--border-light);
    }

    .content h2 {
        color: var(--color-navy);
        font-weight: 600;
        margin-top: 2rem;
    }

    .content h3, .content h4, .content h5, .content h6 {
        color: var(--text-primary);
        font-weight: 600;
    }

    /* Links */
    .content a:hover {
        color: var(--color-navy);
    }

    /* Code */
    .content code {
        font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', monospace;
        font-size: 0.875em;
    }

    .content pre {
        background: var(--bg-tertiary) !important;
        border: 1px solid var(--border-light);
        border-radius: 0.5rem;
    }

    .content :not(pre) > code {
        background: var(--bg-tertiary);
        padding: 0.125rem 0.375rem;
        border-radius: 0.25rem;
        color: var(--color-navy);
    }

    /* Tables */
    .content table th {
        background: var(--bg-tertiary);
        font-weight: 600;
    }

    /* Blockquotes */
    .content blockquote {
        background: var(--bg-tertiary);
        border-left: 4px solid var(--color-blue);
        border-radius: 0 0.5rem 0.5rem 0;
        padding: 1rem;
    }

    /* ============================================= */
    /* Sidebar Styling */
    /* ============================================= */
    .sidebar {
        background: var(--bg-primary);
        border-right: 1px solid var(--border-light);
        display: flex;
        flex-direction: column;
    }

    /* Logo in sidebar */
    .sidebar-logo {
        padding: 0.75rem;
        border-bottom: 1px solid var(--border-light);
        text-align: center;
        flex-shrink: 0;
    }

    .sidebar-logo img {
        max-width: 32px;
        height: auto;
    }

    .sidebar .sidebar-scrollbox {
        position: static !important;
        padding-top: 0.5rem;
        flex: 1;
        overflow-y: auto;
    }

    /* Override JS-added sidebar resize handle width */
    .js .sidebar .sidebar-resize-handle {
        width: auto !important;
    }

    /* Fix page-wrapper margin to not include resize indicator */
    @media only screen and (min-width: 620px) {
        #mdbook-sidebar-toggle-anchor:checked ~ .page-wrapper {
            margin-inline-start: var(--sidebar-width) !important;
        }
    }

    /* Hide theme toggle button */
    #mdbook-theme-toggle,
    #mdbook-theme-list {
        display: none !important;
    }

    /* Chapter list */
    .sidebar ol.chapter {
        padding-left: 0;
    }

    .sidebar ol.chapter li {
        margin: 0.25rem 0;
    }

    .sidebar ol.chapter li a {
        padding: 0.5rem 0.75rem;
        border-radius: 0.5rem;
        transition: all 150ms ease;
    }

    .sidebar ol.chapter li a:hover {
        background: var(--bg-tertiary);
        text-decoration: none;
    }

    .sidebar ol.chapter li a.active {
        background: rgba(49, 130, 206, 0.1);
        color: var(--color-blue);
    }

    /* ============================================= */
    /* Menu bar */
    /* ============================================= */
    #mdbook-menu-bar,
    #mdbook-menu-bar.sticky,
    #mdbook-menu-bar.bordered {
        position: sticky !important;
        top: 0 !important;
        z-index: 100;
        background: var(--bg-primary);
        border-bottom: 1px solid var(--border-light);
        transform: none !important;
        transition: none !important;
    }

    /* Override mdBook's hide-on-scroll behavior */
    #mdbook-menu-bar-hover-placeholder {
        height: 0 !important;
        display: none !important;
    }

    /* Ensure content doesn't overlap menu bar */
    .content {
        margin-top: 0 !important;
    }

    #menu-bar h1.menu-title {
        color: var(--color-navy);
        font-weight: 600;
    }

    #menu-bar .icon-button {
        border-radius: 0.5rem;
        padding: 0.5rem;
        transition: all 150ms ease;
    }

    #menu-bar .icon-button:hover {
        background: var(--bg-tertiary);
        color: var(--color-blue);
    }

    /* ============================================= */
    /* Search */
    /* ============================================= */
    #mdbook-search-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 199;
    }

    #mdbook-search-backdrop.hidden {
        display: none;
    }

    #mdbook-search-wrapper {
        position: fixed;
        top: 80px;
        left: 50%;
        transform: translateX(-50%);
        width: 100%;
        max-width: 600px;
        z-index: 200;
        padding: 0 1rem;
        box-sizing: border-box;
    }

    .searchbar-outer {
        margin: 0;
    }

    .search-wrapper {
        position: relative;
        display: flex;
        align-items: center;
    }

    #mdbook-searchbar {
        width: 100%;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border: 1px solid var(--border-light);
        border-radius: 0.75rem;
        padding: 1rem 1.25rem;
        padding-right: 3rem;
        transition: border-color 150ms ease, box-shadow 150ms ease;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1);
    }

    #mdbook-searchbar:focus {
        border-color: var(--color-blue);
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15), 0 4px 12px rgba(0, 0, 0, 0.1), 0 0 0 3px rgba(49, 130, 206, 0.15);
        outline: none;
    }

    .search-wrapper .spinner-wrapper {
        position: absolute;
        right: 0.75rem;
        top: 50%;
        transform: translateY(-50%);
    }

    #mdbook-searchresults-outer {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        margin-top: 0.5rem;
        background: var(--bg-primary);
        border: 1px solid var(--border-light);
        border-radius: 0.5rem;
        box-shadow: var(--shadow-md);
        max-height: 400px;
        overflow-y: auto;
        z-index: 100;
    }

    #mdbook-searchresults-header {
        padding: 1rem;
        font-weight: 600;
        color: var(--text-secondary);
        border-bottom: 1px solid var(--border-light);
    }

    #mdbook-searchresults {
        list-style: none !important;
        margin: 0 !important;
        padding: 0.5rem !important;
        padding-inline-start: 0.5rem !important;
    }

    ul#mdbook-searchresults li {
        background: transparent;
        border: none;
        border-radius: 0.75rem !important;
        margin: 4px 0 !important;
        padding: 0 !important;
        padding-bottom: 1rem !important;
        transition: background 150ms ease;
        overflow: hidden;
    }

    #mdbook-searchresults li:hover {
        background: var(--bg-tertiary);
    }

    #mdbook-searchresults li a {
        display: block;
        padding: 0.75rem 1rem;
        color: var(--text-primary);
        text-decoration: none;
    }

    #mdbook-searchresults li a:hover {
        color: var(--color-blue);
    }

    /* ============================================= */
    /* Theme popup */
    /* ============================================= */
    #theme-list {
        background: var(--bg-primary);
        border: 1px solid var(--border-light);
        border-radius: 0.5rem;
        box-shadow: var(--shadow-md);
        overflow: hidden;
    }

    #theme-list li {
        padding: 0.5rem 1rem;
        transition: all 150ms ease;
    }

    #theme-list li:hover {
        background: var(--bg-tertiary);
    }

    /* ============================================= */
    /* Navigation buttons */
    /* ============================================= */
    .nav-chapters {
        max-width: 40px;
        height: 80px;
        top: 50%;
        transform: translateY(-50%);
        border-radius: 0.5rem;
    }

    .nav-chapters:hover {
        color: var(--color-blue);
    }

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

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

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

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