/* ============================================================================
   M.A AUTOMOBILES — GESTION DE STOCK
   Feuille de style — identité reprise du site (noir / rouge / blanc,
   Archivo pour les titres, Inter pour le texte).
   ============================================================================ */

:root{
  --black: #101114;
  --black-soft: #1b1d22;
  --white: #ffffff;
  --off-white: #f5f5f6;
  --red: #d5202b;
  --red-dark: #a91922;
  --gray-text: #3a3d42;
  --gray-mid: #6b6f76;
  --gray-line: #e3e4e7;
  --green: #1f8a4c;
  --amber: #b8790c;

  --font-display: 'Archivo', sans-serif;
  --font-body: 'Inter', sans-serif;

  --radius: 4px;
  --shadow-sm: 0 1px 2px rgba(16,17,20,0.08);
  --shadow-md: 0 4px 16px rgba(16,17,20,0.12);
  --header-h: 60px;
  --sidebar-w: 232px;
}

*{ box-sizing:border-box; margin:0; padding:0; }
html,body{ height:100%; }
body{
  font-family: var(--font-body);
  color: var(--gray-text);
  background: var(--off-white);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
  line-height: 1.5;
}
a{ color: inherit; text-decoration:none; }
img{ display:block; max-width:100%; }
button{ font-family: inherit; }
:focus-visible{ outline: 2px solid var(--red); outline-offset: 2px; }

h1,h2,h3,h4{ font-family: var(--font-display); color: var(--black); font-weight:800; letter-spacing:-0.01em; }
h1{ font-size: 24px; }
h2{ font-size: 19px; }
h3{ font-size: 16px; }

.hidden{ display:none !important; }
.text-muted{ color: var(--gray-mid); }
.text-red{ color: var(--red); }

/* ---------- Écrans centrés (login / pin) ---------- */
.center-screen{
  min-height:100vh;
  display:flex;
  align-items:center;
  justify-content:center;
  background: radial-gradient(circle at 30% 20%, #22242b 0%, var(--black) 65%);
  padding: 20px;
}
.center-screen::before{ content:none; }
.auth-card{
  position:relative;
  width:100%;
  max-width: 420px;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(6px);
  border-radius: 2px;
  padding: 40px 36px;
  text-align:center;
  box-shadow: var(--shadow-md);
}
.auth-card .logo{ height:52px; width:auto; margin:0 auto 22px; }
.err-title{ font-size:56px; color: var(--red); margin-bottom: 6px; }

/* ---------- PIN pad ---------- */
.pin-dots{ display:flex; gap:14px; justify-content:center; margin: 22px 0; }
.pin-dot{
  width:16px; height:16px; border-radius:50%;
  border: 2px solid var(--gray-line);
  background: transparent;
  transition: background .12s, border-color .12s;
}
.pin-dot.filled{ background: var(--red); border-color: var(--red); }
.pin-dot.error{ background: var(--red-dark); border-color: var(--red-dark); animation: shake .3s; }

@keyframes shake{
  0%,100%{ transform: translateX(0); }
  25%{ transform: translateX(-6px); }
  75%{ transform: translateX(6px); }
}

.pin-keypad{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 18px;
}
.pin-key{
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  padding: 20px 0;
  background: var(--white);
  border: 1px solid var(--gray-line);
  border-radius: var(--radius);
  cursor:pointer;
  color: var(--black);
  transition: background .1s, transform .05s;
}
.pin-key:active{ transform: scale(0.96); background: var(--off-white); }
.pin-key.key-clear{ color: var(--red); font-size:14px; }
.pin-key.key-back{ font-size: 20px; }

.pin-error-msg{ color: var(--red); font-size: 13px; min-height: 18px; margin-top: 8px; }
.pin-users-hint{ font-size: 13px; color: var(--gray-mid); margin-top: 18px; }

/* ---------- Layout applicatif (PC / direction) ---------- */
.app-shell{ display:flex; min-height:100vh; }
.sidebar{
  width: var(--sidebar-w);
  background: var(--black);
  color: var(--white);
  display:flex;
  flex-direction:column;
  flex-shrink:0;
  position: sticky; top:0; height:100vh;
}
.sidebar .brand{
  display:flex; align-items:center; gap:10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar .brand img{ height:30px; background:var(--white); padding:4px 6px; border-radius:3px; }
.sidebar .brand span{ font-family: var(--font-display); font-weight:800; font-size:14px; }
.sidebar nav{ flex:1; overflow-y:auto; padding: 10px 0; }
.sidebar a.nav-link{
  display:flex; align-items:center; gap:12px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.72);
  font-size: 14px;
  font-weight: 500;
  border-left: 3px solid transparent;
}
.sidebar a.nav-link:hover{ color: var(--white); background: rgba(255,255,255,0.04); }
.sidebar a.nav-link.active{
  color: var(--white);
  border-left-color: var(--red);
  background: rgba(213,32,43,0.12);
}
.sidebar .sidebar-footer{
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12.5px;
  color: rgba(255,255,255,0.55);
}
.sidebar .switch-user-btn{
  display:block; width:100%; margin-top:10px;
  padding: 8px 10px;
  background: rgba(255,255,255,0.08);
  border:none; border-radius: var(--radius);
  color: var(--white); font-size: 12.5px; text-align:left; cursor:pointer;
}
.sidebar .switch-user-btn:hover{ background: rgba(255,255,255,0.15); }

.main-area{ flex:1; min-width:0; display:flex; flex-direction:column; }
.topbar{
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-line);
  display:flex; align-items:center; justify-content:space-between;
  padding: 0 24px;
  position: sticky; top:0; z-index: 20;
}
.topbar h1{ font-size: 18px; }
.topbar .user-chip{
  display:flex; align-items:center; gap:8px;
  font-size: 13px; color: var(--gray-mid);
}
.topbar .user-chip strong{ color: var(--black); }
.burger-btn{ display:none; background:none; border:none; font-size:22px; cursor:pointer; color: var(--black); }

