/**
 * VITASYSTEM SAAS - Mobile First Optimizations
 * Otimizações específicas para responsividade Mobile First
 * Stack: CodeIgniter 4 + Bootstrap 5 + jQuery UI
 * 
 * Data: 19/08/2025
 * Metodologia: Mobile First (min-width breakpoints)
 */

/* ==========================================================================
   1. VARIÁVEIS CSS MOBILE FIRST
   ========================================================================== */

:root {
    /* Font Sizes - Mobile First com clamp() */
    --bs-body-font-size: clamp(14px, 2.5vw, 16px);
    --vitasystem-font-xs: clamp(0.625rem, 2vw, 0.75rem);   /* 10-12px */
    --vitasystem-font-sm: clamp(0.75rem, 2.2vw, 0.875rem); /* 12-14px */
    --vitasystem-font-base: clamp(0.875rem, 2.5vw, 1rem);  /* 14-16px */
    --vitasystem-font-lg: clamp(1rem, 3vw, 1.125rem);      /* 16-18px */
    --vitasystem-font-xl: clamp(1.125rem, 3.5vw, 1.25rem); /* 18-20px */
    
    /* Headings - Escala responsiva */
    --vitasystem-h1: clamp(1.75rem, 4vw, 2.5rem);    /* 28-40px */
    --vitasystem-h2: clamp(1.5rem, 3.5vw, 2rem);     /* 24-32px */
    --vitasystem-h3: clamp(1.25rem, 3vw, 1.75rem);   /* 20-28px */
    --vitasystem-h4: clamp(1.125rem, 2.8vw, 1.5rem); /* 18-24px */
    --vitasystem-h5: clamp(1rem, 2.5vw, 1.25rem);    /* 16-20px */
    --vitasystem-h6: clamp(0.875rem, 2.3vw, 1rem);   /* 14-16px */
    
    /* Spacings - Responsivos */
    --bs-container-padding-x: clamp(15px, 3vw, 30px);
    --vitasystem-spacing-xs: clamp(0.25rem, 1vw, 0.5rem);  /* 4-8px */
    --vitasystem-spacing-sm: clamp(0.5rem, 2vw, 1rem);     /* 8-16px */
    --vitasystem-spacing-md: clamp(1rem, 3vw, 1.5rem);     /* 16-24px */
    --vitasystem-spacing-lg: clamp(1.5rem, 4vw, 2rem);     /* 24-32px */
    --vitasystem-spacing-xl: clamp(2rem, 5vw, 3rem);       /* 32-48px */
    
    /* Border Radius - Responsivos */
    --vitasystem-border-radius-sm: clamp(4px, 1.5vw, 6px);
    --vitasystem-border-radius: clamp(8px, 3vw, 12px);
    --vitasystem-border-radius-lg: clamp(12px, 4vw, 16px);
    --vitasystem-border-radius-xl: clamp(25px, 12vw, 50px); /* Botões */
    
    /* Touch Targets - Mínimo 48px */
    --vitasystem-touch-target: max(48px, 3rem);
    --vitasystem-touch-spacing: max(8px, 0.5rem);
}

/* ==========================================================================
   2. TIPOGRAFIA MOBILE FIRST
   ========================================================================== */

body {
    font-size: var(--vitasystem-font-base);
    line-height: clamp(1.4, 1.6, 1.8);
}

h1 { font-size: var(--vitasystem-h1); }
h2 { font-size: var(--vitasystem-h2); }
h3 { font-size: var(--vitasystem-h3); }
h4 { font-size: var(--vitasystem-h4); }
h5 { font-size: var(--vitasystem-h5); }
h6 { font-size: var(--vitasystem-h6); }

/* Line height melhorado para mobile */
h1, h2, h3, h4, h5, h6 {
    line-height: clamp(1.2, 1.3, 1.4);
    margin-bottom: var(--vitasystem-spacing-sm);
}

/* ==========================================================================
   3. COMPONENTES VITASYSTEM MOBILE FIRST
   ========================================================================== */

/* Demo Banner - Responsivo */
.demo-banner {
    font-size: var(--vitasystem-font-sm);
    padding: var(--vitasystem-spacing-xs) var(--vitasystem-spacing-sm);
    border-radius: var(--vitasystem-border-radius-sm);
    text-align: center;
}

/* Navbar - Touch Optimized */
.navbar-brand img {
    max-height: clamp(32px, 8vw, 48px);
    width: auto;
}

.navbar-toggler {
    min-width: var(--vitasystem-touch-target);
    min-height: var(--vitasystem-touch-target);
    border: none;
    padding: var(--vitasystem-touch-spacing);
}

.navbar-nav .nav-link {
    padding: var(--vitasystem-spacing-sm);
    min-height: var(--vitasystem-touch-target);
    display: flex;
    align-items: center;
}

