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

/* Global box-sizing reset — prevents padding from causing elements to overflow their containers */
*, *::before, *::after {
    box-sizing: border-box;
}

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

.main-wrapper {
    display: flex;
    min-height: 100vh;
    background: var(--bg-main);
}

/* UI Elements: Inputs & Buttons */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
    border-radius: 20px;
    /* Rounded pill shape */
    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);
}

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.8rem 1.6rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.15);
    text-decoration: none;
    font-size: 0.9rem;
}

.btn-primary:hover {
    background: var(--brand-blue-accent);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.25);
    color: white;
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: white;
    color: var(--brand-blue);
    border: 1.5px solid rgba(15, 23, 42, 0.1);
    padding: 0.8rem 1.6rem;
    border-radius: var(--radius-sm);
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s ease;
    text-decoration: none;
    font-size: 0.9rem;
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: var(--brand-blue-accent);
    color: var(--brand-blue-accent);
    transform: translateY(-1px);
}

/* Icon Buttons (Botones circulares para acciones rápidas) */
.btn-icon {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #f8fafc;
    color: var(--brand-blue);
    border: none; /* Eliminamos borde para evitar resaltado grueso */
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    outline: none;
    user-select: none;
}

.btn-icon:hover {
    background: var(--brand-blue);
    color: white;
    transform: scale(1.1);
}

.btn-icon:active {
    transform: scale(0.95);
}

.btn-icon span {
    font-size: 1.1rem;
    line-height: 1;
    display: block;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    border-radius: 10px;
}

.btn-icon.btn-sm {
    width: 32px;
    height: 32px;
}

/* 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;
    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: calc(100% - var(--sidebar-width));
    min-width: 0;
    position: relative;
}

.top-navbar {
    min-height: var(--navbar-height);
    padding: 1rem 2rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

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

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.5rem;
}

.grid-2-1 {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-glass-card {
    padding: 2rem;
}

.page-content {
    padding: 2rem;
    box-sizing: border-box;
    width: 100%;
}

/* 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: var(--brand-blue);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 1.5rem 1.5rem calc(var(--tabbar-height) + 20px);
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
    max-height: 80vh; /* Aumentamos un poco el alto para más comodidad */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* El título se queda arriba */
}

/* 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.98);
    width: 100%;
    max-width: 550px;
    border-radius: var(--radius-xl);
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}

.modal-card > form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 1rem 2rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
    /* Indicador sutil de más contenido arriba/abajo */
    background: linear-gradient(white 30%, rgba(255, 255, 255, 0)), 
                linear-gradient(rgba(255, 255, 255, 0), white 70%) 0 100%, 
                radial-gradient(farthest-side at 50% 0, rgba(0, 0, 0, .05), rgba(0, 0, 0, 0)), 
                radial-gradient(farthest-side at 50% 100%, rgba(0, 0, 0, .05), rgba(0, 0, 0, 0)) 0 100%;
    background-repeat: no-repeat;
    background-size: 100% 40px, 100% 40px, 100% 14px, 100% 14px;
    background-attachment: local, local, scroll, scroll;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.1);
    border-radius: 10px;
}

.modal-footer {
    flex-shrink: 0; /* Siempre visible */
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 0;
    padding: 1.5rem 0 0 0;
    border-top: 1px solid rgba(0,0,0,0.05);
}

.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-overlay.active .mobile-submenu-sheet {
    transform: translateY(0);
}

.mobile-submenu-sheet h4 {
    color: var(--brand-lime);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 1.5rem;
    opacity: 0.8;
}

.mobile-submenu-grid {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    overflow-y: auto;
    flex: 1;
    padding-right: 5px; /* Espacio para scrollbar */
    /* Scrollbar minimalista para que no "ensucie" el diseño premium */
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.mobile-submenu-grid::-webkit-scrollbar {
    width: 4px;
}
.mobile-submenu-grid::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
}

