:root {
  --red: #E5322C;
  --red-dark: #C2241F;
  --red-50: #FDEEED;
  --red-100: #FAD7D5;
  --ink: #1D2026;
  --ink-2: #3A3F47;
  --muted: #6B7180;
  --faint: #9AA0AC;
  --line: #E6E7EB;
  --line-2: #F0F1F4;
  --bg: #FFFFFF;
  --bg-soft: #F7F7F9;
  --green: #1E8E4E;
  --green-50: #E8F5EE;
  --amber: #C26A00;
  --amber-50: #FFF3E0;
  --blue: #2F5FA8;
  --blue-50: #EAF0FA;
  --violet: #6B4BB3;
  --violet-50: #F0ECFA;
  --grey-50: #F1F2F4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg-soft);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--red-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  background: #fff;
  border-bottom: 3px solid var(--red);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto; padding: 0 24px;
  height: 60px; display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { width: 38px; height: 38px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 15px; font-weight: 700; }
.brand-text span { font-size: 11px; color: var(--muted); letter-spacing: .02em; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--ink-2); padding: 8px 12px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--bg-soft); text-decoration: none; }
.nav a.active { color: var(--red-dark); background: var(--red-50); }
.usermenu { display: flex; align-items: center; gap: 12px; }
.usermenu .who { text-align: right; line-height: 1.15; }
.usermenu .who b { display: block; font-size: 13px; }
.usermenu .who span { font-size: 11px; color: var(--muted); text-transform: capitalize; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--red-50); color: var(--red-dark);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
}

