/* =====================================================
   LAYOUT - Grid Principal del Dashboard
   ===================================================== */

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-primary);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* ── App Container ── */
.app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: width var(--transition-base), min-width var(--transition-base);
    z-index: 100;
}

.sidebar__header {
    padding: var(--space-5) var(--space-5);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    border-bottom: 1px solid var(--border-color);
    height: var(--topbar-height);
    flex-shrink: 0;
}

.sidebar__logo {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-bold);
    font-size: var(--fs-md);
    color: white;
    flex-shrink: 0;
}

.sidebar__logo-img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.sidebar__title {
    font-size: var(--fs-md);
    font-weight: var(--fw-bold);
    white-space: nowrap;
    overflow: hidden;
}

.sidebar__nav {
    padding: var(--space-4) var(--space-3);
    flex-shrink: 0;
}

.sidebar__nav-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-1);
}

.sidebar__nav-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--fs-base);
    margin-bottom: 2px;
    user-select: none;
}

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

.sidebar__nav-item.active {
    background: var(--accent-light);
    color: var(--accent-hover);
}

.sidebar__nav-item .icon {
    width: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Sidebar Submenu Animations ── */
.sidebar__submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease,
                padding 0.3s ease;
    opacity: 0;
    padding-left: 32px;
}

.sidebar__submenu.open {
    max-height: 200px;
    opacity: 1;
}

.sidebar__nav-subitem {
    font-size: var(--fs-sm);
    padding: 6px var(--space-2);
    margin-bottom: 1px;
    opacity: 0;
    transform: translateX(-8px);
    transition: opacity 0.25s ease, transform 0.25s ease, background 0.15s ease;
}

.sidebar__submenu.open .sidebar__nav-subitem:nth-child(1) {
    opacity: 0.85;
    transform: translateX(0);
    transition-delay: 0.05s;
}
.sidebar__submenu.open .sidebar__nav-subitem:nth-child(2) {
    opacity: 0.85;
    transform: translateX(0);
    transition-delay: 0.1s;
}
.sidebar__submenu.open .sidebar__nav-subitem:nth-child(3) {
    opacity: 0.85;
    transform: translateX(0);
    transition-delay: 0.15s;
}

.sidebar__nav-subitem:hover {
    opacity: 1 !important;
    transform: translateX(2px);
    background: var(--bg-hover);
}

.sidebar__nav-subitem.active {
    opacity: 1 !important;
    background: var(--accent-light);
    color: var(--accent-hover);
}

.sidebar__nav-arrow {
    margin-left: auto;
    font-size: 10px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.5;
}

.sidebar__nav-group .sidebar__nav-item:first-child:hover .sidebar__nav-arrow {
    opacity: 0.8;
}

/* ── Sidebar Projects List ── */
.sidebar__projects {
    padding: var(--space-3);
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.sidebar__project-list {
    flex: 1;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar__project-list::-webkit-scrollbar {
    display: none;
}

/* Custom Scrollbar Global (Rayita Minimalista) */
.sidebar__activity-list::-webkit-scrollbar,
.notif-dropdown::-webkit-scrollbar,
.content::-webkit-scrollbar {
    width: 4px;
}

.sidebar__activity-list::-webkit-scrollbar-track,
.notif-dropdown::-webkit-scrollbar-track,
.content::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar__activity-list::-webkit-scrollbar-thumb,
.notif-dropdown::-webkit-scrollbar-thumb,
.content::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 10px;
}

.sidebar__activity-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* Scrollbar sutil para sección Avances */
.avances-entries-body {
    max-height: 18rem;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--accent) transparent;
}
.avances-entries-body::-webkit-scrollbar { width: 2px; }
.avances-entries-body::-webkit-scrollbar-track { background: transparent; }
.avances-entries-body::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 10px;
    opacity: 0.5;
}
.avances-entries-body::-webkit-scrollbar-thumb:hover { background: var(--accent); }

.sidebar__project-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--fs-sm);
    margin-bottom: 2px;
}

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

.sidebar__project-item.active {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

.sidebar__project-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.sidebar__project-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.sidebar__activity {
    border-top: 1px solid var(--border-color);
    padding: var(--space-4) var(--space-3);
    flex-shrink: 0;
    max-height: 240px; /* Tamaño regresado y ajustado */
    overflow: hidden;
}

.sidebar__activity-label {
    font-size: var(--fs-xs);
    font-weight: var(--fw-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-1) var(--space-2);
    margin-bottom: var(--space-2);
}

.activity-item {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--fs-xs);
    color: var(--text-secondary);
    line-height: 1.4;
    transition: background var(--transition-fast);
}

