/* =============================
   GSWeb - Optimisation Mobile & Android
   Prêt pour APK / PWA
   ============================= */

/* ===== 1. OPTIMISATIONS TACTILES ===== */

/* Taille minimale des éléments tactiles (44x44px) */
button,
.btn,
a,
input,
select,
textarea,
.table tbody tr td,
.navbar-nav > li > a {
    min-height: 44px;
    min-width: 44px;
}

/* Retirer le délai de 300ms sur mobile */
* {
    touch-action: manipulation;
    -ms-touch-action: manipulation;
}

/* Désactiver le zoom sur les inputs */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
select,
textarea {
    font-size: 16px !important; /* Empêche le zoom auto sur iOS */
}

/* Améliorer le scroll tactile */
body,
.modal,
.dropdown-menu,
.dataTables_wrapper {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
}

/* Retirer le highlight bleu sur Android */
* {
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.1);
    tap-highlight-color: rgba(37, 99, 235, 0.1);
}

/* ===== 2. LAYOUT MOBILE ===== */

/* Container pleine largeur sur mobile */
@media (max-width: 768px) {
    .container {
        width: 100% !important;
        padding: 12px !important;
        margin: 0 !important;
    }
    
    body {
        padding: 0 !important;
        margin: 0 !important;
    }
}

/* Espacement optimisé mobile */
@media (max-width: 576px) {
    .gs-page-header {
        padding: 16px !important;
        flex-direction: column;
        align-items: flex-start !important;
        gap: 12px !important;
    }
    
    .gs-page-header__title {
        font-size: 20px !important;
    }
    
    .gs-page-header__description {
        font-size: 14px !important;
    }
    
    .gs-card,
    .gs-card-modern {
        padding: 16px !important;
        margin-bottom: 16px !important;
        border-radius: 12px !important;
    }
    
    .home-sections {
        padding: 12px !important;
        margin: 8px 0 !important;
    }
}

/* ===== 3. NAVIGATION MOBILE ===== */

/* Navbar optimisée pour mobile */
@media (max-width: 768px) {
    .navbar {
        min-height: 56px !important;
        border-radius: 0 !important;
        margin-bottom: 0 !important;
    }
    
    .navbar-nav {
        margin: 0 !important;
    }
    
    .navbar-nav > li > a {
        padding: 14px 16px !important;
        font-size: 15px !important;
    }
    
    /* Menu hamburger zone tactile */
    .navbar-toggle {
        padding: 12px !important;
        margin: 8px !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    .navbar-collapse {
        border: none !important;
        box-shadow: none !important;
    }
}

/* Bottom Navigation (style Android) */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid #e5e7eb;
    display: none;
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        padding: 8px 0;
    }
    
    body {
        padding-bottom: 70px; /* Espace pour bottom nav */
    }
}

.mobile-bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px;
    color: #6b7280;
    text-decoration: none;
    font-size: 11px;
    transition: all 200ms;
    min-height: 56px;
}

.mobile-bottom-nav__item.active {
    color: #2563eb;
}

.mobile-bottom-nav__icon {
    font-size: 24px;
    margin-bottom: 4px;
}

/* ===== 4. FORMULAIRES MOBILE ===== */

@media (max-width: 576px) {
    .gs-form-group {
        margin-bottom: 16px !important;
    }
    
    .gs-form-input,
    .form-control {
        padding: 14px 16px !important;
        font-size: 16px !important;
        border-radius: 10px !important;
        height: auto !important;
        min-height: 48px !important;
    }
    
    select.gs-form-input,
    select.form-control {
        min-height: 48px !important;
        appearance: none;
        -webkit-appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: left 16px center;
        padding-left: 40px !important;
    }
    
    textarea.gs-form-input,
    textarea.form-control {
        min-height: 100px !important;
    }
    
    .btn {
        padding: 14px 24px !important;
        font-size: 16px !important;
        width: 100%;
        margin-bottom: 12px;
    }
    
    .btn-xs,
    .btn-sm {
        width: auto !important;
        padding: 10px 16px !important;
    }
}

