/*
 * Portail sur smartphone et tablette (AFIS 7.62 / AER 0.28).
 * Commun aux deux plugins : même code, mêmes classes "cmm-".
 * Bureau (> 1024 px) : rien ne change, ces éléments restent masqués.
 */
.cmm-top, .cmm-veil, .cmm-pager, .cmm-drawer-head { display: none; }

@media (max-width: 1024px) {
    .cmm-root {
        display: block !important;
        min-height: 0 !important;
        overflow: visible !important;
        position: relative;
    }
    /* Toute la largeur de l'écran : les thèmes à blocs réduisent sinon le
       portail à une colonne étroite (sélecteur renforcé contre leurs !important). */
    html body .cmm-root.cmm-root {
        width: 100vw !important;
        max-width: 100vw !important;
        margin-left: calc(50% - 50vw) !important;
        margin-right: calc(50% - 50vw) !important;
        box-sizing: border-box !important;
        border-left: 0 !important;
        border-right: 0 !important;
        border-radius: 0 !important;
    }

    /* --- Barre du haut (reste visible au défilement) --- */
    .cmm-top {
        display: block;
        position: -webkit-sticky;
        position: sticky;
        top: 0;
        z-index: 9990;
        box-shadow: 0 2px 10px rgba(15, 37, 66, .18);
    }
    body.admin-bar .cmm-top { top: 32px; }
    .cmm-bar {
        display: flex;
        align-items: center;
        gap: 6px;
        background: #0f2542;
        color: #fff;
        padding: 8px 8px 8px 6px;
        padding-top: calc(8px + env(safe-area-inset-top, 0px));
    }
    .cmm-bar button, .cmm-bar a.cmm-step {
        flex: 0 0 auto;
        width: 44px;
        height: 44px;
        border: 0;
        border-radius: 10px;
        background: rgba(255, 255, 255, .08);
        color: #fff;
        font-size: 22px;
        line-height: 44px;
        text-align: center;
        text-decoration: none;
        cursor: pointer;
        padding: 0;
        -webkit-tap-highlight-color: transparent;
    }
    .cmm-bar a.cmm-step.cmm-off { opacity: .25; pointer-events: none; }
    .cmm-head { flex: 1 1 auto; min-width: 0; padding: 0 4px; }
    .cmm-title {
        font-weight: 700;
        font-size: 16px;
        line-height: 1.2;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .cmm-sub {
        font-size: 11.5px;
        color: #a9c1e0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin-top: 2px;
    }
    .cmm-count {
        display: inline-block;
        font-size: 10.5px;
        font-weight: 700;
        background: rgba(255, 255, 255, .14);
        border-radius: 8px;
        padding: 0 6px;
        margin-left: 6px;
        vertical-align: 1px;
    }

    /* --- Bandeau de sections du dossier, défilant au doigt --- */
    .cmm-chips {
        display: flex;
        gap: 6px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        scrollbar-width: none;
        padding: 8px 10px;
        background: #fff;
        border-bottom: 1px solid #e2e8f0;
    }
    .cmm-chips:empty { display: none; }
    .cmm-chips::-webkit-scrollbar { display: none; }
    .cmm-chips a {
        flex: 0 0 auto;
        white-space: nowrap;
        font-size: 13px;
        padding: 7px 12px;
        border-radius: 18px;
        border: 1px solid #cbd5e1;
        background: #fff;
        color: #1e293b !important;
        text-decoration: none !important;
    }
    .cmm-chips a.cmm-on {
        background: #0f2542;
        border-color: #0f2542;
        color: #fff !important;
        font-weight: 600;
    }

    /* --- Menu latéral : devient un tiroir --- */
    .cmm-root .cmm-side {
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        width: 86vw !important;
        max-width: 320px !important;
        z-index: 100001 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        transform: translateX(-105%);
        transition: transform .26s cubic-bezier(.2, .8, .2, 1);
        padding-top: calc(12px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    }
    .cmm-root.cmm-open .cmm-side {
        transform: none;
        box-shadow: 10px 0 40px rgba(0, 0, 0, .35);
    }
    .cmm-root .cmm-side a { padding-top: 12px !important; padding-bottom: 12px !important; }
    .cmm-drawer-head { display: flex; justify-content: flex-end; margin: -4px 0 4px; }
    .cmm-drawer-head button {
        width: 40px; height: 40px; border: 0; border-radius: 10px;
        background: rgba(255, 255, 255, .1); color: #fff; font-size: 20px; cursor: pointer;
    }
    .cmm-veil {
        display: block;
        position: fixed;
        top: 0; right: 0; bottom: 0; left: 0;
        background: rgba(15, 23, 42, .5);
        z-index: 100000;
        opacity: 0;
        pointer-events: none;
        transition: opacity .26s;
    }
    .cmm-root.cmm-open .cmm-veil { opacity: 1; pointer-events: auto; }
    html.cmm-lock, html.cmm-lock body { overflow: hidden !important; }

    /* --- Contenu --- */
    .cmm-root .cmm-main {
        padding: 20px !important;
        overflow-x: visible !important;
        min-width: 0;
    }
    .cmm-main img, .cmm-main video, .cmm-main iframe { max-width: 100%; height: auto; }
    .cmm-scroll {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    .cmm-scroll > table { min-width: 560px; }
    /* 16 px minimum : sinon l'iPhone zoome dès qu'on touche un champ. */
    .cmm-main input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]),
    .cmm-main select,
    .cmm-main textarea { font-size: 16px !important; max-width: 100%; }
    .cmm-main [style*="min-width"] { min-width: 0 !important; }
    .cmm-main pre { white-space: pre-wrap; }

    /* Section précédente / suivante en bas de page */
    .cmm-pager {
        display: flex;
        gap: 10px;
        margin: 28px 0 8px;
    }
    .cmm-pager a {
        flex: 1 1 0;
        min-width: 0;
        display: block;
        padding: 12px 14px;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        background: #fff;
        text-decoration: none !important;
        color: #0f2542 !important;
        box-shadow: 0 1px 2px rgba(15, 37, 66, .06);
    }
    .cmm-pager a small { display: block; font-size: 11px; color: #64748b; margin-bottom: 2px; }
    .cmm-pager a span { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .cmm-pager a.cmm-next { text-align: right; }
    .cmm-pager a.cmm-vide { visibility: hidden; }
}

@media (max-width: 782px) {
    body.admin-bar .cmm-top { top: 46px; }
}
@media (max-width: 600px) {
    /* La barre d'admin WordPress n'est plus fixe sous 600 px. */
    body.admin-bar .cmm-top { top: 0; }
}

@media (max-width: 640px) {
    /* Téléphone : le portail occupe toute la largeur, sans le cadre.
       Sélecteur renforcé : les thèmes à blocs imposent leurs marges en !important. */
    html body .cmm-root.cmm-root {
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }
    .cmm-root .cmm-main { padding: 14px 12px 20px !important; }
    .cmm-main h1 { font-size: 22px !important; line-height: 1.25 !important; }
    .cmm-main h2 { font-size: 19px !important; }
    .cmm-main [style*="grid-template-columns"] { grid-template-columns: 1fr !important; }
    .cmm-main [style*="grid-template-columns"][style*="repeat(3"],
    .cmm-main [style*="grid-template-columns"][style*="repeat(4"],
    .cmm-main [style*="grid-template-columns"][style*="repeat(5"],
    .cmm-main [style*="grid-template-columns"][style*="repeat(6"],
    .cmm-main [class*="kpi-grid"],
    .cmm-main [class*="stats-grid"] { grid-template-columns: 1fr 1fr !important; }
    .cmm-main [class*="grid-3"], .cmm-main [class*="grid-4"] { grid-template-columns: 1fr !important; }
    .cmm-main [style*="display:flex"][style*="justify-content:space-between"] { flex-wrap: wrap; gap: 8px; }
    .cmm-main [class*="card"] { padding-left: 14px !important; padding-right: 14px !important; }
    .cmm-main button, .cmm-main [class*="-btn"] { min-height: 40px; }
    /* Tableaux en cartes */
    .cmm-scroll > table.cmm-cards { min-width: 0 !important; }
    .cmm-main table.cmm-cards, .cmm-main table.cmm-cards tbody { display: block !important; width: 100% !important; border: 0 !important; background: transparent !important; }
    .cmm-main table.cmm-cards thead { display: none !important; }
    .cmm-main table.cmm-cards tr {
        display: block !important;
        background: #fff !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 12px !important;
        padding: 6px 12px !important;
        margin: 0 0 10px !important;
        box-shadow: 0 1px 2px rgba(15, 37, 66, .05);
    }
    .cmm-main table.cmm-cards td {
        display: block !important;
        position: relative;
        width: auto !important;
        text-align: left !important;
        padding: 8px 0 8px 36% !important;
        border: 0 !important;
        border-bottom: 1px solid #f1f5f9 !important;
        min-height: 20px !important;
        word-break: break-word;
    }
    .cmm-main table.cmm-cards td:last-child { border-bottom: 0 !important; }
    .cmm-main table.cmm-cards td::before {
        content: attr(data-cmm-label);
        position: absolute;
        left: 0;
        top: 9px;
        width: 33%;
        font-size: 11.5px;
        line-height: 1.3;
        font-weight: 600;
        color: #64748b;
    }
    /* Première colonne (n°, code…) : en tête de carte, en gras */
    .cmm-main table.cmm-cards td:first-child { font-weight: 700; font-size: 15px; }
    .cmm-main table.cmm-cards td.cmm-nolabel { padding-left: 0 !important; }
    .cmm-main table.cmm-cards td.cmm-nolabel::before { display: none; }
    .cmm-main table.cmm-cards td.cmm-nolabel form,
    .cmm-main table.cmm-cards td.cmm-nolabel > a,
    .cmm-main table.cmm-cards td.cmm-nolabel > button { display: inline-block; margin: 2px 4px 2px 0; }
    .cmm-main table.cmm-cards td:empty { display: none !important; }
    .cmm-main table.cmm-cards tr:hover { background: #fff !important; }

    .cmm-main [class*="modal"] [class*="content"] { max-width: calc(100vw - 20px) !important; margin: 10px auto !important; }
}

/* AFIS 7.68.1 / AER 0.31.1 — affichage téléphone et tablette :
   petits textes portés à 12 px, champs et boutons à 40 px au doigt. */
@media (max-width: 1024px) {
    .cmm-main pre { font-size: 12px; }
    .cmm-sub, .cmm-count, .cmm-pager a small,
    .cmm-main table.cmm-cards td::before { font-size: 12px; }
    .cmm-main [style*="font-size:9px"], .cmm-main [style*="font-size: 9px"],
    .cmm-main [style*="font-size:10px"], .cmm-main [style*="font-size: 10px"],
    .cmm-main [style*="font-size:10.5px"], .cmm-main [style*="font-size: 10.5px"],
    .cmm-main [style*="font-size:11px"], .cmm-main [style*="font-size: 11px"],
    .cmm-main [style*="font-size:11.5px"], .cmm-main [style*="font-size: 11.5px"],
    .cmm-main small, .cmm-root label[style*="font-size"] { font-size: 12px !important; }
}
@media (pointer: coarse), (max-width: 760px) {
    .cmm-main input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]),
    .cmm-main select,
    .cmm-main button,
    .cmm-main [class*="-btn"] { min-height: 40px; box-sizing: border-box; }
    .cmm-main input[type=checkbox], .cmm-main input[type=radio] { min-width: 20px; min-height: 20px; }
    .cmm-main input[type=file] { min-height: 40px; font-size: 14px !important; }
    .cmm-chips a { min-height: 40px; display: inline-flex; align-items: center; box-sizing: border-box; }
    .cmm-main details > summary { min-height: 40px; box-sizing: border-box; padding-top: 9px; padding-bottom: 9px; }
}

@media (prefers-reduced-motion: reduce) {
    .cmm-root .cmm-side, .cmm-veil, .cmm-chips { transition: none; scroll-behavior: auto; }
}
