/* ILC Sortie Stock — couche spécifique de la charte ILC Pro (après ilc-pro.css).
   Le tableau est une grille CSS (.thead / .row) dont les colonnes viennent de
   --grid-cols (corestock.js) ; sur mobile chaque ligne devient une carte. */

:root:not(#ilc-a):not(#ilc-b) body.ilc-pro.ilc-stock {

  & .appMain { height: calc(100dvh - var(--ilc-corporate-bar-height)); overflow-y: auto; }

  /* Icônes [data-ilc-icon] hydratées par ilc-icons.js */
  & [data-ilc-icon] { display: inline-flex; }
  & [data-ilc-icon] svg { width: 16px; height: 16px; }
  & .sideNav [data-ilc-icon] svg, & .sideFootActions [data-ilc-icon] svg { width: 17px; height: 17px; }
  & :is(.sideNav, .sideFootActions) [data-ilc-icon] { color: var(--ux-muted); }
  & .sideNav .is-active [data-ilc-icon] { color: var(--ux-brand-text); }
  & .btn [data-ilc-icon] { color: var(--ux-brand-text); }
  & :is(.btn.primary, .btn.danger) [data-ilc-icon] { color: inherit; }

  /* Barre filtres + actions de sélection */
  & .stockToolbar {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }
  & .stockToolbar .filterGroup { display: flex !important; align-items: center; gap: 8px !important; flex-wrap: wrap; margin: 0 !important; }
  & .select-field {
    position: relative;
    display: inline-flex !important;
    align-items: center;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: none !important;
    box-shadow: none !important;
  }
  & .select-field > [data-ilc-icon] {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ux-muted);
    pointer-events: none;
    z-index: 1;
  }
  & .select-field > [data-ilc-icon] svg { width: 15px; height: 15px; }
  & .select-field select { min-height: 34px !important; height: 34px; padding: 0 30px 0 33px !important; font-size: 13px !important; font-weight: 500 !important; }
  & .stockToolbar .btn { min-height: 34px !important; font-size: 13px !important; padding: 0 12px !important; }
  & .stockToolbar .chip { min-height: 30px; }
  & .stockToolbar .chip [data-ilc-icon] { display: none; }

  /* Tableau */
  & .tableWrap {
    flex: 1 1 auto;
    min-height: 320px;
    display: flex !important;
    flex-direction: column;
    margin: 0 !important;
    overflow: auto !important;
  }
  & .thead {
    position: sticky;
    top: 0;
    z-index: 2;
    min-height: 40px;
    align-items: center;
    padding: 0 12px !important;
    border-bottom: 1px solid var(--ux-border) !important;
    background: var(--ux-surface-2) !important;
    color: var(--ux-muted) !important;
    font: 600 11.5px/1.3 var(--ux-font) !important;
    letter-spacing: .04em !important;
    text-transform: uppercase;
    box-shadow: none !important;
  }
  & .thead .th, & .thead > div { color: var(--ux-muted) !important; background: transparent !important; border: 0 !important; }
  & .colResizer { background: transparent !important; }
  & .thead > div:hover .colResizer { background: var(--ux-border-strong) !important; }
  & .tbody { flex: 1 1 auto; max-height: none !important; overflow: visible !important; background: transparent !important; }
  /* 10 colonnes : largeur minimale commune à l'en-tête et aux lignes,
     le cadre défile horizontalement (sinon Matériel(s) est écrasé) */
  & .tableWrap > :is(.thead, .tbody) { min-width: 1740px; }

  /* Notifications en bas à droite : ne masquent plus les actions d'en-tête */
  & .toastHost { top: auto !important; bottom: calc(16px + var(--ux-safe-b)) !important; right: 16px !important; }

  & .groupHead {
    position: sticky;
    top: 40px;
    z-index: 1;
    padding: 8px 14px !important;
    border-bottom: 1px solid var(--ux-border) !important;
    background: var(--ux-surface-2) !important;
    color: var(--ux-text-2) !important;
    font: 600 12px/1.3 var(--ux-font) !important;
    letter-spacing: .02em !important;
    text-transform: none !important;
    box-shadow: none !important;
  }

  & .row {
    min-height: 50px;
    align-items: center;
    padding: 6px 12px !important;
    border: 0 !important;
    border-bottom: 1px solid var(--ux-border) !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: 0 !important;
    color: var(--ux-text) !important;
    cursor: pointer;
    transition: background-color .12s var(--ux-ease);
  }
  & .row::before {
    width: 3px !important;
    top: 8px !important;
    bottom: 8px !important;
    border-radius: 0 3px 3px 0;
    background: var(--ux-orange) !important;
    box-shadow: none !important;
  }
  & .row.processed::before { background: var(--ux-green) !important; }
  & .row:hover { background: var(--ux-surface-2) !important; }
  & .row.selected { background: var(--ux-brand-soft) !important; box-shadow: inset 0 0 0 1px var(--ux-brand-ring) !important; }
  & .row.selected::after { box-shadow: none !important; }

  & .cell { color: var(--ux-text) !important; font-size: 13.5px !important; font-weight: 400 !important; padding-right: 12px; text-shadow: none !important; }
  & .cell.muted { color: var(--ux-text-2) !important; font-size: 13px !important; }
  & .cell[data-key="client"] { font-weight: 600 !important; }
  & .cell[data-key="id"], & .cell[data-key="pn"], & .cell[data-key="sn"] { font-family: var(--ux-mono) !important; font-size: 12.5px !important; }

  & .cell .badge.todo { --c: var(--ux-orange); }
  & .cell .badge.done { --c: var(--ux-green); }
  & .cell .badge.todo, & .cell .badge.done {
    border-color: color-mix(in srgb, var(--c) 35%, transparent) !important;
    background: color-mix(in srgb, var(--c) 13%, transparent) !important;
    color: var(--c) !important;
  }
  & .cell .badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

  /* Modales : grille de formulaire, champs à icône */
  & .formGrid { gap: 14px !important; }
  & .control .ico { right: 12px !important; color: var(--ux-muted) !important; opacity: 1 !important; filter: none !important; }
  & .control input, & .control select, & .control textarea { padding-right: 38px !important; }
  & .sn-editor { gap: 8px; }
  & .sn-hint { color: var(--ux-muted) !important; }
  & .sn-error { color: var(--ux-red) !important; }
}

