﻿/*
 * The tab shell: the bar across the top, the tabs in it, their overflow menu and the panes below.
 *
 * Every colour here is a token, set once per theme at the top of the file, and the rules below
 * read those tokens and nothing else. It used to be the other way round: the rules carried the
 * colours as literals behind a var() that was never defined, repeated per theme, and a second
 * stylesheet repeated the same selectors again with a different set of literals. That is how the
 * bar and the tab on it ended up nearly the same shade of white, with the tab in front reading as
 * the faintest thing in the row.
 */
:root {
    --tab-bar-bg: #e4e8ee;
    --tab-bar-border: var(--bs-border-color);
    --tab-bg: #d7dde5;
    --tab-bg-hover: #e9edf2;
    --tab-bg-active: #ffffff;
    --tab-border: var(--bs-border-color);
    --tab-border-active: var(--bs-border-color);
    --tab-accent: var(--color-primary);
    --tab-text: #47566a;
    --tab-text-active: var(--color-primary);
    --tab-close: var(--status-idle);
    --tab-close-hover-bg: var(--status-bad);
    --tab-close-hover-text: #ffffff;
    --tab-scrollbar-thumb: #cbd5e1;
    --tab-drag-outline: var(--color-secondary-medium);
    --tab-active-lift: 0 -2px 6px rgba(0, 35, 63, 0.12);
    --tab-menu-bg: var(--bs-body-bg);
    --tab-menu-border: var(--bs-border-color);
    --tab-menu-text: var(--bs-body-color);
    --tab-menu-hover-bg: var(--color-secondary-light);
    --tab-menu-shadow: 0 12px 24px rgba(0, 35, 63, 0.18);
}

html[data-bs-theme="dark"],
html[class*="-dark"] {
    --tab-bar-bg: rgba(255, 255, 255, 0.04);
    --tab-bar-border: rgba(255, 255, 255, 0.14);
    --tab-bg: rgba(255, 255, 255, 0.07);
    --tab-bg-hover: rgba(255, 255, 255, 0.11);
    --tab-bg-active: rgba(255, 255, 255, 0.16);
    --tab-border: rgba(255, 255, 255, 0.12);
    --tab-border-active: rgba(255, 255, 255, 0.24);
    --tab-accent: var(--color-secondary);
    --tab-text: rgba(255, 255, 255, 0.72);
    --tab-text-active: #ffffff;
    --tab-scrollbar-thumb: rgba(255, 255, 255, 0.24);
    --tab-active-lift: none;
    --tab-menu-shadow: 0 12px 24px rgba(0, 0, 0, 0.5);
}

/* ---- the bar ---- */
.tab-bar {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: stretch;
    background: var(--tab-bar-bg);
    border-bottom: 1px solid var(--tab-bar-border);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/*
 * A collapsed sidebar widens over the page while the pointer is on it, which puts it right where
 * the tab bar is. The theme leaves the sidebar at 11, far under the bar above, so the menu opened
 * underneath it and the reader saw tabs through their own menu. It belongs just above the bar and
 * deliberately no higher: dialogs open around 1050 and have to keep covering everything.
 */
aside.s-sidebar {
    z-index: 1001;
}

.tab-list {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: flex-end;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--tab-scrollbar-thumb) transparent;
    padding: 0 8px;
    gap: 2px;
    min-height: 42px;
}

.tab-list::-webkit-scrollbar {
    height: 6px;
}

.tab-list::-webkit-scrollbar-track {
    background: transparent;
}

.tab-list::-webkit-scrollbar-thumb {
    background: var(--tab-scrollbar-thumb);
    border-radius: 3px;
}

/* ---- one tab ---- */
.tab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px 8px 12px;
    background: var(--tab-bg);
    color: var(--tab-text);
    border: 1px solid var(--tab-border);
    border-bottom: none;
    border-top: 3px solid transparent;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    min-width: 120px;
    max-width: 240px;
    position: relative;
    transition: all 0.2s ease;
    margin-top: 4px;
}

.tab-item:hover {
    background: var(--tab-bg-hover);
}

/* The tab in front carries the house colour on its top edge and sits a shade lighter than the bar
   it stands on. Those two together are what make it read as the one you are looking at. */
.tab-item.active {
    background: var(--tab-bg-active);
    border-color: var(--tab-border-active);
    border-top-color: var(--tab-accent);
    box-shadow: var(--tab-active-lift);
    z-index: 10;
    margin-top: 0;
    padding-top: 10px;
}

.tab-item.dragging {
    opacity: 0.6;
    transform: scale(0.98);
}

.tab-item.drag-over {
    border-color: var(--tab-border-active);
    box-shadow: inset 0 0 0 2px var(--tab-drag-outline);
}

.tab-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
    color: var(--tab-text);
    font-weight: 500;
}

.tab-item.active .tab-title {
    color: var(--tab-text-active);
    font-weight: 700;
}

.tab-close {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--tab-close);
    font-size: 13px;
    line-height: 1;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.tab-close:hover {
    background: var(--tab-close-hover-bg);
    color: var(--tab-close-hover-text);
}

/* ---- the panes ---- */
.s-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.tab-containers {
    width: 100%;
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.tab-container {
    width: 100%;
    height: 100%;
    display: none;
    overflow: auto;
    position: absolute;
    top: 0;
    left: 0;
}

.tab-container[style*="display: block"],
.tab-container.active {
    display: block !important;
}

.tab-iframe {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
}

/* ---- the menus: right click on a tab, and the overflow button at the end of the bar ---- */
.tab-context-menu,
.tab-overflow-menu {
    position: fixed;
    background: var(--tab-menu-bg);
    color: var(--tab-menu-text);
    border: 1px solid var(--tab-menu-border);
    border-radius: 8px;
    box-shadow: var(--tab-menu-shadow);
    padding: 6px;
    font-size: 13px;
}

.tab-context-menu {
    min-width: 160px;
    z-index: 10001;
}

.tab-overflow-menu {
    min-width: 220px;
    max-height: 60vh;
    overflow-y: auto;
    z-index: 1300;
}

.tab-context-item,
.tab-overflow-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px 10px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--tab-menu-text);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-context-item:hover,
.tab-overflow-item:hover {
    background: var(--tab-menu-hover-bg);
}

.tab-overflow-item.active {
    font-weight: 700;
    box-shadow: inset 3px 0 0 var(--tab-accent);
}

.tab-overflow-button {
    flex: none;
    align-self: center;
    margin: 0 8px;
    padding: 4px 10px;
    font-size: 12.5px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--tab-menu-text);
    background: var(--tab-menu-bg);
    border: 1px solid var(--tab-menu-border);
    border-radius: 999px;
    cursor: pointer;
}

.tab-overflow-button:hover {
    border-color: var(--tab-accent);
}
