/* ═══════════════════════════════════════════════════════════════
   MDT LUTIN — Mobile responsive overrides
   Cible: téléphones (≤720px) et tablettes étroites (≤1024px)
═══════════════════════════════════════════════════════════════ */

html,body{-webkit-text-size-adjust:100%}

/* ═══════════════════════════════ LOGIN ═════════════════════════════ */
@media (max-width:480px){
  #login-screen{padding:16px}
  .login-box{
    width:100%;
    max-width:100%;
    padding:28px 22px;
    border-radius:16px;
  }
  .brand-name{font-size:22px}
  .brand-sub{font-size:10px;letter-spacing:2px}
}

/* ═══════════════════════════════ TOPBAR ═════════════════════════════ */
@media (max-width:1024px){
  .topbar{padding:0 10px;gap:6px}
  .tb-brand{gap:8px;min-width:0;flex:1}
  .tb-name{font-size:13px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .topbar-right{gap:6px;flex-shrink:0}
  .tb-tag{padding:4px 9px;font-size:10.5px}
}
@media (max-width:720px){
  .topbar{height:52px;padding:0 8px}
  .layout{height:calc(100vh - 52px)}
  .sidebar,.sb-backdrop{top:52px}
  .tb-brand img{width:28px!important;height:28px!important}
  .tb-name{font-size:12.5px}
  /* Garde l'horloge masquée mais une variante mini possible */
  .notif-bell{width:34px;height:34px}
}
@media (max-width:380px){
  .topbar{padding:0 6px}
  .tb-name{font-size:11.5px}
  .sb-toggle{width:32px;height:32px;margin-right:4px}
}

/* ═══════════════════════════════ NOTIFICATIONS ═════════════════════════ */
@media (max-width:720px){
  .notif-dropdown{
    position:fixed!important;
    top:54px!important;
    right:8px!important;
    left:8px!important;
    width:auto!important;
    max-height:70vh;
  }
}

/* ═══════════════════════════════ GLOBAL SEARCH ═════════════════════════ */
@media (max-width:720px){
  /* Le sélecteur HTML cache déjà .gs-wrap sur 720, mais on garde un fallback */
  .gs-wrap{display:none}
  .gs-dd{position:fixed;top:54px;left:8px;right:8px;width:auto;max-height:70vh}
}

/* ═══════════════════════════════ PAGE / MAIN ═════════════════════════ */
@media (max-width:720px){
  .main{padding:14px 12px 80px}
  .page-header{margin-bottom:16px}
  .page-title{font-size:18px}
  .page-sub{font-size:11.5px}
}
@media (max-width:480px){
  .main{padding:12px 10px 80px}
  .page-title{font-size:17px}
}

/* ═══════════════════════════════ CARDS ═════════════════════════════ */
@media (max-width:720px){
  .card{padding:14px;border-radius:14px;margin-bottom:12px}
  .card-title{font-size:10.5px;margin-bottom:12px}
}

/* ═══════════════════════════════ FORMS ═════════════════════════════ */
@media (max-width:720px){
  .form-grid{grid-template-columns:1fr;gap:10px}
  .form-group.full{grid-column:1/-1}
  .finput,.linput{font-size:16px;padding:11px 13px}  /* 16px = pas de zoom iOS */
  .flabel,.lbl{font-size:11px}
  textarea.finput{min-height:90px}
}

/* ═══════════════════════════════ SEARCH ROW ═════════════════════════ */
@media (max-width:560px){
  .search-row{flex-direction:column;gap:8px}
  .search-row .finput{width:100%}
  .search-row .btn{width:100%;justify-content:center}
}

/* ═══════════════════════════════ BTN GROUP ═════════════════════════ */
@media (max-width:560px){
  .btn-group{flex-direction:column;gap:8px}
  .btn-group .btn{width:100%;justify-content:center;padding:12px 16px}
}

/* ═══════════════════════════════ FILTER BARS / CHIPS ═════════════════ */
@media (max-width:720px){
  .filter-bar{
    flex-wrap:nowrap;
    overflow-x:auto;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:none;
    padding:8px 10px;
    gap:6px;
  }
  .filter-bar::-webkit-scrollbar{display:none}
  .filter-bar .filter-label{flex-shrink:0;font-size:10px}
  .filter-bar .filter-chip{flex-shrink:0;padding:7px 12px;font-size:11.5px;white-space:nowrap}
}

/* ═══════════════════════════════ TABLES — scroll horizontal ══════════ */
@media (max-width:900px){
  /* Force le scroll horizontal sur les cards contenant une table.
     Le HTML utilise style="overflow:hidden" inline, on contre avec !important. */
  .card:has(> table),
  .card:has(table){
    overflow-x:auto!important;
    overflow-y:hidden!important;
    -webkit-overflow-scrolling:touch;
    position:relative;
  }
  table{min-width:620px;font-size:12.5px}
  table th,table td{padding:9px 10px!important;white-space:nowrap}

}

/* ═══════════════════════════════ TILES (dashboard) ═════════════════════ */
@media (max-width:480px){
  .tiles-grid{grid-template-columns:repeat(2,1fr)!important;gap:10px}
  .tile{padding:12px}
  .tile-count{font-size:20px}
  .tile-label{font-size:10.5px}
  .tile-icon svg{width:18px;height:18px}
}

/* ═══════════════════════════════ MODALES ═════════════════════════════ */
@media (max-width:600px){
  .modal-box{
    width:100%!important;
    max-width:100%!important;
    padding:20px 16px!important;
    border-radius:16px 16px 0 0!important;
    margin-top:auto;
  }
  /* Force les overlay modaux à s'aligner en bas (effet sheet) */
  [role="dialog"][style*="position:fixed"][style*="inset:0"]{
    align-items:flex-end!important;
    padding:0!important;
  }
  /* Penalty picker spécifique */
  #pen-picker > div{
    width:100%!important;
    max-width:100%!important;
    max-height:90vh!important;
    border-radius:16px 16px 0 0!important;
  }
  #pen-picker{padding-top:0!important;align-items:flex-end!important}
}

