/* =============================================================================
   BACKOFFICE SYNEXTA — PRODUCTS.CSS
   =============================================================================
   Styles propres au module Produits. Tout ce qui est générique (widget,
   widget-toolbar, toolbar-toggle, row-card, cfg-field / cfg-input / cfg-btn,
   right-drawer) vient de widgets.css et configuration.css et n'est pas
   redéfini ici.

   La ligne produit est une carte unique en grille de 2 rangées :
     rangée 1 → checkbox, favori, nom, prix achat, prix vente, actions
     rangée 2 → métadonnées (description, unité, stock, fourchette)
   Checkbox, favori et actions sont en span sur les 2 rangées.

   Sections :
   1. Grille de la liste
   2. Checkbox de sélection
   3. Cellules de ligne (nom, badges, prix, métadonnées)
   4. États actif / désactivé
   5. Bouton Supprimer et compteurs de toolbar
   6. Modale de suppression
   7. Formulaire du drawer
   8. Responsive
   ============================================================================= */

/* #section 1 : grille de la liste */
.row-card-header.is-product-grid {
    grid-template-columns: 34px 26px minmax(200px, 1fr) 110px 132px 78px;
    padding: 8px 16px;
    align-items: center;
}

.row-card.is-product-grid {
    grid-template-columns: 34px 26px minmax(200px, 1fr) 110px 132px 78px;
    grid-template-rows: auto auto;
    column-gap: 12px;
    row-gap: 1px;
    padding: 7px 16px;
    align-items: center;
}

.row-card.is-product-grid > .product-check   { grid-column: 1; grid-row: 1 / 3; align-self: center; }
.row-card.is-product-grid > .row-card-star   { grid-column: 2; grid-row: 1 / 3; align-self: center; }
.row-card.is-product-grid > .product-name-cell { grid-column: 3; grid-row: 1; }
.row-card.is-product-grid > .product-price   { grid-column: 4; grid-row: 1; }
.row-card.is-product-grid > .row-card-amount { grid-column: 5; grid-row: 1; }
.row-card.is-product-grid > .row-card-actions{ grid-column: 6; grid-row: 1 / 3; align-self: center; }
.row-card.is-product-grid > .product-meta    { grid-column: 3 / 6; grid-row: 2; }

/* #section 2 : checkbox de sélection */
.product-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.product-check input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.product-check-box {
    width: 15px;
    height: 15px;
    border-radius: 3px;
    border: 1.5px solid var(--color-border-strong, rgba(0, 0, 0, 0.28));
    background: #fff;
    position: relative;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.product-check-box::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 0.5px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg) scale(0);
    transition: transform 0.12s ease;
}

.product-check input:checked + .product-check-box {
    background: #2563eb;
    border-color: #2563eb;
}

.product-check input:checked + .product-check-box::after {
    transform: rotate(45deg) scale(1);
}

.product-check input:focus-visible + .product-check-box {
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.product-check:hover .product-check-box {
    border-color: #2563eb;
}

/* #section 3 : cellules de ligne */
.product-name-cell {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 6px;
    min-width: 0;
}

.product-name-cell .row-card-title {
    font-size: 13.5px;
    text-transform: uppercase;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.product-badge {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    height: 17px;
    padding: 0 7px;
    border-radius: 9px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: nowrap;
    border: 1px solid transparent;
}

.product-badge.is-service {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.22);
    color: #1d4ed8;
}

.product-badge.is-goods {
    background: rgba(15, 110, 86, 0.08);
    border-color: rgba(15, 110, 86, 0.22);
    color: #0F6E56;
}

.product-badge.is-off {
    background: rgba(163, 45, 45, 0.07);
    border-color: rgba(163, 45, 45, 0.20);
    color: #A32D2D;
}

.product-lock {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-light, #9ca3af);
    cursor: help;
}

.product-price.is-buy {
    text-align: right;
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    color: var(--color-text-muted, #6b7280);
}

.product-price-empty {
    color: var(--color-text-light, #9ca3af);
}

.row-card.is-product-grid .row-card-amount {
    font-size: 14px;
}

.product-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    font-size: 12px;
    line-height: 1.35;
    color: var(--color-text-muted, #6b7280);
}

.product-meta-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.product-meta-tag {
    flex-shrink: 0;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.045);
    font-size: 11px;
    color: var(--color-text-muted, #6b7280);
    white-space: nowrap;
}

.product-meta-tag.is-range {
    font-variant-numeric: tabular-nums;
}

/* #section 4 : états actif / désactivé */
.row-card.is-state-hidden {
    display: none !important;
}

.row-card.is-inactive .row-card-title,
.row-card.is-inactive .row-card-amount,
.row-card.is-inactive .product-price.is-buy {
    opacity: 0.7;
}

/* #section 5 : bouton Supprimer et compteurs de toolbar */
.product-state-count,
.product-delete-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    margin-left: 5px;
    padding: 0 5px;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.07);
    font-size: 11px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-muted, #6b7280);
}

.product-delete-count:empty {
    display: none;
}

.btn-header.is-danger {
    background: #fff;
    border: 1px solid rgba(163, 45, 45, 0.28);
    color: #A32D2D;
}

.btn-header.is-danger:hover:not(:disabled) {
    background: rgba(163, 45, 45, 0.07);
    border-color: rgba(163, 45, 45, 0.45);
}

.btn-header.is-danger:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    color: var(--color-text-muted, #6b7280);
    border-color: var(--color-border, rgba(0, 0, 0, 0.12));
}

.btn-header.is-danger:disabled .product-delete-count {
    display: none;
}

/* #section 6 : modale de suppression */
.product-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(15, 23, 42, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.product-modal-overlay[hidden] {
    display: none;
}

.product-modal {
    width: 100%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.25);
    overflow: hidden;
}

.product-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
}

