/* ================================================== */
/*                  ENHANCED DARK MODE CSS           */
/*                for Sphinx RTD Theme               */
/* ================================================== */

/* === PREVENT WHITE FLASH ON PAGE LOAD === */
/* Set dark background immediately to prevent white flash during loading */
html {
    background-color: #1c1c1c !important;
    color: #e0e0e0 !important;
}

/* Set dark background on body and main containers only */
body {
    background-color: #1c1c1c !important;
}

/* Override any potential white backgrounds from theme loading */
.wy-nav-side,
.wy-grid-for-nav,
.wy-nav-content-wrap {
    background-color: #1c1c1c !important;
}

/* === DARK MODE COLOR SCHEME === */
/* Define all colors as CSS variables for easy maintenance and theming */
:root {
    /* Background colors - main dark theme palette */
    --dark-bg: #1c1c1c;              /* Primary dark background */
    --dark-bg-alt: #282828;          /* Secondary background for contrast */
    --dark-bg-hover: #333333;        /* Hover state background */
    --dark-bg-code: #171717;         /* Background for code blocks */
    
    /* Text colors - various shades for hierarchy */
    --light-text: #e0e0e0;           /* Primary light text color */
    --light-text-alt: #c0c0c0;       /* Secondary light text (slightly dimmer) */
    --dark-text: #1f1f1f;            /* Dark text for light backgrounds */
    --white-text: #ffffff;           /* Pure white text for contrast */
    --search-highlight-text: #333333; /* Dark text on highlighted backgrounds */
    --colored-text: #1a1a1a;         /* Colored text for l2 nav (light green) not current*/
    --l2-current-text:#000000;        /* Text for current l2 nav item */
    
    /* Accent and interactive colors */
    --accent-blue: #40B4E8;          /* Primary blue accent for links */
    --highlight-yellow: #f1c40f;     /* Search term highlighting */
    --hover-gray: #404040;           /* Navigation hover background */
    --button-bg: #404040;            /* Navigation button background */
    --button-bg-hover: #505050;      /* Navigation button hover background */
    
    /* Heading colors */
    --heading-h1: #c0c0c0;           /* for main headings */
    --heading-h2: #969696;           /* for subheadings */
    --emphasis-text: #fff;        /* for emphasized text */
    --code-teal: #20b2aa;            /* Light sea green for inline code */
    
    /* Navigation current page hierarchy - updated to match hard-coded values */
    --nav-current-light: #e3e3e3;    /* Light background for current items */
    --nav-current-l1: #404040;       /* Level 1 current page background */
    --nav-current-active: #525252;   /* Active current page link background */
    --nav-current-l2: #4d4d4d;       /* Level 2 current page background */
    --nav-current-l3: #595959;       /* Level 3 current page background */
    --nav-current-l4: #666666;       /* Level 4 current page background */
    --nav-current-l5: #737373;       /* Level 5 current page background */
    --nav-current-text: #fff; font-weight: bold;     /* Yellow text for current page links */
    
    /* Interface elements */  
    --border-dark: #555555;          /* Dark borders and dividers */
    --expand-button: #c2c2c2;        /* Tree expand button color */
    
    /* Table colors for alternating rows */
    --table-odd: #2e2e2e;            /* Odd table row background */
    --table-even: #262626;           /* Even table row background */
    
    /* Admonition (note/warning) accent colors - very muted for dark theme */
    --warning-orange: #5c3d00;       /* Very muted orange for warning admonitions */
    --danger-red: #5c1a26;           /* Very muted red for danger/error admonitions */
    --note-blue: #1f3f5f;            /* Very muted blue for note admonitions */
    --tip-green: #1a3f2a;            /* Very muted green for tip admonitions */
    --important-purple: #3d2848;     /* Very muted purple for important admonitions */
    
    /* Print mode colors */
    --print-bg: #ffffff;             /* White background for printing */
    --print-text: #000000;           /* Black text for printing */
}

/* === LAYOUT OVERRIDES === */
/* Increase content width beyond RTD theme default while keeping code blocks reasonable */
.wy-nav-content {
    max-width: 1000px !important;
}

