/* Styles CSS pour l'application POS */

:root {
    --primary-color: #0d6efd;
    --success-color: #198754;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --light-color: #f8f9fa;
    --dark-color: #212529;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-color);
}

/* Layout POS */
.pos-container {
    height: calc(100vh - 56px); /* Hauteur moins navbar */
    display: flex;
    flex-direction: column;
}

.pos-toolbar {
    flex-shrink: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.pos-main {
    flex: 1;
    overflow: hidden;
}

.pos-products {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.categories-bar {
    flex-shrink: 0;
    overflow-x: auto;
    white-space: nowrap;
}

.category-btn {
    white-space: nowrap;
    min-width: 120px;
}

.category-btn.active {
    background-color: var(--primary-color) !important;
    border-color: var(--primary-color) !important;
    color: white !important;
}

.products-grid {
    flex: 1;
    overflow-y: auto;
}

/* Cartes produits */
.product-card {
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    min-height: 180px;
}

.product-card:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

/* État rupture de stock */
.product-card.out-of-stock {
    opacity: 0.5;
    filter: grayscale(100%);
    cursor: not-allowed;
    position: relative;
    pointer-events: none; /* bloque le clic */
}

.product-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
}

.product-placeholder {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--light-color);
    border-radius: 4px;
    margin: 0 auto;
}

.product-name {
    font-size: 0.9rem;
    line-height: 1.2;
    height: 2.4em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
}

.product-price {
    font-size: 1rem;
    color: var(--success-color) !important;
}

/* Panneau panier */
.pos-cart {
    display: flex;
    flex-direction: column;
    box-shadow: -2px 0 4px rgba(0,0,0,0.1);
}

.cart-header {
    flex-shrink: 0;
}

.customer-section {
    flex-shrink: 0;
}

.cart-items {
    flex: 1;
    overflow-y: auto;
}

.cart-totals {
    flex-shrink: 0;
}

.cart-actions {
    flex-shrink: 0;
}

/* Articles du panier */
.cart-item {
    padding: 10px;
    border-bottom: 1px solid #eee;
    transition: background-color 0.2s ease;
}

.cart-item:hover {
    background-color: var(--light-color);
}

.cart-item-name {
    font-weight: 600;
    font-size: 0.9rem;
    line-height: 1.2;
}

.cart-item-price {
    color: var(--success-color);
    font-weight: 600;
}

.qty-controls {
    display: flex;
    align-items: center;
    gap: 5px;
}

.qty-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
}

.qty-input {
    width: 60px;
    text-align: center;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 2px 4px;
}

/* Modal de paiement */
.payment-method {
    text-align: left;
    padding: 12px 16px;
    margin-bottom: 5px;
}

.payment-method.active {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.payment-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background-color: var(--light-color);
    border-radius: 4px;
    margin-bottom: 5px;
}

.payment-remove {
    background: none;
    border: none;
    color: var(--danger-color);
    font-size: 0.9rem;
    cursor: pointer;
}

/* Pavé numérique */
.numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    padding: 15px;
}

.numpad-btn {
    aspect-ratio: 1;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 8px;
}

.numpad-btn-wide {
    grid-column: span 2;
}

/* États et badges */
.stock-low {
    color: var(--warning-color);
}

.stock-out {
    color: var(--danger-color);
}

.session-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.cart-item {
    animation: fadeIn 0.3s ease;
}