/* ---------- layout ---------- */
main { flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.footer {
  border-top: 1px solid var(--line); background: #fff; color: var(--muted);
  font-size: 12px; padding: 12px 24px; text-align: center;
}
.footer b { color: var(--ink-2); font-weight: 600; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.card-head .hint { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: 1fr; } }
@media (max-width: 760px) { .grid-2, .grid-4 { grid-template-columns: 1fr; } .topbar-inner { gap: 12px; padding: 0 12px; } main { padding: 16px 12px; } .usermenu .who { display: none; } }

/* ---------- KPI tiles ---------- */
.kpi { padding: 16px 18px; position: relative; overflow: hidden; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 28px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi .value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-right: 4px; }
.kpi .foot { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--line); }
.kpi.accent::before { background: var(--red); }
.kpi.accent .value { color: var(--red-dark); }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; padding: 8px 14px; font: 600 13px var(--font); cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s; white-space: nowrap;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 20px; font-size: 14px; }
.btn svg { width: 16px; height: 16px; }
.link-btn { background: none; border: 0; color: var(--red-dark); font: inherit; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=month], select, textarea {
  font: 14px var(--font); color: var(--ink); background: #fff;
  border: 1px solid #D5D8DE; border-radius: 8px; padding: 8px 10px; width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px var(--red-50); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
label.field > em { display: block; font-style: normal; font-size: 12px; color: var(--muted); margin-top: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 2px; }
.seg button {
  border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; font: 600 12px var(--font);
  color: var(--muted); cursor: pointer;
}
.seg button.on { background: var(--red); color: #fff; }

/* ---------- flash ---------- */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; line-height: 1.55; }
.flash.error { background: var(--red-50); color: #8E1B17; border: 1px solid var(--red-100); }
.flash.ok { background: var(--green-50); color: #14532D; border: 1px solid #C9E9D6; }
.flash.info { background: var(--blue-50); color: #1E3A6B; border: 1px solid #D4E0F3; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--grey-50); color: var(--ink-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.b-critical { background: var(--red-50); color: #B4231E; }
.b-order { background: var(--amber-50); color: var(--amber); }
.b-future { background: var(--blue-50); color: var(--blue); }
.b-excess { background: var(--violet-50); color: var(--violet); }
.b-healthy { background: var(--green-50); color: var(--green); }
.b-disc { background: var(--grey-50); color: var(--muted); }
.b-final { background: var(--red); color: #fff; }
.b-final::before { background: #fff; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button {
  border: 0; background: none; padding: 10px 14px; font: 600 13.5px var(--font); color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--red-dark); border-bottom-color: var(--red); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; max-height: calc(100vh - 290px); min-height: 200px; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.data th {
  position: sticky; top: 0; z-index: 2; background: #FAFAFB; color: var(--ink-2);
  font-weight: 600; font-size: 12px; text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line);
  white-space: nowrap; cursor: pointer; user-select: none;
}
table.data th.nosort { cursor: default; }
table.data th .arrow { color: var(--red); margin-left: 3px; font-size: 10px; }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.data tbody tr:hover td { background: #FCF7F7; }
table.data tr.clickable { cursor: pointer; }
table.data td.sku { font-weight: 600; white-space: nowrap; }
table.data td.desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data tfoot td { position: sticky; bottom: 0; background: #FAFAFB; font-weight: 700; border-top: 1px solid var(--line); }
/* frozen first columns (item identity) - they stay put while the table scrolls sideways */
table.data td.frozen { position: sticky; z-index: 1; background: #fff; }
table.data th.frozen { z-index: 3; }
table.data tfoot td.frozen { z-index: 3; background: #FAFAFB; }
table.data .frozen-edge { border-right: 1px solid var(--line); }
.table-wrap.has-frozen table.data td.desc { max-width: 240px; }
.table-wrap.frozen-tight table.data td.desc { max-width: 120px; }
.table-tools { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.table-tools input[type=text] { width: 240px; }
.table-tools select { width: auto; min-width: 140px; }
.table-tools .spacer { flex: 1; }
.table-foot { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line-2); }
.pager { display: flex; gap: 6px; align-items: center; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(17, 20, 26, .32); z-index: 90; opacity: 0; pointer-events: none; transition: opacity .15s; }
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(860px, 96vw); background: #fff; z-index: 100;
  box-shadow: var(--shadow-lg); transform: translateX(100%); transition: transform .2s ease; display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.drawer-body { padding: 18px 22px; overflow: auto; flex: 1; }
.close-x { border: 0; background: var(--bg-soft); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 18px; color: var(--muted); }
.close-x:hover { background: var(--line); }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 16px; margin-bottom: 18px; }
.facts div span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.facts div b { font-size: 14px; font-variant-numeric: tabular-nums; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 20px 0 8px; }

/* ---------- login ---------- */
.login-wrap { flex: 1; display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.login-art {
  background: linear-gradient(150deg, #E5322C 0%, #B91F1A 100%); color: #fff; padding: 56px;
  display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.login-art::after {
  content: ""; position: absolute; right: -160px; bottom: -160px; width: 520px; height: 520px;
  border: 26px solid rgba(255, 255, 255, .09); border-radius: 50%;
}
.login-art h1 { font-size: 34px; line-height: 1.15; max-width: 440px; }
.login-art p { opacity: .9; max-width: 420px; font-size: 15px; }
.login-art .logo-white { width: 64px; height: 64px; background: #fff; border-radius: 50%; padding: 6px; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 40px; background: #fff; }
.login-form form { width: 100%; max-width: 360px; }
.login-form h2 { font-size: 24px; margin-bottom: 6px; }
@media (max-width: 860px) { .login-wrap { grid-template-columns: 1fr; } .login-art { display: none; } }

/* ---------- upload ---------- */
.drop {
  border: 1.5px dashed #D3D6DC; border-radius: var(--radius); padding: 16px 18px; background: #fff;
  display: flex; align-items: center; gap: 14px; transition: border-color .12s, background .12s; position: relative;
}
.drop.drag { border-color: var(--red); background: var(--red-50); }
.drop.ok { border-style: solid; border-color: #BFE3CD; background: #FAFDFB; }
.drop.err { border-style: solid; border-color: var(--red-100); background: #FFFBFB; }
.drop .ico {
  width: 40px; height: 40px; border-radius: 10px; background: var(--bg-soft); color: var(--muted);
  display: flex; align-items: center; justify-content: center; flex: none;
}
.drop.ok .ico { background: var(--green-50); color: var(--green); }
.drop.err .ico { background: var(--red-50); color: var(--red); }
.drop .body { flex: 1; min-width: 0; }
.drop .title { font-weight: 600; }
.drop .status { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.drop.ok .status { color: var(--green); }
.drop.err .status { color: #A61E19; }
.drop input[type=file] { display: none; }
.drop .actions { display: flex; gap: 6px; flex: none; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--red); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.overlay {
  position: fixed; inset: 0; background: rgba(255, 255, 255, .86); z-index: 200; display: none;
  align-items: center; justify-content: center; flex-direction: column; gap: 14px; font-weight: 600;
}
.overlay.on { display: flex; }
.overlay .spinner { width: 36px; height: 36px; border-width: 3px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 300;
  box-shadow: var(--shadow-lg); transition: all .2s; font-weight: 500; max-width: 90vw;
}
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

.run-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 18px; }
.run-head .meta { display: flex; gap: 14px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; font-size: 13px; }
.run-head .meta b { color: var(--ink-2); font-weight: 600; }
.run-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.list-row { display: flex; align-items: center; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line-2); }
.list-row:last-child { border-bottom: 0; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

.edit-cell input { width: 90px; padding: 4px 6px; text-align: right; font-size: 13px; }
.chip-src { font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-left: 4px; vertical-align: 1px; }
.src-sales { background: var(--blue-50); color: var(--blue); }
.src-adj { background: var(--amber-50); color: var(--amber); }

/* ---------- charts ---------- */
.chart-tip {
  position: fixed; z-index: 400; display: none; pointer-events: none; background: #fff; color: var(--ink);
  border: 1px solid var(--line); box-shadow: var(--shadow-lg); border-radius: 8px; padding: 8px 10px; font-size: 12px; min-width: 140px;
}
.chart-tip .tt-title { color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.chart-tip .tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.chart-tip .tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.chart-tip .tt-row b { font-variant-numeric: tabular-nums; }
.chart-tip .tt-name { color: var(--muted); }
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar-row { display: grid; grid-template-columns: 150px 1fr 72px; align-items: center; gap: 10px; padding: 2px 0; border-radius: 6px; }
.hbar-row:hover, .hbar-row:focus { background: #FCF7F7; outline: none; }
.hbar-label { font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { height: 14px; }
.hbar-bar { height: 14px; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-val { font-size: 12.5px; font-variant-numeric: tabular-nums; text-align: right; color: var(--ink); font-weight: 600; }
.stackbar { display: flex; gap: 2px; height: 22px; border-radius: 6px; overflow: hidden; }
.stackseg { min-width: 3px; transition: filter .1s; }
.stackseg:hover, .stackseg:focus { filter: brightness(1.08); outline: none; }
.stack-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; margin-top: 14px; }
.stack-item { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--ink-2); }
.stack-item i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.stack-item b { font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; color: var(--ink); }

/* ---------- year view table ---------- */
table.year { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
table.year th, table.year td { padding: 6px 8px; border-bottom: 1px solid var(--line-2); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.year th:first-child, table.year td:first-child { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; }
table.year thead th { background: #FAFAFB; color: var(--ink-2); font-weight: 600; font-size: 11.5px; position: sticky; top: 0; z-index: 2; }
table.year thead th:first-child { z-index: 3; background: #FAFAFB; }
table.year tr.sec td { background: #fff; color: var(--red-dark); font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: .05em; padding-top: 14px; border-bottom: 1px solid var(--line); }
table.year td.cur, table.year th.cur { background: #FDF3F2; }
table.year td.nodata { color: var(--faint); }
table.year tr.total td { font-weight: 700; }
table.year td.tot, table.year th.tot { border-left: 1px solid var(--line); }

/* ---------- dashboard ---------- */
.filters { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 20px; }
.filters label { display: flex; align-items: center; gap: 8px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.filters select { width: auto; min-width: 170px; }
.sec-title { font-size: 12px; font-weight: 700; color: var(--red-dark); text-transform: uppercase; letter-spacing: .06em; margin: 4px 0 10px; display: flex; align-items: center; gap: 10px; }
.sec-title::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.kpi.hero .value { font-size: 40px; font-variant-numeric: normal; }
.kpi .value { font-variant-numeric: normal; }
#dash.loading { opacity: .5; transition: opacity .15s; }
.status-help { margin-top: 18px; border-top: 1px solid var(--line-2); padding-top: 12px; display: flex; flex-direction: column; gap: 7px; font-size: 12.5px; color: var(--muted); }
.status-help i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 8px; vertical-align: 0; }
.status-help b { color: var(--ink-2); font-weight: 600; margin-right: 6px; }

/* ---------- item notes (rule-based summary in the item panel) ---------- */
.item-notes { background: #FBF8F8; border: 1px solid var(--red-100); border-left: 3px solid var(--red); border-radius: 8px; padding: 12px 16px 10px; margin-bottom: 18px; }
.item-notes-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--red-dark); margin-bottom: 6px; }
.item-notes ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.item-notes li { font-size: 13.5px; line-height: 1.5; color: var(--ink); }
.item-notes-foot { font-size: 11px; color: var(--faint); margin-top: 8px; }

/* number columns: heading aligned with the figures below it */
table.data th.n { text-align: right; }

/* ---------- pop-up (top-up confirmation) ---------- */
.modal-bd { position: fixed; inset: 0; background: rgba(17, 20, 26, .4); z-index: 250; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-bd.on { display: flex; }
.modal { background: #fff; border-radius: 12px; box-shadow: var(--shadow-lg); width: min(620px, 100%); max-height: 90vh; overflow: auto; }
.modal-head { padding: 18px 22px 8px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.modal .tm-body { padding: 4px 22px 8px; font-size: 13.5px; line-height: 1.55; }
.modal .tm-body ul { margin: 6px 0 10px; padding-left: 20px; }
.modal .tm-warn { background: var(--amber-50); color: #7A4300; border-radius: 8px; padding: 10px 12px; }
.modal-foot { padding: 12px 22px 18px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line-2); }

/* ---------- report "as on" dates in the upload boxes ---------- */
.drop .asof { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.drop .asof span { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.drop .asof input { width: 160px; padding: 5px 8px; font-size: 13px; }
.drop .asof em { font-style: normal; font-size: 11.5px; color: var(--muted); }

/* ---------- multi-select dropdown ---------- */
.ms { position: relative; display: inline-block; }
.ms-btn {
  display: inline-flex; align-items: center; gap: 8px; justify-content: space-between; min-width: 150px; max-width: 260px;
  font: 14px var(--font); color: var(--ink); background: #fff; border: 1px solid #D5D8DE; border-radius: 8px; padding: 8px 10px; cursor: pointer;
}
.ms-btn:hover { border-color: #C0C4CC; }
.ms-btn.on { border-color: var(--red); background: var(--red-50); }
.ms-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-caret { color: var(--muted); font-size: 11px; }
.ms-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 60; background: #fff; border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow-lg); width: max(100%, 260px); padding: 8px;
}
.ms-panel .ms-search { width: 100%; padding: 6px 8px; font-size: 13px; margin-bottom: 6px; }
.ms-actions { display: flex; gap: 12px; padding: 2px 4px 6px; border-bottom: 1px solid var(--line-2); margin-bottom: 4px; }
.ms-actions button { border: 0; background: none; color: var(--red-dark); font: 600 12px var(--font); cursor: pointer; padding: 0; }
.ms-list { max-height: 280px; overflow: auto; display: flex; flex-direction: column; }
.ms-list label { display: flex; align-items: center; gap: 8px; padding: 6px 6px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.ms-list label:hover { background: var(--bg-soft); }
.ms-list input { accent-color: var(--red); width: 15px; height: 15px; }
.ms-empty { padding: 8px; color: var(--muted); font-size: 12.5px; }

/* ---------- row tick boxes (Executive Summary) ---------- */
table.data input.pick, table.data input.pick-all { width: 16px; height: 16px; accent-color: var(--red); cursor: pointer; vertical-align: middle; }
table.data tr.picked td { background: #FDF3F2; }
table.data input[readonly] { background: #F6F6F8; color: var(--muted); cursor: default; }

/* ---------- Order Calculator ---------- */
.calc-results { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px 18px; margin-top: 14px; }
.calc-results > div { border-left: 3px solid var(--line); padding-left: 10px; }
.calc-results span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.calc-results b { font-size: 19px; font-variant-numeric: tabular-nums; }
.calc-results .badge { white-space: normal; font-size: 11px; }
.calc-new { color: var(--red-dark); }
/* tables 2 and 3 side by side; stacked again on narrower screens */
.calc-two { display: grid; grid-template-columns: minmax(330px, 380px) minmax(0, 1fr); gap: 16px; align-items: start; margin-top: 16px; }
.calc-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
@media (max-width: 1100px) {
  .calc-two { grid-template-columns: minmax(0, 1fr); }
  .calc-fields { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) { .calc-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.calc-field { display: block; }
.calc-field > span { display: block; font-size: 11.5px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.calc-field > em { display: block; font-style: normal; font-size: 11px; color: var(--muted); margin-top: 3px; }
.calc-field.on input { border-color: var(--red); background: var(--red-50); font-weight: 700; }
.calc-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.calc-steps { display: flex; flex-direction: column; gap: 10px; font-size: 13px; line-height: 1.5; }
.calc-step { border-left: 2px solid var(--line-2); padding-left: 10px; }
.calc-step-h { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.calc-step-v { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
input.calc-m { width: 92px; padding: 5px 7px; font-size: 12.5px; text-align: right; }
input.calc-m.on { border-color: var(--red); background: var(--red-50); font-weight: 700; }
/* Order Calculator: filters + the Excel-style working */
.calc-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.calc-ac { position: relative; flex: 1 1 300px; max-width: 460px; }
.calc-ac #calcQ { width: 100%; }
.calc-ac-list { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: #fff;
  border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 28px rgba(20, 22, 30, .14); max-height: 340px; overflow-y: auto; }
.calc-ac-item { padding: 8px 12px; cursor: pointer; font-size: 13px; display: flex; gap: 8px; align-items: baseline; border-bottom: 1px solid var(--line-2); }
.calc-ac-item b { white-space: nowrap; }
.calc-ac-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calc-ac-item em { font-style: normal; color: var(--muted); font-size: 12px; white-space: nowrap; }
.calc-ac-item:hover, .calc-ac-item.on { background: var(--red-50); }
.calc-ac-empty { padding: 8px 12px; font-size: 12.5px; color: var(--muted); }
.calc-filters #calcMs { display: contents; }
.calc-sel { flex: 1 1 100%; font-size: 13.5px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
#calcBody.loading { opacity: .55; pointer-events: none; transition: opacity .15s; }
.calc-sheet { width: 100%; border-collapse: collapse; font-size: 13px; }
.calc-sheet th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); padding: 9px 12px;
  border-bottom: 1px solid var(--line); background: var(--bg-2, #fafafb); white-space: nowrap; }
.calc-sheet th.n, .calc-sheet td.n { text-align: right; }
.calc-sheet td { padding: 6px 12px; border-bottom: 1px solid var(--line-2, #f0f1f3); vertical-align: middle; }
.calc-sheet tr.calc-sec td { font-weight: 700; color: var(--red-dark); background: var(--red-50); padding-top: 8px; padding-bottom: 8px;
  text-transform: uppercase; font-size: 11.5px; letter-spacing: .04em; }
.calc-sheet tr.calc-banner td { background: #fff4cc; font-weight: 600; }
.calc-sheet tr.calc-input td { background: #fffbea; }
/* columns as wide as their content, with the same gap between every pair (like a tidy Excel range) */
/* No., Description and Ref as narrow as their content; Formula takes the rest; Value a fixed column on the right
   with its figures centred (each figure in a same-width block, so the numbers still line up) */
.calc-sheet { width: 100%; table-layout: auto; }
.calc-sheet th, .calc-sheet td { padding-left: 16px; padding-right: 16px; }
.calc-sheet col.c-no, .calc-sheet col.c-ref { width: 1px; }
.calc-sheet col.c-desc { width: 270px; }
.calc-sheet col.c-val { width: 180px; }
.calc-sheet td:nth-child(1), .calc-sheet td:nth-child(3), .calc-sheet th { white-space: nowrap; }
.calc-sheet tr.calc-sec td, .calc-sheet tr.calc-banner td { white-space: normal; }
.calc-sheet .calc-ref { font-weight: 700; text-align: center; }
.calc-sheet th:nth-child(3) { text-align: center; }
.calc-sheet .calc-f { color: var(--muted); font-size: 12.5px; }
.calc-sheet th.n:last-child, .calc-sheet td.calc-v { text-align: center; }
.calc-sheet .calc-v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.calc-sheet .calc-v > .calc-out, .calc-sheet .calc-v > .calc-was, input.calc-in { display: inline-block; width: 150px; box-sizing: border-box; }
.calc-sheet .calc-v > .calc-out, .calc-sheet .calc-v > .calc-was { padding-right: 9px; text-align: right; }
.calc-sheet .calc-v > .calc-was { display: block; margin: 0 auto; font-weight: 500; }
input.calc-in { padding: 5px 8px; font-size: 13px; text-align: right; font-weight: 600; }
input.calc-in.on { border-color: var(--red); background: var(--red-50); }

/* the phone sort control lives in the table tools; only phones see it */
.m-sort-wrap { display: none; gap: 6px; }
.m-filter-toggle { display: none; }

/* ==========================================================================
   Phones and small tablets. Everything above is the desktop layout and is
   left untouched; these rules only apply below 720px.
   ========================================================================== */
@media (max-width: 720px) {
  /* ---- shell ---- */
  main { padding: 14px 10px; }
  .topbar-inner { height: 54px; gap: 10px; padding: 0 10px; }
  .brand img { width: 32px; height: 32px; }
  .brand-text b { font-size: 13px; }
  .brand-text span { display: none; }
  .usermenu { gap: 8px; }
  .nav { gap: 2px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav a { padding: 7px 9px; font-size: 13px; white-space: nowrap; }
  .page-head h1, .run-head h1 { font-size: 22px; }
  .card-pad { padding: 14px; }
  .card-head { padding: 12px 14px; flex-wrap: wrap; gap: 4px 10px; }
  .card-head h2 { font-size: 15px; }
  /* a 1fr track still refuses to shrink below its content; minmax(0, 1fr) lets cards fit the screen */
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  /* page-specific two-column grids set inline (dashboard stock-out risk, new run, users) stack too */
  .grid[style*="grid-template-columns"] { grid-template-columns: minmax(0, 1fr) !important; }
  .stack-legend { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 12px; }
  .footer { padding: 12px; }

  /* touch targets, and 16px inputs so iOS does not zoom the page in */
  input[type=text], input[type=password], input[type=number], input[type=date],
  input[type=month], select, textarea { font-size: 16px; padding: 10px 12px; }
  .btn { padding: 10px 14px; }
  .btn-sm { padding: 7px 11px; font-size: 12.5px; }

  /* ---- KPI tiles: two across rather than one tall column ---- */
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 12px 12px 14px; }
  .kpi .label { font-size: 10.5px; letter-spacing: .02em; }
  .kpi .value { font-size: 20px; margin-top: 3px; }
  .kpi.hero .value { font-size: 26px; }
  .kpi .value small { font-size: 11px; }
  .kpi .foot { font-size: 11px; }

  /* ---- run page header ---- */
  .run-head { flex-direction: column; align-items: stretch; gap: 10px; }
  .run-head .meta { gap: 6px 12px; font-size: 12px; }
  .run-actions { flex-wrap: wrap; }
  .run-actions form, .run-actions .btn { flex: 1 1 auto; }

  /* ---- the table component becomes a list of cards ---- */
  .mh-table .table-tools { padding: 10px 12px; gap: 8px; }
  /* the per-table button groups (units, approve, download) are inline-styled flex rows */
  .mh-table .table-tools > div { flex-wrap: wrap; max-width: 100%; }
  .mh-table .table-tools input[type=text] { width: 100%; }
  .mh-table .table-tools .spacer { display: none; }
  .mh-table .table-tools .ms { width: 100%; }
  .mh-table .table-tools .ms-btn { width: 100%; justify-content: space-between; }
  .mh-table .m-filter-toggle { display: inline-flex; }
  .mh-table .m-filter-toggle.on { border-color: var(--red); background: var(--red-50); color: var(--red-dark); }
  .mh-table .ms, .mh-table .m-sort-wrap { display: none; }
  .mh-table.m-filters-open .ms { display: block; }
  .mh-table.m-filters-open .m-sort-wrap { display: flex; width: 100%; }
  .mh-table .m-sort { flex: 1; }
  .mh-table .m-sort-dir { flex: 0 0 44px; }

  .mh-table .table-wrap { max-height: none; min-height: 0; overflow: visible; }
  .mh-table table.data thead { display: none; }
  .mh-table table.data tbody, .mh-table table.data tfoot { display: block; }
  .mh-table table.data tr {
    display: block; background: #fff; border: 1px solid var(--line); border-radius: 10px;
    padding: 10px 12px; margin: 10px 12px;
  }
  .mh-table table.data tbody tr:hover td, .mh-table table.data tr.picked td { background: transparent; }
  .mh-table table.data tr.picked { border-color: var(--red-100); background: #FDF3F2; }
  .mh-table table.data td { display: none; border: 0; padding: 0; text-align: left; }
  .mh-table table.data td.m {
    display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 3px 0;
    font-variant-numeric: tabular-nums;
  }
  .mh-table table.data td.m::before {
    content: attr(data-l); flex: 0 0 auto; color: var(--muted);
    font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  }
  .mh-table table.data td.m-title { display: block; font-weight: 700; font-size: 14px; }
  .mh-table table.data td.m-name { display: block; font-size: 13px; color: var(--ink-2); padding: 1px 0 5px; }
  .mh-table table.data td.m-sub { display: inline-block; margin: 0 8px 4px 0; font-size: 12px; color: var(--muted); }
  .mh-table table.data td.m-full { display: block; padding: 7px 0 0; }
  .mh-table table.data td.m-title::before, .mh-table table.data td.m-name::before,
  .mh-table table.data td.m-sub::before { display: none; }
  .mh-table table.data td.m-full::before {
    display: block; margin-bottom: 4px; content: attr(data-l); color: var(--muted);
    font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  }
  /* controls inside a card run the full width (the desktop widths are inline styles) */
  .mh-table table.data td.m-full select, .mh-table table.data td.m-full input { width: 100% !important; }
  .mh-table table.data td.desc { max-width: none; white-space: normal; overflow: visible; }
  .mh-table table.data td.sku { white-space: normal; }
  .mh-table table.data .frozen { position: static !important; left: auto !important; }
  .mh-table table.data tfoot tr { background: var(--bg-soft); }
  .mh-table table.data tfoot td { position: static; background: transparent; font-weight: 700; }
  .mh-table table.data tfoot td.m::before { font-weight: 600; }
  .mh-table .table-foot { flex-wrap: wrap; gap: 8px; justify-content: center; }
  .mh-table .empty { padding: 28px 12px; }
  /* row tick boxes are not shown on a phone, so the bulk button can never enable */
  .mh-table #approveSel { display: none; }

  /* ---- item panel ---- */
  .drawer { width: 100vw; }
  .drawer-head { padding: 14px 14px 12px; }
  .drawer-head h2 { font-size: 17px; }
  .drawer-body { padding: 14px; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
  .item-notes { padding: 10px 12px 8px; }
  .item-notes li { font-size: 13px; }
  /* the drawer's own tables stay tables - they scroll sideways inside their wrapper */
  .drawer .table-wrap { overflow-x: auto; }
  /* plain tables outside the card-list component (users, runs, the drawer, the compare totals)
     keep their columns and scroll sideways instead of stretching the page */
  .card > table.data, .card-pad > table.data, .drawer-body > table.data {
    display: block; overflow-x: auto; max-width: 100%;
  }

  /* ---- modals ---- */
  .modal-bd { padding: 10px; align-items: flex-end; }
  .modal { border-radius: 14px; max-height: 92vh; }
  .modal-head { padding: 16px 16px 6px; }
  .modal .tm-body { padding: 4px 16px 8px; }
  .modal-foot { padding: 12px 16px 16px; }
  .modal-foot .btn { flex: 1; }
}

/* very narrow phones: brand and account on top, the menu on its own row below */
@media (max-width: 560px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 8px 10px; gap: 8px; }
  .brand { flex: 1; }
  .nav { order: 3; flex: 0 0 100%; border-top: 1px solid var(--line-2); padding-top: 6px; }
}