/* Botões - Touch Friendly */
.btn {
    min-height: var(--vitasystem-touch-target);
    min-width: var(--vitasystem-touch-target);
    border-radius: var(--vitasystem-border-radius-xl);
    padding: var(--vitasystem-spacing-sm) var(--vitasystem-spacing-md);
    font-size: var(--vitasystem-font-base);
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-sm {
    min-height: calc(var(--vitasystem-touch-target) * 0.8);
    min-width: calc(var(--vitasystem-touch-target) * 0.8);
    font-size: var(--vitasystem-font-sm);
    padding: var(--vitasystem-spacing-xs) var(--vitasystem-spacing-sm);
}

.btn-lg {
    min-height: calc(var(--vitasystem-touch-target) * 1.2);
    min-width: calc(var(--vitasystem-touch-target) * 1.2);
    font-size: var(--vitasystem-font-lg);
    padding: var(--vitasystem-spacing-md) var(--vitasystem-spacing-lg);
}

/* Cards - Mobile Optimized */
.card {
    margin-bottom: var(--vitasystem-spacing-md);
    border-radius: var(--vitasystem-border-radius);
    border: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.card-header {
    padding: var(--vitasystem-spacing-md);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    background: transparent;
}

.card-body {
    padding: var(--vitasystem-spacing-md);
}

.card-title {
    font-size: var(--vitasystem-font-lg);
    margin-bottom: var(--vitasystem-spacing-sm);
}

/* ==========================================================================
   4. FORMULÁRIOS MOBILE FIRST
   ========================================================================== */

.form-control {
    min-height: var(--vitasystem-touch-target);
    font-size: max(16px, var(--vitasystem-font-base)); /* Prevent zoom on iOS */
    border-radius: var(--vitasystem-border-radius);
    border: 1px solid #dee2e6;
    padding: var(--vitasystem-spacing-sm);
    transition: all 0.2s ease;
}

.form-control:focus {
    border-color: var(--vitasystem-primary);
    box-shadow: 0 0 0 3px rgba(107, 115, 255, 0.1);
}

.form-label {
    font-size: var(--vitasystem-font-base);
    font-weight: 500;
    margin-bottom: var(--vitasystem-spacing-xs);
    color: var(--vitasystem-gray-700);
}

.form-select {
    min-height: var(--vitasystem-touch-target);
    font-size: max(16px, var(--vitasystem-font-base));
    border-radius: var(--vitasystem-border-radius);
}

/* Input Groups */
.input-group {
    margin-bottom: var(--vitasystem-spacing-md);
}

.input-group-text {
    border-radius: var(--vitasystem-border-radius);
    background-color: var(--vitasystem-gray-100);
    border: 1px solid #dee2e6;
    padding: var(--vitasystem-spacing-sm);
}

/* ==========================================================================
   5. TABELAS RESPONSIVAS
   ========================================================================== */

.table-responsive {
    border-radius: var(--vitasystem-border-radius);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.table {
    margin-bottom: 0;
}

.table th,
.table td {
    padding: var(--vitasystem-spacing-sm);
    vertical-align: middle;
    border-color: rgba(0, 0, 0, 0.05);
}

.table th {
    font-weight: 600;
    font-size: var(--vitasystem-font-sm);
    color: var(--vitasystem-gray-700);
    background-color: var(--vitasystem-gray-50);
}

/* Mobile table optimization */
@media (max-width: 575.98px) {
    .table-responsive {
        font-size: var(--vitasystem-font-sm);
        border: none;
    }
    
    .table th,
    .table td {
        padding: var(--vitasystem-spacing-xs);
        white-space: nowrap;
    }
    
    .table-actions {
        min-width: 120px;
    }
}

/* ==========================================================================
   6. MODALS E DIALOGS RESPONSIVOS
   ========================================================================== */

.modal-dialog {
    margin: var(--vitasystem-spacing-sm);
    max-width: calc(100vw - 2 * var(--vitasystem-spacing-sm));
}

.modal-header {
    padding: var(--vitasystem-spacing-md);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.modal-body {
    padding: var(--vitasystem-spacing-md);
}

.modal-footer {
    padding: var(--vitasystem-spacing-md);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    gap: var(--vitasystem-spacing-sm);
}

.modal-title {
    font-size: var(--vitasystem-font-lg);
    font-weight: 600;
}

/* Close button touch-friendly */
.btn-close {
    min-width: var(--vitasystem-touch-target);
    min-height: var(--vitasystem-touch-target);
}

/* ==========================================================================
   7. JQUERY UI MOBILE OPTIMIZATIONS
   ========================================================================== */

/* Datepicker Mobile */
.ui-datepicker {
    font-size: var(--vitasystem-font-base) !important;
    border-radius: var(--vitasystem-border-radius) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
    border: none !important;
}

.ui-datepicker .ui-datepicker-header {
    background: var(--vitasystem-primary) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--vitasystem-border-radius-sm) var(--vitasystem-border-radius-sm) 0 0 !important;
    padding: var(--vitasystem-spacing-sm) !important;
}

.ui-datepicker .ui-datepicker-prev,
.ui-datepicker .ui-datepicker-next {
    width: var(--vitasystem-touch-target) !important;
    height: var(--vitasystem-touch-target) !important;
}

.ui-datepicker td {
    padding: 2px !important;
}

.ui-datepicker td a {
    min-width: var(--vitasystem-touch-target) !important;
    min-height: var(--vitasystem-touch-target) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: var(--vitasystem-border-radius-sm) !important;
    text-decoration: none !important;
}

/* Dialog Mobile */
.ui-dialog {
    border-radius: var(--vitasystem-border-radius) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15) !important;
}

.ui-dialog-titlebar {
    background: var(--vitasystem-primary) !important;
    color: white !important;
    border: none !important;
    border-radius: var(--vitasystem-border-radius-sm) var(--vitasystem-border-radius-sm) 0 0 !important;
    padding: var(--vitasystem-spacing-md) !important;
}

.ui-dialog-titlebar-close {
    width: var(--vitasystem-touch-target) !important;
    height: var(--vitasystem-touch-target) !important;
    right: var(--vitasystem-spacing-xs) !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
}

/* Tabs Mobile */
.ui-tabs .ui-tabs-nav {
    border: none !important;
    background: transparent !important;
    border-radius: 0 !important;
    padding: 0 !important;
}

.ui-tabs .ui-tabs-nav li {
    margin: 0 var(--vitasystem-spacing-xs) 0 0 !important;
    border: none !important;
    background: transparent !important;
}

.ui-tabs .ui-tabs-nav li a {
    padding: var(--vitasystem-spacing-sm) var(--vitasystem-spacing-md) !important;
    border-radius: var(--vitasystem-border-radius) !important;
    background: var(--vitasystem-gray-100) !important;
    border: 1px solid var(--vitasystem-gray-200) !important;
    color: var(--vitasystem-gray-700) !important;
    min-height: var(--vitasystem-touch-target) !important;
    display: flex !important;
    align-items: center !important;
}

.ui-tabs .ui-tabs-nav li.ui-tabs-active a {
    background: var(--vitasystem-primary) !important;
    color: white !important;
    border-color: var(--vitasystem-primary) !important;
}

/* ==========================================================================
   8. BREAKPOINTS ESPECÍFICOS BOOTSTRAP 5
   ========================================================================== */

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
    .demo-banner {
        text-align: left;
        padding: var(--vitasystem-spacing-sm) var(--vitasystem-spacing-md);
    }
    
    .modal-dialog {
        margin: var(--vitasystem-spacing-lg) auto;
        max-width: 500px;
    }
    
    .table-responsive {
        font-size: var(--vitasystem-font-base);
    }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
    :root {
        --bs-container-padding-x: 2rem;
    }
    
    .navbar-nav .nav-link {
        padding: var(--vitasystem-spacing-xs) var(--vitasystem-spacing-md);
    }
    
    .card-body {
        padding: var(--vitasystem-spacing-lg);
    }
    
    .modal-dialog {
        max-width: 600px;
    }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
    .card:hover {
        transform: translateY(-4px);
    }
    
    .btn {
        transition: all 0.3s ease;
    }
    
    .modal-dialog {
        max-width: 700px;
    }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .container,
    .container-lg,
    .container-md,
    .container-sm,
    .container-xl {
        max-width: 1140px;
    }
    
    .modal-dialog {
        max-width: 800px;
    }
}

/* Extra extra large devices (larger desktops, 1400px and up) */
@media (min-width: 1400px) {
    .container,
    .container-lg,
    .container-md,
    .container-sm,
    .container-xl,
    .container-xxl {
        max-width: 1320px;
    }
}

/* ==========================================================================
   9. UTILITIES MOBILE FIRST
   ========================================================================== */

/* Touch-friendly spacing */
.touch-friendly {
    min-width: var(--vitasystem-touch-target);
    min-height: var(--vitasystem-touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile hide/show */
.mobile-only {
    display: block;
}

.desktop-only {
    display: none;
}

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

/* Scroll improvements */
.smooth-scroll {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Focus improvements for accessibility */
.form-control:focus,
.btn:focus,
.nav-link:focus {
    outline: 2px solid var(--vitasystem-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   10. PERFORMANCE OPTIMIZATIONS
   ========================================================================== */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Force hardware acceleration for smooth animations */
.card,
.btn,
.modal-dialog {
    transform: translateZ(0);
    will-change: transform;
}

/* Optimize font rendering */
body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeSpeed;
}

/* Improve scrolling performance */
* {
    scroll-behavior: smooth;
}

/* ==========================================================================
   11. PRINT STYLES
   ========================================================================== */

@media print {
    .demo-banner,
    .navbar,
    .btn,
    .modal,
    .offcanvas {
        display: none !important;
    }
    
    .card {
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
    }
    
    body {
        font-size: 12pt;
        line-height: 1.4;
    }
}