.mobile-menu-item {
    display: flex;
    align-items: center;
    background: rgba(255, 255, 255, 0.05);
    padding: 0.8rem 1.2rem;
    border-radius: 16px;
    color: white;
    text-decoration: none;
    gap: 12px;
    transition: all 0.2s ease;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.mobile-menu-item:hover, .mobile-menu-item:active {
    background: rgba(255, 255, 255, 0.12);
    transform: translateX(5px);
    border-color: rgba(255, 255, 255, 0.1);
}

.mobile-menu-item i {
    width: 20px;
    height: 20px;
    opacity: 0.8;
}

.mobile-menu-item span {
    font-size: 0.85rem;
    font-weight: 600;
}

/* 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;
    }

    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .top-navbar {
        padding: 1rem 1.5rem;
        height: auto;
        min-height: var(--navbar-height);
        flex-wrap: wrap;
        gap: 1rem;
    }

    /* 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;
    }
}

@media (max-width: 640px) {
    .bento-grid {
        grid-template-columns: 1fr;
    }

    .page-content {
        padding: 1rem;
    }
}

/* 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;
}

/* ==========================================================
   SISTEMA RESPONSIVE MULTI-GAMA (Smartphones y Tablets)
   ========================================================== */

@media (max-width: 639px) {
    .bento-item {
        grid-column: span 1 !important;
    }
    .glass-card[style*="span"] {
        grid-column: span 1 !important;
    }
}

/* 1. TABLETS GAMAS MEDIA/ALTA (iPad, Galaxy Tab S) - 768px a 1024px */
@media (min-width: 768px) and (max-width: 1024px) {
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.5rem;
    }
    .modal-card {
        max-width: 600px;
        padding: 2.5rem;
    }
}

/* 2. TABLETS GAMA BAJA / PHABLETS (Fire HD, etc) - 640px a 767px */
@media (min-width: 640px) and (max-width: 767px) {
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.2rem;
    }
    .page-content {
        padding: 1.5rem;
    }
    .modal-card {
        max-width: 90%;
        padding: 2rem;
    }
    .btn-primary, .btn-secondary {
        font-size: 0.95rem;
    }
}

/* 3. MÓVILES GAMA ALTA (Pantallas Grandes ej. Pro Max) - 430px a 639px */
@media (min-width: 430px) and (max-width: 639px) {
    .bento-grid, .grid-2, .grid-2-1 {
        grid-template-columns: 1fr;
        gap: 1.2rem;
    }
    .page-content {
        padding: 1.5rem;
    }
    .modal-card {
        width: 92%;
        padding: 1.8rem;
        border-radius: var(--radius-lg);
    }
    .table-glass-card {
        padding: 1.5rem;
    }
    .btn-primary {
        padding: 0.8rem 1.5rem;
    }
}

/* 4. MÓVILES GAMA MEDIA (Estándar ej. iPhone 13/14) - 375px a 429px */
@media (min-width: 375px) and (max-width: 429px) {
    .bento-grid, .grid-2, .grid-2-1 {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .page-content {
        padding: 1.2rem;
    }
    .top-navbar {
        padding: 1rem 1.2rem;
    }
    .modal-card {
        width: 95%;
        padding: 1.5rem;
        border-radius: var(--radius-md);
        margin: 1rem 0;
    }
    .table-glass-card {
        padding: 1.2rem;
    }
    .modal-header h3 {
        font-size: 1.1rem;
    }
    .form-group label {
        font-size: 0.7rem;
    }
    .btn-primary, .btn-secondary {
        padding: 0.75rem 1.2rem;
        font-size: 0.9rem;
    }
}

/* 5. MÓVILES GAMA BAJA (Pantallas muy pequeñas ej. iPhone SE) - Hasta 374px */
@media (max-width: 374px) {
    .bento-grid, .grid-2, .grid-2-1 {
        grid-template-columns: 1fr;
        gap: 0.8rem;
    }
    .page-content {
        padding: 0.8rem;
    }
    .top-navbar {
        padding: 0.6rem 0.8rem;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }
    .modal-card {
        width: 100%;
        padding: 1rem;
        border-radius: var(--radius-md);
        margin: 0;
        max-height: 100vh;
    }
    .table-glass-card {
        padding: 0.8rem;
    }
    .modal-header {
        margin-bottom: 0.8rem;
    }
    .modal-header h3 {
        font-size: 0.95rem;
    }
    .form-group label {
        font-size: 0.6rem !important;
        margin-bottom: 0.3rem;
    }
    input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
        font-size: 0.8rem;
        padding: 0.5rem 0.7rem;
    }
    .btn-primary, .btn-secondary {
        padding: 0.5rem 0.8rem;
        font-size: 0.8rem;
        border-radius: 10px;
        width: 100%;
        justify-content: center;
    }
    .tab-item i {
        font-size: 1.1rem;
    }
    .tab-item span {
        font-size: 0.6rem;
    }
}