/* ==========================================================================
   1. VARIABLES (Chrome Dark Mode Replica)
   ========================================================================== */
:root {
    --chrome-divider: var(--mud-palette-lines-default);
    /* Tab Colors */
    --tab-text-inactive: var(--mud-palette-text-default); /* Muted Text */
    --tab-text-active: var(--mud-palette-primary); /* Bright White Text */
    /* Active Tab (The "Island") */
    --tab-active-bg: var(--mud-palette-background); /* Lighter grey for active tab */
    --tab-hover-bg: var(--mud-palette-action-default-hover); /* Subtle hover state */
    /* Dimensions */
    --header-height: var(--t-appbar-height);
    --tab-height: 36px; /* Compact floating pills */
    --tab-radius: var(--t-border-radius); /* Rounded corners like Chrome 2023 */
    --tab-gap: 6px; /* Gap between tabs */
    --tab-preferred: 240px; /* Preferred tab width (like Chrome) */
    --tab-hard-min: 120px; /* Minimum tab width before overflow */
    --tab-max: 320px; /* Maximum tab width */
}

/* ==========================================================================
   2. HEADER CONTAINER
   ========================================================================== */
#branding_header {
    background-color: var(--mud-palette-appbar-background) !important;
    height: var(--header-height);
    display: flex;
    align-items: center; /* Vertically center everything */
    padding: 0 8px;
    /* No bottom border - The header blends with the app */
    border-bottom: 1px solid var(--mud-palette-lines-default);
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: 20;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.header-content {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    gap: 12px;
}

/* ==========================================================================
   3. TAB BAR AREA
   ========================================================================== */
.header-middle {
    flex-grow: 1;
    display: flex;
    align-items: center;
    height: 100%;
    overflow: hidden;
}

.tl-tabs {
    width: 100%;
}

    .tl-tabs .tl-tabs-toolbar-wrapper {
        display: flex;
        align-items: center;
        gap: var(--tab-gap); /* Gap between tabs */
    }

    .tl-tabs-toolbar-content {
        flex: 1;
        min-width: 0;
        overflow: hidden;
    }

    .tl-tabs-actions {
        display: flex;
        gap: var(--tab-gap);
        flex-shrink: 0;
    }

    /* ==========================================================================
   4. INDIVIDUAL TABS
   ========================================================================== */
    .tl-tabs .tl-tab {
        display: flex;
        align-items: center;
        gap: 6px;
        height: var(--tab-height);
        padding: 0 8px 0 10px;
        margin-bottom: 0;
        /* Shape: Rounded Pill */
        border-radius: var(--tab-radius);
        /* Default / Inactive State */
        background-color: transparent;
        border: 1px solid transparent;
        font-size: 12px;
        font-weight: 500;
        cursor: pointer;
        user-select: none;
        transition: background-color 0.1s; /* Removed width transition - causes lag */
        position: relative; /* For the separator line */
        flex-shrink: 0; /* Prevent tabs from shrinking individually */
        flex-shrink: 0; /* Prevent tabs from shrinking */
        margin: 4px 0;
    }

    /* Use dynamic width when in equal mode */
    .tl-tabs[data-equal="1"] .tl-tabs-toolbar-wrapper > .tl-tab {
        width: var(--tab-equal-per, var(--tab-preferred));
        min-width: var(--tab-hard-min);
        max-width: var(--tab-max);
    }

    /* Tab icon - fixed size */
    .tl-tab-icon {
        flex-shrink: 0;
    }

    /* Tab text container - takes remaining space */
    .tl-tab-text {
        flex: 1;
        min-width: 0; /* Critical for text truncation to work */
        overflow: hidden;
    }

    /* When equal width is enabled, use the calculated width */
    .tl-tabs[data-equal="1"] .tl-tab {
        width: var(--tab-equal-per);
        min-width: var(--tab-equal-per);
        max-width: var(--tab-equal-per);
    }

        /* Hover State */
        .tl-tabs .tl-tab:hover {
            background-color: var(--tab-hover-bg);
            color: var(--tab-text-active);
        }

        /* --- THE CHROME SEPARATOR LINES --- */
        /* Add a vertical line after every inactive tab */
        .tl-tabs .tl-tab:not(.tl-tab-active)::after {
            content: "";
            position: absolute;
            right: -4px; /* Position in the gap */
            top: 10%;
            bottom: 10%;
            width: 1px;
            background-color: var(--mud-palette-lines-default);
            opacity: 0.6;
            pointer-events: none;
        }

        /* Hide separator if the NEXT tab is active or hovered (Clean look) */
        .tl-tabs .tl-tab:has(+ .tl-tab-active)::after {
            display: none;
        }

    /* --- ACTIVE TAB (The Highlighted Pill) --- */
    .tl-tabs .tl-tab-active {
        /* Distinct background color */
        background-color: var(--tab-active-bg) !important;
        color: var(--tab-text-active) !important;
        /* Remove separator for active tab */
        z-index: 1;
        box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    }

