/* ============================================
   SISTEMA MOBILE-FIRST - APP MÓVIL PRIMERO
   Base: Móvil 320px-480px (como aplicación)
   Expansión: Tablet 768px+ y Desktop 1024px+
   ============================================ */

/* === RESET Y BASE === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    /* Base font-size para rem (16px = 1rem) */
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
}

body {
    overflow-x: hidden;
    width: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    line-height: 1.6;
}

/* ============================================
   CONTENEDOR PRINCIPAL TIPO APP MÓVIL
   ============================================ */

/* Base: Móvil - ancho completo con padding */
.container,
.max-w-4xl,
.max-w-6xl,
.max-w-7xl,
main > div,
.lg\:ml-64 {
    width: 100%;
    max-width: 100%;
    padding-left: 1rem;
    padding-right: 1rem;
    margin-left: auto;
    margin-right: auto;
}

/* Contenedor tipo app móvil */
.container-app {
    width: 100%;
    max-width: 30rem; /* 480px */
    margin: 0 auto;
    padding: 0 1rem;
}

/* ============================================
   TIPOGRAFÍA BASE (MÓVIL PRIMERO)
   ============================================ */

/* Títulos - Tamaños móvil optimizados */
h1, .text-5xl, .text-4xl {
    font-size: 1.75rem; /* 28px */
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 0.75rem;
}

h2, .text-3xl {
    font-size: 1.5rem; /* 24px */
    font-weight: 700;
    line-height: 1.3;
    margin-bottom: 0.5rem;
}

h3, .text-2xl {
    font-size: 1.25rem; /* 20px */
    font-weight: 600;
    line-height: 1.4;
    margin-bottom: 0.5rem;
}

h4, .text-xl {
    font-size: 1.125rem; /* 18px */
    font-weight: 600;
    line-height: 1.4;
}

h5, .text-lg {
    font-size: 1rem; /* 16px */
    font-weight: 600;
    line-height: 1.5;
}

/* Texto base */
body,
p,
.text-base {
    font-size: 0.875rem; /* 14px */
    line-height: 1.6;
}

.text-sm {
    font-size: 0.8125rem; /* 13px */
    line-height: 1.5;
}

.text-xs {
    font-size: 0.75rem; /* 12px */
    line-height: 1.4;
}

/* ============================================
   ESPACIADOS BASE (MÓVIL)
   ============================================ */

/* Padding móvil */
.p-8 { padding: 1rem !important; }
.p-6 { padding: 0.875rem !important; }
.p-4 { padding: 0.75rem !important; }
.p-3 { padding: 0.5rem !important; }
.p-2 { padding: 0.375rem !important; }

/* Padding vertical */
.py-8 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.py-6 { padding-top: 0.875rem !important; padding-bottom: 0.875rem !important; }
.py-4 { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; }
.py-3 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
.py-2 { padding-top: 0.375rem !important; padding-bottom: 0.375rem !important; }

/* Padding horizontal */
.px-8 { padding-left: 1rem !important; padding-right: 1rem !important; }
.px-6 { padding-left: 0.875rem !important; padding-right: 0.875rem !important; }
.px-4 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
.px-3 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
.px-2 { padding-left: 0.375rem !important; padding-right: 0.375rem !important; }

/* Margins móvil */
.mb-8, .mt-8 { margin-bottom: 1rem !important; }
.mb-6, .mt-6 { margin-bottom: 0.875rem !important; }
.mb-4, .mt-4 { margin-bottom: 0.75rem !important; }
.mb-3, .mt-3 { margin-bottom: 0.5rem !important; }
.mb-2, .mt-2 { margin-bottom: 0.375rem !important; }

/* Gaps móvil */
.gap-6 { gap: 0.875rem !important; }
.gap-4 { gap: 0.75rem !important; }
.gap-3 { gap: 0.5rem !important; }
.gap-2 { gap: 0.375rem !important; }

/* ============================================
   BOTONES MÓVIL (FULL WIDTH)
   ============================================ */

