/**
 * Table system — Manager Vmax
 * Style global pour tous les tableaux (.table, .entity-table, wrappers).
 * Source unique : remplace les styles dupliqués dans index_pages.css, form.css, styles.css.
 * Tokens : design-tokens.css
 */

/* ── Variables Bootstrap (surcharge sans !important) ─────────────────── */

.table {
    --bs-table-bg: transparent;
    --bs-table-accent-bg: transparent;
    --bs-table-striped-bg: transparent;
    --bs-table-striped-color: var(--color-text-primary);
    --bs-table-active-bg: rgba(248, 250, 252, 0.9);
    --bs-table-hover-bg: rgba(248, 250, 252, 0.85);
    --bs-table-hover-color: var(--color-text-primary);
    --bs-table-border-color: var(--color-border);
    --bs-table-color: var(--color-text-primary);

    width: 100%;
    margin-bottom: 0;
    border-collapse: collapse;
    background: transparent;
    font-size: var(--text-body);
    color: var(--color-text-primary);
}

/* ── Conteneur carte ─────────────────────────────────────────────────── */

.entity-table-wrapper {
    width: 100%;
    background: var(--color-bg-card);
    border-radius: var(--radius-lg);
    border: var(--border-width-thin) solid var(--color-border);
    box-shadow: var(--shadow-sm) rgba(30, 41, 59, 0.06);
    margin-bottom: var(--spacing-xl);
    overflow-x: auto;
}

.entity-table-wrapper-transparent {
    background: transparent;
    box-shadow: none;
    border: none;
}

.entity-table-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.scroll-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

/* ── Cellules ────────────────────────────────────────────────────────── */

.table > :not(caption) > * > *,
.table th,
.table td {
    border: none;
    border-bottom: var(--border-width-thin) solid var(--color-border);
    padding: var(--space-md) var(--space-lg);
    text-align: left;
    vertical-align: middle;
    line-height: var(--line-height-relaxed);
    box-shadow: none;
}

.table > thead > tr > th,
.table thead th {
    background: transparent;
    color: var(--color-text-secondary);
    font-size: var(--text-label);
    font-weight: var(--font-weight-medium);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: var(--border-width-thin) solid var(--color-border);
    padding-top: var(--space-sm);
    padding-bottom: var(--space-sm);
    white-space: nowrap;
}

.table > tbody > tr:last-child > *,
.table tbody tr:last-child td,
.table tbody tr:last-child th {
    border-bottom: none;
}

/* ── Variantes Bootstrap ─────────────────────────────────────────────── */

.table-striped > tbody > tr:nth-of-type(odd) > *,
.table-striped tbody tr:nth-child(odd) > *,
.table-striped tbody tr:nth-child(odd) {
    background-color: transparent;
    --bs-table-accent-bg: transparent;
}

.table-striped > tbody > tr:nth-of-type(even) > *,
.table-striped tbody tr:nth-child(even) > *,
.table-striped tbody tr:nth-child(even) {
    background-color: transparent;
    --bs-table-accent-bg: transparent;
}

.table-hover > tbody > tr:hover > *,
.table-hover tbody tr:hover > *,
.table-hover tbody tr:hover {
    background-color: rgba(248, 250, 252, 0.85);
    --bs-table-accent-bg: rgba(248, 250, 252, 0.85);
    transition: background-color 0.15s ease;
}

.table-sm > :not(caption) > * > * {
    padding: var(--space-sm) var(--space-md);
}

.align-middle > tbody > tr > td,
.align-middle > tbody > tr > th,
.align-middle > thead > tr > th {
    vertical-align: middle;
}

/* ── Liens : jamais soulignés au repos (CDC §13 bis) ─────────────────────
   Bootstrap souligne tout <a> ; un lien vers une autre fiche (lien « nu » d'une première cellule, d'un tableau de page show,
   d'un bloc) ne porte pas de trait. :where() garde une spécificité minimale : toute classe de lien plus précise
   (entity-link, show-link-plain, bouton, onglet, menu) reste prioritaire. */
:where(.entity-table, .table, .show-card, .section, .entity-list-page, .overlay-content) a:not(.btn):not(.btn-link):not(.dropdown-item):not(.nav-link):not(.page-link) {
    text-decoration: none;
}

/* ── Modifier entity-table (listes index) ────────────────────────────── */

.entity-table {
    margin-bottom: 0;
    width: 100%;
}

