@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
    --page-bg: linear-gradient(135deg, #f9f9f9, #e3f2fd);
    --card-bg: #ffffff;
    --card-border: #dee2e6;
    --text-main: #333;
    --text-soft: #64748b;
    --muted: #94a3b8;
    --brand-blue: #007bff;
    --brand-blue-dark: #0056b3;
    --ok: #198754;
    --danger: #dc3545;
    --shadow-soft: 0 8px 25px rgba(0, 0, 0, 0.15);
    --shadow-strong: 0 14px 32px rgba(15, 23, 42, 0.2);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Poppins', Arial, sans-serif;
    color: var(--text-main);
    background: var(--page-bg);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

h1 {
    text-align: center;
    color: #444;
    margin-top: 0;
    margin-bottom: 30px;
    font-size: 28px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
}

h2 {
    color: #444;
    margin-top: 32px;
    margin-bottom: 18px;
    text-align: center;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

h3 {
    margin: 0 0 12px;
    font-size: 18px;
    color: #31465e;
}

.user-container {
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 20px;
}

.user-info {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 15px 20px;
    border-radius: 10px;
    border: 1px solid #dee2e6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
    font-size: 16px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.online-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #28a745;
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.55);
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.5); }
    70% { box-shadow: 0 0 0 9px rgba(40, 167, 69, 0); }
    100% { box-shadow: 0 0 0 0 rgba(40, 167, 69, 0); }
}