/* Keyboard avec suggestions */
input[type="email"] {
    autocomplete: email;
    autocapitalize: off;
}

input[type="tel"] {
    autocomplete: tel;
}

input[type="text"][name*="name"],
input[type="text"][name*="nom"] {
    autocomplete: name;
    autocapitalize: words;
}

/* ===== 5. TABLES MOBILE ===== */

@media (max-width: 768px) {
    .dataTables_wrapper {
        padding: 12px !important;
        border-radius: 12px !important;
    }
    
    /* Table en mode carte sur mobile */
    .table-mobile-cards {
        display: block !important;
    }
    
    .table-mobile-cards thead {
        display: none !important;
    }
    
    .table-mobile-cards tbody,
    .table-mobile-cards tr,
    .table-mobile-cards td {
        display: block !important;
        width: 100% !important;
    }
    
    .table-mobile-cards tr {
        margin-bottom: 16px !important;
        background: white !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 12px !important;
        padding: 12px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
    }
    
    .table-mobile-cards td {
        border: none !important;
        padding: 8px 0 !important;
        position: relative;
        padding-left: 45% !important;
        text-align: right !important;
    }
    
    .table-mobile-cards td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 40%;
        padding-right: 10px;
        white-space: nowrap;
        font-weight: 600;
        color: #374151;
    }
    
    .table-mobile-cards td:last-child {
        text-align: center !important;
        padding-left: 0 !important;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid #e5e7eb !important;
    }
    
    .table-mobile-cards td:last-child::before {
        display: none;
    }
    
    /* Scroll horizontal pour tables normales */
    .table-responsive {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 12px;
    }
    
    .table-responsive .table {
        min-width: 600px;
    }
}

/* ===== 6. MODALS MOBILE ===== */

@media (max-width: 576px) {
    .modal,
    .gs-modal {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        height: 100vh;
        max-height: 100vh !important;
    }
    
    .modal-dialog {
        width: 100% !important;
        margin: 0 !important;
    }
    
    .modal-content,
    .gs-modal__body {
        border-radius: 0 !important;
        max-height: calc(100vh - 150px) !important;
    }
    
    .gs-modal__header {
        padding: 16px !important;
        position: sticky;
        top: 0;
        background: white;
        z-index: 1;
    }
    
    .gs-modal__footer {
        padding: 16px !important;
        position: sticky;
        bottom: 0;
        background: white;
    }
}

/* ===== 7. STATS CARDS MOBILE ===== */

@media (max-width: 768px) {
    .gs-stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }
    
    .gs-stat-card {
        padding: 16px !important;
    }
    
    .gs-stat-card__value {
        font-size: 24px !important;
    }
    
    .gs-stat-card__label {
        font-size: 12px !important;
    }
}

@media (max-width: 400px) {
    .gs-stats-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ===== 8. CARDS MOBILE ===== */

@media (max-width: 576px) {
    .gs-card-icon {
        flex-direction: row !important;
        gap: 12px !important;
    }
    
    .gs-card-icon__icon {
        width: 40px !important;
        height: 40px !important;
        font-size: 20px !important;
    }
    
    .gs-card-icon__content h3 {
        font-size: 16px !important;
        margin-bottom: 4px !important;
    }
    
    .gs-card-icon__content p {
        font-size: 13px !important;
    }
}

/* ===== 9. ALERTS MOBILE ===== */

@media (max-width: 576px) {
    .gs-alert {
        padding: 12px 14px !important;
        font-size: 14px !important;
    }
    
    .gs-alert__icon {
        font-size: 18px !important;
    }
    
    .gs-alert__title {
        font-size: 14px !important;
    }
    
    .gs-alert__message {
        font-size: 13px !important;
    }
}

/* ===== 10. TOAST MOBILE ===== */

@media (max-width: 576px) {
    .toast {
        left: 8px !important;
        right: 8px !important;
        bottom: 80px !important; /* Au dessus du bottom nav */
        max-width: none !important;
        border-radius: 10px !important;
        padding: 12px 16px !important;
        font-size: 14px !important;
    }
}

/* ===== 11. PAGINATION MOBILE ===== */

@media (max-width: 576px) {
    .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
    }
    
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        padding: 8px 12px !important;
        margin: 2px !important;
        font-size: 14px !important;
    }
    
    .dataTables_wrapper .dataTables_info,
    .dataTables_wrapper .dataTables_length {
        text-align: center !important;
        font-size: 13px !important;
    }
    
    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin: 8px 0 !important;
    }
}