/* ═══════════════════════════════ CHIP PICKER ═════════════════════════ */
@media (max-width:720px){
  .chip-picker-chip-label{max-width:160px}
  .chip-picker-input{font-size:14px}
  .chip-picker-dropdown{max-height:200px}
}

/* ═══════════════════════════════ BUTTONS — tap targets ═══════════════ */
@media (max-width:720px){
  .btn{min-height:38px;padding:9px 14px;font-size:12.5px}
  .btn-sm{min-height:32px;padding:6px 10px}
  .nav-item{padding:11px 18px;font-size:12.5px}
  .filter-chip{min-height:32px}
}

/* ═══════════════════════════════ MAP ═════════════════════════════ */
@media (max-width:720px){
  #map,.map-container{height:60vh!important;min-height:380px}
}

/* ═══════════════════════════════ STATS / CHARTS ═════════════════════ */
@media (max-width:720px){
  .stats-grid{grid-template-columns:1fr!important;gap:12px!important}
  .inter-stats{grid-template-columns:repeat(2,1fr)!important;gap:8px!important}
}

/* ═══════════════════════════════ TOAST ═════════════════════════════ */
@media (max-width:480px){
  #toast{
    left:12px!important;
    right:12px!important;
    bottom:14px!important;
    max-width:none!important;
  }
}

/* ═══════════════════════════════ AGENTS toolbar ═════════════════════ */
@media (max-width:560px){
  #page-rpagents > div[style*="display:flex"]{
    flex-wrap:wrap;
    gap:8px!important;
  }
  #rpa-search{flex:1 1 100%!important;font-size:14px!important;padding:10px 12px!important}
  #rpagent-org-btn,#rpagent-new-btn{flex:1 1 auto;white-space:nowrap}
}

/* ═══════════════════════════════ CASIERS ═════════════════════════════ */
@media (max-width:560px){
  .casier-header{
    flex-wrap:wrap;
    gap:8px 10px;
    padding:11px 12px;
  }
  .casier-header > div:first-child{
    flex:1 1 100%;
    min-width:0;
    flex-wrap:wrap;
  }
  .casier-header > div:first-child .btn-link,
  .casier-header > div:first-child > span:first-child{
    word-break:break-word;
    line-height:1.3;
  }
  .casier-header > div:last-child{
    flex:0 0 auto;
    margin-left:auto;
  }
  .casier-body{padding:12px}
  .infraction-line{
    flex-wrap:wrap;
    gap:6px 10px;
    padding:9px 0;
    font-size:11.5px;
  }
  .infraction-line > div{min-width:0!important;text-align:left!important}
}

/* ═══════════════════════════════ EDIT BANNER ═════════════════════════ */
@media (max-width:720px){
  .edit-banner{font-size:11.5px;padding:10px 12px;line-height:1.45}
}

/* ═══════════════════════════════ PERSONS DETAIL ═════════════════════ */
@media (max-width:720px){
  .linked-grid,
  .inter-doc-meta{grid-template-columns:1fr!important;gap:10px!important}
}

