/* ==========================================================================
   Diaspora Impact Africa - PWA & ergonomie mobile
   Chargé sur toutes les pages via includes/pwa_head.php
   ========================================================================== */

/* --- Bandeaux PWA (installation, mise à jour, aide iOS) --- */
.pwa-banner {
    position: fixed;
    left: 50%;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 9000;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    width: max-content;
    max-width: calc(100% - 24px);
    background: rgba(9, 14, 63, 0.97);
    color: #ffffff;
    border: 1px solid rgba(239, 176, 54, 0.5);
    border-radius: 18px;
    padding: 0.7rem 0.8rem 0.7rem 1rem;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    font: 600 14px/1.4 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    animation: pwa-in 0.25s ease-out;
}
.pwa-banner[hidden],
[data-pwa-install][hidden],
[data-notif-badge][hidden] { display: none !important; }

/* --- Notifications : bandeaux dans la page (application ouverte) --- */
.pwa-toasts {
    position: fixed;
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: 12px;
    left: 12px;
    z-index: 9150;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
}
.pwa-toast {
    pointer-events: auto;
    width: 100%;
    max-width: 380px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: #ffffff;
    color: #090E3F;
    border-left: 4px solid #EFB036;
    border-radius: 14px;
    padding: 12px 12px 12px 14px;
    box-shadow: 0 12px 30px rgba(9, 14, 63, 0.18);
    font: 500 13px/1.4 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    cursor: pointer;
    animation: pwa-toast-in 0.25s ease-out;
}
.pwa-toast .pwa-toast-ico { font-size: 18px; line-height: 1; }
.pwa-toast .pwa-toast-txt { flex: 1; min-width: 0; }
.pwa-toast strong { display: block; font-weight: 800; margin-bottom: 2px; }
.pwa-toast .pwa-toast-body { color: #475569; overflow-wrap: anywhere; }
.pwa-toast button { background: none; border: 0; color: #94a3b8; font-size: 18px; line-height: 1; cursor: pointer; padding: 0 2px; min-width: 32px; min-height: 32px; }
@keyframes pwa-toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@media print { .pwa-toasts { display: none !important; } }
.pwa-banner .pwa-txt { flex: 1 1 200px; }
@media (max-width: 480px) {
    .pwa-banner { width: calc(100% - 24px); }
    .pwa-banner .pwa-txt { flex-basis: 100%; text-align: center; }
}
.pwa-banner strong { color: #EFB036; }
.pwa-banner button {
    font: inherit;
    font-weight: 800;
    border: 0;
    border-radius: 12px;
    padding: 0.5rem 0.95rem;
    min-height: 40px;
    cursor: pointer;
    white-space: nowrap;
}
.pwa-banner .pwa-yes { background: #EFB036; color: #090E3F; }
.pwa-banner .pwa-no { background: transparent; color: rgba(255, 255, 255, 0.7); }
.pwa-banner button:focus-visible { outline: 2px solid #EFB036; outline-offset: 2px; }

/* --- Indicateur hors connexion --- */
.pwa-offline {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9100;
    background: #b91c1c;
    color: #ffffff;
    text-align: center;
    font: 700 13px/1.3 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    padding: calc(6px + env(safe-area-inset-top, 0px)) 12px 6px;
}

/* --- Glisser vers le bas pour actualiser (application installée) --- */
.pwa-ptr {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 50%;
    z-index: 9200;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #090E3F;
    color: #EFB036;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
    transform: translate(-50%, -60px);
    opacity: 0;
    pointer-events: none;
    will-change: transform, opacity;
}
.pwa-ptr.pret { background: #EFB036; color: #090E3F; }
.pwa-ptr.retour { transition: transform 0.25s ease, opacity 0.25s ease; }
.pwa-ptr.chargement { transition: transform 0.2s ease; }
.pwa-ptr.chargement svg { animation: pwa-spin 0.8s linear infinite; }
.pwa-ptr-label {
    position: fixed;
    top: calc(env(safe-area-inset-top, 0px) + 44px);
    left: 50%;
    z-index: 9200;
    transform: translate(-50%, -60px);
    opacity: 0;
    pointer-events: none;
    background: rgba(9, 14, 63, 0.92);
    color: #ffffff;
    font: 700 12px/1 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    padding: 7px 12px;
    border-radius: 999px;
    white-space: nowrap;
}
.pwa-ptr-label.retour { transition: transform 0.25s ease, opacity 0.25s ease; }
@keyframes pwa-spin { to { transform: rotate(360deg); } }
@media print { .pwa-ptr, .pwa-ptr-label { display: none !important; } }

@keyframes pwa-in {
    from { opacity: 0; transform: translate(-50%, 10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}
@media (prefers-reduced-motion: reduce) {
    .pwa-banner { animation: none; }
}
@media print {
    .pwa-banner, .pwa-offline { display: none !important; }
}

/* --- Indicateurs des tableaux de bord : groupe repliable sur mobile --- */
.dia-kpi-toggle { display: none; }
@media (max-width: 767px) {
    .dia-kpi-toggle {
        display: flex;
        width: 100%;
        align-items: center;
        gap: 0.7rem;
        min-height: 52px;
        margin: 0 0 0.75rem;
        padding: 0.6rem 0.9rem;
        border-radius: 16px;
        border: 1px solid rgba(239, 176, 54, 0.5);
        background: #ffffff;
        color: #090E3F;
        text-align: left;
        cursor: pointer;
        box-shadow: 0 4px 14px rgba(9, 14, 63, 0.06);
        font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    }
    .dia-kpi-toggle.dark { background: rgba(255, 255, 255, 0.06); color: #ffffff; border-color: rgba(255, 255, 255, 0.15); box-shadow: none; }
    .dia-kpi-toggle .dia-kpi-ico { font-size: 18px; line-height: 1; }
    .dia-kpi-toggle .dia-kpi-textes { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
    .dia-kpi-toggle .dia-kpi-titre { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
    .dia-kpi-toggle .dia-kpi-resume { font-size: 12px; font-weight: 600; opacity: 0.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .dia-kpi-toggle .dia-kpi-chev::before { content: '▾'; display: inline-block; font-size: 16px; transition: transform 0.2s ease; }
    .dia-kpi-toggle.ouvert .dia-kpi-chev::before { transform: rotate(180deg); }
    .dia-kpi-toggle.ouvert .dia-kpi-resume { display: none; }
    .dia-kpi-toggle:focus-visible { outline: 2px solid #EFB036; outline-offset: 2px; }
    [data-kpi-group].dia-kpi-ferme { display: none !important; }
    /* Avant traitement par le script : masqué (évite l'apparition puis disparition) ;
       filet de sécurité : réaffiché si le script ne s'est pas exécuté (classe posée en <head>). */
    .dia-js:not(.dia-kpi-secours) [data-kpi-group]:not([data-kpi-ready]) { display: none !important; }
}

/* --- Ergonomie mobile (règles globales volontairement prudentes) --- */

/* Pas d'agrandissement automatique du texte en mode paysage */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* Supprime le délai du double-tap sur les éléments interactifs */
a, button, input, select, textarea, label, summary, [role="button"] {
    touch-action: manipulation;
}

/* Retour visuel discret au toucher, aux couleurs du site */
a, button, [role="button"] { -webkit-tap-highlight-color: rgba(239, 176, 54, 0.18); }

/* iPhone/iPad : un champ en dessous de 16px déclenche un zoom à la saisie */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 1024px) {
        input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not([type="color"]),
        select,
        textarea {
            font-size: max(16px, 1em) !important;
        }
    }
}

/* Application installée : pas de rebond de défilement horizontal */
.pwa-standalone body { overscroll-behavior-x: none; }
