/* 
 * DJN Habitat v3.0 - Ultra-Premium Layout System
 * Bento Grid + Mobile Navigation (TabBar)
 */

:root {
    --sidebar-width: 280px;
    --navbar-height: 80px;
    --tabbar-height: 70px;
}

.main-wrapper {
    display: flex;
    min-height: 100vh;
    background: var(--bg-main);
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

/* UI Elements: Inputs & Buttons */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    border-radius: 20px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 0.6rem 1rem;
    font-family: inherit;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    background: rgba(255, 255, 255, 0.8);
}

/* Fix iOS Zoom on Focus */
@media screen and (max-width: 768px) {

    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="date"],
    input[type="number"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    background: white;
}

.btn-primary {
    background: var(--brand-blue);
    color: white;
    border: none;
    padding: 0.7rem 1.5rem;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px rgba(59, 130, 246, 0.2);
}

.btn-primary:hover {
    background: var(--brand-blue-accent);
    transform: translateY(-1px);
    box-shadow: 0 6px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background: white;
    color: var(--text-primary);
    border: 1px solid rgba(0, 0, 0, 0.1);
    padding: 0.7rem 1.5rem;
    border-radius: 20px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: var(--text-secondary);
}

/* Mobile Submenu Container */
#mobile-submenu-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}

/* Sidebar (Desktop) */
.sidebar {
    width: var(--sidebar-width);
    background: var(--brand-blue);
    color: white;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    position: fixed;
    height: 100vh;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-header {
    padding: 2rem 1.5rem;
    text-align: center;
}

.sidebar-header img {
    max-width: 140px;
    filter: brightness(0) invert(1);
    opacity: 0.9;
}

.sidebar-menu {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
}

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

.sidebar-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 1rem 1.2rem;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    border-radius: var(--radius-md);
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.menu-item:hover,
.menu-item.active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.menu-item i {
    font-size: 1.25rem;
    margin-right: 12px;
}

/* TabBar (Mobile Navigation) */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    height: var(--tabbar-height);
    background: rgba(15, 23, 42, 0.85);
    /* Navy con transparencia */
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-xl);
    z-index: 2000;
    justify-content: space-around;
    align-items: center;
    padding: 0 1rem;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: rgba(255, 255, 255, 0.5);
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 700;
    gap: 4px;
}

.tab-item.active {
    color: var(--brand-lime);
}

.tab-item i {
    font-size: 1.4rem;
}

/* Content Area */
.content-area {
    margin-left: var(--sidebar-width);
    flex: 1;
    width: 100%;
}

.top-navbar {
    height: var(--navbar-height);
    padding: 0 2.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Bento Grid System */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    grid-auto-rows: auto;
    gap: 1.5rem;
    padding: 0 1rem;
}

.page-content {
    padding: 2rem;
    max-width: var(--container-max);
    margin: 0 auto;
}

/* Sub-menu implementation (Desktop) */
.menu-group {
    display: flex;
    flex-direction: column;
}

.sub-menu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-md);
    margin-left: 1rem;
    margin-right: 0.5rem;
}

.menu-group.open .sub-menu {
    max-height: 400px;
    /* Sufficient for sub-items */
    margin-bottom: 0.5rem;
}

.sub-menu .menu-item {
    font-size: 0.8rem;
    padding: 0.7rem 1.2rem;
    margin-bottom: 2px;
}

.menu-group .menu-item .chevron {
    margin-left: auto;
    margin-right: 0;
    transition: transform 0.3s ease;
}

.menu-group.open .menu-item .chevron {
    transform: rotate(90deg);
}

/* Mobile Sub-menu (Bottom Sheet style) */
.mobile-submenu-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 2500;
    display: none;
    align-items: flex-end;
}

.mobile-submenu-overlay.active {
    display: flex;
}