.entity-table .entity-link {
    color: var(--color-primary-hover);
    text-decoration: none;
    font-weight: var(--font-weight-medium);
}

.entity-table .entity-link:hover {
    text-decoration: underline;
}

.entity-table .cell-phone {
    color: var(--color-text-secondary);
    font-size: var(--font-size-sm);
}

/* ── En-tête sticky dans conteneurs scrollables ──────────────────────── */

.entity-table-wrapper thead,
.entity-table-scroll thead,
.patient-list-body .entity-table-wrapper thead,
.entity-list-body .entity-table-wrapper thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.entity-table-wrapper thead th,
.entity-table-scroll thead th,
.patient-list-body .entity-table-wrapper thead th,
.entity-list-body .entity-table-wrapper thead th {
    background: var(--color-bg-card);
}

/* ── Cellule composée : valeur principale + détail grisé dessous ─────────── */

.table .cell-sub {
    display: block;
    color: var(--color-text-secondary);
    font-size: var(--text-label);
    font-weight: var(--font-weight-normal);
}
.table .cell-sub:empty {
    display: none;
}

/* ── Survol et lignes cliquables (balisage standard : table.entity-table) ── */

.entity-table > tbody > tr:hover > * {
    background-color: rgba(248, 250, 252, 0.85);
    transition: background-color 0.15s ease;
}

/* Une ligne qui ouvre un modal ou une page au clic (cf. cahier des charges : pas de colonne d'actions) */
.table-row--clickable {
    cursor: pointer;
}

/* ── Statuts / badges dans cellules ──────────────────────────────────── */

.table .text-success {
    color: var(--color-success);
    font-weight: var(--font-weight-medium);
}

.table .text-danger {
    color: var(--color-danger);
    font-weight: var(--font-weight-medium);
}

.table .text-warning {
    color: var(--color-warning);
    font-weight: var(--font-weight-medium);
}

.table .text-muted {
    color: var(--color-text-muted);
}

/* ── Tableaux dans grilles show / sections ───────────────────────────── */

.show-grid .entity-table-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    box-sizing: border-box;
}

.show-grid .table {
    width: 100%;
    max-width: 100%;
    table-layout: auto;
}

/* ── Utilitaires ─────────────────────────────────────────────────────── */

.table-no-margin,
.table-no-top-margin {
    margin-top: 0;
    margin-bottom: 0;
}

.table-no-margin-bottom {
    margin-bottom: 0;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ── En-têtes triables ─────────────────────────────────────────────── */

.table th.table-sortable {
    padding: 0;
}

.table-sort-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    width: 100%;
    padding: var(--space-sm) var(--space-lg);
    color: inherit;
    text-decoration: none;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    background: transparent;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    text-align: left;
}

.table-sort-link:hover {
    color: var(--color-text-primary);
}

.table-sort-link:hover .table-sort-indicator--neutral {
    color: var(--color-text-secondary);
    opacity: 1;
}

.table-sort-label {
    flex: 0 1 auto;
}

.table-sort-indicator {
    flex-shrink: 0;
    font-size: 0.625rem;
    line-height: 1;
}

.table-sort-indicator--neutral {
    color: var(--color-text-muted);
    opacity: 0.65;
}

.table-sort-indicator--asc,
.table-sort-indicator--desc {
    color: var(--color-primary);
    opacity: 1;
}

/* ===== Pagination standard (macro show_pagination.pager) : « Précédent · 1–15 sur 192 · Suivant » ===== */
.table-pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-sm);
    color: var(--color-text-muted, #6b7280);
    font-size: var(--font-size-sm);
}

.table-pager__range {
    white-space: nowrap;
}

.table-pager__btn {
    color: inherit;
    text-decoration: none;
    border: var(--border-width, 0.0625rem) solid currentColor;
    border-radius: var(--radius-md);
    padding: 0.25rem 0.6rem;
    background: transparent;
    line-height: var(--line-height-tight);
    white-space: nowrap;
}

a.table-pager__btn:hover {
    background: rgba(107, 114, 128, 0.12);
}

.table-pager__btn.is-disabled {
    opacity: 0.45;
}

/* Variante pour le bandeau foncé des pages index : texte clair, contour semi-transparent, pas de marge haute. */
.table-pager--on-dark {
    margin-top: 0;
    color: #e2e8f0;
}

.table-pager--on-dark .table-pager__btn {
    border-color: rgba(226, 232, 240, 0.45);
}

.table-pager--on-dark a.table-pager__btn:hover {
    background: rgba(226, 232, 240, 0.12);
}

