/* ========================================
   📱 RESPONSIVE DESIGN v4.0 - MOBILE FIRST
   Sistema completo responsive con menú hamburguesa
   ======================================== */

/* ========================================
   1. MOBILE FIRST BASE (< 768px)
   ======================================== */

/* === LAYOUT PRINCIPAL === */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
}

/* === HEADER/NAVBAR === */
.navbar-mobile {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: var(--z-fixed, 1030);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md, 1rem);
    background-color: var(--surface-primary, #1e1e1e);
    border-bottom: 1px solid var(--border-primary, #333333);
    box-shadow: var(--shadow-md, 0 4px 8px rgba(0, 0, 0, 0.4));
}

.navbar-logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm, 0.5rem);
    font-size: var(--font-size-lg, 1.125rem);
    font-weight: var(--font-weight-bold, 700);
    color: var(--text-primary, #ffffff);
    text-decoration: none;
}

.navbar-logo img {
    height: 32px;
    width: auto;
}

/* === BOTÓN HAMBURGUESA === */
.hamburger-btn {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    z-index: var(--z-fixed, 1030);
    position: relative;
}

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 2px;
    background-color: var(--text-primary, #ffffff);
    border-radius: 2px;
    transition: all var(--transition-base, 250ms);
    position: absolute;
}

.hamburger-btn span:nth-child(1) {
    top: 10px;
}

.hamburger-btn span:nth-child(2) {
    top: 19px;
}

.hamburger-btn span:nth-child(3) {
    top: 28px;
}

/* Animación cuando está abierto */
.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg);
    top: 19px;
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg);
    top: 19px;
}

/* === MENÚ LATERAL (SIDEBAR) === */
.sidebar-mobile {
    position: fixed;
    top: 0;
    left: -100%;
    width: 80%;
    max-width: 320px;
    height: 100vh;
    background-color: var(--surface-primary, #1e1e1e);
    border-right: 1px solid var(--border-primary, #333333);
    box-shadow: var(--shadow-xl, 0 16px 32px rgba(0, 0, 0, 0.6));
    z-index: var(--z-modal, 1050);
    overflow-y: auto;
    transition: left var(--transition-base, 250ms);
    padding-top: 70px; /* Espacio para el header */
}

.sidebar-mobile.active {
    left: 0;
}

/* Overlay oscuro cuando el menú está abierto */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal-backdrop, 1040);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base, 250ms);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* === NAVEGACIÓN DEL SIDEBAR === */
.sidebar-nav {
    padding: var(--spacing-md, 1rem);
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-md, 1rem);
    padding: var(--spacing-md, 1rem);
    margin-bottom: var(--spacing-xs, 0.25rem);
    color: var(--text-secondary, #b0b0b0);
    text-decoration: none;
    border-radius: var(--radius-md, 0.5rem);
    transition: all var(--transition-fast, 150ms);
    font-weight: var(--font-weight-medium, 500);
}