/* Remove separator on the tab immediately BEFORE the active one (Browser support varies, but safe to ignore) */

/* ==========================================================================
   5. TAB INTERNALS
   ========================================================================== */
.tl-tab-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tl-tab-sub {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 11px;
    opacity: 0.7;
}

.tl-tabs-add .mud-button-text {
    text-transform: none !important;
    margin-left: 6px;
    margin-right: 12px;
}

/* Close Button (X) - Only visible on Hover/Active */
.close-button-wrap {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    opacity: 0; /* Hidden by default */
    flex-shrink: 0; /* Don't shrink */
    transition: opacity 0.2s;
}

.tl-tab:hover .close-button-wrap,
.tl-tab-active .close-button-wrap {
    opacity: 1;
}

.close-button {
    padding: 0;
    font-size: 14px;
    color: inherit;
    opacity: 0.7;
}

    .close-button:hover {
        background-color: var(--mud-palette-actions-default);
        opacity: 1;
    }

/* Action Buttons (Mer and Ny) - Styling */
.tl-tabs-more, .tl-tabs-add {
    height: var(--tab-height);
    min-height: var(--tab-height);
    border-radius: var(--tab-radius);
}

.tl-tabs-more .mud-button-root,
.tl-tabs-add .mud-button-root {
    height: var(--tab-height);
    min-height: var(--tab-height);
    text-transform: none;
    font-size: 12px;
    font-weight: 500;
    border-radius: var(--tab-radius);
}

.tl-tabs-more .mud-button-root:hover,
.tl-tabs-add .mud-button-root:hover {
    background-color: var(--tab-hover-bg);
}

.tl-tabs-more .mud-button-label,
.tl-tabs-add .mud-button-label {
    display: flex;
    align-items: center;
}

/* ==========================================================================
   ADDED: EDITED MARK STYLES
   ========================================================================== */

/* 1. Base wrapper styles - Hidden by default */
.edited-mark-wrap {
    display: none; /* Don't take up space normally */
    width: 16px;
    height: 16px;
    align-items: center;
    justify-content: center;
    flex-shrink: 0; /* Don't shrink */
}

/* 2. The Dot itself */
.edited-mark {
    width: 8px;
    height: 8px;
    background-color: var(--mud-palette-primary); /* or --mud-palette-primary for a colored dot */
    border-radius: 50%;
    display: block;
}

/* 3. WHEN MODIFIED: Show the mark */
.tl-tab[data-modified="true"] .edited-mark-wrap {
    display: flex;
}

/* 4. WHEN MODIFIED: Hide the close button placeholder to prevent double spacing */
.tl-tab[data-modified="true"] .close-button-wrap {
    display: none;
}

/* 5. HOVER STATE: The "Swap" Logic */
/* When hovering a modified tab, HIDE the dot and SHOW the close button */
.tl-tab[data-modified="true"]:hover .edited-mark-wrap {
    display: none;
}

.tl-tab[data-modified="true"]:hover .close-button-wrap {
    display: flex; /* Bring back the close button container */
    opacity: 1; /* Make sure it's visible */
}


