:root {
  --bg: #F3F6F5;
  --surface: #FFFFFF;
  --ink: #17302C;
  --ink-2: #4E6662;
  --ink-3: #859995;
  --line: #DCE5E2;
  --zellige: #0F6E5A;
  --zellige-deep: #0A4D3F;
  --zellige-soft: #E1F0EB;
  --saffron: #D99327;
  --danger: #C2412D;

  /* status colors */
  --s-nouvelle: #3B6FB6;
  --s-pas_de_reponse: #8A6BB8;
  --s-rappel: #D99327;
  --s-confirmee: #0F6E5A;
  --s-annulee: #C2412D;
  --s-expediee: #2A8C9E;
  --s-livree: #3E9B4F;
  --s-retournee: #7A6A58;

  --radius-s: 6px;
  --radius-m: 10px;
  --font: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--zellige); }
:focus-visible { outline: 2px solid var(--zellige); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr minmax(320px, 440px);
}
.login-side {
  background: var(--zellige-deep);
  color: #EAF5F1;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-side::after {
  /* zellige-inspired star tessellation */
  content: '';
  position: absolute; inset: 0;
  opacity: .09;
  background-image:
    conic-gradient(from 45deg at 50% 50%, #fff 0 25%, transparent 0 50%, #fff 0 75%, transparent 0);
  background-size: 56px 56px;
  mask-image: linear-gradient(to top, #000 10%, transparent 75%);
  pointer-events: none;
}
.login-side h1 { font-size: 44px; line-height: 1.05; font-weight: 600; margin: 0; max-width: 12ch; letter-spacing: -.02em; }
.login-side p { max-width: 38ch; color: #B9D8CF; margin: 16px 0 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--zellige); color: #fff; display: grid; place-items: center; }
.login-side .brand-mark { background: #fff; }
.login-form { padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; background: var(--surface); }
.login-form h2 { margin: 0 0 4px; font-size: 24px; letter-spacing: -.01em; }
.login-form form { display: grid; gap: 14px; margin-top: 24px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.side .brand { padding: 0 8px 18px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-s);
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--zellige-soft); color: var(--zellige-deep); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .count { margin-left: auto; font-size: 12px; background: var(--saffron); color: #fff; border-radius: 99px; padding: 0 7px; font-weight: 600; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; }
.side-foot strong { display: block; font-size: 14px; }
.side-foot button { background: none; border: 0; padding: 0; color: var(--ink-2); cursor: pointer; text-decoration: underline; margin-right: 10px; }

main { padding: 28px 32px 64px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 26px; letter-spacing: -.015em; font-weight: 600; }
.page-head p { margin: 2px 0 0; color: var(--ink-2); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 8px 14px; border-radius: var(--radius-s);
  font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--ink);
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--zellige); border-color: var(--zellige); color: #fff; }
.btn-primary:hover { background: var(--zellige-deep); border-color: var(--zellige-deep); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }

label.field { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=tel], input[type=url], select, textarea {
  width: 100%; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: var(--radius-s);
  background: var(--surface); font-size: 14px; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--zellige); box-shadow: 0 0 0 3px var(--zellige-soft); }
textarea { resize: vertical; min-height: 70px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.actions input, .actions select { width: auto; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }

/* ---------- Flow strip (the signature element) ---------- */
.flow {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  overflow: hidden;
  margin-bottom: 20px;
}
.flow-step {
  padding: 14px 14px 16px;
  border-right: 1px solid var(--line);
  text-decoration: none; color: inherit;
  position: relative;
  display: flex; flex-direction: column; gap: 2px;
}
.flow-step:last-child { border-right: 0; }
.flow-step:hover { background: var(--bg); }
.flow-step::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 4px;
  background: var(--c);
}
.flow-step .n { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.flow-step .l { font-size: 13px; color: var(--ink-2); }
.flow-step .bar { height: 4px; border-radius: 2px; background: var(--bg); margin-top: 8px; overflow: hidden; }
.flow-step .bar span { display: block; height: 100%; background: var(--c); }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px; }
.kpi .v { font-size: 30px; font-weight: 600; letter-spacing: -.02em; line-height: 1.1; }
.kpi .k { color: var(--ink-2); font-size: 14px; }
.kpi .s { color: var(--ink-3); font-size: 13px; margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 3fr 2fr; gap: 16px; margin-bottom: 16px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 18px; min-width: 0; }
.panel h2 { font-size: 16px; margin: 0 0 14px; font-weight: 600; }
.panel-empty { color: var(--ink-3); font-size: 14px; padding: 12px 0; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 10px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; min-width: 0; }
.chart .total { background: var(--zellige-soft); border-radius: 3px 3px 0 0; position: relative; }
.chart .conf { background: var(--zellige); position: absolute; bottom: 0; left: 0; right: 0; border-radius: 3px 3px 0 0; }
.chart .col:hover .total { background: #C9E4DA; }
.chart-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin-top: 6px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list-row:last-child { border-bottom: 0; }

/* ---------- Tables ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.filters input[type=search] { width: 240px; }
.filters select, .filters input[type=date] { width: auto; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; font-size: 13px; color: var(--ink-2); padding: 10px 12px; border-bottom: 1px solid var(--line); background: #FAFCFB; white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #F8FBFA; }
tbody tr.selected { background: var(--zellige-soft); }
td.right, th.right { text-align: right; }
.cell-main { font-weight: 600; }
.cell-sub { font-size: 13px; color: var(--ink-2); }
.dupe { font-size: 12px; color: var(--saffron); font-weight: 600; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 12px 2px; font-size: 14px; color: var(--ink-2); }
.bulkbar {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  background: var(--zellige-deep); color: #fff; padding: 8px 12px; border-radius: var(--radius-m); margin-bottom: 12px;
}
.bulkbar select { width: auto; padding: 5px 8px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  color: var(--c);
}
.chip::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.tag { font-size: 12px; padding: 1px 7px; border-radius: 99px; background: var(--bg); color: var(--ink-2); border: 1px solid var(--line); }
.stock-low { color: var(--danger); font-weight: 600; }

/* ---------- Drawer (order detail) ---------- */
.scrim { position: fixed; inset: 0; background: rgba(23, 48, 44, .35); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%);
  background: var(--surface); z-index: 41; overflow-y: auto;
  box-shadow: -12px 0 40px rgba(23, 48, 44, .18);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .6; } }
.drawer-head { padding: 20px 24px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.drawer-head .top { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 6px 0 0; font-size: 22px; letter-spacing: -.01em; }
.drawer-body { padding: 18px 24px 32px; display: grid; gap: 20px; }
.close { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--ink-2); padding: 4px 8px; }
.call-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.phone-big { font-size: 22px; font-weight: 600; letter-spacing: .01em; text-decoration: none; color: var(--ink); }
.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.status-btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-s);
  padding: 10px 12px; text-align: left; cursor: pointer; font-weight: 600; color: var(--c);
  display: flex; justify-content: space-between; align-items: center;
}
.status-btn:hover { border-color: var(--c); background: color-mix(in srgb, var(--c) 7%, white); }
.status-btn[aria-pressed="true"] { background: var(--c); color: #fff; border-color: var(--c); }
.status-btn kbd { font: inherit; font-size: 11px; opacity: .6; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; }
.section-title { font-size: 14px; font-weight: 600; margin: 0 0 8px; }
.dl { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 14px; margin: 0; }
.dl dt { color: var(--ink-2); }
.dl dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.timeline li { padding: 8px 0 8px 16px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 13px; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); }
.timeline .when { color: var(--ink-3); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; z-index: 50; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(560px, calc(100% - 32px)); max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: var(--radius-m); padding: 22px 24px;
  box-shadow: 0 20px 60px rgba(23, 48, 44, .25);
}
.modal h2 { margin: 0 0 16px; font-size: 19px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Import ---------- */
.import-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.import-grid .panel p { color: var(--ink-2); font-size: 14px; margin: 0 0 12px; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius-m); padding: 22px; text-align: center;
  color: var(--ink-2); cursor: pointer; font-size: 14px;
}
.drop.over { border-color: var(--zellige); background: var(--zellige-soft); }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; background: var(--bg); padding: 2px 5px; border-radius: 4px; word-break: break-all; }
.result { margin-top: 12px; font-size: 14px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-s);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 60;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

.mobile-top { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .flow { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .flow-step:nth-child(4) { border-right: 0; }
  .flow-step:nth-child(-n+4) { border-bottom: 1px solid var(--line); }
  .grid-2, .import-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .login { grid-template-columns: 1fr; }
  .login-side { padding: 28px 24px; min-height: 220px; }
  .login-side h1 { font-size: 30px; }
  .login-form { padding: 32px 20px; }
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 240px; z-index: 45; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .mobile-top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; }
  .mobile-top button { background: none; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 10px; cursor: pointer; }
  main { padding: 18px 16px 48px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .filters input[type=search] { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Setup steps ---------- */
.steps { margin: 0 0 10px; padding-left: 20px; font-size: 14px; display: grid; gap: 6px; }
.steps li::marker { color: var(--zellige); font-weight: 600; }
fieldset.store-pick { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 10px 12px 12px; margin: 0; }
fieldset.store-pick legend { padding: 0 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { display: flex; gap: 6px; align-items: center; font-weight: 400; color: var(--ink); font-size: 14px; }
