/* ==========================================================================
   Logistique JBOOST — Design system
   Style : Data-Dense Dashboard · Accent indigo #5146E0 · Light + Dark
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------- */
:root {
    /* Marque */
    --indigo-50:  #eef0fd;
    --indigo-100: #e0e2fb;
    --indigo-200: #c4c7f6;
    --indigo-500: #5146E0;
    --indigo-600: #4339c4;
    --indigo-700: #372fa6;

    /* Surfaces & texte (light) */
    --bg:          #f4f5fa;
    --surface:     #ffffff;
    --surface-2:   #fafbff;
    --surface-3:   #f3f4fa;
    --text:        #0f172a;
    --muted:       #64748b;
    --faint:       #94a3b8;
    --border:      #e7e9f2;
    --border-soft: #eef0f6;

    /* Sémantique */
    --primary:     var(--indigo-500);
    --primary-ink: #ffffff;
    --success:     #16a34a;
    --warning:     #d97706;
    --danger:      #dc2626;

    /* Élévation */
    --shadow-xs: 0 1px 2px rgba(16,24,40,.05);
    --shadow-sm: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
    --shadow-md: 0 4px 12px rgba(16,24,40,.08), 0 2px 4px rgba(16,24,40,.04);
    --shadow-lg: 0 12px 32px rgba(16,24,40,.12), 0 4px 8px rgba(16,24,40,.06);
    --shadow-indigo: 0 8px 24px rgba(81,70,224,.28);

    /* Rayons */
    --r-xs: 6px;
    --r-sm: 8px;
    --r:    12px;
    --r-lg: 16px;
    --r-xl: 20px;

    /* Rythme */
    --sidebar-w: 248px;
    --topbar-h:  64px;

    /* Transitions */
    --t-fast: 130ms cubic-bezier(.4,0,.2,1);
    --t:      200ms cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
    --bg:          #0b0e17;
    --surface:     #141926;
    --surface-2:   #1a2030;
    --surface-3:   #1f2638;
    --text:        #f1f4fb;
    --muted:       #94a3b8;
    --faint:       #64748b;
    --border:      #25304a;
    --border-soft: #1e2638;
    --primary:     #7b72f2;
    --indigo-50:   #1e2438;
    --indigo-100:  #2a3358;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.4);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.45);
    --shadow-md: 0 4px 14px rgba(0,0,0,.5);
    --shadow-lg: 0 16px 40px rgba(0,0,0,.6);
    --shadow-indigo: 0 8px 24px rgba(123,114,242,.35);
}

/* ---- Base -------------------------------------------------------------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'cv11', 'ss01';
}
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
a { color: inherit; text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -.01em; color: var(--text); }
.num { font-variant-numeric: tabular-nums; }

/* ---- Shell : sidebar + main -------------------------------------------- */
.app { display: flex; min-height: 100dvh; }

.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100dvh;
    padding: 18px 14px;
    z-index: 40;
}
.brand {
    display: flex; align-items: center; gap: 11px;
    padding: 6px 8px 18px;
}
.brand-mark {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, var(--indigo-500), var(--indigo-700));
    display: grid; place-items: center; color: #fff; flex: 0 0 auto;
    box-shadow: var(--shadow-indigo);
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.brand-sub  { font-size: 11px; color: var(--faint); font-weight: 500; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; }
.nav-label {
    font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
    color: var(--faint); padding: 14px 10px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 11px; border-radius: var(--r-sm);
    color: var(--muted); font-weight: 550; font-size: 13.5px;
    transition: background var(--t-fast), color var(--t-fast);
    position: relative;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; opacity: .85; }
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active {
    background: var(--indigo-50); color: var(--primary);
}
[data-theme="dark"] .nav-item.active { background: rgba(123,114,242,.14); }
.nav-item.active svg { opacity: 1; }
.nav-item .count {
    margin-left: auto; font-size: 11px; font-weight: 600;
    background: var(--surface-3); color: var(--muted);
    padding: 1px 7px; border-radius: 999px;
}
.nav-item.active .count { background: var(--indigo-100); color: var(--primary); }

