/* ==========================================================================
   Amogh ERP — design system
   ========================================================================== */
:root {
  /* brand */
  --primary: #2451d6; --primary-600: #1d43b8; --primary-50: #eef3ff; --primary-100: #dfe8ff;
  /* neutrals (slate) */
  --bg: #f5f7fa; --surface: #ffffff; --surface-2: #f9fafb; --line: #e4e8ee; --line-2: #eef1f5;
  --ink: #101828; --ink-2: #344054; --muted: #667085; --faint: #98a2b3;
  /* sidebar */
  --side: #0f172a; --side-2: #1e293b; --side-ink: #cbd5e1; --side-muted: #64748b;
  /* status (always paired with a text label) */
  --good: #067647; --good-bg: #ecfdf3; --good-line: #abefc6;
  --warn: #b54708; --warn-bg: #fffaeb; --warn-line: #fedf89;
  --bad: #b42318; --bad-bg: #fef3f2; --bad-line: #fecdca;
  --info: #175cd3; --info-bg: #eff8ff; --info-line: #b2ddff;
  --neutral-bg: #f2f4f7; --neutral-ink: #475467;
  --radius: 10px; --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .22), 0 4px 8px -4px rgba(16, 24, 40, .08);
  --side-w: 248px; --top-h: 60px;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-600); }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
h2 { margin: 0; font-size: 1.5rem; font-weight: 650; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h3 { margin: 0 0 14px; font-size: .98rem; font-weight: 620; color: var(--ink); display: flex; align-items: center; gap: 8px; }
code { background: var(--neutral-bg); padding: 1px 5px; border-radius: 4px; font-size: .85em; }
::selection { background: var(--primary-100); }

/* ---------- sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; z-index: 40; transition: transform .2s ease;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 18px 20px 16px; color: #fff; }
.brand:hover { color: #fff; }
.logo { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem;
  background: linear-gradient(135deg, #3b6cf6, #1d43b8); box-shadow: 0 4px 12px rgba(36, 81, 214, .45); }
.logo-img { flex-shrink: 0; width: 50px; height: 40px; border-radius: 9px; background: #fff; display: grid; place-items: center; padding: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .35); }
.logo-img img { max-width: 100%; max-height: 100%; display: block; }
.brand-text { font-size: 1.08rem; line-height: 1.15; }
.brand-text b { font-weight: 750; }
.brand-text small { display: block; font-size: .72rem; color: var(--side-muted); font-weight: 500; margin-top: 2px; max-width: 160px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
nav { flex: 1; overflow-y: auto; padding: 6px 12px; }
nav a { display: flex; align-items: center; gap: 11px; padding: 8px 11px; margin: 1px 0; border-radius: 8px; color: var(--side-ink); font-weight: 500; }
nav a svg { color: var(--side-muted); }
nav a:hover { background: var(--side-2); color: #fff; }
nav a.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(36, 81, 214, .35); }
nav a.active svg { color: #fff; }
nav .step { margin-left: auto; font-size: .7rem; font-weight: 700; color: var(--side-muted); background: var(--side-2); border-radius: 99px; width: 19px; height: 19px; display: grid; place-items: center; }
nav a.active .step { background: rgba(255, 255, 255, .2); color: #fff; }
.nav-group { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--side-muted); font-weight: 650; padding: 18px 11px 6px; }
.sidebar-foot { padding: 14px 12px 18px; border-top: 1px solid var(--side-2); }
.scan-cta { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 10px; border-radius: 9px; font-weight: 600;
  color: #fff; background: var(--side-2); border: 1px dashed #475569; }
.scan-cta:hover { color: #fff; background: #273449; border-color: #94a3b8; }

/* ---------- shell / topbar ---------- */
.shell { margin-left: var(--side-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--top-h); display: flex; align-items: center; gap: 16px; padding: 0 28px;
  background: rgba(255, 255, 255, .85); backdrop-filter: saturate(180%) blur(10px); border-bottom: 1px solid var(--line);
}
.top-title { font-weight: 650; font-size: 1rem; white-space: nowrap; }
.global-search { flex: 1; max-width: 520px; margin-left: auto; position: relative; }
.global-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 16px; height: 16px; }
.global-search input { padding-left: 34px; background: var(--surface-2); height: 36px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; font-weight: 700; border: 1px solid var(--primary-100); }
.icon-btn { border: 0; background: none; padding: 7px; border-radius: 8px; color: var(--ink-2); cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--neutral-bg); }
.menu-btn { display: none; }
.scrim { display: none; }

