:root {
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --panel-bg: #ffffff;
    --card-bg: #ffffff;
    --card-hover: #f1f5f9;
    --text-main: #334155;
    --text-muted: #64748b;
    --primary: #10b981;
    --primary-hover: #059669;
    --accent: #f59e0b;
    --border: #e2e8f0;
    --shadow-soft: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-glow: 0 0 15px rgba(16, 185, 129, 0.3);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height pour Safari/iOS */
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    box-shadow: var(--shadow-soft);
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.8rem;
    color: var(--primary);
    margin-bottom: 3rem;
    font-weight: 700;
}

.nav-links {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 0.5rem; /* Pour l'espace de la scrollbar */
}

/* Scrollbar personnalisée pour le menu */
.nav-links::-webkit-scrollbar {
    width: 6px;
}
.nav-links::-webkit-scrollbar-track {
    background: transparent;
}
.nav-links::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
.nav-links::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    text-align: left;
    padding: 1rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 600;
    font-family: inherit;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-btn:hover {
    background-color: var(--card-hover);
    color: var(--text-main);
}

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

/* Main Wrapper */
.main-wrapper {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.view-section {
    display: none;
    height: 100%;
    width: 100%;
    overflow-y: auto;
    background: var(--bg-color);
}

.view-section.active {
    display: flex;
    flex-direction: column;
}

/* Banner */
.banner {
    position: relative;
    height: 250px;
    width: 100%;
    overflow: hidden;
    flex-shrink: 0;
}

.banner-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.banner-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: linear-gradient(to right, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.4) 100%);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 0 3rem;
}

.banner-overlay h1 {
    font-size: 2.5rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

/* Create Layout */
.create-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.categories-panel {
    width: 220px;
    padding: 2rem;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    background: var(--panel-bg);
}

.categories-panel h3 {
    margin-bottom: 1rem;
    color: var(--text-muted);
}

#category-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.cat-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    text-align: left;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.95rem;
}
.cat-btn.active {
    background: var(--card-hover);
    color: var(--primary);
    font-weight: 700;
}

.products-panel {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.5rem;
}

/* Product Card */
.product-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex; flex-direction: column; gap: 0.5rem;
    box-shadow: var(--shadow-soft);
    transition: transform 0.2s, box-shadow 0.2s;
}
.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    border-color: var(--primary);
}

.prod-brand { color: var(--primary); font-size: 0.75rem; text-transform: uppercase; font-weight: 700; }
.prod-name { font-weight: 700; font-size: 1.1rem; }
.prod-details {
    background: var(--bg-color); padding: 10px; border-radius: 8px; font-size: 0.8rem;
    display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin: 10px 0; color: var(--text-muted);
}
.prod-price { font-size: 1.3rem; font-weight: 700; color: var(--text-main); margin-bottom: 10px; }

.add-to-cart-controls { display: flex; gap: 10px; margin-top: auto; }
.qty-input { width: 60px; text-align: center; border: 1px solid var(--border); border-radius: 6px; }
.add-btn { flex: 1; padding: 0.6rem; border: none; background: var(--primary); color: white; border-radius: 6px; font-weight: 600; cursor: pointer; }
.add-btn:hover { background: var(--primary-hover); }

/* Cart Panel */
.cart-panel {
    width: 320px;
    background: var(--panel-bg);
    border-left: 1px solid var(--border);
    padding: 1.5rem;
    display: flex; flex-direction: column;
}

.cart-panel h2 { margin-bottom: 1.5rem; }
.cart-items { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1rem; }
.empty-cart { color: var(--text-muted); text-align: center; margin-top: 2rem; }
.cart-item { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.cart-item-header { display: flex; justify-content: space-between; font-weight: 600; }
.cart-item-controls { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; }
.qty-btn { width: 26px; height: 26px; border: none; background: var(--bg-color); border-radius: 4px; cursor: pointer; }

.cart-summary { background: var(--bg-color); padding: 1.5rem; border-radius: 12px; margin: 1.5rem 0; }
.summary-row { display: flex; justify-content: space-between; margin-bottom: 0.5rem; color: var(--text-muted); }
.total-price-row { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); font-size: 1.2rem; font-weight: 700; color: var(--text-main); margin-bottom:0;}

.action-btn {
    width: 100%; padding: 1rem; border: none; background: var(--primary); color: white; border-radius: 8px; font-weight: 700; cursor: pointer; transition: 0.2s;
}
.action-btn:hover:not(:disabled) { background: var(--primary-hover); }
.action-btn:disabled { background: var(--border); cursor: not-allowed; }

/* Sections */
.section-header { padding: 3rem; background: white; border-bottom: 1px solid var(--border); }
.section-header h1 { color: var(--primary); font-size: 2rem; }
.section-header p { color: var(--text-muted); }

/* Edit Table */
.edit-table-container { padding: 2rem; overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; background: white; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-soft); }
.data-table th, .data-table td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: var(--bg-color); font-weight: 600; color: var(--text-muted); }
.edit-btn { padding: 0.5rem 1rem; border: none; background: var(--accent); color: white; border-radius: 4px; cursor: pointer; }

