:root {
  --accent: #4f46e5;
  --accent-d: #4338ca;
  --accent-soft: #eef2ff;
  --accent-grad: linear-gradient(135deg, #6366f1, #4f46e5 70%, #4338ca);
  --ink: #131a2e;
  --ink-2: #5a6478;
  --ink-3: #9aa3b5;
  --line: #e8ebf2;
  --line-2: #f1f3f8;
  --bg: #f4f6fa;
  --card: #ffffff;
  --r-card: 20px;
  --r-md: 13px;
  --r-sm: 10px;
  --sh-sm: 0 2px 8px rgba(28,35,60,.05);
  --sh-md: 0 6px 22px rgba(28,35,60,.08);
  --sh-lg: 0 18px 50px rgba(28,35,60,.18);
  --ease: cubic-bezier(.4,0,.2,1);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-soft); }
.boot { height: 100vh; display: grid; place-items: center; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: sp .8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes shimmer { to { background-position: 200% 0; } }

/* ---------------- Auth ---------------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr .9fr; }
.auth-visual { background: var(--accent-grad); color: #fff; padding: 52px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-visual::after { content: ""; position: absolute; width: 480px; height: 480px; border-radius: 50%; background: rgba(255,255,255,.08); top: -160px; right: -160px; }
.auth-visual .brand { display: flex; align-items: center; gap: 12px; position: relative; }
.auth-visual .mark { width: 46px; height: 46px; border-radius: 13px; background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 800; font-size: 23px; }
.auth-visual .brand strong { display: block; font-size: 17px; }
.auth-visual .brand span { font-size: 13px; opacity: .82; }
.auth-visual h1 { font-size: 32px; margin: 0 0 10px; line-height: 1.12; position: relative; }
.auth-visual p { opacity: .9; max-width: 430px; position: relative; }
.auth-panel { display: flex; flex-direction: column; justify-content: center; gap: 18px; padding: 52px; max-width: 440px; }
.auth-panel small { color: var(--ink-3); }
@media (max-width: 820px) { .auth-wrap { grid-template-columns: 1fr; } .auth-visual { display: none; } }

/* ---------------- Shell ---------------- */
.shell { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; gap: 3px; position: sticky; top: 0; height: 100vh; }
.sb-brand { display: flex; align-items: center; gap: 11px; padding: 6px 10px 18px; }
.sb-logo { width: 40px; height: 40px; border-radius: 12px; background: var(--accent-grad); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 20px; box-shadow: var(--sh-sm); }
.sb-brandtxt b { display: block; font-size: 14.5px; }
.sb-brandtxt small { color: var(--ink-3); font-size: 12px; }
.sb-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--r-sm); color: var(--ink-2); cursor: pointer; font-weight: 600; text-decoration: none; border: none; background: none; font: inherit; width: 100%; text-align: left; position: relative; transition: background .16s var(--ease), color .16s var(--ease); }
.sb-link:hover { background: var(--line-2); color: var(--ink); }
.sb-link.active { background: var(--accent-soft); color: var(--accent-d); }
.sb-link.active::before { content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.sb-link .ic { width: 22px; height: 22px; display: grid; place-items: center; }
.sb-link svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.sb-foot { margin-top: auto; }
.content { display: flex; flex-direction: column; min-width: 0; }
.appbar { display: flex; align-items: center; gap: 14px; padding: 15px 28px; background: rgba(255,255,255,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.appbar h1 { font-size: 19px; margin: 0; letter-spacing: -.01em; }
.appbar .spacer { flex: 1; }
.ab-user { display: flex; align-items: center; gap: 9px; }
.ab-ava { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-grad); color: #fff; display: grid; place-items: center; font-weight: 700; }
.ab-id b { display: block; font-size: 13px; }
.ab-id small { color: var(--ink-3); font-size: 12px; }
.ab-logout { border: 1px solid var(--line); background: #fff; border-radius: var(--r-sm); width: 38px; height: 38px; cursor: pointer; display: grid; place-items: center; transition: all .16s var(--ease); }
.ab-logout:hover { border-color: #fecaca; background: #fef2f2; }
.ab-logout svg { width: 18px; height: 18px; fill: none; stroke: var(--ink-2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: stroke .16s; }
.ab-logout:hover svg { stroke: #dc2626; }
.burger { display: none; }
.main { padding: 26px 28px; max-width: 1280px; width: 100%; animation: fadeUp .25s var(--ease); }
@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .22s var(--ease); width: 256px; box-shadow: var(--sh-lg); }
  .sidebar.open { transform: none; }
  .burger { display: grid; place-items: center; width: 38px; height: 38px; border: 1px solid var(--line); background: #fff; border-radius: var(--r-sm); cursor: pointer; font-size: 17px; }
  .sb-backdrop { display: none; position: fixed; inset: 0; background: rgba(19,26,46,.4); z-index: 30; }
  .sb-backdrop.show { display: block; }
}

/* ---------------- Buttons & primitives ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: var(--r-sm); padding: 9px 15px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: transform .12s var(--ease), box-shadow .16s var(--ease), border-color .16s, background .16s; white-space: nowrap; }
.btn:hover { border-color: #d3d9e6; box-shadow: var(--sh-sm); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-d); border-color: var(--accent-d); box-shadow: 0 6px 18px rgba(79,70,229,.32); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-2); box-shadow: none; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn.danger { color: #dc2626; border-color: #fbd5d5; }
.btn.danger:hover { background: #fef2f2; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--sh-sm); padding: 22px; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.page-head h2 { margin: 0; font-size: 23px; letter-spacing: -.02em; }
.page-head .spacer { flex: 1; }
.muted { color: var(--ink-2); }
.empty { text-align: center; color: var(--ink-3); padding: 46px 20px; }
.empty svg { width: 46px; height: 46px; opacity: .4; margin-bottom: 10px; }

/* ---------------- Stats / dashboard ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 18px 20px; box-shadow: var(--sh-sm); transition: transform .18s var(--ease), box-shadow .18s var(--ease); }
.stat:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }
.stat .ic { width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 12px; }
.stat .ic svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.stat .n { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.stat .l { color: var(--ink-2); font-size: 13px; margin-top: 1px; }
.stat.hero { background: var(--accent-grad); border: none; color: #fff; }
.stat.hero .ic { background: rgba(255,255,255,.18); color: #fff; }
.stat.hero .l { color: rgba(255,255,255,.85); }

.section-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; letter-spacing: -.01em; }
.pipe { display: grid; grid-template-columns: repeat(auto-fit, minmax(116px, 1fr)); gap: 12px; margin-bottom: 24px; }
.pipe-cell { background: #fff; border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; box-shadow: var(--sh-sm); transition: transform .16s var(--ease); }
.pipe-cell:hover { transform: translateY(-2px); }
.pipe-cell .pn { font-size: 23px; font-weight: 800; }
.pipe-cell .pl { font-size: 12.5px; color: var(--ink-2); }
.pipe-cell .bar { height: 4px; border-radius: 4px; margin-top: 9px; }

/* ---------------- Tables ---------------- */
.card.flush { padding: 0; overflow: hidden; }
.card-head { padding: 16px 22px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.card-head b { flex: 1; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: 11px 14px; border-bottom: 1px solid var(--line); font-weight: 700; }
.tbl td { padding: 13px 14px; border-bottom: 1px solid var(--line-2); }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr.clk { cursor: pointer; transition: background .14s; }
.tbl tr.clk:hover td { background: var(--accent-soft); }
.tbl .ref { font-weight: 700; color: var(--accent-d); }

/* ---------------- Badges ---------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 11px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.s-nouveau { background: #eef1f6; color: #5a6478; }
.s-devis { background: #e0ecff; color: #1d4ed8; }
.s-bat { background: #ede9fe; color: #6d28d9; }
.s-planification { background: #fef3c7; color: #b45309; }
.s-impression { background: #ffedd5; color: #c2410c; }
.s-controle { background: #ccfbf1; color: #0f766e; }
.s-expedition { background: #cffafe; color: #0e7490; }
.s-termine { background: #dcfce7; color: #15803d; }
.s-annule { background: #fee2e2; color: #b91c1c; }

/* ---------------- Kanban board ---------------- */
.view-toggle { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.view-toggle button { border: none; background: none; font: inherit; font-weight: 600; font-size: 13px; color: var(--ink-2); padding: 6px 13px; border-radius: 8px; cursor: pointer; transition: all .14s; }
.view-toggle button.on { background: var(--accent-soft); color: var(--accent-d); }
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; scroll-snap-type: x proximity; }
.col { flex: 0 0 270px; background: #eef0f5; border-radius: var(--r-md); padding: 10px; scroll-snap-align: start; transition: background .16s; }
.col.drop { background: var(--accent-soft); outline: 2px dashed var(--accent); outline-offset: -3px; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 4px 8px 10px; font-weight: 700; font-size: 13px; }
.col-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.col-head .cnt { margin-left: auto; background: #fff; color: var(--ink-2); border-radius: 999px; font-size: 12px; padding: 1px 9px; font-weight: 700; }
.kcard { background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 13px; margin-bottom: 9px; cursor: grab; box-shadow: var(--sh-sm); transition: transform .14s var(--ease), box-shadow .16s var(--ease); animation: pop .2s var(--ease); }
.kcard:hover { transform: translateY(-2px); box-shadow: var(--sh-md); }
.kcard:active { cursor: grabbing; }
.kcard.drag { opacity: .45; }
.kcard .kref { font-size: 11.5px; font-weight: 700; color: var(--accent-d); }
.kcard .ktitle { font-weight: 700; font-size: 14px; margin: 2px 0 6px; }
.kcard .kmeta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-3); flex-wrap: wrap; }
.kcard .kclient { color: var(--ink-2); }
.kcard .ktags { display: flex; gap: 5px; margin-top: 8px; }
.mini { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 6px; }
.mini.ok { background: #dcfce7; color: #15803d; }
.mini.wait { background: #fef3c7; color: #b45309; }
.col-empty { color: var(--ink-3); font-size: 12.5px; text-align: center; padding: 16px 8px; }

/* ---------------- Forms ---------------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid #d5dbe8; border-radius: var(--r-sm); padding: 10px 12px; font: inherit; background: #fff; transition: border-color .14s, box-shadow .14s; }
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.13); }
.field input[type=file] { padding: 8px; cursor: pointer; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2); transition: all .14s var(--ease); }
.chip:hover { border-color: #d3d9e6; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------------- Detail ---------------- */
.detail-grid { display: grid; grid-template-columns: 1fr 350px; gap: 18px; align-items: start; }
@media (max-width: 920px) { .detail-grid { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: 132px 1fr; gap: 8px 12px; }
.kv dt { color: var(--ink-3); font-size: 13px; }
.kv dd { margin: 0; font-weight: 600; }
.stepper { display: flex; gap: 6px; margin: 4px 0 16px; flex-wrap: wrap; }
.step { flex: 1; min-width: 60px; text-align: center; font-size: 11px; font-weight: 700; color: var(--ink-3); padding: 7px 4px; border-radius: 8px; background: var(--line-2); position: relative; transition: all .16s; }
.step.done { background: var(--accent-soft); color: var(--accent-d); }
.step.cur { background: var(--accent); color: #fff; }
.journal { display: flex; flex-direction: column; gap: 13px; }
.jev { border-left: 2px solid var(--line); padding: 1px 0 1px 13px; animation: fadeUp .2s var(--ease); }
.jev .jt { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.jev.status, .jev.bat, .jev.calc { border-color: var(--accent); }
.jev .jm { font-size: 13.5px; }

/* ---------------- Modal ---------------- */
.ov { position: fixed; inset: 0; background: rgba(19,26,46,.5); display: grid; place-items: center; z-index: 60; padding: 20px; animation: fadeUp .16s var(--ease); backdrop-filter: blur(2px); }
.modal { background: #fff; border-radius: 20px; width: 100%; max-width: 580px; max-height: 90vh; overflow-y: auto; box-shadow: var(--sh-lg); animation: pop .22s var(--ease); }
.modal-head { display: flex; align-items: center; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 24px; }
.modal-foot { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: #fff; }
.x { border: none; background: none; font-size: 24px; cursor: pointer; color: var(--ink-3); line-height: 1; transition: color .14s; }
.x:hover { color: var(--ink); }

.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 22px; border-radius: 12px; z-index: 100; box-shadow: var(--sh-lg); font-weight: 600; animation: pop .2s var(--ease); }

/* ---------------- Portail client ---------------- */
.cp-wrap { min-height: 100vh; }
.cp-top { display: flex; align-items: center; gap: 14px; padding: 16px 28px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.cp-brand { display: flex; align-items: center; gap: 11px; font-size: 15px; flex: 1; }
.cp-brand .sb-logo { width: 36px; height: 36px; font-size: 18px; }
.cp-user { display: flex; align-items: center; gap: 12px; }
.cp-main { max-width: 920px; margin: 0 auto; padding: 30px 24px 56px; animation: fadeUp .25s var(--ease); }
.cp-main h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 20px; }
.cp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.cp-card { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--r-card); padding: 18px 20px; box-shadow: var(--sh-sm); text-decoration: none; color: var(--ink); transition: transform .16s var(--ease), box-shadow .18s var(--ease); }
.cp-card:hover { transform: translateY(-3px); box-shadow: var(--sh-md); }
.cp-ref { font-size: 12px; font-weight: 700; color: var(--accent-d); }
.cp-title { font-weight: 700; font-size: 16px; margin: 3px 0 2px; }
.cp-meta { color: var(--ink-3); font-size: 13px; }
