/* ============================================================================
   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-refresh.spinning svg { animation: appRefreshSpin .7s linear; }
  .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; }

  /* Pastilles (onglets dossiers) : UNE seule ligne qui défile sur mobile (pas d'éparpillement) */
  #dossiers-tabs{
    flex-wrap:nowrap !important;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    padding-bottom:6px;
  }
  #dossiers-tabs > button{ flex-shrink:0; }

  /* Garde-fou : empêcher toute la page de devenir plus large que l'écran (sinon on doit
     dézoomer). Les zones qui doivent défiler ont leur propre overflow-x:auto. */
  html, body, #app, .main-content, #page-content{ max-width:100%; overflow-x:hidden; }
}

/* ============================================================= */
/* === LISTE DOSSIERS « lignes propres » → cartes nom+statut === */
/* Sur téléphone : on ne garde que le NOM + le bandeau de statut. */
/* Le reste (chez qui, action, jours, boutons, case à cocher) est */
/* masqué — un appui ouvre le dossier pour voir/agir.             */
/* ============================================================= */
@media (max-width: 900px) {
  .dos-row { padding: 14px 14px 14px 62px !important; gap: 0 !important; min-height: 52px; }
  .dos-row .dos-check,
  .dos-row .dos-chez,
  .dos-row .dos-action,
  .dos-row .dos-jours,
  .dos-row .dos-sub { display: none !important; }
  /* On garde la zone boutons, mais SEUL le bouton 📄 contrat reste visible sur mobile.
     Le reste (Rokhas, modifier, supprimer) s'obtient en ouvrant le dossier. */
  .dos-row .dos-btns { display: flex !important; flex-shrink: 0; margin-left: auto; }
  .dos-row .dos-btns > * { display: none !important; }
  .dos-row .dos-btns .dos-contrat {
    display: inline-flex !important; align-items: center; justify-content: center;
    width: 38px; height: 38px; min-height: 38px; padding: 0;
    border: 0.5px solid #ddc78f; border-radius: 10px;
    background: #faf6ea; color: #7c6224; font-size: 17px;
  }
  .dos-main { flex: 1; }
  .dos-nom { font-size: 15px; white-space: normal; }
  .dos-toolbar { display: none; }
  /* Chips de filtre : bien tactiles, défilent horizontalement */
  .dos-chips { gap: 7px; padding-bottom: 12px; }
  .dos-chip { padding: 8px 14px; }
}

/* ============================================================= */
/* === SKIN « MODÈLE DOSSIERS » — rehaussement global rubriques  */
/* === (dernier bloc : prioritaire en cascade). Pour annuler :   */
/* === supprimer de ce commentaire jusqu'à la fin du fichier.    */
/* ============================================================= */
:root{ --display:"Cormorant Garamond",Georgia,serif; }