/* Todos los botones full-width en móvil */
button,
.btn,
a[class*="bg-primary"],
a[class*="bg-secondary"],
a[class*="bg-red"],
a[class*="bg-blue"],
a[class*="bg-green"],
[type="button"],
[type="submit"] {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    font-weight: 600;
    text-align: center;
    border-radius: 0.75rem;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

/* Botones pequeños (iconos) */
button.p-2,
button.p-3,
.btn-icon {
    width: auto;
    padding: 0.625rem;
    aspect-ratio: 1;
}

/* Grupos de botones - stack vertical */
.flex.gap-3,
.flex.gap-4 {
    flex-direction: column;
}

.flex.gap-3 > button,
.flex.gap-3 > a,
.flex.gap-4 > button,
.flex.gap-4 > a {
    width: 100%;
}

/* ============================================
   CARDS Y CONTENEDORES MÓVIL
   ============================================ */

/* Cards móvil */
.bg-white,
.dark\:bg-slate-800,
.rounded-3xl,
.rounded-2xl,
.rounded-xl {
    padding: 1rem !important;
    border-radius: 1rem !important;
}

/* Contenedores de sección */
section,
.section {
    padding: 1rem;
    margin-bottom: 1rem;
}

/* ============================================
   GRIDS MÓVIL (1 COLUMNA)
   ============================================ */

/* Todos los grids son 1 columna en móvil */
.grid,
.grid-cols-2,
.grid-cols-3,
.grid-cols-4,
.grid-cols-5,
.grid-cols-6,
.md\:grid-cols-2,
.md\:grid-cols-3,
.lg\:grid-cols-4 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

/* Grid de 12 columnas (facturas, etc) */
.grid-cols-12 {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.col-span-1,
.col-span-2,
.col-span-3,
.col-span-4,
.col-span-5,
.col-span-6,
.col-span-7,
.col-span-8,
.col-span-9,
.col-span-10,
.col-span-11,
.col-span-12 {
    width: 100%;
}

/* ============================================
   FLEX MÓVIL (STACK VERTICAL)
   ============================================ */

/* Flex containers - stack vertical por defecto */
.flex:not(.flex-col):not(.flex-row) {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Flex con gap - mantener vertical */
.flex.gap-2,
.flex.gap-3,
.flex.gap-4,
.flex.gap-6 {
    flex-direction: column;
}

/* Flex items - full width */
.flex > * {
    width: 100%;
}

/* Excepciones: iconos inline */
.flex.items-center.gap-2,
.flex.items-center.gap-3,
.flex.items-center.gap-4 {
    flex-direction: row !important;
}

.flex.items-center > * {
    width: auto !important;
}

/* ============================================
   FORMULARIOS MÓVIL
   ============================================ */

/* Inputs full-width */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="search"],
select,
textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem; /* 16px - previene zoom iOS */
    line-height: 1.5;
    border-radius: 0.75rem;
    border: 1px solid;
    min-height: 2.75rem; /* 44px touch target */
}

/* Labels */
label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
}

/* Form groups */
.form-group,
.mb-6,
.mb-4 {
    margin-bottom: 1rem;
}

/* ============================================
   TABLAS MÓVIL (SCROLL HORIZONTAL)
   ============================================ */

/* Wrapper con scroll */
.overflow-x-auto,
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -1rem; /* Sangría para usar todo el ancho */
    padding: 0 1rem;
}

/* Tabla con ancho mínimo */
table {
    width: 100%;
    min-width: 40rem; /* 640px */
    border-collapse: collapse;
}

/* Celdas compactas */
td,
th {
    padding: 0.625rem 0.5rem;
    font-size: 0.8125rem;
    text-align: left;
}

th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* ============================================
   MODALES MÓVIL (FULL SCREEN)
   ============================================ */

/* Modal full-screen en móvil */
.modal-content,
[x-show][class*="fixed"] > div:not(.absolute) {
    position: fixed !important;
    inset: 0;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    margin: 0 !important;
    padding: 1rem !important;
    border-radius: 0 !important;
    overflow-y: auto;
}

/* Header del modal */
.modal-content h3,
[x-show][class*="fixed"] h3 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

/* ============================================
   SIDEBAR MÓVIL (OVERLAY)
   ============================================ */

/* Sidebar móvil - overlay full */
aside.sidebar,
aside[class*="fixed"] {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80% !important;
    max-width: 20rem !important;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 1000;
}

/* Sidebar abierto */
aside.sidebar.translate-x-0,
aside[class*="fixed"].translate-x-0 {
    transform: translateX(0);
}

/* Contenido principal - sin margin en móvil */
.lg\:ml-64 {
    margin-left: 0 !important;
}

/* Header móvil - full width */
header {
    width: 100%;
    padding: 0.75rem 1rem !important;
}

/* Títulos del header */
header h2 {
    font-size: 1.25rem !important;
}

header p {
    font-size: 0.75rem !important;
}

/* ============================================
   NAVEGACIÓN MÓVIL
   ============================================ */

/* Nav items */
nav a {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    border-radius: 0.75rem;
}

/* ============================================
   AVATARES Y ELEMENTOS CIRCULARES
   ============================================ */

