/**
 * Admin Dashboard Styles
 * Dedicated CSS for admin panel responsive layout
 */

/* ==========================================================================
   Producer List - Responsive Layout
   ========================================================================== */

/* Content container - shared width for title and table */
.admin-content {
    width: 100%;
    max-width: 1300px;
    margin-left: auto;
    margin-right: auto;
}

/* Table container inherits content width */
.admin-table {
    width: 100%;
}

/* --------------------------------------------------------------------------
   Tableau des producteurs — un vrai <table>.

   Il garde ses colonnes à toutes les tailles et défile horizontalement sur
   petit écran plutôt que de s'empiler (ce qui comprimait tout et rendait la
   liste illisible). La colonne Actions reste collée à droite pendant le
   défilement : le menu d'actions doit toujours être atteignable.

   `border-collapse: separate` est OBLIGATOIRE ici : en mode `collapse`, les
   bordures d'une cellule `position: sticky` ne se déplacent pas avec elle et
   restent peintes à leur position d'origine. C'est la même raison qui fait
   porter les séparateurs de lignes par les cellules et non par les `<tr>` —
   une bordure de `<tr>` n'est pas peinte en mode `separate`.
   -------------------------------------------------------------------------- */

.table-scroll {
    overflow-x: auto;
    overflow-y: visible;
}

.producers-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    /* `fixed` est requis deux fois plutôt qu'une : il fait autorité sur les
       largeurs du <colgroup>, et il est la condition pour que `text-overflow`
       opère dans une cellule. En `auto`, une cellule s'élargit pour accueillir
       son contenu et l'ellipsis n'apparaît jamais. */
    table-layout: fixed;
    /* Largeur plancher = somme des colonnes ; c'est elle qui déclenche le
       défilement. Au-delà, `fixed` répartit l'espace en trop proportionnellement
       entre les colonnes — l'équivalent du `flex-grow` d'avant. */
    min-width: 945px;   /* nom + email + état saisie + statut + actions */
}

/* Les colonnes Technicien et Département sont masquées sous le point de rupture
   `md` de Tailwind (768px) : la largeur plancher doit suivre, sinon le tableau
   reste large de 7 colonnes pour n'en afficher que 5 — et défile pour rien. */
@media (min-width: 768px) {
    .admin-table.is-super-admin .producers-table {
        min-width: 1280px;  /* + technicien + département */
    }
}

/* Largeurs des colonnes. Avec `table-layout: fixed`, ce sont celles de la
   PREMIÈRE ligne qui font autorité — donc celles des `<th>` ci-dessous ; les
   `<td>` portent les mêmes classes, ce qui garde la déclaration unique.
   En pixels et non en pourcentage : ce qui compte est la place réellement
   nécessaire au contenu, pas une fraction d'un conteneur qui peut être étroit.
   Leur somme est le `min-width` du tableau déclaré plus haut. */
.producers-table .col-nom         { width: 240px; }
.producers-table .col-email       { width: 290px; }
.producers-table .col-technicien  { width: 175px; }
.producers-table .col-departement { width: 160px; }
.producers-table .col-etat-saisie { width: 240px; }
.producers-table .col-statut      { width: 115px; }
.producers-table .col-actions     { width: 60px;  }

.producers-table th,
.producers-table td {
    text-align: left;
    vertical-align: middle;
    padding: 1rem 0.75rem;
}

.producers-table thead th {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    background-color: #f8fafc;          /* slate-50 */
    border-bottom: 1px solid #e2e8f0;   /* slate-200 */
    font-size: 0.75rem;
    font-weight: 600;
    color: #6b7280;                     /* gray-500 */
    text-transform: uppercase;
    letter-spacing: 0.025em;
    /* Les libellés d'en-tête sont plus longs que les valeurs qu'ils coiffent :
       on les laisse passer à la ligne, seules les cellules gardent l'ellipsis. */
    white-space: normal;
    line-height: 1.3;
}

/* Gouttières extérieures — l'équivalent du `px-4 md:px-6` que portait la ligne. */
.producers-table th:first-child,
.producers-table td:first-child { padding-left: 1rem; }
.producers-table th:last-child,
.producers-table td:last-child  { padding-right: 1rem; }

@media (min-width: 768px) {
    .producers-table th:first-child,
    .producers-table td:first-child { padding-left: 1.5rem; }
    .producers-table th:last-child,
    .producers-table td:last-child  { padding-right: 1.5rem; }
}

/* Séparateurs et fond portés par les cellules (cf. `separate` plus haut).
   Le fond doit être opaque : les autres colonnes défilent sous la colonne
   collante, et un fond transparent les laisserait voir au travers. */
.producers-table tbody td {
    background-color: #ffffff;
    border-bottom: 1px solid #f1f5f9;   /* slate-100 */
}

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

.producer-row:hover td {
    background-color: #f8fafc;
}

/* Troncature. `table-layout: fixed` donne sa largeur à la cellule, donc
   l'ellipsis peut s'appliquer directement dessus. */
