/* ═══════════════════════════════════════════════════════════
   DTISoft — Fiche document Journal Stock (INV / MVT / ...)
   ═══════════════════════════════════════════════════════════ */

/* D44 (2026-10-28) : plan d'affichage 9500, comme la fiche transfert (.tr-overlay) — au-dessus des fiches document (8000),
   sous les fiches article / tiers (9600, F7 depuis cette fiche) et sous les choix / fenêtres de la fiche (choix d'article
   11000, choix d'emplacement 9550 ou plan de la fiche + 1, fenêtres D22 plan de la fiche + 2, DTIDialog 20000). Ouverte depuis
   une autre fiche, elle passe devant (Echeancier.openAbove abaisse l'ouvreur ; à plan égal, la dernière posée est devant).
   Avant : 1000 — elle passait DERRIÈRE toute fiche entre 8000 et 9600 restée ouverte (cohérence DTIOverlay, modal-utils.js :
   le premier plan se juge au plan d'affichage calculé). Le rapport d'écarts d'inventaire se met à 900 pour passer dessous. */
.sd-overlay {
    position: fixed; inset: 0; z-index: 9500;
    background: rgba(0,0,0,.45);
    display: flex; align-items: stretch; justify-content: stretch;
}
.sd-panel {
    margin: 0; flex: 1; background: white;
    display: flex; flex-direction: column; overflow: hidden;
}

