/* =========================================================
   CS STOCK CONNECT — DESIGN MOBILE COMPACT ET MODERNE
   Version shell-29
   ========================================================= */

.mobile-bottom-nav{display:none}

@media(max-width:760px){
  :root{
    --mobile-gutter:14px;
    --mobile-nav-height:72px;
    --mobile-radius:16px;
  }

  html{background:var(--bg)}
  body{
    min-width:320px;
    padding-bottom:calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    background:var(--bg);
  }

  /* En-tête plus léger */
  .topbar{
    min-height:68px!important;
    padding:10px var(--mobile-gutter)!important;
    gap:10px!important;
    border-bottom:1px solid var(--border)!important;
    box-shadow:none!important;
    background:color-mix(in srgb,var(--card) 94%,transparent)!important;
  }
  .topbar-main{gap:10px!important;min-width:0!important}
  #menuBtn{display:none!important}
  .page-heading h1{
    max-width:190px!important;
    margin:0 0 3px!important;
    font-size:1.08rem!important;
    line-height:1.15!important;
    font-weight:850!important;
  }
  .page-heading p{
    max-width:210px!important;
    font-size:.72rem!important;
    line-height:1.25!important;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
  }
  .top-actions{gap:6px!important}
  .top-actions .theme-btn{
    width:36px!important;
    height:36px!important;
    min-width:36px!important;
    border-radius:11px!important;
    box-shadow:none!important;
    font-size:1rem!important;
  }
  #networkStatus{display:none!important}
  #syncBtn{
    width:36px!important;
    height:36px!important;
    min-width:36px!important;
    padding:0!important;
    border:1px solid var(--border)!important;
    border-radius:11px!important;
    background:var(--card-2)!important;
    color:var(--primary)!important;
    box-shadow:none!important;
    font-size:0!important;
  }
  #syncBtn::before{content:"↻";font-size:1.15rem;font-weight:900}

  /* Contenu général */
  .content{padding:12px var(--mobile-gutter) 20px!important}
  .panel,.stat-card{border-radius:var(--mobile-radius)!important;box-shadow:none!important}
  .panel{background:var(--card)!important}
  .panel-head{padding:14px 15px!important}
  .panel-head h2{font-size:.95rem!important}
  .panel-subtitle{margin-top:4px!important;font-size:.76rem!important}

  /* Sélecteur de mois compact */
  .month-bar{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:center!important;
    gap:10px!important;
    padding:11px 12px!important;
    margin-bottom:12px!important;
    border-radius:14px!important;
    background:var(--card)!important;
    box-shadow:none!important;
  }
  .month-bar-copy{gap:1px!important}
  .month-label{font-size:.62rem!important;letter-spacing:.06em!important}
  #activeMonthLabel{font-size:.94rem!important}
  .month-bar-actions{width:auto!important;display:flex!important;gap:6px!important;flex-wrap:nowrap!important}
  .month-bar-actions .btn{
    width:36px!important;
    height:36px!important;
    min-width:36px!important;
    padding:0!important;
    border-radius:10px!important;
    font-size:0!important;
  }
  #chooseMonthBtn::before{content:"▣";font-size:1rem}
  #newMonthBtn::before{content:"＋";font-size:1.1rem}

  /* Tableau de bord compact */
  .cards,.dashboard-kpis,.v11-mini-kpis{
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:9px!important;
    margin-bottom:12px!important;
  }
  .cards .stat-card{
    min-height:94px!important;
    padding:13px!important;
    border-top:0!important;
    background:var(--card)!important;
  }
  .cards .stat-card::after{width:62px!important;height:62px!important;right:-20px!important;bottom:-22px!important}
  .cards .stat-card span{
    min-height:0!important;
    font-size:.72rem!important;
    line-height:1.25!important;
  }
  .cards .stat-card strong{margin-top:auto!important;font-size:1.45rem!important;line-height:1.1!important}
  .cards .stat-card small{font-size:.65rem!important}
  .dashboard-grid{grid-template-columns:1fr!important;gap:12px!important}

  /* Champs et boutons : grands pour le doigt, mais pas massifs */
  input,textarea,select,.select-field{
    min-height:48px;
    padding:11px 12px!important;
    border-radius:12px!important;
    font-size:16px!important;
    background:var(--card)!important;
  }
  textarea{min-height:92px}
  label{font-size:.82rem;font-weight:750}
  .btn{
    min-height:44px;
    padding:10px 13px!important;
    border-radius:12px!important;
    box-shadow:none!important;
    font-size:.84rem!important;
  }
  .btn:hover{transform:none!important}

  /* Barre de recherche et actions */
  .toolbar,.v11-toolbar,#view-medicines .medicine-toolbar{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px!important;
    margin-bottom:11px!important;
    align-items:stretch!important;
  }
  .toolbar>input,.v11-toolbar>input,#view-medicines .medicine-toolbar #medicineSearch{
    grid-column:1/-1!important;
    width:100%!important;
    max-width:none!important;
    margin:0!important;
  }
  .toolbar>.btn,.v11-toolbar>.btn,#view-medicines .medicine-toolbar>.btn{
    width:100%!important;
    margin:0!important;
  }
  #view-medicines #addMedicineBtn{grid-column:1/2!important}
  #view-medicines #addMultipleMedicineBtn{grid-column:2/3!important}
  #view-medicines #selectMedicinesBtn{grid-column:1/-1!important}
  .mobile-filter-toggle{
    grid-column:1/-1!important;
    min-height:40px!important;
    padding:8px 11px!important;
    border-style:dashed!important;
    color:var(--muted)!important;
    background:transparent!important;
  }
  .mobile-filter-toggle span:first-child{display:none}

  /* Listes mobiles : cartes plates et compactes */
  .table-wrap:has(.mobile-card-table){overflow:visible!important;border:0!important;background:transparent!important}
  .mobile-card-table{display:block!important;min-width:0!important;width:100%!important}
  .mobile-card-table thead{display:none!important}
  .mobile-card-table tbody{display:grid!important;gap:8px!important}
  .mobile-card-table tbody tr.mobile-data-card{
    display:grid!important;
    grid-template-columns:repeat(2,minmax(0,1fr))!important;
    gap:8px 12px!important;
    padding:12px!important;
    border:1px solid var(--border)!important;
    border-radius:15px!important;
    background:var(--card)!important;
    box-shadow:none!important;
  }
  .mobile-card-table tbody td{
    display:flex!important;
    min-width:0!important;
    padding:0!important;
    border:0!important;
    flex-direction:column!important;
    gap:2px!important;
    align-items:flex-start!important;
    text-align:left!important;
    white-space:normal!important;
    font-size:.82rem!important;
  }
  .mobile-card-table tbody td::before{
    content:attr(data-label);
    color:var(--muted);
    font-size:.60rem!important;
    font-weight:800!important;
    letter-spacing:.045em;
    text-transform:uppercase;
  }
  .mobile-card-table tbody td[data-label="Produit"],
  .mobile-card-table tbody td[data-label="Médicament"],
  .mobile-card-table tbody td[data-label="Nom du médicament"],
  .mobile-card-table tbody td[data-label="Référence"]{grid-column:1/-1!important}
  .mobile-card-table tbody td[data-label="Actions"],
  .mobile-card-table tbody td:last-child:has(.row-actions){
    grid-column:1/-1!important;
    padding-top:8px!important;
    margin-top:2px!important;
    border-top:1px solid var(--border)!important;
  }
  .mobile-card-table .row-actions{
    display:flex!important;
    width:100%!important;
    justify-content:flex-end!important;
    gap:6px!important;
  }
  .mobile-card-table .row-actions button{
    width:38px!important;
    min-width:38px!important;
    height:38px!important;
    min-height:38px!important;
    padding:0!important;
    border-radius:10px!important;
  }

  /* Carte stock dédiée */
  .mobile-stock-table tbody tr.mobile-data-card{
    grid-template-columns:minmax(0,1fr) auto!important;
    padding:13px!important;
  }
  .mobile-stock-table .col-name{
    grid-column:1/-1!important;
    padding-right:34px!important;
  }
  .mobile-stock-table .col-name::before{display:none!important}
  .mobile-stock-table .col-name strong{
    font-size:.94rem!important;
    line-height:1.3!important;
    letter-spacing:-.01em;
  }
  .mobile-stock-table .col-type,.mobile-stock-table .col-source{
    display:inline-flex!important;
    width:auto!important;
    align-self:start!important;
  }
  .mobile-stock-table .col-type::before,.mobile-stock-table .col-source::before{display:none!important}
  .mobile-stock-table .col-available{
    grid-column:1/2!important;
    padding:10px 11px!important;
    border-radius:12px!important;
    background:var(--primary-soft,#e7f7f5)!important;
  }
  .mobile-stock-table .col-available::before{color:var(--primary-dark)!important}
  .mobile-stock-table .col-available strong{font-size:1.35rem!important;color:var(--primary-dark)!important}
  .mobile-stock-table .col-alert{grid-column:2/3!important;align-items:flex-end!important;justify-content:center!important}
  .mobile-stock-table .col-expiry{grid-column:1/-1!important;display:flex!important;flex-direction:row!important;justify-content:space-between!important;align-items:center!important;padding-top:6px!important}
  .mobile-stock-table .col-expiry::before{margin-right:auto}
  .mobile-stock-table tr:not(.mobile-expanded) .col-unit,
  .mobile-stock-table tr:not(.mobile-expanded) .col-price,
  .mobile-stock-table tr:not(.mobile-expanded) .col-required,
  .mobile-stock-table tr:not(.mobile-expanded) .col-initial,
  .mobile-stock-table tr:not(.mobile-expanded) .col-entries,
  .mobile-stock-table tr:not(.mobile-expanded) .col-exits{display:none!important}
  .mobile-stock-table .col-actions{grid-column:1/-1!important}
  .mobile-stock-table .col-actions .row-actions{justify-content:flex-end!important}
  .mobile-card-details{
    margin-right:auto!important;
    width:auto!important;
    min-width:0!important;
    padding:0 10px!important;
    background:transparent!important;
    border:0!important;
    color:var(--primary)!important;
  }
  .mobile-card-details svg{width:17px!important;height:17px!important}
  .mobile-stock-table .bulk-selection-cell:not(.hidden){top:11px!important;right:11px!important}

  /* Fenêtres transformées en feuilles plein écran propres */
  dialog{
    width:100%!important;
    max-width:none!important;
    height:100dvh!important;
    max-height:100dvh!important;
    margin:0!important;
    border-radius:0!important;
  }
  dialog::backdrop{background:rgba(2,18,17,.56)!important}
  .dialog-form{
    min-height:100dvh!important;
    max-height:100dvh!important;
    padding:0 16px calc(86px + env(safe-area-inset-bottom))!important;
    gap:13px!important;
    overflow:auto!important;
    background:var(--bg)!important;
  }
  .dialog-head{
    position:sticky!important;
    top:0!important;
    z-index:30!important;
    margin:0 -16px!important;
    padding:13px 16px!important;
    border-bottom:1px solid var(--border)!important;
    background:var(--card)!important;
  }
  .dialog-head h2{font-size:1.05rem!important}
  .dialog-head .muted{font-size:.72rem!important}
  .dialog-head .icon-btn{
    width:38px!important;
    height:38px!important;
    border-radius:11px!important;
    background:var(--card-2)!important;
  }
  .form-grid{grid-template-columns:1fr!important;gap:11px!important}

  .mobile-wizard-progress{
    padding:4px 0 10px!important;
    border:0!important;
    border-radius:0!important;
    background:transparent!important;
  }
  .mobile-wizard-progress-copy small{font-size:.68rem!important}
  .mobile-wizard-progress-copy strong{font-size:.9rem!important}
  .mobile-wizard-dots{gap:4px!important}
  .mobile-wizard-dots i{height:4px!important;flex:1!important;width:28px!important}
  .mobile-wizard-actions,
  #adjustmentDialog .dialog-actions,
  #batchMedicineDialog .dialog-actions,
  #inventoryDialog .dialog-actions{
    position:fixed!important;
    left:0!important;
    right:0!important;
    bottom:0!important;
    z-index:45!important;
    display:grid!important;
    grid-template-columns:1fr 1.25fr!important;
    gap:8px!important;
    margin:0!important;
    padding:10px 14px calc(10px + env(safe-area-inset-bottom))!important;
    border-top:1px solid var(--border)!important;
    background:color-mix(in srgb,var(--card) 96%,transparent)!important;
    box-shadow:0 -8px 22px rgba(15,23,42,.08)!important;
    backdrop-filter:blur(14px)!important;
  }
  .mobile-wizard-actions .btn{width:100%!important}

  /* Inventaire mobile : une saisie nette et visible */
  #inventoryDialog .inventory-search-row{
    top:65px!important;
    margin:0!important;
    padding:8px 0!important;
    background:var(--bg)!important;
  }
  .inventory-mobile-progress{height:5px!important;margin:0!important}
  .mobile-inventory-count-table tbody tr.mobile-data-card{
    grid-template-columns:minmax(0,1fr) 112px!important;
    align-items:center!important;
  }
  .mobile-inventory-count-table tbody td:first-child{grid-column:1/-1!important}
  .mobile-inventory-count-table .inventory-count-input{
    min-height:52px!important;
    font-size:1.05rem!important;
    border:2px solid var(--border)!important;
  }
  #inventoryDialog .inventory-dialog-form>.dialog-actions{grid-template-columns:1fr 1.25fr!important}
  #inventoryDialog .inventory-dialog-form>.dialog-actions .btn:first-child{display:none!important}
  #inventoryDialog .inventory-dialog-form>.dialog-actions .btn:last-child{grid-column:auto!important}

  /* Ajout multiple */
  #batchMedicineDialog .batch-common-grid{grid-template-columns:1fr!important}
  .mobile-batch-table tbody tr.mobile-data-card{grid-template-columns:1fr 1fr!important}
  .mobile-batch-table tbody td:first-child{grid-column:1/-1!important}

  /* Barre de navigation inférieure */
  .mobile-bottom-nav{
    position:fixed;
    left:0;
    right:0;
    bottom:0;
    z-index:80;
    display:grid;
    grid-template-columns:repeat(5,1fr);
    height:calc(var(--mobile-nav-height) + env(safe-area-inset-bottom));
    padding:6px 5px env(safe-area-inset-bottom);
    border-top:1px solid var(--border);
    background:color-mix(in srgb,var(--card) 96%,transparent);
    box-shadow:0 -8px 24px rgba(15,23,42,.08);
    backdrop-filter:blur(18px);
  }
  .mobile-bottom-nav button{
    position:relative;
    display:flex;
    flex-direction:column;
    align-items:center;
    justify-content:center;
    gap:3px;
    min-width:0;
    border:0;
    border-radius:12px;
    background:transparent;
    color:var(--muted);
    font-size:.62rem;
    font-weight:750;
  }
  .mobile-bottom-nav button svg{
    width:22px;
    height:22px;
    fill:none;
    stroke:currentColor;
    stroke-width:2;
    stroke-linecap:round;
    stroke-linejoin:round;
  }
  .mobile-bottom-nav button.active{color:var(--primary);background:var(--primary-soft,#e7f7f5)}
  .mobile-bottom-nav button[data-mobile-more="true"] svg{stroke-width:2.4}

  /* Menu latéral ouvert depuis Plus */
  .sidebar{width:min(86vw,320px)!important;padding-bottom:90px!important}
  .sidebar nav{gap:4px!important}
  .nav-btn{min-height:44px!important;padding:9px 10px!important;font-size:.9rem!important}
  .nav-icon{width:25px!important;height:25px!important;flex-basis:25px!important;font-size:.95rem!important}
  .nav-section-label{margin-top:12px!important;font-size:.62rem!important}

  /* Notifications */
  .toast-stack{left:10px!important;right:10px!important;bottom:calc(var(--mobile-nav-height) + 12px + env(safe-area-inset-bottom))!important;width:auto!important}
  .toast-item{border-radius:13px!important}
}

@media(min-width:761px){
  .mobile-bottom-nav{display:none!important}
}

@media(max-width:760px){
  /* Neutralise les anciennes couleurs type Excel dans les cartes mobiles. */
  #view-medicines .mobile-stock-table .stock-sheet-row td{
    min-width:0!important;
    background:transparent!important;
    color:var(--text)!important;
    text-align:left!important;
    filter:none!important;
  }
  #view-medicines .mobile-stock-table .stock-sheet-row:hover td{filter:none!important}
  #view-medicines .mobile-stock-table .col-available{
    background:var(--primary-soft,#e7f7f5)!important;
    color:var(--primary-dark)!important;
  }
  #view-medicines .mobile-stock-table .col-actions{background:transparent!important}
  #view-medicines .mobile-stock-table .col-alert{background:transparent!important;color:var(--text)!important}

  .mobile-stock-table tr:not(.mobile-expanded) .col-type{grid-column:1/2!important;grid-row:2!important}
  .mobile-stock-table tr:not(.mobile-expanded) .col-source{grid-column:2/3!important;grid-row:2!important;align-items:flex-end!important;text-align:right!important}
  .mobile-stock-table tr:not(.mobile-expanded) .col-available{grid-column:1/2!important;grid-row:3!important}
  .mobile-stock-table tr:not(.mobile-expanded) .col-alert{grid-column:2/3!important;grid-row:3!important;align-items:flex-end!important;justify-content:center!important}
  .mobile-stock-table tr:not(.mobile-expanded) .col-expiry{grid-column:1/-1!important;grid-row:4!important}
  .mobile-stock-table tr:not(.mobile-expanded) .col-actions{grid-column:1/-1!important;grid-row:5!important}
  .mobile-stock-table .col-alert::before{color:var(--muted)!important}
  .mobile-stock-table .col-alert .badge{white-space:nowrap!important}
  .mobile-stock-table .program-badge,.mobile-stock-table .source-badge{
    max-width:100%!important;
    padding:4px 8px!important;
    border-radius:999px!important;
    font-size:.68rem!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }
}

