/* 
 * Styles pour la page de statistiques de l'application Order Prep
 * Version avec fixation agressive du problème de chevauchement
 */

.stats-container {
    font-family: 'Open Sans', sans-serif;
    padding: 15px;
    background-color: #f9f9f9;
    height: 100%;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    /* Ajout d'un padding-bottom important pour éviter le chevauchement */
    padding-bottom: 120px !important;
}

/* En-tête des statistiques */
.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    width: 100%;
}

.stats-header-left {
    display: flex;
    flex-direction: column;
}

.stats-day-label {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    margin: 0;
}

.stats-date {
    font-size: 14px;
    color: #666;
    margin: 2px 0 0 0;
}

.stats-logo {
    max-width: 100px;
    height: auto;
}

/* Bloc de statistiques */
.stats-block {
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    width: 100%;
    box-sizing: border-box;
}

.stats-block-title {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    margin: 0 0 10px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.stats-period-label {
    color: var(--order-prep-primary-color, #00897b);
    font-size: 14px;
}

/* Lignes des statistiques */
.stats-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid #f0f0f0;
    width: 100%;
}

.stats-row:last-child {
    border-bottom: none;
}

.stats-label {
    font-size: 14px;
    color: #666;
    width: 50%;
}

.stats-value {
    font-size: 16px;
    font-weight: bold;
    color: #333;
    width: 50%;
    text-align: right;
}

/* Section sélecteur de date */
.stats-date-selector {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    width: 100%;
    box-sizing: border-box;
}

.stats-date-field {
    width: 48%;
}

.stats-date-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    color: #333;
    box-sizing: border-box;
}

/* Graphique des ventes - CORRECTION MAJEURE */
.stats-chart-container {
    background-color: #fff;
    border-radius: 10px;
    padding: 15px;
    /* Augmentation drastique de la marge en bas */
    margin-bottom: 120px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

.stats-chart {
    width: 100%;
    /* Réduction de la hauteur du graphique */
    height: 250px;
    position: relative;
    /* Assurer que le contenu reste dans la boîte */
    overflow: hidden;
}

/* Correction spécifique pour le conteneur du graphique */
canvas#monthly-sales-chart {
    margin-bottom: 20px !important;
    max-height: 230px !important;
}

/* Force le conteneur principal à respecter l'espace pour la navigation */
.order-prep-container.stats-page {
    padding-bottom: 120px !important;
}

/* Augmenter la hauteur avec la navigation bottom */
.order-prep-full-page {
    padding-bottom: 120px !important;
}

/* Styles pour l'accordéon */
.stats-accordion {
    background-color: #fff;
    border-radius: 10px;
    margin-bottom: 15px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    overflow: hidden;
    width: 100%;
    box-sizing: border-box;
}

.stats-accordion-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    font-weight: 500;
    color: #333;
    padding: 15px;
    cursor: pointer;
    transition: background-color 0.3s;
    width: 100%;
    box-sizing: border-box;
}

.stats-accordion-header:hover {
    background-color: #f9f9f9;
}

.stats-accordion-header.collapsed svg {
    transform: rotate(180deg);
}

.stats-accordion-content {
    display: none;
    padding: 0 15px;
    border-top: 1px solid #f0f0f0;
    width: 100%;
    box-sizing: border-box;
}

.stats-trend-up {
    color: var(--order-prep-primary-color, #00c853);
}

.stats-trend-down {
    color: #ff3d00; /* Rouge pour les tendances négatives */
}

.stats-daily-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
    width: 100%;
    box-sizing: border-box;
}

.stats-daily-row:last-child {
    border-bottom: none;
}

.stats-daily-date {
    width: 25%;
    font-size: 14px;
    color: #333;
}

.stats-daily-value {
    width: 35%;
    font-size: 14px;
    font-weight: bold;
    text-align: right;
}

.stats-daily-value.higher {
    color: #00c853; /* Vert pour les valeurs supérieures à la semaine précédente */
}

