/* Estilos Principales */
.top-header {
    height: var(--header-height);
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0.5rem;
    position: sticky;
    top: 0;
    z-index: 40;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toggle-sidebar-btn {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.75rem;
}

.content-wrapper {
    padding: 0.5rem;
    flex: 1;
    width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}

/* Tabs System */
.tabs-container {
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - 1rem);
    width: 100%;
    box-sizing: border-box;
}

.tabs-header {
    display: flex;
    background-color: var(--bg-body);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

/* ── Variables pastel por posición (modo claro) ── */
.tabs-header .tab-item {
    --tab-pastel-bg: #f4f5f7;
    --tab-pastel-border: #d8dce2;
    --tab-pastel-active-bg: #e9edf3;
}
.tabs-header .tab-item:nth-child(6n + 1) {
    --tab-pastel-bg: #fce8ef;
    --tab-pastel-border: #efc8d8;
    --tab-pastel-active-bg: #f8d6e5;
}
.tabs-header .tab-item:nth-child(6n + 2) {
    --tab-pastel-bg: #fff2df;
    --tab-pastel-border: #f1ddbd;
    --tab-pastel-active-bg: #ffe8ca;
}
.tabs-header .tab-item:nth-child(6n + 3) {
    --tab-pastel-bg: #e9f7ec;
    --tab-pastel-border: #cce7d4;
    --tab-pastel-active-bg: #d8efdf;
}
.tabs-header .tab-item:nth-child(6n + 4) {
    --tab-pastel-bg: #e8f4ff;
    --tab-pastel-border: #c9dff5;
    --tab-pastel-active-bg: #d8eafb;
}
.tabs-header .tab-item:nth-child(6n + 5) {
    --tab-pastel-bg: #efeafe;
    --tab-pastel-border: #d7cdf5;
    --tab-pastel-active-bg: #e3dbfb;
}
.tabs-header .tab-item:nth-child(6n) {
    --tab-pastel-bg: #e7f8f6;
    --tab-pastel-border: #c5e5df;
    --tab-pastel-active-bg: #d6efeb;
}

/* ── Variables pastel en modo oscuro ── */
[data-theme="dark"] .tabs-header .tab-item {
    --tab-pastel-bg: #243042;
    --tab-pastel-border: #3a4b63;
    --tab-pastel-active-bg: #2d3b52;
}
[data-theme="dark"] .tabs-header .tab-item:nth-child(6n + 1) {
    --tab-pastel-bg: #3d2f43;
    --tab-pastel-border: #58456a;
    --tab-pastel-active-bg: #4a3954;
}
[data-theme="dark"] .tabs-header .tab-item:nth-child(6n + 2) {
    --tab-pastel-bg: #443a2e;
    --tab-pastel-border: #625241;
    --tab-pastel-active-bg: #534737;
}
[data-theme="dark"] .tabs-header .tab-item:nth-child(6n + 3) {
    --tab-pastel-bg: #2f4336;
    --tab-pastel-border: #45624f;
    --tab-pastel-active-bg: #385240;
}
[data-theme="dark"] .tabs-header .tab-item:nth-child(6n + 4) {
    --tab-pastel-bg: #2d3f4f;
    --tab-pastel-border: #435f78;
    --tab-pastel-active-bg: #355069;
}
[data-theme="dark"] .tabs-header .tab-item:nth-child(6n + 5) {
    --tab-pastel-bg: #353549;
    --tab-pastel-border: #50506e;
    --tab-pastel-active-bg: #43435b;
}
[data-theme="dark"] .tabs-header .tab-item:nth-child(6n) {
    --tab-pastel-bg: #2b4342;
    --tab-pastel-border: #416362;
    --tab-pastel-active-bg: #335453;
}

.tab-item {
    padding: 0.35rem 0.6rem;
    cursor: pointer;
    border-right: 1px solid var(--border-color);
    background-color: var(--tab-pastel-bg, var(--bg-body));
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 110px;
    justify-content: space-between;
    user-select: none;
    font-size: 0.875rem;
    position: relative;
    transition: background-color 0.2s, filter 0.2s, box-shadow 0.2s, transform 0.2s;
}

.tab-item:hover:not(.active) {
    filter: brightness(0.98);
    transform: translateY(-1px);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18), 0 6px 14px rgba(15, 23, 42, 0.08);
}