/* ---------- Mobile (Android / iOS) : lignes en cartes ---------- */
@media (max-width: 760px) {
  :root:not(#ilc-a):not(#ilc-b) body.ilc-pro.ilc-stock {
    & .appMain { height: auto; overflow: visible; }
    & .headerActions { margin-left: auto; }
    & .lblHideSm { display: none; }
    & .stockToolbar, & .stockToolbar .filterGroup { width: 100%; }
    & .select-field { flex: 1 1 100%; }
    & .select-field select { width: 100%; min-height: 44px !important; height: 44px; }
    & .stockToolbar .selectionActions { display: grid !important; grid-template-columns: 1fr 1fr; }
    & .stockToolbar .selectionActions #btnResetCols { display: none; }
    & .stockToolbar .selectionActions .btn { width: 100%; padding: 0 8px !important; }
    & .stockToolbar .chip { flex: 1 1 0; width: auto !important; justify-content: center; }

    & .tableWrap { overflow: visible !important; border: 0 !important; background: transparent !important; min-height: 0; }
    & .tableWrap > :is(.thead, .tbody) { min-width: 0; }
    & .toastHost { left: 12px !important; right: 12px !important; }
    & .thead { display: none !important; }
    & .tbody { display: flex; flex-direction: column; gap: 10px; }
    & .groupHead { position: static; margin-top: 4px; border: 0 !important; background: transparent !important; padding: 4px 2px !important; color: var(--ux-muted) !important; text-transform: uppercase; letter-spacing: .05em !important; font-size: 11.5px !important; }

    & .row {
      display: grid !important;
      grid-template-columns: 1fr auto !important;
      gap: 6px 12px;
      padding: 12px 14px 12px 16px !important;
      border: 1px solid var(--ux-border) !important;
      border-radius: var(--ux-r-lg) !important;
      background: var(--ux-surface) !important;
      box-shadow: var(--ux-shadow-sm) !important;
      position: relative;
      width: 100% !important;
      min-width: 0 !important;
      max-width: 100% !important;
    }
    & .row.selected { background: var(--ux-brand-soft) !important; }
    & .row .cell { order: 5; grid-column: 1 / -1; padding: 0 !important; white-space: normal !important; overflow: visible !important; text-align: left !important; }
    & .row .cell:empty { display: none; }
    & .row .cell[data-key="material"] { order: 1; grid-column: 1; font-weight: 600 !important; font-size: 14.5px !important; }
    & .row .cell[data-key="state"] { order: 2; grid-column: 2; justify-self: end; }
    & .row .cell[data-key="client"] { order: 3; font-weight: 500 !important; color: var(--ux-text-2) !important; }
    & .row .cell[data-key="id"] { display: none; }
    & .row .cell:is([data-key="pn"], [data-key="sn"], [data-key="qty"], [data-key="date"], [data-key="tech"], [data-key="comment"])::before {
      display: inline-block;
      min-width: 92px;
      color: var(--ux-muted);
      font: 500 12px/1.4 var(--ux-font);
      text-transform: none;
    }
    & .row .cell[data-key="pn"]::before { content: "P/N"; }
    & .row .cell[data-key="sn"]::before { content: "S/N"; }
    & .row .cell[data-key="qty"]::before { content: "Quantité"; }
    & .row .cell[data-key="date"]::before { content: "Sortie le"; }
    & .row .cell[data-key="tech"]::before { content: "Technicien"; }
    & .row .cell[data-key="comment"]::before { content: "Commentaire"; }
    & .formGrid { grid-template-columns: 1fr !important; }
  }
}