@media(max-width:760px){
  /* Les petites confirmations restent de vraies fenêtres compactes. */
  dialog:not(#medicineDialog):not(#movementDialog):not(#inventoryDialog):not(#batchMedicineDialog):not(#adjustmentDialog){
    width:min(94vw,520px)!important;
    max-width:520px!important;
    height:auto!important;
    max-height:88dvh!important;
    margin:auto!important;
    border-radius:18px!important;
  }
  dialog:not(#medicineDialog):not(#movementDialog):not(#inventoryDialog):not(#batchMedicineDialog):not(#adjustmentDialog) .dialog-form{
    min-height:0!important;
    max-height:88dvh!important;
    padding:16px!important;
    overflow:auto!important;
    background:var(--card)!important;
  }
  dialog:not(#medicineDialog):not(#movementDialog):not(#inventoryDialog):not(#batchMedicineDialog):not(#adjustmentDialog) .dialog-head{
    position:static!important;
    margin:0!important;
    padding:0 0 10px!important;
    background:transparent!important;
    border-bottom:0!important;
  }

  #medicineDialog,#movementDialog,#inventoryDialog,#batchMedicineDialog,#adjustmentDialog{
    width:100%!important;
    max-width:none!important;
    height:100dvh!important;
    max-height:100dvh!important;
    margin:0!important;
    border-radius:0!important;
  }
}

