/* Portal in-page tab bar — Phase 1.
 * Sits at the top of .portal-content, above flash messages and page content.
 * Uses the existing theme tokens so light + dark mode work without overrides.
 */

/* Tab bar viewport reserve — exposed as a CSS variable so workspace
 * stylesheets (main.css ordquant panels, mobile PO list, etc.) can
 * subtract it from their `calc(100dvh - …)` rules.
 *
 * 80px = 40px (bar min-height) + 1px (border-bottom) + ~39px buffer
 * for Bootstrap container padding, sub-pixel rounding, and the
 * workspace heading row's top + bottom margins (mt-3 + mb-3 = 32px).
 * The top margin gives the heading / Back button breathing room
 * below the tab bar; it must be reserved here so workspace panels
 * sized by `calc(100dvh - … - var(--portal-tab-bar-h))` don't push
 * into overflow.
 *
 * One value across all breakpoints. The formulas it feeds use
 * `100dvh` (dynamic viewport height) which already tracks the actual
 * visible viewport on iOS / iPadOS Safari, so no per-breakpoint
 * inflation is needed — the size mismatch between `100vh` (the large
 * viewport) and the actually-visible area is what made earlier values
 * (238px / 449px) feel necessary. With dvh in place, those bumps
 * over-reserve and cause panels to be far smaller than required. */
:root {
    --portal-tab-bar-h: 80px;
}

/* Pages without the portal sidebar (login, etc.) drop the .with-sidebar
 * body class — the tab bar isn't relevant there. */
body:not(.with-sidebar) .portal-tab-bar {
    display: none;
}
/* When the tab bar is hidden, the workspace viewport calcs should treat
 * its contribution as zero so layouts don't reserve dead space. */
body:not(.with-sidebar) {
    --portal-tab-bar-h: 0px;
}

.portal-tab-bar {
    /* Sit flush against the navbar above; the inner list provides padding. */
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    /* Hide the horizontal scrollbar on the bar itself; tabs are interactive
       so users can scroll via wheel or touch. */
    scrollbar-width: none;
    /* Make sure the bar always claims a row even if it has no tabs yet. */
    min-height: 40px;
}
.portal-tab-bar::-webkit-scrollbar {
    display: none;
}

.portal-tab-list {
    display: flex;
    align-items: stretch;
    gap: 8px;
    padding: 0 0.5rem;
    margin: 0;
    /* Prevent tabs from collapsing under each other on narrow screens — they
       become horizontally scrollable instead. */
    width: max-content;
    min-width: 100%;
}

.portal-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 8px;
    font-size: 0.9rem;
    line-height: 1.2;
    white-space: nowrap;
    max-width: 240px;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    cursor: pointer;
}

.portal-tab:hover {
    background: var(--btn-hover-bg);
    color: var(--text);
    text-decoration: none;
}

.portal-tab:focus-visible {
    outline: 2px solid var(--link);
    outline-offset: -2px;
}

.portal-tab.active {
    color: var(--text);
    background: var(--bg);
    border-bottom-color: var(--link);
    font-weight: 600;
}

.portal-tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    /* Allow the label to shrink so the close button stays in view on
       long titles. */
    min-width: 0;
}

.portal-tab-close {
    background: transparent;
    border: 0;
    padding: 0.1rem 0.25rem;
    margin-right: -0.25rem;
    color: inherit;
    opacity: 0.55;
    line-height: 1;
    border-radius: 3px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Refined sizing: bi-x glyph at 1rem reads as a clean lightweight ×
       rather than the bolder bi-x-lg used previously. */
    font-size: 1rem;
    transition: color 0.15s ease, opacity 0.15s ease, background-color 0.15s ease;
}
.portal-tab-close:hover {
    opacity: 1;
    color: var(--bs-danger, #dc3545);
}
.portal-tab-close:focus-visible {
    opacity: 1;
    outline: 2px solid var(--link);
    outline-offset: 1px;
}

/* Mobile — slightly tighter padding, smaller max width so more tabs are
   visible at once. The bar stays horizontally scrollable. */
@media (max-width: 767.98px) {
    .portal-tab {
        max-width: 160px;
        padding: 0.45rem 0.7rem;
        font-size: 0.85rem;
    }
    .portal-tab-list {
        padding: 0 0.25rem;
    }
}