/* ===== 12. ORIENTATION LANDSCAPE ===== */

@media (max-width: 768px) and (orientation: landscape) {
    .gs-page-header {
        padding: 12px 16px !important;
    }
    
    .gs-page-header__title {
        font-size: 18px !important;
    }
    
    .mobile-bottom-nav {
        display: none !important;
    }
    
    body {
        padding-bottom: 0 !important;
    }
}

/* ===== 13. PULL TO REFRESH ===== */

.ptr-container {
    position: relative;
    overflow: hidden;
}

.ptr-content {
    transition: transform 0.3s;
}

.ptr-loading {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    padding: 20px;
    text-align: center;
    opacity: 0;
    transition: all 0.3s;
}

.ptr-container.ptr-active .ptr-loading {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== 14. SAFE AREA (NOTCH) ===== */

/* Support pour iPhone X, notch Android */
body {
    padding-top: constant(safe-area-inset-top);
    padding-top: env(safe-area-inset-top);
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
}

.navbar {
    padding-top: constant(safe-area-inset-top);
    padding-top: env(safe-area-inset-top);
}

.mobile-bottom-nav {
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
}

/* ===== 15. OPTIMISATIONS PERFORMANCE MOBILE ===== */

/* Réduire les animations sur mobile */
@media (max-width: 768px) {
    * {
        animation-duration: 0.2s !important;
        transition-duration: 0.15s !important;
    }
    
    /* Désactiver les hover effects sur tactile */
    .hover-lift:hover,
    .hover-glow:hover,
    .hover-scale:hover {
        transform: none !important;
        box-shadow: none !important;
    }
}

/* ===== 16. TEXT MOBILE ===== */

@media (max-width: 576px) {
    body {
        font-size: 14px !important;
        line-height: 1.5 !important;
    }
    
    h1 {
        font-size: 24px !important;
    }
    
    h2 {
        font-size: 20px !important;
    }
    
    h3 {
        font-size: 18px !important;
    }
    
    h4 {
        font-size: 16px !important;
    }
    
    h5, h6 {
        font-size: 14px !important;
    }
}

/* ===== 17. IMAGES MOBILE ===== */

@media (max-width: 768px) {
    img {
        max-width: 100% !important;
        height: auto !important;
    }
    
    .gs-login__logo {
        width: 72px !important;
        height: 72px !important;
    }
}

/* ===== 18. LOADING OVERLAY MOBILE ===== */

@media (max-width: 576px) {
    .loading-overlay {
        backdrop-filter: blur(8px);
    }
    
    .spinner-lg {
        width: 32px !important;
        height: 32px !important;
    }
}

/* ===== 19. BACK TO TOP MOBILE ===== */

@media (max-width: 576px) {
    #backToTop {
        width: 44px !important;
        height: 44px !important;
        bottom: 80px !important; /* Au dessus du bottom nav */
        right: 16px !important;
        font-size: 20px !important;
    }
}

/* ===== 20. ANDROID NATIVE STYLES ===== */

/* Style Material Design pour Android */
.android-ripple {
    position: relative;
    overflow: hidden;
}

.android-ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.android-ripple:active::after {
    width: 300px;
    height: 300px;
}

/* ===== 21. GESTURE SUPPORT ===== */