/* =========================================================
   SDU PRIORITAIRE SUR MOBILE — shell-30
   Le stock disponible devient le point focal de chaque carte.
   ========================================================= */
.sdu-mobile-label,
.sdu-mobile-reference,
.sdu-mobile-status,
.sdu-unit{display:none}

@media(max-width:760px){
  #view-medicines .mobile-stock-table .col-available.sdu-emphasis{
    position:relative!important;
    grid-column:1/-1!important;
    grid-row:3!important;
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    grid-template-areas:
      "label status"
      "main status"
      "reference reference"!important;
    gap:2px 12px!important;
    align-items:center!important;
    min-height:92px!important;
    margin-top:4px!important;
    padding:13px 14px 12px 17px!important;
    border:1px solid color-mix(in srgb,var(--border) 76%,transparent)!important;
    border-left-width:5px!important;
    border-radius:14px!important;
    box-shadow:0 5px 15px rgba(15,23,42,.055)!important;
    overflow:hidden!important;
  }
  #view-medicines .mobile-stock-table .col-available.sdu-emphasis::before{display:none!important}
  #view-medicines .mobile-stock-table .col-available.sdu-satisfactory{
    border-left-color:#07855b!important;
    background:linear-gradient(135deg,rgba(5,150,105,.13),rgba(255,255,255,.72))!important;
  }
  #view-medicines .mobile-stock-table .col-available.sdu-necessary{
    border-left-color:#d97706!important;
    background:linear-gradient(135deg,rgba(245,158,11,.16),rgba(255,255,255,.76))!important;
  }
  #view-medicines .mobile-stock-table .col-available.sdu-urgent{
    border-left-color:#dc2626!important;
    background:linear-gradient(135deg,rgba(239,68,68,.15),rgba(255,255,255,.76))!important;
  }
  body.dark #view-medicines .mobile-stock-table .col-available.sdu-satisfactory{
    background:linear-gradient(135deg,rgba(5,150,105,.23),rgba(15,23,42,.72))!important;
  }
  body.dark #view-medicines .mobile-stock-table .col-available.sdu-necessary{
    background:linear-gradient(135deg,rgba(245,158,11,.22),rgba(15,23,42,.72))!important;
  }
  body.dark #view-medicines .mobile-stock-table .col-available.sdu-urgent{
    background:linear-gradient(135deg,rgba(239,68,68,.22),rgba(15,23,42,.72))!important;
  }
  .mobile-stock-table .sdu-mobile-label{
    display:block!important;
    grid-area:label!important;
    color:var(--muted)!important;
    font-size:.68rem!important;
    line-height:1!important;
    font-weight:900!important;
    letter-spacing:.1em!important;
  }
  .mobile-stock-table .sdu-mobile-main{
    grid-area:main!important;
    display:flex!important;
    align-items:baseline!important;
    gap:7px!important;
    min-width:0!important;
  }
  #view-medicines .mobile-stock-table .sdu-value{
    color:var(--text)!important;
    font-size:2rem!important;
    line-height:1!important;
    font-weight:950!important;
    letter-spacing:-.045em!important;
  }
  .mobile-stock-table .sdu-unit{
    display:inline!important;
    max-width:145px!important;
    color:var(--text)!important;
    font-size:.8rem!important;
    font-weight:800!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }
  .mobile-stock-table .sdu-mobile-reference{
    display:block!important;
    grid-area:reference!important;
    margin-top:4px!important;
    color:var(--muted)!important;
    font-size:.7rem!important;
    line-height:1.3!important;
    font-weight:650!important;
  }
  .mobile-stock-table .sdu-mobile-status{
    display:inline-flex!important;
    grid-area:status!important;
    align-self:center!important;
    justify-self:end!important;
    min-width:82px!important;
    min-height:30px!important;
    align-items:center!important;
    justify-content:center!important;
    padding:5px 9px!important;
    font-size:.68rem!important;
    font-weight:900!important;
    text-transform:uppercase!important;
    letter-spacing:.035em!important;
  }
  .mobile-stock-table tr:not(.mobile-expanded) .col-alert{display:none!important}
  .mobile-stock-table tr.mobile-expanded .col-alert{
    grid-column:1/-1!important;
    grid-row:auto!important;
  }

  /* Le SDU du formulaire Entrée/Sortie reste visible dès le choix du produit. */
  #movementSduCard,
  #adjustmentStockCard{
    border-left:5px solid var(--primary)!important;
    padding:14px 15px!important;
    border-radius:14px!important;
    box-shadow:0 5px 15px rgba(15,23,42,.06)!important;
  }
  #movementSduCard span,
  #adjustmentStockCard span{
    font-size:.72rem!important;
    font-weight:900!important;
    letter-spacing:.055em!important;
    text-transform:uppercase!important;
  }
  #movementSduValue,
  #adjustmentStockValue{
    font-size:1.75rem!important;
    line-height:1!important;
    font-weight:950!important;
    letter-spacing:-.035em!important;
  }
}


