/* ═══════════════════════════════════════
   VARIABLES — Thème Biscuiterie
═══════════════════════════════════════ */
:root {
    --primary:        #B5835A;
    --primary-dark:   #8B5E3C;
    --primary-light:  #D4A77A;
    --secondary:      #7C5C3A;
    --accent:         #F5E6D3;
    --accent-dark:    #EAD0B5;
    --bg:             #FDF8F3;
    --bg-alt:         #F0E6D9;
    --text:           #2D1B0D;
    --text-mid:       #6B4C35;
    --text-muted:     #9E7B5A;
    --card:           #FFFFFF;
    --success:        #4CAF50;
    --danger:         #E53935;
    --border:         rgba(181,131,90,0.18);

    --sh-sm:  0 2px 8px  rgba(45,27,13,0.07);
    --sh-btn: 0 4px 14px rgba(181,131,90,0.38);

    --r-sm:  10px;
    --r-md:  16px;
    --r-lg:  22px;
    --ease:  cubic-bezier(.4,0,.2,1);
    --tr:    all .22s var(--ease);
}

/* ═══════════ BASE & LAYOUT APP NATIVE (Zéro Scroll Global) ═══════════ */
* {
    box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    height: 100svh; /* Bloque l'application sur la hauteur visible exacte */
    overflow: hidden; /* Empêche tout défilement parasite global */
    display: flex;
    flex-direction: column;
    padding-bottom: 0; /* Géré proprement par les conteneurs flex */
}

/* Mode Historique */
body.history-mode header { background: #C62828 !important; }

/* Animations */
@keyframes fadeUp   { from { opacity:0; transform:translateY(14px); } to { opacity:1; transform:none; } }
@keyframes spin     { to   { transform:rotate(360deg); } }
@keyframes popIn    { 0%{transform:scale(.92);opacity:0} 60%{transform:scale(1.04)} 100%{transform:scale(1);opacity:1} }
@keyframes pulse    { 0% { opacity: 1; } 50% { opacity: 0.5; } 100% { opacity: 1; } }
@keyframes pulse-save {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(21, 101, 192, 0.4); }
    70% { transform: scale(1.02); box-shadow: 0 0 0 10px rgba(21, 101, 192, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(21, 101, 192, 0); }
}

#app {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 10px 15px;
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

.view        { display:none; height: 100%; overflow: hidden; }
.view.active { display: flex !important; flex-direction: column; animation: fadeUp .28s var(--ease); overflow-y: auto !important; overflow-x: hidden; }

h2 {
    text-align: center;
    margin: 0 0 22px 0;
    color: var(--text);
    font-size: 1.35rem; font-weight: 800;
    flex-shrink: 0;
}

h2::after {
    content: ''; display: block;
    width: 36px; height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 2px; margin: 8px auto 0;
}

/* ═══════════ HEADER ═══════════ */
header {
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: white;
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    box-shadow: 0 3px 18px rgba(45,27,13,.22);
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    flex-shrink: 0; /* L'en-tête ne s'écrase jamais */
}

.h-left, .h-right {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 7px;
}

.h-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1 1 auto;
    min-width: 0;
}

#headerTitle, #headerShiftName, #currentDateDisplay {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    text-align: center;
}

.nav-btn {
    background: rgba(255,255,255,.15);
    border: 1px solid rgba(255,255,255,.22);
    color: white;
    padding: 8px 11px;
    border-radius: var(--r-sm);
    font-size: .95rem; cursor: pointer;
    transition: var(--tr);
}

.nav-btn:active { background:rgba(255,255,255,.3); transform:scale(.93); }

.cart-btn {
    background: rgba(255,255,255,.18);
    border: 1px solid rgba(255,255,255,.28);
    color: white;
    padding: 8px 13px;
    border-radius: var(--r-sm);
    font-size: .88rem; font-weight: 600;
    cursor: pointer; position: relative;
    display: flex; align-items: center; gap: 6px;
    transition: var(--tr);
}

.badge {
    position: absolute; top:-7px; right:-7px;
    background: var(--danger); color: white;
    border-radius: 50%; min-width: 20px; height: 20px;
    padding: 0 4px; font-size: .72rem; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid white;
}