.product-modal-title {
    margin: 0;
    font-size: 15.5px;
    font-weight: 700;
    color: var(--color-text, #1a1a1a);
}

.product-modal-close {
    background: none;
    border: none;
    padding: 4px;
    border-radius: 5px;
    color: var(--color-text-muted, #6b7280);
    cursor: pointer;
    line-height: 0;
}

.product-modal-close:hover {
    background: var(--color-bg-alt, #f1f5f9);
    color: var(--color-text, #1a1a1a);
}

.product-modal-body {
    padding: 18px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.product-modal-rule {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 7px;
    background: rgba(37, 99, 235, 0.05);
    border: 1px solid rgba(37, 99, 235, 0.16);
    color: #1e40af;
}

.product-modal-rule svg {
    flex-shrink: 0;
    margin-top: 1px;
}

.product-modal-rule p {
    margin: 0;
    font-size: 12.5px;
    line-height: 1.5;
}

.product-modal-group-title {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 0 0 8px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-text-muted, #6b7280);
}

.product-modal-group.is-deletable .product-modal-group-title { color: #A32D2D; }

.product-modal-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: rgba(0, 0, 0, 0.07);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-muted, #6b7280);
}

.product-modal-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid var(--color-border, rgba(0, 0, 0, 0.10));
    border-radius: 7px;
    overflow: hidden;
}

.product-modal-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    font-size: 13px;
}

.product-modal-list li:last-child { border-bottom: none; }
.product-modal-list li:nth-child(even) { background: #fafbfc; }

.product-modal-item-name {
    font-weight: 600;
    color: var(--color-text, #1a1a1a);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.product-modal-item-note {
    flex-shrink: 0;
    font-size: 11.5px;
    color: var(--color-text-muted, #6b7280);
}

.product-modal-hint {
    margin: 8px 0 0;
    font-size: 12px;
    color: var(--color-text-muted, #6b7280);
}

.product-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--color-border, rgba(0, 0, 0, 0.08));
    background: #fafbfc;
}

.cfg-btn.cfg-btn-danger {
    background: #A32D2D;
    border-color: #A32D2D;
    color: #fff;
}

.cfg-btn.cfg-btn-danger:hover:not(:disabled) {
    background: #8d2626;
    border-color: #8d2626;
}

.cfg-btn.cfg-btn-danger:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* #section 7 : formulaire du drawer */
.product-form-grid {
    display: grid;
    gap: 12px;
    align-items: start;
}

.product-form-grid.is-2-1 { grid-template-columns: 2fr 1fr; }
.product-form-grid.is-3   { grid-template-columns: 1fr 1fr 1fr; }

.product-multiselect {
    height: auto;
    min-height: 120px;
    padding: 6px 8px;
    background-image: none;
    cursor: default;
}

.product-multiselect option {
    padding: 4px 6px;
    border-radius: 4px;
}

.product-switch {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}

.product-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.product-switch-track {
    position: relative;
    flex-shrink: 0;
    width: 34px;
    height: 20px;
    margin-top: 1px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.16);
    transition: background 0.15s ease;
}

.product-switch-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transition: transform 0.15s ease;
}

.product-switch input:checked + .product-switch-track { background: #2563eb; }
.product-switch input:checked + .product-switch-track::after { transform: translateX(14px); }
.product-switch input:focus-visible + .product-switch-track { box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18); }

.product-switch-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 13.5px;
    color: var(--color-text, #1a1a1a);
    line-height: 1.35;
}

.product-switch-help {
    font-size: 12px;
    color: var(--color-text-muted, #6b7280);
}

.cfg-input.is-error {
    border-color: #A32D2D;
    background: rgba(163, 45, 45, 0.03);
}

.product-form-error {
    font-size: 12.5px;
    color: #A32D2D;
    margin-top: 2px;
}

/* #section 8 : responsive */
@container widget (max-width: 700px) {
    .row-card.is-product-grid > .product-meta {
        flex-basis: 100%;
    }
}

@media (max-width: 640px) {
    .product-form-grid.is-2-1,
    .product-form-grid.is-3 {
        grid-template-columns: 1fr;
    }

    .product-modal { max-width: none; }
}