.content{ padding: 24px; flex:1; }

/* ---------- Cartes / KPI ---------- */
.kpi-grid{ display:grid; grid-template-columns: repeat(4, 1fr); gap:16px; margin-bottom: 24px; }
.kpi-card{
  background: var(--white); border:1px solid var(--gray-line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
}
.kpi-card .kpi-label{ font-size:12.5px; text-transform:uppercase; letter-spacing:.04em; color: var(--gray-mid); margin-bottom:6px; }
.kpi-card .kpi-value{ font-family: var(--font-display); font-size: 30px; font-weight:800; color: var(--black); }
.kpi-card.alert .kpi-value{ color: var(--red); }

.panel{
  background: var(--white); border:1px solid var(--gray-line); border-radius: var(--radius);
  padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow-sm);
}
.panel-header{ display:flex; align-items:center; justify-content:space-between; margin-bottom: 16px; flex-wrap:wrap; gap:10px; }

/* ---------- Boutons ---------- */
.btn{
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 600; font-size: 14px;
  border: 1px solid transparent;
  cursor:pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn-primary{ background: var(--red); color:var(--white); }
.btn-primary:hover{ background: var(--red-dark); }
.btn-dark{ background: var(--black); color:var(--white); }
.btn-dark:hover{ background: var(--black-soft); }
.btn-outline{ background: var(--white); color: var(--black); border-color: var(--gray-line); }
.btn-outline:hover{ background: var(--off-white); }
.btn-ghost{ background:transparent; color: var(--gray-text); }
.btn-ghost:hover{ background: var(--off-white); }
.btn-danger{ background: var(--white); color: var(--red); border-color: var(--red); }
.btn-danger:hover{ background: #fdecec; }
.btn-lg{ padding: 18px 20px; font-size: 16px; }
.btn:disabled{ opacity:.5; cursor:not-allowed; }
.btn-block{ width:100%; }
.btn-icon{ padding: 8px; }

/* ---------- Formulaires ---------- */
label{ display:block; font-size: 13px; font-weight:600; color: var(--black); margin-bottom:6px; }
input[type=text], input[type=number], input[type=email], input[type=password],
input[type=search], input[type=date], input[type=tel], select, textarea{
  width:100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-line);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--white);
  color: var(--black);
}
textarea{ resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus{ border-color: var(--red); }
.field{ margin-bottom: 16px; }
.field-row{ display:grid; grid-template-columns: 1fr 1fr; gap:14px; }
.field-hint{ font-size:12px; color: var(--gray-mid); margin-top:4px; }
.field-error{ font-size:12px; color: var(--red); margin-top:4px; }

.qty-stepper{ display:flex; align-items:center; gap: 10px; }
.qty-stepper button{
  width: 44px; height:44px; border-radius: var(--radius);
  border:1px solid var(--gray-line); background:var(--white);
  font-size: 22px; font-weight:700; cursor:pointer; color: var(--black);
}
.qty-stepper button:active{ background: var(--off-white); }
.qty-stepper input{ width: 64px; text-align:center; font-weight:700; font-size:18px; }

/* ---------- Tables ---------- */
.table-wrap{ overflow-x:auto; }
table{ width:100%; border-collapse: collapse; font-size: 14px; }
thead th{
  text-align:left; font-size:12px; text-transform:uppercase; letter-spacing:.03em;
  color: var(--gray-mid); padding: 10px 12px; border-bottom: 2px solid var(--gray-line);
}
tbody td{ padding: 12px; border-bottom: 1px solid var(--gray-line); vertical-align: middle; }
tbody tr:hover{ background: var(--off-white); }
.prod-thumb{ width:40px; height:40px; border-radius: var(--radius); object-fit:cover; background: var(--off-white); border:1px solid var(--gray-line); }

.badge{ display:inline-block; padding:3px 9px; border-radius: 20px; font-size:11.5px; font-weight:700; text-transform:uppercase; letter-spacing:.02em; }
.badge-green{ background:#e7f6ec; color: var(--green); }
.badge-red{ background:#fdecec; color: var(--red); }
.badge-amber{ background:#fdf2e0; color: var(--amber); }
.badge-gray{ background:var(--off-white); color: var(--gray-mid); }

/* ---------- Mode magasin (tablette/téléphone) : gros boutons tactiles ---------- */
.worker-shell{ min-height:100vh; display:flex; flex-direction:column; background: var(--off-white); }
.worker-topbar{
  background: var(--black); color: var(--white);
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 18px;
}
.worker-topbar .who{ font-family: var(--font-display); font-weight:800; font-size:15px; }
.worker-topbar .who small{ display:block; font-family: var(--font-body); font-weight:400; opacity:.7; font-size:11.5px; }
.worker-topbar button{
  background: rgba(255,255,255,0.1); border:none; color:var(--white);
  padding: 10px 14px; border-radius: var(--radius); font-size:13px; font-weight:600; cursor:pointer;
}

.action-grid{ display:grid; grid-template-columns: repeat(2, 1fr); gap:14px; padding: 18px; }
.action-tile{
  background: var(--white); border:1px solid var(--gray-line); border-radius: 8px;
  padding: 26px 16px; text-align:center; cursor:pointer;
  box-shadow: var(--shadow-sm);
}
.action-tile .tile-label{ font-family: var(--font-display); font-weight:800; font-size:15px; color: var(--black); }
.action-tile.primary{ background: var(--red); border-color: var(--red); }
.action-tile.primary .tile-label{ color: var(--white); }
.action-tile:active{ transform: scale(0.98); }

.scan-area{
  padding: 16px;
}
#scanner-video-wrap{
  position:relative; width:100%; max-width: 480px; margin: 0 auto;
  border-radius: 8px; overflow:hidden; background:#000; aspect-ratio: 4/3;
}
#scanner-video-wrap video, #scanner-video-wrap canvas{ width:100%; height:100%; object-fit:cover; }
.scan-frame-overlay{
  position:absolute; inset: 15% 10%;
  border: 3px solid var(--red); border-radius: 8px;
  pointer-events:none;
}

.cart-list{ padding: 0 16px; }
.cart-item{
  display:flex; align-items:center; gap:12px;
  background:var(--white); border:1px solid var(--gray-line); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 10px;
}
.cart-item img{ width:44px; height:44px; border-radius:var(--radius); object-fit:cover; background:var(--off-white); }
.cart-item .cart-info{ flex:1; min-width:0; }
.cart-item .cart-info .name{ font-weight:700; color:var(--black); font-size:14px; }
.cart-item .cart-info .meta{ font-size:12px; color:var(--gray-mid); }
.cart-item .cart-remove{ background:none; border:none; color: var(--red); font-size:20px; cursor:pointer; padding:4px 8px; }

.sticky-bottom-bar{
  position: sticky; bottom:0;
  background: var(--white); border-top:1px solid var(--gray-line);
  padding: 14px 16px; box-shadow: 0 -4px 12px rgba(0,0,0,0.06);
}

/* ---------- Modals ---------- */
.modal-overlay{
  position:fixed; inset:0; background: rgba(16,17,20,0.55);
  display:flex; align-items:center; justify-content:center; z-index: 100; padding: 16px;
}
.modal-box{
  background: var(--white); border-radius: 6px; width:100%; max-width: 560px;
  max-height: 90vh; overflow-y:auto; box-shadow: var(--shadow-md);
}
.modal-box.modal-lg{ max-width: 760px; }
.modal-header{ display:flex; align-items:center; justify-content:space-between; padding: 18px 22px; border-bottom:1px solid var(--gray-line); }
.modal-header h2{ font-size:17px; }
.modal-close{ background:none; border:none; font-size:22px; cursor:pointer; color:var(--gray-mid); }
.modal-body{ padding: 22px; }
.modal-footer{ display:flex; justify-content:flex-end; gap:10px; padding: 16px 22px; border-top:1px solid var(--gray-line); }

/* ---------- Toasts ---------- */
#toast-container{ position:fixed; top:16px; right:16px; z-index: 200; display:flex; flex-direction:column; gap:10px; }
.toast{
  background: var(--black); color:var(--white); padding: 12px 18px; border-radius: var(--radius);
  font-size:14px; box-shadow: var(--shadow-md); min-width: 240px; animation: slideIn .18s ease-out;
}
.toast.success{ background: var(--green); }
.toast.error{ background: var(--red); }
@keyframes slideIn{ from{ opacity:0; transform: translateY(-8px);} to{ opacity:1; transform:none; } }

/* ---------- Alerte auto-déconnexion ---------- */
#logout-warning{
  position:fixed; inset:0; background: rgba(16,17,20,0.72);
  display:flex; align-items:center; justify-content:center; z-index: 300;
}
#logout-warning .box{ background:var(--white); border-radius:8px; padding: 34px 30px; text-align:center; max-width: 340px; }
#logout-warning .countdown{ font-family: var(--font-display); font-size: 44px; color: var(--red); font-weight:900; margin: 10px 0; }

/* ---------- Empty states ---------- */
.empty-state{ text-align:center; padding: 40px 20px; color: var(--gray-mid); }
.empty-state .big-icon{ font-size:42px; margin-bottom:10px; }

/* ---------- Filtres ---------- */
.filters-bar{ display:flex; gap:10px; flex-wrap:wrap; margin-bottom:16px; align-items:flex-end; }
.filters-bar .field{ margin-bottom:0; min-width: 160px; }

/* ---------- Tabs ---------- */
.tabs{ display:flex; gap: 4px; border-bottom: 2px solid var(--gray-line); margin-bottom: 18px; }
.tab-btn{
  background:none; border:none; padding: 10px 16px; font-weight:600; font-size:14px;
  color: var(--gray-mid); cursor:pointer; border-bottom: 2px solid transparent; margin-bottom:-2px;
}
.tab-btn.active{ color: var(--red); border-bottom-color: var(--red); }

/* ---------- Responsive ---------- */
@media (max-width: 1199px){
  .kpi-grid{ grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 991px){
  .sidebar{ position:fixed; left:-100%; top:0; height:100vh; z-index: 60; transition: left .2s; width: 260px; }
  .sidebar.open{ left:0; }
  .burger-btn{ display:block; }
  .sidebar-backdrop{ display:none; position:fixed; inset:0; background:rgba(0,0,0,.4); z-index:50; }
  .sidebar-backdrop.open{ display:block; }
  .content{ padding:16px; }
}

@media (max-width: 767px){
  .kpi-grid{ grid-template-columns: 1fr 1fr; }
  .field-row{ grid-template-columns: 1fr; }
  table thead{ display:none; }
  table, tbody, tr, td{ display:block; width:100%; }
  tbody tr{
    border:1px solid var(--gray-line); border-radius: var(--radius); margin-bottom:10px; padding:8px 12px;
    background: var(--white);
  }
  tbody td{ border:none; padding:6px 0; display:flex; justify-content:space-between; gap:10px; }
  tbody td::before{ content: attr(data-label); font-weight:600; color: var(--gray-mid); font-size:12px; }
  .action-grid{ grid-template-columns: 1fr 1fr; padding: 12px; gap:10px; }
}

@media (max-width: 480px){
  .auth-card{ padding: 32px 22px; }
  .pin-key{ padding: 16px 0; font-size: 20px; }
}
