/* ═══════════════════════════════════════════════════════════════════
   CIELUM SIDEBAR + PAGE HEADER
   ═══════════════════════════════════════════════════════════════════ */

:root {
    --sidebar-width-expanded: 250px;
    --sidebar-width-collapsed: 68px;
    --sidebar-bg: #ffffff;
    --sidebar-border: #f0f0f5;
    --sidebar-text: #4b5563;
    --sidebar-text-muted: #9ca3af;
    --sidebar-hover-bg: #f3f0ff;
    --sidebar-active-bg: #ede9fe;
    --sidebar-active-text: #5F2DEE;
    --sidebar-active-border: #5F2DEE;
    --sidebar-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR WRAPPER (handles width transition + toggle overflow)
   ══════════════════════════════════════════════════════════════════ */
.cielum-sidebar-wrapper {
    position: relative;
    width: var(--sidebar-width-expanded);
    min-width: var(--sidebar-width-expanded);
    height: 100vh;
    transition: width var(--sidebar-transition), min-width var(--sidebar-transition);
    flex-shrink: 0;
}

.cielum-sidebar-wrapper.collapsed {
    width: var(--sidebar-width-collapsed);
    min-width: var(--sidebar-width-collapsed);
}

/* ══════════════════════════════════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════════════════════════════════ */
.cielum-sidebar {
    width: 100%;
    height: 100%;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 40;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.03);
}

/* ── Header (Logo) ─────────────────────────────────────────────── */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 16px 16px;
    min-height: 64px;
    overflow: hidden;
}

.sidebar-logo {
    width: 36px;
    height: 36px;
    min-width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #5F2DEE 0%, #B882FC 100%);
    border-radius: 10px;
    padding: 6px;
}

.sidebar-logo-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: brightness(0) invert(1);
}

.sidebar-brand-text {
    font-size: 15px;
    font-weight: 700;
    color: #1f2937;
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s ease, width 0.3s ease;
}

.cielum-sidebar.collapsed .sidebar-brand-text {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

/* ── Toggle Button ─────────────────────────────────────────────── */
.sidebar-toggle {
    position: absolute;
    top: 28px;
    right: -14px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--sidebar-bg);
    border: 1.5px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    transition: box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    color: var(--sidebar-text-muted);
    font-size: 11px;
}

.sidebar-toggle:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
    box-shadow: 0 3px 12px rgba(95, 45, 238, 0.2);
    border-color: var(--sidebar-active-text);
}

.sidebar-toggle-icon {
    transition: transform var(--sidebar-transition);
}

.cielum-sidebar-wrapper.collapsed .sidebar-toggle-icon {
    transform: rotate(180deg);
}

/* ── Divider ───────────────────────────────────────────────────── */
.sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 6px 14px;
}

.cielum-sidebar.collapsed .sidebar-divider {
    margin: 6px 10px;
}

/* ── Navigation ────────────────────────────────────────────────── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 10px;
    scrollbar-width: thin;
    scrollbar-color: #e5e7eb transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: #e5e7eb;
    border-radius: 4px;
}

.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ── Section Title ─────────────────────────────────────────────── */
.sidebar-section-title {
    padding: 18px 12px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
}

.sidebar-section-text {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text-muted);
    white-space: nowrap;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.sidebar-section-dot {
    display: none;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sidebar-text-muted);
    margin: 0 auto;
}

.cielum-sidebar.collapsed .sidebar-section-text {
    opacity: 0;
    width: 0;
}

.cielum-sidebar.collapsed .sidebar-section-dot {
    display: block;
}

.cielum-sidebar.collapsed .sidebar-section-title {
    justify-content: center;
    padding: 14px 0 6px;
}

/* ── Menu Item ─────────────────────────────────────────────────── */
.sidebar-item { border-radius: 10px; overflow: hidden; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 10px;
    color: var(--sidebar-text);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.15s ease;
    text-align: left;
    position: relative;
    overflow: hidden;
}

.sidebar-link:hover {
    background: var(--sidebar-hover-bg);
    color: var(--sidebar-active-text);
}

.sidebar-item.active .sidebar-link {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.sidebar-item.active .sidebar-link::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 20px;
    background: var(--sidebar-active-border);
    border-radius: 0 3px 3px 0;
}

.sidebar-icon {
    width: 20px;
    min-width: 20px;
    text-align: center;
    font-size: 15px;
    opacity: 0.75;
    transition: opacity 0.15s ease;
}

.sidebar-item.active .sidebar-icon,
.sidebar-link:hover .sidebar-icon {
    opacity: 1;
}

.sidebar-label {
    opacity: 1;
    transition: opacity 0.2s ease, width 0.3s ease;
    overflow: hidden;
}

.cielum-sidebar.collapsed .sidebar-label {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

.cielum-sidebar.collapsed .sidebar-link {
    justify-content: center;
    padding: 10px 0;
    gap: 0;
}

.cielum-sidebar.collapsed .sidebar-item.active .sidebar-link::before {
    height: 16px;
}

.cielum-sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 20px 0 16px;
}

.cielum-sidebar.collapsed .sidebar-logo {
    margin: 0;
}

.cielum-sidebar.collapsed .sidebar-nav {
    padding: 8px 6px;
}

.cielum-sidebar.collapsed .sidebar-footer {
    padding: 8px 6px 16px;
}

.cielum-sidebar.collapsed .sidebar-divider {
    margin: 6px 8px;
}