.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border-soft); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ---- Topbar ------------------------------------------------------------ */
.topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 16px;
    padding: 0 28px;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 80%, transparent);
    backdrop-filter: saturate(180%) blur(8px);
    position: sticky; top: 0; z-index: 30;
}
.topbar h1 { font-size: 19px; }
.topbar .crumb { font-size: 12.5px; color: var(--faint); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.icon-btn {
    width: 38px; height: 38px; border-radius: var(--r-sm);
    border: 1px solid var(--border); background: var(--surface);
    display: grid; place-items: center; color: var(--muted);
    cursor: pointer; transition: all var(--t-fast);
}
.icon-btn:hover { color: var(--primary); border-color: var(--indigo-200); background: var(--surface-2); }
.icon-btn svg { width: 18px; height: 18px; }

.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, #f59e0b, var(--danger));
    color: #fff; display: grid; place-items: center; font-weight: 650; font-size: 13px;
}

.content { padding: 26px 28px 48px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---- Buttons ----------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 40px; padding: 0 16px; border-radius: var(--r-sm);
    font-size: 13.5px; font-weight: 600; font-family: inherit;
    border: 1px solid transparent; cursor: pointer; white-space: nowrap;
    transition: all var(--t-fast);
}
.btn svg { width: 16px; height: 16px; }
.btn:active { transform: translateY(.5px) scale(.99); }
.btn-primary {
    background: linear-gradient(180deg, var(--indigo-500), var(--indigo-600));
    color: #fff; box-shadow: var(--shadow-xs);
}
.btn-primary:hover { box-shadow: var(--shadow-indigo); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--indigo-200); color: var(--primary); background: var(--surface-2); }
.btn-subtle { background: var(--surface-3); color: var(--muted); }
.btn-subtle:hover { color: var(--text); }
.btn-danger-ghost { background: var(--surface); color: var(--danger); border-color: var(--border); }
.btn-danger-ghost:hover { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---- Cards ------------------------------------------------------------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r); box-shadow: var(--shadow-sm);
    overflow: hidden;   /* le contenu (tableau) épouse les coins arrondis */
}
.card-pad { padding: 18px 20px; }
.card-head {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 20px; border-bottom: 1px solid var(--border-soft);
}
.card-head h3 { font-size: 15px; }
.card-head .sub { font-size: 12.5px; color: var(--faint); }

/* ---- KPI cards --------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r); padding: 18px; position: relative; overflow: hidden;
    box-shadow: var(--shadow-sm); transition: transform var(--t), box-shadow var(--t);
}
.kpi:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-ico {
    width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
}
.kpi-ico svg { width: 20px; height: 20px; }
.kpi-ico.i-indigo { background: var(--indigo-50); color: var(--primary); }
.kpi-ico.i-green  { background: #e8f7ee; color: var(--success); }
.kpi-ico.i-amber  { background: #fdf3e3; color: var(--warning); }
.kpi-ico.i-blue   { background: #e6f0fe; color: #2563eb; }
[data-theme="dark"] .kpi-ico.i-indigo { background: rgba(123,114,242,.16); }
[data-theme="dark"] .kpi-ico.i-green  { background: rgba(22,163,74,.16); }
[data-theme="dark"] .kpi-ico.i-amber  { background: rgba(217,119,6,.16); }
[data-theme="dark"] .kpi-ico.i-blue   { background: rgba(37,99,235,.16); }
.kpi-trend { font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 999px; }
.kpi-trend.up   { color: var(--success); background: #e8f7ee; }
.kpi-trend.flat { color: var(--muted);   background: var(--surface-3); }
.kpi-value { font-size: 28px; font-weight: 720; letter-spacing: -.02em; margin-top: 14px; }
.kpi-label { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---- Badges (statut) --------------------------------------------------- */
.badge {
    --c: var(--muted);
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px 3px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
    color: var(--c);
    background: color-mix(in srgb, var(--c) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--c) 22%, transparent);
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--c); }

/* Badge-sélecteur de statut (modifiable directement dans le tableau) */
.statut-pill { --c: var(--muted); position: relative; display: inline-flex; }
.statut-pill select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    font: inherit; font-size: 12px; font-weight: 600; line-height: 1;
    color: var(--c); cursor: pointer;
    padding: 5px 26px 5px 11px; border-radius: 999px;
    background: color-mix(in srgb, var(--c) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--c) 24%, transparent);
    transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
