/* =============================================================================
   responsive.css — Regles responsives Innled QR v1.19.3
   -----------------------------------------------------------------------------
   Breakpoints :
     @media (max-width: 980px)  — tablette : sidebar -> tiroir, topbar mobile
     @media (max-width: 760px)  — mobile   : tableaux -> cartes, grilles -> 1col
     @media (max-width: 640px)  — petit mobile : padding reduit, typo compacte
   Remplace mobile-nav.css (conserve pour compatibilite transitoire).
   Toutes les valeurs proviennent de tokens.css.
   Maquette handoff §3 — Responsive (correctif P0).
   ============================================================================= */

/* =============================================================================
   980px — Tablette : sidebar disparait, topbar mobile apparait
   ============================================================================= */
@media (max-width: 980px) {

  /* --- Grille : une seule colonne (sidebar sort du flux) --- */
  .app-frame {
    grid-template-columns: 1fr;
  }

  .app-main {
    min-height: auto;
  }

  /* --- Sidebar -> tiroir hors-ecran glissant depuis la gauche ---
     Surcharge shell.css : meme specificite + charge apres => l'emporte. */
  body:not(.login-page):not(.public-product-page) .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--drawer-w);   /* 322px */
    max-width: 86%;
    height: 100dvh;
    min-height: 100dvh;
    transform: translateX(-105%);
    transition: transform var(--t-drawer);
    z-index: 1001;
    overflow-y: auto;
    box-shadow: var(--sh-frame);
  }

  body:not(.login-page):not(.public-product-page) .app-frame.drawer-open .app-sidebar {
    transform: none;
  }

  /* --- Backdrop (voile) --- */
  .app-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(3, 19, 38, 0.55);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--t-backdrop), visibility var(--t-backdrop);
    z-index: 1000;
    cursor: pointer;
  }

  .app-frame.drawer-open .app-drawer-backdrop {
    opacity: 1;
    visibility: visible;
  }

  /* Bloque le scroll du fond quand le tiroir est ouvert */
  body.drawer-locked { overflow: hidden; }

  /* --- Topbar mobile : fond navy, hauteur 60px ---
     Maquette : hamburger 44x44 + logo + avatar 38px. */
  .app-topbar {
    height: 60px;
    flex: 0 0 60px;
    padding: 0 16px;
    background: var(--navy-900);
    border-bottom: 1px solid rgba(255,255,255,.08);
  }

  .app-topbar .app-version-pill { display: none; }
  .app-topbar .topbar-name      { display: none; }

  .topbar-avatar {
    width: 38px;
    height: 38px;
    background: rgba(255,255,255,.12);
    border-color: rgba(255,255,255,.2);
    color: var(--on-dark);
  }

  /* Logo/app name dans la topbar mobile */
  .topbar-brand-mobile {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-right: auto;
  }

  .topbar-brand-mobile strong {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: var(--ls-logo);
    color: var(--gold-light);
  }

  .topbar-brand-mobile span {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: rgba(255,255,255,.45);
  }

  /* --- Hamburger visible en mobile --- */
  .app-burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-min);  /* 44px */
    height: var(--touch-min);
    margin-right: 8px;
    border-radius: 12px;
    background: transparent;
    color: var(--on-dark);
  }

  .app-burger svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
  }

  /* Actions topbar : uniquement avatar en mobile */
  .topbar-actions {
    gap: 10px;
  }

  /* Padding page reduit en tablette */
  .pg { padding: var(--pad-app-m); /* 20px 16px */ }

  /* Titres de page : taille mobile */
  .ds-ph h1 { font-size: var(--fs-h1-m); /* 24px */ }
}

/* =============================================================================
   760px — Mobile : tableaux -> cartes empilees
   Strategie cards-mobile : meme balisage <table>, chaque <td> porte
   data-label="<entete>" ; sous 760px chaque ligne devient une carte.
   Aucun scroll horizontal (exigence audit §8).
   ============================================================================= */
@media (max-width: 760px) {

  /* --- Masque l'entete de tableau --- */
  table.cards-mobile thead,
  table.cards-mobile tr:has(> th) { display: none; }

  /* --- Tableau et tbody en bloc --- */
  table.cards-mobile,
  table.cards-mobile tbody {
    display: block;
    width: 100%;
  }

  /* --- Chaque ligne devient une carte --- */
  table.cards-mobile tr {
    display: block;
    background: var(--card);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-card);
    box-shadow: var(--sh-card);
    padding: 10px 14px;
    margin-bottom: 12px;
  }

  /* --- Cellule de base : bloc pleine largeur --- */
  table.cards-mobile td {
    display: block;
    border: 0;
    padding: 8px 0;
    min-height: 36px;
  }

  /* --- Cellule avec libelle : libelle a gauche, valeur a droite --- */
  table.cards-mobile td[data-label]:not([data-label=""]) {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
  }

  table.cards-mobile tr > td + td {
    border-top: 1px solid var(--border);
  }

  /* Rappel du libelle (pseudo-element) */
  table.cards-mobile td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    flex: 0 0 38%;
    font-weight: 800;
    font-size: 11px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
  }

  /* Cellule vide : masquee */
  table.cards-mobile td:empty { display: none; }

  /* La valeur s'aligne a droite */
  table.cards-mobile td > * { margin-left: auto; }

  table.cards-mobile td input,
  table.cards-mobile td select,
  table.cards-mobile td textarea {
    flex: 1 1 60%;
    min-width: 0;
  }

  /* Plus de scroll horizontal sur le wrapper de tableau */
  .table-wrap:has(table.cards-mobile) { overflow-x: visible; }

  /* Grille Sync SQL mapping : 1 colonne en mobile */
  .mirror-col-grid { grid-template-columns: 1fr; }

  /* Barre de filtres : champs pleine largeur */
  .pg-toolbar { gap: 8px; }
  .pg-toolbar-field { min-width: 100%; max-width: 100%; }
  .pg-toolbar-actions { width: 100%; }

  /* Actions de page : orientation verticale */
  .ds-ph { flex-direction: column; align-items: stretch; }
  .ds-ph-actions { justify-content: stretch; }
  .ds-ph-actions .ds-btn { flex: 1; justify-content: center; }
}

/* =============================================================================
   640px — Petit mobile : ajustements fins
   ============================================================================= */
@media (max-width: 640px) {

  /* Grilles KPI : 2 colonnes minimum */
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  }

  /* Boutons nav wrap sous le titre */
  .ds-ph { gap: 10px; }
}
