@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
    --bg-1: #f5f9ff;
    --bg-2: #eef3fb;
    --text-1: #1f2937;
    --text-2: #4b5563;
    --card: #ffffff;
    --line: #e5e7eb;
    --primary: #2563eb;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --radius: 14px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Poppins', Arial, sans-serif;
    color: var(--text-1);
    background: radial-gradient(circle at top right, #e7f0ff 0%, var(--bg-1) 45%, var(--bg-2) 100%);
}

.content {
    max-width: 1240px;
    margin: 28px auto 0;
    padding: 0 20px 40px;
}

.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.1);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 20px;
}

.online-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #28a745;
    margin-right: 8px;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px;
    border-radius: 999px;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}

.role-badge.role-Entreprise, .role-badge.role-entreprise { background: linear-gradient(135deg, #dc3545, #c82333); }
.role-badge.role-Dirigeant, .role-badge.role-dirigeant { background: linear-gradient(135deg, #fd7e14, #e55a00); }
.role-badge.role-Lieutenant, .role-badge.role-lieutenant { background: linear-gradient(135deg, #6f42c1, #5a2d91); }
.role-badge.role-Responsable, .role-badge.role-responsable { background: linear-gradient(135deg, #20c997, #198754); }
.role-badge.role-Vendeur, .role-badge.role-vendeur { background: linear-gradient(135deg, #0d6efd, #0b5ed7); }
.role-badge.role-Livreur, .role-badge.role-livreur { background: linear-gradient(135deg, #198754, #146c43); }
.role-badge.role-Guetteur, .role-badge.role-guetteur { background: linear-gradient(135deg, #ffc107, #ffca2c); color: #111827; }
.role-badge.role-Préparateur, .role-badge.role-préparateur, .role-badge.role-Preparateur, .role-badge.role-preparateur { background: linear-gradient(135deg, #6610f2, #520dc2); }
.role-badge.role-Ravitailleur, .role-badge.role-ravitailleur { background: linear-gradient(135deg, #d63384, #b02a5b); }
.role-badge.role-Standartdiste, .role-badge.role-standartdiste { background: linear-gradient(135deg, #495057, #343a40); }

.logout-link {
    color: var(--danger);
    text-decoration: none;
    margin-left: 10px;
    font-weight: 700;
    transition: color 0.2s ease;
}

.logout-link:hover {
    color: #b02a37;
}

h1 {
    margin-top: 0;
    margin-bottom: 30px;
    text-align: center;
    color: #444;
    font-size: 28px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
}

.stat-info h3 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--success);
}

.stat-info p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-2);
    font-weight: 500;
}

.table-container {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.table-header {
    padding: 20px 22px 12px;
}

.table-header h2 {
    margin: 0;
    font-size: 20px;
}

.table-wrapper {
    overflow-x: auto;
    padding: 0 12px 14px;
}

.salaries-table {
    width: 100%;
    min-width: 900px;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 13px;
}

.salaries-table th,
.salaries-table td {
    padding: 12px 10px;
    text-align: center;
    border-bottom: 1px solid #edf2f7;
}

.salaries-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.45px;
    color: #374151;
    background: linear-gradient(180deg, #f9fbff, #f2f6fd);
}

.salaries-table th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.salaries-table th.sortable:hover {
    background: linear-gradient(180deg, #eff6ff, #e6f0ff);
}

.salaries-table th .sort-indicator {
    margin-left: 6px;
    color: #64748b;
    font-size: 12px;
    font-weight: 700;
}

.salaries-table tbody tr {
    transition: background-color 0.18s ease;
}

.salaries-table tbody tr:hover {
    background: #f8fbff;
}

.salary-amount {
    font-weight: 700;
    color: var(--success);
}

.mission-count {
    font-weight: 700;
    color: var(--primary);
}

.user-cell {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.user-avatar {
    display: none;
}

.action-buttons {
    display: inline-flex;
    gap: 8px;
}

.btn-pay,
.btn-view,
.btn-edit-mission,
.btn-delete-mission,
.btn-cancel,
.btn-pay-submit {
    border: none;
    border-radius: 10px;
    padding: 8px 13px;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.16s ease, filter 0.16s ease;
}

.btn-pay:hover,
.btn-view:hover,
.btn-edit-mission:hover,
.btn-delete-mission:hover,
.btn-cancel:hover,
.btn-pay-submit:hover:not(:disabled) {
    transform: translateY(-1px);
    filter: brightness(1.03);
}

.btn-pay { background: linear-gradient(135deg, #16a34a, #10b981); }
.btn-view { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.btn-edit-mission { background: linear-gradient(135deg, #f59e0b, #d97706); }
.btn-delete-mission { background: linear-gradient(135deg, #ef4444, #dc2626); }
.btn-cancel { background: linear-gradient(135deg, #ef4444, #dc2626); }
.btn-pay-submit { background: linear-gradient(135deg, #16a34a, #10b981); }

.btn-pay-submit:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    overflow-y: auto;
    padding: 20px 0;
    background: rgba(2, 6, 23, 0.58);
    backdrop-filter: blur(4px);
}

.modal-content {
    width: min(92%, 860px);
    max-height: 92vh;
    margin: 2% auto;
    background: #fff;
    border-radius: 18px;
    border: 1px solid #e6ebf2;
    box-shadow: 0 24px 50px rgba(2, 6, 23, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.22s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-14px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px 10px;
    border-bottom: 1px solid #eef2f7;
}

.modal-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 700;
}

.modal-header .close {
    font-size: 30px;
    line-height: 1;
    color: #64748b;
    cursor: pointer;
}

.modal-header .close:hover {
    color: #ef4444;
}

.payment-form,
.history-content {
    padding: 20px 22px 24px;
    overflow-y: auto;
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    letter-spacing: 0.3px;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    font-family: inherit;
    color: #111827;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.18);
}

.native-select-hidden {
    position: absolute !important;
    opacity: 0 !important;
    pointer-events: none !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}

.mission-select {
    position: relative;
}

.mission-select-trigger {
    width: 100%;
    min-height: 44px;
    padding: 11px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    font-size: 14px;
    font-family: inherit;
    color: #111827;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    cursor: pointer;
    text-align: left;
}

.mission-select-trigger:hover {
    border-color: #93c5fd;
}

.mission-select-trigger:focus,
.mission-select-trigger[aria-expanded="true"] {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 4px rgba(96, 165, 250, 0.18);
}

.mission-select-label {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mission-select-chevron {
    color: #64748b;
    font-size: 14px;
    transition: transform 0.2s ease;
}

.mission-select-trigger[aria-expanded="true"] .mission-select-chevron {
    transform: rotate(180deg);
}

.mission-select-panel {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    z-index: 1200;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
    padding: 10px;
}

.mission-select-search {
    width: 100%;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 9px;
    font-size: 13px;
    margin-bottom: 8px;
}

.mission-select-search:focus {
    outline: none;
    border-color: #60a5fa;
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.16);
}

.mission-select-options {
    max-height: 270px;
    overflow-y: auto;
    border-radius: 8px;
}

.mission-select-group {
    padding: 4px 0 8px;
}

.mission-select-group + .mission-select-group {
    border-top: 1px dashed #e2e8f0;
}

.mission-select-group-title {
    padding: 6px 8px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    color: #64748b;
}

.mission-select-option {
    width: 100%;
    border: 0;
    border-radius: 8px;
    background: transparent;
    text-align: left;
    padding: 8px 10px;
    font-size: 13px;
    color: #1f2937;
    cursor: pointer;
}

.mission-select-option:hover {
    background: #eff6ff;
}

.mission-select-option.is-selected {
    background: #dbeafe;
    color: #1d4ed8;
    font-weight: 600;
}

.mission-select-option.placeholder-option {
    color: #6b7280;
    font-style: italic;
}

.mission-select-empty {
    padding: 10px;
    text-align: center;
    color: #64748b;
    font-size: 13px;
    font-style: italic;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.total-section {
    margin: 14px 0;
    padding: 14px;
    border-radius: 12px;
    background: linear-gradient(135deg, #ecfdf5, #d1fae5);
    border: 1px solid #bbf7d0;
    text-align: center;
}

.total-display strong {
    font-size: 19px;
    color: #065f46;
}

.form-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
}

.history-table {
    width: 100%;
    margin-top: 12px;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    overflow: hidden;
}

.history-table th,
.history-table td {
    padding: 10px;
    border-bottom: 1px solid #edf2f7;
    text-align: left;
}

.history-table th {
    background: #f8fafc;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #475569;
}

.history-table tbody tr:hover {
    background: #f8fbff;
}

.mission-title {
    font-weight: 600;
    color: #1f2937;
}

.mission-date {
    color: #6b7280;
    font-size: 12px;
}

.mission-amount {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    background: linear-gradient(135deg, #16a34a, #10b981);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.no-missions {
    text-align: center;
    color: #64748b;
    font-style: italic;
    padding: 34px 16px;
}

.history-modal-header-block {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid #e5edfa;
    border-radius: 12px;
    background: linear-gradient(180deg, #f9fbff, #f2f7ff);
}

.history-modal-title {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
}

.history-modal-subtitle {
    margin: 4px 0 0;
    color: #64748b;
    font-size: 13px;
}

.history-summary {
    display: flex;
    align-items: center;
    gap: 8px;
}

.summary-chip {
    min-width: 112px;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #dbe5f3;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.summary-label {
    font-size: 11px;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.summary-chip strong {
    font-size: 14px;
    color: #1f2937;
}

.summary-chip-location {
    border-color: #bfdbfe;
    background: linear-gradient(180deg, #f8fbff, #edf4ff);
}

.summary-location-name {
    display: block;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #1e3a8a;
}

.summary-location-count {
    margin-top: 3px;
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid #bfdbfe;
    background: #ffffff;
    color: #1d4ed8;
    font-size: 11px;
    font-weight: 600;
}

.summary-chip-success {
    border-color: #bbf7d0;
    background: #ecfdf5;
}

.summary-chip-success strong {
    color: #166534;
}

.history-sales-summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(140px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.history-sales-summary .summary-chip {
    min-width: 0;
}

.money-cell {
    font-variant-numeric: tabular-nums;
    color: #0f172a;
}

.history-actions-cell {
    white-space: nowrap;
}

.history-actions-cell .btn-edit-mission,
.history-actions-cell .btn-delete-mission {
    margin-right: 6px;
}

.history-actions-cell .btn-delete-mission {
    margin-right: 0;
}

.alert {
    max-width: 760px;
    margin: 14px auto 20px;
    padding: 13px 16px;
    border-radius: 12px;
    font-weight: 600;
    text-align: center;
    border: 1px solid transparent;
}

.alert-success {
    color: #166534;
    background: #ecfdf5;
    border-color: #bbf7d0;
}

.alert-error {
    color: #991b1b;
    background: #fef2f2;
    border-color: #fecaca;
}

@media (max-width: 980px) {
    .stats-container {
        grid-template-columns: 1fr;
    }

    .salaries-table {
        min-width: 700px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .form-actions button {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .content {
        padding: 0 10px 28px;
    }

    .user-info {
        font-size: 13px;
        justify-content: flex-start;
    }

    h1 {
        font-size: 22px;
        margin-bottom: 18px;
    }

    .table-header {
        padding: 16px 14px 10px;
    }

    .table-wrapper {
        padding: 0 8px 10px;
    }

    .modal-content {
        width: 96%;
        max-height: 95vh;
        margin: 2.5% auto;
    }

    .modal-header h2 {
        font-size: 18px;
    }

    .payment-form,
    .history-content {
        padding: 14px;
    }

    .history-modal-header-block {
        flex-direction: column;
    }

    .history-summary {
        width: 100%;
    }

    .history-sales-summary {
        grid-template-columns: 1fr;
    }

    .summary-chip {
        flex: 1;
    }
}