/* =========================================================
   STOCK DISPONIBLE + SYNCHRONISATION RAPIDE — shell-31
   ========================================================= */
.sdu-mobile-progress{display:none}

@media(max-width:760px){
  /* Le thème reste disponible dans Paramètres ; la place de l'en-tête
     est réservée à l'action opérationnelle la plus utile. */
  #themeBtn{display:none!important}

  /* Bouton de synchronisation explicite et toujours visible. */
  #syncBtn{
    position:relative!important;
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    gap:6px!important;
    width:auto!important;
    min-width:78px!important;
    height:38px!important;
    min-height:38px!important;
    padding:0 11px!important;
    border:1px solid color-mix(in srgb,var(--primary) 35%,var(--border))!important;
    border-radius:12px!important;
    background:color-mix(in srgb,var(--primary) 10%,var(--card))!important;
    color:var(--primary-dark)!important;
    box-shadow:0 3px 10px rgba(15,23,42,.07)!important;
    font-size:0!important;
    font-weight:900!important;
    overflow:visible!important;
  }
  #syncBtn::before{
    content:"↻"!important;
    position:static!important;
    font-size:1.12rem!important;
    line-height:1!important;
    font-weight:950!important;
  }
  #syncBtn::after{
    content:"Sync"!important;
    position:static!important;
    font-size:.76rem!important;
    line-height:1!important;
    font-weight:900!important;
    letter-spacing:.01em!important;
  }
  #syncBtn.sync-pending{
    border-color:#f59e0b!important;
    background:#fff7e6!important;
    color:#9a5700!important;
  }
  #syncBtn.sync-pending::after{content:"Sync !"!important}
  #syncBtn.sync-pending > *{pointer-events:none}
  #syncBtn.sync-pending:before{color:#d97706!important}
  #syncBtn.sync-pending{box-shadow:0 0 0 3px rgba(245,158,11,.12)!important}
  #syncBtn.sync-ok{
    border-color:color-mix(in srgb,#059669 40%,var(--border))!important;
    background:color-mix(in srgb,#10b981 11%,var(--card))!important;
    color:#047857!important;
  }
  #syncBtn:disabled{opacity:.82!important;cursor:wait!important}
  #syncBtn:disabled::before{animation:cs-sync-spin .75s linear infinite!important}
  #syncBtn:disabled::after{content:"Envoi"!important}
  @keyframes cs-sync-spin{to{transform:rotate(360deg)}}
  body.dark #syncBtn.sync-pending{background:#3b2b12!important;color:#fbbf24!important;border-color:#92400e!important}
  body.dark #syncBtn.sync-ok{background:#102f27!important;color:#6ee7b7!important;border-color:#166534!important}

  /* Le stock disponible devient le premier point de lecture de la carte. */
  #view-medicines .mobile-stock-table .col-available.sdu-emphasis{
    grid-template-columns:minmax(0,1fr) auto!important;
    grid-template-areas:
      "label status"
      "main main"
      "reference reference"
      "progress progress"!important;
    min-height:126px!important;
    gap:5px 12px!important;
    margin-top:7px!important;
    padding:15px 16px 14px 18px!important;
    border-width:2px!important;
    border-left-width:6px!important;
    border-radius:16px!important;
    box-shadow:0 9px 22px rgba(15,23,42,.09)!important;
  }
  #view-medicines .mobile-stock-table .col-available.sdu-satisfactory{
    border-color:rgba(5,150,105,.42)!important;
    border-left-color:#059669!important;
    background:linear-gradient(145deg,rgba(16,185,129,.18),rgba(255,255,255,.92))!important;
  }
  #view-medicines .mobile-stock-table .col-available.sdu-necessary{
    border-color:rgba(245,158,11,.48)!important;
    border-left-color:#d97706!important;
    background:linear-gradient(145deg,rgba(245,158,11,.20),rgba(255,255,255,.94))!important;
  }
  #view-medicines .mobile-stock-table .col-available.sdu-urgent{
    border-color:rgba(239,68,68,.48)!important;
    border-left-color:#dc2626!important;
    background:linear-gradient(145deg,rgba(239,68,68,.19),rgba(255,255,255,.94))!important;
  }
  body.dark #view-medicines .mobile-stock-table .col-available.sdu-satisfactory{
    background:linear-gradient(145deg,rgba(5,150,105,.31),rgba(15,23,42,.92))!important;
  }
  body.dark #view-medicines .mobile-stock-table .col-available.sdu-necessary{
    background:linear-gradient(145deg,rgba(245,158,11,.29),rgba(15,23,42,.92))!important;
  }
  body.dark #view-medicines .mobile-stock-table .col-available.sdu-urgent{
    background:linear-gradient(145deg,rgba(239,68,68,.28),rgba(15,23,42,.92))!important;
  }
  .mobile-stock-table .sdu-mobile-label{
    color:var(--text)!important;
    font-size:.73rem!important;
    letter-spacing:.085em!important;
  }
  .mobile-stock-table .sdu-mobile-label em{
    display:inline-flex!important;
    margin-left:5px!important;
    padding:3px 6px!important;
    border-radius:999px!important;
    background:rgba(15,23,42,.08)!important;
    color:var(--muted)!important;
    font-size:.58rem!important;
    font-style:normal!important;
    letter-spacing:.04em!important;
    vertical-align:1px!important;
  }
  .mobile-stock-table .sdu-mobile-main{
    justify-content:flex-start!important;
    gap:9px!important;
    margin:2px 0 1px!important;
  }
  #view-medicines .mobile-stock-table .sdu-value{
    font-size:2.7rem!important;
    line-height:.96!important;
    letter-spacing:-.055em!important;
    text-shadow:0 1px 0 rgba(255,255,255,.45)!important;
  }
  .mobile-stock-table .sdu-unit{
    max-width:180px!important;
    font-size:.9rem!important;
    font-weight:850!important;
  }
  .mobile-stock-table .sdu-mobile-reference{
    margin-top:1px!important;
    font-size:.74rem!important;
    font-weight:750!important;
  }
  .mobile-stock-table .sdu-mobile-progress{
    display:block!important;
    grid-area:progress!important;
    width:100%!important;
    height:7px!important;
    margin-top:4px!important;
    overflow:hidden!important;
    border-radius:999px!important;
    background:rgba(15,23,42,.10)!important;
  }
  .mobile-stock-table .sdu-mobile-progress i{
    display:block!important;
    height:100%!important;
    min-width:3px!important;
    border-radius:inherit!important;
    background:currentColor!important;
  }
  .mobile-stock-table .sdu-satisfactory .sdu-mobile-progress{color:#059669!important}
  .mobile-stock-table .sdu-necessary .sdu-mobile-progress{color:#d97706!important}
  .mobile-stock-table .sdu-urgent .sdu-mobile-progress{color:#dc2626!important}
  .mobile-stock-table .sdu-mobile-status{
    min-width:88px!important;
    min-height:31px!important;
    font-size:.66rem!important;
  }
}

@media(max-width:365px){
  .page-heading h1{max-width:130px!important}
  .page-heading p{max-width:145px!important}
  #syncBtn{min-width:70px!important;padding:0 9px!important}
  #notificationBtn{width:34px!important;min-width:34px!important;height:34px!important}
}

/* =========================================================
   EN-TÊTE MOBILE : SYNC + NOTIFICATIONS + THÈME — shell-32
   Les trois raccourcis restent visibles en permanence.
   ========================================================= */
@media(max-width:760px){
  .topbar{
    display:grid!important;
    grid-template-columns:minmax(0,1fr) auto!important;
    align-items:center!important;
    min-height:68px!important;
    padding:9px 12px!important;
    column-gap:8px!important;
  }
  .topbar-main{
    min-width:0!important;
    overflow:hidden!important;
  }
  .page-heading{
    min-width:0!important;
    overflow:hidden!important;
  }
  .page-heading h1{
    max-width:none!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }
  .page-heading p{
    max-width:none!important;
    white-space:nowrap!important;
    overflow:hidden!important;
    text-overflow:ellipsis!important;
  }

  .top-actions{
    display:flex!important;
    align-items:center!important;
    justify-content:flex-end!important;
    flex-wrap:nowrap!important;
    flex:0 0 auto!important;
    gap:5px!important;
  }
  #networkStatus{display:none!important}

  /* Ordre opérationnel : synchroniser, consulter les alertes, changer le thème. */
  #syncBtn{order:1!important}
  .notification-wrap{order:2!important;position:relative!important}
  #themeBtn{order:3!important}

  #syncBtn{
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    gap:4px!important;
    width:auto!important;
    min-width:62px!important;
    height:38px!important;
    min-height:38px!important;
    padding:0 9px!important;
    border-radius:12px!important;
    font-size:0!important;
  }
  #syncBtn::before{
    content:"↻"!important;
    font-size:1.08rem!important;
    line-height:1!important;
  }
  #syncBtn::after{
    content:"Sync"!important;
    font-size:.71rem!important;
    line-height:1!important;
    font-weight:900!important;
  }
  #syncBtn.sync-pending::after{content:"Sync !"!important}
  #syncBtn:disabled::after{content:"…"!important}

  #notificationBtn,
  #themeBtn{
    display:inline-flex!important;
    align-items:center!important;
    justify-content:center!important;
    width:38px!important;
    min-width:38px!important;
    height:38px!important;
    min-height:38px!important;
    padding:0!important;
    border:1px solid var(--border)!important;
    border-radius:12px!important;
    background:var(--card-2)!important;
    color:var(--text)!important;
    box-shadow:none!important;
    font-size:1.02rem!important;
    line-height:1!important;
  }
  #notificationBtn:active,
  #themeBtn:active,
  #syncBtn:active{transform:scale(.95)!important}

  #notificationBtn{
    position:relative!important;
    overflow:visible!important;
  }
  #notificationCount{
    position:absolute!important;
    top:-5px!important;
    right:-5px!important;
    display:flex!important;
    align-items:center!important;
    justify-content:center!important;
    min-width:18px!important;
    height:18px!important;
    padding:0 4px!important;
    border:2px solid var(--card)!important;
    border-radius:999px!important;
    background:#dc2626!important;
    color:#fff!important;
    font-size:.59rem!important;
    line-height:1!important;
    font-weight:950!important;
    box-shadow:0 2px 6px rgba(220,38,38,.35)!important;
  }
  #notificationCount.hidden{display:none!important}

  /* Le panneau ne déborde plus du téléphone. */
  .notification-panel{
    position:fixed!important;
    top:66px!important;
    right:10px!important;
    left:10px!important;
    width:auto!important;
    max-width:420px!important;
    max-height:min(72vh,560px)!important;
    margin-left:auto!important;
    overflow:auto!important;
    border-radius:16px!important;
    z-index:1200!important;
  }

  body.dark #notificationBtn,
  body.dark #themeBtn{
    background:var(--card-2)!important;
    border-color:var(--border)!important;
    color:var(--text)!important;
  }
}