/* Avatares móvil */
.w-16.h-16,
.w-14.h-14 {
    width: 3rem !important;
    height: 3rem !important;
}

.w-12.h-12,
.w-10.h-10 {
    width: 2.5rem !important;
    height: 2.5rem !important;
}

/* Iconos en avatares */
.w-16 i,
.w-14 i,
.w-12 i,
.w-10 i {
    font-size: 1.25rem !important;
}

/* ============================================
   ICONOS MÓVIL
   ============================================ */

/* Iconos proporcionales */
i.text-5xl,
i.text-4xl {
    font-size: 2rem !important;
}

i.text-3xl,
i.text-2xl {
    font-size: 1.5rem !important;
}

i.text-xl {
    font-size: 1.25rem !important;
}

i.text-lg {
    font-size: 1rem !important;
}

/* Iconos en botones - proporcional */
button i,
a i {
    font-size: 1em;
}

/* ============================================
   BADGES Y ESTADOS
   ============================================ */

.badge,
.rounded-full[class*="px-"] {
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    border-radius: 0.75rem;
}

/* ============================================
   BOTÓN FLOTANTE MÓVIL
   ============================================ */

.fixed.bottom-8,
.fixed.bottom-6 {
    position: fixed;
    bottom: 1rem !important;
    right: 1rem !important;
}

.fixed .w-16.h-16 {
    width: 3.5rem !important;
    height: 3.5rem !important;
}

.fixed .w-16 i {
    font-size: 1.75rem !important;
}

/* ============================================
   LISTAS Y ITEMS
   ============================================ */

/* List items - full width */
.list-item,
li,
.flex.items-center.gap-4 {
    width: 100%;
    padding: 0.75rem;
}

/* ============================================
   IMÁGENES RESPONSIVE
   ============================================ */

img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Galería de imágenes móvil - 2 columnas */
.grid.grid-cols-3 {
    grid-template-columns: repeat(2, 1fr) !important;
}

/* ============================================
   STATS Y DASHBOARD
   ============================================ */

/* Stats cards - 1 columna */
.stats-grid,
.grid.grid-cols-4 {
    grid-template-columns: 1fr !important;
}

/* Números en stats */
.stat-card .text-3xl {
    font-size: 2rem !important;
}

/* ============================================
   ACCESIBILIDAD MÓVIL
   ============================================ */

/* Touch targets mínimos */
button,
a,
input,
select {
    min-height: 2.75rem; /* 44px */
}

/* Focus visible */
*:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

/* ============================================
   UTILIDADES MÓVIL
   ============================================ */

/* Hidden en móvil */
.hidden-mobile {
    display: none !important;
}

/* Visible solo en móvil */
.mobile-only {
    display: block !important;
}

/* Text truncate */
.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   MEDIA QUERY: TABLET (768px+)
   Expansión desde móvil a tablet
   ============================================ */

