/**
 * Fichier  : assets/css/crud-mobile.css
 * Auteur   : KREMER Régis
 * Version  : 2.6.86
 * Date     : 2026-07-20
 * Description : Cartes métier et volets tactiles des CRUD secondaires.
 *
 * Changelog :
 *   v2.6.86 (2026-07-20) — CRUD MOBILE CARDS10.
 */

.crud-mobile-cards,
.crud-mobile-filter-toolbar {
    display: none;
}

@media (max-width: 1199px) {
    html[data-crud-mobile-page] .crud-mobile-source {
        display: none !important;
    }

    html[data-crud-mobile-page] .crud-mobile-cards {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 12px;
        margin-top: 14px;
        padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    }

    html[data-crud-mobile-page] .crud-mobile-filter-toolbar {
        display: flex;
        justify-content: flex-end;
        margin: 0 0 10px;
    }

    .crud-mobile-filter-button {
        min-height: 46px;
        min-width: 112px;
    }

    .crud-mobile-filter-button.is-active {
        border-color: var(--blue, #2563eb);
        color: var(--blue, #2563eb);
    }

    .crud-mobile-card {
        min-width: 0;
        margin: 0;
        overflow: hidden;
    }

    .crud-mobile-card .ms-entity-card__header {
        align-items: flex-start;
        gap: 10px;
    }

    .crud-mobile-card .ms-entity-card__identity {
        min-width: 0;
    }

    .crud-mobile-card .ms-entity-card__title,
    .crud-mobile-card .ms-entity-card__meta,
    .crud-mobile-card dd {
        overflow-wrap: anywhere;
    }

    .crud-mobile-card__status {
        flex: 0 0 auto;
        max-width: 42%;
        padding: 5px 8px;
        border: 1px solid var(--border);
        background: var(--bg-input);
        color: var(--text-secondary);
        font-size: 11px;
        font-weight: 800;
        line-height: 1.2;
        text-align: center;
    }

    .crud-mobile-card__status.is-success {
        border-color: color-mix(in srgb, var(--green, #16a34a) 38%, transparent);
        background: color-mix(in srgb, var(--green, #16a34a) 12%, transparent);
        color: var(--green, #16a34a);
    }

    .crud-mobile-card__status.is-warning {
        border-color: color-mix(in srgb, var(--warning, #d97706) 40%, transparent);
        background: color-mix(in srgb, var(--warning, #d97706) 12%, transparent);
        color: var(--warning, #d97706);
    }

    .crud-mobile-card__status.is-danger {
        border-color: color-mix(in srgb, var(--red, #dc2626) 40%, transparent);
        background: color-mix(in srgb, var(--red, #dc2626) 12%, transparent);
        color: var(--red, #dc2626);
    }

    .crud-mobile-card .ms-entity-card__fields {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .crud-mobile-card .ms-entity-card__field:first-child:nth-last-child(1) {
        grid-column: 1 / -1;
    }

    .crud-mobile-card__actions {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .crud-mobile-card__actions .btn,
    .crud-mobile-load-more {
        min-height: 48px;
        white-space: normal;
    }

    .crud-mobile-load-more {
        width: 100%;
    }

    .crud-mobile-empty {
        display: grid;
        gap: 4px;
        padding: 28px 18px;
        border: 1px dashed var(--border);
        background: var(--bg-card);
        color: var(--text-muted);
        text-align: center;
    }

    .crud-mobile-empty strong {
        color: var(--text-primary);
    }

    .crud-mobile-filter-form {
        display: grid;
        gap: 14px;
    }

    .crud-mobile-filter-field {
        display: grid;
        gap: 6px;
        font-size: 13px;
        font-weight: 750;
        color: var(--text-secondary);
    }

    .crud-mobile-filter-field select,
    .crud-mobile-filter-field input {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
    }

    html[data-crud-mobile-page] .filters-divider,
    html[data-crud-mobile-page] .filters-section:empty {
        display: none !important;
    }

    html[data-crud-mobile-page] .filters-bar,
    html[data-crud-mobile-page] .report-filters,
    html[data-crud-mobile-page] .loc-topbar {
        min-width: 0;
    }

    html[data-crud-mobile-page] .search-box,
    html[data-crud-mobile-page] .loc-search-wrap,
    html[data-crud-mobile-page] .report-filters > input {
        width: 100%;
        min-width: 0;
    }

    html[data-crud-mobile-page] .filters-bar .btn,
    html[data-crud-mobile-page] .loc-topbar .btn,
    html[data-crud-mobile-page] .admin-action-row .btn,
    html[data-crud-mobile-page] .sect-toolbar .btn {
        min-height: 46px;
    }

    /* Les formulaires CRUD courts deviennent des feuilles tactiles. */
    #modalOverlay.crud-mobile-modal {
        align-items: flex-end !important;
        justify-content: center !important;
        padding: 0 !important;
    }

    #modalOverlay.crud-mobile-modal #modalBox {
        width: min(100%, 720px) !important;
        max-width: none !important;
        max-height: min(92dvh, calc(var(--ms-visual-height, 100dvh) - 8px)) !important;
        margin: 0 !important;
        border-radius: 14px 14px 0 0 !important;
        border-bottom: 0 !important;
        display: flex;
        flex-direction: column;
    }

    #modalOverlay.crud-mobile-modal .modal-hdr {
        flex: 0 0 auto;
        position: sticky;
        top: 0;
        z-index: 3;
        background: var(--bg-card);
    }

    #modalOverlay.crud-mobile-modal .modal-body {
        min-height: 0;
        overflow: auto;
        overscroll-behavior: contain;
        padding-bottom: 18px;
    }

    #modalOverlay.crud-mobile-modal .modal-footer {
        flex: 0 0 auto;
        position: sticky;
        bottom: 0;
        z-index: 4;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        background: var(--bg-card);
        border-top: 1px solid var(--border);
    }

    #modalOverlay.crud-mobile-modal .modal-footer .btn {
        min-height: 48px;
        white-space: normal;
    }

    #modalOverlay.crud-mobile-modal .modal-footer .btn-danger:last-child:nth-child(3) {
        grid-column: 1 / -1;
    }

    #modalOverlay.crud-mobile-modal .modal-body [style*="grid-template-columns"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    #modalOverlay.crud-mobile-modal .modal-body [style*="min-width"] {
        min-width: 0 !important;
    }

    #modalOverlay.crud-mobile-modal .modal-body .row,
    #modalOverlay.crud-mobile-modal .modal-body [style*="display:flex"] {
        align-items: stretch !important;
    }

    #modalOverlay.crud-mobile-modal input,
    #modalOverlay.crud-mobile-modal select,
    #modalOverlay.crud-mobile-modal textarea {
        width: 100%;
        max-width: 100%;
        min-height: 46px;
        font-size: 16px;
    }

    /* Emplacements : la vue Zones est la carte métier native sur mobile/tablette. */
    html[data-crud-mobile-page="locations"] .loc-view-toggle [data-view="table"] {
        display: none !important;
    }

    html[data-crud-mobile-page="locations"] #locTableWrap {
        display: none !important;
    }

    .crud-mobile-location-card {
        min-width: 0;
        padding: 14px !important;
        transform: none !important;
    }

    .crud-mobile-location-card .loc-emp-actions {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 8px;
    }

    .crud-mobile-location-card .loc-emp-actions .btn {
        min-height: 44px;
    }

    /* Gestionnaire de magasin : les cartes existantes rejoignent le patron commun. */
    html[data-crud-mobile-page="warehouse-manager"] .warehouse-manager-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 12px !important;
        padding: 0 !important;
    }

    .crud-mobile-manager-card {
        min-width: 0;
        padding: 16px !important;
        transform: none !important;
    }

    .crud-mobile-manager-card .warehouse-actions,
    .crud-mobile-manager-card .warehouse-categories-header {
        gap: 8px;
    }

    .crud-mobile-manager-card button {
        min-height: 44px;
        min-width: 44px;
    }

    .crud-mobile-manager-card .category-tag-remove {
        min-height: 28px;
        min-width: 28px;
    }
}

@media (min-width: 600px) and (max-width: 1199px) {
    html[data-crud-mobile-page] .crud-mobile-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    html[data-crud-mobile-page] .crud-mobile-load-more,
    html[data-crud-mobile-page] .crud-mobile-empty {
        grid-column: 1 / -1;
    }

    #modalOverlay.crud-mobile-modal {
        align-items: stretch !important;
        justify-content: flex-end !important;
    }

    #modalOverlay.crud-mobile-modal #modalBox {
        width: min(620px, 78vw) !important;
        height: 100dvh;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        border-right: 0 !important;
    }
}

@media (max-width: 599px) {
    html[data-crud-mobile-page] .filters-bar,
    html[data-crud-mobile-page] .loc-topbar,
    html[data-crud-mobile-page] .loc-topbar-left,
    html[data-crud-mobile-page] .loc-topbar-right,
    html[data-crud-mobile-page] .sect-toolbar {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 10px !important;
    }

    html[data-crud-mobile-page] .filters-section,
    html[data-crud-mobile-page] .filters-section.ml-auto,
    html[data-crud-mobile-page] .loc-topbar-left,
    html[data-crud-mobile-page] .loc-topbar-right {
        width: 100%;
        margin-left: 0 !important;
    }

    html[data-crud-mobile-page] .filters-section.ml-auto,
    html[data-crud-mobile-page] .loc-topbar-right {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: 8px;
    }

    .crud-mobile-card .ms-entity-card__fields {
        grid-template-columns: minmax(0, 1fr);
    }

    .crud-mobile-card__actions {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 1199px) {
    .lot-history-timeline {
        display: grid;
        gap: 10px;
    }

    .lot-history-item {
        display: grid;
        gap: 10px;
        padding: 14px;
        border: 1px solid var(--border);
        background: var(--bg-input);
    }

    .lot-history-item__head {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 12px;
    }

    .lot-history-item__head time {
        color: var(--text-muted);
        font-size: 12px;
        text-align: right;
    }

    .lot-history-item dl {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin: 0;
    }

    .lot-history-item dl > div {
        display: grid;
        gap: 2px;
    }

    .lot-history-item dt {
        color: var(--text-muted);
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
    }

    .lot-history-item dd,
    .lot-history-item p {
        margin: 0;
        overflow-wrap: anywhere;
    }

    .crud-confirm-message {
        margin: 0;
        line-height: 1.55;
        white-space: pre-line;
    }
}

@media (max-width: 599px) {
    #modalOverlay.crud-mobile-modal [data-comp-row] {
        display: grid !important;
        grid-template-columns: minmax(0, 1fr) minmax(90px, .45fr) 48px;
        gap: 8px !important;
    }

    #modalOverlay.crud-mobile-modal [data-comp-row] [data-comp-pid] {
        grid-column: 1 / -1;
        width: 100% !important;
    }

    #modalOverlay.crud-mobile-modal [data-comp-row] [data-comp-unit] {
        min-width: 0 !important;
        width: 100% !important;
    }

    #modalOverlay.crud-mobile-modal [data-comp-row] [data-comp-del] {
        width: 48px;
        min-width: 48px;
        min-height: 48px;
    }

    #modalOverlay.crud-mobile-modal[data-crud-page="kits"] #modalBody > div > .row:last-child,
    #modalOverlay.crud-mobile-modal[data-crud-page="reservations"] #modalBody > div > .row:last-child {
        position: sticky;
        bottom: -18px;
        z-index: 3;
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin: 18px -18px -18px !important;
        padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px));
        background: var(--bg-card);
        border-top: 1px solid var(--border);
    }

    #modalOverlay.crud-mobile-modal[data-crud-page="kits"] #modalBody > div > .row:last-child .btn,
    #modalOverlay.crud-mobile-modal[data-crud-page="reservations"] #modalBody > div > .row:last-child .btn {
        min-height: 48px;
    }
}