@media(max-width:390px){
  .topbar{padding-left:10px!important;padding-right:10px!important;column-gap:6px!important}
  .top-actions{gap:4px!important}
  #syncBtn{min-width:56px!important;padding:0 7px!important}
  #syncBtn::after{font-size:.66rem!important}
  #notificationBtn,#themeBtn{width:36px!important;min-width:36px!important;height:36px!important;min-height:36px!important}
  .page-heading h1{font-size:1rem!important}
  .page-heading p{font-size:.67rem!important}
}

@media(max-width:345px){
  /* Sur les écrans très étroits, l'icône de synchronisation reste visible
     tandis que son libellé est masqué pour préserver les trois raccourcis. */
  #syncBtn{width:36px!important;min-width:36px!important;padding:0!important}
  #syncBtn::after{display:none!important}
}


/* =========================================================
   CARTE COMMANDE NÉCESSAIRE + BOUTONS MODERNES — shell-33
   ========================================================= */
.header-action-icon{
  width:20px;
  height:20px;
  fill:none;
  stroke:currentColor;
  stroke-width:1.9;
  stroke-linecap:round;
  stroke-linejoin:round;
  pointer-events:none;
}

@media(max-width:760px){
  /* Toute la carte devient jaune uniquement pour le niveau “Nécessaire”.
     Le niveau Urgent conserve son repère rouge distinct. */
  #view-medicines .mobile-stock-table tbody tr.mobile-data-card.stock-status-necessary{
    border-color:rgba(217,119,6,.48)!important;
    background:
      radial-gradient(circle at 92% 6%,rgba(251,191,36,.22),transparent 34%),
      linear-gradient(145deg,#fff9df 0%,#fff4c4 100%)!important;
    box-shadow:0 8px 22px rgba(180,112,0,.11)!important;
  }
  #view-medicines .mobile-stock-table tbody tr.mobile-data-card.stock-status-necessary .col-name strong{
    color:#713f12!important;
  }
  #view-medicines .mobile-stock-table tbody tr.mobile-data-card.stock-status-necessary .col-actions{
    border-top-color:rgba(180,83,9,.18)!important;
  }
  body.dark #view-medicines .mobile-stock-table tbody tr.mobile-data-card.stock-status-necessary{
    border-color:rgba(245,158,11,.52)!important;
    background:
      radial-gradient(circle at 92% 6%,rgba(245,158,11,.18),transparent 38%),
      linear-gradient(145deg,#302713 0%,#251f14 100%)!important;
    box-shadow:0 9px 24px rgba(0,0,0,.22)!important;
  }
  body.dark #view-medicines .mobile-stock-table tbody tr.mobile-data-card.stock-status-necessary .col-name strong{
    color:#fde68a!important;
  }

  /* Boutons modernes : icônes vectorielles, relief doux et retour tactile. */
  #notificationBtn,
  #themeBtn{
    position:relative!important;
    isolation:isolate!important;
    width:40px!important;
    min-width:40px!important;
    height:40px!important;
    min-height:40px!important;
    border-radius:14px!important;
    overflow:visible!important;
    transition:transform .16s ease,box-shadow .16s ease,border-color .16s ease!important;
  }
  #notificationBtn::before,
  #themeBtn::before{
    content:""!important;
    position:absolute!important;
    inset:1px!important;
    z-index:-1!important;
    border-radius:12px!important;
    background:linear-gradient(150deg,rgba(255,255,255,.72),rgba(255,255,255,.08))!important;
    pointer-events:none!important;
  }
  #notificationBtn{
    border-color:color-mix(in srgb,var(--primary) 28%,var(--border))!important;
    background:linear-gradient(145deg,color-mix(in srgb,var(--primary) 15%,var(--card)),var(--card))!important;
    color:var(--primary-dark)!important;
    box-shadow:0 5px 14px rgba(7,94,84,.11),inset 0 1px 0 rgba(255,255,255,.7)!important;
  }
  #themeBtn{
    border-color:rgba(99,102,241,.25)!important;
    background:linear-gradient(145deg,#eef2ff,#faf5ff)!important;
    color:#4f46e5!important;
    box-shadow:0 5px 14px rgba(79,70,229,.12),inset 0 1px 0 rgba(255,255,255,.78)!important;
  }
  #themeBtn.theme-is-dark{
    border-color:rgba(245,158,11,.32)!important;
    background:linear-gradient(145deg,#fff7d6,#fff1b8)!important;
    color:#b45309!important;
  }
  #notificationBtn:hover,
  #themeBtn:hover{
    transform:translateY(-1px)!important;
  }
  #notificationBtn:active,
  #themeBtn:active{
    transform:scale(.93)!important;
    box-shadow:0 2px 7px rgba(15,23,42,.12)!important;
  }
  #notificationBtn:focus-visible,
  #themeBtn:focus-visible{
    outline:3px solid color-mix(in srgb,var(--primary) 24%,transparent)!important;
    outline-offset:2px!important;
  }
  #notificationBtn .header-action-icon,
  #themeBtn .header-action-icon{
    width:20px!important;
    height:20px!important;
    stroke-width:2!important;
    filter:drop-shadow(0 1px 0 rgba(255,255,255,.55));
  }
  body.dark #notificationBtn{
    border-color:rgba(45,212,191,.25)!important;
    background:linear-gradient(145deg,#173b38,#102c2a)!important;
    color:#5eead4!important;
    box-shadow:0 5px 15px rgba(0,0,0,.23),inset 0 1px 0 rgba(255,255,255,.06)!important;
  }
  body.dark #themeBtn,
  body.dark #themeBtn.theme-is-dark{
    border-color:rgba(250,204,21,.27)!important;
    background:linear-gradient(145deg,#3a3216,#2b2718)!important;
    color:#fde047!important;
    box-shadow:0 5px 15px rgba(0,0,0,.23),inset 0 1px 0 rgba(255,255,255,.05)!important;
  }
  body.dark #notificationBtn::before,
  body.dark #themeBtn::before{
    background:linear-gradient(150deg,rgba(255,255,255,.08),transparent)!important;
  }
}

