/* ═══════════════════════════════════════════════════════════
   DTISoft — Remise Detail Popup
   ═══════════════════════════════════════════════════════════ */

.rd-overlay {
    position: fixed; inset: 0; z-index: 8000;
    background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center;
}
.rd-panel {
    background: var(--white); border-radius: 6px;
    width: 95vw; height: 85%; max-width: none;   /* 2026-11-03 (demande utilisateur) : 95 % de l'écran (avant : 92 %, au plus 1400 px) */
    box-shadow: 0 12px 48px rgba(0,0,0,.3);
    display: flex; flex-direction: column; overflow: hidden;
}
.rd-loading { padding: 40px; text-align: center; font-size: 14px; color: var(--gray-500); }

/* ── Header ──────────────────────────────────────────────── */
.rd-header {
    padding: 8px 14px; display: flex; align-items: center; gap: 10px;
    background: var(--gray-50); border-bottom: 1px solid var(--gray-200);
}
.rd-title { font-weight: 700; font-size: 14px; flex: 1; display: flex; align-items: center; gap: 6px; }
.rd-save-btn {
    border: 1px solid #222; background: #222; color: #fff; border-radius: 4px;
    padding: 4px 14px; cursor: pointer; font-size: 12px; font-weight: 600;
    display: flex; align-items: center; gap: 5px;
}
.rd-save-btn:hover { background: #444; }
.rd-close-btn { border: none; background: none; cursor: pointer; font-size: 16px; color: var(--gray-500); padding: 2px 6px; }
.rd-close-btn:hover { color: var(--gray-800); }
.rd-min-btn { border: none; background: none; cursor: pointer; font-size: 12px; color: var(--gray-500); padding: 2px 6px; }
.rd-min-btn:hover { color: var(--gray-800); }

/* ── Content ─────────────────────────────────────────────── */
.rd-content { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }

/* ── Header fields ───────────────────────────────────────── */
.rd-fields { padding: 8px 12px; border-bottom: 1px solid var(--gray-200); }
.rd-fields-row { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 6px; }
.rd-fields-row:last-child { margin-bottom: 0; }
.rd-fld { display: flex; flex-direction: column; gap: 1px; }
.rd-fld label { font-size: 10px; color: var(--gray-500); white-space: nowrap; }
.rd-fld input, .rd-fld select {
    border: 1px solid var(--gray-200); border-radius: 2px;
    padding: 3px 6px; font-size: 13px; font-family: inherit;
    background: var(--white); color: var(--gray-700);
    height: 26px; box-sizing: border-box;
}
.rd-fld-lg { flex: 1; min-width: 0; }
.rd-fld-chk { justify-content: flex-end; }
.rd-chk { font-size: 12px; color: var(--gray-600); display: flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }

/* ── Grid ────────────────────────────────────────────────── */
.rd-grid-wrap { flex: 1; overflow: auto; min-height: 0; }
.rd-grid { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 12px; }
.rd-grid th {
    background: var(--gray-100); padding: 4px 6px;
    text-align: left; font-weight: 600; font-size: 11px;
    color: var(--gray-600); border-bottom: 1px solid var(--gray-200);
    white-space: nowrap; position: sticky; top: 0;
    z-index: 3;   /* 2026-11-03 : en-tête figé AU-DESSUS des cellules qui défilent (champs, listes) */
}
.rd-grid td {
    padding: 1px 3px; border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}
.rd-grid tbody tr:hover { background: var(--blue-pale); }
.rd-th-num { width: 30px; text-align: center; }
.rd-th-r { text-align: right; }
.rd-td-num { text-align: center; color: var(--gray-400); font-size: 11px; }
.rd-td-r { text-align: right; }
.rd-td-c { text-align: center; }

/* ── Editable cells ──────────────────────────────────────── */
.rd-cell-inp {
    border: none; background: #f0f7ff; font-size: 12px; font-family: inherit;
    color: inherit; padding: 1px 4px; width: 100%; box-sizing: border-box;
    outline: none; height: 22px; border-bottom: 1px solid #d0e3f7;
}
.rd-cell-inp:hover { background: #e3f0ff; }
.rd-cell-inp:focus { background: #fffde7; border-bottom-color: var(--primary); }
.rd-cell-inp.rd-r { text-align: right; }
/* Formule P.U. non calculable : le champ le DIT. Sans ce signal, l'erreur
   n'apparaissait qu'au moment où un document se facturait au prix brut — les
   moteurs replient silencieusement dessus quand la formule n'est pas évaluable. */
.rd-cell-inp.rd-cell-ko { background: #fef2f2; color: #b91c1c; border-bottom-color: #dc2626; }
.rd-cell-inp.rd-cell-ko:focus { background: #fff5f5; }

/* ── Colonnes Prix d'achat / Bénéfice / Marge ────────────────
   PA fiche = info (lecture seule), Bénéfice/Marge = calcul live comme la fiche
   article. .rd-perte = vente à perte : signal rouge, anti-erreur de tarif. */
.rd-pa-fiche { color: var(--gray-500); }
.rd-benef, .rd-marge { color: var(--gray-600); font-variant-numeric: tabular-nums; }
.rd-benef.rd-perte, .rd-marge.rd-perte { color: #b91c1c; font-weight: 700; background: #fef2f2; }

/* « PU Actuel » : prix du moteur réel (tables enregistrées), lecture seule */
.rd-pu-actuel { color: var(--gray-600); font-variant-numeric: tabular-nums; }
.rd-aide-txt { font-size: 12px; color: #334155; line-height: 1.45; max-width: 420px; }

/* ── Cellule Article : flèche ▼ → fenêtre de sélection (comme les documents) */
.rd-ref-wrap { position: relative; display: flex; align-items: center; }
.rd-ref-arrow {
    border: none; background: none; cursor: pointer; color: var(--gray-400);
    font-size: 10px; padding: 0 3px; flex-shrink: 0;
}
.rd-ref-arrow:hover { color: var(--primary); }

/* (i) « formules possibles » dans l'en-tête de la colonne P.U. */
.rd-info { display: inline-flex; align-items: center; justify-content: center; width: 13px; height: 13px;
           margin-left: 4px; padding: 0; border: 1px solid #94a3b8; border-radius: 50%; background: none;
           color: #64748b; font: italic 700 9px/1 Georgia, serif; cursor: pointer; vertical-align: middle; }
.rd-info:hover { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
/* `fixed` : la fiche vit dans un conteneur en overflow:hidden (§ 7.16), un
   panneau en `absolute` y serait tronqué. Placement calculé en JS. */
.rd-aide-pop { position: fixed; z-index: 10200; width: 460px; max-width: calc(100vw - 16px);
               max-height: 70vh; overflow-y: auto; background: #fff; border: 1px solid #cbd5e1;
               border-radius: 6px; box-shadow: 0 12px 32px rgba(15,23,42,.22); padding: 10px 12px; }
.rd-aide-t { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
             color: #94a3b8; margin: 9px 0 3px; }
.rd-aide-t:first-child { margin-top: 0; }
.rd-aide-t--ko { color: #b91c1c; }
.rd-aide-row { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: #334155; padding: 1px 0; }
.rd-aide-f { flex: 0 0 190px; font-family: Consolas, monospace; font-size: 11.5px; color: #1e3a8a;
             background: #f1f5f9; border-radius: 3px; padding: 1px 4px; white-space: nowrap;
             overflow: hidden; text-overflow: ellipsis; }
.rd-aide-f--ko { color: #b91c1c; background: #fef2f2; }
.rd-aide-f--full { flex: 1 1 auto; white-space: normal; }
.rd-aide-row i { color: #64748b; }
.rd-cell-sel {
    border: none; background: #f0f7ff; font-size: 11px; font-family: inherit;
    padding: 1px 2px; width: 100%; box-sizing: border-box;
    height: 22px; cursor: pointer; border-bottom: 1px solid #d0e3f7;
}

/* ── Autocomplete in cells ───────────────────────────────── */
.rd-ac-wrap { position: relative; }
.rd-ac-list {
    display: none; position: absolute; top: 100%; left: 0;
    z-index: 500; background: var(--white);
    border: 1px solid var(--gray-300); border-top: none;
    border-radius: 0 0 4px 4px;
    max-height: 180px; overflow-y: auto;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    min-width: 250px;
}
.rd-ac-item {
    padding: 3px 8px; font-size: 11px; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rd-ac-item:hover { background: var(--blue-pale); }
.rd-ac-active { background: var(--blue-pale); }

/* ── Column resize ───────────────────────────────────────── */
.rd-col-resize {
    position: absolute; top: 0; right: -2px; width: 5px; height: 100%;
    cursor: col-resize; z-index: 2;
}
.rd-col-resize:hover { background: var(--primary); opacity: .3; }
.rd-th-resizable { overflow: hidden; text-overflow: ellipsis; cursor: grab; }
.rd-th-dragging { opacity: .4; }
.rd-th-dragover { border-left: 2px solid var(--primary); }

/* ── Status bar ──────────────────────────────────────────── */
.rd-statusbar {
    padding: 4px 12px; background: var(--gray-50); border-top: 1px solid var(--gray-200);
    font-size: 11px; color: var(--gray-500);
    display: flex; gap: 16px; flex-wrap: wrap;
}