/* === BODY AND MAIN CONTENT === */
/* Set the primary dark background and text color for the entire page */
body {
    background-color: var(--dark-bg) !important;
    color: var(--light-text) !important;
}

/* Ensure content areas inherit the dark background */
.wy-nav-content,
.wy-nav-content-wrap {
    background-color: var(--dark-bg);
}

/* === SIDEBAR AND NAVIGATION === */
/* Style the top navigation and search areas with dark theme */
.wy-side-nav-search, 
.wy-nav-top {
    background: var(--dark-bg-alt) !important;
    border-color: var(--border-dark) !important;
}

/* Base navigation menu styling - remove borders and set text colors */
.wy-menu-vertical a {
    color: var(--light-text) !important;
    border: none;
    padding: 1.4045em 1.618em;
}
l1
/* Top-level navigation links use slightly dimmer text */
.wy-menu-vertical li.toctree-l1 > a {
    color: var(--light-text-alt)!important;
}

/* Nested navigation levels use dark text (appears on lighter backgrounds) */
.wy-menu-vertical li.toctree-l2 > a{
    color: var(--colored-text) !important;
    font-weight: bold;
}
.wy-menu-vertical li.toctree-l3 > a,
.wy-menu-vertical li.toctree-l4 > a,
.wy-menu-vertical li.toctree-l5 > a {
    color: var(--light-text) !important;
}

/* Navigation hover effects - unified styling for all navigation levels */
/* Provides consistent white text on gray background for all hover states */
.wy-menu-vertical a:hover,
.wy-nav-side .wy-menu-vertical li.toctree-l2 a:hover,
.wy-nav-side .wy-menu-vertical li.toctree-l3 a:hover,
.wy-nav-side .wy-menu-vertical li.toctree-l4 a:hover,
.wy-nav-side .wy-menu-vertical li.toctree-l5 a:hover,
.wy-nav-side .wy-menu-vertical li.current ul li a:hover,
.wy-nav-side .wy-menu-vertical ul li a:hover {
    color: var(--white-text) !important;
    background-color: var(--hover-gray) !important;
}

/* Current page styling - visual hierarchy for active navigation */
/* Base current page background (light gray) */
.wy-menu-vertical li.current {
    background: var(--nav-current-light)!important;
}

/* Current page link gets hover-style background */
.wy-menu-vertical li.current > a {
    background: var(--dark-bg-hover) !important;
}

/* Active current page links - gray background with yellow text for visibility */
.wy-menu-vertical li.toctree-l1.current > a {
    background: var(--nav-current-l1) !important;
    color: var(--nav-current-text) !important
}
.wy-menu-vertical li.toctree-l2.current,
.wy-menu-vertical li.toctree-l2.current > a {
    background: var(--nav-current-l2) !important;
    color: var(--l2-current-text) !important
}
.wy-menu-vertical li.toctree-l3.current,
.wy-menu-vertical li.toctree-l3.current > a {
    background: var(--nav-current-l3) !important;
    color: var(--nav-current-text) !important
}
.wy-menu-vertical li.toctree-l4.current,
.wy-menu-vertical li.toctree-l4.current > a {
    background: var(--nav-current-l4) !important;
    color: var(--nav-current-text) !important
}

.wy-menu-vertical li.toctree-l5.current,
.wy-menu-vertical li.toctree-l5.current > a {
    background: var(--nav-current-l5) !important;
    color: var(--nav-current-text) !important;
}
.wy-menu-vertical li.toctree-l2,
.wy-menu-vertical li.toctree-l2 > a {
    background: var(--nav-current-l2) !important;
}
.wy-menu-vertical li.toctree-l3,
.wy-menu-vertical li.toctree-l3 > a {
    background: var(--nav-current-l3) !important;
}
.wy-menu-vertical li.toctree-l4,
.wy-menu-vertical li.toctree-l4 > a {
    background: var(--nav-current-l4) !important;
}
.wy-menu-vertical li.toctree-l5,
.wy-menu-vertical li.toctree-l5 > a {
    background: var(--nav-current-l5) !important;
}

/* Tree expand/collapse button styling */
button.toctree-expand {
    color: var(--expand-button) !important;
}

