/* Sidebar */
.sidebar {
    width: var(--sidebar-current-width);
    background: linear-gradient(180deg, var(--color-sidebar-from) 0%, var(--color-sidebar-to) 100%);
    color: white;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.25s ease, transform 0.25s ease;
}

html.sidebar-collapsed {
    --sidebar-current-width: var(--sidebar-width-collapsed);
}

.sidebar-toggle {
    position: fixed;
    top: 50%;
    left: calc(var(--sidebar-current-width) - 1px);
    transform: translateY(-50%);
    z-index: 1001;
    width: 22px;
    height: 56px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-left: none;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    background: linear-gradient(180deg, var(--color-sidebar-from) 0%, var(--color-sidebar-to) 100%);
    color: rgba(255, 255, 255, 0.72);
    box-shadow: 4px 0 16px rgba(15, 23, 42, 0.18);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition:
        left 0.25s ease,
        background 0.15s ease,
        color 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.15s ease;
}

.sidebar-toggle::before {
    content: '';
    position: absolute;
    left: 0;
    top: 14px;
    bottom: 14px;
    width: 2px;
    border-radius: 1px;
    background: var(--color-accent-hover);
    opacity: 0;
    transition: opacity 0.15s ease;
}

.sidebar-toggle:hover {
    background: linear-gradient(180deg, #1e293b 0%, #273548 100%);
    color: #fff;
    border-color: rgba(13, 148, 136, 0.45);
    box-shadow: 4px 0 20px rgba(15, 23, 42, 0.24);
}

.sidebar-toggle:hover::before,
html.sidebar-collapsed .sidebar-toggle::before {
    opacity: 1;
}

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--color-accent-hover);
    outline-offset: 2px;
}

.sidebar-toggle-icon {
    width: 15px;
    height: 15px;
    transition: transform 0.25s ease;
}

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

html.sidebar-collapsed .sidebar-toggle {
    left: 0;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 2px 0 12px rgba(15, 23, 42, 0.2);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.sidebar-content::-webkit-scrollbar {
    width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

.logo-container {
    flex-shrink: 0;
    padding: var(--space-6) var(--space-4);
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.15);
}

.logo-container img {
    max-width: 100%;
    max-height: 80px;
    object-fit: contain;
}

.logo-placeholder {
    width: 100%;
    height: 80px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px dashed rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.8125rem;
    text-align: center;
    padding: var(--space-2);
}

.logo-placeholder-mark {
    font-size: 0.6875rem;
    font-weight: var(--font-weight-semibold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: var(--space-1);
}

.sidebar-title {
    font-size: 1.0625rem;
    font-weight: var(--font-weight-semibold);
    margin-top: var(--space-4);
    color: white;
    letter-spacing: var(--letter-tight);
}

.nav-menu {
    padding: var(--space-2) 0;
    flex: 1;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: var(--space-2);
}

.nav-section-title {
    padding: var(--space-3) var(--space-6) var(--space-2);
    font-size: 0.6875rem;
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.4);
    margin-top: var(--space-2);
}

.nav-section-title:first-child {
    margin-top: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: var(--space-3) var(--space-6);
    color: rgba(255, 255, 255, 0.82);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    border-left: 3px solid transparent;
    font-size: 0.875rem;
    font-weight: var(--font-weight-medium);
    position: relative;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: white;
    border-left-color: var(--color-accent-hover);
}

.nav-item.active {
    background: var(--color-accent-soft);
    color: white;
    border-left-color: var(--color-accent);
    font-weight: var(--font-weight-semibold);
}

.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--color-accent);
}

.nav-item-sub {
    padding-left: 2.5rem;
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.65);
    padding-top: var(--space-2);
    padding-bottom: var(--space-2);
}

.nav-item-sub:hover {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.9);
}

.nav-item-sub.active {
    background: rgba(15, 118, 110, 0.15);
    color: white;
}

.nav-item--group {
    font-weight: var(--font-weight-medium);
    font-size: 0.875rem;
}

.nav-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: var(--space-3) var(--space-6);
}

.user-section {
    padding: var(--space-4) var(--space-6);
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
    margin-top: auto;
}

.user-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-3);
}

.user-name {
    font-size: 0.875rem;
    color: rgba(255, 255, 255, 0.95);
    font-weight: var(--font-weight-medium);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.logout-link {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 0.8125rem;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-sm);
    transition: background 0.15s ease, color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    background: rgba(255, 255, 255, 0.08);
    font-weight: var(--font-weight-medium);
}

.logout-link:hover {
    background: rgba(220, 38, 38, 0.25);
    color: white;
}

/* Top contextual nav */
.top-context-nav {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-context-nav__inner {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--space-2) var(--space-8);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-5);
}

.top-context-nav__group {
    font-size: 0.6875rem;
    font-weight: var(--font-weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-muted);
    flex-shrink: 0;
}

.top-context-nav__items {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    align-items: center;
}

.top-context-nav__items li {
    margin: 0;
    padding: 0;
    list-style: none;
}

