/*
 * tab-bar.css
 * ─────────────────────────────────────────────────────────────────────────────
 * Reusable horizontal tab bar component with dropdown group support.
 * Fully dark/light mode aware. Works in iframes and scrollable containers.
 *
 * Deploy to : /include/styles/tab-bar.css
 * Include in: /views/layout/page_foot.inc
 *
 * MARKUP PATTERN:
 * ───────────────
 * <div class="tab-bar" id="myTabs" data-target="#my-content">
 *
 *   <!-- Standalone tab (no dropdown) -->
 *   <a class="tb-tab active" href="" data-tab="home">
 *     <i class="fa fa-home"></i> Home
 *   </a>
 *
 *   <!-- Dropdown group -->
 *   <div class="tb-dropdown">
 *     <span class="tb-group">
 *       <i class="fa fa-list"></i> Section Name
 *     </span>
 *     <div class="tb-menu">
 *       <a href="page1.asp" data-tab="page1">
 *         <i class="fa fa-file fa-fw"></i> Page One
 *       </a>
 *       <a href="page2.asp" data-tab="page2">
 *         <i class="fa fa-file fa-fw"></i> Page Two
 *       </a>
 *     </div>
 *   </div>
 *
 * </div>
 *
 * <!-- Content container (id must match data-target on tab-bar) -->
 * <div id="my-content" class="tb-content"></div>
 *
 * OPTIONS (data attributes on .tab-bar):
 *   data-target   = "#selector" of the content container (required)
 *   data-mode     = "ajax" (default) | "hash" (no AJAX, just anchor links)
 * ─────────────────────────────────────────────────────────────────────────────
 */

