/* =============================================================================
   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: #FFFFFF;
    border-bottom: 1px solid rgba(0, 0, 0, 0.07);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: stretch;
    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: stretch;
    flex: 1 1 auto;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    gap: 1px;
    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 4px;
    border-left: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    background: #FFFFFF;
}

/* ───────────────────────────────────────────────────────────────────────────
   INDIVIDUAL TAB
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    height: 100%;
    border: none;
    background: transparent;
    color: #6B7280;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none !important;
    border-bottom: 3px solid transparent;
    border-top: 3px solid transparent;     /* balance the bottom border visually */
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    flex-shrink: 0;
    max-width: 180px;
    position: relative;
    user-select: none;
}

.site-tab:hover {
    color: var(--brand-primary, #5057BE);
    background: rgba(80, 87, 190, 0.05);
    text-decoration: none !important;
}

.site-tab.active {
    color: var(--brand-primary, #5057BE);
    border-bottom-color: var(--brand-primary, #5057BE);
    border-top-color: transparent;
    font-weight: 600;
    background: rgba(80, 87, 190, 0.06);
}

/* ── Tab Label (truncating) ── */
.site-tab-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 120px;
}

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

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

/* ── Close Button ── */
.site-tab-close {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: none;
    background: transparent;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: #9CA3AF;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s;
    line-height: 1;
}

.site-tab:hover .site-tab-close,
.site-tab.active .site-tab-close {
    opacity: 1;
}

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

/* ── Pop-out Button ── */
.site-tab-popout {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: none;
    background: transparent;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    color: #9CA3AF;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s;
    line-height: 1;
}

.site-tab:hover .site-tab-popout,
.site-tab.active .site-tab-popout {
    opacity: 1;
}

.site-tab-popout:hover {
    background: rgba(80, 87, 190, 0.12);
    color: var(--brand-primary, #5057BE);
}

/* ── Separator between tabs ── */
.site-tab::before {
    content: '';
    position: absolute;
    right: 0;
    top: 25%;
    height: 50%;
    width: 1px;
    background: rgba(0,0,0,0.07);
}

.site-tab:last-child::before,
.site-tab.active::before,
.site-tab:hover + .site-tab::before { display: none; }

/* ── Group color indicator on tab ── */
.site-tab.has-group {
    border-top: 3px solid var(--tab-group-color, transparent);
}

.site-tab.has-group.active {
    border-top-color: var(--tab-group-color, transparent);
}

/* ───────────────────────────────────────────────────────────────────────────
   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, #5057BE);
}

.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, #5057BE);
    color: #FFFFFF;
    border-color: var(--brand-primary, #5057BE);
}

/* ───────────────────────────────────────────────────────────────────────────
   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;
}

/* ───────────────────────────────────────────────────────────────────────────
   ACTION BUTTONS (right side of bar)
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #9CA3AF;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
}

.site-tab-action-btn:hover {
    background: rgba(80, 87, 190, 0.08);
    color: var(--brand-primary, #5057BE);
}

/* ── Tab count badge ── */
.site-tab-count {
    font-size: 0.65rem;
    font-weight: 700;
    color: #9CA3AF;
    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: 120px; }
    .site-tab-label { max-width: 80px; }
    .site-tab-action-btn { width: 22px; height: 22px; }
}

/* ───────────────────────────────────────────────────────────────────────────
   HIDE WHEN ADMIN MODE
   ─────────────────────────────────────────────────────────────────────────── */
body.admin-view #site-tab-bar { display: none; }

/* ───────────────────────────────────────────────────────────────────────────
   SPLIT VIEW BUTTON  (per-tab, appears on hover like popout/close)
   ─────────────────────────────────────────────────────────────────────────── */
.site-tab-split {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: none;
    background: transparent;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.55rem;
    color: #9CA3AF;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s, color 0.12s;
    line-height: 1;
}

.site-tab:hover .site-tab-split,
.site-tab.active .site-tab-split {
    opacity: 1;
}

.site-tab-split:hover,
.site-tab-split.active {
    background: rgba(13, 148, 136, 0.12);
    color: #0D9488;
    opacity: 1;
}

/* Tab that is currently open in the split panel gets a teal underline accent */
.site-tab.split-open {
    border-bottom-color: #0D9488;
}

/* ───────────────────────────────────────────────────────────────────────────
   SPLIT PANEL  (iframe panel on the right half of the content area)
   ─────────────────────────────────────────────────────────────────────────── */
#site-split-panel {
    position: fixed;
    /* left/top/right/bottom all set by JS positionSplitPanel() */
    z-index: 97; /* below tab bar (98) */
    display: flex;
    flex-direction: column;
    background: #F3F4F6;
    border-left: 2px solid #0D9488;
    box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
    animation: splitPanelIn 0.2s ease;
}

@keyframes splitPanelIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ── Split panel header ── */
#site-split-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 10px;
    height: 36px;
    background: #FFFFFF;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

#site-split-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.78rem;
    font-weight: 600;
    color: #374151;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#site-split-title i {
    color: #0D9488;
    font-size: 0.72rem;
    flex-shrink: 0;
}

#site-split-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.site-split-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 5px;
    border: none;
    background: transparent;
    color: #9CA3AF;
    cursor: pointer;
    font-size: 0.72rem;
    text-decoration: none !important;
    transition: background 0.12s, color 0.12s;
}

.site-split-action-btn:hover {
    background: rgba(0, 0, 0, 0.07);
    color: #374151;
}

/* ── The iframe itself fills remaining height ── */
#site-split-frame {
    flex: 1 1 auto;
    width: 100%;
    border: none;
    background: #FFFFFF;
}

/* ── Main content area narrows when split is active (JS also sets padding-right) ── */
body.site-split-active #content-page {
    transition: padding-right 0.2s ease;
}

/* ───────────────────────────────────────────────────────────────────────────
   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, #5057BE);
}

.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, #5057BE);
    background: #FFFFFF;
}

.sgp-save-btn {
    border: none;
    background: var(--brand-primary, #5057BE);
    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, #5057BE);
    background: transparent;
    color: var(--brand-primary, #5057BE);
    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, #5057BE);
    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;
}
