/* =============================================================================
   iView Learning — Global Site Tab Bar
   Browser-style persistent tabs across the whole platform
   Version: 1.0  |  February 2026
   ============================================================================= */

/* ───────────────────────────────────────────────────────────────────────────
   TAB BAR CONTAINER
   Sits sticky just under the fixed top navbar (height ~80px).
   ─────────────────────────────────────────────────────────────────────────── */
#site-tab-bar {
    position: fixed;
    top: 80px;                            /* JS overrides with live navbar height */
    left: 260px;                          /* JS overrides with live sidebar width  */
    right: 0;
    z-index: 98;                          /* just below iq-top-navbar (99) */
    background: var(--bg-secondary, #F8FAFC);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
    display: flex;
    align-items: center;
    height: 42px;
    padding: 0;
    overflow: hidden;
}

/* Sidebar collapses/overlays at medium breakpoint */
@media (max-width: 1299px) {
    #site-tab-bar {
        top: 100px;
        left: 0;
    }
}

@media (max-width: 991px) {
    #site-tab-bar {
        top: 90px;
        left: 0;
    }
}

/* ── Scrollable inner list ── */
#site-tab-list {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 4px;
    padding: 0 8px;
}

#site-tab-list::-webkit-scrollbar { display: none; }

/* ── Spacer to push right-hand actions to the end ── */
#site-tab-bar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px 0 8px;
    border-left: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    background: var(--bg-secondary, #F8FAFC);
}

/* ───────────────────────────────────────────────────────────────────────────
   INDIVIDUAL TAB
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 10px 0 12px;
    height: 32px;
    margin: 0;
    border: 1px solid transparent;
    border-radius: var(--radius-lg, 12px);
    background: transparent;
    color: var(--text-secondary, #50646A);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none !important;
    transition: color var(--transition-fast, 150ms), background var(--transition-fast, 150ms),
        box-shadow var(--transition-fast, 150ms), border-color var(--transition-fast, 150ms);
    flex-shrink: 0;
    max-width: 240px;
    position: relative;
    user-select: none;
    /* Opaque tab background, reused by the hover action overlay */
    --site-tab-bg: var(--bg-secondary, #F8FAFC);
}

