/* ===== Gestion commerciale – thème clair moderne ===== */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --ink: #1b2130;
  --ink-2: #4a5468;
  --muted: #7a8396;
  --line: #e6e8ef;
  --line-2: #eef0f5;
  --brand: #a3262a;          /* rouge BERRICHE */
  --brand-dark: #861d21;
  --brand-soft: #fbeceb;
  --accent: #e8823a;         /* orange du logo */
  --ok: #15803d;  --ok-soft: #e7f6ec;
  --warn: #b45309; --warn-soft: #fff4e2;
  --bad: #c42b2b; --bad-soft: #fdeaea;
  --info: #1d5fa8; --info-soft: #e8f0fb;
  --violet: #6d3fc0; --violet-soft: #f1ebfb;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 28, 48, .04), 0 4px 16px rgba(20, 28, 48, .06);
  --shadow-lg: 0 12px 40px rgba(20, 28, 48, .18);
  --sidebar: 248px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar); background: var(--surface);
  border-right: 1px solid var(--line); display: flex; flex-direction: column; z-index: 50;
  transition: transform .25s ease;
}
.sidebar .brand { display: flex; align-items: center; justify-content: center; padding: 18px 16px 14px; min-height: 76px; text-decoration: none; }
.sidebar .brand img { max-width: 190px; max-height: 54px; object-fit: contain; }
.sidebar .brand span { font-weight: 800; font-size: 19px; color: var(--brand); font-style: italic; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 6px 12px; }
.sidebar nav .group { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; margin: 2px 0; border-radius: var(--radius-sm);
  color: var(--ink-2); font-weight: 500; text-decoration: none; transition: background .15s, color .15s;
}
.sidebar nav a svg { width: 20px; height: 20px; flex: none; stroke: currentColor; }
.sidebar nav a:hover { background: var(--line-2); color: var(--ink); }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand); font-weight: 650; box-shadow: inset 3px 0 0 var(--brand); }
.sidebar .userbox { border-top: 1px solid var(--line); padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.sidebar .userbox .who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, var(--brand), var(--accent)); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.sidebar .userbox .name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.sidebar .userbox .role { font-size: 12px; color: var(--muted); }
.sidebar .userbox .actions { display: flex; gap: 6px; }
.sidebar .userbox .actions button { flex: 1; white-space: nowrap; }
.sidebar .userbox .actions button:last-child { flex: none; }
button svg, .btn svg { width: 17px; height: 17px; stroke: currentColor; flex: none; }

.mobilebar { display: none; }
.scrim { display: none; }

main { max-width: 1240px; margin: 0 auto; padding: 26px 32px 48px; animation: page-in .35s ease both; }
body.with-sidebar main { margin-left: var(--sidebar); max-width: none; }
body.with-sidebar main > * { max-width: 1180px; }

@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- Typography ---------- */
h1 { font-size: 26px; font-weight: 750; letter-spacing: -.02em; margin: 2px 0 20px; }
h2 { margin: 0 0 14px; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 14px 0 6px; }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 22px 0; text-align: center; }

