/**
 * MIP — Mobile-first UX (MAIN + TENANTS)
 * Couche globale : overflow, pouce, modales, tableaux, clavier.
 * Ne réécrit pas les thèmes ; complète mip-responsive / action-buttons.
 */

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html,
body {
    max-width: 100%;
}

/* Évite le scroll horizontal accidentel (page), pas les tableaux internes */
body.mip-main-app,
body.mip-pharm-theme,
body.mip-clinic-pro,
body.mip-cabinet-theme,
body.mip-lab-theme,
body.mip-imaging-theme,
body.m5-kindi-app,
.app-wrapper {
    overflow-x: clip;
}

/* ---------- Tap targets pouce (téléphones) ---------- */
@media (max-width: 430px) {
    .btn-primary,
    .btn-secondary,
    .btn-danger,
    .submit-btn,
    .mip-tenant-btn--primary,
    .menu-toggle,
    #menuToggle,
    .pf-sidebar-collapse-btn,
    .cds-page-tool-btn--primary,
    .cds-page-tool-btn {
        min-height: 44px;
        min-width: 44px;
    }

    .btn-sm,
    .mip-action-icon,
    .tenant-action-btn,
    a.btn-icon,
    .products-icon-btn,
    .cds-icon-action-btn {
        min-height: 40px;
        min-width: 40px;
    }

    /* Delete vs Save : jamais côte à côte identiques */
    .form-actions,
    .mip-dialog-footer,
    .modal-footer,
    .cds-form-footer,
    .cds-appt-form-actions {
        gap: 12px;
        row-gap: 10px;
    }
}

/* Clavier iOS : 16px évite le zoom auto */
@media (max-width: 768px) {
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]),
    select,
    textarea {
        font-size: 16px !important;
        max-width: 100%;
    }

    img,
    svg,
    video,
    canvas {
        max-width: 100%;
        height: auto;
    }

    /* Tableaux : scroll interne, pas la page */
    .table-wrap,
    .table-responsive,
    .mip-table-wrap,
    .data-table-wrap,
    table.mip-table,
    .products-table-wrap,
    .cds-table-wrap {
        overflow-x: auto;
        max-width: 100%;
        -webkit-overflow-scrolling: touch;
    }

    /* Pagination / filtres / recherche : wrap */
    .pagination,
    .mip-pagination,
    .list-filters,
    .mip-list-filters,
    .products-toolbar,
    .list-toolbar,
    .patients-toolbar {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .search-bar,
    .topbar-search-wrap,
    input[type="search"],
    .filter-select {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Dropdowns dans le viewport */
    .topbar-dropdown,
    .dropdown-menu,
    .mip-select-menu {
        max-width: min(100vw - 16px, 360px);
        max-height: min(70vh, 420px);
        overflow: auto;
    }

    /* Modales / drawers */
    .modal,
    .mip-dialog-overlay .mip-dialog,
    .mip-crud-dialog,
    .mip-alert-dialog__card,
    .product-edit-modal {
        max-width: calc(100vw - 16px);
        max-height: min(100dvh - 16px, 100%);
        box-sizing: border-box;
    }

    .mip-dialog-overlay,
    .mip-crud-dialog-overlay,
    .modal-overlay,
    .sidebar-overlay {
        padding: env(safe-area-inset-top, 8px) 8px env(safe-area-inset-bottom, 8px);
        box-sizing: border-box;
    }

    .sidebar,
    .app-sidebar {
        max-width: min(92vw, 320px);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
}

/* Sticky actions au-dessus du clavier / home indicator */
@media (max-width: 768px) {
    .form-actions--sticky,
    .mip-form-actions-bar,
    .cds-form-page .cds-appt-form-footer-slot,
    .cds-form-page .cds-form-footer {
        bottom: env(safe-area-inset-bottom, 0);
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom, 0px));
    }

    body.mip-kb-open .form-actions--sticky,
    body.mip-kb-open .cds-form-page .cds-appt-form-footer-slot,
    body.mip-kb-open .cds-form-page .cds-form-footer,
    body.mip-kb-open .modal-footer,
    body.mip-kb-open .mip-dialog-footer {
        bottom: var(--mip-kb-inset, 0px);
    }
}

/* 360 : encore plus compact, pas de troncature critique des titres */
@media (max-width: 360px) {
    .page-title,
    .saydali-page-title,
    .cds-page-title,
    .mip-drugs-page-title {
        font-size: 1.05rem;
        line-height: 1.3;
        overflow-wrap: anywhere;
    }

    .topbar,
    .saydali-header {
        padding-inline: 8px;
    }
}

/* Tablette 768–1024 : drawer déjà géré par mip-responsive ; garder boutons lisibles */
@media (min-width: 431px) and (max-width: 1024px) {
    .btn-primary,
    .submit-btn,
    .mip-tenant-btn--primary {
        min-height: 42px;
    }
}