.mobile-submenu-sheet {
    width: 100%;
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 32px 32px 0 0;
    padding: 1rem 1.2rem calc(var(--tabbar-height) + 30px + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.mobile-submenu-overlay.active .mobile-submenu-sheet {
    transform: translateY(0);
}

.mobile-submenu-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.mobile-menu-item:active {
    transform: scale(0.98);
    background: rgba(255, 255, 255, 0.1) !important;
}

/* Modal System (Glassmorphism) */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: rgba(255, 255, 255, 0.95);
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    transform: scale(0.9);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-card {
    transform: scale(1);
    opacity: 1;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h3 {
    margin: 0;
    color: var(--brand-blue);
    font-size: 1.2rem;
}

.mobile-submenu-sheet h4 {
    margin-bottom: 2rem;
}

/* Removed .mobile-submenu-grid in favor of .mobile-submenu-list */

/* Responsive Visibility */
.header-logo-mobile {
    display: none;
}

/* Footer Desktop: Flotante/Sticky */
.app-footer {
    padding: 1.5rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-sm);

    margin-top: auto;
    position: sticky;
    bottom: 1rem;

    /* Desktop Positioning: A la derecha del Sidebar */
    margin-left: calc(var(--sidebar-width) + 2rem);
    margin-right: 2rem;
    margin-bottom: 1rem;
    width: auto;
    z-index: 90;
}

@media (max-width: 1024px) {
    .header-logo-mobile {
        display: block;
    }

    .sidebar {
        display: none;
    }

    .content-area {
        margin-left: 0;
        /* Padding inferior para evitar que el tabbar tape contenido */
        padding-bottom: calc(var(--tabbar-height) + 20px);
    }

    .mobile-nav {
        display: flex;
    }

    /* Footer Mobile Overrides */
    .app-footer {
        position: relative !important;
        bottom: auto !important;
        margin: 1rem !important;
        margin-bottom: 5rem !important;
        margin-left: 1rem !important;
        margin-right: 1rem !important;
        width: auto !important;
    }

    /* Bento Grid Mobile Stabilization */
    .bento-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 0 0.5rem;
    }

    .top-navbar {
        padding: 1rem;
        height: auto;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
        text-align: left;
    }

    .top-navbar h1,
    .top-navbar h2 {
        font-size: clamp(1.25rem, 5vw, 1.8rem) !important;
        margin-top: 0 !important;
    }

    .navbar-right {
        align-self: flex-start;
        position: relative;
        top: 0;
        right: 0;
        margin-top: 0.5rem;
    }

    /* Force all grid items to span only 1 column to prevent overflow */
    .bento-grid>*,
    .bento-item {
        grid-column: span 1 !important;
        max-width: 100% !important;
        overflow: hidden;
    }
}

@media (max-width: 430px) {
    :root {
        --tabbar-height: 65px;
    }

    body {
        font-size: 14px;
    }

    .page-content {
        padding: 0.5rem;
    }

    .top-navbar {
        padding: 1.5rem 1rem 0.5rem;
        gap: 0.2rem;
    }

    .top-navbar h1,
    .top-navbar h2 {
        font-size: 1.1rem !important;
        line-height: 1.2;
        padding-right: 0 !important;
    }

    .bento-grid {
        gap: 0.75rem;
    }

    .glass-card {
        padding: 0.85rem !important;
    }

    .mobile-menu-item {
        padding: 0.7rem !important;
        gap: 8px !important;
    }

    .mobile-menu-item div div i {
        width: 18px !important;
        height: 18px !important;
    }

    .mobile-nav {
        bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        height: 60px;
    }

    /* Transform Tables into Cards on Mobile */
    .glass-card table,
    .glass-card thead,
    .glass-card tbody,
    .glass-card th,
    .glass-card td,
    .glass-card tr {
        display: block;
        width: 100% !important;
        min-width: 0 !important;
    }

    .glass-card thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .glass-card tr {
        border: 1px solid rgba(0, 0, 0, 0.05);
        border-radius: 12px;
        margin-bottom: 1rem;
        padding: 0.5rem;
        background: rgba(255, 255, 255, 0.4);
    }

    .glass-card td {
        border: none !important;
        position: relative;
        padding-left: 40% !important;
        text-align: left !important;
        font-size: 0.85rem;
        min-height: 30px;
        display: flex;
        align-items: center;
    }

    .glass-card td:before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        width: 35%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: 800;
        color: var(--text-muted);
        text-transform: uppercase;
        font-size: 0.6rem;
    }

    .glass-card td[data-label="Acciones"] {
        padding-left: 10px !important;
        justify-content: center;
        border-top: 1px solid rgba(0, 0, 0, 0.05) !important;
        margin-top: 0.5rem;
        padding-top: 1rem !important;
    }

    .glass-card td[data-label="Acciones"]:before {
        display: none;
    }
}

/* Sidebar Menu Labels */
.sidebar-menu .menu-group .sub-menu .menu-label {
    padding: 0.5rem 1rem 0.2rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 1px;
    margin-top: 0.5rem;
}

.sidebar-menu .menu-group .sub-menu .menu-label:first-child {
    margin-top: 0;
}