* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--background);
    color: var(--text-primary);
    font-size: var(--fs-body);
    line-height: 1.5;
}

img {
    max-width: 100%;
    display: block;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
}

input {
    font-family: inherit;
}

ul,
ol {
    list-style: none;
}

h1,
h2,
h3 {
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

h1 {
    font-size: var(--fs-h1);
}

h2 {
    font-size: 24px;
}

h3 {
    font-size: var(--fs-h3);
}

::selection {
    background: var(--primary-soft);
    color: var(--primary-dark);
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
    box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-ghost {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-ghost:hover {
    background: var(--surface-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn-danger:hover {
    background: #a92e2e;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ===== Action menu (colonne "Action" des tableaux) ===== */
.action-menu-trigger {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    transition: var(--transition);
}

.action-menu-trigger:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.crud-action-menu {
    z-index: 600;
    min-width: 190px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px;
}

.crud-action-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 12px;
    border-radius: var(--radius-sm, 6px);
    font-size: 13px;
    color: var(--text-primary);
    transition: var(--transition);
}

.crud-action-menu-item:hover {
    background: var(--surface-hover);
}

.crud-action-menu-item.danger {
    color: var(--danger);
}

.crud-action-menu-item.danger:hover {
    background: var(--danger-bg);
}

.crud-action-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 4px;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 12px;
    font-weight: 600;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--danger);
}

.badge-neutral {
    background: var(--surface-alt);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.badge-info {
    background: var(--info-bg);
    color: var(--info);
}

/* ===== Panels / cards ===== */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.panel-header h3 {
    margin-bottom: 4px;
}

.panel-sub {
    color: var(--text-muted);
    font-size: var(--fs-caption);
}

.link-action {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary);
    white-space: nowrap;
}

.link-action:hover {
    text-decoration: underline;
}

/* ===== Segmented control ===== */
.segmented {
    display: inline-flex;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 2px;
}

/* ===== Modal (composant global — agent-clients.html, programmes.html...) ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 25, 23, .55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    visibility: hidden;
    transition: opacity 160ms var(--ease), visibility 160ms var(--ease);
    padding: 20px;
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    padding: 24px;
    transform: translateY(10px);
    transition: transform 160ms var(--ease);
}

.modal-overlay.show .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}

.modal-header h3 {
    font-size: 16px;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.modal .form-group {
    margin-bottom: 16px;
}

.modal .form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 7px;
}

.modal .form-group input,
.modal .form-group select,
.modal .form-group textarea {
    width: 100%;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-size: 13.5px;
    color: var(--text-primary);
    font-family: var(--font);
}

.modal .form-group textarea {
    height: auto;
    padding: 10px 14px;
    resize: vertical;
}

.modal .form-group input:focus,
.modal .form-group select:focus,
.modal .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.modal .form-row {
    display: flex;
    gap: 12px;
}

.modal .form-row .form-group {
    flex: 1;
}

/* Sépare visuellement les groupes de champs dans un long formulaire modal
   (ex. fiche d'inscription complète) sans introduire de nouveau composant. */
.form-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin: 18px 0 10px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}

.form-section-label:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    font-size: 13.5px;
    color: var(--text-secondary);
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* Lignes répétables (ex. plusieurs programmes SABOTAY à l'inscription) */
.program-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    margin-bottom: 12px;
}

.program-row .form-group {
    flex: 1;
    margin-bottom: 0;
}

.program-row .form-group label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 7px;
}

.program-row select {
    width: 100%;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-size: 13.5px;
    color: var(--text-primary);
    transition: var(--transition);
}

.program-row select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.program-row-remove {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--danger);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.program-row-remove:hover {
    border-color: var(--danger);
    background: var(--surface-alt);
}

/* Photo de profil (js-user-initials) — remplace le fond dégradé + initiales
   par l'image choisie dans Paramètres > Profil, partout où l'avatar apparaît. */
.js-user-initials.has-photo {
    background-size: cover;
    background-position: center;
    color: transparent;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

@media (max-width: 640px) {
    .modal {
        padding: 20px;
    }
}

.segmented button {
    padding: 6px 12px;
    border-radius: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.segmented button.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.segmented button:hover:not(.active) {
    color: var(--text-primary);
}

/* ===== Barre de filtres (composant global — recherche/selects/dates) =====
   Repris à l'identique de membres.css/utilisateurs.css (où il reste défini
   en double pour ne pas toucher à ces pages déjà fonctionnelles) : centralisé
   ici pour que toute nouvelle page de liste (dépôts, versements,
   commissions, transactions, parrainages, Kredi Fidelite, journal
   d'activité...) puisse l'utiliser sans lier le CSS d'une autre page. */
.filters-panel {
    margin-bottom: 22px;
}

.filters-bar {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    flex-wrap: wrap;
}

.filter-search {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0 14px;
    height: 40px;
    flex: 1 1 260px;
    min-width: 200px;
    color: var(--text-muted);
    transition: var(--transition);
}

.filter-search:focus-within {
    border-color: var(--primary);
    background: var(--surface);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-search svg {
    flex-shrink: 0;
}

.filter-search input {
    border: none;
    background: none;
    outline: none;
    width: 100%;
    flex: 1;
    font-size: 13.5px;
    color: var(--text-primary);
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.filter-group label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
}

.filter-group .segmented {
    max-width: 100%;
    overflow-x: auto;
}

.filter-select {
    height: 40px;
    padding: 0 30px 0 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%235b6b68" stroke-width="2"><polyline points="6 9 12 15 18 9"/></svg>') no-repeat right 8px center;
    color: var(--text-primary);
    font-size: 13.5px;
    font-weight: 500;
    min-width: 180px;
    appearance: none;
    -webkit-appearance: none;
    transition: var(--transition);
    cursor: pointer;
}

.filter-select:hover {
    border-color: var(--border-strong);
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

@media (max-width: 900px) {
    .filters-bar {
        gap: 14px;
    }

    .filter-search {
        flex: 1 1 100%;
    }
}

@media (max-width: 640px) {
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group,
    .filter-select {
        width: 100%;
    }
}

/* ===== Toasts ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 14px 14px 14px 18px;
    min-width: 280px;
    max-width: 360px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 250ms var(--ease);
}

.toast-close {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 0;
    padding: 0;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.toast-close:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.success {
    border-left-color: var(--success);
}

.toast div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.toast strong {
    font-size: 13.5px;
}

.toast span {
    font-size: 12.5px;
    color: var(--text-secondary);
}

.toast.hide {
    animation: slideOut 250ms var(--ease) forwards;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(120%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    to {
        opacity: 0;
        transform: translateX(120%);
    }
}

.shake {
    animation: shake 300ms;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-6px);
    }

    75% {
        transform: translateX(6px);
    }
}
/* Tri des colonnes (sortable-table.js) — s'applique à tous les tableaux admin */
.th-sortable { cursor: pointer; user-select: none; white-space: nowrap; position: relative; }
.th-sortable:hover { color: var(--primary, #1f2f4d); }
.th-sortable::after {
  content: "";
  display: inline-block;
  width: 0; height: 0;
  margin-left: 6px;
  vertical-align: middle;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid currentColor;
  opacity: .22;
}
.th-sortable[aria-sort="ascending"]::after { opacity: .9; }
.th-sortable[aria-sort="descending"]::after { opacity: .9; transform: rotate(180deg); }
.th-sortable:focus-visible { outline: 2px solid var(--primary, #1f2f4d); outline-offset: -2px; }

/* Recherche placée directement au-dessus du tableau (public/js/table-search.js). */
.table-search-bar {
    display: flex;
    justify-content: flex-end;
    padding: 0 0 12px;
}

.table-search-bar .table-search-inline {
    flex: 0 1 320px;
    min-width: 200px;
    margin: 0;
}

@media (max-width: 600px) {
    .table-search-bar .table-search-inline { flex: 1 1 100%; }
}

/* Champs de formulaire et de filtre hors modale (panneaux, barres de filtres) :
   même rendu que les champs des modales, pour qu'aucun input ne reste nu. */
.panel .form-group { margin-bottom: 16px; }
.panel .form-group label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 7px; }
.panel .form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.panel .form-row > .form-group { flex: 1 1 220px; }
.panel .form-group input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.panel .form-group select,
.panel .form-group textarea,
.filters-bar .filter-group input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) {
    width: 100%;
    height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface);
    font-size: 13.5px;
    color: var(--text-primary);
    font-family: var(--font);
}
.filters-bar .filter-group input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { height: 40px; width: auto; min-width: 150px; font-weight: 500; }
.panel .form-group textarea { height: auto; padding: 10px 14px; resize: vertical; }
.panel .form-group input:focus,
.panel .form-group select:focus,
.panel .form-group textarea:focus,
.filters-bar .filter-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
