:root {
    --primary-color: #2c3e50;
    --secondary-color: #27ae60;
    --accent-color: #e67e22;
    --background-color: #f5f6fa;
    --card-bg: #ffffff;
    --text-color: #2d3436;
    --border-color: #dfe6e9;
    --danger-color: #e74c3c;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding: 20px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
}

nav {
    display: flex;
    gap: 10px;
}

.nav-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-weight: 500;
    color: var(--text-color);
    border-radius: 6px;
    transition: all 0.2s;
    text-decoration: none;
    font-size: 1rem;
    font-family: inherit;
}

.nav-btn:hover {
    background-color: var(--border-color);
}

.nav-btn.active {
    background-color: var(--primary-color);
    color: white;
}

/* Manual Entry Form */
.manual-entry-form {
    background: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.form-group select,
.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
}

.product-grid-header {
    margin-bottom: 15px;
}

.product-grid-header input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    max-height: 70vh;
    overflow-y: auto;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 6px;
}

.product-item-saisie {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    border: 1px solid #f0f0f0;
    border-radius: 6px;
    font-size: 0.85rem;
}

.product-item-saisie strong {
    font-weight: 500;
}

.product-item-saisie small {
    display: block;
    font-size: 0.75rem;
    color: #888;
}

.product-item-saisie .qty-input {
    width: 50px;
    padding: 4px;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.85rem;
}

.product-item-saisie.has-qty {
    background-color: #e3f2fd;
    border-color: #90caf9;
}

/* Utils */
.hidden {
    display: none !important;
}

.badge {
    background-color: var(--danger-color);
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 0.75rem;
    vertical-align: middle;
    margin-left: 5px;
    display: none; /* affiché via JS quand count > 0 */
}

.client-badge {
    font-size: 0.8rem;
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 10px;
    color: #666;
}

.ready {
    border-left: 5px solid var(--secondary-color);
}

.partial {
    border-left: 5px solid var(--accent-color);
}

.missing {
    border-left: 5px solid var(--danger-color);
}

.card {
    background: var(--card-bg);
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    margin-bottom: 20px;
}

.drop-zone {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
}

.drop-zone:hover {
    border-color: var(--secondary-color);
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-family: inherit;
    font-size: 0.95rem;
    transition: background-color 0.2s;
    text-decoration: none;
    display: inline-block;
}

.btn.primary {
    background-color: var(--secondary-color);
    color: white;
}

.btn.primary:hover {
    background-color: #219150;
}

.btn.primary:disabled {
    background-color: #b0bec5;
    cursor: not-allowed;
    opacity: 0.7;
}

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

.btn.secondary:hover {
    background-color: #f8f9fa;
}

.btn.danger {
    background-color: var(--danger-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.btn.danger:hover {
    background-color: #c0392b;
}

/* Client Grouping */
.client-group {
    background: #fff;
    border: 1px solid #eee;
    border-radius: 8px;
    margin-bottom: 20px;
    padding: 15px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.client-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 2px solid #f0f0f0;
    padding-bottom: 10px;
    cursor: pointer;
    user-select: none;
}

.client-header::after {
    content: '▼';
    font-size: 0.8em;
    color: #666;
    transition: transform 0.2s;
}

.client-group.collapsed .client-header::after {
    transform: rotate(-90deg);
}

.client-group.collapsed .client-header {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.client-group.collapsed .client-orders {
    display: none !important;
}

.client-header h3 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.2em;
}

.client-status {
    font-weight: bold;
    font-size: 0.9em;
    padding: 4px 8px;
    border-radius: 4px;
    background: #f0f0f0;
    color: #555;
}

.client-status.ready {
    background: #d4edda;
    color: #155724;
}

.client-status.partial {
    background: #fff3cd;
    color: #856404;
}

.client-status.shipped {
    background: #d1ecf1;
    color: #0c5460;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #636e72;
    background: var(--card-bg);
    border-radius: 12px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

/* Mappings View */
.mapping-card {
    background: white;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 15px;
}

.mapping-info {
    flex: 1;
    min-width: 200px;
}

.mapping-info h3 {
    margin: 0 0 5px 0;
    font-size: 1.1em;
}

.mapping-info p {
    margin: 0;
    color: #666;
    font-size: 0.9em;
}

.mapping-action {
    flex: 2;
    display: flex;
    gap: 10px;
    position: relative;
    align-items: center;
}

.mapping-input-wrapper {
    flex-grow: 1;
    position: relative;
}

.product-search-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 6px;
}

.search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: none;
}

.search-results div {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}

.search-results div:hover {
    background-color: #f5f5f5;
}

/* Supprimer le marker natif des <summary> stylisés manuellement */
details > summary {
    list-style: none;
}
details > summary::-webkit-details-marker {
    display: none;
}

/* Colonnes triables */
th[data-col] {
    cursor: pointer;
    user-select: none;
}

th[data-col]:hover {
    background-color: #e2e6ea;
}

th[data-col][data-sort-dir="asc"]::after {
    content: ' ▲';
    font-size: 0.7em;
    color: #666;
}

th[data-col][data-sort-dir="desc"]::after {
    content: ' ▼';
    font-size: 0.7em;
    color: #666;
}

/* Gestion des rôles */
body.role-preparateur .ebp-push-btn,
body.role-preparateur .ebp-csv-btn {
    display: none !important;
}

/* Toolbar base */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.toolbar .actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

/* =====================
   RESPONSIVE MOBILE
   ===================== */
@media (max-width: 768px) {
    .app-container {
        padding: 10px;
    }

    /* Header : titre au-dessus, nav en dessous */
    header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 12px;
        margin-bottom: 14px;
    }

    h1 {
        font-size: 1.1rem;
        text-align: center;
    }

    /* Navigation : défilement horizontal */
    nav {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        gap: 6px;
        padding-bottom: 4px;
        scrollbar-width: none; /* Firefox */
    }

    nav::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }

    .nav-btn {
        padding: 7px 10px;
        font-size: 0.8rem;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Toolbar */
    .toolbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .toolbar h2 {
        font-size: 1.1rem;
    }

    /* Drop zone */
    .drop-zone {
        padding: 20px 10px;
    }

    /* Cards */
    .card {
        padding: 12px;
    }

    /* Client header */
    .client-header {
        flex-wrap: wrap;
        gap: 6px;
    }

    .client-header h3 {
        font-size: 1rem;
    }

    /* Order lines : actions sur deux lignes si nécessaire */
    .order-line {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Modal */
    .modal-content {
        padding: 20px;
        width: 95%;
    }

    /* Mapping cards */
    .mapping-card {
        flex-direction: column;
        align-items: stretch;
    }

    .mapping-action {
        flex-direction: column;
    }

    /* Tableau mappings */
    #existing-mappings-table {
        font-size: 0.8rem;
    }

    /* Login overlay */
    #login-overlay > div {
        min-width: unset !important;
        width: 90% !important;
        padding: 24px !important;
    }
}



/* Empêche le zoom automatique d'iOS Safari sur le focus des champs de saisie.
   iOS zoome quand font-size < 16px. Cette règle s'applique uniquement
   sur les appareils tactiles (mobile/tablette). */
@media (hover: none) and (pointer: coarse) {
    input, select, textarea {
        font-size: 16px !important;
    }
}