/* ---------- Cards & layout ---------- */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 20px; margin-bottom: 18px;
  box-shadow: var(--shadow); border: 1px solid rgba(20, 28, 48, .04); animation: rise .4s ease both;
}
main > .card:nth-of-type(2), main > form > .card:nth-of-type(2) { animation-delay: .05s; }
main > .card:nth-of-type(3), main > form > .card:nth-of-type(3) { animation-delay: .1s; }
main > .card:nth-of-type(n+4), main > form > .card:nth-of-type(n+4) { animation-delay: .15s; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.grid .full { grid-column: 1 / -1; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
input, select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid #d9dde6; border-radius: var(--radius-sm); font-size: 15px;
  font-family: inherit; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(163, 38, 42, .12); }
input:disabled, select:disabled, textarea:disabled { background: #f7f8fb; color: var(--ink-2); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--brand); color: #fff; border: 1px solid transparent; padding: 11px 18px; border-radius: var(--radius-sm);
  font-size: 15px; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; font-family: inherit;
  box-shadow: 0 1px 2px rgba(163, 38, 42, .25); transition: background .15s, transform .12s, box-shadow .15s;
}
button:hover, .btn:hover { background: var(--brand-dark); text-decoration: none; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(163, 38, 42, .25); }
button:active, .btn:active { transform: translateY(0); }
button.secondary, .btn.secondary { background: #fff; color: var(--ink); border-color: #d9dde6; box-shadow: none; }
button.secondary:hover, .btn.secondary:hover { background: #f4f5f9; box-shadow: none; }
button.danger, .btn.danger { background: #fff; color: var(--bad); border-color: #f1c6c6; box-shadow: none; }
button.danger:hover, .btn.danger:hover { background: var(--bad-soft); box-shadow: none; }
button.success, .btn.success { background: var(--ok); box-shadow: 0 1px 2px rgba(21, 128, 61, .25); }
button.success:hover, .btn.success:hover { background: #126a33; box-shadow: 0 4px 12px rgba(21, 128, 61, .25); }
button.whatsapp, .btn.whatsapp { background: #1fa855; box-shadow: none; }
button.whatsapp:hover, .btn.whatsapp:hover { background: #178a45; }
button.small, .btn.small { padding: 7px 11px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; transform: none; }
.iconbtn { background: transparent; color: var(--ink); box-shadow: none; padding: 8px; border: 0; }
.iconbtn:hover { background: var(--line-2); box-shadow: none; transform: none; }
.iconbtn svg { width: 24px; height: 24px; stroke: currentColor; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { background: #f8f9fc; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tbody tr { transition: background .12s; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #fafbfe; }
tfoot th { background: #fff; color: var(--ink); font-size: 14px; text-transform: none; letter-spacing: 0; border-top: 2px solid var(--line); }
.thumb { width: 48px; height: 48px; object-fit: contain; border-radius: 10px; background: #fff; border: 1px solid var(--line-2); display: block; }

/* ---------- Badges & tabs ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.st-recue { background: var(--info-soft); color: var(--info); }
.st-diagnostic { background: var(--violet-soft); color: var(--violet); }
.st-attente_piece { background: var(--warn-soft); color: var(--warn); }
.st-en_reparation { background: #fdeee6; color: #b4461a; }
.st-prete { background: var(--ok-soft); color: var(--ok); }
.st-livree { background: #eef0f4; color: #4a5468; }
.st-annulee { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; background: #f1f2f7; padding: 5px; border-radius: 12px; width: fit-content; max-width: 100%; }
.tabs button { background: transparent; color: var(--ink-2); padding: 8px 14px; font-size: 14px; box-shadow: none; border: 0; }
.tabs button:hover { background: rgba(255, 255, 255, .7); transform: none; box-shadow: none; }
.tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(20, 28, 48, .12); }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); text-decoration: none; color: inherit;
  display: flex; flex-direction: column; gap: 4px; border: 1px solid rgba(20, 28, 48, .04); animation: rise .45s ease both;
  transition: transform .15s, box-shadow .15s;
}
.stat:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(20, 28, 48, .1); text-decoration: none; }
.stat .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; margin-bottom: 8px; background: var(--line-2); color: var(--ink-2); }
.stat .ico svg { width: 21px; height: 21px; stroke: currentColor; }
.stat .n { font-size: 28px; font-weight: 750; letter-spacing: -.02em; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 13.5px; }
.stat.alert .n { color: var(--bad); }
.stat.alert .ico { background: var(--bad-soft); color: var(--bad); }
.stats .stat:nth-child(2) { animation-delay: .04s; } .stats .stat:nth-child(3) { animation-delay: .08s; }
.stats .stat:nth-child(4) { animation-delay: .12s; } .stats .stat:nth-child(5) { animation-delay: .16s; }
.stats .stat:nth-child(6) { animation-delay: .2s; } .stats .stat:nth-child(n+7) { animation-delay: .24s; }

/* ---------- Photos ---------- */
.photos { display: flex; gap: 10px; flex-wrap: wrap; }
.photo { position: relative; }
.photo img { width: 130px; height: 100px; object-fit: cover; border-radius: 10px; display: block; cursor: zoom-in; border: 1px solid var(--line); }
.photo button { position: absolute; top: 4px; right: 4px; padding: 3px 8px; font-size: 12px; }

/* ---------- Dialogs & toast ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(740px, 96vw); max-height: 92vh; box-shadow: var(--shadow-lg); }
dialog[open] { animation: pop .22s ease both; }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(6px); } to { opacity: 1; transform: none; } }
dialog::backdrop { background: rgba(17, 22, 35, .45); backdrop-filter: blur(3px); }
dialog .dlg-body { padding: 22px; overflow-y: auto; max-height: calc(92vh - 74px); }
dialog .dlg-foot { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; background: #fafbfd; }
dialog.viewer { width: auto; max-width: 96vw; background: #000; }
dialog.viewer img { max-width: 96vw; max-height: 90vh; display: block; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1b2130; color: #fff; padding: 12px 20px;
  border-radius: 12px; font-size: 15px; display: none; z-index: 1000; max-width: 90vw; box-shadow: var(--shadow-lg); animation: toast-in .25s ease both;
}
#toast.err { background: var(--bad); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Repair page ---------- */
.tests { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.test { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fcfcfe; }
.test .opts { display: flex; gap: 4px; }
.test .opts button { padding: 6px 10px; font-size: 13px; background: #fff; color: var(--ink-2); border: 1px solid var(--line); box-shadow: none; }
.test .opts button:hover { transform: none; box-shadow: none; }
.test .opts button.on.ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.test .opts button.on.ko { background: var(--bad); color: #fff; border-color: var(--bad); }
.sigpad { border: 2px dashed #cfd4de; border-radius: 12px; background: #fff; touch-action: none; width: 100%; max-width: 520px; height: 180px; display: block; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }

/* ---------- Search pickers ---------- */
.picker { position: relative; }
.picker ul { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px; list-style: none; margin: 6px 0 0; padding: 4px; max-height: 280px; overflow-y: auto; box-shadow: var(--shadow-lg); }
.picker li { padding: 10px; cursor: pointer; border-radius: 8px; }
.picker li:hover { background: var(--brand-soft); }

/* ---------- Dashboard ---------- */
.hello { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.hello h1 { margin: 0; }
.hello .date { color: var(--muted); margin-top: 4px; }
.hello .date::first-letter { text-transform: uppercase; }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.quick a {
  display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: var(--radius); text-decoration: none; color: #fff; font-weight: 650;
  background: linear-gradient(135deg, var(--brand), #c4442f); box-shadow: 0 6px 18px rgba(163, 38, 42, .25); transition: transform .15s, box-shadow .15s; animation: rise .4s ease both;
}
.quick a:nth-child(2) { background: linear-gradient(135deg, #c4442f, var(--accent)); animation-delay: .05s; }
.quick a:nth-child(3) { background: linear-gradient(135deg, #2b3448, #1b2130); box-shadow: 0 6px 18px rgba(27, 33, 48, .25); animation-delay: .1s; }
.quick a:hover { transform: translateY(-3px); text-decoration: none; }
.quick a svg { width: 24px; height: 24px; stroke: currentColor; }
.dash-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; margin-bottom: 18px; }
.dash-grid .card { margin-bottom: 0; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; background: #1b2130; color: #fff; padding: 8px 10px; border-radius: 8px; font-size: 13px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .12s; }
.mini-list { list-style: none; padding: 0; margin: 0; }
.mini-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.mini-list li:last-child { border-bottom: 0; }
.mini-list a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 10px; width: 100%; }
.mini-list img { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line-2); background: #fff; flex: none; }
.mini-list .grow { flex: 1; min-width: 0; }
.mini-list .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* ---------- Low stock alerts ---------- */
.nav-badge { margin-left: auto; background: var(--bad); color: #fff; font-size: 11.5px; font-weight: 700; min-width: 22px; height: 22px; padding: 0 6px;
  border-radius: 999px; display: inline-grid; place-items: center; animation: pulse 2s ease-in-out 3; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(196, 43, 43, .5); } 50% { box-shadow: 0 0 0 6px rgba(196, 43, 43, 0); } }
.stock-alert { position: fixed; bottom: 16px; right: 16px; z-index: 900; background: var(--bad); color: #fff; padding: 14px 18px; border-radius: 12px;
  box-shadow: var(--shadow-lg); max-width: min(420px, 92vw); text-decoration: none; animation: rise .35s ease both; transition: opacity .4s, transform .4s; }
.stock-alert:hover { text-decoration: none; filter: brightness(1.05); }
.stock-alert.hide { opacity: 0; transform: translateY(10px); pointer-events: none; }
tr.low td { background: var(--bad-soft); }
.badge.low { background: var(--bad-soft); color: var(--bad); }

/* ---------- Role-based visibility ---------- */
body:not(.role-gerant) .only-gerant { display: none !important; }
body.role-technicien .only-sales, body:not([class*="role-"]) .only-sales { display: none !important; }

/* ---------- Tablet / phone ---------- */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(17, 22, 35, .4); z-index: 40; }
  .mobilebar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: 0; z-index: 30;
    background: rgba(255, 255, 255, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); padding: 8px 12px;
  }
  .mobilebar img { max-height: 36px; max-width: 160px; }
  .mobilebar .title { font-weight: 700; color: var(--brand); }
  body.with-sidebar main { margin-left: 0; }
  main { padding: 16px 14px 40px; }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .stat .n { font-size: 22px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .ico { width: 34px; height: 34px; margin-bottom: 4px; }
  .hide-sm { display: none; }
  td.num { white-space: nowrap; }
  .stock-alert { right: 12px; left: 12px; max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.today-card { border-left: 4px solid var(--brand); }
.guide-box { margin-top: 14px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 12px; background: #fbfbfd; }
.guide-box ol { margin: 10px 0; padding-left: 22px; }
.guide-box li { margin: 4px 0; }
