/* ==========================================
   TABS SYSTEM - Premium Aesthetics
   ========================================== */

.tabs-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
    background: var(--bg-primary);
    overflow: hidden;
}

.tab-strip {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 0.5rem;
    gap: 2px;
    overflow-x: auto;
    scrollbar-width: none;
    /* Firefox */
    height: 40px;
    align-items: flex-end;
    user-select: none;
}

.tab-strip::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.tab-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    height: 34px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-family: var(--font-ui);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    /* Comportement flexible intelligent */
    flex: 0 1 auto;
    width: 200px;
    /* Largeur cible */
    min-width: 80px;
    max-width: 240px;
}

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

.tab-item.active {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-color: var(--border-color);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
    z-index: 10;
    font-weight: 500;
}

.tab-item.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--bg-primary);
}

.tab-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--primary-color);
    border-radius: 6px 6px 0 0;
}

.tab-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

.tab-item.active .tab-icon {
    opacity: 1;
    color: var(--primary-color);
}

.tab-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    opacity: 0;
    transition: all 0.2s;
    margin-right: -4px;
}

.tab-item:hover .tab-close {
    opacity: 0.5;
}

.tab-close:hover {
    opacity: 1 !important;
    background: var(--bg-hover);
    color: var(--status-error);
}

.tab-tour {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 4px;
    opacity: 0.4;
    transition: all 0.2s;
    margin-right: 2px;
}

.tab-tour:hover {
    opacity: 1 !important;
    background: var(--bg-hover);
    color: var(--primary-color);
}

.tab-content-area {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
}

/* Split view integration */
.split-view-tabs {
    display: flex;
    width: 100%;
    height: 100%;
}

.split-pane {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.split-pane.active .tab-strip {
    background: var(--bg-tertiary);
}

.split-pane.active .tab-item.active::before {
    background: var(--primary-color);
}

.split-pane:not(.active) .tab-item.active::before {
    background: var(--text-muted);
    opacity: 0.5;
}

/* Tab Preset Button & Menu */
.tab-preset-wrapper {
    display: flex;
    align-items: center;
    padding: 0 4px;
    margin-left: auto;
    flex-shrink: 0;
}

.tab-preset-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.tab-preset-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.tab-preset-menu {
    position: fixed;
    min-width: 200px;
    max-width: 280px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 10001;
    padding: 4px;
    animation: tabPresetMenuAppear 0.15s ease-out;
}

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

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

.tab-preset-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: background 0.15s ease;
}

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

.tab-preset-menu-item.tab-preset-save {
    color: var(--primary-color);
}

.tab-preset-menu-item span {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tab-preset-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s ease;
}

.tab-preset-menu-item:hover .tab-preset-delete {
    opacity: 0.6;
}

.tab-preset-delete:hover {
    opacity: 1 !important;
    background: var(--bg-hover);
    color: var(--status-error);
}

.tab-preset-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 8px;
}

.tab-preset-menu-empty {
    padding: 12px 10px;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    font-style: italic;
}

/* Animations */
@keyframes tabAppear {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

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

.tab-item {
    animation: tabAppear 0.2s ease-out;
}

/* Sidebar integration for tabs */
.treeview-item {
    position: relative;
    padding-right: 45px !important;
    /* Juste assez pour le compteur au repos */
    width: 100% !important;
    min-height: 32px;
    /* Force l'étirement sur toute la sidebar */
    display: flex !important;
    align-items: center;
    justify-content: flex-start;
    box-sizing: border-box;
}

.treeview-item-actions {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    /* Alignés à droite */
    gap: 4px;
    /* Espacement entre les boutons */
    height: 100%;
    opacity: 0;
    pointer-events: none;
    z-index: 10001 !important;
    background: transparent;
    transition: opacity 0.1s ease;
    width: auto;
    /* Largeur automatique selon le contenu */
}

/* La ligne survolée passe au-dessus de TOUT */
.treeview-item:hover,
.act-header:hover,
.chapter-header:hover,
.scene-item:hover {
    z-index: 100 !important;
}

/* Visibilité des boutons dès le survol de la ligne */
.treeview-item:hover .treeview-action-btn,
.act-header:hover .treeview-action-btn,
.chapter-header:hover .treeview-action-btn,
.scene-item:hover .treeview-action-btn {
    opacity: 1 !important;
    visibility: visible !important;
    transform: none;
    /* Pas de scale */
    pointer-events: auto !important;
}

/* Visibilité du conteneur d'actions et activation des clics */
.treeview-item:hover .treeview-item-actions,
.act-header:hover .treeview-item-actions,
.chapter-header:hover .treeview-item-actions,
.scene-item:hover .treeview-item-actions {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    /* On réactive les clics au survol */
}

/* COMPTEUR DE MOTS AU REPOS : Bien calé à droite */
.word-count-badge {
    position: absolute !important;
    right: 4px !important;
    margin: 0 !important;
    /* On annule les marges inline JS */
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    /* Ne pas gêner le clic */
}

/* MASQUAGE DU COMPTEUR DE MOTS AU SURVOL (Pour éviter la superposition) */
.treeview-item:hover .word-count-badge,
.act-header:hover .word-count-badge,
.chapter-header:hover .word-count-badge,
.scene-item:hover .word-count-badge {
    opacity: 0 !important;
    transition: opacity 0.1s;
}

/* Style des boutons - SIMPLES ET EFFICACES */
.treeview-action-btn {
    position: relative !important;
    /* Plus d'absolu */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 4px;
    /* Carrés arrondis plus classiques */
    border: none;
    background: var(--bg-secondary);
    /* Fond opaque pour masquer le texte en dessous */
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    opacity: 1;
    /* Toujours visibles dans leur conteneur */
    transform: none !important;
    /* Plus de scale */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    /* Légère ombre pour détacher du fond */
    padding: 0;
    margin: 0;
}

.treeview-action-btn:hover {
    background: var(--primary-color);
    color: white !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.treeview-action-btn.delete:hover {
    background: var(--error-color, #dc2626);
    color: white !important;
}

/* Poignée de drag-and-drop intégrée au flux (STYLE IDENTIQUE) */
.drag-handle {
    position: absolute !important;
    right: 96px;
    /* Alignement calé : 4px (marge) + 86px (groupe boutons) + 6px (gap) */
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    /* Identique */
    height: 26px;
    /* Identique */
    border-radius: 4px;
    /* Identique */
    background: var(--bg-secondary);
    /* Identique */
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    /* Identique */
    color: var(--text-muted);
    cursor: grab;
    opacity: 0;
    z-index: 10002;
    transition: all 0.2s ease;
}

/* Apparition au survol */
.treeview-item:hover .drag-handle,
.act-header:hover .drag-handle,
.chapter-header:hover .drag-handle,
.scene-item:hover .drag-handle {
    opacity: 1 !important;
    pointer-events: auto;
}

.drag-handle:hover {
    background: var(--primary-color);
    color: white !important;
    transform: translateY(calc(-50% - 1px)) !important;
    /* Soulèvement tout en gardant le centrage */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.drag-handle:active {
    cursor: grabbing;
}

.treeview-action-btn i,
.drag-handle i {
    width: 14px;
    height: 14px;
}