/* Réseau */
.sync-status { display: inline-flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; font-size: 0.8rem; margin-left: 8px; transition: 0.3s; flex-shrink: 0;}
.status-ok { background: #E8F5E9; box-shadow: 0 0 0 2px #4CAF50; }
.status-offline { background: #FFEBEE; box-shadow: 0 0 0 2px #F44336; animation: pulse 2s infinite; }
.status-syncing { background: #E3F2FD; box-shadow: 0 0 0 2px #2196F3; animation: spin 1s linear infinite; }

/* ═══════════ GRILLES & BOUTONS ═══════════ */
.grid { display:grid; grid-template-columns:1fr 1fr; gap:13px; }
.btn-list { grid-template-columns:1fr; }
 

.btn {
    background: var(--card);
    border: 1.5px solid var(--border);
    color: var(--text);
    padding: 16px 14px;
    border-radius: var(--r-md);
    font-size: 1.05rem; font-weight: 600;
    cursor: pointer;
    box-shadow: var(--sh-sm);
    transition: var(--tr);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    min-height: 88px;
    position: relative; overflow: hidden;
}
.btn:active { transform:scale(.96); box-shadow:none; }

.btn-primary { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); border-color: transparent; color: white; box-shadow: var(--sh-btn); }
.btn-success { background: linear-gradient(135deg, #2E7D32, #43A047); border-color: transparent; color: white; box-shadow: 0 4px 14px rgba(76,175,80,.35); }
.btn-outline { background: transparent; border: 2px dashed var(--primary-light); color: var(--primary-dark); min-height: 62px; font-weight:500; }
.btn-trash { background: #E53935; color: white; border: none; border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 0.9rem; }

/* Boutons Equipes & Activités */
.shift-card { min-height:110px; border-radius:var(--r-lg); font-size:1.05rem; font-weight:700; flex-direction:column; gap:4px; }
.shift-matin  { background:linear-gradient(135deg,#F39C12,#F1C40F); border-color:transparent; color:white; }
.shift-jour   { background:linear-gradient(135deg,#E67E22,#F39C12); border-color:transparent; color:white; }
.shift-aprem  { background:linear-gradient(135deg,#C0392B,#E74C3C); border-color:transparent; color:white; }
.shift-nuit   { background:linear-gradient(135deg,#1A2980,#26D0CE); border-color:transparent; color:white; }

.main-menu-grid { display:grid; grid-template-columns:1fr 1fr; gap:13px; margin-bottom:14px; }
.activity-btn { min-height:105px; gap:6px; }
.btn-production     { background:linear-gradient(135deg,#d35400,#E67E22); border-color:transparent; color:white; }
.btn-demoulage      { background:linear-gradient(135deg,#6c3483,#9B59B6); border-color:transparent; color:white; }
.btn-conditionnement{ background:linear-gradient(135deg,#1a5276,#2980B9); border-color:transparent; color:white; }
.btn-broyage        { background:linear-gradient(135deg,#4e342e,#795548); border-color:transparent; color:white; }
.btn-enrobage       { background:linear-gradient(135deg,#922b21,#C0392B); border-color:transparent; color:white; }

.btn-fraction {
    background: var(--card);
    border: 1.5px solid var(--border);
    color: var(--text);
    border-radius: var(--r-md);
    font-size: 1.05rem; font-weight: 600;
    cursor: pointer;
    box-shadow: var(--sh-sm);
    transition: var(--tr);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    min-height: 40px;
    position: relative; overflow: hidden;
}

.drive-btn {
    display:flex; align-items:center; justify-content:center; gap:9px;
    background:var(--card); border:1.5px solid var(--border);
    color:var(--text-mid); padding:13px 18px;
    border-radius:var(--r-md); font-size:.9rem; font-weight:600;
    cursor:pointer; box-shadow:var(--sh-sm); text-decoration:none;
    transition:var(--tr); min-height:52px;
}

/* ═══════════ CORRECTION TAILLE BOUTONS VRAC & INCOMPLET ═══════════ */
#btnSaveVrac, #btnSaveIncomplet {
    min-height: 44px !important; /* Annule les 88px de la classe .btn */
    height: 44px !important;
    padding: 8px 15px !important;
    font-size: 0.9rem !important;
    border-radius: 10px !important;
    margin-top: 5px;
}



.entry-row-flex {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 8px;
}

.btn-save-inline {
    display: none;
    height: 54px;
    min-width: 60px;
    border-radius: 12px;
    border: none;
    color: white;
    font-size: 1.4rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.btn-save-inline.success {
    background-color: #4CAF50 !important;
    min-width: 100px;
}

/* ═══════════ RECHERCHE & LISTE PRODUITS ═══════════ */
.search-bar-container { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; background: white; padding: 10px; border-radius: 12px; box-shadow: 0 2px 5px rgba(0,0,0,0.05); flex-shrink: 0;}
.search-bar-container input, .search-bar-container select { flex: 1; min-width: 150px; padding: 12px; border-radius: 8px; border: 1px solid #ddd; font-size: 1rem; outline: none; }
.search-bar-container input:focus { border-color: var(--primary); }

.recent-section-title { width: 100%; color: #F57C00; font-size: 0.9rem; text-transform: uppercase; font-weight: bold; letter-spacing: 1px; margin-top: 5px; margin-bottom: 5px; border-bottom: 2px solid #FFE0B2; padding-bottom: 5px;}
.all-section-title { width: 100%; color: #607D8B; font-size: 0.9rem; text-transform: uppercase; font-weight: bold; letter-spacing: 1px; margin-top: 20px; margin-bottom: 5px; border-bottom: 2px solid #CFD8DC; padding-bottom: 5px;}

.product-btn { min-height: auto !important; padding: 12px 15px !important; display: flex !important; flex-direction: column !important; align-items: flex-start !important; text-align: left !important; background: white; border: 1px solid #e0e0e0; border-radius: 10px; transition: 0.2s; }
.product-btn:hover { border-color: var(--primary); box-shadow: 0 4px 10px rgba(0,0,0,0.05); transform: translateY(-1px); }

.client-tag-elegant { background: #E3F2FD; color: #1565C0; padding: 3px 8px; border-radius: 6px; font-size: 0.75rem; font-weight: bold; border: 1px solid #BBDEFB; display: inline-block;}
.admin-product-row { transition: all 0.3s ease-in-out; position: relative; }

/* ═══════════ CARTES PRODUITS (Compacité optimisée pour le Non-Scroll global) ═══════════ */
.product-card { background: white; border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; border: 1px solid #eee; display: flex; align-items: center; gap: 15px; box-shadow: var(--sh-sm); flex-shrink: 0; }
.product-card-icon { font-size: 1.6rem; background: #F3E5F5; width: 45px; height: 45px; display: flex; align-items: center; justify-content: center; border-radius: 12px; flex-shrink: 0; }
.product-card-body { flex: 1; min-width: 0; }
.product-card-label { font-size: 0.75rem; color: #8D6E63; text-transform: uppercase; font-weight: bold; letter-spacing: 1px; margin-bottom: 4px; }
.product-card-name { font-size: 1.1rem; font-weight: 900; color: #222; margin-bottom: 2px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.product-card-sub { font-size: 0.85rem; color: #8D6E63; font-weight: 600; }

/* ═══════════ SAISIE ZEN ═══════════ */
.inline-inputs-container { display: flex; flex-wrap: wrap; gap: 20px; justify-content: center; align-items: flex-end; margin-top: 10px; }
.inline-input-group { flex: 1; min-width: 0 !important; max-width: 400px; position: relative; }
.inline-label { display: block; font-weight: 800; font-size: 1.1rem; margin-bottom: 8px; text-align: center; }

.input-massive { font-size: 1.6rem !important; font-weight: 900 !important; text-align: center !important; height: 48px !important; width: 100% !important; border-radius: 12px !important; border: 2px solid #E0E0E0 !important; transition: 0.3s !important; background: white !important;}
.input-massive:focus { outline: none !important; }

.input-green { color: #2E7D32 !important; }
.input-green:focus { border-color: #4CAF50 !important; box-shadow: 0 0 0 5px rgba(76,175,80,0.2) !important; }
.input-blue { color: #1565C0 !important; border-color: #BBDEFB !important; }
.input-blue:focus { border-color: #2196F3 !important; box-shadow: 0 0 0 5px rgba(33,150,243,0.2) !important; }
.input-orange { color: #E65100 !important; border-color: #FFE0B2 !important; background: white !important;}
.input-orange:focus { border-color: #FF9800 !important; box-shadow: 0 0 0 5px rgba(255,152,0,0.2) !important; }

.btn-save-pulsing { animation: pulse-save 2s infinite; border: 2px solid #0d47a1 !important; }

.toggle-incompletes { display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: #E65100; font-weight: bold; cursor: pointer; padding: 12px; border-radius: 12px; background: #FFF3E0; border: 1px dashed #FFB74D; width: 100%; margin-top: 15px; font-size: 1rem; flex-shrink: 0;}
#dsVracSection { box-shadow: 0 8px 20px rgba(33, 150, 243, 0.15); }

/* Switch Vrac */
.vrac-slider { width: 48px; height: 26px; background: #4CAF50; border-radius: 13px; position: relative; transition: background .3s; flex-shrink: 0; display: inline-block; }
.vrac-slider::after { content: ''; width: 20px; height: 20px; background: white; border-radius: 50%; position: absolute; top: 3px; left: 3px; transition: transform .3s; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.vrac-slider.nc-on { background: #E65100; }
.vrac-slider.nc-on::after { transform: translateX(22px); }

/* ═══════════ WIZARD (Création Produit) ═══════════ */
 
.wizard-header { display: flex; justify-content: space-between; margin-bottom: 25px; position: relative; flex-shrink: 0; }
.wizard-header::before { content: ''; position: absolute; top: 15px; left: 0; right: 0; height: 3px; background: #E0E0E0; z-index: 1; }
.wiz-step-ind { position: relative; z-index: 2; background: #E0E0E0; color: #757575; width: 35px; height: 35px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; transition: 0.3s; }
.wiz-step-ind.active { background: #1565C0; color: white; box-shadow: 0 0 0 5px rgba(21,101,192,0.2); }
.wiz-step-ind.done { background: #4CAF50; color: white; }
.wiz-part { display: none; animation: popIn 0.3s ease; }
.wiz-buttons { display: flex; gap: 10px; margin-top: 25px; }
.wiz-buttons .btn { flex: 1; min-height: 50px; font-size: 1.1rem; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; font-weight: bold; margin-bottom: 8px; color: #455A64; }
.form-control { width: 100%; padding: 12px; border: 2px solid #CFD8DC; border-radius: 10px; font-size: 1.1rem; outline: none; transition: 0.2s; }
.form-control:focus { border-color: #1565C0; }
.custom-input-div { margin-top: 10px; display: none; }

/* ═══════════ RECAP / COMPTE-RENDU ═══════════ */
.recap-ticket { background: #f9f9f9; border-radius: 12px; padding: 15px; margin-top: 20px; border: 1px solid #eee; }
.recap-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed #ddd; font-size: 0.95rem; }
.recap-row:last-child { border-bottom: none; }
.recap-total { display: flex; justify-content: space-between; padding-top: 10px; margin-top: 5px; border-top: 2px solid #ddd; font-weight: 900; font-size: 1.2rem; color: #333; }

.report-item { background:var(--card); padding:13px 15px; border-radius:var(--r-md); margin-bottom:10px; box-shadow:var(--sh-sm); display:flex; justify-content:space-between; align-items:center; transition:var(--tr); }
.report-details h4 { margin:0 0 4px 0; display:flex; align-items:center; flex-wrap:wrap; gap:5px; font-size:.98rem; font-weight:700; }
.report-qty { font-size:1.55rem; font-weight:800; background:var(--accent); padding:6px 13px; border-radius:var(--r-sm); text-align:center; white-space:nowrap; }
.report-actions button { padding:10px; border:none; border-radius:var(--r-sm); margin-left:7px; font-size:1rem; cursor:pointer; transition:var(--tr); }
.report-actions button:active { transform:scale(.88); }

/* ═══════════ TOASTS & MODALS ═══════════ */
#autoSaveToast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%) translateY(-100px); background: #2E7D32; color: white; padding: 12px 30px; border-radius: 30px; font-weight: 900; font-size: 1.1rem; box-shadow: 0 4px 15px rgba(0,0,0,0.2); z-index: 10000; opacity: 0; transition: all 0.4s; pointer-events: none; }
#autoSaveToast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
.save-feedback { font-size: 0.9rem; color: #2E7D32; opacity: 0; transition: 0.3s; text-align: center; margin-top: 8px; font-weight: bold; transform: translateY(-5px);}
.save-feedback.show { opacity: 1; transform: translateY(0); }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 10000; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(5px); }
.modal-content { background: white; max-width: 500px; width: 100%; border-radius: 16px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); animation: popIn 0.3s ease; display: flex; flex-direction: column; max-height: 90vh;}
#dupModal { animation: fadeInOverlay .18s ease; }
@keyframes fadeInOverlay { from { opacity:0; } to { opacity:1; } }
#dupModal > div { animation: slideUpPanel .22s cubic-bezier(.16,1,.3,1); }
@keyframes slideUpPanel { from { opacity:0; transform:translateY(20px); } to { opacity:1; transform:translateY(0); } }

/* Validation Admin */
.row-success-flash { transform: scale(1.02); box-shadow: 0 0 15px rgba(46, 125, 50, 0.4); border-color: #2E7D32 !important; z-index: 10; }

/* ═══════════ RESPONSIVE MOBILE ═══════════ */
@media (max-width: 600px) {
    #shiftView .btn, #mainMenuView .btn, #categoryGrid .btn {
        min-height: 85px !important; font-size: 1.25rem !important; border-radius: 16px !important;
        display: flex !important; flex-direction: column !important; align-items: center !important; justify-content: center !important;
    }

    #dsMainQtySection, #dsVracSection, #condIncompletesSection, .product-card { padding: 15px 12px !important; }
    .inline-inputs-container { flex-wrap: nowrap !important; gap: 8px !important; }
    .input-massive { font-size: 1.4rem !important; height: 45px !important; border-radius: 8px !important; }
     .inline-label { font-size: 0.85rem !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 4px !important; }
    #condManualStdUnit, #condLotQtyUnit, #dsVracQtyUnit { font-size: 1.1rem !important; right: 8px !important; bottom: 14px !important; }
    
    
    .h-center { flex: 2; }
    #headerTitle { font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px; }
    .history-mode #headerTitle { font-size: 0.9rem; }
    
    .date-indicator {
        position: fixed; top: 65px; left: 50%; transform: translateX(-50%);
        background: #ef6c00; color: white; padding: 4px 12px;
        border-radius: 20px; font-size: 0.75rem; font-weight: bold;
        z-index: 99; box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }
}
@media (max-width: 480px) {
    header { padding: 8px 10px; gap: 6px; }
    .h-left, .h-right { gap: 5px; }
    .nav-btn { padding: 8px 9px; font-size: .9rem; }
    .cart-btn { padding: 8px 10px; font-size: .82rem; }
}

/* ═══════════ CLAVIER VIRTUEL ═══════════ */
.virtual-keypad {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: #ECEFF1;
    padding: 15px 15px 35px 15px;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    z-index: 10000;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(.4,0,.2,1);
    border-top-left-radius: 20px;
    border-top-right-radius: 20px;
    flex-shrink: 0;
}

.virtual-keypad.visible {
    transform: translateY(0);
}

.vk-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    font-weight: 900;
    color: #455A64;
    font-size: 1.1rem;
}

.vk-close {
    background: #CFD8DC;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: bold;
    color: #37474F;
    cursor: pointer;
}

.vk-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 500px;
    margin: 0 auto;
}

.vk-grid button {
    background: white;
    border: 2px solid #CFD8DC;
    border-radius: 12px;
    font-size: 2rem;
    font-weight: 900;
    color: #263238;
    padding: 15px 0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
    cursor: pointer;
    transition: 0.1s;
}

.vk-grid button:active {
    background: #B0BEC5;
    transform: scale(0.95);
}
.input-green.vk-fake-focus { border-color: #4CAF50 !important; box-shadow: 0 0 0 5px rgba(76,175,80,0.2) !important; }
.input-blue.vk-fake-focus { border-color: #2196F3 !important; box-shadow: 0 0 0 5px rgba(33,150,243,0.2) !important; }
.input-orange.vk-fake-focus { border-color: #FF9800 !important; box-shadow: 0 0 0 5px rgba(255,152,0,0.2) !important; }