/* ============================================================================
   MOBILE.CSS — Expérience téléphone repensée (iOS / Android)
   Chargé APRÈS style.css et les styles intégrés d'index.html → priorité garantie.
   Travaille avec js/mobile.js qui :
     - étiquette les cellules des tableaux (data-label) → affichage en cartes
     - construit la barre d'onglets en bas (body reçoit la classe .has-bottomnav)
   Sur ordinateur (>900px) : AUCUN changement.
   ========================================================================== */

/* ---------- Barre d'onglets en bas (cachée sur ordinateur) ---------- */
.bottom-nav { display: none; }

@media (max-width: 900px) {

  /* ===== 1. CONFORT TACTILE GÉNÉRAL ===== */
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; }

  /* Champs à 16px : empêche le zoom automatique d'iOS à la saisie */
  .form-group input, .form-group select, .form-group textarea,
  .filters input, .filters select,
  .msg-input-area input {
    font-size: 16px !important;
    min-height: 46px;
  }
  .form-group textarea { min-height: 90px; }

  /* Boutons faciles à toucher (44px = norme Apple/Google) */
  .btn { min-height: 44px; padding: 10px 16px; font-size: 14px; }
  .btn-sm { min-height: 38px; padding: 7px 12px; font-size: 13px; }
  .btn-icon { min-width: 40px; min-height: 40px; font-size: 18px; }
  .modal-close { min-width: 44px; min-height: 44px; font-size: 26px; }

  /* Éléments du menu latéral plus espacés */
  .nav-item { padding: 14px 16px; font-size: 14px; }

  /* Connexion : carte adaptée au téléphone */
  .login-page { padding: 16px; }
  .login-box { padding: 32px 22px; }

  /* Bulles de discussion plus larges */
  .msg-bubble { max-width: 85%; }

  /* ===== 2. BARRE D'ONGLETS EN BAS ===== */
  .bottom-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 250;
    background: #1a1a1a;
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.25);
  }
  .bn-item {
    flex: 1; min-width: 0;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: none; border: none; cursor: pointer;
    color: rgba(255,255,255,0.6);
    font-family: inherit; font-size: 10px; font-weight: 500;
    padding: 5px 2px; border-radius: 8px; position: relative;
  }
  .bn-item .bn-icon { font-size: 21px; line-height: 1; }
  .bn-item .bn-label {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .bn-item.active { color: var(--bronze-light, #c4a84f); }
  .bn-item:active { background: rgba(255,255,255,0.08); }
  .bn-badge {
    position: absolute; top: 0; left: calc(50% + 6px);
    background: var(--danger, #c0392b); color: #fff;
    border-radius: 10px; min-width: 16px; height: 16px; padding: 0 4px;
    font-size: 9px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
  }

  /* Quand la barre existe : plus besoin du bouton hamburger (l'onglet ⋯ ouvre le menu) */
  body.has-bottomnav .menu-toggle { display: none !important; }
  body.has-bottomnav .main-content {
    padding: calc(14px + env(safe-area-inset-top)) 14px calc(86px + env(safe-area-inset-bottom)) !important;
  }
  /* La cloche de notifications remonte au-dessus de la barre */
  body.has-bottomnav .notif-bell { bottom: calc(74px + env(safe-area-inset-bottom)) !important; }
  /* Le bas du menu latéral (Déconnexion) reste visible AU-DESSUS de la barre */
  body.has-bottomnav .sidebar-footer { padding-bottom: calc(86px + env(safe-area-inset-bottom)) !important; }

  /* ===== 3. TABLEAUX → CARTES (plus aucun scroll horizontal) =====
     mobile.js ajoute la classe .m-table et data-label sur chaque cellule. */
  .m-table { min-width: 0 !important; }
  .m-table thead { display: none; }
  .m-table, .m-table tbody, .m-table tr { display: block; width: 100%; }
  .m-table tbody tr {
    background: #fff;
    border: 1px solid var(--border-soft, #f0ebdd);
    border-left: 3px solid var(--bronze, #9a7b2f);
    border-radius: 12px;
    margin-bottom: 10px;
    padding: 6px 14px;
    box-shadow: 0 1px 2px rgba(60,45,15,.05), 0 4px 14px rgba(60,45,15,.05);
  }
  .m-table tbody tr:hover td { background: transparent; }
  .m-table td {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    border: none !important;
    padding: 7px 0 !important;
    font-size: 13.5px;
    text-align: right;
    min-height: 30px;
  }
  .m-table td + td { border-top: 1px dashed var(--border-soft, #f0ebdd) !important; }
  .m-table td::before {
    content: attr(data-label);
    flex-shrink: 0;
    font-size: 10.5px; font-weight: 600;
    color: #9a8559; text-transform: uppercase; letter-spacing: 0.4px;
    text-align: left;
  }
  /* Cellule sans en-tête (ex. colonne Actions) : contenu seul, aligné à droite */
  .m-table td[data-label=""]::before, .m-table td:not([data-label])::before { content: none; }
  .m-table td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; }
  /* Cellules vides : on ne montre pas de ligne inutile */
  .m-table td:empty { display: none; }
  /* Boutons d'action dans les cartes : bien espacés */
  .m-table td .btn, .m-table td .btn-sm { flex-shrink: 0; }
  .m-table td > div { text-align: right; }

  /* Les cartes contenant ces tableaux n'ont plus besoin de défiler */
  .card:has(.m-table) { overflow-x: visible; }
  .table-wrap:has(.m-table) { overflow-x: visible; }

  /* ===== 4. MODALES → FEUILLES QUI MONTENT DU BAS ===== */
  .modal-overlay {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  .modal-box, .modal-box.modal-lg {
    width: 100% !important; max-width: 100% !important;
    max-height: 92dvh !important;
    border-radius: 18px 18px 0 0 !important;
    animation: sheetUp 0.22s ease;
    display: flex; flex-direction: column;
    overflow-y: hidden !important;   /* le corps défile, pas la boîte entière */
  }
  /* Poignée visuelle en haut de la feuille */
  .modal-header { position: relative; padding: 20px 16px 12px !important; }
  .modal-header::before {
    content: '';
    position: absolute; top: 7px; left: 50%; transform: translateX(-50%);
    width: 40px; height: 4px; border-radius: 2px; background: #d8d2c2;
  }
  .modal-body { padding: 16px !important; overflow-y: auto !important; flex: 1; -webkit-overflow-scrolling: touch; }
  /* Pied de modale collé en bas, boutons pleine largeur, hors de la zone gestes iPhone */
  .modal-footer {
    position: sticky; bottom: 0; background: #fff;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)) !important;
    flex-wrap: wrap;
  }
  .modal-footer .btn { flex: 1 1 auto; justify-content: center; }

  @keyframes sheetUp {
    from { transform: translateY(40%); opacity: 0.6; }
    to   { transform: translateY(0);   opacity: 1; }
  }

  /* ===== 5. DIVERS ===== */
  /* Onglets du dossier : défilement fluide, pastilles tactiles */
  .dossier-tabs, .tabs { gap: 6px; padding-bottom: 10px; }
  .dtab, .tab-btn { min-height: 38px; padding: 8px 14px; }

  /* Liste de documents : nom + actions sur 2 lignes si besoin */
  .doc-item { flex-wrap: wrap; padding: 12px; }
  .doc-actions { width: 100%; justify-content: flex-end; }

  /* Cartes statistiques plus compactes */
  .stat-card { padding: 14px; }

  /* En-tête de page : boutons d'action pleine largeur sous le titre */
  .page-header > div:last-child:not(:first-child) { width: 100%; }
  .page-header .btn { width: 100%; justify-content: center; }
  .page-header .btn + .btn { margin-top: 8px; }
}

/* ===== 6. CARTES DOSSIERS COMPACTES (retour Zakaria : trop hautes) ===== */
@media (max-width: 900px) {
  /* Infos secondaires masquées sur téléphone — visibles en ouvrant le dossier */
  .m-table td[data-label="Projet"],
  .m-table td[data-label="Niveaux"],
  .m-table td[data-label="Dessin"] { display: none; }

  /* Tout est plus serré : une carte = l'essentiel d'un coup d'œil */
  .m-table tbody tr { padding: 4px 12px; margin-bottom: 8px; }
  .m-table td { padding: 5px 0 !important; min-height: 26px; font-size: 13px; }
  .m-table td::before { font-size: 10px; }

  /* Lecture claire (demande Zakaria) : nom+statut → TÂCHE À FAIRE (mise en
     valeur) → chez qui → séjour → le reste. */
  .m-table tbody tr { display: flex; flex-direction: column; }
  .m-table td { order: 6; }
  .m-table td[data-label="Client"] { order: 0; }
  .m-table td[data-label="Action à effectuer"] {
    order: 1;
    background: #fff8e8; border: 1px solid #eedfb5 !important; border-radius: 8px;
    padding: 7px 10px !important; margin: 4px 0;
    font-weight: 600; color: #7a5a10;
  }
  .m-table td[data-label="Actuellement chez"] { order: 2; font-weight: 500; }
  .m-table td[data-label="Séjour"] { order: 3; }
  .m-table td[data-label="Commune"] { order: 4; }
  .m-table td[data-label="Documents"] { order: 5; }
  .m-table td[data-label=""] { order: 9; }

  /* Tableau de bord : les grilles en colonnes s'adaptent au téléphone */
  .dash-2col { grid-template-columns: 1fr !important; }
  .dash-4col, .dash-5col { grid-template-columns: 1fr 1fr !important; }
}

/* Très petits écrans */
@media (max-width: 380px) {
  .bn-item .bn-label { font-size: 9px; }
  .m-table td { font-size: 13px; }
}


/* ============================================================= */
/* === REFONTE BRONZE — accord mobile (barre du bas espresso) === */
/* === Ajout d'apparence uniquement. ========================== */
/* ============================================================= */
@media (max-width: 900px){
  .bottom-nav{
    background:linear-gradient(180deg,#2B251A 0%,#211C13 100%);
    border-top:1px solid rgba(255,255,255,.08);
  }
  .bn-item.active{ color:var(--bronze-light,#C2A35A); }
  .bn-item.active .bn-icon{ filter:drop-shadow(0 0 6px rgba(194,163,90,.5)); }

  /* Carte dossier mobile : liseré bronze + ombre douce cohérents */
  .m-table tbody tr{ border-left:3px solid var(--bronze,#9A7B33); }
  /* Tâche à faire mise en valeur : accordée au lavis bronze */
  .m-table td[data-label="Action à effectuer"]{
    background:var(--action-bg,#F3ECD9);
    border:1px solid #E6D7AE !important;
    color:var(--bronze-dark,#7C6224);
  }
  /* Feuilles modales : poignée plus discrète */
  .modal-header::before{ background:#E0D8C6; }
}
