/* ========== BROWSER-LIKE TAB SYSTEM ========== */

/* Tab-Leiste Container */
.tab-bar {
    background: linear-gradient(to bottom, #f8f9fa, #e9ecef);
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: flex-end;
    padding: 6px 12px 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    min-height: 42px;
}

.tab-bar::-webkit-scrollbar {
    height: 4px;
}

.tab-bar::-webkit-scrollbar-thumb {
    background: #adb5bd;
    border-radius: 2px;
}

/* Einzelner Tab */
.browser-tab {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    margin-right: 2px;
    background: #dee2e6;
    border: 1px solid #ced4da;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    max-width: 200px;
    min-width: 100px;
    white-space: nowrap;
    font-size: 0.875rem;
    transition: all 0.15s ease;
    user-select: none;
    position: relative;
    bottom: -1px;
}

.browser-tab:hover {
    background: #f8f9fa;
}

.browser-tab.active {
    background: #fff;
    border-bottom-color: #fff;
    z-index: 1;
}

/* Tab-Titel */
.browser-tab .tab-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    color: #495057;
}

.browser-tab.active .tab-title {
    color: #212529;
    font-weight: 500;
}

/* Tab-Schließen Button */
.browser-tab .tab-close {
    margin-left: 8px;
    border: none;
    background: transparent;
    color: #6c757d;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1;
    opacity: 0.6;
    transition: all 0.15s;
}

.browser-tab:hover .tab-close {
    opacity: 1;
}

.browser-tab .tab-close:hover {
    background: #dc3545;
    color: white;
    opacity: 1;
}

/* Loading Spinner im Tab */
.browser-tab .tab-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #0d6efd;
    border-top-color: transparent;
    border-radius: 50%;
    animation: tab-spin 0.6s linear infinite;
    margin-right: 8px;
    display: none;
}

.browser-tab.loading .tab-spinner {
    display: inline-block;
}

.browser-tab.loading .tab-title {
    color: #6c757d;
}

@keyframes tab-spin {
    to { transform: rotate(360deg); }
}

/* Neuer Tab Button */
.tab-new-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px dashed #adb5bd;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    color: #6c757d;
    cursor: pointer;
    margin-left: 4px;
    font-size: 14px;
    transition: all 0.15s;
    position: relative;
    bottom: -1px;
}

.tab-new-btn:hover {
    background: #f8f9fa;
    border-style: solid;
    color: #495057;
}

/* Alle Tabs schließen Button */
.tab-close-all-btn {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid #dc3545;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    color: #dc3545;
    cursor: pointer;
    margin-right: 8px;
    font-size: 12px;
    transition: all 0.15s;
    position: relative;
    bottom: -1px;
    white-space: nowrap;
}

.tab-close-all-btn:hover {
    background: #dc3545;
    color: white;
}

/* Tab Content Container */
.tab-content-area {
    background: #fff;
    min-height: calc(100vh - 120px);
    position: relative;
}

/*
 * Tab-Area leicht anheben, damit Modals *innerhalb* der Pane nicht hinter dem Backdrop kleben.
 * Body-Modals (Bootstrap: Backdrop 1050, Dialog 1055) müssen aber *über* der Tab-Area (1060) liegen,
 * sonst liegt der gesamte Tab-Inhalt optisch über Dialog/Backdrop (falsch positioniert / „im Hintergrund“).
 */
body.modal-open .tab-content-area {
    z-index: 1060;
}

body.modal-open .modal-backdrop {
    z-index: 1065 !important;
}

body.modal-open .modal {
    z-index: 1070 !important;
}

/* Einzelne Tab-Pane */
.tab-pane {
    display: none;
    padding: 0;
}

.tab-pane.active {
    display: block;
}

/* Loading Overlay für Tab-Content */
.tab-pane .loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.tab-pane .loading-overlay .spinner-border {
    width: 3rem;
    height: 3rem;
}

/* Verstecke normalen Content wenn Tabs aktiv */
body.tabs-active .no-tabs-content {
    display: none !important;
}

/* Zeige Tabs nur wenn aktiviert */
body:not(.tabs-active) .tab-bar,
body:not(.tabs-active) .tab-content-area {
    display: none !important;
}

/* Responsive: Tabs scrollen auf kleinen Bildschirmen */
@media (max-width: 768px) {
    .browser-tab {
        min-width: 80px;
        max-width: 150px;
        padding: 6px 10px;
    }
    
    .browser-tab .tab-title {
        font-size: 0.8rem;
    }
}