.col-email,
.col-technicien,
.col-departement {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Colonne Actions — collée à droite pendant le défilement horizontal.
   Elle ne porte qu'un menu kebab : chaque pixel qu'elle rend est du texte
   lisible en plus dans les autres colonnes. */
.col-actions {
    position: sticky;
    right: 0;
    text-align: center;
    /* Séparateur franc, visible en permanence : c'est lui qui rattache la
       colonne au tableau. L'ombre ci-dessous ne s'y ajoute que s'il reste
       réellement à défiler — sinon elle donne l'impression d'un panneau
       flottant posé sur le tableau. */
    border-left: 1px solid #e2e8f0;     /* slate-200 */
}

/* `position: sticky` cree un contexte d'empilement par cellule. Les cellules
   se peignent donc dans l'ordre du DOM, et celles des lignes suivantes passent
   par-dessus un menu ouvert. La classe est posee par `toggleRowMenu()`. */
.col-actions.menu-open {
    z-index: 20;
}

.producers-table thead .col-actions {
    background-color: #f8fafc;
}

.table-scroll.is-scrollable .col-actions {
    box-shadow: -6px 0 6px -6px rgba(15, 23, 42, 0.12);
}


/* Champs de la recherche rapide */
.filter-select {
    border: 1px solid #cbd5e1;      /* slate-300 */
    border-radius: 0.5rem;
    padding: 0.5rem 0.625rem;
    font-size: 0.8125rem;
    color: #374151;                 /* gray-700 */
    background-color: #ffffff;
    max-width: 100%;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: #10b981;          /* emerald-500 */
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

/* Masquage des lignes filtrées. `!important` parce que `.producer-row` impose
   `display:flex` depuis ce fichier, chargé après Tailwind : la classe `hidden`
   ne suffirait pas. */
.producer-row.row-filtered {
    display: none !important;
}

/* ==========================================================================
   Boutons de tri dans les en-têtes
   ========================================================================== */
.sort-btn {
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    user-select: none;
}

.sort-btn:hover {
    color: #047857; /* emerald-700 */
}

.sort-btn .sort-icon {
    /* 0.75rem et non 0.7 : l'echelle typographique du design system est FERMEE
       (10 / 12 / 13 / 14 / 16 / 18 / 20 / 24), 11,2 px n'en fait pas partie. */
    font-size: 0.75rem;
    color: #9ca3af; /* gray-400 */
}

.sort-btn[data-active] .sort-icon {
    color: #047857; /* emerald-700 */
}

/* ==========================================================================
   Toggle Switch Styles (Auto Export)
   ========================================================================== */

/* Pixel-Perfect Toggle Switch */
.toggle-track {
    width: 44px;
    height: 24px;
    background-color: #e5e7eb;
    /* gray-200 */
    border-radius: 9999px;
    transition: background-color 0.2s ease-in-out;
}

.toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background-color: white;
    border-radius: 50%;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    transition: transform 0.2s ease-in-out;
    pointer-events: none;
    /* Let clicks pass to input via label */
}

/* Checked State */
#autoExportToggle:checked~.toggle-track {
    background-color: #10b981;
    /* emerald-500 */
}

#autoExportToggle:checked~.toggle-knob {
    transform: translateX(20px);
    /* 44px (track) - 4px (padding) - 20px (knob) = 20px move */
}

/* Explicit container for positioning */
.toggle-wrapper {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

/* Accessibility helper - strictly hide input */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Label spacing */
.toggle-label {
    margin-left: 10px;
    /* Force margin since Tailwind utility might be missing in build */
}

/* ==========================================================================
   Tableur Légumes — toolbar + cellules style Excel
   ========================================================================== */

.grid-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.625rem;
    border-radius: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;        /* gray-700 */
    background: #ffffff;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
    user-select: none;
}

.grid-toolbar-btn:hover {
    background: #f1f5f9;   /* slate-100 */
}

.grid-toolbar-btn:disabled {
    color: #9ca3af;        /* gray-400 */
    cursor: not-allowed;
    background: transparent;
}

.grid-toolbar-btn-danger {
    color: #b91c1c;        /* red-700 */
}

.grid-toolbar-btn-danger:hover {
    background: #fef2f2;   /* red-50 */
}

/* Cellule tableur — wrapper td */
.grid-cell {
    padding: 0;
    border-right: 1px solid #f1f5f9;
    position: relative;
    background: #ffffff;
    transition: background-color 0.1s;
}

.grid-cell.selected {
    background: #ecfdf5;   /* emerald-50 */
    box-shadow: inset 0 0 0 1px #10b981; /* emerald-500 */
}

.grid-cell.active {
    background: #d1fae5;   /* emerald-100 */
    box-shadow: inset 0 0 0 2px #047857; /* emerald-700 */
    z-index: 1;
}

.grid-cell-input {
    width: 100%;
    padding: 0.5rem 0.625rem;
    border: 0;
    outline: 0;
    font-size: 0.875rem;
    color: #1f2937;        /* gray-800 */
    background: transparent;
    caret-color: transparent; /* en mode navigation, le caret est caché */
    cursor: cell;
}

.grid-cell.editing .grid-cell-input {
    caret-color: #047857;  /* emerald-700 — caret visible en édition */
    cursor: text;
    background: #ffffff;
}

.grid-cell.editing {
    box-shadow: inset 0 0 0 2px #047857;
    background: #ffffff;
}

/* Numéro de ligne — en-tête de gauche, sélectionnable pour cibler toute la ligne */
.grid-row-num {
    padding: 0.5rem;
    text-align: center;
    font-size: 0.75rem;
    color: #9ca3af;
    background: #f8fafc;
    border-right: 1px solid #e5e7eb;
    user-select: none;
    cursor: pointer;
    width: 3rem;
}

.grid-row-num:hover {
    background: #e2e8f0;
}

.grid-row-num.row-selected {
    background: #6ee7b7;   /* emerald-300 */
    color: #064e3b;
    font-weight: 600;
}

#gridTable {
    border-collapse: collapse;
    table-layout: fixed;
}

#gridTable:focus {
    outline: none;
}

#gridTable tr.deleted-row {
    opacity: 0.4;
    text-decoration: line-through;
}