/* Swipe indicators */
.swipe-indicator {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    background: rgba(37, 99, 235, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 1001;
}

.swipe-indicator.left {
    left: 20px;
}

.swipe-indicator.right {
    right: 20px;
}

.swipe-indicator.active {
    opacity: 1;
}

/* ===== 22. OFFLINE INDICATOR ===== */

.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #dc2626;
    color: white;
    text-align: center;
    padding: 8px;
    font-size: 13px;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s;
}

.offline-indicator.show {
    transform: translateY(0);
}

/* ===== 23. VIBRATION FEEDBACK ===== */

/* Classe pour indiquer les éléments avec feedback haptique */
.haptic-feedback:active {
    opacity: 0.7;
}

/* ===== 24. OPTIMISATIONS SPÉCIFIQUES TABLE NOTES MOBILE ===== */

@media (max-width: 768px) {
    /* Container du tableau de notes */
    #listNotes_wrapper {
        width: 100% !important;
        overflow: visible !important;
    }
    
    /* Le tableau lui-même doit scroller horizontalement */
    #listNotes_wrapper .dataTables_scroll {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    #listNotes {
        width: 100% !important;
        min-width: 100% !important;
        font-size: 13px !important;
        display: table !important;
    }
    
    /* Cellules plus compactes sur mobile */
    #listNotes th,
    #listNotes td {
        padding: 10px 8px !important;
        white-space: nowrap !important;
        font-size: 13px !important;
    }
    
    /* En-têtes fixes pour scroll horizontal */
    #listNotes thead {
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
        background-color: #f0f0f0 !important;
    }
    
    /* Ajuster la largeur des colonnes importantes */
    #listNotes td:nth-child(3),
    #listNotes th:nth-child(3) {
        min-width: 150px !important;
        max-width: 200px !important;
        white-space: normal !important;
        word-wrap: break-word !important;
    }
    
    /* Colonnes de notes (étroites) */
    #listNotes td:nth-child(n+4),
    #listNotes th:nth-child(n+4) {
        min-width: 60px !important;
        text-align: center !important;
    }
    
    /* Wrapper du tableau avec scroll visible */
    .gs-card {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 0 !important;
    }
    
    /* Indicateur de scroll */
    .gs-card::after {
        content: '← Faites défiler →';
        display: block;
        text-align: center;
        padding: 12px;
        background: #f9fafb;
        color: #6b7280;
        font-size: 12px;
        border-top: 1px solid #e5e7eb;
        animation: fadeOut 3s ease-in-out forwards;
    }
    
    @keyframes fadeOut {
        0%, 70% { opacity: 1; }
        100% { opacity: 0; display: none; }
    }
    
    /* Améliorer la visibilité des boutons d'action */
    #listNotes .btn-xs {
        padding: 6px 10px !important;
        font-size: 12px !important;
        margin: 2px !important;
        white-space: nowrap !important;
    }
    
    /* Pagination plus visible sur mobile */
    #listNotes_wrapper .dataTables_paginate {
        padding: 16px 0 !important;
        text-align: center !important;
    }
    
    #listNotes_wrapper .paginate_button {
        padding: 10px 14px !important;
        margin: 0 4px !important;
        border-radius: 8px !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    /* Gestion du processing/loading */
    #listNotes_processing {
        background: rgba(255, 255, 255, 0.95) !important;
        border-radius: 12px !important;
        padding: 20px !important;
        font-size: 16px !important;
    }
}

/* Très petits écrans (< 400px) */
@media (max-width: 400px) {
    #listNotes {
        font-size: 11px !important;
    }
    
    #listNotes th,
    #listNotes td {
        padding: 8px 6px !important;
        font-size: 11px !important;
    }
    
    #listNotes .btn-xs {
        padding: 4px 8px !important;
        font-size: 11px !important;
    }
}

/* ===== 25. DARK MODE MOBILE ===== */

@media (prefers-color-scheme: dark) {
    /* Les variables dark mode seront définies ici si nécessaire */
}

/* ===== 26. PRINT MOBILE ===== */

@media print {
    .mobile-bottom-nav,
    #backToTop,
    .navbar-toggle,
    .toast,
    .loading-overlay {
        display: none !important;
    }
}