/* ── Tooltips (collapsed) ──────────────────────────────────────── */
.cielum-sidebar.collapsed .sidebar-link[title]:hover::after {
    content: attr(title);
    position: absolute;
    left: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%);
    background: #1f2937;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: 8px;
    white-space: nowrap;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

.cielum-sidebar.collapsed .sidebar-link[title]:hover::before {
    content: '';
    position: absolute;
    left: calc(100% + 8px);
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-right-color: #1f2937;
    z-index: 9999;
    pointer-events: none;
}

/* ── Footer ────────────────────────────────────────────────────── */
.sidebar-footer {
    padding: 8px 10px 16px;
}

.sidebar-logout {
    color: #ef4444 !important;
}

.sidebar-logout:hover {
    background: #fef2f2 !important;
    color: #dc2626 !important;
}

/* ── Hidden ────────────────────────────────────────────────────── */
.sidebar-item.hidden,
.sidebar-section-title.hidden {
    display: none !important;
}

/* ══════════════════════════════════════════════════════════════════
   PAGE HEADER (dinámico por ruta)
   ══════════════════════════════════════════════════════════════════ */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: #fff;
    border-bottom: 1px solid #f0f0f5;
    min-height: 60px;
    flex-shrink: 0;
    gap: 16px;
}

.page-header-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.page-header-title {
    font-size: 16px;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}

.page-header-desc {
    font-size: 12px;
    color: #9ca3af;
    margin: 0;
}

.page-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* ── Tokens chip (header) ──────────────────────────────────────── */
.page-header-tokens {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    background: #f5f3ff;
    border: 1px solid #ede9fe;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 12px;
    font-weight: 600;
    color: var(--sidebar-active-text);
}

.page-header-tokens:hover {
    background: #ede9fe;
    border-color: #c4b5fd;
}

.page-header-tokens-icon {
    font-size: 12px;
}

.page-header-tokens-value {
    white-space: nowrap;
}

.page-header-tokens.tokens-warning {
    background: #fffbeb;
    border-color: #fde68a;
    color: #d97706;
}

.page-header-tokens.tokens-blocked {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
}

/* ── User chip (header) ────────────────────────────────────────── */
.page-header-user {
    position: relative;
}

.page-header-user-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px 5px 5px;
    border: 1px solid #f0f0f5;
    border-radius: 24px;
    background: #fff;
    cursor: pointer;
    transition: all 0.15s ease;
}

.page-header-user-btn:hover {
    border-color: #e5e7eb;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.page-header-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.page-header-user-name {
    font-size: 12px;
    font-weight: 600;
    color: #374151;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-header-user-badge {
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 10px;
    letter-spacing: 0.03em;
}

.page-header-chevron {
    font-size: 9px;
    color: #9ca3af;
    transition: transform 0.2s ease;
}

.page-header-chevron.rotate-180 {
    transform: rotate(180deg);
}

/* ── User dropdown ─────────────────────────────────────────────── */
.page-header-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: 220px;
    background: #fff;
    border: 1px solid #f0f0f5;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    z-index: 100;
    overflow: hidden;
}

.page-header-dropdown.hidden {
    display: none;
}

.page-header-dropdown-header {
    padding: 12px 14px;
    border-bottom: 1px solid #f5f5f5;
}

.page-header-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    font-size: 13px;
    color: #4b5563;
    border: none;
    background: none;
    cursor: pointer;
    text-align: left;
    transition: all 0.1s ease;
}

.page-header-dropdown-item:hover {
    background: #f3f0ff;
    color: var(--sidebar-active-text);
}

.page-header-dropdown-item i {
    width: 16px;
    text-align: center;
    font-size: 12px;
    opacity: 0.7;
}

.page-header-dropdown-danger {
    color: #ef4444;
}

.page-header-dropdown-danger:hover {
    background: #fef2f2;
    color: #dc2626;
}

.page-header-dropdown-divider {
    height: 1px;
    background: #f5f5f5;
}

/* ══════════════════════════════════════════════════════════════════
   RESPONSIVE
   ══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .cielum-sidebar-wrapper {
        position: fixed;
        left: 0;
        top: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform var(--sidebar-transition), width var(--sidebar-transition);
    }

    .cielum-sidebar-wrapper.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .cielum-sidebar-wrapper.collapsed {
        width: var(--sidebar-width-expanded);
        min-width: var(--sidebar-width-expanded);
    }

    .cielum-sidebar.collapsed .sidebar-label,
    .cielum-sidebar.collapsed .sidebar-brand-text,
    .cielum-sidebar.collapsed .sidebar-section-text {
        opacity: 1;
        width: auto;
        pointer-events: auto;
    }

    .cielum-sidebar.collapsed .sidebar-section-dot { display: none; }

    .cielum-sidebar.collapsed .sidebar-link {
        justify-content: flex-start;
        padding: 10px 14px;
    }

    .sidebar-toggle { display: none; }

    .sidebar-mobile-toggle { display: flex !important; }

    .sidebar-overlay { display: block !important; }

    .sidebar-overlay.active {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 90;
    }

    /* Header responsivo */
    .page-header { padding: 10px 16px; }
    .page-header-title { font-size: 14px; }
    .page-header-user-name { display: none; }
    .page-header-user-badge { display: none; }
}

@media (min-width: 769px) {
    .sidebar-mobile-toggle { display: none !important; }
    .sidebar-overlay { display: none !important; }
}
