@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');

body {
    font-family: 'Poppins', Arial, sans-serif;
    background: linear-gradient(135deg, #f9f9f9, #e3f2fd);
    color: #333;
    margin: 0;
    padding: 0;
}

.container {
    max-width: 1200px;
    margin: 30px auto 0 auto;
    padding: 0 20px 40px 20px;
}

.user-info {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 15px 20px;
    border-radius: 10px;
    text-align: center;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 25px;
}

.role-badge {
    background: linear-gradient(135deg, #6f42c1, #5a2d91);
    color: #fff;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 0.85em;
    margin-left: 10px;
    font-weight: bold;
    display: inline-block;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Role background gradients (support both capitalized and lowercase class names) */
.role-Entreprise, .role-entreprise { background: linear-gradient(135deg, #dc3545, #c82333); }
.role-Dirigeant, .role-dirigeant { background: linear-gradient(135deg, #fd7e14, #e55a00); }
.role-Lieutenant, .role-lieutenant { background: linear-gradient(135deg, #6f42c1, #5a2d91); }
.role-Responsable, .role-responsable { background: linear-gradient(135deg, #20c997, #198754); }
.role-Vendeur, .role-vendeur { background: linear-gradient(135deg, #0d6efd, #0b5ed7); }
.role-Livreur, .role-livreur { background: linear-gradient(135deg, #198754, #146c43); }
.role-Guetteur, .role-guetteur { background: linear-gradient(135deg, #ffc107, #ffca2c); color: #000; }
.role-Préparateur, .role-préparateur, .role-Preparateur, .role-preparateur { background: linear-gradient(135deg, #6610f2, #520dc2); }
.role-Ravitailleur, .role-ravitailleur { background: linear-gradient(135deg, #d63384, #b02a5b); }
.role-Standartdiste, .role-standartdiste { background: linear-gradient(135deg, #495057, #343a40); }

h1 {
    text-align: center;
    color: #444;
    margin-top: 0;
    margin-bottom: 30px;
    font-size: 28px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.comptes-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 25px;
    justify-content: center;
    margin-bottom: 40px;
}

.compte-card {
    background: #fff;
    border: 2px solid #dee2e6;
    border-radius: 12px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.08);
    padding: 25px 35px;
    min-width: 220px;
    text-align: center;
    transition: box-shadow 0.2s, transform 0.2s;
    margin-bottom: 10px;
}

.compte-card:hover {
    box-shadow: 0 8px 30px rgba(0,0,0,0.13);
    transform: translateY(-2px) scale(1.03);
}

.compte-nom {
    font-size: 18px;
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.compte-montant {
    font-size: 22px;
    font-weight: bold;
    color: #198754;
    margin-bottom: 0;
}

.forms-section {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
    justify-content: center;
    margin-bottom: 40px;
}

.form-card {
    background: #fff;
    border: 2px solid #dee2e6;
    border-radius: 15px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.10);
    padding: 35px 30px 25px 30px;
    min-width: 320px;
    max-width: 420px;
    flex: 1 1 320px;
    margin-bottom: 10px;
}

.form-card h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #444;
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.5px;
}

.form-group {
    margin-bottom: 18px;
}

.form-group label {
    display: block;
    margin-bottom: 7px;
    font-weight: 600;
    color: #333;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ced4da;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    font-weight: 500;
    transition: border-color 0.3s, box-shadow 0.3s;
    background-color: #fff;
    box-sizing: border-box;
    margin-bottom: 0;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.13);
}

.form-card button[type="submit"] {
    width: 100%;
    padding: 14px 0;
    background: #007bff;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: background 0.2s, transform 0.2s;
    margin-top: 10px;
    box-shadow: 0 4px 15px rgba(0,123,255,0.13);
}

.form-card button[type="submit"]:hover {
    background: #0056b3;
    transform: translateY(-2px);
}

.success-message, .error-message {
    max-width: 650px;
    margin: 20px auto;
    padding: 15px 20px;
    border-radius: 8px;
    font-weight: 600;
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.08);
    font-size: 16px;
}

.success-message {
    color: #155724;
    background: #d4edda;
    border: 2px solid #c3e6cb;
}

.error-message {
    color: #721c24;
    background: #f8d7da;
    border: 2px solid #f5c6cb;
}

/* Montants colorés dans l'historique */
.montant-positif {
    color: #155724;
    font-weight: bold;
    background: linear-gradient(135deg, #d4edda, #c3e6cb);
    padding: 4px 10px;
    border-radius: 6px;
    display: inline-block;
}

.montant-negatif {
    color: #721c24;
    font-weight: bold;
    background: linear-gradient(135deg, #f8d7da, #f5c6cb);
    padding: 4px 10px;
    border-radius: 6px;
    display: inline-block;
}

.historique-table td.montant-cell {
    text-align: center !important;
}

/* Historique */
.historique-section {
    margin-top: 40px;
    background: #fff;
    border: 2px solid #dee2e6;
    border-radius: 15px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.10);
    padding: 35px 20px 25px 20px;
}

.historique-section h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #444;
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    letter-spacing: 0.5px;
}

.historique-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    font-size: 14px;
    margin: 0 auto;
}

.historique-table th, .historique-table td {
    padding: 12px 8px;
    text-align: center;
    border-bottom: 1px solid #eee;
    font-size: 13px;
}

.historique-table th {
    background: #f4f4f4;
    color: #333;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #ddd;
    font-size: 12px;
}

.historique-table tr:nth-child(even) {
    background: #fafafa;
}

.historique-table tr:hover {
    background: #f0f0f0;
}

.historique-table td {
    color: #333;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.description-dir {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.desc-prefix {
    font-weight: 600;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    border: 0;
    background: transparent;
    letter-spacing: 0;
}

.desc-prefix.is-depuis {
    color: #0f766e;
}

.desc-prefix.is-vers {
    color: #1d4ed8;
}

.desc-text {
    color: #1f2937;
    font-weight: 500;
}

.historique-table td.transfert {
    color: #007bff;
    font-weight: bold;
}

.historique-hidden {
    display: none;
}

.delete-actions {
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.btn-toggle-all,
.btn-delete-selected,
.btn-toggle-historique {
    border: none;
    border-radius: 9px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .16s ease, box-shadow .16s ease, background .2s ease;
}

.btn-toggle-all {
    background: linear-gradient(135deg, #2b8ef2, #1478de);
    color: #fff;
    box-shadow: 0 6px 14px rgba(20, 120, 222, 0.25);
}

.btn-delete-selected {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    box-shadow: 0 6px 14px rgba(220, 38, 38, 0.22);
}

.btn-toggle-historique {
    margin: 16px auto 0;
    display: block;
    background: linear-gradient(135deg, #22a447, #18863a);
    color: #fff;
    box-shadow: 0 6px 14px rgba(24, 134, 58, 0.22);
}

.btn-toggle-all:hover,
.btn-delete-selected:hover,
.btn-toggle-historique:hover {
    transform: translateY(-1px);
    filter: brightness(0.97);
}

.delete-checkbox,
#select-all {
    cursor: pointer;
    width: 17px;
    height: 17px;
    accent-color: #2563eb;
}

.historique-table th {
    background: linear-gradient(180deg, #f8fafc 0%, #edf2f9 100%);
    color: #24364d;
    border-bottom: 2px solid #dbe4f0;
}

.historique-table tr:nth-child(even) {
    background: #fbfdff;
}

.historique-table tr:hover {
    background: #eef5ff;
}

.historique-table td:nth-child(4),
.historique-table th:nth-child(4) {
    min-width: 240px;
    max-width: 420px;
    width: 280px;
    transition: width 0.24s ease, max-width 0.24s ease;
}

.historique-table td.compte-expanded {
    width: 560px;
    max-width: 760px;
}

.voir-plus-btn {
    border: 1px solid #c7d2fe;
    background: #eef2ff;
    color: #3730a3;
    border-radius: 6px;
    padding: 3px 9px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 4px;
    transition: background .15s ease, border-color .15s ease;
}

.voir-plus-btn:hover {
    background: #e0e7ff;
    border-color: #a5b4fc;
}

.compte-full-text,
.compte-truncated {
    word-break: break-word;
}

/* Modal confirmation suppression historique */
.cd-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    transition: opacity .16s ease;
}

.cd-modal.is-open {
    opacity: 1;
    pointer-events: auto;
}

.cd-modal-card {
    width: min(92vw, 460px);
    background: #fff;
    border: 1px solid #dbe4f0;
    border-radius: 12px;
    box-shadow: 0 16px 38px rgba(15, 23, 42, 0.22);
    padding: 18px 18px 16px;
}

.cd-modal-title {
    margin: 0 0 8px;
    font-size: 20px;
    font-weight: 700;
    color: #1f2937;
}

.cd-modal-text {
    margin: 0;
    color: #334155;
    line-height: 1.45;
}

.cd-modal-actions {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.cd-modal-btn {
    border: none;
    border-radius: 8px;
    padding: 9px 14px;
    font-weight: 600;
    cursor: pointer;
}

.cd-modal-btn.cancel {
    background: #e2e8f0;
    color: #334155;
}

.cd-modal-btn.confirm {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
}

@media (max-width: 900px) {
    .comptes-grid, .forms-section {
        flex-direction: column;
        gap: 20px;
        align-items: stretch;
    }
    .compte-card, .form-card {
        min-width: unset;
        max-width: 100%;
    }
    .historique-section {
        padding: 20px 5px;
    }

    .delete-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-toggle-all,
    .btn-delete-selected,
    .btn-toggle-historique {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 0 5px 30px 5px;
    }
    .user-info {
        font-size: 13px;
        padding: 10px 5px;
    }
    h1 {
        font-size: 20px;
        margin-bottom: 18px;
    }
    .compte-nom {
        font-size: 15px;
    }
    .compte-montant {
        font-size: 17px;
    }
    .form-card h3, .historique-section h3 {
        font-size: 16px;
    }
    .form-card, .compte-card {
        padding: 18px 8px;
    }
    .historique-table th, .historique-table td {
        padding: 8px 4px;
        font-size: 11px;
    }
}

/* Custom select (volet déroulant + liste) */
.custom-select-native {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    pointer-events: none !important;
}

.cds-select {
    position: relative;
    width: 100%;
}

.cds-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: 2px solid #ced4da;
    border-radius: 8px;
    background: #fff;
    color: #1f2937;
    font-size: 15px;
    font-weight: 500;
    padding: 12px 40px 12px 16px;
    text-align: left;
    cursor: pointer;
    position: relative;
    transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}

.cds-trigger:hover {
    background: #f8fbff;
}

.cds-trigger:focus-visible,
.cds-select.open .cds-trigger {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0,123,255,0.13);
}

.cds-trigger::after {
    content: '';
    position: absolute;
    right: 14px;
    top: 50%;
    width: 8px;
    height: 8px;
    border-right: 2px solid #475569;
    border-bottom: 2px solid #475569;
    transform: translateY(-65%) rotate(45deg);
    transition: transform .16s ease;
}

.cds-select.open .cds-trigger::after {
    transform: translateY(-35%) rotate(-135deg);
}

.cds-menu {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 1200;
    border: 1px solid #dbe4f0;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 14px 30px rgba(15,23,42,0.16);
    max-height: 260px;
    overflow-y: auto;
    padding: 6px;
    display: none;
}

.cds-select.open .cds-menu {
    display: block;
}

.cds-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #1f2937;
    text-align: left;
    padding: 9px 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.cds-option:hover {
    background: #eef5ff;
}

.cds-option.active {
    background: #eaf2ff;
    color: #1e40af;
    font-weight: 600;
}

.cds-prefix {
    display: inline;
    font-size: 12px;
    font-weight: 600;
    border-radius: 0;
    padding: 0;
    line-height: 1;
    white-space: nowrap;
    background: transparent;
    border: 0;
}

.cds-prefix.is-depuis {
    color: #0f766e;
}

.cds-prefix.is-vers {
    color: #1d4ed8;
}

.cds-rest {
    color: inherit;
}