.site-tab:hover {
    color: var(--brand-primary, #12807C);
    --site-tab-bg: color-mix(in srgb, var(--brand-primary, #12807C) 8%, var(--bg-secondary, #F8FAFC));
    background: var(--site-tab-bg);
    text-decoration: none !important;
}

.site-tab.active {
    color: var(--brand-primary, #12807C);
    font-weight: 600;
    --site-tab-bg: #FFFFFF;
    background: var(--site-tab-bg);
    border-color: rgba(18, 128, 124, 0.12);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
}

/* Active tab keeps its close button visible, so reserve room for it */
.site-tab.active:not(.pinned) {
    padding-right: 30px;
}

/* ── Tab Label (truncating — uses all available width in the tab) ── */
.site-tab-label {
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Action buttons overlay (pop-out / close) ──
   Floats over the end of the tab on hover so it doesn't steal label width. */
.site-tab-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    gap: 2px;
    padding: 0 6px 0 18px;
    border-radius: 0 var(--radius-lg, 12px) var(--radius-lg, 12px) 0;
    background: linear-gradient(to right, transparent, var(--site-tab-bg) 16px);
}

.site-tab:hover .site-tab-actions,
.site-tab:focus-within .site-tab-actions,
.site-tab.active:not(.pinned) .site-tab-actions {
    display: inline-flex;
}

/* Active tab (not hovered) shows only its close button */
.site-tab.active:not(:hover):not(:focus-within) .site-tab-popout {
    display: none;
}

.site-tab.active:not(:hover):not(:focus-within) .site-tab-actions {
    padding-left: 0;
    background: transparent;
}

/* ── Tab Icon ── */
.site-tab-icon {
    flex-shrink: 0;
    font-size: 0.85rem;
    color: inherit;
    opacity: 0.8;
}

.site-tab.active .site-tab-icon { opacity: 1; }

/* ── Close Button ── */
.site-tab-close {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-full, 50%);
    border: none;
    background: transparent;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.62rem;
    color: var(--neutral-500, #9BA4BA);
    cursor: pointer;
    transition: background var(--transition-fast, 150ms), color var(--transition-fast, 150ms);
    line-height: 1;
}

.site-tab-close:hover {
    background: rgba(239, 68, 68, 0.12);
    color: var(--error, #EF4444);
}

/* ── Pop-out Button ── */
.site-tab-popout {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    border-radius: var(--radius-full, 50%);
    border: none;
    background: transparent;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: var(--neutral-500, #9BA4BA);
    cursor: pointer;
    transition: background var(--transition-fast, 150ms), color var(--transition-fast, 150ms);
    line-height: 1;
}

.site-tab-popout:hover {
    background: var(--hover-overlay, rgba(18, 128, 124, 0.12));
    color: var(--brand-primary, #12807C);
}

/* ── Group color indicator on tab ── */
.site-tab.has-group::before {
    content: '';
    position: absolute;
    top: 6px;
    left: 4px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--tab-group-color, transparent);
}

.site-tab.has-group {
    padding-left: 16px;
}

/* ───────────────────────────────────────────────────────────────────────────
   TAB CONTEXT MENU  — right-click to add/remove from group
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab-ctx {
    position: fixed;
    z-index: 1100;
    min-width: 180px;
    max-width: 240px;
    background: #FFFFFF;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
    font-size: 0.78rem;
    padding: 4px 0;
    display: none;
    animation: sgpIn 0.12s ease;
}

.site-tab-ctx.open { display: block; }

.stc-label {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #9CA3AF;
    padding: 6px 12px 4px;
}

.stc-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none;
    background: transparent;
    padding: 6px 12px;
    font-size: 0.78rem;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    text-align: left;
    transition: background 0.1s;
}

.stc-item:hover { background: #F3F4F6; }

.stc-item.stc-active { font-weight: 600; }

.stc-item.stc-remove { color: #EF4444; }
.stc-item.stc-remove:hover { background: rgba(239, 68, 68, 0.08); }

.stc-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.stc-check {
    margin-left: auto;
    font-size: 0.65rem;
    color: var(--brand-primary, #12807C);
}

.stc-divider {
    height: 1px;
    background: rgba(0, 0, 0, 0.06);
    margin: 4px 0;
}

/* ── Add-tab button in groups panel ── */
.sgp-add-tab-btn {
    border: 1px solid #D1D5DB;
    background: transparent;
    color: #6B7280;
    border-radius: 5px;
    padding: 3px 7px;
    font-size: 0.65rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    white-space: nowrap;
}

.sgp-add-tab-btn:hover {
    background: var(--brand-primary, #12807C);
    color: #FFFFFF;
    border-color: var(--brand-primary, #12807C);
}

/* ───────────────────────────────────────────────────────────────────────────
   PINNED (HOME) TAB — always first, no close button
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab.pinned .site-tab-close { display: none; }
.site-tab.pinned {
    padding: 0 14px;
    min-width: 38px;
    color: var(--brand-primary, #12807C);
}

.site-tab.pinned .site-tab-icon { opacity: 1; }

/* ───────────────────────────────────────────────────────────────────────────
   ACTION BUTTONS (right side of bar)
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-md, 8px);
    border: none;
    background: transparent;
    color: var(--neutral-600, #64748B);
    cursor: pointer;
    font-size: 0.95rem;
    transition: background var(--transition-fast, 150ms), color var(--transition-fast, 150ms);
    flex-shrink: 0;
}

.site-tab-action-btn:hover,
.site-tab-action-btn:focus-visible {
    background: var(--hover-overlay, rgba(18, 128, 124, 0.08));
    color: var(--brand-primary, #12807C);
}

#site-tabs-close-all:hover,
#site-tabs-close-all:focus-visible {
    background: rgba(239, 68, 68, 0.08);
    color: var(--error, #EF4444);
}

/* ── Scroll arrows (only shown when tabs overflow) ── */
.site-tab-scroll-btn {
    margin: 0 2px;
    font-size: 1rem;
}

.site-tab-scroll-btn[hidden] { display: none; }

.site-tab-scroll-btn:disabled {
    opacity: 0.35;
    cursor: default;
    background: transparent;
    color: var(--neutral-600, #64748B);
}

/* ── Tab count badge ── */
.site-tab-count {
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--neutral-500, #9BA4BA);
    min-width: 20px;
    text-align: center;
    display: none; /* shown on overflow */
}

/* ───────────────────────────────────────────────────────────────────────────
   CONTENT-PAGE TOP PADDING COMPENSATION
   After inserting the 42px tab bar, we push content down so it isn't hidden.
   ─────────────────────────────────────────────────────────────────────────── */
#content-page.has-site-tabs {
    padding-top: calc(80px + 42px) !important;  /* navbar (80px) + tab bar (42px) */
}

@media (max-width: 1299px) {
    #content-page.has-site-tabs { padding-top: calc(100px + 42px) !important; }
}

@media (max-width: 991px) {
    #content-page.has-site-tabs { padding-top: calc(90px + 42px) !important; }
}

/* ───────────────────────────────────────────────────────────────────────────
   STUDY-SKILLS PAGES: push ss-tab-bar down to clear site-tab-bar
   ─────────────────────────────────────────────────────────────────────────── */
body.has-site-tabs #ss-tab-bar {
    top: calc(80px + 42px);              /* navbar + site tab bar */
}

@media (max-width: 1299px) {
    body.has-site-tabs #ss-tab-bar { top: calc(100px + 42px); }
}

@media (max-width: 991px) {
    body.has-site-tabs #ss-tab-bar { top: calc(90px + 42px); }
}

/* ───────────────────────────────────────────────────────────────────────────
   ENTER ANIMATION
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab {
    animation: siteTabIn 0.12s ease;
}

@keyframes siteTabIn {
    from { opacity: 0; transform: translateX(-5px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ───────────────────────────────────────────────────────────────────────────
   MOBILE — stack-friendly
   ─────────────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .site-tab { padding: 0 8px; max-width: 150px; }
    .site-tab-action-btn { width: 22px; height: 22px; }
}

/* ───────────────────────────────────────────────────────────────────────────
   TAB GROUPS PANEL
   Dropdown that appears below the groups button in the action area.
   ─────────────────────────────────────────────────────────────────────────── */
#site-groups-panel {
    position: fixed;
    top: calc(80px + 42px + 4px);   /* navbar + tab bar + gap; JS overrides if needed */
    right: 8px;
    z-index: 1050;                   /* above Notes & Bookmarks sidebar (900) */
    width: 300px;
    background: #FFFFFF;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    font-size: 0.8rem;
    overflow: hidden;
    display: none;
    flex-direction: column;
    animation: sgpIn 0.15s ease;
}

#site-groups-panel.open {
    display: flex;
}

@keyframes sgpIn {
    from { opacity: 0; transform: translateY(-6px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}

/* ── Panel header ── */
.sgp-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    background: #F9FAFB;
}

.sgp-title {
    font-weight: 700;
    font-size: 0.8rem;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sgp-title i {
    color: var(--brand-primary, #12807C);
}

.sgp-close-btn {
    border: none;
    background: transparent;
    color: #9CA3AF;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background 0.12s, color 0.12s;
}

.sgp-close-btn:hover {
    background: rgba(0,0,0,0.06);
    color: #374151;
}

/* ── Inner sections ── */
.sgp-section {
    padding: 10px 12px;
}

.sgp-saved-section {
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    max-height: 220px;
    overflow-y: auto;
    scrollbar-width: thin;
}

.sgp-section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #9CA3AF;
    margin-bottom: 8px;
}

/* ── Save row: input + button ── */
.sgp-save-row {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.sgp-input {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, 0.12);
    border-radius: 6px;
    padding: 5px 9px;
    font-size: 0.78rem;
    color: #374151;
    outline: none;
    transition: border-color 0.12s;
    background: #F9FAFB;
}

.sgp-input:focus {
    border-color: var(--brand-primary, #12807C);
    background: #FFFFFF;
}

.sgp-save-btn {
    border: none;
    background: var(--brand-primary, #12807C);
    color: #FFFFFF;
    border-radius: 6px;
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: filter 0.12s;
}

.sgp-save-btn:hover { filter: brightness(0.88); }

/* ── Color swatches ── */
.sgp-colors {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.sgp-color-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
    flex-shrink: 0;
}

.sgp-color-swatch:hover { transform: scale(1.2); }

.sgp-color-swatch.selected {
    border-color: rgba(0, 0, 0, 0.35);
    transform: scale(1.15);
}

/* ── Tab count hint ── */
.sgp-tab-preview {
    margin-top: 2px;
}

.sgp-empty-hint {
    font-size: 0.72rem;
    color: #9CA3AF;
    font-style: italic;
}

/* ── Saved group rows ── */
.sgp-group-row {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.sgp-group-row:last-child { border-bottom: none; }

.sgp-group-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sgp-group-name {
    flex: 1;
    font-weight: 600;
    color: #374151;
    font-size: 0.78rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sgp-group-count {
    font-size: 0.7rem;
    color: #9CA3AF;
    flex-shrink: 0;
}

.sgp-open-btn {
    border: 1px solid var(--brand-primary, #12807C);
    background: transparent;
    color: var(--brand-primary, #12807C);
    border-radius: 5px;
    padding: 3px 9px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.12s, color 0.12s;
    white-space: nowrap;
}

.sgp-open-btn:hover {
    background: var(--brand-primary, #12807C);
    color: #FFFFFF;
}

.sgp-del-btn {
    border: none;
    background: transparent;
    color: #D1D5DB;
    cursor: pointer;
    font-size: 0.7rem;
    padding: 3px 5px;
    border-radius: 4px;
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
}

.sgp-del-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #EF4444;
}