.sidebar-nav-item:hover,
.sidebar-nav-item.active {
    background-color: var(--surface-hover, #333333);
    color: var(--accent-primary, #00d4ff);
}

.sidebar-nav-item i {
    font-size: var(--font-size-lg, 1.125rem);
    width: 24px;
    text-align: center;
}

.sidebar-divider {
    height: 1px;
    background-color: var(--border-primary, #333333);
    margin: var(--spacing-md, 1rem) 0;
}

/* === CONTENIDO PRINCIPAL === */
.main-content {
    flex: 1;
    padding: var(--spacing-lg, 1.5rem);
    padding-top: calc(60px + var(--spacing-lg, 1.5rem)); /* Espacio para navbar fijo */
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* === TABLAS RESPONSIVE === */
.table-responsive {
    display: none; /* Ocultar tabla en móvil */
}

.table-cards {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md, 1rem);
}

.table-card {
    background-color: var(--surface-primary, #1e1e1e);
    border: 1px solid var(--border-primary, #333333);
    border-radius: var(--radius-lg, 0.75rem);
    padding: var(--spacing-lg, 1.5rem);
    box-shadow: var(--shadow-md, 0 4px 8px rgba(0, 0, 0, 0.4));
}

.table-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-md, 1rem);
    padding-bottom: var(--spacing-md, 1rem);
    border-bottom: 1px solid var(--border-primary, #333333);
}

.table-card-title {
    font-size: var(--font-size-lg, 1.125rem);
    font-weight: var(--font-weight-bold, 700);
    color: var(--text-primary, #ffffff);
}

.table-card-body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm, 0.5rem);
}

.table-card-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-xs, 0.25rem) 0;
}

.table-card-label {
    font-size: var(--font-size-sm, 0.875rem);
    color: var(--text-secondary, #b0b0b0);
    font-weight: var(--font-weight-medium, 500);
}

.table-card-value {
    font-size: var(--font-size-base, 1rem);
    color: var(--text-primary, #ffffff);
    text-align: right;
}

.table-card-actions {
    display: flex;
    gap: var(--spacing-sm, 0.5rem);
    margin-top: var(--spacing-md, 1rem);
    padding-top: var(--spacing-md, 1rem);
    border-top: 1px solid var(--border-primary, #333333);
}

.table-card-actions .btn {
    flex: 1;
}

/* === GRID RESPONSIVE === */
.grid-responsive {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--spacing-md, 1rem);
}

/* === FORMULARIOS EN MÓVIL === */
.form-row-mobile {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md, 1rem);
}

/* ========================================
   2. TABLET (768px - 1024px)
   ======================================== */
@media (min-width: 768px) {
    /* Ocultar elementos mobile */
    .hamburger-btn {
        display: none;
    }

    .sidebar-mobile {
        position: static;
        width: 280px;
        height: 100vh;
        padding-top: 0;
        border-right: 1px solid var(--border-primary, #333333);
    }

    .sidebar-overlay {
        display: none;
    }

    /* Layout con sidebar permanente */
    .app-container {
        flex-direction: row;
    }

    .navbar-mobile {
        display: none;
    }

    .main-content {
        padding-top: var(--spacing-2xl, 3rem);
        margin-left: 0;
    }

    /* Mostrar tablas normales */
    .table-responsive {
        display: block;
    }

    .table-cards {
        display: none;
    }

    /* Grid de 2 columnas */
    .grid-responsive {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Formularios en fila */
    .form-row-mobile {
        flex-direction: row;
    }
}

/* ========================================
   3. DESKTOP (> 1024px)
   ======================================== */
@media (min-width: 1024px) {
    .sidebar-mobile {
        width: 320px;
    }

    .main-content {
        padding: var(--spacing-3xl, 4rem);
        max-width: 1400px;
        margin: 0 auto;
    }

    /* Grid de 3 columnas */
    .grid-responsive {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Grid de 4 columnas para cards pequeñas */
    .grid-4-cols {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ========================================
   4. DASHBOARD CARDS RESPONSIVE
   ======================================== */
.dashboard-cards {
    display: grid;
    gap: var(--spacing-lg, 1.5rem);
    grid-template-columns: 1fr;
    margin-bottom: var(--spacing-2xl, 3rem);
}

@media (min-width: 640px) {
    .dashboard-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .dashboard-cards {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* Tarjeta de métrica */
.metric-card {
    background-color: var(--surface-primary, #1e1e1e);
    border: 1px solid var(--border-primary, #333333);
    border-radius: var(--radius-lg, 0.75rem);
    padding: var(--spacing-lg, 1.5rem);
    box-shadow: var(--shadow-md, 0 4px 8px rgba(0, 0, 0, 0.4));
    transition: all var(--transition-base, 250ms);
}

.metric-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg, 0 8px 16px rgba(0, 0, 0, 0.5));
    border-color: var(--accent-primary, #00d4ff);
}

.metric-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md, 0.5rem);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-2xl, 1.5rem);
    margin-bottom: var(--spacing-md, 1rem);
}

.metric-value {
    font-size: var(--font-size-3xl, 1.875rem);
    font-weight: var(--font-weight-bold, 700);
    color: var(--text-primary, #ffffff);
    margin-bottom: var(--spacing-xs, 0.25rem);
}

.metric-label {
    font-size: var(--font-size-sm, 0.875rem);
    color: var(--text-secondary, #b0b0b0);
    font-weight: var(--font-weight-medium, 500);
}

/* ========================================
   5. UTILIDADES RESPONSIVE
   ======================================== */

/* Ocultar en móvil */
@media (max-width: 767px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Ocultar en tablet */
@media (min-width: 768px) and (max-width: 1023px) {
    .hide-tablet {
        display: none !important;
    }
}

/* Ocultar en desktop */
@media (min-width: 1024px) {
    .hide-desktop {
        display: none !important;
    }
    
    .show-mobile {
        display: none !important;
    }
}

/* Mostrar solo en mobile */
.show-mobile {
    display: block;
}

@media (min-width: 768px) {
    .show-mobile {
        display: none;
    }
}

/* ========================================
   6. ACCESIBILIDAD
   ======================================== */

/* Focus visible para teclado */
.sidebar-nav-item:focus-visible,
.btn:focus-visible,
.form-control:focus-visible {
    outline: 2px solid var(--accent-primary, #00d4ff);
    outline-offset: 2px;
}

/* Reducir movimiento */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