/* ── Header overlay (titre + boutons) ─────────────────────── */
.sd-header {
    display: flex; align-items: center; gap: 12px;
    padding: 8px 14px; background: var(--gray-100);
    border-bottom: 1px solid var(--gray-300);
}
.sd-title { font-weight: 600; font-size: 14px; color: var(--gray-900); flex: 1; }
.sd-title-pdv {
    background: #2563eb; color: white; padding: 2px 8px;
    border-radius: 4px; font-size: 11px; margin-left: 8px;
}
.sd-header button { background: var(--gray-600); color: white; border: 0; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.sd-header button:hover { background: var(--gray-700); }
.sd-pj-btn { background: var(--gray-600); }
/* Étiquettes (2026-10-01, remplace l'ancien bouton « à venir ») : désactivé tant que le document n'est pas enregistré. */
.sd-etiq-btn { background: var(--gray-500); }
.sd-header .sd-etiq-btn:disabled { opacity: .5; cursor: not-allowed; }
.sd-header .sd-etiq-btn:disabled:hover { background: var(--gray-500); }
.sd-save-btn { background: #2563eb !important; }
.sd-save-btn:hover { background: #1d4ed8 !important; }
.sd-save-btn-saved { background: var(--gray-400) !important; cursor: default !important; }
.sd-save-btn-saved:hover { background: var(--gray-400) !important; }
.sd-winctrls { display: flex; gap: 4px; }
.sd-winbtn { background: transparent !important; color: var(--gray-700) !important; padding: 6px 10px !important; }
.sd-winbtn:hover { background: rgba(0,0,0,.08) !important; }
.sd-close-btn:hover { background: #dc2626 !important; color: white !important; }

/* ── Contenu ───────────────────────────────────────────── */
.sd-content { flex: 1; overflow: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 12px; }

.sd-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.sd-fld { display: flex; flex-direction: column; gap: 2px; }
.sd-fld label { font-size: 11px; color: var(--gray-600); font-weight: 500; }
.sd-fld input, .sd-fld textarea, .sd-fld select {
    padding: 4px 8px; border: 1px solid var(--gray-300); border-radius: 4px;
    font-size: 12px; background: white;
}
.sd-fld input:focus, .sd-fld textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
.sd-fld input[readonly] { background: var(--gray-50); color: var(--gray-700); cursor: default; }

/* ── Grid items ────────────────────────────────────────── */
.sd-grid-wrap { flex: 1; overflow: auto; border: 1px solid var(--gray-200); border-radius: 4px; min-height: 240px; }
.sd-grid { width: 100%; border-collapse: collapse; font-size: 12px; background: white; }
.sd-grid th, .sd-grid td { padding: 4px 6px; border-bottom: 1px solid var(--gray-200); border-right: 1px solid var(--gray-200); text-align: left; vertical-align: middle; }
.sd-grid th:last-child, .sd-grid td:last-child { border-right: 0; }
.sd-grid input, .sd-grid select { text-align: left; }
.sd-grid .sd-r, .sd-grid .sd-r input, .sd-grid .sd-th-r { text-align: right; }
.sd-grid .sd-td-num, .sd-grid .sd-td-c, .sd-grid .sd-th-num, .sd-grid .sd-th-c { text-align: center; }
.sd-grid th {
    background: var(--gray-100); color: var(--gray-700);
    font-weight: 600; font-size: 11px;
    position: sticky; top: 0; z-index: 1;
}
.sd-th-num { width: 32px; text-align: center; }
.sd-th-c { width: 24px; text-align: center; }
.sd-th-ref { width: 140px; }
.sd-th-lib { min-width: 200px; }
.sd-th-r { text-align: right; }
.sd-th-def { color: var(--gray-500); font-style: italic; }

.sd-td-num { text-align: center; color: var(--gray-500); font-size: 11px; cursor: pointer; user-select: none; background: var(--gray-50); }
.sd-td-num:hover { background: var(--gray-200); }
.sd-td-c { text-align: center; }
.sd-td-r { text-align: right; }
.sd-td-ref { width: 140px; }
.sd-td-lib { min-width: 200px; }
.sd-td-def { color: var(--gray-500); font-style: italic; background: var(--gray-50); }
.sd-td-ro { background: var(--gray-50); color: var(--gray-700); }

.sd-cell-inp {
    width: 100%; min-width: 0; box-sizing: border-box;
    padding: 2px 4px; border: 1px solid transparent;
    border-radius: 2px; font-size: 12px; background: transparent;
}
.sd-cell-inp:hover { border-color: var(--gray-300); background: white; }
.sd-cell-inp:focus { outline: none; border-color: #2563eb; background: white; box-shadow: inset 0 0 0 1px rgba(37,99,235,.2); }
.sd-cell-inp.sd-r { text-align: right; }

.sd-ref-wrap { position: relative; display: flex; }
.sd-cell-ref { padding-right: 22px; }
.sd-ref-arrow { position: absolute; right: 0; top: 0; bottom: 0; padding: 0 6px; background: transparent; border: 0; color: var(--gray-500); cursor: pointer; }
.sd-ref-arrow:hover { background: var(--gray-200); }

.sd-diff-pos { color: #16a34a; font-weight: 600; }
.sd-diff-neg { color: #dc2626; font-weight: 600; }

.sd-row-sel td { background: rgba(59, 130, 246, .12) !important; }
.sd-new-row .sd-td-num { color: var(--gray-300); }

/* Flash de mise en évidence d'une ligne ciblée (ouverture depuis le rapport
   d'écarts inventaire : scroll + surlignage temporaire ambre). */
.sd-row-flash td { animation: sd-row-flash 2.6s ease-out; }
@keyframes sd-row-flash {
    0%, 25% { background: rgba(245, 158, 11, .50); }
    100%    { background: transparent; }
}

/* ── Footer fiche ──────────────────────────────────────── */
.sd-footer {
    border-top: 1px solid var(--gray-300); background: var(--gray-50);
    padding: 10px 14px; display: flex; flex-direction: column; gap: 8px;
}
.sd-footer-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.sd-foot-totals { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--gray-700); }
.sd-foot-totals strong { color: var(--gray-900); font-size: 14px; }
.sd-foot-totals i { margin-right: 6px; color: var(--gray-500); }
.sd-foot-audit { font-size: 11px; color: var(--gray-500); }
.sd-foot-audit strong { color: var(--gray-700); font-weight: 600; }

/* ── Picker article popup ──────────────────────────────── */
.sd-picker-overlay {
    position: fixed; inset: 0; z-index: 9550;   /* D44 : au-dessus de la fiche (9500) — avant 1100 */
    background: rgba(0,0,0,.5);
    display: flex; align-items: center; justify-content: center;
}
.sd-picker-panel { background: white; border-radius: 6px; width: 1100px; max-width: 95vw; height: 80vh; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.sd-picker-x {
    position: absolute; top: 6px; right: 6px; z-index: 10;
    background: var(--gray-700); color: white; border: 0;
    width: 32px; height: 32px; border-radius: 4px;
    cursor: pointer; font-size: 14px;
    display: inline-flex; align-items: center; justify-content: center;
}
.sd-picker-x:hover { background: #dc2626; }
.sd-picker-bar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 14px; background: #eff6ff; color: #1e40af;
    border-bottom: 1px solid var(--gray-200); font-size: 13px;
}
.sd-picker-bar i.fa-info-circle { margin-right: 6px; }
.sd-picker-close {
    background: var(--gray-600); color: white; border: 0;
    padding: 5px 12px; border-radius: 4px; cursor: pointer; font-size: 12px;
    display: inline-flex; align-items: center; gap: 6px;
}
.sd-picker-close:hover { background: #dc2626; }
.sd-picker-content { flex: 1; overflow: hidden; }

/* ── Context menu ──────────────────────────────────────── */
.sd-ctx-menu {
    position: fixed; z-index: 9560;   /* D44 : au-dessus de la fiche (9500) ; le script le pose de toute façon à plan de la fiche + 1 — avant 1500 */
    background: white; border: 1px solid var(--gray-300); border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    padding: 4px 0; min-width: 180px;
}
.sd-ctx-menu button {
    display: flex; align-items: center; gap: 8px; width: 100%;
    background: transparent; border: 0; padding: 8px 14px; text-align: left;
    cursor: pointer; font-size: 12px; color: var(--gray-700);
}
.sd-ctx-menu button:hover:not(:disabled) { background: var(--gray-100); }
.sd-ctx-menu button:disabled { color: var(--gray-400); cursor: not-allowed; }
.sd-ctx-menu .sd-ctx-danger { color: #dc2626; }
.sd-ctx-menu .sd-ctx-danger:hover:not(:disabled) { background: #fee2e2; }

/* ── Searchable select inline (Casier/Stock/NumLot) ─────────── */
.sd-ss { position: relative; display: block; width: 100%; }
.sd-ss-inp { width: 100%; }
.sd-ss-list {
    position: absolute; left: 0; top: 100%; margin: 0; padding: 4px 0;
    list-style: none; background: white;
    border: 1px solid var(--gray-300); border-radius: 4px;
    box-shadow: 0 6px 16px rgba(0,0,0,.18);
    max-height: 240px; overflow-y: auto;
    min-width: 180px; width: max-content; max-width: 360px;
    z-index: 200; font-size: 12px; text-align: left;
}
.sd-ss-opt {
    padding: 5px 10px; cursor: pointer; white-space: nowrap;
    border-bottom: 1px solid var(--gray-100);
}
.sd-ss-opt:last-child { border-bottom: 0; }
.sd-ss-opt:hover { background: #eff6ff; }
.sd-ss-opt[hidden] { display: none; }
.sd-ss-opt strong { color: var(--gray-900); }
.sd-ss-hint { color: var(--gray-500); font-size: 11px; margin-left: 6px; }

/* ── Casier picker popup (popup multi-casiers) ───────────── */
.sd-cp-overlay { z-index: 9550; }   /* D44 : au-dessus de la fiche (9500) ; le script pose max(1150, plan de la fiche + 1) — avant 1150 */
.sd-cp-panel {
    background: white; border-radius: 6px; padding: 0;
    width: 680px; max-width: 92vw; max-height: 80vh; overflow: auto;
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.sd-cp-header {
    padding: 14px 18px; border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; justify-content: space-between;
    font-size: 15px;
}
.sd-cp-close { background: transparent; border: 0; padding: 4px 10px; cursor: pointer; color: var(--gray-700); }
.sd-cp-close:hover { background: var(--gray-200); border-radius: 4px; }
.sd-cp-pick {
    background: #16a34a; color: white; border: 0; padding: 4px 10px;
    border-radius: 4px; cursor: pointer; font-size: 12px;
    display: inline-flex; align-items: center; gap: 6px;
}
.sd-cp-pick:hover { background: #15803d; }

/* ── Mode minimisé : cacher boutons non essentiels du header ─── */
/* .sd-dup-btn (Dupliquer, 2026-10-02) : la pastille ne garde que titre + minimiser + fermer (§7.43). */
.dti-minimized .sd-pj-btn,
.dti-minimized .sd-etiq-btn,
.dti-minimized .sd-preview-btn,
.dti-minimized .sd-docprint-btn,
.dti-minimized .sd-email-btn,
.dti-minimized .sd-dup-btn,
.dti-minimized .sd-save-btn { display: none !important; }
/* Bouton Dupliquer désactivé (document non enregistré) : style porté par la feuille, plus en ligne. */
.sd-header .sd-dup-btn:disabled { opacity: .5; cursor: not-allowed; }
.dti-minimized .sd-header {
    padding: 6px 8px !important;
    gap: 4px !important;
    cursor: pointer;
}
.dti-minimized .sd-title { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dti-minimized .sd-title-pdv { display: none; }

/* ── Column drag (reorder) ─────────────────────────────────── */
.sd-grid thead th.sd-th-draggable     { cursor: grab; position: relative; }
.sd-grid thead th.sd-th-draggable:active { cursor: grabbing; }
.sd-grid thead th.sd-th-dragging      { opacity: .45; }
.sd-grid thead th.sd-th-drop-target   { box-shadow: inset 3px 0 0 0 #2563eb; }

/* ── Column resize grip ────────────────────────────────────── */
.sd-grid thead th.sd-th-resizable { position: relative; }
.sd-th-resize-grip {
    position: absolute; top: 0; right: -5px; width: 10px; height: 100%;
    cursor: col-resize; user-select: none; z-index: 2;
}
.sd-th-resize-grip:hover { background: rgba(37,99,235,.25); }
.sd-th-resize-grip:active { background: rgba(37,99,235,.4); }

/* ═══════════════════════════════════════════════════════════
   D22 (2026-10-19) — une ligne par article × emplacement, heure de chaque comptage, fenêtres « Ajouter / Remplacer /
   Ignorer ». Les styles VITAUX des fenêtres (.sd-dbl-overlay : position, fond, z-index, panneau) sont EN LIGNE dans
   stockdoc-detail.js (fenêtre modale et visible même avec cette feuille périmée en cache) ; ici : l'apparence.
   Couleurs par variables locales (thème : redéfinir --sd-* sur .sd-overlay / .sd-dbl-overlay).
   ═══════════════════════════════════════════════════════════ */
.sd-overlay, .sd-dbl-overlay {
    --sd-alerte: #dc2626; --sd-alerte-fond: #fef2f2; --sd-alerte-bord: #fecaca;
    --sd-attention: #b45309; --sd-attention-fond: #fffbeb;
    --sd-info: var(--gray-500, #64748b); --sd-accent: #2563eb;
}

/* Bandeau des messages du serveur / contrôles (TEXTE BRUT, retours à la ligne gardés) */
.sd-bandeau {
    white-space: pre-line; padding: 8px 12px; border-radius: 4px; font-size: 12px; line-height: 1.45;
    background: var(--sd-alerte-fond); color: #7f1d1d; border: 1px solid var(--sd-alerte-bord);
}
.sd-bandeau[hidden] { display: none; }

/* En-tête INV : « Heure » du comptage */
.sd-fld-heure input[type="time"] { min-width: 90px; }
.sd-heure-mention { font-size: 10px; color: var(--sd-info); font-style: italic; }

/* Colonnes d'information (N° série, Compté à) : lecture seule */
.sd-grid .sd-th-info { color: var(--gray-500, #64748b); font-weight: 500; }
.sd-grid .sd-td-info { color: var(--gray-600, #475569); background: var(--gray-50, #f8fafc); font-size: 11px; white-space: nowrap; }

/* Lignes : doublon à regrouper (contour rouge), doublon DPIFac hérité (pastille), quantité à saisir */
.sd-grid tr.sd-row-dbl td { box-shadow: inset 0 2px 0 0 var(--sd-alerte), inset 0 -2px 0 0 var(--sd-alerte); }
.sd-grid tr.sd-row-dbl td:first-child { box-shadow: inset 2px 2px 0 0 var(--sd-alerte), inset 0 -2px 0 0 var(--sd-alerte); }
.sd-grid tr.sd-row-dbl-herite .sd-td-num { position: relative; }
.sd-grid tr.sd-row-dbl-herite .sd-td-num::after {
    content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%;
    background: var(--sd-attention);
}
.sd-grid tr.sd-row-qu-requise td[data-col-id="qu"] { background: var(--sd-attention-fond); box-shadow: inset 0 0 0 1px var(--sd-attention); }

/* Choix de l'emplacement : stock attendu, « déjà compté », casier de la fiche */
.sd-cp-note { font-size: 10px; font-weight: 400; color: var(--sd-info); margin-top: 2px; white-space: normal; }
.sd-cp-deja { color: var(--sd-attention); }
.sd-cp-fiche td { background: #eff6ff; }
.sd-cp-fiche .sd-cp-pick { background: var(--sd-accent); }

/* Fenêtres de la fiche (compléments d'apparence) */
.sd-dbl-panel { font-family: inherit; }
.sd-dbl-titre { color: #0f172a; }
.sd-dbl-file { text-transform: none; letter-spacing: .02em; }
.sd-dbl-ligne { color: #1e293b; }
.sd-dbl-champ input:focus { outline: none; border-color: var(--sd-accent); box-shadow: 0 0 0 2px rgba(37,99,235,.2); }
.sd-dbl-btns .sd-dbl-btn:focus-visible { outline: 2px solid var(--sd-accent); outline-offset: 2px; }
.sd-dbl-btns .sd-dbl-btn:not(:disabled):hover { filter: brightness(.95); }
.sd-dbl-aide { border-top: 1px solid var(--gray-200, #e2e8f0); padding-top: 8px; }
