/* =====================================================================
   VERSION MOBILE — pages historiques (tableau de bord, commandes, versions…)
   Chargé partout par theme_head.php. Les modules récents (Contenus, Broderie,
   Chorus) ont leurs propres règles mobiles dans leur feuille de style.
   Le comportement tactile (appui long, onglets) est dans mobile.js.
   ===================================================================== */

/* ----- Écrans tactiles (sans survol) : actions visibles sans passer la souris ----- */

@media (hover: none){
  .todo_client .icon_urgent,
  .todo_client .icon_go_attente,
  .todo_client .icon_del_attente,
  .taches_col_attente .todo_client .icon_attente_longue,
  .taches_col_attente .todo_client .icon_del_attente{
    display : inline-block !important;
    opacity : 0.55;
  }

  .todo_client.urgent .icon_urgent{ opacity : 1; }

  .item_bat .open_bat_file{ opacity : 1 !important; visibility : visible !important; }

  /* Appui long = ouvrir (mobile.js) : pas de menu « copier / partager » du système */
  .tache_client,
  .name_client,
  .item_bat{
    -webkit-touch-callout : none;
    -webkit-user-select : none;
    user-select : none;
  }
}

/* ----- Fenêtres : jamais plus larges que l'écran ----- */

@media (max-width: 760px){
  .popup,
  #popup_client,
  .popup_bat_edit .popup{
    width : calc(100vw - 24px) !important;
    max-width : 420px;
    max-height : calc(100vh - 40px);
    overflow-y : auto;
  }

  .popup input[type="text"],
  .popup textarea,
  #popup_client #input_popup_client,
  .add_todo,
  .add_client,
  #add_bat{
    font-size : 16px !important; /* 16 px : évite le zoom automatique d'iOS sur les champs */
  }
}

/* ----- Tableau de bord : une carte à la fois (onglets Tâches / BAT en bas) ----- */

.dash-tabs,
.taches-cols-switch{ display : none; }

@media (max-width: 760px){
  main.flex{
    display : block;
    height : auto;
    min-height : 100vh;
    padding : calc(var(--header-height) + 10px) 10px 84px;
  }

  #main_bat,
  #main_list_taches{
    width : 100% !important;
    min-width : 0 !important;
    height : calc(100vh - var(--header-height) - 104px);
    height : calc(100dvh - var(--header-height) - 104px);
    padding : 14px 14px 0;
    border-radius : 18px;
  }

  body[data-dash-tab="taches"] #main_bat,
  body[data-dash-tab="bat"] #main_list_taches{
    display : none;
  }

  /* En-tête de la liste : titre, En cours / En attente, tri */
  #taches_top{ flex-wrap : wrap; gap : 8px; }
  #taches_top .primary_title{ font-size : 18px; }
  #taches_toolbar{ width : 100%; flex-wrap : wrap; gap : 8px; }
  #switch_vue{ flex : 1 1 auto; }
  .switch_vue_btn{ flex : 1 1 0; }
  #tri_select{ flex : 1 1 140px; }

  /* Choix de la colonne affichée (personne, ou Attente / Attente longue) */
  .taches-cols-switch{
    margin : 10px 0 4px;
    padding : 3px;
    display : flex;
    gap : 2px;
    border-radius : 12px;
    background : var(--surface-3);
  }

  .taches-cols-switch button{
    flex : 1 1 0;
    height : 34px;
    border : none;
    border-radius : 9px;
    background : transparent;
    color : var(--text-2);
    font-family : inherit;
    font-size : 13.5px;
    font-weight : 700;
    cursor : pointer;
  }

  .taches-cols-switch button.active{
    background : var(--surface);
    color : var(--text);
    box-shadow : 0 1px 3px var(--hover-strong);
  }

  /* Les colonnes défilent horizontalement, une par écran */
  .taches_view{
    gap : 0 !important;
    overflow-x : auto;
    overscroll-behavior-x : contain;
    scroll-snap-type : x mandatory;
    scrollbar-width : none;
  }

  .taches_view::-webkit-scrollbar{ display : none; }

  .taches_view > .taches_col{
    flex : 0 0 100% !important;
    width : 100% !important;
    min-width : 100%;
    padding : 0 2px;
    border-left : none !important;
    scroll-snap-align : start;
  }

  .taches_col_header{ display : none; }

  .todo_client{ padding-right : 4px; }
  .todo_client .name_client{ white-space : normal; }

  .add_client_bar{ padding-bottom : 12px; }

  /* Barre d'onglets en bas d'écran */
  .dash-tabs{
    position : fixed;
    left : 12px;
    right : 12px;
    bottom : max(12px, env(safe-area-inset-bottom));
    z-index : 90;
    padding : 5px;
    display : grid;
    grid-template-columns : 1fr 1fr;
    gap : 4px;
    border : 1px solid var(--border);
    border-radius : 18px;
    background : var(--header-bg);
    backdrop-filter : saturate(180%) blur(14px);
    -webkit-backdrop-filter : saturate(180%) blur(14px);
    box-shadow : var(--shadow-pop);
  }

  .dash-tabs button{
    height : 44px;
    display : flex;
    align-items : center;
    justify-content : center;
    gap : 8px;
    border : none;
    border-radius : 13px;
    background : transparent;
    color : var(--text-2);
    font-family : inherit;
    font-size : 14px;
    font-weight : 700;
    cursor : pointer;
  }

  .dash-tabs button.active{
    background : var(--primary-color);
    color : white;
  }

  .dash-tabs .badge{
    min-width : 20px;
    padding : 1px 6px;
    border-radius : 99px;
    background : var(--surface-2);
    color : var(--text-2);
    font-size : 11.5px;
  }

  .dash-tabs .badge:empty{ display : none; }

  .dash-tabs button.active .badge{
    background : rgba(255,255,255,0.25);
    color : white;
  }
}

/* ----- Page Commandes ----- */

@media (max-width: 760px){
  #page_commandes{
    padding : calc(var(--header-height) + 14px) 12px 32px !important;
    display : block !important;
  }

  #page_commandes .column{
    width : 100% !important;
    margin : 0 0 20px !important;
    padding : 0 !important;
  }

  #page_commandes .bloc_tags,
  #page_commandes .grid_tags,
  #page_commandes .column.droite > div{
    grid-template-columns : 1fr 1fr !important;
  }
}

@media (max-width: 420px){
  #page_commandes .bloc_tags,
  #page_commandes .grid_tags,
  #page_commandes .column.droite > div{
    grid-template-columns : 1fr !important;
  }
}

/* ----- Page Versions ----- */

@media (max-width: 760px){
  #page_versions{ padding : calc(var(--header-height) + 14px) 12px 32px !important; }
  #page_versions .card{ padding : 18px 16px !important; }
  #page_versions .current strong{ font-size : 22px !important; }
  #page_versions .row > form,
  #page_versions .row > form .btn{ width : 100%; }
  #page_versions label.field,
  #page_versions label.field select,
  #page_versions label.field input{ width : 100%; }
}

/* ----- Import des clients ----- */

@media (max-width: 760px){
  body > form,
  body > .container,
  body > section{
    max-width : 100%;
  }
}