/* ==========================================================================
   6. HEADER RIGHT (Icons Area)
   ========================================================================== */
.header-right {
    position: relative; /* REQUIRED: Anchors the ::before element */
    flex-shrink: 0;
    height: 36px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-left: 12px; /* Keeps space between the line and the content */
    /* Remove the old border */
    border-left: none;
}

    .header-right::before {
        content: "";
        position: absolute;
        left: 0; /* anchors it to the left edge of the .header-right padding box */
        /* Control the height of the line here */
        top: 15%;
        bottom: 15%;
        width: 1px;
        background-color: var(--mud-palette-lines-default);
        opacity: 0.6;
        pointer-events: none;
    }

    /* Fix Icon Buttons */
    .header-right .mud-icon-button {
        padding: 6px;
    }


/* ==========================================================================
   7. DRAG & DROP FIXES
   ========================================================================== */

/* The global cursor when dragging */
.is-dragging {
    cursor: grabbing !important;
    user-select: none;
}

/* THE DRAGGED TAB ITSELF */
.tl-tab.tl-dragging {
    /* 1. Force Solid Background (Fixes the see-through text issue) */
    background-color: var(--tab-active-bg) !important;
    color: var(--tab-text-active) !important;
    opacity: 1 !important;
    /* 2. Float above everything else */
    z-index: 9999 !important;
    position: relative;
    /* 3. "Lifted" Card Effect */
    box-shadow: 0 8px 20px rgba(0,0,0,0.6) !important;
    border: 1px solid var(--mud-palette-lines-default); /* Subtle highlight border */
    border-radius: var(--tab-radius);
    /* 4. Disable mouse interactions on the dragged item itself */
    pointer-events: none;
    cursor: grabbing;
}

/* ==========================================================================
   8. OVERFLOW MENU STYLES
   ========================================================================== */

/* 1. The Popover Container */
.tl-tabs-overflow-popover .mud-popover-paper {
    min-width: 240px;
    max-width: 300px;
    background-color: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    padding: 4px 0; /* Small vertical padding for the list */
}

/* 2. The MudMenuItem (container) */
.tl-tabs-overflow-popover .mud-list-item {
    min-height: 40px; /* Slightly taller for menu feel */
    margin: 0;
}

/* 3. The Tab Instance INSIDE the Menu */
.tl-tabs-overflow-popover .tl-tab {
    width: 100%;
    height: 100%;
    min-height: 40px;
    margin: 0;
    padding: 0 16px;
    display: flex;
    border-radius: 0;
    background-color: transparent !important;
    border: none;
    color: var(--mud-palette-text-primary);
    justify-content: center;
    align-items: center;
    gap: 12px;
}

    /* 4. Active State inside Menu */
    .tl-tabs-overflow-popover .tl-tab.tl-tab-active {
        background-color: var(--mud-palette-primary-hover) !important; /* Light highlight */
        color: var(--mud-palette-primary) !important;
        font-weight: bold;
        box-shadow: none; /* Remove the "pill" shadow */
    }

    /* 5. Hide the Separator lines inside the menu */
    .tl-tabs-overflow-popover .tl-tab::after {
        display: none !important;
    }

/* 6. Layout adjustments for text inside menu */
.tl-tabs-overflow-popover .tl-tab-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
    line-height: 1.2;
}

/* 7. Button Visibility in Menu */
.tl-tabs-overflow-popover .tl-tab .close-button-wrap {
    opacity: 0.5; /* Always slightly visible in menu */
    display: flex;
    margin-left: auto; /* Push to far right */
}

.tl-tabs-overflow-popover .tl-tab:hover .close-button-wrap {
    opacity: 1;
}

/* Hide edit mark wrapper in menu to prevent alignment issues, 
   switch purely to bold text or color for modified items if needed */
.tl-tabs-overflow-popover .tl-tab[data-modified="true"] .edited-mark-wrap {
    display: flex;
    margin-right: 8px; /* Move dot to the left of close button */
}