@media(max-width:390px){
  #notificationBtn,#themeBtn{
    width:38px!important;
    min-width:38px!important;
    height:38px!important;
    min-height:38px!important;
    border-radius:13px!important;
  }
}

/* ===== shell-42 — administration des licences sur téléphone ===== */
@media (max-width: 700px){
  #licenseAdminPanel > .toolbar{
    display:grid!important;
    grid-template-columns:minmax(0,1fr)!important;
    gap:10px!important;
    align-items:stretch!important;
    overflow:visible!important;
  }

  #licenseAdminPanel > .toolbar > input,
  #licenseAdminPanel > .toolbar > select,
  #licenseAdminPanel > .toolbar > .cs-select,
  #licenseAdminPanel > .toolbar > .btn{
    grid-column:1 / -1!important;
    width:100%!important;
    min-width:0!important;
    max-width:none!important;
    margin:0!important;
  }

  #licenseAdminPanel #licenseStatusFilter + .cs-select-trigger,
  #licenseAdminPanel .cs-select--toolbar,
  #licenseAdminPanel .cs-select-trigger{
    width:100%!important;
    min-width:0!important;
    max-width:none!important;
  }

  #licenseAdminPanel #bulkActivateLicenses{
    min-height:50px!important;
    white-space:normal!important;
    line-height:1.25!important;
    padding:11px 14px!important;
  }
}