/* En-têtes de page : titres serif éditoriaux, comme la liste Dossiers */
.page-header{ align-items:flex-start; margin-bottom:22px; }
.page-title, .dossier-title{
  font-family:var(--display) !important;
  font-size:28px; font-weight:600; line-height:1.05; letter-spacing:0; color:#1f1a10;
}
.page-subtitle{ font-size:12.5px; color:var(--muted,#938A78); margin-top:5px; }
.page-kicker{ color:var(--bronze-dark,#7C6224); }

/* Tableaux : en-tête doux, lignes aérées, survol bronze clair */
table thead th{
  background:#FBF9F4 !important; color:var(--muted,#938A78) !important;
  font-size:10.5px; font-weight:700; letter-spacing:1px; text-transform:uppercase;
  padding:13px 16px !important; border-bottom:1px solid var(--border,#E7E1D4) !important;
}
table tbody td{ padding:14px 16px; border-bottom:1px solid var(--border-soft,#EFEAE0); }
table tbody tr:hover td{ background:#FBF9F4 !important; }

/* La carte qui enveloppe un tableau prend des angles nets */
.card.table-card, .table-wrap.card{ padding:0; overflow:hidden; }
.card > .table-wrap{ margin:0; }

/* Badges : pastilles plus fermes et cohérentes */
.badge{ padding:4px 11px; border-radius:20px; font-weight:700; font-size:11px; }

/* Boutons : douceur cohérente */
.btn{ border-radius:9px; }
.btn-primary{ box-shadow:0 2px 8px rgba(124,98,36,.26); }
.btn-primary:hover{ background:var(--bronze-dark,#7C6224); }

/* Petits boutons d'action carrés dans les tableaux (icônes) */
.btn-icon{ width:32px; height:32px; border-radius:8px; border:1px solid var(--border,#E7E1D4); background:#fff; color:var(--neutral,#938A78); }
.btn-icon:hover{ border-color:var(--bronze-light,#C2A35A); color:var(--bronze-dark,#7C6224); background:#FBF9F4; }

/* Avatars / pastilles « actuellement chez » : net */
.chez-avatar .av{ box-shadow:0 1px 2px rgba(40,33,18,.12); }

/* Badges colorés (statut / rôle) */
.badge.b-amber{ background:#F3ECD9; color:#7C6224; }
.badge.b-green{ background:#E9F0E0; color:#3C6029; }
.badge.b-blue{ background:#E3EDF7; color:#2E5E96; }
.badge.b-gray{ background:#EFEAE0; color:#5A5346; }
.badge.b-red{ background:#F6E2DD; color:#8E2C20; }

/* --- Composants réutilisables « modèle Dossiers » --- */
/* Jauge de pièces */
.pc{ display:flex; align-items:center; gap:9px; }
.pc-bar{ width:54px; height:5px; border-radius:99px; background:#EADFC6; overflow:hidden; }
.pc-bar > span{ display:block; height:100%; background:var(--bronze,#9A7B33); border-radius:99px; }
.pc-n{ font-size:12px; font-weight:700; color:var(--ink-soft,#5A5346); font-variant-numeric:tabular-nums; }
/* Avatar initiales */
.av-mini{ width:28px; height:28px; border-radius:50%; display:inline-flex; align-items:center; justify-content:center; font-size:10px; font-weight:700; color:#fff; flex:none; box-shadow:0 1px 2px rgba(40,33,18,.12); }
.chez-line{ display:inline-flex; align-items:center; gap:8px; }
/* Boutons d'action ronds dans les lignes */
.row-acts{ display:flex; gap:7px; justify-content:flex-end; }
.row-act{ width:32px; height:32px; border-radius:8px; border:1px solid var(--border,#E7E1D4); background:#fff; display:inline-flex; align-items:center; justify-content:center; cursor:pointer; color:var(--neutral,#938A78); transition:.13s; padding:0; line-height:1; }
.row-act:hover{ border-color:var(--bronze-light,#C2A35A); color:var(--bronze-dark,#7C6224); background:#FBF9F4; }
.row-act svg{ width:15px; height:15px; }
.row-act.open{ background:var(--bronze,#9A7B33); border-color:var(--bronze,#9A7B33); color:#fff; font-size:15px; font-weight:700; }
.row-act.open:hover{ background:var(--bronze-dark,#7C6224); color:#fff; }
.row-act.del{ border-color:#E3B7AE; color:var(--danger,#B23A2C); background:var(--danger-bg,#F6E2DD); }
.row-act.del:hover{ background:var(--danger,#B23A2C); border-color:var(--danger,#B23A2C); color:#fff; }

/* ===== Cloche notifications VISIBLE en HAUT sur mobile ===== */
/* La barre du haut (cloche + compte) passait SOUS la barre d'état de l'iPhone (top:10px sous
   l'encoche) → invisible. On la descend sous la zone sûre (safe-area) → cloche visible en
   haut à droite, panneau des notifications qui s'ouvre vers le bas. */
@media (max-width: 760px) {
  #app-topbar.app-topbar {
    top: calc(env(safe-area-inset-top) + 8px) !important;
    right: 12px !important;
    bottom: auto !important;
    left: auto !important;
    z-index: 260 !important;
  }
  #app-topbar .notif-bell button {
    width: 44px !important; height: 44px !important; border-radius: 50% !important;
    background: var(--bronze, #9A7B33) !important; color: #fff !important; border: none !important;
    box-shadow: 0 3px 12px rgba(0,0,0,.22) !important;
  }
  #app-topbar .notif-badge { top: -4px !important; right: -4px !important; }
  #app-topbar .notif-panel {
    top: 54px !important; bottom: auto !important; right: 0 !important;
    width: calc(100vw - 28px) !important; max-height: 66vh !important; overflow-y: auto !important;
  }
}