main { flex: 1; padding: 26px 28px 64px; width: 100%; }

/* ---------- page header ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; font-size: .92rem; }
.crumb { color: var(--muted); font-size: .82rem; margin-bottom: 6px; font-weight: 500; }
.crumb a { color: var(--muted); }
.crumb { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.back-btn { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 10px 0 7px; margin-right: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); border-radius: 7px; font: inherit; font-size: .82rem; font-weight: 600; cursor: pointer; box-shadow: var(--shadow-sm); }
.back-btn svg { width: 15px; height: 15px; }
.back-btn:hover { background: var(--surface-2); color: var(--ink); border-color: #d0d5dd; }
.crumb a:hover { color: var(--primary); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--shadow-sm); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > h3 { padding: 16px 20px 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr)); gap: 18px; margin-bottom: 18px; }
.cols > .card { margin-bottom: 0; }
.cols-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; margin-bottom: 18px; }
.cols-2-1 > .card { margin-bottom: 0; }
.muted { color: var(--muted); }
.hint { font-size: .82rem; color: var(--muted); }
.error { background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad-line); padding: 12px 16px; border-radius: var(--radius-sm); }
.notice { background: var(--info-bg); color: #194185; border: 1px solid var(--info-line); padding: 10px 14px; border-radius: var(--radius-sm); font-size: .9rem; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 8px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: .9rem; white-space: nowrap; box-shadow: var(--shadow-sm); transition: background .12s, border-color .12s, box-shadow .12s;
  vertical-align: middle;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); border-color: #d0d5dd; color: var(--ink); }
.btn:focus-visible { outline: 3px solid var(--primary-100); outline-offset: 1px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.btn.go { background: #0f9d58; background: var(--good); border-color: var(--good); color: #fff; }
.btn.go:hover { background: #05603a; border-color: #05603a; color: #fff; }
.btn.ghost { box-shadow: none; background: transparent; }
.btn.ghost:hover { background: var(--neutral-bg); }
.btn.danger { color: var(--bad); border-color: var(--bad-line); }
.btn.danger:hover { background: var(--bad-bg); color: var(--bad); }
/* coloured utility buttons */
.btn.btn-soft { background: var(--primary-50); border-color: var(--primary-100); color: var(--primary); box-shadow: none; }
.btn.btn-soft:hover { background: var(--primary-100); border-color: #c3d3fb; color: var(--primary-600); }
.btn.btn-excel { background: #107c41; border-color: #107c41; color: #fff; }
.btn.btn-excel:hover { background: #0b5e31; border-color: #0b5e31; color: #fff; }
.btn.btn-excel-outline { background: #f0f9f3; border-color: #9fd3b4; color: #107c41; box-shadow: none; }
.btn.btn-excel-outline:hover { background: #ddf2e5; border-color: #6fbf90; color: #0b5e31; }
.btn.small, .btn.sm { height: 30px; padding: 0 10px; font-size: .84rem; }
.btn:disabled { opacity: .55; cursor: wait; }
.icon { border: 0; background: none; cursor: pointer; color: var(--faint); font-size: 1rem; padding: 4px 6px; border-radius: 6px; }
.icon:hover { color: var(--bad); background: var(--bad-bg); }

/* dropdown ("More") */
.dd { position: relative; }
.dd-menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-lg); padding: 6px; z-index: 35; display: none; }
.dd.open .dd-menu { display: block; }
.dd-menu button, .dd-menu a { display: flex; width: 100%; align-items: center; gap: 9px; padding: 8px 10px; border: 0; background: none; border-radius: 7px;
  font: inherit; color: var(--ink-2); cursor: pointer; text-align: left; }
.dd-menu button:hover, .dd-menu a:hover { background: var(--neutral-bg); color: var(--ink); }
.dd-menu .danger { color: var(--bad); }
.dd-menu .danger:hover { background: var(--bad-bg); color: var(--bad); }
.dd-menu hr { border: 0; border-top: 1px solid var(--line-2); margin: 5px 2px; }
.dd-menu label { display: block; padding: 6px 10px 2px; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 650; }
.dd-menu select { margin: 2px 0 4px; }

/* ---------- badges (text label + colour, never colour alone) ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600;
  background: var(--neutral-bg); color: var(--neutral-ink); border: 1px solid #e4e7ec; white-space: nowrap; vertical-align: middle; line-height: 1.5; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.s-good { background: var(--good-bg); color: var(--good); border-color: var(--good-line); }
.badge.s-warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-line); }
.badge.s-bad { background: var(--bad-bg); color: var(--bad); border-color: var(--bad-line); }
.badge.s-info { background: var(--info-bg); color: var(--info); border-color: var(--info-line); }
.badge.plain::before { display: none; }
h2 .badge { font-size: .8rem; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f8faff; }
.table-wrap { overflow-x: auto; }
.card > .table-wrap:first-child, .card.flush .table-wrap { margin: 0; }
.list-card { padding: 0; overflow: hidden; }
.list-card .toolbar { padding: 14px 16px; border-bottom: 1px solid var(--line); margin: 0; background: var(--surface); }
.list-card table th:first-child, .list-card table td:first-child { padding-left: 18px; }
.doc-no { font-weight: 650; color: var(--ink); }
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; white-space: nowrap; }
.cell-sub { display: block; color: var(--muted); font-size: .82rem; margin-top: 1px; }
.empty { padding: 22px 16px; text-align: center; color: var(--muted); font-size: .92rem; }
.empty svg { width: 26px; height: 26px; color: var(--faint); display: block; margin: 0 auto 10px; stroke-width: 1.4; }
.overdue { color: var(--bad); font-weight: 600; }
.mini-table td { padding: 10px 6px; }
.mini-table tr:first-child td { padding-top: 2px; }

/* ---------- toolbar / filters ---------- */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { max-width: 280px; height: 36px; }
.toolbar .count { margin-left: auto; color: var(--muted); font-size: .85rem; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; height: 30px; padding: 0 12px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font: inherit; font-size: .84rem; font-weight: 550; cursor: pointer; }
.chip:hover { border-color: #c7cdd6; }
.chip.on { background: var(--primary-50); color: var(--primary); border-color: var(--primary-100); }

/* ---------- forms ---------- */
input, select, textarea {
  width: 100%; font: inherit; padding: 8px 11px; border: 1px solid #d0d5dd; border-radius: 8px; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow-sm); transition: border-color .12s, box-shadow .12s;
}
input, select { height: 38px; }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; box-shadow: none; accent-color: var(--primary); }
input:focus, select:focus, textarea:focus { outline: none; border-color: #84a5f5; box-shadow: 0 0 0 4px var(--primary-50); }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { resize: vertical; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(230px, 100%), 1fr)); gap: 14px 18px; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld > span { font-size: .82rem; color: var(--ink-2); font-weight: 600; }
.fld.wide { grid-column: 1 / -1; }
.fld.check { flex-direction: row; align-items: center; gap: 9px; }
.fld.check > span { font-weight: 500; }
.row-inline { display: flex; gap: 6px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 6px; padding: 16px 0; position: sticky; bottom: 0;
  background: linear-gradient(to top, var(--bg) 70%, rgba(245, 247, 250, 0)); z-index: 5; }
.section-title { font-size: .74rem; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 700; margin: 0 0 12px; }

/* line-item editor */
.items-edit th { background: transparent; border-bottom: 1px solid var(--line); padding: 8px 6px; }
/* fixed column widths so every header sits exactly over its input; description takes the rest */
.items-edit th.c-idx { width: 34px; }
.items-edit th.c-hsn { width: 120px; }
.items-edit th.c-qty { width: 100px; }
.items-edit th.c-unit { width: 90px; }
.items-edit th.c-rate { width: 120px; }
.items-edit th.c-pct { width: 82px; }
.items-edit th.c-amt { width: 120px; }
.items-edit th.c-del { width: 36px; }
.items-edit td input.w-xs, .items-edit td input.w-s, .items-edit td input.w-m { width: 100%; }
.items-edit td { padding: 6px; border-bottom: 0; vertical-align: top; }
.items-edit td.idx { color: var(--faint); padding-top: 15px; width: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.items-edit textarea { min-height: 38px; }
.items-edit input.num { text-align: right; }
.items-edit tbody.item + tbody.item tr:first-child td { border-top: 1px dashed var(--line); padding-top: 10px; }
.items-edit .refs { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1.3fr) 64px 150px; gap: 5px; margin-top: 5px; }
.items-edit .refs input { min-width: 0; }
.items-edit .refs input { width: 100%; font-size: .82rem; height: 30px; padding: 4px 8px; box-shadow: none; background: var(--surface-2); }
.items-edit .refs input:focus { background: #fff; }
.items-edit .verify, .verify-chip { background: var(--warn-bg) !important; border-color: #f5b74e !important; }
.verify-chip { border: 1px solid; border-radius: 5px; padding: 0 6px; color: var(--warn); font-weight: 600; }
.items-edit tr.srcrow td { padding: 10px 6px 2px; }
.items-edit tr.srcrow img, .src-head img { display: block; width: 100%; max-width: 1100px; border: 1px solid var(--line); border-radius: 6px; cursor: zoom-in; }
.items-edit tr.srcrow img.zoom { max-width: none; width: 160%; cursor: zoom-out; }
.src-head { margin: 0 0 6px 34px; }
.amt { padding-top: 15px !important; white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.w-xs { width: 72px; } .w-s { width: 92px; } .w-m { width: 116px; }
.item-ref { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.inv-pick { margin-top: 14px; max-height: 48vh; overflow: auto; border: 1px solid var(--line); border-radius: 9px; }
.inv-pick th { position: sticky; top: 0; z-index: 1; }
.inv-pick td { vertical-align: middle; padding: 7px 10px; }
.inv-pick input[data-desc] { height: 32px; font-size: .88rem; box-shadow: none; min-width: 220px; }
.inv-pick input[data-qty], .inv-pick input[data-rate] { height: 32px; text-align: right; box-shadow: none; }
.inv-pick input[data-rate].changed { background: var(--info-bg); border-color: var(--info-line); font-weight: 600; }
.inv-pick input[data-qty].verify { background: var(--bad-bg); border-color: var(--bad-line); }
.inv-pick tr.off td { opacity: .5; }
.inv-pick tr.done td { opacity: .45; }
.inv-pick .item-ref { margin-top: 2px; }
.sticker-pick { margin-top: 14px; display: grid; gap: 6px; max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; }
.sticker-pick .fld.check { align-items: flex-start; }
.sticker-pick .fld.check input { margin-top: 3px; }
.plan-table td { padding: 5px 8px; vertical-align: middle; }
.plan-table input { height: 32px; font-size: .88rem; box-shadow: none; }
.plan-table input[data-p="process"] { border-color: transparent; background: transparent; font-weight: 550; padding-left: 0; }
.plan-table input[data-p="process"]:focus { border-color: #84a5f5; background: #fff; padding-left: 8px; }
.items-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.items-tools .spacer { flex: 1; } /* Add line on the left, Excel import / template on the right */
.xl-tools { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.items-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.items-head .section-title { margin: 0; }

/* totals */
.totals { margin-left: auto; width: 320px; margin-top: 14px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 9px; padding: 10px 14px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.totals .grand { font-weight: 700; font-size: 1.06rem; color: var(--ink); border-top: 1px solid var(--line); margin-top: 4px; padding-top: 9px; }

/* key/value */
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 9px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .86rem; }
.cols-2-1 > .card:last-child .kv { grid-template-columns: 84px 1fr; }
.kv dd { margin: 0; white-space: pre-wrap; color: var(--ink); font-weight: 500; }

/* ---------- document stepper ---------- */
.flow { display: flex; align-items: stretch; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow-x: auto; }
.stage { flex: 1; min-width: 150px; padding: 14px 16px; position: relative; border-right: 1px solid var(--line-2); }
.stage:last-child { border-right: 0; }
.stage-title { display: flex; align-items: center; gap: 8px; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 700; margin-bottom: 8px; }
.stage-title .dot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: .72rem; background: var(--neutral-bg); color: var(--faint); border: 1px solid var(--line); }
.stage.done .stage-title { color: var(--good); }
.stage.done .stage-title .dot { background: var(--good-bg); color: var(--good); border-color: var(--good-line); }
.stage.current { background: var(--primary-50); }
.stage.current .stage-title { color: var(--primary); }
.stage.current .stage-title .dot { background: var(--primary); color: #fff; border-color: var(--primary); }
.stage a { display: block; font-weight: 650; font-size: .9rem; margin-top: 3px; color: var(--ink); }
.stage a:hover { color: var(--primary); }
.stage a.me { color: var(--primary); }
.stage small { font-weight: 500; color: var(--muted); }
.stage .none { color: var(--faint); font-size: .85rem; }
.arrow { display: none; }

.progress { height: 8px; background: var(--neutral-bg); border-radius: 99px; overflow: hidden; min-width: 90px; }
.progress > i { display: block; height: 100%; background: var(--good); border-radius: 99px; }

/* ---------- dashboard ---------- */
.hello { margin-bottom: 20px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: block; color: var(--ink); box-shadow: var(--shadow-sm); transition: border-color .12s, box-shadow .12s, transform .12s; }
.tile:hover { border-color: #c7d4f7; box-shadow: var(--shadow); color: var(--ink); transform: translateY(-1px); }
.tile .top { display: flex; justify-content: space-between; align-items: center; }
.tile .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tile .ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-50); color: var(--primary); }
.tile .ic svg { width: 17px; height: 17px; }
.tile .v { font-size: 1.85rem; font-weight: 700; margin: 8px 0 2px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .s { font-size: .82rem; color: var(--muted); }

.pipeline { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; margin-bottom: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.pipe { padding: 16px 18px; border-right: 1px solid var(--line-2); color: var(--ink); position: relative; display: block; }
.pipe:last-child { border-right: 0; }
.pipe:hover { background: var(--surface-2); color: var(--ink); }
.pipe .n { font-size: .72rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .07em; }
.pipe .t { font-weight: 650; margin: 2px 0 8px; display: flex; align-items: center; gap: 7px; }
.pipe .t svg { color: var(--muted); width: 16px; height: 16px; }
.pipe .v { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.pipe .s { font-size: .8rem; color: var(--muted); }
.pipe:not(:last-child)::after { content: ""; position: absolute; right: -7px; top: 50%; width: 12px; height: 12px; background: var(--surface); border-top: 1px solid var(--line-2); border-right: 1px solid var(--line-2); transform: translateY(-50%) rotate(45deg); z-index: 1; }

.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: grid; grid-template-columns: 10px 1fr; gap: 12px; padding: 9px 0; font-size: .9rem; position: relative; }
.activity li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--primary-100); border: 2px solid var(--primary); margin-top: 6px; }
.activity li:not(:last-child)::after { content: ""; position: absolute; left: 4px; top: 22px; bottom: -6px; width: 2px; background: var(--line-2); }
.activity time { color: var(--faint); font-size: .78rem; display: block; margin-top: 1px; }

/* ---------- modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); backdrop-filter: blur(2px); display: grid; place-items: center; z-index: 60; padding: 20px; animation: fade .12s ease; }
.modal { background: var(--surface); border-radius: 14px; width: min(580px, 100%); max-height: 92vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: pop .16s ease; }
.modal.wide { width: min(880px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 14px; border-bottom: 1px solid var(--line-2); }
.modal-head h3 { margin: 0; font-size: 1.08rem; }
.modal-head .icon:hover { color: var(--ink); background: var(--neutral-bg); }
.modal-body { padding: 18px 22px 20px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding-top: 18px; margin-top: 6px; border-top: 1px solid var(--line-2); }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }

/* ---------- sign-in screen ---------- */
body.signed-out .sidebar, body.signed-out .shell, body.signed-out .scrim { display: none !important; }
.auth-screen { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 20px; overflow: auto;
  background: radial-gradient(1200px 600px at 15% 10%, #1e3a8a 0%, transparent 60%), radial-gradient(900px 500px at 90% 90%, #0b1f4d 0%, transparent 60%), #0f172a; }
.auth-screen[hidden] { display: none; } /* display:grid above would otherwise override the hidden attribute */
.auth-card { width: min(420px, 100%); background: var(--surface); border-radius: 16px; padding: 30px 30px 26px; box-shadow: 0 30px 70px -20px rgba(0, 0, 0, .55); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; font-size: 1.15rem; }
.auth-brand .logo-img { width: 56px; height: 46px; box-shadow: none; border: 1px solid var(--line); }
.auth-brand b { font-weight: 750; }
.auth-brand small { display: block; font-size: .78rem; color: var(--muted); }
.auth-card h2 { font-size: 1.35rem; }
.auth-card .hint { margin: 6px 0 18px; }
.auth-card form { display: grid; gap: 14px; }
.auth-submit { height: 42px; font-size: .95rem; margin-top: 4px; }
.auth-error { background: var(--bad-bg); color: var(--bad); border: 1px solid var(--bad-line); border-radius: 8px; padding: 9px 12px; font-size: .88rem; }

/* account menu */
.user-menu .avatar { border: 1px solid var(--primary-100); cursor: pointer; font: inherit; font-weight: 700; padding: 0; }
.user-menu .avatar:hover { background: var(--primary-100); }
.user-menu .dd-menu { min-width: 230px; }
.um-head { padding: 8px 10px 4px; }
.um-head b { display: block; }
.um-head small { color: var(--muted); }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #101828; color: #fff; padding: 11px 16px; border-radius: 10px; max-width: 440px; box-shadow: var(--shadow-lg); font-weight: 500; display: flex; gap: 10px; align-items: flex-start; animation: pop .16s ease; }
.toast::before { content: "✓"; color: #6ce9a6; font-weight: 800; }
.toast.err { background: var(--bad); }
.toast.err::before { content: "!"; color: #fff; }

/* ---------- PO scan ---------- */
.engine { display: grid; gap: 10px; }
.engine label { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; cursor: pointer; }
.engine label:has(input:checked) { border-color: #84a5f5; background: var(--primary-50); }
.engine label:has(input:disabled) { opacity: .7; cursor: default; }
.drop { display: block; border: 2px dashed #c3cbd8; border-radius: 12px; padding: 40px 20px; text-align: center; cursor: pointer; background: var(--surface-2); transition: .12s; }
.drop svg { width: 36px; height: 36px; color: var(--primary); stroke-width: 1.5; display: block; margin: 0 auto 10px; }
.drop:hover, .drop.over { border-color: var(--primary); background: var(--primary-50); }
.scanning { display: flex; align-items: center; gap: 12px; padding: 12px; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--primary-100); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.scan-grid { display: grid; grid-template-columns: minmax(280px, 5fr) 7fr; gap: 18px; align-items: start; }
.scan-grid > div > .card:last-child { margin-bottom: 18px; }
.preview { position: sticky; top: calc(var(--top-h) + 14px); padding: 8px; }
.preview img { width: 100%; display: block; border-radius: 6px; }
.preview iframe { width: 100%; height: 78vh; border: 0; }
.checks { list-style: none; margin: 0 0 12px; padding: 0; }
.checks li { padding: 7px 0; border-bottom: 1px solid var(--line-2); font-size: .9rem; display: flex; gap: 8px; align-items: flex-start; }
.checks li:last-child { border-bottom: 0; }
.newcust { margin: 6px 0 16px; padding: 14px; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 9px; }
.newcust:empty { display: none; }
.live-check { margin-top: 14px; display: grid; gap: 8px; font-size: .92rem; }
.raw { margin-top: 16px; }
.raw summary { cursor: pointer; color: var(--primary); font-weight: 550; }
.raw pre { max-height: 320px; overflow: auto; background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 12px; font-size: .78rem; white-space: pre-wrap; }

/* grid/flex children may shrink below their content width (prevents sideways scrolling on phones) */
.cols > *, .cols-2-1 > *, .tiles > *, .pipeline > *, .scan-grid > *, .shell, main { min-width: 0; }
.shell { overflow-x: clip; }

/* ==========================================================================
   Responsive
   ≤1200 icon rail · ≤1100 stacked detail columns · ≤860 drawer nav · ≤640 phone (card tables)
   ========================================================================== */

/* --- laptop / landscape tablet: icon-only sidebar rail --- */
@media (max-width: 1200px) and (min-width: 861px) {
  :root { --side-w: 76px; }
  .brand { justify-content: center; padding: 18px 0 16px; }
  .logo-img { width: 52px; height: 42px; }
  .brand-text, nav .lbl, nav .step, .nav-group, .sidebar-foot .lbl { display: none; }
  nav { padding: 6px 10px; }
  nav a { justify-content: center; padding: 10px 0; position: relative; }
  nav a svg { width: 20px; height: 20px; }
  .nav-group { display: block; height: 1px; padding: 0; margin: 12px 8px; background: var(--side-2); font-size: 0; }
  .sidebar-foot { padding: 12px 10px 16px; }
  .scan-cta { padding: 10px 0; }
  /* tooltip */
  nav a:hover::after, .scan-cta:hover::after {
    content: attr(title); position: absolute; left: calc(100% + 12px); top: 50%; transform: translateY(-50%);
    background: #101828; color: #fff; font-size: .8rem; font-weight: 600; padding: 5px 9px; border-radius: 6px; white-space: nowrap; box-shadow: var(--shadow-lg); z-index: 50;
  }
  .scan-cta { position: relative; }
}

@media (max-width: 1100px) {
  .pipeline { grid-template-columns: repeat(2, 1fr); }
  .pipe:nth-child(2n)::after { display: none; }
  .pipe:nth-child(-n+2) { border-bottom: 1px solid var(--line-2); }
  .pipe:nth-child(2n) { border-right: 0; }
  .cols-2-1, .scan-grid { grid-template-columns: 1fr; }
  .preview { position: static; }
  .preview img { max-height: 70vh; object-fit: contain; }
  main { padding: 22px 22px 60px; }
  .topbar { padding: 0 22px; }
}

/* --- portrait tablet & phone: slide-out drawer --- */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); width: 272px; box-shadow: none; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 35; }
  body.nav-open { overflow: hidden; }
  .shell { margin-left: 0; }
  .menu-btn { display: grid; }
  .topbar { padding: 0 14px; gap: 10px; height: 56px; }
  .top-title { font-size: .95rem; }
  .global-search { max-width: none; }
  .top-actions .btn span { display: none; }
  .top-actions .btn { width: 36px; padding: 0; }
  main { padding: 18px 16px 60px; }
  h2 { font-size: 1.3rem; }
  .flow { flex-direction: column; }
  .stage { border-right: 0; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 14px; min-width: 0; }
  .stage:last-child { border-bottom: 0; }
  .stage-title { margin: 0; min-width: 130px; }
  .stage a { margin: 0; }
  .stage a br { display: none; }
  .stage small::before { content: " · "; }
  .kv { grid-template-columns: 130px 1fr; }
  .totals { width: 100%; }
  .tiles { grid-template-columns: 1fr 1fr; gap: 12px; }
  .toolbar input { max-width: none; flex: 1 1 100%; }
  .chips { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex-shrink: 0; }
  .toolbar .count { margin-left: 0; }
}

/* --- phone --- */
@media (max-width: 640px) {
  :root { font-size: 14.5px; }
  .top-title { display: none; }
  .global-search input { font-size: 16px; } /* no iOS zoom on focus */
  .global-search input::placeholder { font-size: 14px; }
  main { padding: 14px 12px 80px; }
  .card { padding: 14px; border-radius: 12px; margin-bottom: 14px; }
  .cols, .cols-2-1 { gap: 14px; margin-bottom: 14px; }
  .card.flush > h3 { padding: 14px 14px 0; }

  /* page header: title first, actions as a horizontally scrollable row */
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 14px; }
  .page-head .actions { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px; padding: 2px 12px 6px; scrollbar-width: none; }
  .page-head .actions::-webkit-scrollbar { display: none; }
  .page-head .actions > * { flex-shrink: 0; }
  .page-head .actions .dd { position: static; }
  .dd-menu { position: fixed; left: 12px; right: 12px; top: auto; bottom: 12px; min-width: 0; border-radius: 14px; padding: 8px; max-height: 70vh; overflow: auto; }
  .dd-menu button, .dd-menu a { padding: 12px; }
  .hello .sub { font-size: .88rem; }

  /* dashboard */
  .pipeline { grid-template-columns: 1fr 1fr; }
  .pipe { padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
  .pipe:nth-child(2n) { border-right: 0; }
  .pipe:nth-last-child(-n+2) { border-bottom: 0; }
  .pipe::after { display: none; }
  .pipe .v { font-size: 1.35rem; }
  .tiles { gap: 10px; }
  .tile { padding: 12px 14px; }
  .tile .ic { display: none; }
  .tile .v { font-size: 1.3rem; margin-top: 4px; }

  /* forms */
  .grid { grid-template-columns: 1fr; gap: 12px; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom */
  .form-actions { margin: 0 -12px; padding: 12px; background: var(--surface); border-top: 1px solid var(--line); position: sticky; bottom: 0; }
  .form-actions .btn { flex: 1; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 10px; }
  .cols-2-1 > .card:last-child .kv { grid-template-columns: 1fr; }

  /* tables become stacked cards (labels come from data-label, set by JS) */
  table.rt thead { display: none; }
  table.rt, table.rt tbody, table.rt tr, table.rt td { display: block; width: 100%; }
  table.rt tr { padding: 10px 14px; border-bottom: 1px solid var(--line-2); }
  table.rt tbody tr:last-child { border-bottom: 0; }
  table.rt td { border: 0; padding: 4px 0; text-align: right; overflow-wrap: anywhere; }
  table.rt td::before { content: attr(data-label); float: left; margin-right: 14px; color: var(--muted); font-size: .76rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding-top: 2px; }
  table.rt td::after { content: ""; display: block; clear: both; }
  table.rt td .cell-sub { text-align: right; }
  table.rt td:first-child { font-size: 1rem; text-align: left; padding-bottom: 6px; }
  table.rt td:first-child .cell-sub { text-align: left; }
  table.rt td:first-child::before { display: none; }
  table.rt td[data-label=""]::before { display: none; }
  table.rt td:empty { display: none; }
  table.rt td .btn { margin: 4px 0 0 4px; }
  table.rt tr.click:hover td { background: none; }
  table.rt tr.click:active { background: #f8faff; }
  .list-card table th:first-child, .list-card table td:first-child { padding-left: 0; }
  .mini-table td { padding: 2px 0; }

  /* line-item editor: one card per line */
  .items-edit thead { display: none; }
  .items-edit, .items-edit tbody.item, .items-edit tr { display: block; width: 100%; }
  .items-edit tbody.item { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--surface); }
  .items-edit tbody.item + tbody.item tr:first-child td { border-top: 0; padding-top: 0; }
  .items-edit tr:not(.srcrow) { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .items-edit td { padding: 0; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
  .items-edit td::before { content: attr(data-label); font-size: .72rem; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
  .items-edit td[data-label=""]::before { display: none; }
  .items-edit td:nth-child(2) { grid-column: 1 / -1; }
  .items-edit td.idx { grid-column: 1 / 2; padding: 0; font-size: .85rem; }
  .items-edit td.idx::before { content: "Line"; }
  .items-edit td:last-child { grid-column: 3; grid-row: 1; align-items: flex-end; }
  .items-edit td:last-child::before { display: none; }
  .items-edit .w-xs, .items-edit .w-s, .items-edit .w-m { width: 100%; }
  .items-edit .refs { grid-template-columns: 1fr 1fr; }
  .items-edit .amt { padding-top: 0 !important; text-align: left; font-size: 1rem; }
  .items-edit tr.srcrow { display: block; }
  .items-edit tr.srcrow td { padding: 0 0 8px; display: block; }
  .items-edit tr.srcrow td:first-child { display: none; }
  .items-edit tr.srcrow img { overflow-x: auto; }
  .src-head { margin-left: 0; }

  /* modal → full-screen sheet */
  .modal-back { padding: 0; place-items: end stretch; }
  .modal, .modal.wide { width: 100%; max-height: 94vh; border-radius: 16px 16px 0 0; }
  .modal-body { padding: 14px 16px calc(16px + env(safe-area-inset-bottom)); }
  .modal-foot { position: sticky; bottom: -16px; background: var(--surface); padding-bottom: 6px; }
  .modal-foot .btn { flex: 1; }

  /* scan page */
  .drop { padding: 28px 14px; }
  .engine label { font-size: .9rem; }
  .preview iframe { height: 60vh; }

  #toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
}
@media (max-width: 340px) {
  .tiles { grid-template-columns: 1fr; }
  .items-edit tr:not(.srcrow) { grid-template-columns: 1fr 1fr; }
  .items-edit td:last-child { grid-column: 2; }
}
@media print {
  .sidebar, .topbar, .actions, .toolbar, .form-actions { display: none !important; }
  .shell { margin: 0; }
}