.wy-menu-vertical li.current a {
    border: none;
    padding: 1.4045em 2.427em;
}

/* === PREVIOUS/NEXT NAVIGATION BUTTONS === */
/* Style both top and bottom navigation buttons to match dark theme */
.rst-footer-buttons {
    margin: 3em 0;
}

/* Previous and Next button styling - comprehensive selectors for all locations */
/* Default button styling */
.btn-neutral,
.rst-footer-buttons .btn-neutral,
.rst-footer-buttons a.btn-neutral,
.rst-content .btn-neutral,
.rst-content a.btn-neutral,
div[role="navigation"] .btn-neutral,
div[role="navigation"] a.btn-neutral {
    background-color: var(--nav-current-l2) !important; /* Use L2 background to match navigation */
    color: #ffffff !important;
    border: 1px solid var(--border-dark) !important;
    border-radius: 4px;
    padding: 10px 20px;
    text-decoration: none;
}

/* Button hover effects */
.btn-neutral:hover,
.rst-footer-buttons .btn-neutral:hover,
.rst-footer-buttons a.btn-neutral:hover,
.rst-content .btn-neutral:hover,
.rst-content a.btn-neutral:hover,
div[role="navigation"] .btn-neutral:hover,
div[role="navigation"] a.btn-neutral:hover {
    background-color: var(--nav-current-l3) !important; /* Slightly lighter for hover */
    color: #ffffff !important;
    border-color: var(--accent-blue) !important;
}