/* ── Filtres d'en-tête de colonne (CDC §14) : macro table_sort.th(..., filter) + js/table-filters.js ── */

.table th.table-filterable {
    padding: 0;
}

.table-th-inner {
    display: flex;
    align-items: center;
}

.table-th-inner > .table-sort-link {
    /* Entonnoir collé au libellé de sa colonne (pas poussé contre la colonne suivante). */
    flex: 0 1 auto;
    width: auto;
    min-width: 0;
}

.table-filter-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    margin-left: var(--space-xs);
    padding: 0;
    border: none;
    border-radius: 0.375rem;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.6875rem;
    cursor: pointer;
}

.table-filter-btn:hover,
.table-filter-btn[aria-expanded="true"] {
    background: rgba(15, 23, 42, 0.08);
    color: var(--color-text-primary);
}

.table-filter-btn {
    position: relative;
}

/* Filtre actif : entonnoir teinté + pastille de la couleur de la flèche de tri (--color-primary) avec le nombre de valeurs. */
.table-filter-btn.is-active {
    background: color-mix(in srgb, var(--color-primary) 14%, #ffffff);
    color: var(--color-primary);
}

.table-filter-badge {
    position: absolute;
    top: -0.4375rem;
    right: -0.4375rem;
    min-width: 0.9375rem;
    height: 0.9375rem;
    padding: 0 0.25rem;
    box-sizing: border-box;
    border-radius: 50rem;
    background: var(--color-primary);
    color: #fff;
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 0.9375rem;
    text-align: center;
    box-shadow: 0 0 0 0.125rem #fff;
}

.table-filter-panel {
    position: fixed;
    z-index: 1200;
    box-sizing: border-box;
    width: 18rem;
    max-width: calc(100vw - 1rem);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    padding: var(--space-lg);
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.18);
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
    font-size: 0.875rem;
    color: var(--color-text-primary);
    text-align: left;
}

.table-filter-panel[hidden] {
    display: none;
}

.table-filter-input {
    box-sizing: border-box;
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.375rem;
    font: inherit;
}

.table-filter-range {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.table-filter-range > span {
    flex: 0 0 2rem;
    color: var(--color-text-secondary);
}

.table-filter-options {
    display: flex;
    flex-direction: column;
    gap: 0;
    max-height: 14rem;
    overflow-y: auto;
}

.table-filter-option {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    cursor: pointer;
}

/* Une option = une ligne pleine largeur : interrupteur à gauche, libellé à droite, sur la même ligne.
   Couvre la case brute (.table-filter-option) et sa version convertie par toggle-switch.js. */
.table-filter-options .table-filter-option,
.table-filter-options .toggle-switch-wrapper {
    display: flex;
    flex-flow: row nowrap;
    align-items: center;
    gap: var(--space-md);
    width: 100%;
    margin: 0;
    padding: 0.5rem 0.25rem;
    box-sizing: border-box;
    min-height: 2.5rem;
    border-bottom: 1px solid #f1f5f9;
}

.table-filter-options .table-filter-option:last-child,
.table-filter-options .toggle-switch-wrapper:last-child {
    border-bottom: 0;
}

.table-filter-options .toggle-switch-wrapper:hover,
.table-filter-options .table-filter-option:hover {
    background: #f8fafc;
}

.table-filter-options .toggle-switch-label,
.table-filter-options .table-filter-option > span {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.25;
    color: var(--color-text-primary);
    overflow-wrap: anywhere;
}

/* Interrupteur compact, jamais mis en bloc par un style de label global (ex. .entity-filters label) */
.table-filter-options .toggle-switch {
    display: inline-block;
    flex: 0 0 auto;
    width: 2.5rem;
    height: 1.375rem;
    margin: 0;
}

.table-filter-options .toggle-switch .toggle-slider:before {
    width: 1rem;
    height: 1rem;
    left: 0.1875rem;
    bottom: 0.1875rem;
}

.table-filter-options .toggle-switch input[type="checkbox"]:checked + .toggle-slider:before {
    transform: translateX(1.125rem);
}

.table-filter-empty {
    color: var(--color-text-muted);
}

.table-filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding-top: var(--space-md);
    border-top: 1px solid #e2e8f0;
}

/* Résumé « N résultats · Effacer les filtres » au-dessus de la pagination d'un tableau de fiche filtré. */
.table-filter-summary {
    margin: var(--space-sm) 0 0;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}