.stats-daily-value.lower {
    color: #ff3d00; /* Rouge pour les valeurs inférieures à la semaine précédente */
}

.stats-daily-count {
    width: 40%;
    font-size: 14px;
    color: #666;
    text-align: right;
}

/* Responsive */
@media (max-width: 480px) {
    .stats-container {
        padding: 10px;
        margin: 0;
        width: 100vw;
        max-width: 100%;
        /* Padding extrême pour mobile */
        padding-bottom: 140px !important;
    }
    
    .stats-day-label {
        font-size: 15px;
    }
    
    .stats-date {
        font-size: 13px;
    }
    
    .stats-logo {
        max-width: 70px;
    }
    
    .stats-value {
        font-size: 15px;
    }
    
    .stats-block {
        padding: 10px;
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
    
    /* Modification pour que le tableau prenne toute la largeur */
    .stats-accordion {
        width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
    
    .stats-accordion-header {
        padding: 12px 10px;
    }
    
    .stats-accordion-content {
        padding: 0 5px;
    }
    
    .stats-daily-row {
        width: 100%;
        display: flex;
        padding: 10px 5px;
        justify-content: space-between;
    }
    
    .stats-daily-date {
        width: 20%;
        font-size: 12px;
        padding-right: 5px;
    }
    
    .stats-daily-value {
        width: 38%;
        font-size: 12px;
        text-align: right;
        padding-right: 5px;
    }
    
    .stats-daily-count {
        width: 42%;
        font-size: 12px;
        text-align: right;
    }
    
    /* Ajustement du sélecteur de date sur mobile */
    .stats-date-selector {
        width: 100%;
    }
    
    .stats-date-input:focus {
    border-color: var(--order-prep-primary-color, #8F100E);
    outline: none;
    box-shadow: 0 0 0 2px rgba(var(--order-prep-primary-color-rgb, 0, 226, 190), 0.2);
}
    
    .stats-date-field {
        width: 48%;
    }
    
    .stats-date-input {
        font-size: 12px;
        padding: 8px 5px;
    }
    
    /* Correction encore plus agressive pour mobile */
    .stats-chart-container {
        margin-bottom: 30px !important;
        border-top: 3px solid var(--order-prep-primary-color, #8F100E);
    }
    
    .stats-chart {
        height: 200px !important;
    }
    
    canvas#monthly-sales-chart {
        max-height: 180px !important;
    }
    
    /* Force de l'affichage complet */
    .order-prep-container.stats-page {
        padding-bottom: 140px !important;
    }
    
    .order-prep-full-page {
        padding-bottom: 140px !important;
    }
}
/* ==========================================================================
   Onglets Commandes / Produits, et tableau de repartition
   Rouge de la charte Incroyable Thriller : #8F100E
   ========================================================================== */

.op-onglets {
    display: flex;
    gap: 4px;
    padding: 12px 16px 0;
    border-bottom: 2px solid #e4e4e4;
    background: #fff;
}

.op-onglet {
    padding: 10px 20px;
    font-size: 15px;
    font-weight: 600;
    color: #666;
    text-decoration: none;
    border-radius: 6px 6px 0 0;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}

.op-onglet:hover { color: #8F100E; }

.op-onglet.is-active {
    color: #8F100E;
    border-bottom-color: #8F100E;
    background: #fff;
}

/* Raccourcis de periode */
.op-periodes {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 14px 16px 0;
}

.op-periode {
    padding: 6px 14px;
    font-size: 13px;
    color: #333;
    text-decoration: none;
    background: #f0f0f0;
    border-radius: 14px;
    white-space: nowrap;
}

.op-periode:hover { background: #e4e4e4; }

.op-periode.is-active {
    background: #8F100E;
    color: #fff;
}

/* Tableau */
.op-table-wrap { overflow-x: auto; }

.op-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.op-table th,
.op-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: middle;
}

.op-table thead th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: #666;
    border-bottom: 2px solid #e4e4e4;
    white-space: nowrap;
}

.op-table .op-num { text-align: right; white-space: nowrap; }
.op-table .op-nom { font-weight: 600; color: #333; }
.op-table .op-ca { font-weight: 700; color: #8F100E; }

.op-table tfoot td {
    font-weight: 700;
    border-top: 2px solid #e4e4e4;
    border-bottom: none;
    background: #fafafa;
}

/* Une valeur non nulle se remarque, sans crier */
.op-table .op-alerte { color: #d63638; font-weight: 600; }
.op-table .op-sous { display: block; font-size: 11px; font-weight: 400; color: #9e9e9e; }

/* Barre de part de marche */
.op-part-valeur { display: block; }

.op-part-barre {
    display: block;
    height: 4px;
    margin-top: 3px;
    background: #eee;
    border-radius: 2px;
    overflow: hidden;
}

.op-part-barre > span {
    display: block;
    height: 100%;
    background: #8F100E;
}

.op-note {
    margin: 14px 16px 0;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: #333;
    background: #fef4f4;
    border-left: 3px solid #d63638;
    border-radius: 0 4px 4px 0;
}

.op-vide {
    padding: 28px 16px;
    text-align: center;
    color: #9e9e9e;
}

@media (max-width: 600px) {
    .op-onglet { padding: 10px 14px; font-size: 14px; }
    .op-table th, .op-table td { padding: 8px 8px; font-size: 13px; }
    .op-table thead th { font-size: 11px; }
}



/* Champs de periode et bouton, repris des styles en ligne de la page Commandes :
   la page Produits utilise les memes composants et n'y avait pas acces, son bouton
   sortait donc sans aucun style. */

.stats-date-selector {
    display: flex;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 15px;
}

.stats-date-field {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.stats-date-label {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.stats-date-input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    color: #333;
    box-sizing: border-box;
    background: white;
    -webkit-appearance: none;
    -moz-appearance: textfield;
}

.stats-date-input:focus {
    border-color: var(--order-prep-primary-color, #8F100E);
    outline: none;
    box-shadow: 0 0 0 2px var(--order-prep-primary-color-light, rgba(0, 226, 190, 0.2));
}

.stats-date-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.stats-update-btn {
    background: var(--order-prep-primary-color, #8F100E);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 5px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.stats-update-btn:hover {
    background: var(--order-prep-primary-color-dark, #00b89e);
}

.stats-update-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* ==========================================================================
   Corrections mobile
   ========================================================================== */

/* Le formulaire de periode plaçait deux champs a 48% plus un bouton, soit plus
   de 100% : le bouton sortait de l'ecran. Il passe a la ligne quand il le faut. */
.stats-date-selector {
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-start;
    align-items: flex-end;
}

.stats-date-field {
    width: auto;
    flex: 1 1 160px;
    min-width: 0;
}

.stats-date-selector .stats-update-btn {
    flex: 0 0 auto;
}

/* Le tableau etait en width:100% sans largeur minimale : au lieu de declencher
   le defilement, il comprimait ses sept colonnes jusqu'a tronquer le contenu.
   Une largeur plancher force le defilement horizontal, qui reste contenu dans
   son cadre grace a overflow-x sur le conteneur. */
.op-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.op-table {
    min-width: 620px;
}

@media (max-width: 600px) {
    /* En dessous de cette largeur, champs et bouton prennent toute la ligne :
       plus lisible que trois elements ecrases cote a cote. */
    .stats-date-field {
        flex: 1 1 100%;
    }

    .stats-date-selector .stats-update-btn {
        width: 100%;
    }

    .stats-date-input {
        width: 100%;
        box-sizing: border-box;
    }

    /* La barre de part de marche n'apporte rien sur un ecran etroit, la valeur suffit */
    .op-part-barre {
        display: none;
    }

    .op-table {
        min-width: 560px;
    }
}