/* History */
.history-grid { padding: 2rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.5rem; }
.history-card { background: white; padding: 1.5rem; border-radius: 12px; box-shadow: var(--shadow-soft); border-top: 4px solid var(--primary); }
.hist-date { font-weight: 700; font-size: 1.2rem; margin-bottom: 10px; }
.hist-totals { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 15px; }
.hist-content { background: var(--bg-color); padding: 10px; border-radius: 6px; font-family: monospace; font-size: 0.8rem; white-space: pre-wrap; max-height: 150px; overflow-y: auto; }

/* Modals */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.4); backdrop-filter: blur(5px); align-items: center; justify-content: center; }
.modal-content { background: white; padding: 2.5rem; border-radius: 16px; width: 600px; max-width: 90vw; position: relative; box-shadow: 0 20px 40px rgba(0,0,0,0.1); }
.small-modal { width: 400px; }
.close-btn { position: absolute; top: 15px; right: 20px; font-size: 24px; cursor: pointer; color: var(--text-muted); }
.form-input { width: 100%; padding: 0.8rem; border: 1px solid var(--border); border-radius: 8px; margin: 1.5rem 0; font-family: inherit; }
textarea#summary-text { width: 100%; height: 250px; border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin: 1.5rem 0; font-family: monospace; }
.success-msg { color: var(--primary); font-weight: 600; margin-top: 10px; }
.edit-form .form-group { margin-bottom: 1rem; }
.edit-form label { display: block; margin-bottom: 5px; color: var(--text-muted); font-size: 0.9rem; }
.edit-form input { width: 100%; padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; }

.hover-zoom:hover {
    transform: scale(3) !important;
    z-index: 9999;
    position: relative;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
}

/* =========================================
   RESPONSIVE DESIGN (Tablette & Mobile)
   ========================================= */

/* Tablette (max 1024px) */
@media (max-width: 1024px) {
    .create-layout {
        flex-direction: column;
        overflow-y: auto;
        display: block;
    }
    .categories-panel {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 1rem;
        overflow: visible;
    }
    #category-nav {
        flex-direction: row;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 0.5rem;
    }
    .cat-btn {
        flex-shrink: 0;
    }
    .products-panel {
        padding: 1rem;
        overflow: visible;
        flex: none;
    }
    .cart-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border);
        min-height: 350px;
    }
}

/* Mobile (max 768px) */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    /* Transformation de la Sidebar en Bottom Navigation Bar */
    .sidebar {
        width: 100vw;
        max-width: 100vw;
        height: auto;
        padding: 0;
        border-right: none;
        border-top: 1px solid var(--border);
        position: fixed;
        bottom: 0;
        left: 0;
        background: white;
        z-index: 1000;
        display: block; /* On passe en block pour que nav-links gère le scroll seul */
        box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
    }
    .logo {
        display: none;
    }
    #sidebar-user-info {
        display: none !important;
    }
    #sidebar-user-info {
        display: none !important;
    }
    #sidebar-user-info {
        display: none !important;
    }
    .nav-links {
        display: flex;
        flex-direction: row;
        width: 100%;
        max-width: 100vw;
        justify-content: flex-start;
        gap: 0;
        overflow-x: auto;
        overflow-y: hidden;
        white-space: nowrap;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch; /* Activation du swipe fluide sur iOS/Android */
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
        padding: 0.5rem;
    }
    .nav-links::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }
    .nav-btn {
        flex-direction: column;
        padding: 0.5rem 0.8rem;
        font-size: 0.75rem;
        gap: 5px;
        text-align: center;
        flex-shrink: 0; /* Empêche le bouton de s'écraser */
        min-width: 80px; /* Largeur minimale pour pouvoir cliquer */
    }
    .nav-btn i {
        font-size: 1.2rem;
    }
    .nav-btn.active {
        box-shadow: none;
        transform: scale(1.05);
    }
    
    .main-wrapper {
        padding-bottom: 75px; /* Espace pour la barre du bas */
        height: 100vh;
    }
    
    .banner {
        height: 150px;
    }
    .banner-overlay h1 {
        font-size: 1.8rem;
    }
    .banner-overlay {
        padding: 0 1.5rem;
    }
    
    /* Tableaux Scrollables */
    .edit-table-container, .history-grid {
        padding: 1rem;
    }
    .data-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 1rem;
    }
    
    .cart-panel {
        overflow: visible;
        height: auto;
        padding-bottom: 120px; /* Espace de sécurité pour bien voir le bouton */
    }
    
    .cart-items {
        flex: none;
        overflow: visible;
        height: auto;
    }
    
    /* Modales */
    .modal-content {
        width: 95%;
        padding: 1.5rem;
        margin: 10px;
        max-height: 90vh;
        overflow-y: auto;
    }
    .small-modal {
        width: 95%;
    }
}

.logout-btn {
    color: #ef4444;
    margin-top: 2rem;
}

@media (max-width: 768px) {
    .logout-btn {
        margin-top: 0;
    }
}
