/*
 * Grille de comptage éditable — style de la modale d'inventaire.
 * Couleurs : variables du panneau Filament (triplets RGB : --primary-500, --gray-200, …),
 * donc le thème (bleu) et le mode sombre (classe .dark) sont suivis automatiquement.
 */

.gc {
    --gc-bordure: rgba(var(--gray-200), 1);
    --gc-fond: #fff;
    --gc-fond-entete: rgba(var(--gray-50), 1);
    --gc-fond-survol: rgba(var(--primary-50), 0.55);
    --gc-fond-actif: rgba(var(--primary-50), 1);
    --gc-texte: rgba(var(--gray-950), 1);
    --gc-texte-doux: rgba(var(--gray-500), 1);
    --gc-focus: rgba(var(--primary-500), 1);
    --gc-halo: rgba(var(--primary-500), 0.18);
    --gc-rayon: 0.5rem;

    display: flex;
    flex-direction: column;
    gap: 0.625rem;
    color: var(--gc-texte);
    font-size: 0.875rem;
}

:is(.dark .gc) {
    --gc-bordure: rgba(255, 255, 255, 0.1);
    --gc-fond: rgba(var(--gray-900), 1);
    --gc-fond-entete: rgba(255, 255, 255, 0.04);
    --gc-fond-survol: rgba(var(--primary-400), 0.08);
    --gc-fond-actif: rgba(var(--primary-400), 0.14);
    --gc-texte: rgba(var(--gray-100), 1);
    --gc-texte-doux: rgba(var(--gray-400), 1);
    --gc-focus: rgba(var(--primary-400), 1);
    --gc-halo: rgba(var(--primary-400), 0.25);
}

/* --- Synthèse ------------------------------------------------------------------------- */

.gc-synthese {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    color: var(--gc-texte-doux);
    font-size: 0.8125rem;
}

.gc-synthese strong {
    color: var(--gc-texte);
    font-variant-numeric: tabular-nums;
}

.gc-filtre {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    margin-left: auto;
    cursor: pointer;
    user-select: none;
}

.gc-filtre input {
    accent-color: var(--gc-focus);
}

/* --- Tableau ---------------------------------------------------------------------------- */

.gc-cadre {
    max-height: min(60vh, 34rem);
    overflow: auto;
    border: 1px solid var(--gc-bordure);
    border-radius: var(--gc-rayon);
    background: var(--gc-fond);
}

.gc-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
}

.gc-table thead th {
    position: sticky; /* l'en-tête reste visible pendant le défilement */
    top: 0;
    z-index: 1;
    padding: 0.5rem 0.625rem;
    background: var(--gc-fond-entete);
    border-bottom: 1px solid var(--gc-bordure);
    color: var(--gc-texte-doux);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-align: left;
    text-transform: uppercase;
    backdrop-filter: blur(6px);
}

.gc-table td {
    padding: 0.3125rem 0.625rem;
    border-bottom: 1px solid var(--gc-bordure);
    vertical-align: middle;
}

.gc-table tbody tr:last-child td {
    border-bottom: 0;
}

/* Largeurs : la colonne Produit prend le reste */
.gc-col-vignette { width: 3rem; }
.gc-col-nombre   { width: 6.5rem; text-align: right !important; font-variant-numeric: tabular-nums; }
.gc-col-saisie   { width: 9.5rem; }
.gc-col-obs      { width: 13rem; }
.gc-col-actions  { width: 2.75rem; text-align: center; }

/* --- Lignes : survol, ligne en cours de saisie, ligne qui vient d'être ajoutée -------- */

.gc-ligne {
    transition: background-color 120ms ease;
}

.gc-ligne:hover {
    background: var(--gc-fond-survol);
}

.gc-ligne--active,
.gc-ligne--active:hover {
    background: var(--gc-fond-actif);
    box-shadow: inset 3px 0 0 var(--gc-focus);
}

.gc-ligne--surlignee {
    animation: gc-flash 1.2s ease-out;
}

@keyframes gc-flash {
    from { background: rgba(var(--primary-500), 0.25); }
    to   { background: transparent; }
}

/* --- Cellules ------------------------------------------------------------------------ */