/* Responsive */
@media (max-width: 768px) {
    .pos-container {
        height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    .pos-toolbar {
        flex-shrink: 0;
    }
    
    .pos-main {
        flex: 1;
        display: flex;
        flex-direction: column;
        height: calc(100vh - 56px); /* Hauteur totale - hauteur de la barre d'outils */
        overflow: hidden;
        position: relative;
        z-index: 1; /* S'assure que le contenu principal est au-dessus des éléments positionnés */
    }
    
    .pos-products {
        order: 1;
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .categories-bar {
        flex-shrink: 0;
        padding: 10px;
        background: #f8f9fa;
        border-bottom: 1px solid #dee2e6;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
        height: auto;
        min-height: 60px; /* Hauteur minimale pour les catégories */
    }
    
    .categories-bar .d-flex {
        min-width: max-content;
    }
    
    .products-grid {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 10px;
        min-height: 50vh; /* Hauteur minimale plus grande pour les produits */
        max-height: calc(100vh - 300px); /* Ajustement pour laisser de l'espace pour les autres éléments */
    }
    
    .pos-cart {
        order: 2;
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-top: 1px solid #dee2e6;
        background: white;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 50vh;
        max-height: 70vh;
        z-index: 1000;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        transition: transform 0.3s ease;
        display: flex;
        flex-direction: column;
        overflow: hidden; /* Cache le défilement global */
    }
    
    .cart-items {
        flex: 1;
        overflow-y: auto;
        overflow-x: auto; /* Permet le défilement horizontal si nécessaire */
        -webkit-overflow-scrolling: touch;
        padding: 0 15px 70px 15px; /* Ajout de padding en bas pour le bouton */
        width: 100%;
        box-sizing: border-box;
        scrollbar-width: thin; /* Pour Firefox */
        scrollbar-color: #ccc transparent; /* Pour Firefox */
    }
    
    /* Style de la barre de défilement pour WebKit (Chrome, Safari, etc.) */
    .cart-items::-webkit-scrollbar {
        height: 6px;
        width: 6px;
    }
    
    .cart-items::-webkit-scrollbar-thumb {
        background-color: #ccc;
        border-radius: 3px;
    }
    
    .cart-items::-webkit-scrollbar-track {
        background: transparent;
    }
    
    /* Conteneur du contenu du panier */
    .cart-items > * {
        min-width: fit-content; /* S'assure que le contenu peut être plus large que le conteneur */
        box-sizing: border-box;
        padding-bottom: 10px; /* Espace en bas pour éviter que le contenu ne soit caché par la barre de défilement */
    }
    
    /* Masquer le panier par défaut sur mobile */
    .pos-cart.collapsed {
        transform: translateY(calc(100% - 40px));
        -webkit-transform: translateY(calc(100% - 40px));
        overflow: visible; /* Permet au bouton de basculement de déborder si nécessaire */
    }
    
    /* Conteneur des boutons d'action du panier */
    .cart-actions {
        position: sticky;
        bottom: 0;
        background: white;
        padding: 10px 15px;
        border-top: 1px solid #eee;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    /* Bouton pour afficher/masquer le panier */
    .cart-toggle {
        display: block !important;
        position: absolute;
        top: -40px;
        left: 0;
        right: 0;
        height: 40px;
        background: #f8f9fa;
        border: 1px solid #dee2e6;
        border-bottom: none;
        border-radius: 8px 8px 0 0;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    .cart-items {
        max-height: 40vh;
        min-height: 200px;
    }
    
    .pos-toolbar .col-md-4 {
        margin-bottom: 10px;
    }
    
    .pos-toolbar .text-end {
        text-align: left !important;
    }
    
    .pos-toolbar .d-flex {
        flex-direction: column;
        align-items: flex-start !important;
    }
    
    .pos-toolbar .d-flex > div {
        margin-bottom: 5px;
    }
    
    .pos-toolbar .btn-group {
        margin: 5px 0;
        flex-wrap: wrap;
    }
    
    .pos-toolbar .btn-group .btn {
        margin: 2px;
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
    }
    
    .categories-bar {
        padding: 8px 4px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .category-btn {
        font-size: 0.8rem;
        padding: 0.25rem 0.5rem;
        min-width: auto;
    }
    
    .products-grid .row {
        margin-left: -5px;
        margin-right: -5px;
    }
    
    .products-grid .col {
        padding-left: 5px;
        padding-right: 5px;
        margin-bottom: 10px;
    }
    
    .product-card {
        min-height: 160px;
    }
    
    .product-name {
        font-size: 0.8rem;
        height: 2.2em;
    }
    
    .product-price {
        font-size: 0.9rem;
    }
}

/* Mode sombre (optionnel) */
@media (prefers-color-scheme: dark) {
    :root {
        --light-color: #2d3748;
        --dark-color: #f7fafc;
    }
    
    body {
        background-color: var(--dark-color);
        color: var(--light-color);
    }
}

/* Impression */
@media print {
    .pos-toolbar,
    .pos-cart,
    .navbar {
        display: none !important;
    }
    
    .pos-products {
        width: 100% !important;
    }
}