.tab-item.active {
    background-color: var(--tab-pastel-active-bg, var(--bg-card));
    border-bottom: 3px solid var(--primary-color);
    font-weight: 700;
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.24), 0 -2px 6px rgba(0,0,0,0.05);
}

.tab-item.active::after {
    content: '';
    position: absolute;
    left: 0.45rem;
    top: 50%;
    width: 0.42rem;
    height: 0.42rem;
    border-radius: 999px;
    background: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.14);
    transform: translateY(-50%);
}

.tab-item.active {
    padding-left: 1.15rem;
}

.tab-item:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.28), 0 0 0 3px rgba(37, 99, 235, 0.16);
}

/* ── Pastel desactivado: vuelve al estilo plano original ── */
:root[data-pastel-tabs="off"] .tabs-header .tab-item {
    background-color: var(--bg-body) !important;
}
:root[data-pastel-tabs="off"] .tabs-header .tab-item.active {
    background-color: var(--bg-card) !important;
    box-shadow: none;
}

.tab-close {
    font-size: 0.8rem;
    opacity: 0.5;
    border-radius: 50%;
    width: 14px;
    height: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tab-close:hover {
    opacity: 1;
    background-color: rgba(0,0,0,0.1);
}

.tabs-content {
    flex: 1;
    padding: var(--spacing-md);
    overflow-y: auto;
    position: relative;
    overflow-x: hidden;
}

.tab-pane {
    display: none;
    height: 100%;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 768px) {
    .top-header {
        min-height: var(--header-height);
        height: auto;
        padding: 0.45rem 0.65rem calc(0.4rem + env(safe-area-inset-bottom, 0px));
        gap: 0.45rem;
        flex-wrap: wrap;
        backdrop-filter: blur(12px);
        background-color: rgba(255, 255, 255, 0.92);
        background-color: color-mix(in srgb, var(--bg-header) 88%, transparent);
    }

    .header-left,
    .header-right {
        min-width: 0;
    }

    .header-right {
        flex: 1;
        justify-content: flex-end;
    }

    .toggle-sidebar-btn {
        min-width: 40px;
        min-height: 40px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        border-radius: 999px;
    }

    #page-title {
        font-size: 0.98rem;
        max-width: 58vw;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.2;
    }

    .user-profile {
        max-width: 38vw;
        min-height: 40px;
        padding: 0.1rem 0.35rem;
        border-radius: 999px;
        background: var(--bg-body);
    }

    .user-profile span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .content-wrapper {
        padding: 0.45rem;
        padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    }

    .tabs-container {
        height: calc(100vh - var(--header-height) - 0.95rem);
        height: calc(100dvh - var(--header-height) - 0.95rem - env(safe-area-inset-bottom, 0px));
        border-radius: 1rem;
    }

    .tabs-header {
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        scrollbar-width: thin;
        padding: 0.2rem 0.2rem 0;
        gap: 0.2rem;
    }

    .tabs-content {
        padding: 0.55rem;
        overscroll-behavior: contain;
    }

    .tab-item {
        min-width: 136px;
        min-height: 42px;
        scroll-snap-align: start;
        border-right: 0;
        border-radius: 0.8rem 0.8rem 0 0;
        box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.18);
    }

    .tab-close {
        width: 18px;
        height: 18px;
        font-size: 0.9rem;
    }

    .tab-pane {
        height: auto;
        min-height: 100%;
    }
}

@media (min-width: 1024px) {
    .top-header {
        padding: 0 0.4rem;
    }

    .content-wrapper {
        padding: 0.35rem;
    }

    .tabs-container {
        height: calc(100vh - var(--header-height) - 0.7rem);
    }

    .tabs-header {
        min-height: 34px;
    }

    .tab-item {
        padding: 0.24rem 0.55rem;
        min-width: 98px;
        font-size: 0.82rem;
        line-height: 1.1;
    }

    .tabs-content {
        padding: 0.55rem;
    }
}
