:root {
  --primary: #C17F24;
  --primary-dark: #8B5A1A;
  --primary-light: #E8A84A;
  --primary-soft: #FFF0D9;
  --bg: #FFF8F0;
  --bg-card: #FFFFFF;
  --text: #2D1B0E;
  --text-light: #7A5C44;
  --text-muted: #A08060;
  --border: #EDD9C0;
  --success: #27AE60;
  --success-soft: #EAFAF1;
  --warning: #E67E22;
  --warning-soft: #FEF9E7;
  --danger: #C0392B;
  --danger-soft: #FDEDEC;
  --info: #2980B9;
  --info-soft: #EBF5FB;
  --role-vendeur: #8E44AD;
  --role-boulanger: #C17F24;
  --role-patissier: #C0392B;
  --role-patron: #D4AC0D;
  --status-attente: #E67E22;
  --status-cours: #2980B9;
  --status-pret: #27AE60;
  --status-livre: #95A5A6;
  --header-h: 60px;
  --nav-h: 68px;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(139,90,26,0.1);
  --shadow-lg: 0 8px 30px rgba(139,90,26,0.15);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* ── VIEWS ── */
.view { display: none; }
.view.active { display: flex; flex-direction: column; min-height: 100vh; }
.hidden { display: none !important; }

/* ── LOGIN ── */
#view-login { flex-direction: column; align-items: center; justify-content: flex-end; background: linear-gradient(160deg, #C17F24 0%, #8B5A1A 100%); }
.login-brand { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-brand-svg { width: 170px; height: 170px; filter: drop-shadow(0 6px 20px rgba(0,0,0,0.2)); }
.login-container { background: white; border-radius: 28px 28px 0 0; padding: 36px 32px calc(36px + env(safe-area-inset-bottom, 0px)); width: 100%; max-width: 480px; margin: 0; box-shadow: 0 -8px 40px rgba(0,0,0,0.12); text-align: center; }
.login-container form { display: flex; flex-direction: column; gap: 12px; }
.login-container input { padding: 14px 16px; border: 2px solid var(--border); border-radius: var(--radius-sm); font-size: 16px; outline: none; transition: border-color .2s; }
.login-container input:focus { border-color: var(--primary); }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
@media (min-width: 600px) {
  #view-login { justify-content: center; gap: 0; }
  .login-brand { flex: none; padding-bottom: 8px; }
  .login-container { border-radius: 28px; max-width: 400px; padding: 36px 40px 40px; }
}

/* ── APP SHELL ── */
#app { display: flex; flex-direction: column; min-height: 100vh; }
#app.hidden { display: none; }

/* ── HEADER ── */
.app-header { position: fixed; top: 0; left: 0; right: 0; height: var(--header-h); background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; z-index: 100; box-shadow: 0 2px 12px rgba(139,90,26,0.25); }
.header-left { display: flex; align-items: center; gap: 10px; }
.app-title-mallet { font-family: 'Dancing Script', cursive; font-size: 28px; font-weight: 700; color: white; line-height: 1; }
.header-right { display: flex; align-items: center; gap: 8px; }
.user-name { font-size: 13px; font-weight: 600; color: rgba(255,255,255,.9); }
.btn-icon { color: white; font-size: 18px; padding: 6px; opacity: .8; transition: opacity .2s; }
.btn-icon:hover { opacity: 1; }

/* ── MAIN CONTENT ── */
#main-content { margin-top: var(--header-h); margin-bottom: var(--nav-h); flex: 1; overflow-y: auto; }
.page { display: none; padding: 16px; min-height: calc(100vh - var(--header-h) - var(--nav-h)); }
.page.active { display: block; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-header h2 { font-size: 22px; font-weight: 800; color: var(--text); }

/* ── BOTTOM NAV ── */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-h); background: white; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-around; padding: 0 8px; z-index: 100; box-shadow: 0 -4px 20px rgba(0,0,0,0.06); }
.nav-btn { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 4px; border-radius: var(--radius-sm); color: var(--text-muted); transition: color .2s; }
.nav-btn.active { color: var(--primary); }
.nav-btn.active .nav-icon { transform: scale(1.1); }
.nav-icon { font-size: 22px; transition: transform .2s; }
.nav-label { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

/* ── BUTTONS ── */
.btn-primary { background: var(--primary); color: white; padding: 14px 24px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 700; transition: background .2s, transform .1s; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-secondary { background: var(--primary-soft); color: var(--primary-dark); padding: 14px 24px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 700; transition: background .2s; }
.btn-secondary:hover { background: var(--border); }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-large { width: 100%; padding: 16px; font-size: 17px; margin-top: 8px; border-radius: var(--radius); }
.btn-danger { background: var(--danger); color: white; padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 700; }
.btn-success { background: var(--success); color: white; padding: 8px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 700; }
.btn-outline { border: 2px solid var(--primary); color: var(--primary); background: none; padding: 7px 14px; border-radius: var(--radius-sm); font-size: 13px; font-weight: 700; }

/* ── BADGES ── */
.role-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.role-vendeur { background: #F4ECF7; color: var(--role-vendeur); }
.role-boulanger { background: var(--primary-soft); color: var(--primary-dark); }
.role-patissier { background: #FDEDEC; color: var(--role-patissier); }
.role-patron { background: #FEF9E7; color: #7D6608; }

.status-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.status-en_attente { background: #FEF9E7; color: var(--status-attente); }
.status-en_cours { background: var(--info-soft); color: var(--status-cours); }
.status-pret { background: var(--success-soft); color: var(--status-pret); }
.status-livre { background: #F2F3F4; color: var(--status-livre); }

.cat-badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.cat-boulangerie { background: #FEF0E6; color: #A04000; }
.cat-patisserie { background: #FDEDEC; color: #C0392B; }
.cat-viennoiserie { background: var(--primary-soft); color: var(--primary-dark); }

/* ── CARDS ── */
.card { background: var(--bg-card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 12px; }
.card-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.card-title { font-size: 15px; font-weight: 700; color: var(--text); }
.card-subtitle { font-size: 13px; color: var(--text-light); margin-top: 2px; }
.card-meta { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.card-badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ── DASHBOARD ── */
.dashboard-header { margin-bottom: 20px; padding: 20px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); border-radius: var(--radius); color: white; }
.dashboard-header h2 { font-size: 22px; font-weight: 800; }
.dashboard-header .subtitle { font-size: 14px; opacity: .85; margin-top: 4px; text-transform: capitalize; }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat-card { background: white; border-radius: var(--radius-sm); padding: 16px 12px; text-align: center; box-shadow: var(--shadow); border: 1px solid var(--border); }
.stat-value { font-size: 32px; font-weight: 900; color: var(--primary); }
.stat-label { font-size: 11px; font-weight: 600; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.8px; margin: 16px 0 10px; }

/* ── FILTERS ── */
.filters-row { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; scrollbar-width: none; }
.filters-row::-webkit-scrollbar { display: none; }
.filter-btn { flex-shrink: 0; padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 600; background: white; color: var(--text-light); border: 1.5px solid var(--border); transition: all .2s; }
.filter-btn.active { background: var(--primary); color: white; border-color: var(--primary); }

/* ── ORDERS ── */
.orders-list { display: flex; flex-direction: column; gap: 0; }
.order-card { background: white; border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 10px; cursor: pointer; transition: box-shadow .2s, transform .1s; border-left: 4px solid var(--border); }
.order-card:active { transform: scale(.99); }
.order-card.status-en_attente { border-left-color: var(--status-attente); }
.order-card.status-en_cours { border-left-color: var(--status-cours); }
.order-card.status-pret { border-left-color: var(--status-pret); }
.order-card.status-livre { border-left-color: var(--status-livre); }
.order-top { display: flex; align-items: flex-start; justify-content: space-between; }
.order-client { font-size: 16px; font-weight: 700; }
.order-time { font-size: 12px; color: var(--text-muted); }
.order-items-preview { font-size: 13px; color: var(--text-light); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.order-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; flex-wrap: wrap; gap: 6px; }
.order-seller { font-size: 12px; color: var(--text-muted); }
.urgent-badge { background: var(--danger); color: white; padding: 2px 8px; border-radius: 20px; font-size: 10px; font-weight: 700; animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity:1 } 50% { opacity:.6 } }

/* ── ORDER DETAIL ── */
.detail-section { margin-bottom: 16px; }
.detail-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.detail-value { font-size: 15px; font-weight: 600; color: var(--text); }
.items-list { display: flex; flex-direction: column; gap: 6px; }
.item-row-detail { display: flex; justify-content: space-between; padding: 8px 12px; background: var(--bg); border-radius: var(--radius-sm); font-size: 14px; }
.item-qty-badge { font-weight: 700; color: var(--primary); }
.detail-note { background: var(--warning-soft); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; color: var(--text-light); border-left: 3px solid var(--warning); }

/* ── STOCK ── */
.stock-alerts { margin-bottom: 14px; }
.alert-banner { background: var(--danger-soft); border: 1.5px solid var(--danger); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 8px; display: flex; align-items: center; gap: 10px; }
.alert-icon { font-size: 20px; }
.alert-text { flex: 1; }
.alert-title { font-size: 14px; font-weight: 700; color: var(--danger); }
.alert-sub { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.stock-card { background: white; border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 8px; display: flex; align-items: center; gap: 12px; }
.stock-card.low { border-left: 4px solid var(--danger); }
.stock-card.ok { border-left: 4px solid var(--success); }
.stock-icon { width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.stock-info { flex: 1; min-width: 0; }
.stock-name { font-size: 15px; font-weight: 700; color: var(--text); }
.stock-cat { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.stock-qty-section { text-align: right; flex-shrink: 0; }
.stock-qty { font-size: 20px; font-weight: 900; color: var(--text); }
.stock-unit { font-size: 11px; color: var(--text-muted); }
.stock-threshold { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.qty-bar { height: 4px; border-radius: 2px; background: var(--border); margin-top: 6px; overflow: hidden; }
.qty-bar-fill { height: 100%; border-radius: 2px; transition: width .5s; }
.qty-bar-fill.ok { background: var(--success); }
.qty-bar-fill.low { background: var(--danger); }
.stock-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ── TEAM ── */
.team-card { background: white; border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); border: 1px solid var(--border); margin-bottom: 10px; display: flex; align-items: center; gap: 14px; }
.avatar { width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 800; color: white; flex-shrink: 0; }
.avatar.role-vendeur { background: var(--role-vendeur); }
.avatar.role-boulanger { background: var(--primary); }
.avatar.role-patissier { background: var(--role-patissier); }
.avatar.role-patron { background: var(--role-patron); color: #5D4037; }
.team-info { flex: 1; }
.team-name { font-size: 15px; font-weight: 700; }
.team-email { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── FORMS ── */
label { font-size: 13px; font-weight: 700; color: var(--text-light); display: block; margin-bottom: 5px; margin-top: 14px; }
label:first-child { margin-top: 0; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], select, textarea {
  width: 100%; padding: 12px 14px; border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: 15px; outline: none; transition: border-color .2s; background: white; color: var(--text);
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 80px; }
.input-with-unit { display: grid; grid-template-columns: 1fr 120px; gap: 8px; }
.order-item-row { display: grid; grid-template-columns: 1fr 80px 36px; gap: 8px; margin-bottom: 8px; align-items: center; }
.btn-remove-item { width: 36px; height: 36px; background: var(--danger-soft); color: var(--danger); border-radius: var(--radius-sm); font-size: 14px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ── MODALS ── */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 200; display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .2s; }
@keyframes fadeIn { from { opacity:0 } to { opacity:1 } }
.modal-content { background: white; border-radius: 24px 24px 0 0; width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto; padding: 24px 20px 32px; animation: slideUp .25s cubic-bezier(.4,0,.2,1); }
@keyframes slideUp { from { transform: translateY(100%) } to { transform: translateY(0) } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { font-size: 20px; font-weight: 800; }
.modal-close { width: 32px; height: 32px; background: var(--bg); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--text-light); }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; }

/* ── TOASTS ── */
#toast-container { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 400px; pointer-events: none; }
.toast { padding: 13px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; animation: toastIn .3s cubic-bezier(.4,0,.2,1); box-shadow: var(--shadow-lg); pointer-events: all; display: flex; align-items: center; gap: 10px; }
@keyframes toastIn { from { opacity:0; transform: translateY(-12px) } to { opacity:1; transform: translateY(0) } }
.toast.fade-out { animation: toastOut .3s forwards; }
@keyframes toastOut { to { opacity:0; transform: translateY(-12px) } }
.toast-success { background: white; border-left: 4px solid var(--success); color: var(--text); }
.toast-error { background: white; border-left: 4px solid var(--danger); color: var(--text); }
.toast-info { background: white; border-left: 4px solid var(--info); color: var(--text); }
.toast-warning { background: white; border-left: 4px solid var(--warning); color: var(--text); }
.toast-icon { font-size: 18px; }

/* ── LOADING / EMPTY ── */
.loading, .empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 14px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-msg { font-weight: 600; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg) } }

/* ── NOTIF DOT ── */
.notif-dot { width: 8px; height: 8px; background: var(--danger); border-radius: 50%; position: absolute; top: 6px; right: 6px; }
.nav-btn { position: relative; }

/* ── RESPONSIVE (tablet/desktop) ── */
@media (min-width: 600px) {
  .modal-content { border-radius: 24px; margin: auto; max-height: 85vh; }
  .modal { align-items: center; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (min-width: 900px) {
  #main-content { max-width: 720px; margin-left: auto; margin-right: auto; }
  .bottom-nav { max-width: 720px; left: 50%; transform: translateX(-50%); border-radius: 24px 24px 0 0; }
}

/* ── MOBILE / PWA ── */

/* Safe areas iOS (encoche + barre home) */
.app-header {
  padding-top: env(safe-area-inset-top, 0px);
  height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
}
#main-content {
  margin-top: calc(var(--header-h) + env(safe-area-inset-top, 0px));
  margin-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}
.bottom-nav {
  padding-bottom: env(safe-area-inset-bottom, 0px);
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
}

/* Évite le zoom iOS sur les inputs (déclenché si font-size < 16px) */
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=time], select, textarea { font-size: 16px; }

/* Supprime le tap highlight bleu iOS/Android */
* { -webkit-tap-highlight-color: transparent; }

/* Désactive le double-tap zoom sur boutons et cartes */
button, a, .order-card, .stock-card, .filter-btn, .nav-btn { touch-action: manipulation; }

/* Empêche le bounce/overscroll iOS sur le body */
html { overscroll-behavior-y: none; }

/* Scroll fluide sur iOS */
#main-content, .modal-content, .filters-row { -webkit-overflow-scrolling: touch; }

/* Meilleur feedback tactile */
.order-card:active { transform: scale(.985); box-shadow: none; }
.nav-btn:active { background: var(--primary-soft); border-radius: var(--radius-sm); }
.filter-btn:active { transform: scale(.95); }
.btn-primary:active, .btn-secondary:active, .btn-danger:active { opacity: .85; }

/* Modal : laisse de la place au clavier virtuel sur iOS */
.modal-content {
  padding-bottom: max(32px, env(safe-area-inset-bottom, 32px));
}

/* ── LOGO HEADER ── */
.header-badge { width: 36px; height: 36px; flex-shrink: 0; margin-right: 2px; }

/* ── ANIMATIONS ── */

/* Transitions de page */
@keyframes pageIn { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: translateY(0) } }
.page.active { animation: pageIn .28s cubic-bezier(.25,.46,.45,.94); }

/* Entrée des cartes */
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: translateY(0) } }
.order-card { animation: cardIn .22s cubic-bezier(.25,.46,.45,.94) both; }
.stock-card { animation: cardIn .22s cubic-bezier(.25,.46,.45,.94) both; }
.stat-card  { animation: cardIn .22s cubic-bezier(.25,.46,.45,.94) both; }
.team-card  { animation: cardIn .22s cubic-bezier(.25,.46,.45,.94) both; }

/* Teinte de fond selon le statut (dégradé subtil depuis le bord gauche coloré) */
.order-card.status-en_attente { background: linear-gradient(to right, #FEF6E4 0%, white 56px); }
.order-card.status-en_cours   { background: linear-gradient(to right, #EAF4FB 0%, white 56px); }
.order-card.status-pret       { background: linear-gradient(to right, #E9F7EF 0%, white 56px); }
.order-card.status-livre      { background: #FAFAFA; opacity: .78; }

/* Pulsation douce sur les badges de statut actifs */
@keyframes pulseOrange { 0%,100% { box-shadow: 0 0 0 0 rgba(230,126,34,0) } 60% { box-shadow: 0 0 0 5px rgba(230,126,34,0.18) } }
@keyframes pulseBlue   { 0%,100% { box-shadow: 0 0 0 0 rgba(41,128,185,0) } 60% { box-shadow: 0 0 0 5px rgba(41,128,185,0.18) } }
.status-badge.status-en_attente { animation: pulseOrange 2.8s ease-in-out infinite; }
.status-badge.status-en_cours   { animation: pulseBlue   2.2s ease-in-out infinite; }

/* Point de notification — pop */
@keyframes notifPop { 0%,100% { transform: scale(1); opacity: 1 } 50% { transform: scale(1.55); opacity: .85 } }
.notif-dot { animation: notifPop 2s ease-in-out infinite; }

/* Stat cards — effet hover léger */
.stat-card { transition: transform .2s, box-shadow .2s; cursor: default; }
@media (hover: hover) { .stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); } }

/* Boutons — meilleur hover desktop */
@media (hover: hover) {
  .order-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
  .filter-btn:hover:not(.active) { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
  .btn-outline:hover { background: var(--primary-soft); }
}

/* Skeleton loader */
@keyframes shimmer { 0% { background-position: -400px 0 } 100% { background-position: 400px 0 } }
.loading .spinner + * { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── ASSISTANT FLOTTANT ── */
.asst-fab {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 14px);
  left: 16px;
  width: 52px; height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  font-size: 22px;
  box-shadow: 0 4px 20px rgba(193,127,36,0.45);
  z-index: 150;
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s, box-shadow .2s;
  touch-action: manipulation;
}
.asst-fab:active { transform: scale(.92); }
@media (hover: hover) {
  .asst-fab:hover { transform: scale(1.07); box-shadow: 0 6px 28px rgba(193,127,36,0.55); }
}

.asst-panel {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 10px);
  left: 12px;
  right: 12px;
  max-width: 400px;
  height: 460px;
  background: white;
  border-radius: 20px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.20);
  z-index: 151;
  display: flex; flex-direction: column;
  overflow: hidden;
  animation: slideUp .25s cubic-bezier(.4,0,.2,1);
}
@media (min-width: 500px) {
  .asst-panel { right: auto; width: 360px; }
}

.asst-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  padding: 13px 16px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.asst-title { display: flex; align-items: center; gap: 8px; color: white; font-weight: 700; font-size: 14px; }
.asst-icon  { font-size: 17px; }
.asst-close { color: rgba(255,255,255,.8); font-size: 16px; padding: 4px 8px; line-height: 1; touch-action: manipulation; }
.asst-close:hover { color: white; }

.asst-messages {
  flex: 1; overflow-y: auto; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
  -webkit-overflow-scrolling: touch;
}
.asst-msg {
  max-width: 90%; padding: 9px 13px; border-radius: 16px;
  font-size: 13.5px; line-height: 1.5; word-break: break-word;
}
.asst-msg-user {
  background: var(--primary); color: white;
  border-bottom-right-radius: 4px; align-self: flex-end;
}
.asst-msg-bot {
  background: var(--bg); color: var(--text);
  border-bottom-left-radius: 4px; align-self: flex-start;
  border: 1px solid var(--border);
}

/* Typing indicator */
.asst-typing {
  display: flex; gap: 5px; align-items: center;
  padding: 12px 16px !important;
}
.asst-typing span {
  width: 7px; height: 7px; background: var(--text-muted);
  border-radius: 50%; animation: typingDot .9s ease-in-out infinite;
}
.asst-typing span:nth-child(2) { animation-delay: .18s; }
.asst-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes typingDot {
  0%,100% { opacity: .3; transform: translateY(0) }
  50%     { opacity: 1;  transform: translateY(-5px) }
}

.asst-suggestions {
  display: flex; gap: 6px; padding: 0 12px 10px;
  overflow-x: auto; scrollbar-width: none; flex-shrink: 0;
}
.asst-suggestions::-webkit-scrollbar { display: none; }
.asst-chip {
  flex-shrink: 0; padding: 5px 11px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  background: var(--primary-soft); color: var(--primary-dark);
  border: 1.5px solid var(--border);
  transition: background .15s; touch-action: manipulation;
}
.asst-chip:active { background: var(--border); }

.asst-input-row {
  display: flex; gap: 8px; padding: 10px 12px;
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.asst-input {
  flex: 1; padding: 9px 14px;
  border: 1.5px solid var(--border); border-radius: 20px;
  font-size: 14px; outline: none; background: white; color: var(--text);
}
.asst-input:focus { border-color: var(--primary); }
.asst-send {
  width: 38px; height: 38px; flex-shrink: 0;
  background: var(--primary); color: white;
  border-radius: 50%; font-size: 16px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  touch-action: manipulation;
}
.asst-send:active { opacity: .85; }

/* ── CA ESTIMATOR ── */
.ca-card {
  background: white; border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  border: 1px solid var(--border); margin-bottom: 16px;
}
.ca-ref-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; flex-wrap: wrap; gap: 8px;
}
.ca-ref-label { font-size: 13px; font-weight: 700; color: var(--text-light); }
.ca-ref-input-wrap { display: flex; align-items: center; gap: 6px; }
.ca-ref-input {
  width: 82px; padding: 7px 10px;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 700; text-align: center; outline: none;
  color: var(--text);
}
.ca-ref-input:focus { border-color: var(--primary); }
.ca-ref-unit { font-size: 12px; color: var(--text-muted); font-weight: 600; }

.ca-params { display: flex; gap: 14px; flex-wrap: wrap; }
.ca-param   { flex: 1; min-width: 110px; }
.ca-param-label {
  font-size: 10px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 7px;
}
.ca-param-btns { display: flex; gap: 5px; }
.ca-p-btn {
  padding: 5px 10px; border-radius: 20px; font-size: 17px;
  border: 1.5px solid var(--border); background: white;
  transition: all .15s; touch-action: manipulation;
}
.ca-p-btn.active {
  border-color: var(--primary); background: var(--primary-soft);
  transform: scale(1.08);
}
.ca-day-tag {
  display: inline-block; padding: 5px 12px;
  background: var(--primary-soft); color: var(--primary-dark);
  border-radius: 20px; font-size: 12px; font-weight: 700;
}
.ca-event-select {
  width: 100%; padding: 8px 10px; font-size: 14px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  outline: none; background: white; color: var(--text);
}
.ca-event-select:focus { border-color: var(--primary); }

.ca-results { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.ca-result-main {
  display: flex; align-items: center;
  justify-content: space-between; margin-bottom: 12px;
}
.ca-result-label { font-size: 12px; color: var(--text-muted); margin-bottom: 3px; }
.ca-result-value { font-size: 32px; font-weight: 900; color: var(--primary); line-height: 1; }
.ca-result-var {
  font-size: 13px; font-weight: 800; padding: 5px 10px;
  border-radius: 20px; white-space: nowrap;
}
.ca-result-var.pos { background: var(--success-soft); color: var(--success); }
.ca-result-var.neg { background: var(--danger-soft);  color: var(--danger); }

.ca-result-week {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg); border-radius: var(--radius-sm); padding: 11px 14px;
  margin-bottom: 10px;
}
.ca-result-week-label { font-size: 13px; color: var(--text-light); font-weight: 600; }
.ca-result-week-val   { font-size: 18px; font-weight: 900; color: var(--text); }

.ca-coeffs-detail {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px;
}
.ca-coeffs-detail span {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--bg); border: 1px solid var(--border);
  padding: 3px 8px; border-radius: 20px;
}

.ca-best-worst { display: flex; gap: 6px; flex-wrap: wrap; }
.ca-bw-item {
  flex: 1; min-width: 130px; padding: 8px 12px;
  border-radius: var(--radius-sm); font-size: 12px; font-weight: 600;
}
.ca-bw-best  { background: var(--success-soft); color: var(--success); }
.ca-bw-worst { background: var(--warning-soft); color: var(--warning); }

.ca-placeholder {
  font-size: 13px; color: var(--text-muted);
  text-align: center; padding: 16px 0 4px; font-style: italic;
}

/* Bloc météo automatique */
.ca-weather-block {
  background: var(--bg); border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 10px;
  border: 1px solid var(--border);
}
.ca-weather-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.ca-auto-badge {
  font-size: 11px; font-weight: 600; color: var(--success);
  background: var(--success-soft); padding: 2px 8px;
  border-radius: 20px;
}
.ca-auto-pending { color: var(--warning); background: var(--warning-soft); }
.ca-weather-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.ca-weather-main {
  display: flex; align-items: center; gap: 8px;
}
.ca-weather-emoji  { font-size: 26px; line-height: 1; }
.ca-weather-label  { font-size: 14px; font-weight: 700; color: var(--text); }
.ca-temp-badge {
  background: var(--primary-soft); color: var(--primary-dark);
  padding: 3px 9px; border-radius: 20px; font-size: 13px; font-weight: 700;
}
.ca-weather-btns { display: flex; gap: 4px; align-items: center; }
.ca-refresh-btn  { font-size: 14px !important; padding: 5px 8px !important; }

/* ── CA RÉEL DU JOUR ── */
.ca-real-section {
  margin-top: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.ca-real-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.ca-real-badge {
  font-size: 12px; font-weight: 700;
  padding: 3px 10px; border-radius: 20px;
}
.ca-real-badge.pos { background: var(--success-soft); color: var(--success); }
.ca-real-badge.neg { background: var(--danger-soft);  color: var(--danger); }
.ca-real-hint {
  font-size: 11px; color: var(--text-muted); font-style: italic;
}

/* Rangée comparaison estimé / réel / écart */
.ca-compare-row {
  display: flex; align-items: center; gap: 6px;
  margin-top: 10px; flex-wrap: wrap;
}
.ca-compare-item {
  flex: 1; min-width: 60px;
  display: flex; flex-direction: column; align-items: center;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 6px 8px;
}
.ca-compare-label {
  font-size: 10px; color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .4px; margin-bottom: 2px;
}
.ca-compare-val {
  font-size: 15px; font-weight: 800; color: var(--text);
}
.ca-compare-val.pos { color: var(--success); }
.ca-compare-val.neg { color: var(--danger); }
.ca-compare-sep {
  font-size: 16px; color: var(--text-muted); flex-shrink: 0;
}

/* ── GRAPHIQUE 7 JOURS ── */
.ca-chart {
  margin-top: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 12px 10px;
}
.ca-chart-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.ca-chart-title {
  font-size: 13px; font-weight: 700; color: var(--text);
}
.ca-chart-accuracy {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
}
.ca-chart-accuracy.good { background: var(--success-soft); color: var(--success); }
.ca-chart-accuracy.ok   { background: var(--warning-soft); color: var(--warning); }
.ca-chart-accuracy.low  { background: var(--danger-soft);  color: var(--danger);  }

.ca-chart-bars {
  display: flex; align-items: flex-end; gap: 4px;
  height: 90px; /* diff label + bars + label */
}
.ca-chart-col {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 0;
}
.ca-chart-col.today .ca-chart-day { color: var(--primary); font-weight: 700; }
.ca-chart-col.today .ca-bar-est   { background: rgba(193,127,36,0.35); }

.ca-chart-diff {
  font-size: 9px; font-weight: 700; height: 14px; line-height: 14px;
  text-align: center; width: 100%;
}
.ca-chart-diff.pos { color: var(--success); }
.ca-chart-diff.neg { color: var(--danger); }

.ca-chart-col-bars {
  display: flex; align-items: flex-end; gap: 2px;
  width: 100%; height: 64px;
}
.ca-bar-est {
  flex: 1; border-radius: 3px 3px 0 0; min-height: 3px;
  background: rgba(193,127,36,0.22);
  transition: height .3s ease;
}
.ca-bar-real {
  flex: 1; border-radius: 3px 3px 0 0; min-height: 0;
  background: var(--success);
  transition: height .3s ease;
}
.ca-chart-day {
  font-size: 10px; color: var(--text-muted);
  margin-top: 4px; text-align: center; width: 100%;
}
.ca-chart-legend {
  display: flex; gap: 14px; justify-content: center;
  margin-top: 10px;
}
.ca-legend-est  { font-size: 11px; color: rgba(193,127,36,0.6);  font-weight: 600; }
.ca-legend-real { font-size: 11px; color: var(--success); font-weight: 600; }

/* ── ONGLETS CATÉGORIE STOCK ── */
.stock-cat-tabs {
  display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap;
}
.stock-cat-btn {
  padding: 6px 14px; border-radius: 20px; font-size: 13px; font-weight: 600;
  background: var(--bg-card); border: 1.5px solid var(--border);
  color: var(--text-light); transition: all .15s;
}
.stock-cat-btn:hover { border-color: var(--primary); color: var(--primary); }
.stock-cat-btn.active {
  background: var(--primary); border-color: var(--primary);
  color: white;
}

/* ── CALIBRATION STATUT ── */
.ca-cal-status-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 8px;
}
.ca-cal-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; padding: 5px 10px;
  border-radius: 20px; flex: 1;
}
.ca-cal-badge.calibrated {
  background: var(--success-soft); color: var(--success);
}
.ca-cal-badge.generic {
  background: var(--warning-soft); color: var(--warning);
}
.ca-cal-badge-date {
  font-weight: 400; font-size: 10px; opacity: .8;
}
.ca-cal-open-btn {
  font-size: 12px; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 20px; white-space: nowrap;
  transition: background .15s;
}
.ca-cal-open-btn:hover { background: var(--border); }

/* ── BANNER AUTO-CALIBRATION ── */
.ca-autocal-banner {
  background: linear-gradient(135deg, #EBF5FB, #D6EAF8);
  border: 1px solid #AED6F1; border-radius: var(--radius-sm);
  padding: 10px 12px; margin-bottom: 12px;
}
.ca-autocal-text {
  font-size: 12px; color: var(--info); margin-bottom: 8px; line-height: 1.4;
}
.ca-autocal-btns {
  display: flex; gap: 8px; justify-content: flex-end;
}
.ca-autocal-dismiss {
  font-size: 12px; color: var(--text-muted); padding: 4px 10px;
  border-radius: 20px; background: rgba(255,255,255,.6);
  border: 1px solid var(--border);
}
.ca-autocal-apply {
  font-size: 12px; font-weight: 700; color: white; padding: 4px 12px;
  border-radius: 20px; background: var(--info); border: none;
}

/* ── MODAL CALIBRATION ── */
.ca-cal-desc {
  font-size: 13px; color: var(--text-light); line-height: 1.5;
  margin-bottom: 14px;
}
.ca-cal-badge-real {
  background: var(--info-soft); color: var(--info);
  font-size: 12px; font-weight: 600; padding: 6px 10px;
  border-radius: var(--radius-sm); margin-bottom: 12px;
  border: 1px solid #AED6F1; line-height: 1.4;
}
.ca-cal-rows {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px;
}
.ca-cal-row {
  display: flex; align-items: center; gap: 10px;
}
.ca-cal-label {
  font-size: 13px; font-weight: 600; color: var(--text); width: 90px; flex-shrink: 0;
}
.ca-cal-label.has-real { color: var(--success); }
.ca-cal-avg-row {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  font-size: 12px; color: var(--text-muted);
  background: var(--bg); border-radius: var(--radius-sm);
  padding: 8px 12px; margin-bottom: 14px;
}
.ca-cal-avg-row strong {
  font-size: 15px; color: var(--text);
}