/* Scanner d'étiquettes : résultat modifiable, origine de chaque valeur, alternatives */
:root:not(#ilc-a):not(#ilc-b):not(#ilc-c) body.ilc-pro.ilc-stock {
  & .scanField {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px 12px;
    border: 1px solid var(--ux-border-strong) !important;
    background: var(--ux-surface-2) !important;
  }
  & .scanField .sfHead { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  & .scanField .sfLabel { min-width: 0; color: var(--ux-muted) !important; }
  & .scanField .sfInput {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    border: 1px solid var(--ux-border-strong);
    border-radius: 10px;
    background: var(--ux-surface);
    color: var(--ux-text);
    font: 600 15px/1.3 ui-monospace, "Cascadia Code", "SFMono-Regular", Menlo, monospace;
    letter-spacing: .02em;
  }
  & .scanField .sfInput:focus { outline: 2px solid var(--ux-brand-ring); outline-offset: 1px; border-color: var(--ux-brand); }
  & .scanField.empty .sfInput { border-style: dashed; }
  & .sfSource {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid transparent;
    font: 600 11px/1.5 var(--ux-font);
    white-space: nowrap;
  }
  & .sfSource.is-sure { color: var(--ux-green); background: var(--ux-green-bg); border-color: var(--ux-green-bd); }
  & .sfSource.is-check { color: var(--ux-orange); background: var(--ux-orange-bg); border-color: var(--ux-orange-bd); }
  & .sfSource.is-missing { color: var(--ux-muted); background: var(--ux-surface-3); border-color: var(--ux-border); }
  & .sfAlts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; color: var(--ux-muted); font: 500 12px/1.4 var(--ux-font); }
  & .sfAlt {
    min-height: 30px;
    padding: 3px 10px;
    border: 1px solid var(--ux-border-strong);
    border-radius: 999px;
    background: var(--ux-surface);
    color: var(--ux-text-2);
    font: 600 12px/1.3 ui-monospace, "Cascadia Code", Menlo, monospace;
    cursor: pointer;
  }
  & .sfAlt:hover { border-color: var(--ux-brand); color: var(--ux-brand-text); }
  & .scanNotice {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--ux-orange-bd);
    background: var(--ux-orange-bg);
    color: var(--ux-orange);
    font: 600 12.5px/1.4 var(--ux-font);
  }
  & .scanBarcodes { display: flex; align-items: center; gap: 6px; color: var(--ux-muted); font: 500 12px/1.4 var(--ux-font); }
  & #btnScanTorch[aria-pressed="true"] { border-color: var(--ux-yellow-bd); background: var(--ux-yellow-bg); color: var(--ux-yellow); }
  & #btnScanTorch[hidden] { display: none !important; }
  & :is(.scanNotice, .scanBarcodes, .scanRawToggle summary) [data-ilc-icon] svg,
  & :is(.scanNotice, .scanBarcodes, .scanRawToggle summary) svg { width: 14px; height: 14px; flex: 0 0 auto; }
}
@media (max-width: 520px) {
  :root:not(#ilc-a):not(#ilc-b):not(#ilc-c) body.ilc-pro.ilc-stock .scanField .sfInput { font-size: 16px; }
}
