* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; background: #f8fafc; color: #0f172a; overflow: hidden; }
/* Conteneur général figé à 100vh (jamais min-height) : le défilement de la page elle-même est
   désactivé, seuls le menu et le contenu défilent, chacun indépendamment (correction post-v1.0,
   section "menu latéral et page de droite indépendants"). */
#app { display: flex; height: 100vh; }

.sidebar { width: 240px; flex-shrink: 0; background: #0f172a; color: white; padding: 16px; height: 100vh; overflow-y: auto; transition: width .15s ease; }
.sidebar .brand { font-weight: 700; font-size: 18px; margin-bottom: 16px; padding: 0 8px; white-space: nowrap; overflow: hidden; }
.sidebar .brand-short { display: none; }
.nav-group { margin-bottom: 14px; }
.nav-group-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #64748b;
  padding: 6px 10px 4px; white-space: nowrap; background: transparent; width: 100%;
  display: flex; align-items: center; justify-content: space-between; text-align: start;
}
.nav-group-label::after { content: "\25BE"; font-size: 9px; flex-shrink: 0; }
.nav-group.group-collapsed .nav-group-label::after { content: "\25B8"; }
html[dir="rtl"] .nav-group.group-collapsed .nav-group-label::after { content: "\25C2"; }
.nav-group.group-collapsed .nav-group-items { display: none; }
.sidebar a { display: block; padding: 9px 10px; border-radius: 6px; color: #cbd5e1; text-decoration: none; font-size: 14px; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar a:hover { background: #1e293b; color: white; }
.sidebar a.active { background: #2563eb; color: white; }

/* Sidebar repliée (desktop) : icônes/texte tronqué, largeur réduite */
.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .brand-full, .sidebar.collapsed .nav-group-label { display: none; }
.sidebar.collapsed .brand-short { display: block; text-align: center; }
.sidebar.collapsed a { text-align: center; font-size: 11px; padding: 8px 4px; }

.main { flex: 1; min-width: 0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.topbar { flex-shrink: 0; display: flex; align-items: center; gap: 12px; padding: 10px 20px; background: white; border-bottom: 1px solid #e2e8f0; }
.content { flex: 1; padding: 24px; overflow-y: auto; overflow-x: auto; }
.btn-icon { background: transparent; color: #0f172a; font-size: 18px; padding: 4px 8px; }
.btn-icon:hover { background: #f1f5f9; }
#mobile-menu-btn { display: none; }
.sidebar-backdrop { display: none; }

/* Mobile : sidebar en panneau superposé, ouverte via le bouton hamburger */
@media (max-width: 768px) {
  #app { position: relative; }
  .sidebar { position: fixed; inset-inline-start: 0; top: 0; bottom: 0; z-index: 200; width: 250px; transform: translateX(-100%); transition: transform .2s ease; }
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .sidebar.collapsed { width: 250px; } /* le mode replié n'a pas de sens en superposition mobile */
  .sidebar.collapsed .brand-full { display: block; }
  .sidebar.collapsed .nav-group-label { display: flex; }
  .sidebar.collapsed .brand-short { display: none; }
  .sidebar.collapsed a { text-align: start; font-size: 14px; padding: 9px 10px; }
  #mobile-menu-btn { display: inline-block; }
  .collapse-btn { display: none; }
  .sidebar-backdrop.visible { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 150; }
}

h1 { font-size: 20px; margin: 0 0 16px; }
.card { background: white; border: 1px solid #e2e8f0; border-radius: 10px; padding: 16px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-label { font-size: 12px; color: #64748b; }
.stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; background: white; border-radius: 8px; overflow: hidden; }
th, td { text-align: start; padding: 9px 10px; border-bottom: 1px solid #eef2f7; }
th { background: #f1f5f9; font-weight: 600; font-size: 12px; text-transform: uppercase; color: #475569; }
tr:hover td { background: #f8fafc; }

input, select, textarea { padding: 7px 10px; border: 1px solid #cbd5e1; border-radius: 6px; font-size: 14px; width: 100%; }
label { font-size: 12px; color: #475569; display: block; margin-bottom: 3px; }
.field { margin-bottom: 10px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

button { cursor: pointer; border: none; border-radius: 6px; padding: 8px 14px; font-size: 14px; font-weight: 500; }
.btn-primary { background: #0f172a; color: white; }
.btn-primary:hover { background: #1e293b; }
.btn-secondary { background: #e2e8f0; color: #0f172a; }
.btn-danger { background: #dc2626; color: white; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-neutral { background: #e2e8f0; color: #334155; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-warning { background: #fef9c3; color: #854d0e; }
.alert-success { background: #dcfce7; color: #166534; }

.help-text { color: #64748b; font-size: 13px; }
.btn-secondary.active { background: #2563eb; color: white; }
.pos-product-btn:disabled { pointer-events: none; }

.toast-container { position: fixed; top: 16px; inset-inline-end: 16px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 10px 16px; border-radius: 8px; color: white; font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,.15); animation: slidein .2s ease; }
.toast-success { background: #16a34a; }
.toast-error { background: #dc2626; }
@keyframes slidein { from { opacity:0; transform: translateY(-8px);} to {opacity:1; transform:none;} }

.login-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; width: 100%; background: #0f172a; }
.login-box { background: white; padding: 32px; border-radius: 12px; width: 340px; }

.search-bar { margin-bottom: 12px; max-width: 320px; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: white; border-radius: 10px; padding: 20px; width: 420px; max-height: 85vh; overflow: auto; }

/* RTL */
html[dir="rtl"] .sidebar { text-align: right; }
html[dir="rtl"] table { direction: rtl; }
html[dir="rtl"] .stat-value, html[dir="rtl"] td.num { direction: ltr; text-align: right; unicode-bidi: isolate; }
