/* ============================================================
   PORTAIL CITOYEN ANIDA - portail-mobile.css
   Experience telephone / tablette, chargee APRES portail.css.
   Rien ne change sur ordinateur (> 900 px).
   ============================================================ */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, video, iframe { max-width: 100%; }
.pm-tabbar { display: none; }
.rsp-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Tablette (<= 900 px) ---------- */
@media (max-width: 900px) {
  .navbar__inner { padding: 0 14px; gap: 10px; height: 60px; }
  .navbar__links { display: none !important; }
  .navbar__logo img { height: 36px !important; max-width: 46vw; }
  .navbar__sep { flex: 1; }
  .main-wrap { padding: 20px 16px; }
  .section { padding: 34px 16px; }
  .dash-grid { grid-template-columns: 1fr !important; }
  .dash-sidebar { display: none; }
  .footer__inner { grid-template-columns: 1fr 1fr; gap: 22px; }
  /* Grilles ecrites dans les pages */
  [style*="grid-template-columns:300px 1fr"], [style*="grid-template-columns: 300px 1fr"],
  [style*="grid-template-columns:280px 1fr"], [style*="grid-template-columns: 280px 1fr"],
  [style*="grid-template-columns:1fr 320px"], [style*="grid-template-columns: 1fr 320px"],
  [style*="grid-template-columns:1fr 200px"], [style*="grid-template-columns: 1fr 200px"] { grid-template-columns: 1fr !important; }
}

