/* ═══════════════════════════════════════════════════════════
   DTISoft — Compensation note de crédit ↔ facture — namespace `cp-`
   Popups (proposition / annulation / choix NC), alerte crédit, bloc
   « Règlements » de la fiche document, rapport crédits dormants, toast.
   z-index : popups 10500 (au-dessus des fiches dd 8000 et des alertes
   10010, sous la fenêtre d'encaissement pai-form 12000), toast 13000.
   ═══════════════════════════════════════════════════════════ */
.cp-overlay {
    position: fixed; inset: 0; z-index: 10500;
    background: rgba(15, 23, 42, .55);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(2px);
    animation: cpFadeIn .18s ease-out;
}
@keyframes cpFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes cpPopIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.cp-panel {
    display: flex; flex-direction: column;
    width: 680px; max-width: calc(100% - 32px); max-height: 90vh;
    background: #fff; border-radius: 12px; overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
    border-top: 6px solid #16a34a;
    font-size: 13px; color: #1e293b;
    animation: cpPopIn .2s cubic-bezier(.34, 1.56, .64, 1);
}
.cp-panel-sm { width: 520px; }
.cp-panel-danger { border-top-color: #b91c1c; }
.cp-head { padding: 16px 22px 8px; }
.cp-title { font-size: 18px; font-weight: 700; color: #111827; }
.cp-sub { font-size: 12.5px; color: #64748b; margin-top: 3px; line-height: 1.4; }
.cp-note { font-size: 12px; color: #92400e; background: #fffbeb; border: 1px solid #fcd34d;
           border-radius: 6px; padding: 6px 10px; margin-top: 8px; line-height: 1.4; }
.cp-body { padding: 6px 22px 12px; overflow: auto; }
.cp-p { margin: 0 0 8px; line-height: 1.45; }
.cp-muted { color: #94a3b8; }
.cp-strong { font-weight: 700; }
.cp-r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Bandeau facture */
.cp-fact {
    display: flex; flex-wrap: wrap; gap: 10px 22px;
    background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px;
    padding: 8px 12px; margin-bottom: 10px;
}
.cp-fact-item { display: flex; flex-direction: column; gap: 1px; }
.cp-fact-lbl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: #64748b; }
.cp-fact-val { font-size: 14px; }
.cp-fact-reste .cp-fact-val { color: #b45309; font-size: 16px; }

/* Tableau des notes de crédit */
.cp-table { width: 100%; border-collapse: collapse; }
.cp-table th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em;
    color: #475569; padding: 4px 6px; border-bottom: 1px solid #e2e8f0; background: #f8fafc;
}
.cp-table td { padding: 5px 6px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.cp-row-on td { background: #f0fdf4; }
.cp-nc { font-weight: 600; }
.cp-badge-hist {
    display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px;
    background: #f1f5f9; color: #64748b; font-size: 10.5px; font-weight: 600; vertical-align: middle;
}
.cp-chk { width: 15px; height: 15px; cursor: pointer; }
.cp-inp-montant {
    width: 110px; text-align: right; padding: 4px 6px; font-weight: 700; font-size: 13px;
    border: 1px solid #cbd5e1; border-radius: 6px; background: #fff; color: #1e293b;
}
.cp-inp-montant:focus { outline: none; border-color: #16a34a; box-shadow: 0 0 0 3px rgba(22, 163, 74, .15); }

/* Récap vivant */
.cp-recap { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; margin-top: 10px; }
.cp-recap-line { display: flex; gap: 16px; align-items: baseline; }
.cp-recap-line > span { color: #64748b; }
.cp-recap-line > b { min-width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
.cp-recap-big > span { color: #1e293b; font-weight: 600; }
.cp-recap-big > b { font-size: 17px; color: #15803d; }
.cp-recap-info { font-size: 11.5px; color: #94a3b8; margin-top: 4px; }

.cp-err {
    color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px;
    padding: 6px 10px; margin-top: 8px; font-size: 12.5px;
}
.cp-err[hidden] { display: none !important; }

/* Pied + boutons */
.cp-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 22px 16px; border-top: 1px solid #eef2f7; }
.cp-btn {
    padding: 8px 18px; border-radius: 7px; font-size: 13px; font-weight: 600;
    cursor: pointer; border: 1px solid transparent; transition: background .15s;
}
.cp-btn:disabled { opacity: .55; cursor: default; }
.cp-btn-primary { background: #16a34a; color: #fff; }
.cp-btn-primary:hover:not(:disabled) { background: #15803d; }
.cp-btn-secondary { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.cp-btn-secondary:hover:not(:disabled) { background: #e2e8f0; }
.cp-btn-danger { background: #b91c1c; color: #fff; }
.cp-btn-danger:hover:not(:disabled) { background: #991b1b; }
.cp-btn-blue { background: #2563eb; color: #fff; padding: 10px 28px; font-size: 14px; }
.cp-btn-blue:hover:not(:disabled) { background: #1d4ed8; }
.cp-btn-blue:focus { outline: 2px solid #93c5fd; outline-offset: 2px; }
.cp-btn-mini { padding: 3px 9px; font-size: 11.5px; border-radius: 5px; background: #fff; color: #334155; border-color: #cbd5e1; margin-right: 4px; }
.cp-btn-mini:hover:not(:disabled) { background: #f1f5f9; }
.cp-btn-mini-primary { background: #16a34a; color: #fff; border-color: #16a34a; }
.cp-btn-mini-primary:hover:not(:disabled) { background: #15803d; }

/* Choix après création d'une NC */
.cp-choices { display: flex; flex-direction: column; gap: 8px; margin: 6px 0 4px; }
.cp-choice {
    display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
    padding: 10px 14px; border: 2px solid #e2e8f0; border-radius: 10px; background: #fff;
    cursor: pointer; font: inherit; color: #1e293b; transition: border-color .12s, background .12s;
}
.cp-choice:hover, .cp-choice:focus { border-color: #16a34a; background: #f0fdf4; outline: none; }
.cp-choice-ic { font-size: 24px; line-height: 1; flex: 0 0 auto; }
.cp-choice-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cp-choice-t { font-weight: 700; font-size: 14px; }
.cp-choice-d { font-size: 12px; color: #64748b; line-height: 1.35; }

/* Alerte « crédit disponible » (informative, style alerte tiers) */
.cp-alert-overlay { z-index: 10010; }
.cp-alert {
    text-align: center; padding: 28px 32px 22px; width: auto;
    min-width: 460px; max-width: 600px; border-top-color: #16a34a;
}
.cp-alert-icon {
    width: 60px; height: 60px; margin: 0 auto 14px; border-radius: 50%;
    background: #16a34a; color: #fff; font-size: 30px;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 20px rgba(22, 163, 74, .35);
}
.cp-alert-title { font-size: 20px; font-weight: 700; color: #111827; margin-bottom: 6px; }
.cp-alert-tier { font-size: 15px; font-weight: 600; color: #374151; margin-bottom: 8px; }
.cp-alert-alias { color: #6b7280; font-weight: 400; font-size: 13px; }
.cp-alert-msg { font-size: 14px; color: #4b5563; line-height: 1.5; margin-bottom: 16px; padding: 0 8px; }
.cp-alert-list {
    text-align: left; margin: 0 8px 16px; padding: 10px 14px 10px 30px;
    background: #f0fdf4; border: 1px solid #bbf7d0; border-left: 4px solid #16a34a; border-radius: 6px;
    color: #14532d; font-size: 13px; line-height: 1.5;
}

/* Bloc « Règlements » sous les totaux de la fiche document (dans .dd-totals) */
.cp-regl {
    border-top: 1px solid #bbf7d0; margin-top: 6px; padding-top: 5px;
    font-size: 11.5px; color: #14532d;
}
.cp-regl[hidden] { display: none !important; }
.cp-regl-title { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: #15803d; font-weight: 700; margin-bottom: 2px; }
.cp-regl-line { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; align-items: baseline; }
.cp-regl-lbl { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-regl-val { white-space: nowrap; font-variant-numeric: tabular-nums; }
.cp-regl-annulee { text-decoration: line-through; color: #94a3b8; }
.cp-regl-tot { border-top: 1px solid #bbf7d0; margin-top: 3px; padding-top: 3px; font-weight: 700; font-size: 12.5px; }
.cp-regl-annuler {
    border: none; background: none; color: #b91c1c; cursor: pointer;
    font-size: 13px; font-weight: 700; line-height: 1; padding: 0 0 0 5px; vertical-align: middle;
}
.cp-regl-annuler:hover { color: #7f1d1d; }
/* « Rattacher ici » : règlement encaissé sur un doc amont → cette facture. */
.cp-regl-rattacher {
    border: 1px solid #16a34a; background: #f0fdf4; color: #15803d; cursor: pointer;
    font-size: 11px; font-weight: 700; line-height: 1; border-radius: 5px;
    padding: 2px 6px; margin-left: 6px; vertical-align: middle; white-space: nowrap;
}
.cp-regl-rattacher:hover { background: #dcfce7; }
.cp-regl-rattacher.cp-regl-arm { background: #fef3c7; border-color: #d97706; color: #92400e; }
.cp-regl-rattacher:disabled { opacity: .6; cursor: default; }
.cp-regl-err {
    color: #b91c1c; background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px;
    padding: 5px 9px; margin-top: 6px; font-size: 12px;
}

/* Fiche document : bouton « Crédit client » (à côté de Payer) + chip solde box.
   `.dd-payer-btn` est display:flex → l'attribut hidden doit être réaffirmé. */
.dd-credit-btn { border-color: #16a34a; color: #15803d; }
.dd-credit-btn:hover:not(:disabled) { background: #16a34a; color: #fff; }
.dd-credit-btn[hidden] { display: none !important; }
.dd-solde-credit { display: block; font-size: 10px; font-weight: 600; color: #16a34a; white-space: nowrap; }
.dd-solde-credit[hidden] { display: none !important; }

/* Fenêtre d'encaissement : tuile « Crédit client » + barre legacy */
.pai-carte-credit { border-color: #86efac; background: #f0fdf4; color: #15803d; }
.pai-carte-credit:hover { border-color: #16a34a; background: #dcfce7; }
.pai-credit-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px;
    padding: 7px 12px; margin: -6px 0 12px; font-size: 12.5px; color: #14532d;
}
.pai-credit-use {
    padding: 5px 12px; border-radius: 6px; border: 1px solid #16a34a; background: #16a34a; color: #fff;
    font-weight: 600; font-size: 12px; cursor: pointer;
}
.pai-credit-use:hover { background: #15803d; }
.pai-reste-box.pai-reste-nc { background: #f0fdf4; border-color: #bbf7d0; }
.pai-reste-box.pai-reste-nc span { color: #15803d; }
.pai-reste-box.pai-reste-nc b { color: #14532d; }

/* Rapport crédits dormants (Options → Situation Clients) */
.cp-dorm-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.cp-dorm-table th {
    text-align: left; background: #f1f5f9; color: #475569; font-weight: 600;
    padding: 5px 8px; border-bottom: 1px solid #e2e8f0; white-space: nowrap;
}
.cp-dorm-table td { padding: 4px 8px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.cp-dorm-table tr:hover td { background: #f8fafc; }
.cp-actions { white-space: nowrap; }
.cp-dorm-foot { display: flex; gap: 6px; margin-top: 8px; font-size: 12.5px; font-weight: 600; color: #334155; }

/* Toast */
.cp-toast {
    position: fixed; right: 18px; bottom: 18px; z-index: 13000;
    max-width: 460px; padding: 10px 16px; border-radius: 8px;
    background: #15803d; color: #fff; font-size: 13px; line-height: 1.4;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
    animation: cpToastIn .2s ease-out; transition: opacity .4s, transform .4s;
}
.cp-toast-err { background: #b91c1c; }
.cp-toast-out { opacity: 0; transform: translateY(8px); }
@keyframes cpToastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