@media (min-width: 48rem) { /* 768px */
    
    /* Contenedor se expande */
    .container,
    .max-w-4xl {
        max-width: 48rem; /* 768px */
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
    
    /* Tipografía se expande */
    h1, .text-5xl, .text-4xl {
        font-size: 2.25rem; /* 36px */
    }
    
    h2, .text-3xl {
        font-size: 1.875rem; /* 30px */
    }
    
    h3, .text-2xl {
        font-size: 1.5rem; /* 24px */
    }
    
    body, p, .text-base {
        font-size: 1rem; /* 16px */
    }
    
    /* Espaciados se expanden */
    .p-8 { padding: 1.5rem !important; }
    .p-6 { padding: 1.25rem !important; }
    .p-4 { padding: 1rem !important; }
    
    .gap-6 { gap: 1.25rem !important; }
    .gap-4 { gap: 1rem !important; }
    
    /* Botones - inline permitido */
    .flex.gap-3,
    .flex.gap-4 {
        flex-direction: row;
    }
    
    .flex.gap-3 > button,
    .flex.gap-4 > button,
    .flex.gap-3 > a,
    .flex.gap-4 > a {
        width: auto;
    }
    
    /* Grids - 2 columnas */
    .grid-cols-2,
    .md\:grid-cols-2 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-cols-3,
    .md\:grid-cols-3 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Modal - centrado */
    .modal-content,
    [x-show][class*="fixed"] > div:not(.absolute) {
        position: relative !important;
        inset: auto;
        width: 90% !important;
        max-width: 42rem !important;
        height: auto !important;
        max-height: 90vh !important;
        margin: 2rem auto !important;
        border-radius: 1.5rem !important;
    }
    
    /* Hidden en tablet */
    .mobile-only {
        display: none !important;
    }
}

/* ============================================
   MEDIA QUERY: DESKTOP (1024px+)
   Expansión completa a desktop
   ============================================ */

@media (min-width: 64rem) { /* 1024px */
    
    /* Contenedor desktop */
    .container,
    .max-w-4xl {
        max-width: 56rem; /* 896px */
        padding-left: 2rem;
        padding-right: 2rem;
    }
    
    .max-w-6xl {
        max-width: 72rem; /* 1152px */
    }
    
    /* Tipografía desktop */
    h1, .text-5xl, .text-4xl {
        font-size: 3rem; /* 48px */
    }
    
    h2, .text-3xl {
        font-size: 2.25rem; /* 36px */
    }
    
    h3, .text-2xl {
        font-size: 1.875rem; /* 30px */
    }
    
    /* Espaciados desktop */
    .p-8 { padding: 2rem !important; }
    .p-6 { padding: 1.5rem !important; }
    .p-4 { padding: 1rem !important; }
    
    .gap-6 { gap: 1.5rem !important; }
    .gap-4 { gap: 1rem !important; }
    
    .mb-8 { margin-bottom: 2rem !important; }
    .mb-6 { margin-bottom: 1.5rem !important; }
    
    /* Sidebar visible */
    aside.sidebar,
    aside[class*="fixed"] {
        transform: translateX(0) !important;
        width: 16rem !important;
    }
    
    /* Contenido principal con margin */
    .lg\:ml-64 {
        margin-left: 16rem !important;
    }
    
    /* Header desktop */
    header {
        padding: 1rem 1.5rem !important;
    }
    
    header h2 {
        font-size: 1.875rem !important;
    }
    
    header p {
        font-size: 0.875rem !important;
    }
    
    /* Grids - múltiples columnas */
    .grid-cols-3,
    .md\:grid-cols-3 {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .grid-cols-4,
    .lg\:grid-cols-4 {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .grid-cols-6 {
        grid-template-columns: repeat(6, 1fr);
    }
    
    /* Grid de 12 columnas restaurado */
    .grid-cols-12 {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
    }
    
    .col-span-1 { grid-column: span 1; width: auto; }
    .col-span-2 { grid-column: span 2; width: auto; }
    .col-span-3 { grid-column: span 3; width: auto; }
    .col-span-4 { grid-column: span 4; width: auto; }
    .col-span-5 { grid-column: span 5; width: auto; }
    .col-span-6 { grid-column: span 6; width: auto; }
    .col-span-7 { grid-column: span 7; width: auto; }
    .col-span-8 { grid-column: span 8; width: auto; }
    .col-span-9 { grid-column: span 9; width: auto; }
    .col-span-10 { grid-column: span 10; width: auto; }
    .col-span-11 { grid-column: span 11; width: auto; }
    .col-span-12 { grid-column: span 12; width: auto; }
    
    /* Tablas - full width */
    table {
        min-width: auto;
    }
    
    .overflow-x-auto {
        margin: 0;
        padding: 0;
    }
    
    /* Botones desktop - inline */
    button,
    .btn,
    a[class*="bg-"] {
        width: auto;
        display: inline-block;
    }
    
    /* Hidden en desktop */
    .hidden-desktop {
        display: none !important;
    }
}

/* ============================================
   MEDIA QUERY: LARGE DESKTOP (1280px+)
   Máxima expansión
   ============================================ */

@media (min-width: 80rem) { /* 1280px */
    
    .container,
    .max-w-4xl {
        max-width: 64rem; /* 1024px */
    }
    
    .max-w-6xl {
        max-width: 80rem; /* 1280px */
    }
    
    .max-w-7xl {
        max-width: 90rem; /* 1440px */
    }
}

/* ============================================
   MODO LANDSCAPE MÓVIL
   ============================================ */

@media (max-width: 63.9375rem) and (orientation: landscape) {
    
    /* Reducir altura de modales */
    .modal-content,
    [x-show][class*="fixed"] > div:not(.absolute) {
        max-height: 80vh !important;
    }
    
    /* Header más compacto */
    header {
        padding: 0.5rem 1rem !important;
    }
}

/* ============================================
   PREVENIR OVERFLOW
   ============================================ */

html,
body {
    overflow-x: hidden;
    max-width: 100%;
}

* {
    max-width: 100%;
}

/* ============================================
   SAFE AREA (iPhone notch)
   ============================================ */

@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
    
    .fixed.bottom-8,
    .fixed.bottom-6 {
        bottom: max(1rem, calc(1rem + env(safe-area-inset-bottom))) !important;
    }
}

/* ============================================
   REDUCCIÓN DE MOVIMIENTO (Accesibilidad)
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