/* ---------- Telephone (<= 640 px) ---------- */
@media (max-width: 640px) {
  body { font-size: 15px; padding-bottom: calc(70px + env(safe-area-inset-bottom)); }
  /* Barre du haut compacte */
  .navbar { padding-top: env(safe-area-inset-top); }
  .navbar__inner { height: 56px; padding: 0 12px; gap: 8px; }
  .navbar__logo img { height: 32px !important; max-width: 52vw; }
  #pwaInstallBtn { padding: 7px !important; font-size: 0 !important; gap: 0 !important; border-radius: 10px !important; }
  #pwaInstallBtn svg { width: 18px !important; height: 18px !important; }
  .navbar > .navbar__inner > a.navbar__link { display: none; }
  .navbar__btn { padding: 8px 12px; font-size: .8rem; border-radius: 10px; }
  .navbar__notif { font-size: 1.2rem; padding: 8px; }
  .navbar__avatar { width: 38px; height: 38px; }
  .navbar__usermenu { position: fixed !important; top: calc(60px + env(safe-area-inset-top)) !important; right: 10px !important; left: 10px !important; min-width: 0 !important; border-radius: 16px !important; }
  .navbar__usermenu a { padding: 13px 16px !important; font-size: .92rem !important; }

  /* Contenu */
  .main-wrap { padding: 16px 14px; }
  .container { padding: 0 14px; }
  .section { padding: 28px 14px; }
  .section-title { font-size: 1.25rem; }
  .page-header { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 16px; }
  .page-header__title { font-size: 1.2rem; line-height: 1.3; }
  .page-header .btn { width: 100%; justify-content: center; }
  .card__body { padding: 16px; }
  .card__header { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
  .hero { padding: 36px 16px; }
  .hero__title { font-size: 1.55rem !important; }
  .hero__sub { font-size: .95rem; }
  .hero__btns a { flex: 1 1 100%; text-align: center; }
  .stat-item { padding: 6px 10px; }
  .stat-item__val { font-size: 1.45rem; }
  .steps { flex-direction: column; }
  .step::after { content: "\2193"; right: auto; left: 50%; top: auto; bottom: -12px; transform: translateX(-50%); }
  .demandes-grid { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  .demande-card { padding: 14px; }
  .demande-card__icon { font-size: 1.6rem; margin-bottom: 6px; }
  .demande-card__title { font-size: .86rem; }
  .demande-card__desc { font-size: .74rem; }

  /* Formulaires : gros champs, pas de zoom iPhone */
  .form-control, input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea { font-size: 16px !important; }
  .form-control { padding: 12px 14px; border-radius: 10px; }
  .form-row { grid-template-columns: 1fr !important; }
  .btn { padding: 12px 18px; min-height: 44px; justify-content: center; }
  .btn--sm { min-height: 36px; padding: 8px 12px; }
  .upload-zone { padding: 18px 12px; }
  .alert { font-size: .85rem; }

  /* Pages de connexion / inscription */
  .auth-wrap { padding: 16px 12px calc(84px + env(safe-area-inset-bottom)); align-items: flex-start; min-height: auto; }
  .auth-card { padding: 24px 18px !important; border-radius: 18px; max-width: 100% !important; }
  .auth-title { font-size: 1.2rem; }
  [style*="grid-template-columns:100px 1fr 1fr"], [style*="grid-template-columns: 100px 1fr 1fr"] { grid-template-columns: 1fr 1fr !important; }
  [style*="grid-template-columns:100px 1fr 1fr"] > :first-child, [style*="grid-template-columns: 100px 1fr 1fr"] > :first-child { grid-column: 1 / -1; }

  /* Grilles des pages */
  [style*="grid-template-columns"]:not([style*="auto-fill"]):not([style*="auto-fit"]):not([style*="repeat(3"]):not([style*="repeat(2"]):not([style*="100px 1fr 1fr"]) { grid-template-columns: 1fr !important; }
  [style*="repeat(4"], [style*="repeat(5"], [style*="repeat(6"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }

  /* Tableaux -> cartes (cellules etiquetees par portail-mobile.js) */
  table.pm-stack, table.pm-stack tbody, table.pm-stack tr, table.pm-stack td { display: block; width: 100%; }
  table.pm-stack thead { display: none; }
  table.pm-stack tr { background: #fff; border: 1px solid var(--gray-200); border-radius: 14px; margin: 0 0 12px; padding: 6px 4px; box-shadow: 0 1px 3px rgba(0,0,0,.05); }
  table.pm-stack tr:hover td { background: transparent; }
  table.pm-stack td { border: none !important; padding: 7px 12px !important; display: flex; gap: 12px; justify-content: space-between; align-items: center; text-align: right; font-size: .88rem; }
  table.pm-stack td::before { content: attr(data-label); font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--gray-400); text-align: left; flex-shrink: 0; max-width: 45%; }
  table.pm-stack td[data-label=""]::before { display: none; }
  table.pm-stack td:first-child { font-weight: 800; color: var(--green); }
  .card:has(> table.pm-stack), .card:has(> .table-wrap > table.pm-stack) { background: transparent; border: none; box-shadow: none; overflow: visible; }

  /* Pied de page compact */
  .footer { margin-top: 30px; padding: 26px 16px 18px; }
  .footer__inner { grid-template-columns: 1fr 1fr !important; gap: 18px; }
  .footer__inner > div:first-child { grid-column: 1 / -1; }
  .footer__bottom { flex-direction: column; text-align: center; }

  /* Barre d'onglets du bas, comme une application */
  .pm-tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 300; background: rgba(255,255,255,.97);
    backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-top: 1px solid var(--gray-200); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -8px 24px -14px rgba(0,0,0,.3); }
  .pm-tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; color: #64748b; text-decoration: none;
    font-size: .64rem; font-weight: 700; padding: 5px 0 3px; border-radius: 12px; position: relative; -webkit-tap-highlight-color: transparent; }
  .pm-tabbar a svg { width: 24px; height: 24px; }
  .pm-tabbar a.on { color: var(--green); }
  .pm-tabbar a.on::before { content: ""; position: absolute; top: -6px; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--green); }
  .pm-tabbar a.pm-main { color: #fff; }
  .pm-tabbar a.pm-main span.pm-plus { width: 50px; height: 50px; margin-top: -24px; border-radius: 50%; background: linear-gradient(135deg, var(--green-m), var(--green)); display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 18px -6px rgba(26,92,46,.7); border: 4px solid #fff; }
  .pm-tabbar a.pm-main span.pm-plus svg { width: 24px; height: 24px; }
  .pm-tabbar a.pm-main em { color: var(--green); font-style: normal; }
  .pm-tabbar a:active { background: var(--gray-100); }
  .pm-tabbar i { position: absolute; top: 0; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: #dc2626; color: #fff;
    font-size: .6rem; font-weight: 800; line-height: 14px; font-style: normal; border: 2px solid #fff; text-align: center; }
  /* Bandeaux fixes du bas au-dessus de la barre */
  .al-ban, #pwaIosModal > div { margin-bottom: calc(70px + env(safe-area-inset-bottom)); }
}

/* ---------- Petits telephones (<= 360 px) ---------- */
@media (max-width: 360px) {
  .demandes-grid { grid-template-columns: 1fr !important; }
  .footer__inner { grid-template-columns: 1fr !important; }
  .navbar__logo img { max-width: 44vw; }
}
@media print { .pm-tabbar { display: none !important; } body { padding-bottom: 0; } }

/* ---------- Accueil : diaporama ---------- */
@media (max-width: 640px) {
  .slider-wrap { min-height: 0 !important; }
  .slide { flex-direction: column; align-items: flex-start; padding: 26px 22px 58px !important; gap: 10px !important; }
  .slide__icon { font-size: 2.6rem !important; }
  .slide__title { font-size: 1.4rem !important; }
  .slide__title br { display: none; }
  .slide__desc { font-size: .9rem !important; line-height: 1.55 !important; margin-bottom: 14px !important; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; }
  .slide__btn { padding: 11px 20px !important; }
  .slider-arrow { top: auto !important; bottom: 12px !important; transform: none !important; width: 36px !important; height: 36px !important; }
  .slider-arrow.prev { left: 14px !important; } .slider-arrow.next { right: 14px !important; }
  .slider-controls { bottom: 24px !important; }
  /* Messagerie : liste OU conversation, comme une application de messages */
  .pm-msg-list-only > :nth-child(2) { display: none !important; }
  .pm-msg-conv-only > :nth-child(1) { display: none !important; }
  .pm-back { display: inline-flex; align-items: center; gap: 6px; margin: 0 0 10px; font-weight: 700; color: var(--green); text-decoration: none; font-size: .9rem; }
}

/* Les colonnes de grille ne debordent jamais (contenu long, champs, boutons) */
@media (max-width: 900px) {
  [style*="display:grid"] > *, [style*="display: grid"] > * { min-width: 0; }
  .pm-msg-conv-only textarea, .pm-msg-conv-only input, .pm-msg-conv-only select { max-width: 100%; }
}

/* Barre du haut : liens sur une ligne (ajout du lien Annonces) */
@media (min-width: 901px) { .navbar__link { white-space: nowrap; } }
@media (min-width: 901px) and (max-width: 1240px) { .navbar__links { gap: 2px; } .navbar__link { padding: 6px 8px; font-size: .84rem; } }
@media (min-width: 901px) and (max-width: 1240px) { .navbar__logo { flex-shrink: 0; } }
@media (min-width: 901px) and (max-width: 1060px) { .navbar__link { padding: 6px 5px; font-size: .76rem; } .navbar__logo img { height: 36px !important; } }
@media (min-width: 901px) and (max-width: 990px) { .navbar__links { gap: 0; } .navbar__link { padding: 6px 4px; font-size: .72rem; } .navbar__logo img { height: 30px !important; } .navbar__sep { display: none; } }