/* ═══════════════════════════════ GRILLES INLINE EN JS ═════════════════
   Beaucoup de pages injectent <div style="grid-template-columns:1fr 1fr">
   ou repeat(2|3,1fr) directement. On force la colonne unique sur mobile,
   peu importe le niveau d'imbrication. ═══════════════════════════════ */
@media (max-width:720px){
  .main div[style*="grid-template-columns:1fr 1fr"],
  .main div[style*="grid-template-columns: 1fr 1fr"],
  .main div[style*="grid-template-columns:repeat(2,1fr)"],
  .main div[style*="grid-template-columns: repeat(2,1fr)"],
  .main div[style*="grid-template-columns:repeat(3,1fr)"],
  .main div[style*="grid-template-columns: repeat(3,1fr)"]{
    grid-template-columns:1fr!important;
  }
}
@media (max-width:480px){
  .main div[style*="grid-template-columns:repeat(4,1fr)"],
  .main div[style*="grid-template-columns: repeat(4,1fr)"]{
    grid-template-columns:repeat(2,1fr)!important;
  }
}

/* ═══════════════════════════════ SAFETY — no horizontal scroll ═════════ */
@media (max-width:720px){
  html,body{overflow-x:hidden;max-width:100vw}
  .main{max-width:100vw;overflow-x:hidden}
  .page{max-width:100%;overflow-x:hidden}
  .page > *{max-width:100%}
}

/* ═══════════════════════════════ BOTTOM NAV ═════════════════════════ */
.bottom-nav{display:none}
@media (max-width:720px){
  .bottom-nav{
    display:flex;
    position:fixed;left:0;right:0;bottom:0;z-index:60;
    height:58px;
    padding-bottom:env(safe-area-inset-bottom,0);
    background:var(--bg2,#0c1322);
    border-top:1px solid var(--border,rgba(255,255,255,.08));
    box-shadow:0 -4px 16px rgba(0,0,0,.3);
  }
  .bn-item{
    flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;
    background:none;border:none;cursor:pointer;
    color:var(--text3,#6b7693);font-size:9.5px;font-weight:600;letter-spacing:.2px;
    padding:6px 2px;min-width:0;
  }
  .bn-item svg{width:20px;height:20px}
  .bn-item.active{color:var(--accent,#60a5fa)}
  .bn-item:active{background:rgba(255,255,255,.04)}
  .layout{height:calc(100vh - 52px)}
}

/* ═══════════════════════════════ FAB CRÉATION RAPIDE ═══════════════════ */
.qc-wrap{display:none}
@media (max-width:720px){
  .qc-wrap{
    display:block;position:fixed;right:16px;z-index:61;
    bottom:calc(58px + env(safe-area-inset-bottom,0) + 16px); /* au-dessus de la bottom-nav */
  }
  .qc-fab{
    width:52px;height:52px;border-radius:50%;border:none;cursor:pointer;
    background:var(--accent,#60a5fa);color:#0b1220;
    display:flex;align-items:center;justify-content:center;
    box-shadow:0 6px 18px rgba(0,0,0,.4);
    transition:transform .18s ease;
  }
  .qc-fab svg{width:22px;height:22px}
  .qc-fab.open{transform:rotate(45deg)}
  .qc-menu{
    position:absolute;right:0;bottom:64px;
    display:flex;flex-direction:column;gap:8px;min-width:210px;
  }
  .qc-menu[hidden]{display:none}
  .qc-action{
    display:flex;align-items:center;gap:8px;
    background:var(--bg2,#0c1322);color:var(--text,#e6ecf7);
    border:1px solid var(--border,rgba(255,255,255,.1));border-radius:12px;
    padding:12px 14px;font-size:13px;font-weight:600;text-align:left;cursor:pointer;
    box-shadow:0 4px 12px rgba(0,0,0,.3);
  }
  .qc-action:active{background:rgba(255,255,255,.05)}
}

/* ═══════════════════════════════ MODE HORS-LIGNE ═══════════════════════ */
.offline-banner{
  display:block;margin:0 0 14px;
  background:rgba(251,191,36,.12);border:1px solid rgba(251,191,36,.4);
  color:#fbbf24;border-radius:10px;
  padding:10px 14px;font-size:12.5px;font-weight:600;line-height:1.45;
}
.offline-banner[hidden]{display:none}
/* Hors-ligne = lecture seule : neutraliser les boutons de création/édition + le FAB. */
body.is-offline .btn-primary,
body.is-offline #qc-fab,
body.is-offline [id$="-new-btn"]{
  opacity:.45;pointer-events:none;
}