/* =========================================================
   shell-64 — Menu mobile plein écran + formulaire centre accessible
   ========================================================= */
@media(max-width:760px){
  /* Le tiroir doit recouvrir l'en-tête et la barre de navigation inférieure. */
  .sidebar{
    position:fixed!important;
    inset:0 auto 0 0!important;
    top:0!important;
    bottom:0!important;
    width:min(86vw,320px)!important;
    height:100vh!important;
    height:100dvh!important;
    max-height:100dvh!important;
    z-index:1400!important;
    padding:calc(14px + env(safe-area-inset-top,0px)) 14px calc(18px + env(safe-area-inset-bottom,0px))!important;
    overflow:hidden!important;
  }
  .sidebar.open{transform:translateX(0)!important}
  .sidebar-backdrop{
    z-index:1390!important;
    inset:0!important;
  }
  .sidebar-brand{
    flex:0 0 auto!important;
    padding:6px 8px 14px!important;
    margin-bottom:8px!important;
  }
  .sidebar nav{
    flex:1 1 auto!important;
    min-height:0!important;
    overflow-y:auto!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch!important;
    padding-bottom:18px!important;
  }
  body:has(.sidebar.open) .mobile-bottom-nav{
    z-index:70!important;
  }

  /* Fenêtre Centre : corps scrollable, boutons toujours visibles. */
  #centerAdminDialog.form-dialog{
    width:100%!important;
    max-width:none!important;
    height:100vh!important;
    height:100dvh!important;
    min-height:0!important;
    max-height:100dvh!important;
    margin:0!important;
    padding:0!important;
    border-radius:0!important;
    overflow:hidden!important;
  }
  #centerAdminDialog .center-admin-dialog{
    display:flex!important;
    flex-direction:column!important;
    width:100%!important;
    height:100%!important;
    min-height:0!important;
    max-height:100%!important;
    margin:0!important;
    padding:0!important;
    overflow:hidden!important;
    background:var(--card)!important;
  }
  #centerAdminDialog .center-admin-scroll{
    flex:1 1 0!important;
    min-height:0!important;
    overflow-x:hidden!important;
    overflow-y:auto!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch!important;
    padding:calc(14px + env(safe-area-inset-top,0px)) 16px 24px!important;
    background:var(--card)!important;
  }
  #centerAdminDialog .dialog-head{
    position:relative!important;
    top:auto!important;
    z-index:1!important;
    margin:0 0 15px!important;
    padding:0!important;
    border-bottom:0!important;
    background:transparent!important;
  }
  #centerAdminDialog .dialog-actions{
    position:relative!important;
    left:auto!important;
    right:auto!important;
    bottom:auto!important;
    flex:0 0 auto!important;
    display:grid!important;
    grid-template-columns:minmax(0,.8fr) minmax(0,1.2fr)!important;
    gap:10px!important;
    width:100%!important;
    margin:0!important;
    padding:11px 16px calc(11px + env(safe-area-inset-bottom,0px))!important;
    border-top:1px solid var(--border)!important;
    background:color-mix(in srgb,var(--card) 98%,transparent)!important;
    box-shadow:0 -8px 22px rgba(15,23,42,.08)!important;
    z-index:1450!important;
  }
  #centerAdminDialog .dialog-actions .btn{
    width:100%!important;
    min-width:0!important;
    min-height:48px!important;
    margin:0!important;
    padding:10px 8px!important;
  }
}
@media(max-width:380px){
  #centerAdminDialog .dialog-actions{grid-template-columns:1fr!important}
}