.statut-pill select:hover { background: color-mix(in srgb, var(--c) 18%, transparent); }
.statut-pill select:focus { outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 22%, transparent); }
.statut-pill::after {
    content: ''; position: absolute; right: 11px; top: 50%; transform: translateY(-50%);
    width: 0; height: 0; pointer-events: none;
    border-left: 3.5px solid transparent; border-right: 3.5px solid transparent;
    border-top: 4.5px solid var(--c);
}
.statut-pill select option { color: var(--text); background: var(--surface); font-weight: 500; }
.statut-pill.saving { opacity: .6; }

/* ---- Table ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data thead th {
    text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .04em;
    text-transform: uppercase; color: var(--faint);
    padding: 12px 16px; background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
table.data thead th a { display: inline-flex; align-items: center; gap: 4px; color: inherit; }
table.data thead th a:hover { color: var(--primary); }
table.data thead th.sorted { color: var(--primary); }
table.data tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tbody tr { transition: background var(--t-fast); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data tbody tr:last-child td { border-bottom: none; }
.cell-name { font-weight: 600; color: var(--text); }
.cell-sub { color: var(--muted); font-size: 12.5px; }
.cell-amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions .icon-btn { width: 32px; height: 32px; }
.row-actions .icon-btn svg { width: 15px; height: 15px; }

/* ---- Filter bar -------------------------------------------------------- */
.toolbar {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 18px;
}
.search {
    position: relative; flex: 1 1 280px; max-width: 380px;
}
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--faint); }
.input, .select {
    height: 40px; border: 1px solid var(--border); background: var(--surface);
    border-radius: var(--r-sm); color: var(--text); font-size: 13.5px; font-family: inherit;
    padding: 0 12px; transition: border var(--t-fast), box-shadow var(--t-fast);
}
.search .input { width: 100%; padding-left: 36px; }
.input:focus, .select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
.select { cursor: pointer; padding-right: 30px; }
.spacer { margin-left: auto; }

/* ---- Forms ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 550; color: var(--muted); }
.field .input, .field .select, .field textarea {
    width: 100%; height: 42px;
}
.field textarea {
    height: auto; min-height: 72px; padding: 10px 12px; resize: vertical;
    border: 1px solid var(--border); background: var(--surface); border-radius: var(--r-sm);
    color: var(--text); font-size: 13.5px; font-family: inherit;
}
.field textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent); }
.req { color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.form-grid .col-span { grid-column: 1 / -1; }

/* ---- Collapsible add panel -------------------------------------------- */
details.adder { margin-bottom: 18px; }
details.adder > summary {
    list-style: none; cursor: pointer;
    display: inline-flex; align-items: center; gap: 7px;
}
details.adder > summary::-webkit-details-marker { display: none; }
details.adder[open] > summary .chev { transform: rotate(45deg); }

/* ---- Flash / toast ----------------------------------------------------- */
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; border-radius: var(--r-sm); margin-bottom: 18px;
    font-size: 13.5px; font-weight: 550;
    background: color-mix(in srgb, var(--success) 12%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--success) 30%, transparent);
    color: var(--success);
    animation: slidein var(--t) ease-out;
}
.flash svg { width: 18px; height: 18px; }
@keyframes slidein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---- Empty state ------------------------------------------------------- */
.empty { text-align: center; padding: 56px 20px; color: var(--faint); }
.empty svg { width: 44px; height: 44px; margin-bottom: 12px; opacity: .6; }
.empty h3 { color: var(--muted); font-size: 15px; margin-bottom: 4px; }

/* ---- Dialog ------------------------------------------------------------ */
dialog {
    border: none; padding: 0; border-radius: var(--r-lg); width: 92%; max-width: 620px;
    background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(8,12,24,.5); backdrop-filter: blur(2px); }
