/* État Stock — tabbed cards + drilldown modals. Standalone styles. */

/* ── Minimalist Stock dashboard ──────────────────────────────── */
.es-summary {
    display: flex;
    align-items: baseline;
    gap: 12px;
    flex-wrap: wrap;
    margin: 6px 0 22px;
    font-size: 13px;
    color: #64748b;
    font-weight: 400;
}
.es-summary strong { color: #0f172a; font-weight: 700; }
.es-summary-sep { color: #cbd5e1; }
.es-summary-warn { color: #b45309; }
.es-summary-warn strong { color: #b45309; }
.es-summary-ok { color: #15803d; }

.es-details {
    margin-bottom: 26px;
    padding: 4px 0 4px;
}
.es-btn-ghost {
    background: transparent;
    color: #64748b;
    border: 1px solid #e5e7eb;
    font-weight: 500;
}
.es-btn-ghost:hover { color: #0f172a; border-color: #0f172a; background: #fff; }
.es-btn-ghost.is-active { color: #0f172a; border-color: #0f172a; background: #f8fafc; }

/* 4 chart cards (2x2 on the left of the layout) */
.es-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
@media (max-width: 700px) { .es-charts { grid-template-columns: 1fr; } }

.es-chart {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px 16px;
    min-height: 150px;
}
.es-chart-h {
    font-size: 10.5px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .7px;
    margin-bottom: 14px;
}
.es-chart-body { font-size: 12px; }

/* Generic horizontal bar row */
.es-bar-row {
    display: grid;
    grid-template-columns: 36px 1fr auto;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.es-bar-row:last-child { margin-bottom: 0; }
.es-bar-lbl {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 11px;
    color: #1f2937;
}
.es-bar-lbl-art {
    grid-column: 1 / 2;
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100px;
}
.es-bar-track {
    height: 10px;
    background: #f1f5f9;
    border-radius: 999px;
    overflow: hidden;
}
.es-bar-fill {
    height: 100%;
    border-radius: 999px;
    transition: width .25s ease;
}
.es-bar-val {
    font-family: 'Space Mono', monospace;
    font-weight: 700;
    font-size: 11.5px;
    color: #1f2937;
    text-align: right;
    min-width: 50px;
}

/* Donut chart */
.es-donut-wrap { display: flex; align-items: center; gap: 16px; }
.es-donut {
    width: 90px; height: 90px;
    border-radius: 50%;
    flex-shrink: 0;
    position: relative;
}
.es-donut-hole {
    position: absolute; inset: 14px;
    background: #fff;
    border-radius: 50%;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
.es-donut-v {
    font-family: 'Space Mono', monospace;
    font-weight: 800; font-size: 18px;
    color: #0f172a;
    line-height: 1;
}
.es-donut-l {
    font-size: 9.5px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .4px;
    font-weight: 700;
    margin-top: 3px;
}
.es-donut-legend {
    display: flex; flex-direction: column;
    gap: 5px; font-size: 11.5px;
}
.es-leg {
    display: flex; align-items: center; gap: 6px;
    color: #475569; font-weight: 500;
}
.es-leg strong { color: #0f172a; font-weight: 700; font-family: 'Space Mono', monospace; }
.es-leg-dot {
    width: 8px; height: 8px;
    border-radius: 2px;
}
.es-leg-pct { color: #94a3b8; font-size: 10.5px; }

/* Fresh vs old stacked bar */
.es-fresh-stack {
    display: flex;
    height: 18px;
    border-radius: 999px;
    overflow: hidden;
    background: #f1f5f9;
    margin-bottom: 12px;
    border: 1px solid #e5e7eb;
}
.es-fresh-seg { height: 100%; transition: width .25s ease; }
.es-fresh-fresh { background: linear-gradient(90deg, #16a34a, #15803d); }
.es-fresh-old   { background: linear-gradient(90deg, #f59e0b, #b45309); }
.es-fresh-legend {
    display: flex; flex-direction: column;
    gap: 6px; font-size: 12px;
}

/* 2-column layout — cards (left) · planning + charts (right) */
.es-layout {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 22px;
    align-items: start;
}
.es-layout-main { display: flex; flex-direction: column; gap: 28px; }
.es-layout-side { position: relative; }
.es-panel-sticky {
    position: sticky; top: 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 16px 18px;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}
.es-panel-sticky .es-panel-head { margin-top: 0; }
@media (max-width: 1080px) {
    .es-layout { grid-template-columns: 1fr; }
    .es-panel-sticky { position: static; max-height: none; }
    .es-summary-grid { grid-template-columns: repeat(2, 1fr) !important; }
}
@media (max-width: 640px) {
    .es-summary-grid { grid-template-columns: 1fr !important; }
}

/* ── Charts sidebar ── */
.es-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
}
.esc-card {
    background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px;
    padding: 10px 12px;
}
.esc-card-label { font-size: 10px; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: .4px; }
.esc-card-val   { font-size: 18px; font-weight: 800; color: #1a1a2e; margin-top: 3px; line-height: 1.1; }
.esc-card-sub   { font-size: 10.5px; color: #9ca3af; margin-top: 2px; }
.esc-card.aging { background: #fffbeb; border-color: #fde68a; }
.esc-card.aging .esc-card-val { color: #b45309; }
.esc-card.crit  { background: #fef2f2; border-color: #fecaca; }
.esc-card.crit .esc-card-val { color: #b91c1c; }

.es-charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}
.esc-chart-block { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px 12px 12px; }
.esc-chart-title { font-size: 11px; font-weight: 700; color: #374151; text-transform: uppercase; letter-spacing: .4px; margin-bottom: 6px; }
.esc-chart-sub   { font-size: 10px; color: #9ca3af; margin-bottom: 8px; line-height: 1.35; }
.esc-chart-wrap  { position: relative; height: 160px; }

.es-dashgrid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}
@media (max-width: 980px) { .es-dashgrid { grid-template-columns: 1fr; } }

.es-panel {
    background: transparent;
    border: none;
    padding: 0;
    box-shadow: none;
}
.es-panel-head { margin-bottom: 14px; }
.es-panel-head h2 {
    font-size: 11px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: .8px;
}

/* Age chart */
.es-age-stack {
    display: flex;
    height: 14px;
    border-radius: 999px;
    overflow: hidden;
    background: #f1f5f9;
    margin-bottom: 14px;
    border: 1px solid #e5e7eb;
}
.es-age-stack-seg { height: 100%; transition: width .25s ease; }
.es-age-rows { display: flex; flex-direction: column; gap: 6px; }
.es-age-row { display: grid; grid-template-columns: 90px 1fr 130px; align-items: center; gap: 10px; font-size: 12.5px; }
.es-age-lbl { display: flex; align-items: center; gap: 7px; font-weight: 700; color: #1f2937; }
.es-age-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.es-age-bar { height: 8px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.es-age-bar-fill { height: 100%; transition: width .25s ease; }
.es-age-val { font-family: 'Space Mono', monospace; font-weight: 700; text-align: right; color: #1f2937; font-size: 12.5px; }
.es-age-val small { color: #94a3b8; font-weight: 500; font-size: 10.5px; }

/* Planning */
.es-plan-day { padding: 8px 0; border-bottom: 1px dashed #e5e7eb; }
.es-plan-day:last-child { border-bottom: none; }
.es-plan-day.is-today { background: linear-gradient(90deg, #fef2f2 0%, transparent 50%); margin: 0 -16px; padding: 8px 16px; border-radius: 0; }
.es-plan-day-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.es-plan-day-label { font-weight: 800; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: #475569; }
.es-plan-day.is-today .es-plan-day-label { color: #b91c1c; }
.es-plan-day-total { font-family: 'Space Mono', monospace; font-weight: 700; font-size: 11.5px; color: #1f2937; background: #f1f5f9; padding: 2px 8px; border-radius: 999px; }
.es-plan-item { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; align-items: center; padding: 3px 0; font-size: 12.5px; }
.es-plan-ligne { display: inline-flex; align-items: center; justify-content: center; height: 18px; border-radius: 4px; font-size: 9.5px; font-weight: 800; color: #fff; padding: 0 5px; font-family: 'Space Mono', monospace; }
.es-plan-ligne.l1 { background: #dc2626; }
.es-plan-ligne.l2 { background: #d97706; }
.es-plan-ligne.l3 { background: #16a34a; }
.es-plan-ligne.l4 { background: #2563eb; }
.es-plan-art { color: #1f2937; font-weight: 600; }
.es-plan-sacs { font-family: 'Space Mono', monospace; font-weight: 700; color: #1f2937; }
.es-plan-empty { font-size: 11.5px; color: #94a3b8; font-style: italic; padding-left: 4px; }

/* Stock cards — minimalist */
.es-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.es-card-ligne {
    display: inline-flex; align-items: center; justify-content: center;
    height: 18px; min-width: 22px; padding: 0 6px;
    border-radius: 3px;
    font-family: 'Space Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: .3px;
}
.es-card-ligne.l1 { background: #dc2626; }
.es-card-ligne.l2 { background: #d97706; }
.es-card-ligne.l3 { background: #16a34a; }
.es-card-ligne.l4 { background: #2563eb; }
.es-card-foot {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    margin-top: auto;
    padding-top: 14px;
    font-size: 11.5px;
    color: #94a3b8;
    font-weight: 400;
    border-top: 1px solid #f1f5f9;
}
.es-card-warn {
    color: #b45309;
    font-weight: 500;
    margin-left: auto;
}


:root {
    --es-red:    #dc2626;
    --es-red2:   #b91c1c;
    --es-green:  #16a34a;
    --es-amber:  #d97706;
    --es-bg:     #f7f7f8;
    --es-card:   #ffffff;
    --es-border: #e5e7eb;
    --es-muted:  #6b7280;
    --es-text:   #1f2937;
    --es-faint:  #f3f4f6;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body.es-app {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--es-bg); color: var(--es-text);
    min-height: 100vh;
}
a { color: var(--es-red); text-decoration: none; }

.es-topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: #fff; padding: 0 22px; height: 56px;
    border-bottom: 1px solid var(--es-border);
    gap: 14px;
}
.es-brand { font-size: 1.2rem; font-weight: 800; letter-spacing: 4px; color: var(--es-text); display: inline-flex; align-items: center; gap: 10px; }
.es-brand::before { content: ""; width: 9px; height: 9px; border-radius: 999px; background: var(--es-red); }
.es-brand small { color: var(--es-muted); font-weight: 500; letter-spacing: 1.5px; font-size: .8rem; }
.es-tb-right { display: flex; gap: 16px; align-items: center; font-size: .85rem; color: var(--es-muted); }

.es-tabs { display: flex; gap: 4px; }
.es-tab {
    background: transparent; border: none;
    padding: 8px 18px; border-radius: 8px;
    font-size: 14px; font-weight: 700; color: var(--es-muted);
    cursor: pointer; font-family: inherit;
    transition: all .12s ease;
}
.es-tab:hover { background: var(--es-faint); color: var(--es-text); }
.es-tab.is-active { background: var(--es-red); color: #fff; }

.es-pane { display: none; }
.es-pane.is-active { display: block; }

.es-wrap { max-width: 1500px; margin: 18px auto; padding: 0 18px; }
.es-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 14px; gap: 12px; flex-wrap: wrap;
}
.es-header h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.5px; color: #0f172a; }
.es-header { margin-bottom: 4px !important; }
.es-header-actions { display: flex; gap: 10px; align-items: center; }

.es-search {
    padding: 9px 14px; border: 1px solid var(--es-border);
    border-radius: 8px; font-size: 14px; min-width: 240px;
    background: #fff; outline: none;
    transition: border-color .12s;
    font-family: inherit;
}
.es-search:focus { border-color: var(--es-red); }

.es-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 14px;
}
.es-loader { padding: 60px; text-align: center; color: var(--es-muted); grid-column: 1 / -1; }

.es-card {
    background: var(--es-card);
    border: 1px solid var(--es-border);
    border-radius: 10px;
    padding: 18px 18px 14px;
    cursor: pointer;
    transition: border-color .15s;
    display: flex; flex-direction: column;
    min-height: 130px;
}
.es-card:hover { border-color: #0f172a; }
.es-card-product { font-size: 15px; font-weight: 600; color: var(--es-text); word-break: break-word; line-height: 1.3; }
.es-card-meta { font-size: 12px; color: var(--es-muted); font-weight: 400; }
.es-card-qty {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 28px; font-weight: 700; color: var(--es-text);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    letter-spacing: -0.5px;
    margin-bottom: 14px;
}
.es-card-unit { font-size: 13px; font-weight: 700; color: #94a3b8; letter-spacing: 0; }
.es-cards { gap: 12px !important; }
.es-cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important; }
/* Inside the 2-col layout, keep cards comfortable */
.es-layout-main .es-cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important; }
/* Préparation cards : 5 colonnes fixes */
#es-prep-cards.es-cards { grid-template-columns: repeat(5, 1fr) !important; }
@media (max-width: 1200px){ #es-prep-cards.es-cards { grid-template-columns: repeat(4, 1fr) !important; } }
@media (max-width: 900px){  #es-prep-cards.es-cards { grid-template-columns: repeat(3, 1fr) !important; } }
@media (max-width: 640px){  #es-prep-cards.es-cards { grid-template-columns: repeat(2, 1fr) !important; } }
@media (max-width: 420px){  #es-prep-cards.es-cards { grid-template-columns: 1fr !important; } }

.es-badge {
    display: inline-block;
    padding: 3px 10px; border-radius: 999px;
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .4px;
    background: #dbeafe; color: #1e40af;
}
.es-badge-pret { background: #dcfce7; color: #166534; }
.es-badge-epp  { background: #fef3c7; color: #92400e; }
.es-badge-ppp  { background: #fce7f3; color: #9d174d; }
.es-badge-pre  { background: #e0e7ff; color: #3730a3; }

.es-prep-progress { margin-top: auto; padding-top: 4px; }
.es-prep-stats {
    display: flex; gap: 14px; align-items: baseline;
    margin-bottom: 8px;
    font-variant-numeric: tabular-nums;
}
.es-prep-stat { display: inline-flex; flex-direction: column; line-height: 1.1; }
.es-prep-stat strong { font-size: 20px; font-weight: 800; color: #16a34a; }
.es-prep-stat small { font-size: 10px; color: var(--es-muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.es-prep-stat-rem strong { color: #d97706; }
.es-prep-stat-tot strong { color: var(--es-text); }
.es-prep-bar { height: 8px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.es-prep-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #16a34a, #15803d);
    transition: width .25s ease;
}

.es-prep-actions { padding-top: 10px; border-top: 1px solid var(--es-border); margin-top: 10px; }
.es-prep-primary { margin-bottom: 8px; }
.es-prep-primary .es-btn { width: 100%; justify-content: center; }
.es-prep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.es-pbtn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 10px; border: 1px solid var(--es-border); background: #fff; color: var(--es-text); border-radius: 10px; font-size: 13px; font-weight: 700; cursor: pointer; font-family: inherit; transition: all .12s; }
.es-pbtn:hover { background: var(--es-faint); border-color: #cbd5e1; }
.es-pbtn-danger { background: #fef2f2; color: #b91c1c; border-color: #fca5a5; }
.es-pbtn-danger:hover { background: #fee2e2; border-color: #f87171; }
.es-pbtn-blue { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.es-pbtn-blue:hover { background: #dbeafe; border-color: #93c5fd; }
.es-prep-divider { grid-column: 1 / -1; border-top: 1px solid var(--es-border); margin: 24px 0 6px; padding-top: 16px; font-size: 24px; font-weight: 600; letter-spacing: -0.5px; color: #0f172a; text-transform: none; }

/* Lots history modal */
.es-lots-summary {
    display: flex; gap: 18px; flex-wrap: wrap;
    margin-bottom: 14px; padding: 10px 14px;
    background: #f8fafc; border: 1px solid var(--es-border); border-radius: 8px;
    font-size: 13px; color: var(--es-muted);
}
.es-lots-summary strong { color: var(--es-text); font-weight: 700; font-family: 'Space Mono', monospace; }
.es-lots-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.es-lots-table th {
    background: #f7f7f8; padding: 9px 10px; text-align: left;
    font-weight: 700; font-size: 10.5px; text-transform: uppercase; letter-spacing: .5px;
    color: var(--es-muted); border-bottom: 1px solid var(--es-border); white-space: nowrap;
}
.es-lots-table th.num { text-align: right; }
.es-lots-table td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.es-lots-table td.num { text-align: right; font-family: 'Space Mono', monospace; font-weight: 700; color: var(--es-text); }
.es-lots-table td.ts { font-size: 11.5px; color: var(--es-muted); white-space: nowrap; }
.es-lots-table tr:hover td { background: #fafafc; }
.es-lots-table code { background: rgba(220, 38, 38, .08); color: #b91c1c; padding: 2px 7px; border-radius: 4px; font-family: 'Space Mono', monospace; font-weight: 700; font-size: 12px; }
.es-empty { padding: 40px; text-align: center; color: var(--es-muted); font-size: 13px; }

.es-btn {
    padding: 8px 14px; border-radius: 8px;
    font-size: 13px; font-weight: 700; cursor: pointer;
    border: none; font-family: inherit;
    transition: background-color .12s ease, opacity .12s;
}
.es-btn-primary   { background: var(--es-red);   color: #fff; }
.es-btn-primary:hover { background: var(--es-red2); }
.es-btn-secondary { background: var(--es-faint); color: var(--es-text); }
.es-btn-secondary:hover { background: #e5e7eb; }
.es-btn-success   { background: var(--es-green); color: #fff; }
.es-btn-success:hover { opacity: .9; }
.es-btn-warn      { background: var(--es-amber); color: #fff; }
.es-btn-warn:hover { opacity: .9; }
.es-btn-danger    { background: #dc2626; color: #fff; }
.es-btn-danger:hover { background: #b91c1c; }
.es-btn:disabled  { opacity: .4; cursor: not-allowed; }
.es-btn-sm { padding: 6px 10px; font-size: 12px; }

/* === Modals === */
.es-modal-bd {
    position: fixed; inset: 0;
    background: rgba(15,23,42,.55);
    z-index: 100;
    display: none;
    align-items: center; justify-content: center;
    padding: 16px;
}
.es-modal-bd.open { display: flex; }
.es-modal {
    background: #fff; width: 100%;
    max-width: 720px; border-radius: 12px;
    padding: 24px; max-height: 92vh; overflow-y: auto;
    position: relative;
}
.es-modal h2 { font-size: 18px; font-weight: 800; margin-bottom: 12px; padding-right: 30px; }
.es-modal .es-sub { color: var(--es-muted); font-size: 13px; margin-bottom: 14px; }
.es-modal-x {
    position: absolute; top: 12px; right: 14px;
    background: none; border: none; font-size: 20px; color: var(--es-muted);
    cursor: pointer;
}
.es-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

.es-field { margin-top: 12px; }
.es-field label { display: block; font-size: 12px; font-weight: 700; color: var(--es-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.es-field input, .es-field select {
    width: 100%; padding: 10px 12px;
    border: 1px solid var(--es-border); border-radius: 8px;
    font-size: 14px; font-family: inherit;
    outline: none; background: #fff;
    transition: border-color .12s;
}
.es-field input:focus, .es-field select:focus { border-color: var(--es-red); }
.es-hint { font-size: 12px; color: var(--es-muted); margin-top: 4px; }

/* === Lots table === */
.es-lots-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-top: 8px;
}
.es-lots-table th, .es-lots-table td {
    padding: 9px 10px; text-align: left;
    border-bottom: 1px solid var(--es-border);
}
.es-lots-table th { background: var(--es-faint); font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--es-muted); }
.es-lots-table tr:last-child td { border-bottom: none; }
.es-lots-table .es-lot-code { font-family: monospace; font-weight: 700; }
.es-lots-table .es-lot-qty { font-variant-numeric: tabular-nums; }
.es-lots-table .es-lot-age { color: var(--es-muted); }

.es-empty { padding: 30px; text-align: center; color: var(--es-muted); font-size: 14px; }