/* ── Tab bar container ── */
.tab-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    overflow-x: auto;
    overflow-y: visible;
    background: var(--dm-surface, #181c27);
    border-bottom: 2px solid var(--dm-border, #272d3d);
    scrollbar-width: none;
    -ms-overflow-style: none;
    position: sticky;
    top: 0;
    z-index: 50;
}

html.light-mode .tab-bar {
    background: #ffffff;
    border-bottom: 2px solid #dde2ee;
}

.tab-bar::-webkit-scrollbar {
    display: none;
}

/* ── Standalone tab ── */
.tab-bar .tb-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 18px;
    min-height: 44px;
    font-size: .82rem;
    font-weight: 500;
    color: var(--dm-text-muted, #94a3b8) !important;
    text-decoration: none !important;
    white-space: nowrap;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    flex-shrink: 0;
    transition: color .15s, border-color .15s, background .15s;
}

    .tab-bar .tb-tab:hover {
        color: var(--dm-text, #e2e8f0) !important;
        background: rgba(255,255,255,.04);
    }

html.light-mode .tab-bar .tb-tab:hover {
    color: #1e2535 !important;
    background: #f4f6fb;
}

.tab-bar .tb-tab.active {
    color: var(--dm-accent, #4f8ef7) !important;
    border-bottom: 3px solid var(--dm-accent, #4f8ef7);
    background: rgba(79,142,247,.06);
}

html.light-mode .tab-bar .tb-tab.active {
    color: #2563eb !important;
    border-color: #2563eb;
    background: rgba(37,99,235,.05);
}

/* ── Dropdown wrapper ── */
.tab-bar .tb-dropdown {
    position: relative;
    display: flex;
    align-items: stretch;
    flex-shrink: 0;
}

/* ── Dropdown group trigger ── */
.tab-bar .tb-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 18px;
    min-height: 44px;
    font-size: .82rem;
    font-weight: 500;
    letter-spacing: normal;
    text-transform: none;
    color: var(--dm-text-muted, #64748b);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, background .15s, border-color .15s;
}

    .tab-bar .tb-group::after {
        content: '';
        display: inline-block;
        width: 0;
        height: 0;
        margin-left: 5px;
        border-left: 4px solid transparent;
        border-right: 4px solid transparent;
        border-top: 5px solid currentColor;
        transition: transform .2s;
        flex-shrink: 0;
    }

.tab-bar .tb-dropdown.open .tb-group::after {
    transform: rotate(180deg);
}

.tab-bar .tb-group:hover {
    color: var(--dm-text, #e2e8f0);
    background: rgba(255,255,255,.04);
}

html.light-mode .tab-bar .tb-group:hover {
    color: #1e2535;
    background: #f4f6fb;
}

/* Active group — a child item is currently selected */
.tab-bar .tb-group.active {
    color: var(--dm-accent, #4f8ef7) !important;
    border-bottom: 3px solid var(--dm-accent, #4f8ef7);
    background: rgba(79,142,247,.06);
}

html.light-mode .tab-bar .tb-group.active {
    color: #2563eb !important;
    border-color: #2563eb;
    background: rgba(37,99,235,.05);
}

/* ── Dropdown menu — uses fixed positioning to escape overflow:hidden ── */
.tab-bar .tb-menu {
    display: none;
    position: fixed; /* escapes overflow:auto on tab-bar */
    z-index: 9999;
    min-width: 220px;
    background: var(--dm-surface, #181c27);
    border: 1px solid var(--dm-border, #272d3d);
    border-top: none;
    border-radius: 0 0 10px 10px;
    box-shadow: 0 12px 32px rgba(0,0,0,.4);
    padding: 4px 0;
    /* top/left set by JS when opened */
}

html.light-mode .tab-bar .tb-menu {
    background: #ffffff;
    border-color: #dde2ee;
    box-shadow: 0 12px 32px rgba(0,0,0,.12);
}

.tab-bar .tb-dropdown.open .tb-menu {
    display: block;
    animation: tbMenuIn .15s ease;
}

@keyframes tbMenuIn {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Dropdown menu items — no icons ── */
.tab-bar .tb-menu a {
    display: flex;
    align-items: center;
    padding: 9px 18px;
    font-size: .82rem;
    font-weight: 400;
    color: var(--dm-text, #e2e8f0) !important;
    text-decoration: none !important;
    white-space: nowrap;
    transition: background .12s, color .12s, padding-left .12s;
    border-left: 3px solid transparent;
}

    /* Hide any icons inside menu items */
    .tab-bar .tb-menu a i,
    .tab-bar .tb-menu a .fa {
        display: none !important;
    }

    .tab-bar .tb-menu a:hover {
        background: rgba(79,142,247,.08) !important;
        color: var(--dm-accent, #4f8ef7) !important;
        padding-left: 22px;
    }

html.light-mode .tab-bar .tb-menu a:hover {
    background: #eef1f8 !important;
    color: #2563eb !important;
}

.tab-bar .tb-menu a.active {
    background: rgba(79,142,247,.1) !important;
    color: var(--dm-accent, #4f8ef7) !important;
    border-left: 3px solid var(--dm-accent, #4f8ef7);
    font-weight: 600;
    padding-left: 15px;
}

html.light-mode .tab-bar .tb-menu a.active {
    background: rgba(37,99,235,.07) !important;
    color: #2563eb !important;
    border-color: #2563eb;
}

/* ── Spacer — pushes everything after it to the right ── */
/* Usage: <span class="tb-spacer"></span> */
.tab-bar .tb-spacer {
    flex: 1;
}

/* ── Divider inside dropdown ── */
.tab-bar .tb-menu hr,
.tab-bar .tb-divider {
    margin: 4px 0;
    border: none;
    border-top: 1px solid var(--dm-border, #272d3d);
}

html.light-mode .tab-bar .tb-menu hr,
html.light-mode .tab-bar .tb-divider {
    border-color: #dde2ee;
}

/* ── Section label inside dropdown (non-clickable sub-header) ── */
.tab-bar .tb-menu-label {
    display: block;
    padding: 6px 18px 2px;
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--dm-accent, #4f8ef7);
    pointer-events: none;
}

/* ── Content container ── */
.tb-content {
    min-height: 400px;
    padding: 16px 0;
}

    /* Loading bar animation */
    .tb-content.tb-loading::before {
        content: '';
        display: block;
        height: 3px;
        background: linear-gradient(90deg, transparent 0%, var(--dm-accent, #4f8ef7) 50%, transparent 100%);
        background-size: 200% 100%;
        animation: tbLoadBar 1.1s infinite linear;
        border-radius: 2px;
        margin-bottom: 12px;
    }

@keyframes tbLoadBar {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .tab-bar .tb-group {
        padding: 0 10px;
        font-size: .7rem;
    }

    .tab-bar .tb-tab {
        padding: 0 10px;
        font-size: .78rem;
    }

    .tab-bar .tb-menu {
        min-width: 180px;
    }
}