dialog[open] { animation: pop var(--t) cubic-bezier(.2,.8,.2,1); }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border-soft); }
.dlg-head h3 { font-size: 16px; }
.dlg-body { padding: 22px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border-soft); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---- Pipeline (dashboard) ---------------------------------------------- */
.pipe-row { display: flex; align-items: center; gap: 14px; padding: 9px 0; }
.pipe-name { width: 170px; flex: 0 0 170px; font-size: 13px; font-weight: 550; display: flex; align-items: center; gap: 8px; }
.pipe-name .dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.pipe-track { flex: 1 1 auto; height: 9px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.pipe-fill { height: 100%; border-radius: 999px; transition: width var(--t); animation: grow .6s cubic-bezier(.2,.8,.2,1); }
@keyframes grow { from { width: 0 !important; } }
.pipe-count { width: 40px; flex: 0 0 40px; text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---- Kanban ------------------------------------------------------------ */
.kanban-scroll { overflow-x: auto; padding-bottom: 14px; }
.kanban { display: flex; gap: 14px; min-width: min-content; }
.kcol {
    width: 280px; flex: 0 0 280px;
    background: var(--surface-3); border: 1px solid var(--border-soft);
    border-radius: var(--r); display: flex; flex-direction: column; max-height: calc(100dvh - 200px);
}
.kcol-head {
    display: flex; align-items: center; gap: 8px; padding: 12px 14px;
    border-bottom: 1px solid var(--border); position: sticky; top: 0;
    background: var(--surface-3); border-radius: var(--r) var(--r) 0 0; z-index: 2;
}
.kcol-head .dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.kcol-head .title { font-size: 12.5px; font-weight: 650; }
.kcol-head .n { margin-left: auto; font-size: 11.5px; font-weight: 650; color: var(--muted); background: var(--surface); padding: 1px 8px; border-radius: 999px; }
.kcol-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; overflow-y: auto; flex: 1 1 auto; min-height: 60px; }
.kcol-body.drag-over { background: color-mix(in srgb, var(--primary) 8%, transparent); outline: 2px dashed color-mix(in srgb, var(--primary) 40%, transparent); outline-offset: -4px; border-radius: var(--r-sm); }
.kcard {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
    padding: 12px; box-shadow: var(--shadow-xs); cursor: grab;
    transition: box-shadow var(--t-fast), transform var(--t-fast), border-color var(--t-fast);
}
.kcard:hover { box-shadow: var(--shadow-md); border-color: var(--indigo-200); transform: translateY(-1px); }
.kcard.dragging { opacity: .5; cursor: grabbing; }
.kcard-name { font-weight: 650; font-size: 13.5px; }
.kcard-prod { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.kcard-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.kcard-amount { font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kcard-resp { font-size: 11px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.kcard-resp .pip { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 9px; font-weight: 700; background: var(--indigo-500); }

/* ---- Suivi des commandes : disposition verticale (lanes) --------------- */
.klanes { display: flex; flex-direction: column; gap: 14px; }
.klane {
    background: var(--surface-3); border: 1px solid var(--border-soft);
    border-radius: var(--r); overflow: hidden; transition: border-color var(--t-fast);
}
.klane-head {
    display: flex; align-items: center; gap: 9px; padding: 12px 16px;
    background: var(--surface); border-bottom: 1px solid var(--border);
}
.klane-head .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.klane-head .title { font-weight: 650; font-size: 14px; }
.klane-head .n {
    margin-left: auto; font-size: 11.5px; font-weight: 650; color: var(--muted);
    background: var(--surface-3); padding: 2px 9px; border-radius: 999px;
}
.klane-body {
    padding: 14px; display: flex; flex-wrap: wrap; gap: 10px; min-height: 70px;
    align-content: flex-start; transition: background var(--t-fast);
}
.klane-body.drag-over {
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    outline: 2px dashed color-mix(in srgb, var(--primary) 40%, transparent);
    outline-offset: -6px;
}
.klane .kcard { width: 264px; flex: 0 0 264px; }
.lane-empty {
    color: var(--faint); font-size: 13px; font-style: italic;
    padding: 6px 4px; pointer-events: none;
}
@media (max-width: 600px) {
    .klane .kcard { width: 100%; flex: 1 1 100%; }
}

/* ---- Section spacing --------------------------------------------------- */
.stack-lg > * + * { margin-top: 22px; }
.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 22px; }

/* ---- Responsive -------------------------------------------------------- */
@media (max-width: 1080px) {
    .kpis { grid-template-columns: repeat(2, 1fr); }
    .grid-2 { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
    .sidebar {
        position: fixed; left: 0; top: 0; transform: translateX(-100%);
        transition: transform var(--t); box-shadow: var(--shadow-lg);
    }
    .sidebar.open { transform: none; }
    .menu-toggle { display: grid !important; }
    .content { padding: 18px 16px 40px; }
    .topbar { padding: 0 16px; }
    .scrim { display: none; position: fixed; inset: 0; background: rgba(8,12,24,.5); z-index: 35; }
    .scrim.show { display: block; }
}
@media (max-width: 560px) {
    .kpis { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
}
.menu-toggle { display: none; }