.gc-vignette {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    background: hsl(var(--gc-teinte) 70% 92%);
    color: hsl(var(--gc-teinte) 45% 32%);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

:is(.dark .gc-vignette) {
    background: hsl(var(--gc-teinte) 35% 22%);
    color: hsl(var(--gc-teinte) 70% 80%);
}

.gc-produit {
    min-width: 0;
}

.gc-produit__nom {
    display: block;
    overflow: hidden;
    font-weight: 500;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.gc-produit__meta {
    display: block;
    color: var(--gc-texte-doux);
    font-size: 0.75rem;
}

.gc-theorique {
    color: var(--gc-texte-doux);
}

/* --- Champs de saisie ----------------------------------------------------------------- */

.gc-input {
    width: 100%;
    height: 2rem;
    padding: 0 0.625rem;
    border: 1px solid var(--gc-bordure);
    border-radius: 0.375rem;
    background: var(--gc-fond);
    color: inherit;
    font: inherit;
    outline: none;
    transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.gc-input::placeholder {
    color: var(--gc-texte-doux);
    opacity: 0.7;
}

/* Micro-interaction : bordure bleue + halo au focus */
.gc-input:focus {
    border-color: var(--gc-focus);
    box-shadow: 0 0 0 3px var(--gc-halo);
}

.gc-input:disabled {
    border-color: transparent;
    background: transparent;
    cursor: default;
}

.gc-input--compte {
    font-weight: 600;
    text-align: right;
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
}

.gc-input--compte::-webkit-outer-spin-button,
.gc-input--compte::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Unité de saisie (carton…) et équivalent en unité de base, sous le champ compté */
.gc-conditionnement {
    display: block;
    margin-top: 0.125rem;
    color: var(--gc-texte-doux);
    font-size: 0.6875rem;
    line-height: 1.2;
    text-align: right;
    white-space: nowrap;
}

/* Observation : discrète tant qu'on ne s'en sert pas */
.gc-input--discret {
    border-color: transparent;
    background: transparent;
    font-size: 0.8125rem;
}

.gc-ligne:hover .gc-input--discret:not(:disabled) {
    border-color: var(--gc-bordure);
}

.gc-input--discret:focus {
    background: var(--gc-fond);
}

/* --- Écart : pastille colorée selon le sens ---------------------------------------- */

.gc-ecart {
    display: inline-block;
    min-width: 3.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    text-align: center;
}

.gc-ecart--attente { color: var(--gc-texte-doux); font-weight: 400; font-style: italic; }
.gc-ecart--nul     { background: rgba(var(--success-500), 0.12); color: rgba(var(--success-700), 1); }
.gc-ecart--positif { background: rgba(var(--warning-500), 0.15); color: rgba(var(--warning-700), 1); }
.gc-ecart--negatif { background: rgba(var(--danger-500), 0.12);  color: rgba(var(--danger-700), 1); }

:is(.dark .gc-ecart--nul)     { color: rgba(var(--success-400), 1); }
:is(.dark .gc-ecart--positif) { color: rgba(var(--warning-400), 1); }
:is(.dark .gc-ecart--negatif) { color: rgba(var(--danger-400), 1); }

/* --- Bouton supprimer ------------------------------------------------------------------ */

.gc-supprimer {
    display: inline-grid;
    place-items: center;
    width: 1.875rem;
    height: 1.875rem;
    border-radius: 0.375rem;
    color: rgba(var(--danger-600), 1);
    opacity: 0.55;
    transition: opacity 120ms ease, background-color 120ms ease;
}

.gc-ligne:hover .gc-supprimer,
.gc-supprimer:focus-visible {
    opacity: 1;
}

.gc-supprimer:hover {
    background: rgba(var(--danger-500), 0.1);
}

.gc-icone {
    width: 1.0625rem;
    height: 1.0625rem;
}

.gc-vide {
    padding: 1.5rem !important;
    color: var(--gc-texte-doux);
    text-align: center;
}

/* --- Recherche rapide / scanner ------------------------------------------------------ */

.gc-recherche {
    position: relative;
}

.gc-recherche__icone {
    position: absolute;
    top: 50%;
    left: 0.75rem;
    width: 1.25rem;
    height: 1.25rem;
    color: var(--gc-texte-doux);
    transform: translateY(-50%);
    pointer-events: none;
}

.gc-recherche__input {
    height: 2.5rem;
    padding-left: 2.5rem;
    border-style: dashed;
}

.gc-recherche__input:focus {
    border-style: solid;
}

.gc-resultats {
    position: absolute;
    bottom: calc(100% + 0.25rem); /* s'ouvre vers le haut : la recherche est en bas de la modale */
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 18rem;
    overflow: auto;
    padding: 0.25rem;
    border: 1px solid var(--gc-bordure);
    border-radius: var(--gc-rayon);
    background: var(--gc-fond);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.25);
}

.gc-resultat {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0.625rem;
    border-radius: 0.375rem;
    cursor: pointer;
}

.gc-resultat--selection {
    background: var(--gc-fond-actif);
}

.gc-resultat__meta {
    flex-shrink: 0;
    color: var(--gc-texte-doux);
    font-size: 0.75rem;
}

/* --- Petits écrans : vignette et observation masquées, la saisie du compté reste prioritaire -- */

@media (max-width: 768px) {
    .gc-col-vignette,
    .gc-col-obs { display: none; }
    .gc-col-nombre { width: 5rem; }
    .gc-col-saisie { width: 6.5rem; }
}