.role-badge {
    color: #fff;
    padding: 4px 12px;
    border-radius: 14px;
    font-size: 0.82em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.role-Entreprise, .role-entreprise { background: linear-gradient(135deg, #dc3545, #b81f2d); }
.role-Dirigeant, .role-dirigeant { background: linear-gradient(135deg, #fd7e14, #de5e00); }
.role-Lieutenant, .role-lieutenant { background: linear-gradient(135deg, #6f42c1, #56319b); }
.role-Responsable, .role-responsable { background: linear-gradient(135deg, #20c997, #168f6c); }
.role-Vendeur, .role-vendeur { background: linear-gradient(135deg, #0d6efd, #0b58ca); }
.role-Livreur, .role-livreur { background: linear-gradient(135deg, #198754, #13653f); }
.role-Guetteur, .role-guetteur { background: linear-gradient(135deg, #ffc107, #f0b106); color: #1f2937; }
.role-Préparateur, .role-préparateur, .role-Preparateur, .role-preparateur { background: linear-gradient(135deg, #6610f2, #4d0cb8); }
.role-Ravitailleur, .role-ravitailleur { background: linear-gradient(135deg, #d63384, #a82765); }
.role-Standartdiste, .role-standartdiste { background: linear-gradient(135deg, #495057, #32373c); }

.logout-link {
    color: #dc3545;
    text-decoration: none;
    margin-left: 15px;
    font-weight: bold;
    padding: 5px 10px;
    border-radius: 5px;
    transition: all 0.3s ease;
}

.logout-link:hover {
    background-color: #dc3545;
    color: white;
    text-decoration: none;
}

.success-message,
.error-message,
.count-info {
    max-width: 1200px;
    margin: 20px auto;
    border-radius: 8px;
    padding: 15px 20px;
    font-weight: 600;
}

.success-message {
    color: #155724;
    background: #d4edda;
    border: 2px solid #c3e6cb;
    box-shadow: 0 4px 15px rgba(21, 87, 36, 0.2);
}

.error-message {
    color: #721c24;
    background: #f8d7da;
    border: 2px solid #f5c6cb;
    box-shadow: 0 4px 15px rgba(114, 28, 36, 0.2);
}

.count-info {
    color: #444;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    box-shadow: none;
}

.section {
    background: var(--card-bg);
    border: 2px solid var(--card-border);
    border-radius: 15px;
    padding: 24px;
    margin: 0 auto 30px;
    box-shadow: var(--shadow-soft);
}

.section::before {
    display: none;
}

.no-data {
    text-align: center;
    padding: 18px;
    color: var(--text-soft);
    background: #f8f9fa;
    border: 1px dashed #ced4da;
    border-radius: 10px;
    font-weight: 600;
}

.table-container {
    width: 100%;
    overflow-x: auto;
    margin: 20px auto;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.table-container table {
    width: 100%;
    min-width: 3200px;
    border-collapse: collapse;
    font-size: 13px;
}

.table-container thead th {
    position: sticky;
    top: 0;
    z-index: 12;
    background: linear-gradient(180deg, #f9fbff 0%, #edf2f9 100%);
    color: #1f3650;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    border-right: 1px solid #e5edf7;
    padding: 14px 12px;
    font-size: 12px;
    white-space: nowrap;
}

.table-container thead th:first-child {
    border-top-left-radius: 12px;
}

.table-container thead th:last-child {
    border-top-right-radius: 12px;
}

.table-container tbody tr {
    transition: background .18s ease;
}

.table-container tbody tr:nth-child(even) {
    background: #fbfcfe;
}

.table-container tbody tr:hover {
    background: #f2f6ff;
}

.table-container td {
    border-bottom: 1px solid #eef2f7;
    border-right: 1px solid #f1f5f9;
    padding: 12px 10px;
    color: #1f2937;
    text-align: center;
    vertical-align: middle;
    font-size: 13px;
    min-width: 150px;
}

.table-container td:last-child,
.table-container th:last-child {
    border-right: none;
}

/* Colonnes larges */
.table-container td:nth-child(14), .table-container th:nth-child(14) {
    min-width: 300px;
    max-width: 420px;
}

.table-container td:nth-child(21),
.table-container td:nth-child(22),
.table-container td:nth-child(23),
.table-container th:nth-child(21),
.table-container th:nth-child(22),
.table-container th:nth-child(23) {
    min-width: 250px;
}

.hidden-row {
    display: none;
}

.editable-field {
    width: 100%;
    border: 1px solid #d0dae6;
    border-radius: 8px;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 13px;
    color: #213347;
    background: #fdfefe;
    transition: border-color .2s ease, box-shadow .2s ease;
}

.editable-field:focus {
    border-color: #4d86da;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
    outline: none;
}

.editable-description {
    min-height: 78px;
    resize: vertical;
    line-height: 1.45;
}

tr.edit-mode {
    background: #fff3cd !important;
    box-shadow: inset 0 0 0 2px #ffc107;
}

.quantite-cell.qte-low { background: #fffaf0; color: #8a5a00; font-weight: 700; }
.quantite-cell.qte-medium { background: #f3f8ff; color: #215ea9; font-weight: 700; }
.quantite-cell.qte-high { background: #f1fbf4; color: #1e7d48; font-weight: 700; }
.quantite-cell.qte-critical { background: #fdf3f5; color: #a11f3a; font-weight: 700; }

.image-preview {
    width: 62px;
    height: 62px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid #d7e1ee;
    cursor: zoom-in;
    transition: transform .2s ease, box-shadow .2s ease;
}

.image-preview:hover {
    transform: scale(1.45);
    box-shadow: var(--shadow-strong);
    z-index: 9;
    position: relative;
}

.video-preview {
    width: 150px;
    max-height: 96px;
    border-radius: 10px;
    border: 1px solid #d7e1ee;
    background: #000;
}

.no-image,
.no-video {
    color: var(--muted);
    font-style: italic;
    font-size: 12px;
}

.chiffre-cell {
    min-width: 260px;
}

.chiffre-info {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px;
    display: grid;
    gap: 6px;
    text-align: left;
}

.chiffre-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 5px 8px;
    border-radius: 7px;
    background: #fff;
    border: 1px solid #eef2f7;
}

.chiffre-label {
    color: #4a5b70;
    font-weight: 600;
}

.chiffre-value {
    font-weight: 700;
    color: #1f3852;
}

.chiffre-ca .chiffre-value { color: #1455a0; }
.chiffre-cout .chiffre-value { color: #956307; }
.chiffre-benefice .chiffre-value { color: #197a49; }

.price-g-container {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #dee2e6;
    background: #f8f9fa;
    font-weight: 600;
    color: #1f2937;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.actions-cell {
    min-width: 290px;
}

.action-buttons,
.edit-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.edit-buttons {
    display: none;
    margin-top: 8px;
}

.btn-action,
.btn-save-edit,
.btn-cancel-edit,
.btn-show-all,
.btn-cancel,
.btn-confirm,
.btn-cancel-modal,
.btn-save-modal,
.btn-upload,
.btn-remove-image,
.btn-remove-video,
.btn-back {
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: inherit;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease, filter .2s ease;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-action:hover,
.btn-save-edit:hover,
.btn-cancel-edit:hover,
.btn-show-all:hover,
.btn-cancel:hover,
.btn-confirm:hover,
.btn-cancel-modal:hover,
.btn-save-modal:hover,
.btn-upload:hover,
.btn-remove-image:hover,
.btn-remove-video:hover,
.btn-back:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(15, 23, 42, 0.15);
}

.btn-view { background: #007bff; color: #fff; }
.btn-view:hover { background: #0056b3; }

.btn-edit { background: #ffc107; color: #212529; }
.btn-edit:hover { background: #e0a800; color: #212529; }

.btn-delete,
.btn-confirm { background: #dc3545; color: #fff; }
.btn-delete:hover,
.btn-confirm:hover { background: #c82333; }

.btn-complete,
.btn-save-edit,
.btn-save-modal { background: #198754; color: #fff; }
.btn-complete:hover,
.btn-save-edit:hover,
.btn-save-modal:hover { background: #146c43; }

.btn-cancel-complete,
.btn-cancel-edit,
.btn-cancel,
.btn-cancel-modal { background: #6c757d; color: #fff; }
.btn-cancel-complete:hover,
.btn-cancel-edit:hover,
.btn-cancel:hover,
.btn-cancel-modal:hover { background: #5a6268; }

.btn-show-all {
    margin: 14px auto 4px;
    display: flex;
    padding: 10px 14px;
    border: 1px solid #d5deeb;
    background: #ffffff;
    color: #1f2f44;
    border-radius: 8px;
}

.btn-show-all.showing-all {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #334155;
}

.back-link {
    text-align: center;
    margin-top: 26px;
}

.btn-back {
    padding: 10px 18px;
    font-size: 12px;
    background: #6c757d;
    color: #fff;
}

.btn-back:hover {
    background: #5a6268;
}

.modal,
.modal-detail,
.edit-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1400;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
}

.modal-content,
.modal-detail-content,
.edit-modal-content {
    background: #fff;
    border-radius: 15px;
    border: 2px solid #dee2e6;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.modal {
    align-items: center;
    justify-content: center;
}

#deleteModal {
    display: none;
}

#deleteModal .modal-content {
    width: min(560px, 92vw);
    margin: 9vh auto;
    padding: 30px;
    text-align: center;
}

.price-info {
    margin: 12px 0 8px;
    padding: 9px 10px;
    border-radius: 8px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    color: #333;
    font-weight: 700;
}

.warning {
    color: #a53a45;
    font-weight: 600;
    margin: 0 0 14px;
}

.modal-buttons {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

.modal-detail {
    overflow: auto;
}

.modal-detail-content {
    width: min(1000px, 94vw);
    margin: 5vh auto;
    padding: 30px;
    position: relative;
}

.close-detail {
    position: absolute;
    top: 18px;
    right: 22px;
    font-size: 2.1em;
    cursor: pointer;
    color: #555;
    font-weight: bold;
    transition: color 0.3s;
}

.close-detail:hover {
    color: #007bff;
}

.detail-body {
    margin-top: 14px;
}

.detail-loading {
    text-align: center;
    padding: 26px;
    color: #4b5563;
    font-weight: 600;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    background: #f8f9fa;
}

.produits-list {
    display: grid;
    gap: 16px;
}

.produit-card {
    border: 1px solid #dee2e6;
    border-radius: 15px;
    background: #ffffff;
    padding: 20px;
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 14px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.produit-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

.produit-image img {
    width: 100%;
    height: 128px;
    object-fit: cover;
    border-radius: 10px;
    border: 1px solid #d7e1ee;
    cursor: zoom-in;
}

.produit-image-placeholder {
    width: 100%;
    height: 128px;
    border-radius: 10px;
    border: 2px dashed #ced4da;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6b7280;
    font-weight: 600;
}

.produit-main {
    display: grid;
    gap: 12px;
}

.produit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.produit-title {
    margin: 0;
    font-size: 22px;
    color: #1f2f44;
    font-weight: 700;
}

.produit-badge {
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid #cfe2ff;
    background: #eaf3ff;
    color: #1b4f8a;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.produit-info-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 8px;
}

.produit-info-item {
    background: #f8fafc;
    border: 1px solid #e3e8ef;
    border-radius: 9px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.produit-info-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: #64748b;
    font-weight: 700;
}

.produit-info-value {
    color: #1f2937;
    font-weight: 600;
    line-height: 1.35;
}

.produit-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(130px, 1fr));
    gap: 10px;
}

.metric-card {
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 10px;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-label {
    color: #64748b;
    font-size: 12px;
    font-weight: 600;
}

.metric-value {
    color: #1e3a5f;
    font-size: 18px;
    font-weight: 700;
}

.produit-description {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 10px;
    padding: 10px 12px;
}

.produit-description h4 {
    margin: 0 0 6px;
    color: #334155;
    font-size: 14px;
    font-weight: 700;
}

.produit-description p {
    margin: 0;
    color: #374151;
    line-height: 1.5;
    white-space: pre-wrap;
}

.produit-footer {
    border-top: 1px solid #e5e7eb;
    padding-top: 8px;
    color: #6b7280;
    font-size: 12px;
    font-weight: 500;
}

.edit-modal {
    overflow: auto;
}

.edit-modal-content {
    width: min(1080px, 95vw);
    margin: 4vh auto;
    overflow: hidden;
}

.edit-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: #f8f9fa;
    border-bottom: 2px solid #dee2e6;
}

.edit-modal-header h2 {
    margin: 0;
    width: 100%;
    text-align: center;
    color: #444;
    font-size: 22px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.close-edit,
.close {
    font-size: 2.1em;
    color: #555;
    cursor: pointer;
    line-height: 1;
    font-weight: bold;
    transition: color 0.3s;
}

.close-edit:hover,
.close:hover {
    color: #007bff;
}

.edit-modal-body {
    padding: 24px;
    max-height: 72vh;
    overflow: auto;
}

.edit-form {
    display: grid;
    gap: 14px;
}

.form-section {
    border: 1px solid #dee2e6;
    border-radius: 10px;
    background: #ffffff;
    padding: 18px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-group {
    margin-bottom: 10px;
}

.form-group-placeholder {
    visibility: hidden;
    pointer-events: none;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: #333;
    font-size: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-control {
    width: 100%;
    border: 2px solid #ced4da;
    border-radius: 8px;
    padding: 12px 16px;
    font-family: inherit;
    font-size: 15px;
    color: #333;
    background: #fff;
}

.form-control:focus {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.2);
    outline: none;
}

.image-upload-zone,
.video-upload-zone {
    display: grid;
    gap: 10px;
}

.current-image-preview,
.current-video-preview {
    min-height: 170px;
    border: 2px dashed #007bff;
    border-radius: 10px;
    background: #f8f9fa;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.current-image-preview img,
.current-video-preview video {
    max-width: 100%;
    max-height: 260px;
    border-radius: 10px;
}

.no-image-placeholder,
.no-video-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #6e7f95;
    gap: 8px;
}

.icon-image,
.icon-video {
    font-size: 30px;
}

.upload-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-upload {
    background: #007bff;
    color: #fff;
}

.btn-upload:hover {
    background: #0056b3;
}

.btn-remove-image,
.btn-remove-video {
    background: #dc3545;
    color: #fff;
}

.btn-remove-image:hover,
.btn-remove-video:hover {
    background: #c82333;
}

.edit-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 18px 24px;
    border-top: 2px solid #dee2e6;
    background: #f8f9fa;
}

#imageModal {
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-image {
    max-width: 90vw;
    max-height: 86vh;
    border-radius: 15px;
    border: 2px solid #dee2e6;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.8);
}

#imageModal .close {
    position: absolute;
    top: 20px;
    right: 24px;
    color: #fff;
    font-size: 36px;
}

@media (max-width: 1024px) {
    .container {
        padding: 14px 12px 32px;
    }

    h1 {
        font-size: 24px;
    }

    .section {
        padding: 16px;
        border-radius: 14px;
    }

    .produit-card {
        grid-template-columns: 1fr;
    }

    .produit-info-grid {
        grid-template-columns: 1fr 1fr;
    }

    .produit-metrics {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .user-info {
        font-size: 14px;
    }

    h1 {
        font-size: 22px;
        margin-bottom: 20px;
    }

    h2 {
        font-size: 18px;
    }

    td, th {
        font-size: 12px;
        min-width: 130px;
        padding: 9px 8px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .edit-modal-content {
        width: 96vw;
        margin: 2vh auto;
    }

    .edit-modal-footer,
    .modal-buttons {
        flex-direction: column;
        align-items: stretch;
    }

    .btn-action,
    .btn-save-edit,
    .btn-cancel-edit,
    .btn-cancel,
    .btn-confirm,
    .btn-cancel-modal,
    .btn-save-modal,
    .btn-upload,
    .btn-remove-image,
    .btn-remove-video {
        width: 100%;
    }
}
