/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
   ! SHARED FILE — tesseract-jax and tesseract-streamlit pull this file   !
   ! from tesseract-core/main at build time via HTTP.                     !
   ! Do NOT rename or move this file. Keep changes compatible with all    !
   ! three repos.                                                         !
   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */


/* ===== Top navigation bar (all pages) ===== */

.top-nav {
    background: var(--color-background-secondary);
    border-bottom: 1px solid var(--color-background-border);
    padding: 0.6rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.top-nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.top-nav-brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--color-foreground-primary) !important;
    text-decoration: none !important;
}

.top-nav-brand:hover {
    color: var(--color-foreground-primary) !important;
    text-decoration: none !important;
    opacity: 0.8;
}

.top-nav-brand:visited {
    color: var(--color-foreground-primary) !important;
}

.top-nav-links {
    display: flex;
    gap: 1.5rem;
    align-items: center;
}

.top-nav-links a {
    color: var(--color-foreground-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.15s;
}

.top-nav-links a:hover {
    color: var(--color-brand-primary);
    text-decoration: none;
}

.top-nav a.external-link::after {
    content: " \2197";
}

/* Docs dropdown */
.top-nav-dropdown {
    position: relative;
}

button.top-nav-dropdown-trigger {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--color-foreground-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s;
}

button.top-nav-dropdown-trigger:hover {
    color: var(--color-brand-primary);
}

.top-nav-dropdown-trigger::after {
    content: "";
    display: inline-block;
    width: 0;
    height: 0;
    margin-left: 4px;
    vertical-align: 2px;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
}

.top-nav-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    min-width: 200px;
    background: var(--color-background-primary);
    border: 1px solid var(--color-background-border);
    border-radius: 8px;
    padding: 0.5rem 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    z-index: 200;
}

/* Invisible bridge between trigger and menu to maintain hover */
.top-nav-dropdown::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 12px;
    display: none;
}

.top-nav-dropdown:hover::after {
    display: block;
}

body[data-theme="dark"] .top-nav-dropdown-menu {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.top-nav-dropdown:hover .top-nav-dropdown-menu {
    display: block;
}

.top-nav-dropdown-menu a {
    display: block;
    padding: 0.35rem 1rem;
    font-size: 0.85rem !important;
    color: var(--color-foreground-secondary) !important;
    white-space: nowrap;
}

.top-nav-dropdown-menu a:hover {
    background: var(--color-background-secondary);
    color: var(--color-brand-primary) !important;
}

.top-nav-dropdown-label {
    display: block;
    padding: 0.5rem 1rem 0.2rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-foreground-muted);
}

.top-nav-dropdown-label:first-child {
    padding-top: 0.25rem;
}

/* Hamburger toggle (hidden on desktop) */
.top-nav-toggle {
    display: none;
}

.top-nav-hamburger {
    display: none;
    flex-direction: column;
    gap: 4px;
    cursor: pointer;
    padding: 4px;
}

.top-nav-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--color-foreground-secondary);
    transition: transform 0.2s;
}

@media (max-width: 768px) {
    .top-nav-hamburger {
        display: flex;
    }

    .top-nav-links {
        display: none;
        flex-direction: column;
        align-items: flex-start;
        width: 100%;
        gap: 0;
        padding-top: 0.5rem;
        border-top: 1px solid var(--color-background-border);
        margin-top: 0.6rem;
    }

    .top-nav-inner {
        flex-wrap: wrap;
    }

    .top-nav-toggle:checked ~ .top-nav-links {
        display: flex;
    }

    .top-nav-links > a,
    .top-nav-links > span {
        padding: 0.35rem 0;
    }

    /* Flatten dropdown on mobile */
    .top-nav-dropdown {
        width: 100%;
    }

    .top-nav-dropdown-menu {
        position: static;
        transform: none;
        border: none;
        box-shadow: none;
        padding: 0 0 0 0.75rem;
        min-width: auto;
        background: transparent;
    }

    .top-nav-dropdown:hover .top-nav-dropdown-menu,
    .top-nav-dropdown .top-nav-dropdown-menu {
        display: block;
    }

    /* Show dropdown trigger as a section label on mobile */
    button.top-nav-dropdown-trigger {
        color: var(--color-foreground-muted);
        font-size: 0.75rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        cursor: default;
        padding: 0.5rem 0 0.15rem;
    }

    button.top-nav-dropdown-trigger::after {
        display: none;
    }

    button.top-nav-dropdown-trigger:hover {
        color: var(--color-foreground-muted);
    }

    .top-nav-dropdown-menu a {
        padding: 0.25rem 0;
    }

    .top-nav-dropdown-label {
        padding: 0.4rem 0 0.15rem;
    }
}


/* ===== Offset Furo elements below the sticky top-nav ===== */

.sidebar-sticky,
.toc-sticky {
    top: calc(var(--top-nav-offset, 0px) + 0.5rem);
    max-height: calc(100vh - var(--top-nav-offset, 0px) - 0.5rem);
}

/* Push Furo's mobile header below our top-nav and make it visually secondary */
.mobile-header {
    top: var(--top-nav-offset, 0px) !important;
    background-color: var(--color-background-primary) !important;
    border-bottom: 1px solid var(--color-background-border) !important;
    font-size: 0.85rem;
}

/* Offset the slide-in sidebar/toc drawers so they don't hide behind top-nav */
@media (max-width: 67em) {
    #__navigation:checked ~ .page .sidebar-drawer {
        top: var(--top-nav-offset, 0px);
        height: calc(100vh - var(--top-nav-offset, 0px));
    }
}
@media (max-width: 52em) {
    #__toc:checked ~ .page .toc-drawer {
        top: var(--top-nav-offset, 0px);
        height: calc(100vh - var(--top-nav-offset, 0px));
    }
}

/* GitHub Star button — theme toggle & alignment.
   Uses two variants, toggled via body[data-theme] and prefers-color-scheme
   for "auto" mode. */
.github-star-light,
.github-star-dark {
    display: inline-flex;
    align-items: center;
    height: 28px; /* match github-buttons large iframe height */
}
.github-star-light > span,
.github-star-dark > span {
    display: inline-flex !important;
    align-items: center;
    height: 28px;
}
.github-star-dark { display: none; }
body[data-theme="dark"] .github-star-light { display: none; }
body[data-theme="dark"] .github-star-dark { display: inline-flex; }
@media (prefers-color-scheme: dark) {
    body[data-theme="auto"] .github-star-light { display: none; }
    body[data-theme="auto"] .github-star-dark { display: inline-flex; }
}
@media (prefers-color-scheme: light) {
    body[data-theme="auto"] .github-star-dark { display: none; }
    body[data-theme="auto"] .github-star-light { display: inline-flex; }
}