/* Button focus states for accessibility */
.btn-neutral:focus,
.rst-footer-buttons .btn-neutral:focus,
.rst-footer-buttons a.btn-neutral:focus,
.rst-content .btn-neutral:focus,
.rst-content a.btn-neutral:focus,
div[role="navigation"] .btn-neutral:focus,
div[role="navigation"] a.btn-neutral:focus {
    background-color: var(--nav-current-l3) !important; /* Same as hover */
    color: #ffffff !important;
    border-color: var(--accent-blue) !important;
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

/* Icon styling within buttons */
.btn-neutral .fa,
.rst-footer-buttons .btn-neutral .fa,
.rst-footer-buttons a.btn-neutral .fa,
.rst-content .btn-neutral .fa,
.rst-content a.btn-neutral .fa,
div[role="navigation"] .btn-neutral .fa,
div[role="navigation"] a.btn-neutral .fa {
    color: #ffffff !important;
}

/* Additional button variants if they exist */
.btn {
    background-color: var(--nav-current-l2) !important; /* Match navigation level */
    color: var(--white-text) !important;
    border: 1px solid var(--border-dark) !important;
}

.btn:hover {
    background-color: var(--nav-current-l3) !important; /* Lighter hover */
    color: var(--white-text) !important;
    border-color: var(--accent-blue) !important;
}

/* === HEADINGS === */
/* Main page headings - blue for primary hierarchy */
h1 {
    color: var(--heading-h1) !important;
}

/* Subheadings - green for secondary hierarchy */
h2 {
    color: var(--heading-h2) !important;
}

/* === LINKS === */
/* Standard link styling - blue accent color for all link states */
a, 
a:link, 
a:visited {
    color: var(--accent-blue);
}

/* Link hover state - white text for better contrast */
a:hover {
    color: var(--white-text);
}

/* === TEXT FORMATTING === */
/* Bold/emphasized text (**text** in markdown) - gold color for emphasis */
strong {
    color: var(--emphasis-text)!important; 
    font-weight: bold;
}

/* === CODE BLOCKS === */
/* Inline code styling (`code` in markdown) - teal text with dark background */
code.docutils.literal {
    color: var(--code-teal);
    background-color: var(--dark-bg-hover)!important;
    border: 1px solid var(--border-dark)!important;
    padding: 2px 4px;
    border-radius: 3px;
}

/* Fix RTD theme inline code that breaks table formatting */
.rst-content code.literal,
.rst-content tt.literal {
    white-space: nowrap !important;
}

/* Multi-line code blocks with syntax highlighting */
div.highlight pre {
    background-color: var(--dark-bg-code) !important;
    color: var(--light-text);
    border: 1px solid var(--border-dark);
    width: 100%; /* Prevent code blocks from exceeding container */
    box-sizing: border-box; /* Include padding and borders in width calculation */
}

/* Code block containers - prevent full-width expansion */
div.highlight,
.rst-content div[class^="highlight"] {
    max-width: 100%;
    overflow-x: auto;
    margin: 1em 0;
}

/* === TABLES === */
/* Fix RTD responsive table wrapper that causes first table text wrapping */
.wy-table-responsive {
    overflow: visible !important;
    max-width: none !important;
}

/* Table headers - dark background with white text for contrast */
table.docutils th,
table th,
.rst-content table.docutils th {
    background-color: var(--dark-bg) !important;
    color: var(--white-text) !important;
    border: 1px solid var(--border-dark) !important;
    padding: 8px 12px !important;
}


/* Table cells - inherit colors from parent rows */
table.docutils td,
table td,
.rst-content table.docutils td {
    background-color: inherit !important;
    color: inherit !important;
    border: 1px solid var(--border-dark) !important;
    padding: 8px 12px !important;
    white-space: nowrap !important; /* Prevent text wrapping in cells */
}

/* Base table styling */
table.docutils,
table,
.rst-content table.docutils {
    border-collapse: collapse !important;
    border: 1px solid var(--border-dark) !important;
    width: auto; /* Auto-size to content instead of 100% */
    margin: 1em 0;
}

/* Alternating table row colors for improved readability */
/* Support multiple row class naming conventions */
.row-odd,
tr:nth-child(odd),
table.docutils tbody tr:nth-child(odd),
.rst-content table.docutils tbody tr:nth-child(odd) {
    background: var(--table-odd) !important;
    color: var(--light-text) !important;
}

.row-even,
tr:nth-child(even),
table.docutils tbody tr:nth-child(even),
.rst-content table.docutils tbody tr:nth-child(even) {
    background: var(--table-even) !important;
    color: var(--light-text-alt) !important;
}

/* Table hover effects for better UX */
table.docutils tbody tr:hover,
.rst-content table.docutils tbody tr:hover {
    background-color: var(--dark-bg-hover) !important;
    color: var(--white-text) !important;
}

/* === ADMONITIONS (Notes, Warnings, etc.) === */
/* Base styling for all admonition boxes with dark theme colors */
div.admonition {
    background-color: var(--dark-bg-alt) !important;
    border: 1px solid var(--border-dark) !important;
    color: var(--light-text) !important;
    border-radius: 4px;
    padding: 12px;
    margin: 1em 0;
}

/* Ensure admonition text remains readable */
div.admonition p {
    color: var(--light-text) !important;
    margin: 0.5em 0;
}

/* Admonition titles */
div.admonition .admonition-title {
    color: var(--white-text) !important;
    font-weight: bold;
    margin-bottom: 0.5em;
}

/* Specific admonition types with dark-theme friendly colors */
/* Note admonitions - very muted blue */
div.admonition.note,
div.admonition[class*="note"],
.rst-content .admonition.note,
.rst-content .admonition[class*="note"] {
    border-left: 4px solid var(--note-blue) !important;
    border-color: var(--note-blue) !important;
}
div.admonition.note .admonition-title,
.rst-content .admonition.note .admonition-title {
    background-color: var(--note-blue) !important;
    color: var(--white-text) !important;
}

.rst-content div,
.rst-content pre.literal-block {
  border: none !important;
  /* overflow-x:auto; */
  margin:1px 0 24px
}

/* Warning/caution/attention admonitions - very muted orange */
div.admonition.warning,
div.admonition.caution,
div.admonition.attention,
div.admonition[class*="warning"],
div.admonition[class*="caution"],
div.admonition[class*="attention"],
.rst-content .admonition.warning,
.rst-content .admonition.caution,
.rst-content .admonition.attention {
    border-left: 4px solid var(--warning-orange) !important;
    border-color: var(--warning-orange) !important;
}
div.admonition.warning .admonition-title,
div.admonition.caution .admonition-title,
div.admonition.attention .admonition-title,
.rst-content .admonition.warning .admonition-title,
.rst-content .admonition.caution .admonition-title,
.rst-content .admonition.attention .admonition-title {
    background-color: var(--warning-orange) !important;
    color: var(--white-text) !important;
}

/* Danger/error admonitions - very muted red */
div.admonition.danger,
div.admonition.error,
div.admonition[class*="danger"],
div.admonition[class*="error"],
.rst-content .admonition.danger,
.rst-content .admonition.error {
    border-left: 4px solid var(--danger-red) !important;
    border-color: var(--danger-red) !important;
}
div.admonition.danger .admonition-title,
div.admonition.error .admonition-title,
.rst-content .admonition.danger .admonition-title,
.rst-content .admonition.error .admonition-title {
    background-color: var(--danger-red) !important;
    color: var(--white-text) !important;
}

/* Tip/hint admonitions - very muted green */
div.admonition.tip,
div.admonition.hint,
div.admonition[class*="tip"],
div.admonition[class*="hint"],
.rst-content .admonition.tip,
.rst-content .admonition.hint {
    border-left: 4px solid var(--tip-green) !important;
    border-color: var(--tip-green) !important;
}
div.admonition.tip .admonition-title,
div.admonition.hint .admonition-title,
.rst-content .admonition.tip .admonition-title,
.rst-content .admonition.hint .admonition-title {
    background-color: var(--tip-green) !important;
    color: var(--white-text) !important;
}

/* Important/seealso admonitions - very muted purple */
div.admonition.important,
div.admonition.seealso,
div.admonition[class*="important"],
div.admonition[class*="seealso"],
.rst-content .admonition.important,
.rst-content .admonition.seealso {
    border-left: 4px solid var(--important-purple) !important;
    border-color: var(--important-purple) !important;
}
div.admonition.important .admonition-title,
div.admonition.seealso .admonition-title,
.rst-content .admonition.important .admonition-title,
.rst-content .admonition.seealso .admonition-title {
    background-color: var(--important-purple) !important;
    color: var(--white-text) !important;
}

/* === SEARCH HIGHLIGHTING === */
/* Enhanced search term highlighting - works with search-phrase.js */
/* Yellow background with dark text and subtle glow effect */
span.highlighted,
.rst-content .highlighted,
.wy-nav-content-wrap .highlighted,
article .highlighted {
    background-color: var(--highlight-yellow) !important;
    color: var(--search-highlight-text) !important;
    box-shadow: 0 0 0 2px var(--highlight-yellow);
    font-weight: 700;
    padding: 1px 2px;
    border-radius: 2px;
}

/* === FORMS AND INPUTS === */
/* Search input and form fields with dark theme styling */
input[type="text"],
input[type="search"] {
    background-color: var(--dark-bg-alt)!important;
    color: var(--light-text)!important;
    border: 1px solid var(--border-dark)!important;
}

/* Input focus states - brighter background and blue border */
input[type="text"]:focus,
input[type="search"]:focus {
    background-color: var(--dark-bg-hover)!important;
    border-color: var(--accent-blue)!important;
}

/* === RESPONSIVE IMPROVEMENTS === */
/* Mobile-friendly padding adjustments for smaller screens */
@media (max-width: 768px) {
    .wy-nav-content {
        padding: 1.618em 1em;
    }
}

/* === ACCESSIBILITY IMPROVEMENTS === */
/* Custom text selection highlighting - blue background with white text */
::selection {
    background-color: var(--accent-blue)!important;
    color: var(--white-text)!important;
}

/* === SCROLLBAR STYLING === */
/* Custom scrollbar to match dark theme */
/* Webkit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--dark-bg-alt)!important;
    border-radius: 6px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-dark)!important;
    border-radius: 6px;
    border: 2px solid var(--dark-bg-alt)!important;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--hover-gray)!important;
}

::-webkit-scrollbar-corner {
    background: var(--dark-bg-alt)!important;
}

/* Firefox scrollbar styling */
html {
    scrollbar-width: thin;
    scrollbar-color: var(--border-dark) var(--dark-bg-alt);
}

/* === PRINT STYLES === */
/* Print-friendly styling - revert to standard black text on white background */
@media print {
    body {
        background: var(--print-bg) !important;
        color: var(--print-text) !important;
    }
}