.activity-item:hover {
    background: var(--bg-hover);
}

.activity-item__icon {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 10px;
    margin-top: 1px;
}

.activity-item__text {
    flex: 1;
}

.activity-item__text strong {
    color: var(--text-primary);
    font-weight: var(--fw-medium);
}

.activity-item__time {
    font-size: var(--fs-xs);
    color: var(--text-muted);
    white-space: nowrap;
    margin-top: 2px;
}

/* ── Main Content ── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* ── Top Bar ── */
.topbar {
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    padding: 0 var(--space-6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.topbar__left {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.topbar__title {
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
}

.topbar__search {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: var(--space-2) var(--space-4);
    min-width: 260px;
    transition: border-color var(--transition-fast);
}

.topbar__search:focus-within {
    border-color: var(--accent);
    box-shadow: var(--accent-glow);
}

.topbar__search input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-family: var(--font-primary);
    font-size: var(--fs-sm);
    width: 100%;
}

.topbar__search input::placeholder {
    color: var(--text-muted);
}

.topbar__search-icon {
    color: var(--text-muted);
    font-size: var(--fs-base);
}

.topbar__right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.topbar__notification {
    position: relative;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
    color: var(--text-secondary);
    font-size: var(--fs-lg);
}

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

.topbar__notification-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 16px;
    height: 16px;
    background: var(--flag-blocked); /* Volvemos al Rojo */
    border-radius: 50%;
    font-size: 9px;
    font-weight: var(--fw-bold);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 0 10px rgba(239, 68, 68, 0.4);
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}

.topbar__user:hover {
    background: var(--bg-hover);
}

.topbar__avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: var(--fw-bold);
    font-size: var(--fs-sm);
    color: white;
}

.topbar__user-info {
    line-height: 1.2;
}

.topbar__user-name {
    font-size: var(--fs-sm);
    font-weight: var(--fw-semibold);
}

.topbar__user-role {
    font-size: var(--fs-xs);
    color: var(--text-muted);
}

/* ── Content Area ── */
.content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-6);
    scroll-behavior: smooth;
}

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

.content::-webkit-scrollbar-track {
    background: transparent;
}

.content::-webkit-scrollbar-thumb {
    background: var(--bg-elevated);
    border-radius: 3px;
}

.content::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ── Section Spacing ── */
.section {
    margin-bottom: var(--space-6);
}

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

.section__title {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ── Grid Layouts ── */
.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-card-gap);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-card-gap);
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-card-gap);
}

.grid-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-card-gap);
}

/* ── Responsive ── */
@media (max-width: 1400px) {
    .grid-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 1200px) {
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ── Hamburger Button ── */
.topbar__hamburger {
    display: none;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    cursor: pointer;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: background var(--transition-fast), color var(--transition-fast);
    flex-shrink: 0;
    padding: 0;
}

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

/* ── Sidebar Backdrop (mobile overlay) ── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 99;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-backdrop.visible {
    display: block;
}

@media (max-width: 900px) {
    .sidebar {
        width: var(--sidebar-collapsed);
        min-width: var(--sidebar-collapsed);
    }

    .sidebar__title,
    .sidebar__nav-label,
    .sidebar__nav-item span,
    .sidebar__projects,
    .sidebar__activity {
        display: none;
    }

    .grid-4,
    .grid-3,
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .topbar {
        padding: 0 var(--space-4);
    }

    .topbar__search {
        min-width: 180px;
    }

    .topbar__user-info {
        display: none;
    }
}

@media (max-width: 640px) {
    /* Show hamburger, hide search bar */
    .topbar__hamburger {
        display: flex;
    }

    .topbar__search {
        display: none;
    }

    /* Reduce content padding */
    .content {
        padding: var(--space-4) var(--space-3);
    }

    /* Sidebar becomes a fixed overlay */
    .sidebar {
        position: fixed;
        top: 0;
        left: calc(-1 * var(--sidebar-width));
        height: 100vh;
        width: var(--sidebar-width) !important;
        min-width: var(--sidebar-width) !important;
        z-index: 100;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar--open {
        left: 0;
    }

    /* Restore sidebar content hidden by 900px rule when open */
    .sidebar--open .sidebar__title,
    .sidebar--open .sidebar__nav-label,
    .sidebar--open .sidebar__nav-item span,
    .sidebar--open .sidebar__activity {
        display: revert;
    }

    .sidebar--open .sidebar__projects {
        display: flex;
    }

    /* Section headers wrap on small screens */
    .section__header {
        flex-wrap: wrap;
        gap: var(--space-2);
    }
}