.top-context-nav__items a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: var(--font-weight-medium);
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}

.top-context-nav__items a:hover {
    background: var(--color-border-light);
    color: var(--color-text);
}

.top-context-nav__items a.is-active {
    background: var(--color-accent-soft);
    color: var(--color-accent);
    font-weight: var(--font-weight-semibold);
}

/* Cofre layout */
.cofre-topbar {
    position: sticky;
    top: 0;
    z-index: 1200;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
}

.cofre-brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    text-decoration: none;
    color: var(--color-text);
    font-weight: var(--font-weight-bold);
    font-size: 0.875rem;
    flex-shrink: 0;
}

.cofre-brand img {
    height: 24px;
    width: auto;
    object-fit: contain;
}

.cofre-top-actions {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    flex-wrap: wrap;
}

.cofre-module-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    text-decoration: none;
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    border-radius: var(--radius-full);
    padding: var(--space-1) var(--space-3);
    font-size: 0.8125rem;
    font-weight: var(--font-weight-semibold);
    transition: background 0.15s ease, border-color 0.15s ease;
}

.cofre-module-link:hover {
    background: var(--color-bg);
}

.cofre-module-link.is-active {
    background: var(--color-sidebar-from);
    color: white;
    border-color: var(--color-sidebar-from);
}

.cofre-profile {
    position: relative;
    margin-left: var(--space-1);
}

.cofre-profile-btn {
    border: 1px solid var(--color-border);
    background: var(--color-bg);
    color: var(--color-text);
    border-radius: var(--radius-full);
    padding: var(--space-2) var(--space-3);
    font-size: 0.8125rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: var(--font-weight-medium);
}

.cofre-profile-menu {
    position: absolute;
    right: 0;
    top: calc(100% + var(--space-2));
    width: 260px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-3);
    display: none;
}

.cofre-profile-menu.is-open {
    display: block;
}

.cofre-profile-name {
    font-size: 0.875rem;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
}

.cofre-profile-email {
    font-size: 0.8125rem;
    color: var(--color-muted);
    margin-top: var(--space-1);
    word-break: break-all;
}

.cofre-profile-divider {
    height: 1px;
    background: var(--color-border);
    margin: var(--space-3) 0;
}

.cofre-profile-logout {
    display: inline-flex;
    width: 100%;
    justify-content: center;
    align-items: center;
    gap: var(--space-2);
    text-decoration: none;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    color: var(--color-danger);
    background: var(--color-danger-bg);
    border: 1px solid var(--color-danger-border);
    font-weight: var(--font-weight-semibold);
    font-size: 0.8125rem;
}

.cofre-app .sidebar {
    display: none;
}

.cofre-app {
    display: block;
    background: var(--color-bg);
}

.cofre-app .main-content {
    margin-left: 0;
    width: 100%;
    min-height: calc(100vh - 58px);
}

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-current-width);
    min-height: 100vh;
    transition: margin-left 0.25s ease;
}

.content-wrapper {
    padding: var(--space-8);
    max-width: var(--content-max-width);
    margin: 0 auto;
}

.page-header {
    background: var(--color-surface);
    padding: var(--space-6) var(--space-8);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    margin-bottom: var(--space-8);
    border: 1px solid var(--color-border-light);
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: var(--font-weight-semibold);
}

/* Responsive */
@media (max-width: 768px) {
    html.sidebar-collapsed {
        --sidebar-current-width: 0px;
    }

    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(0);
    }

    html.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }

    .sidebar-toggle {
        left: 0;
        top: 50%;
        transform: translateY(-50%);
    }

    html:not(.sidebar-collapsed) .sidebar-toggle {
        left: calc(var(--sidebar-width) - 1px);
    }

    .main-content {
        margin-left: 0;
    }

    .content-wrapper {
        padding: var(--space-4);
    }

    .top-context-nav__inner {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }

    .cofre-topbar {
        flex-wrap: wrap;
        padding: var(--space-2) var(--space-3);
        gap: var(--space-2);
    }

    .cofre-brand {
        order: 1;
        width: 100%;
        justify-content: center;
    }

    .cofre-top-actions {
        order: 2;
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        overflow: visible;
        padding-bottom: var(--space-1);
    }

    .cofre-module-link {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .cofre-profile {
        order: 3;
        margin-left: 0;
        flex: 0 0 auto;
    }

    .cofre-top-actions .cofre-module-link {
        order: 2;
    }

    .cofre-profile-btn {
        padding: var(--space-1) var(--space-3);
        font-size: 0.8125rem;
    }

    .cofre-module-link--2fa .cofre-module-label,
    .cofre-profile-btn .cofre-profile-label {
        display: none;
    }

    .cofre-module-link--2fa,
    .cofre-profile-btn {
        min-width: 38px;
        justify-content: center;
        padding-left: var(--space-2);
        padding-right: var(--space-2);
    }

    .cofre-profile-menu {
        right: 0;
        left: auto;
        width: min(88vw, 280px);
    }
}
