/* mobile.css — Adaptations mobile JGS Avocat
   ATTENTION : toutes les règles ici sont à l'intérieur d'un @media — la version
   ordinateur n'est PAS modifiée. Au-dessus de 768px, ce fichier est ignoré. */

@media (max-width: 768px) {

  /* ═══════════════════════════════════════════════════════════
     1) RÈGLES GLOBALES (appliquées à toutes les pages)
     ═══════════════════════════════════════════════════════════ */

  body {
    margin-left: 0 !important;
    font-size: 15px;
  }
  /* Marge haute pour la barre supérieure mobile (uniquement quand injectée) */
  body.has-mobile-topbar { padding-top: 56px; }
  /* Annule l'épinglage desktop sur mobile */
  body.sidebar-pinned { margin-left: 0 !important; }

  /* ── BARRE SUPÉRIEURE MOBILE (hamburger) ─────────────────── */
  .mobile-topbar {
    display: flex;
    position: fixed; top: 0; left: 0; right: 0;
    height: 56px;
    background: var(--bordeaux);
    color: white;
    align-items: center;
    padding: 0 12px;
    z-index: 198;
    box-shadow: 0 2px 6px rgba(0,0,0,.15);
  }
  .mobile-burger {
    background: none; border: none; color: white;
    font-size: 24px; cursor: pointer; padding: 8px 12px;
    min-width: 44px; min-height: 44px;
    display: flex; align-items: center; justify-content: center;
  }
  .mobile-topbar-title {
    font-family: var(--font-display); font-size: 1.1rem;
    font-weight: 600; font-style: italic;
    letter-spacing: 0.06em; margin-left: 8px;
  }

  /* ── SIDEBAR : tiroir latéral (UNIQUEMENT header#sidebar) ──
     Les <header> "décoratifs" des pages login/portail/setup ne sont pas affectés. */
  header#sidebar {
    width: 260px !important;
    transform: translateX(-100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1) !important;
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
    z-index: 199;
  }
  header#sidebar.sidebar-open {
    transform: translateX(0);
    width: 260px !important;
  }
  header#sidebar .logo { opacity: 1 !important; }
  header#sidebar .logo-icon { display: none !important; }
  header#sidebar .sidebar-pin { display: none !important; }
  header#sidebar nav a {
    padding: 14px 18px !important;
    font-size: 14px !important;
    min-height: 44px;
  }

  /* Backdrop (assombrit le contenu quand le menu est ouvert) */
  .mobile-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 197;
    animation: jgs-fadein .2s;
  }
  .mobile-backdrop.show { display: block; }
  @keyframes jgs-fadein { from { opacity: 0; } to { opacity: 1; } }

  /* ── TOOLBAR (titre + recherche + boutons) ───────────────── */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 1rem 1rem;
  }
  .toolbar-title { font-size: 1.4rem; }
  .toolbar-right { flex-wrap: wrap; gap: 8px; }
  .search-wrap { flex: 1; min-width: 100%; }
  .search-wrap input {
    width: 100% !important;
    min-height: 40px;
  }
  .search-wrap input:focus { width: 100% !important; }
  .toolbar-right .btn-new,
  .toolbar-right button {
    flex: 1;
    min-height: 40px;
    font-size: 13px;
  }

  /* ── BARRE DE SÉLECTION ──────────────────────────────────── */
  .sel-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px 1rem;
  }
  .sel-bar > div { display: flex; gap: 8px; }
  .sel-bar > div > button { flex: 1; min-height: 40px; }

  /* ── BACK BAR (toutes pages détail) ──────────────────────── */
  .back-bar {
    padding: 0.6rem 1rem !important;
    flex-wrap: wrap;
  }
  .back-current { font-size: 13px; }

  /* ── PAGINATION ──────────────────────────────────────────── */
  .pagination { padding: 1rem; gap: 4px; }
  .page-btn { padding: 8px 12px; min-height: 40px; }

  /* ── MODALES ─────────────────────────────────────────────── */
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 90vh;
    border-radius: 12px 12px 0 0;
    padding: 1.2rem 1rem !important;
  }
  .modal-overlay { align-items: flex-end; }
  .modal-confirm {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 12px 12px 0 0;
    padding: 1.2rem 1rem !important;
  }
  .form-grid { grid-template-columns: 1fr !important; gap: .8rem; }

  /* ── INPUTS / TEXTAREA TACTILES ──────────────────────────── */
  input, textarea, select, button {
    font-size: 16px;          /* iOS : empêche le zoom auto sur focus */
  }
  .form-field input,
  .form-field select,
  .form-field textarea { min-height: 40px; }

  #logout-btn-sidebar {
    padding: 14px 18px !important;
    font-size: 12px !important;
  }

  /* ═══════════════════════════════════════════════════════════
     2) LISTES : tables → cartes empilées
     (affaires, clients, adversaires, avocats, intervenants,
      experts, consultations)
     ═══════════════════════════════════════════════════════════ */

  .table-wrap {
    padding: 1rem;
    overflow-x: visible;
  }
  .table-wrap table { min-width: 0; display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tbody { display: block; }
  .table-wrap tbody tr {
    display: block;
    background: white !important;
    border: 1px solid var(--border) !important;
    border-radius: 10px;
    margin-bottom: 12px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
  }
  .table-wrap tbody tr:hover {
    transform: none !important;
    filter: none !important;
    box-shadow: 0 2px 8px rgba(0,0,0,.08) !important;
  }
  .table-wrap tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 0 !important;
    border: none !important;
    text-align: right;
    font-size: 13px;
  }
  .table-wrap tbody td.cb-col {
    justify-content: flex-end;
    padding: 0 0 8px 0 !important;
    border-bottom: 1px solid var(--border) !important;
    margin-bottom: 8px;
  }
  /* Cellule-titre : 2ème td (1er = checkbox) ou 1er si pas de checkbox */
  .table-wrap tbody td:first-child:not(.cb-col),
  .table-wrap tbody td.cb-col + td {
    justify-content: flex-start;
    font-family: var(--font-display);
    font-size: 1.05rem !important;
    font-weight: 600;
    color: var(--bordeaux);
    border-bottom: 1px solid var(--border) !important;
    padding-bottom: 8px !important;
    margin-bottom: 4px;
    text-align: left;
  }
  .table-wrap tbody td:first-child::before,
  .table-wrap tbody td.cb-col + td::before {
    content: "" !important;     /* pas de libellé sur la cellule-titre */
  }

  /* Style commun des libellés */
  .table-wrap tbody td::before {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    flex-shrink: 0;
    text-align: left;
  }

  /* ── Libellés par page ── */
  /* Affaires : (cb=1), Dossier=2, Client=3, Adversaire=4, Créé=5, Statut=6, Juri=7, RG=8 */
  body.page-affaires .table-wrap tbody td:nth-child(3)::before { content: "Client"; }
  body.page-affaires .table-wrap tbody td:nth-child(4)::before { content: "Adversaire"; }
  body.page-affaires .table-wrap tbody td:nth-child(5)::before { content: "Créé le"; }
  body.page-affaires .table-wrap tbody td:nth-child(6)::before { content: "Statut"; }
  body.page-affaires .table-wrap tbody td:nth-child(7)::before { content: "Juridiction"; }
  body.page-affaires .table-wrap tbody td:nth-child(8)::before { content: "N° RG"; }

  /* Clients : (cb=1), Nom=2, Prenom=3, Courriel=4, Tel=5, Ville=6, Profession=7 */
  body.page-clients .table-wrap tbody td:nth-child(3)::before { content: "Prénom"; }
  body.page-clients .table-wrap tbody td:nth-child(4)::before { content: "Courriel"; }
  body.page-clients .table-wrap tbody td:nth-child(5)::before { content: "Téléphone"; }
  body.page-clients .table-wrap tbody td:nth-child(6)::before { content: "Ville"; }
  body.page-clients .table-wrap tbody td:nth-child(7)::before { content: "Profession"; }

  /* Adversaires : (cb=1), Nom=2, Prenom=3, Adresse=4, CP=5, Ville=6 */
  body.page-adversaires .table-wrap tbody td:nth-child(3)::before { content: "Prénom"; }
  body.page-adversaires .table-wrap tbody td:nth-child(4)::before { content: "Adresse"; }
  body.page-adversaires .table-wrap tbody td:nth-child(5)::before { content: "Code postal"; }
  body.page-adversaires .table-wrap tbody td:nth-child(6)::before { content: "Ville"; }

  /* Avocats : (cb=1), Nom=2, Organisation=3, Courriel=4, Tel=5, Ville=6 */
  body.page-avocats .table-wrap tbody td:nth-child(3)::before { content: "Organisation"; }
  body.page-avocats .table-wrap tbody td:nth-child(4)::before { content: "Courriel"; }
  body.page-avocats .table-wrap tbody td:nth-child(5)::before { content: "Téléphone"; }
  body.page-avocats .table-wrap tbody td:nth-child(6)::before { content: "Ville"; }

  /* Intervenants : (cb=1), Nom=2, Prenom=3, Courriel=4, Tel=5, Ville=6 */
  body.page-intervenants .table-wrap tbody td:nth-child(3)::before { content: "Prénom"; }
  body.page-intervenants .table-wrap tbody td:nth-child(4)::before { content: "Courriel"; }
  body.page-intervenants .table-wrap tbody td:nth-child(5)::before { content: "Téléphone"; }
  body.page-intervenants .table-wrap tbody td:nth-child(6)::before { content: "Ville"; }

  /* Experts : (cb=1), Nom=2, Prenom=3, Qualite=4, Courriel=5, Tel=6, Ville=7 */
  body.page-experts .table-wrap tbody td:nth-child(3)::before { content: "Prénom"; }
  body.page-experts .table-wrap tbody td:nth-child(4)::before { content: "Qualité"; }
  body.page-experts .table-wrap tbody td:nth-child(5)::before { content: "Courriel"; }
  body.page-experts .table-wrap tbody td:nth-child(6)::before { content: "Téléphone"; }
  body.page-experts .table-wrap tbody td:nth-child(7)::before { content: "Ville"; }

  /* Consultations : (cb=1), N°=2, Client=3, Dossier=4, Créé=5, Statut=6, Remise=7 */
  body.page-consultations .table-wrap tbody td:nth-child(3)::before { content: "Client"; }
  body.page-consultations .table-wrap tbody td:nth-child(4)::before { content: "Dossier"; }
  body.page-consultations .table-wrap tbody td:nth-child(5)::before { content: "Créé le"; }
  body.page-consultations .table-wrap tbody td:nth-child(6)::before { content: "Statut"; }
  body.page-consultations .table-wrap tbody td:nth-child(7)::before { content: "Remise"; }

  /* ═══════════════════════════════════════════════════════════
     3) PAGES DÉTAIL (toutes les variantes)
     ═══════════════════════════════════════════════════════════ */

  body[class*="page-detail"] .content {
    padding: 0 1rem !important;
    margin: 1rem auto !important;
  }
  body[class*="page-detail"] .hero-card {
    flex-direction: column !important;
    padding: 1.2rem 1rem !important;
    gap: 1rem;
  }
  body[class*="page-detail"] .hero-title { font-size: 1.4rem !important; }
  body[class*="page-detail"] .hero-actions {
    width: 100%;
    flex-direction: row !important;
    flex-wrap: wrap;
    align-items: stretch !important;
    justify-content: flex-start !important;
  }
  body[class*="page-detail"] .hero-actions > div {
    flex-wrap: wrap;
    width: 100%;
  }
  body[class*="page-detail"] .hero-actions button {
    flex: 1 1 auto;
    min-width: 120px;
    min-height: 40px;
    font-size: 12px !important;
  }
  body[class*="page-detail"] .sections-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
  body[class*="page-detail"] .section-card {
    padding: 1rem !important;
  }
  body[class*="page-detail"] .info-row {
    flex-direction: column;
    gap: 2px;
    margin-bottom: 0.8rem;
  }
  body[class*="page-detail"] .info-label {
    min-width: 0 !important;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
  }

  /* ═══════════════════════════════════════════════════════════
     4) PAGE ACCUEIL
     ═══════════════════════════════════════════════════════════ */

  body.page-accueil .content {
    padding: 0 1rem !important;
    margin: 1rem auto !important;
  }
  body.page-accueil .hero-title { font-size: 1.5rem !important; }

  body.page-accueil .taches-frise { padding: 1rem !important; }
  body.page-accueil .frise-row { gap: 0; }
  body.page-accueil .frise-date-pill {
    min-width: 64px !important;
    padding: 8px 4px !important;
    margin-right: 10px !important;
  }
  body.page-accueil .frise-date-num { font-size: 1.4rem !important; }
  body.page-accueil .frise-tasks { padding-left: 10px !important; }

  body.page-accueil .timeline-wrap {
    padding: 1rem !important;
    overflow-x: auto;
  }

  body.page-accueil .content > div[style*="justify-content:space-between"],
  body.page-accueil .content > div[style*="justify-content: space-between"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px;
  }

  /* Mail-split (Outlook-like) → empilement vertical */
  body.page-accueil .mail-split {
    flex-direction: column !important;
    height: auto !important;
    min-height: auto;
  }
  body.page-accueil .mail-list-pane {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    max-height: 50vh;
    border-right: none !important;
    border-bottom: 1px solid var(--border);
  }
  body.page-accueil .mail-resizer { display: none !important; }
  body.page-accueil .mail-read-pane {
    min-height: 320px;
    min-width: 0 !important;
  }
  body.page-accueil .mail-read-pane-header { padding: .8rem 1rem; }
  body.page-accueil .mail-read-pane-body { font-size: 14px; }
  body.page-accueil .reply-pane { padding: .8rem 1rem; }

  body.page-accueil .compose-modal {
    width: 100% !important;
    height: 100vh;
    max-width: 100% !important;
    max-height: 100vh;
    border-radius: 0;
  }
  body.page-accueil .compose-overlay { align-items: stretch; }
  body.page-accueil .compose-textarea { min-height: 50vh; }

  /* ═══════════════════════════════════════════════════════════
     5) PAGE AGENDA
     ═══════════════════════════════════════════════════════════ */

  body.page-agenda .content {
    padding: 0 1rem !important;
    margin: 1rem auto !important;
  }
  body.page-agenda .toolbar { padding: .8rem 1rem; }
  body.page-agenda .filters {
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }
  body.page-agenda .filters input,
  body.page-agenda .filters select {
    flex: 1 1 100%;
    min-height: 40px;
    font-size: 14px;
  }
  body.page-agenda .filters button {
    flex: 1 1 100%;
    min-height: 40px;
  }

  /* Onglets : barre scrollable horizontalement plutôt que tronquée */
  body.page-agenda .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  body.page-agenda .tab {
    flex-shrink: 0;
    padding: 10px 14px;
    font-size: 13px;
  }

  /* Cartes événements compactes */
  body.page-agenda .evt-card {
    padding: .9rem 1rem;
    gap: 12px;
    align-items: center;
  }
  body.page-agenda .evt-date-badge {
    min-width: 56px;
    padding: 5px 6px;
  }
  body.page-agenda .evt-date-day { font-size: 18px; }
  body.page-agenda .evt-card:hover { transform: none; }

  /* ═══════════════════════════════════════════════════════════
     6) PAGE FACTURATION (layout custom : .topbar + .page)
     ═══════════════════════════════════════════════════════════ */

  /* Pas de header#sidebar → on garde la topbar custom de facturation */
  body.page-facturation { padding-top: 0 !important; }
  body.page-facturation .topbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px;
    padding: .8rem 1rem !important;
    position: sticky;
    top: 0;
    z-index: 100;
  }
  body.page-facturation .topbar-left {
    justify-content: center;
  }
  body.page-facturation .btn-back {
    text-align: center;
    min-height: 40px;
  }
  body.page-facturation .page {
    padding: 1rem !important;
  }
  body.page-facturation .affaire-card {
    padding: 1rem !important;
  }
  /* KPIs : 3 cartes alignées en row → grille 1 colonne sur mobile */
  body.page-facturation .kpi-row {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }
  body.page-facturation .kpi-card { padding: .8rem 1rem !important; }
  body.page-facturation .kpi-value { font-size: 18px !important; }

  /* Section Pennylane */
  body.page-facturation .pennylane-section { padding: 1rem !important; }
  body.page-facturation .pennylane-header {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }
  body.page-facturation .token-config {
    flex-direction: column;
    align-items: stretch !important;
  }
  body.page-facturation .token-config input { min-width: 0 !important; width: 100%; }

  /* Tables facturation : éditables → on garde un scroll horizontal
     plutôt que de transformer en cartes (les inputs en cartes seraient illisibles) */
  body.page-facturation .bloc {
    padding: 1rem !important;
    overflow-x: auto;
  }
  body.page-facturation .bloc table {
    min-width: 540px;          /* force le scroll horizontal sur petit écran */
    font-size: 13px;
  }
  body.page-facturation .bloc-title {
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }
  body.page-facturation .btn-add-ligne {
    align-self: flex-end;
    min-height: 36px;
  }
  body.page-facturation .actions-row {
    flex-direction: column;
    gap: 8px;
  }
  body.page-facturation .actions-row > * {
    width: 100%;
    min-height: 42px;
  }

  /* ═══════════════════════════════════════════════════════════
     7) FORMULAIRES (formulaire.html, formulaire-client.html)
     Les form-grid sont déjà passés en 1 colonne par la règle générale.
     ═══════════════════════════════════════════════════════════ */

  body.page-formulaire .content,
  body.page-formulaire-client .content,
  body.page-formulaire-client #main-content {
    padding: 0 1rem !important;
    margin: 1rem auto !important;
  }
  body.page-formulaire .form-grid,
  body.page-formulaire-client .form-grid {
    gap: 1rem !important;
  }
  body.page-formulaire .toggle-type button,
  body.page-formulaire-client .toggle-type button {
    padding: 12px 8px;
    font-size: 11px;
  }
  /* Boutons d'action en bas du formulaire : empilés */
  body.page-formulaire .modal-actions,
  body.page-formulaire-client .modal-actions {
    flex-direction: column;
    gap: 8px;
  }
  body.page-formulaire .modal-actions > *,
  body.page-formulaire-client .modal-actions > * {
    width: 100%;
    min-height: 42px;
  }

  /* ═══════════════════════════════════════════════════════════
     8) PAGE SAUVEGARDE / ONEDRIVE / SETUP
     Pages utilitaires simples — règles légères
     ═══════════════════════════════════════════════════════════ */

  body.page-sauvegarde .content,
  body.page-onedrive .content,
  body.page-setup-account .content {
    padding: 0 1rem !important;
    margin: 1rem auto !important;
  }

  /* ═══════════════════════════════════════════════════════════
     9) PAGES LOGIN / PORTAIL / RESET
     Déjà responsives par design (carte centrée). On rajoute
     juste un peu de souplesse.
     ═══════════════════════════════════════════════════════════ */

  body.page-login .login-wrap,
  body.page-login-client .login-wrap,
  body.page-reset-password .login-wrap {
    padding: 1rem !important;
  }
  body.page-login .login-card,
  body.page-login-client .login-card,
  body.page-reset-password .login-card {
    padding: 1.5rem 1.2rem !important;
    border-radius: 12px !important;
  }
  body.page-portail-client .content {
    padding: 0 1rem !important;
    margin: 1rem auto !important;
  }

}  /* fin @media (max-width: 768px) */

/* ── DESKTOP : on neutralise les éléments mobiles s'ils étaient injectés ── */
@media (min-width: 769px) {
  .mobile-topbar,
  .mobile-backdrop { display: none !important; }
}
