/* Finale-like look (Salesforce Lightning flavour): white top bar with a blue rule, grey canvas,
   compact tables with grouped headers, blue action buttons. Dark theme through variables. */
:root {
  color-scheme: light;
  --bg: #f4f6f9; --panel: #fff; --ink: #181818; --muted: #6b6e73; --line: #dddbda; --line-2: #ecebea;
  --brand: #0070d2; --brand-dark: #005fb2; --brand-ink: #fff; --link: #0070d2; --head-bg: #fff;
  --th-bg: #f3f3f3; --row-hover: #f7fbff; --row-alt: #fff; --input-bg: #fff; --input-line: #c9c7c5; --focus: #1b96ff;
  --ok-bg: #e6f7ea; --ok-ink: #1b6d2f; --bad-bg: #fde8e8; --bad-ink: #b00020; --warn: #c23934; --warn-bg: #fff1e6; --warn-ink: #8c4b00;
  --step: #d8dde6; --step-ink: #fff; --card-head: #f3f3f3; --neg: #c23934; --shadow: 0 1px 3px rgba(0,0,0,.08);
  --expand-bg: #f7f9fb; --tab-ink: #3e3e3c;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #11161c; --panel: #181f27; --ink: #e6e9ed; --muted: #98a2ad; --line: #2b3440; --line-2: #222b35;
  --brand: #2b8de6; --brand-dark: #1f74c0; --link: #6db3ff; --head-bg: #0e1319;
  --th-bg: #1f2833; --row-hover: #1d2a38; --input-bg: #0f151c; --input-line: #3a4552; --focus: #4fa3ff;
  --ok-bg: #11301a; --ok-ink: #9fe3b1; --bad-bg: #3a1115; --bad-ink: #ffb4b4; --warn-bg: #3a2a10; --warn-ink: #ffd49a;
  --step: #33404d; --card-head: #1f2833; --expand-bg: #141b23; --tab-ink: #c7ced6;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 13px/1.4 "Segoe UI", Arial, Helvetica, sans-serif; color: var(--ink); background: var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 18px; margin: 0; font-weight: 700; }
h2 { font-size: 16px; font-weight: 400; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 0 0 6px; }
main { flex: 1; padding: 0 16px 24px; }
main.bare { padding: 0; }
footer { color: var(--muted); font-size: 11px; text-align: center; padding: 14px; border-top: 1px solid var(--line-2); }
code { background: var(--th-bg); padding: 1px 5px; border-radius: 3px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.neg { color: var(--neg); font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* top bar */
.topbar { height: 38px; background: var(--head-bg); border-bottom: 3px solid var(--brand); display: flex; align-items: stretch; padding: 0 8px 0 10px; position: sticky; top: 0; z-index: 40; box-shadow: var(--shadow); }
.logo { display: flex; align-items: center; margin-right: 14px; }
.menus { display: flex; align-items: stretch; }
.menus.right { margin-left: auto; }
.menu { position: relative; display: flex; }
.menu-btn { all: unset; cursor: pointer; padding: 0 12px; display: flex; align-items: center; gap: 4px; color: var(--ink); font-size: 13px; border-top: 3px solid transparent; margin-top: -0px; }
.menu-btn:hover, .menu.open .menu-btn { background: var(--th-bg); }
.menu.current .menu-btn { background: var(--th-bg); border-top-color: var(--brand); }
.chev { display: inline-block; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(45deg) translateY(-2px); margin-left: 2px; }
.dropdown { display: none; position: absolute; top: 100%; left: 0; min-width: 220px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.14); padding: 4px 0; z-index: 50; }
.menu.open .dropdown { display: block; }
.menus.right .dropdown { left: auto; right: 0; }
.dropdown a, .dropdown .who { display: block; padding: 7px 14px; color: var(--ink); white-space: nowrap; }
.dropdown a:hover { background: var(--row-hover); text-decoration: none; }
.dropdown a.active { font-weight: 700; }
.dropdown .sep { border-top: 1px solid var(--line-2); margin: 4px 0; }
.dropdown .who { color: var(--muted); font-size: 12px; }
.gear { display: flex; align-items: center; padding: 0 8px; color: var(--brand); }
.gear.current { background: var(--th-bg); }

/* page head */
.page-head { display: flex; align-items: center; gap: 12px; padding: 14px 0 8px; }
.page-head .icon { width: 32px; height: 32px; border-radius: 4px; background: #3296ed; display: flex; align-items: center; justify-content: center; flex: none; }
.page-head .icon svg { width: 20px; height: 20px; }
.icon-stock { background: #3296ed; } .icon-products { background: #2f9bd6; } .icon-lookups { background: #5f94d6; } .icon-history { background: #3b8fdd; }
.icon-takes { background: #8c74d3; } .icon-changes { background: #7f74d3; } .icon-transfers { background: #9a7fd8; }
.icon-sales { background: #8bc34a; } .icon-customers { background: #78b833; } .icon-suppliers { background: #e26a4e; } .icon-purchases { background: #f0a132; } .icon-reorder { background: #e9b300; }
.icon-settings { background: #2e844a; } .icon-import { background: #5f94d6; }
.titles { display: flex; flex-direction: column; }
.crumb { font-size: 11.5px; }
h1 .sub { color: var(--brand); font-weight: 700; }
h1 .view-pick { color: var(--brand); cursor: pointer; }
.head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.saved-state { color: var(--muted); font-size: 12px; }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 4px; border: 1px solid var(--brand); background: var(--brand); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn.outline { background: var(--panel); color: var(--brand); border-color: var(--input-line); }
.btn.outline:hover { background: var(--th-bg); }
.btn.sm { padding: 4px 10px; font-weight: 400; }
.btn.danger { background: var(--panel); color: var(--neg); border-color: var(--neg); }
.btn.link { background: none; border: 0; color: var(--link); padding: 0; font-weight: 400; }
.btn.commit { background: #7fb5e8; border-color: #7fb5e8; padding: 9px 18px; }
.btn.commit.ready { background: var(--brand); border-color: var(--brand); }
.btn[disabled] { opacity: .6; cursor: default; }
.btn-menu { position: relative; display: inline-block; }
.btn-menu .dropdown { right: 0; left: auto; min-width: 200px; }
.btn-menu.open .dropdown { display: block; }
.confirm-armed { background: var(--neg) !important; border-color: var(--neg) !important; color: #fff !important; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin: 6px 0 14px; overflow-x: auto; }
.tabs a { padding: 8px 12px 9px; color: var(--tab-ink); border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.active { color: var(--ink); font-weight: 700; border-bottom-color: var(--brand); }
.tabs a:hover { text-decoration: none; border-bottom-color: var(--line); }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; margin: 0 0 10px; }
.filters .f { display: flex; flex-direction: column; gap: 3px; min-width: 160px; }
.filters .f.wide { min-width: 220px; }
.filters .f.narrow { min-width: 110px; }
.filters label { font-size: 12px; color: var(--muted); }
.filters .search-wrap { min-width: 200px; }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=email], select, textarea {
  padding: 7px 10px; border: 1px solid var(--input-line); border-radius: 4px; background: var(--input-bg); color: var(--ink); font: inherit; min-height: 32px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 2px rgba(27,150,255,.25); }
input:disabled, input[readonly] { background: var(--th-bg); color: var(--muted); }
input[type=number] { text-align: right; }
.search-wrap { position: relative; }
.search-wrap input { width: 100%; padding-right: 28px; }
.search-ico { position: absolute; right: 9px; top: 50%; width: 10px; height: 10px; border: 1.6px solid var(--muted); border-radius: 50%; transform: translateY(-60%); }
.search-ico::after { content: ""; position: absolute; width: 5px; height: 1.6px; background: var(--muted); right: -5px; bottom: -2px; transform: rotate(45deg); }
.filtered { font-size: 12px; color: var(--muted); margin: 4px 0 10px; }
.filtered b { color: var(--ink); }
.more-btn { align-self: flex-end; }
.chip { display: inline-block; background: var(--th-bg); border: 1px solid var(--line); border-radius: 12px; padding: 1px 8px; font-size: 11.5px; margin-left: 4px; }

/* tables */
.tablewrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
table.grid { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.grid th, table.grid td { padding: 4px 8px; border-bottom: 1px solid var(--line-2); text-align: left; white-space: nowrap; vertical-align: middle; }
table.grid th { background: var(--th-bg); font-weight: 700; font-size: 11.5px; color: var(--ink); border-bottom: 1px solid var(--line); vertical-align: bottom; line-height: 1.2; }
table.grid th.group { text-align: center; text-decoration: underline; font-weight: 700; border-bottom: 0; padding-bottom: 0; }
table.grid th.group + th.group { border-left: 1px solid var(--line); }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid td.wrap { white-space: normal; }
table.grid td.desc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
table.grid td.mono { font-family: Consolas, "Courier New", monospace; font-size: 12px; }
table.grid tbody tr:hover { background: var(--row-hover); }
table.grid tr.expanded > td { font-weight: 700; background: var(--row-hover); }
table.grid tr.child td { background: var(--expand-bg); border-bottom-color: var(--line-2); color: var(--ink); font-size: 12px; }
table.grid tr.child td:first-child { position: relative; }
table.grid tr.child td.indent { padding-left: 22px; }
table.grid th.sortable a { color: inherit; }
table.grid th.sorted a { color: var(--brand); }
table.grid .arrow { margin-right: 2px; }
table.grid td.img { width: 36px; padding: 2px 6px; }
table.grid td.img img { width: 24px; height: 24px; object-fit: cover; border-radius: 2px; display: block; }
table.grid .expander { all: unset; cursor: pointer; display: inline-block; width: 13px; height: 13px; border: 1px solid var(--muted); border-radius: 2px; text-align: center; line-height: 11px; font-size: 12px; color: var(--muted); }
table.grid tr.bold td { font-weight: 700; }
table.grid td.warn { color: var(--warn); }
table.grid td.check { width: 28px; }
table.form td { vertical-align: top; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: var(--th-bg); }
.pill-committed, .pill-active, .pill-shipped, .pill-received, .pill-done { background: var(--ok-bg); color: var(--ok-ink); }
.pill-editable, .pill-draft, .pill-packed, .pill-running { background: var(--warn-bg); color: var(--warn-ink); }
.pill-cancelled, .pill-inactive, .pill-error { background: var(--bad-bg); color: var(--bad-ink); }
.pill-completed { background: var(--th-bg); color: var(--muted); }
.fulfil-ok { color: var(--ink); } .fulfil-back { color: #d97b00; } .fulfil-bad { color: var(--neg); }

/* pager */
.pager { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 12px; margin: 10px 0; flex-wrap: wrap; }
.pager .goto input { width: 64px; min-height: 26px; padding: 2px 6px; }

/* toast */
.toast { margin: 10px 0 0; padding: 9px 14px; border-radius: 4px; font-size: 13px; }
.toast.ok { background: var(--ok-bg); color: var(--ok-ink); border: 1px solid #b7e4c3; }
.toast.bad { background: var(--bad-bg); color: var(--bad-ink); border: 1px solid #f3b4b4; }

/* two-column create screens (quick stock change / transfer) */
.two-col { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.steps-card { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 0 0 16px; }
.steps-card .card-title { background: var(--card-head); padding: 8px 14px; font-size: 12px; letter-spacing: .6px; font-weight: 600; color: var(--muted); border-radius: 4px 4px 0 0; }
.steps { list-style: none; margin: 0; padding: 10px 24px 0 16px; }
.step { display: grid; grid-template-columns: 28px 1fr; gap: 14px; position: relative; padding-bottom: 14px; }
.step::before { content: ""; position: absolute; left: 13px; top: 30px; bottom: 0; width: 2px; background: var(--step); }
.step:last-child::before { display: none; }
.step .n { width: 28px; height: 28px; border-radius: 50%; background: var(--step); color: var(--step-ink); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.step.done .n, .step.active .n { background: #6f8fb0; }
.step h3 { font-size: 18px; font-weight: 400; margin: 2px 0 8px; }
.step input[type=text], .step input[type=number], .step input[type=date], .step select, .step textarea { width: 100%; }
.step .row3 { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; gap: 10px; align-items: end; }
.step .row3 .or { padding-bottom: 8px; color: var(--muted); }
.step label.sm { font-size: 12px; color: var(--muted); display: block; margin-bottom: 3px; }
.commit-row { text-align: center; padding: 10px 0 0; }
.recent { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.recent .card-title { display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-size: 16px; }
.recent .card-title .icon { width: 28px; height: 28px; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.recent .card-title .icon svg { width: 18px; height: 18px; }
.recent .item { margin: 0 14px 10px; border: 1px solid var(--line); border-radius: 4px; padding: 8px 12px; font-size: 12px; position: relative; }
.recent .item .line1 { font-size: 13px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 90px; }
.recent .item .meta { color: var(--ink); }
.recent .item .meta b { font-weight: 700; }
.recent .item .by { color: var(--muted); margin-top: 2px; }
.recent .item .cancel { position: absolute; right: 10px; top: 8px; }
.recent .more { text-align: center; padding: 10px; border-top: 1px solid var(--line-2); }
.recent .empty { padding: 20px; }

/* stock item chooser inside steps */
.stock-items { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.stock-items label { display: flex; gap: 10px; align-items: center; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; cursor: pointer; }
.stock-items label:hover { background: var(--row-hover); }
.stock-items .q { margin-left: auto; font-variant-numeric: tabular-nums; }
.stock-items .q.neg { color: var(--neg); }
.picker { position: relative; }
.picker-list { position: absolute; left: 0; right: 0; top: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 0 0 4px 4px; box-shadow: 0 6px 16px rgba(0,0,0,.14); z-index: 30; max-height: 320px; overflow: auto; }
.picker-list div { padding: 6px 10px; cursor: pointer; display: flex; gap: 10px; font-size: 12.5px; }
.picker-list div:hover, .picker-list div.sel { background: var(--row-hover); }
.picker-list .pid { font-weight: 600; min-width: 130px; }
.picker-list .q { margin-left: auto; color: var(--muted); }
.picker-list .nothing { color: var(--muted); cursor: default; }
.picked { margin-top: 6px; font-size: 12px; color: var(--muted); }

/* detail pages */
.detail-top { display: grid; grid-template-columns: 1.2fr 1fr 1fr 1.2fr; gap: 20px; padding: 10px 0 18px; border-bottom: 1px solid var(--line-2); }
.detail-top h4 { margin: 0 0 6px; font-weight: 400; color: var(--ink); }
.detail-top ul { list-style: none; margin: 0; padding: 0; }
.detail-top li { margin: 2px 0; }
.meta-right { text-align: right; color: var(--ink); font-size: 12px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 14px 18px 18px; margin: 16px 0; position: relative; }
.section > h2 { font-size: 18px; font-weight: 400; margin: -4px 0 10px; }
.section .help { position: absolute; right: 14px; top: 10px; font-size: 11.5px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 14px; }
.fields.wide { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; }
.field.span2 { grid-column: span 2; }
.field.span3 { grid-column: span 3; }
.field.span4 { grid-column: 1 / -1; }
.field .ro { padding: 7px 10px; background: var(--th-bg); border-radius: 4px; min-height: 32px; color: var(--muted); }
.supplier-row { display: grid; grid-template-columns: 90px repeat(6, 1fr); gap: 10px; align-items: end; margin-bottom: 8px; }
.supplier-row > b { padding-bottom: 8px; text-align: right; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; align-items: baseline; }
.kv .k { color: var(--muted); }
.status-line { display: flex; gap: 14px; align-items: center; margin: 8px 0 10px; flex-wrap: wrap; }
.doc-meta { color: var(--ink); font-size: 12.5px; margin: 4px 0; }
.chart { width: 100%; height: 160px; background: var(--panel); }
.sparkline text { font-size: 10px; fill: var(--muted); }
.sparkline rect { fill: var(--brand); }
.sparkline line { stroke: var(--line); }
.inline-form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .f { display: flex; flex-direction: column; gap: 3px; }
.inline-form label { font-size: 12px; color: var(--muted); }
.lines-table td input { min-height: 28px; padding: 3px 6px; }
.lines-table td input.q { width: 80px; }
.lines-table td select { min-height: 28px; padding: 3px 6px; }
.count-input { width: 90px; }
.count-input.changed { border-color: var(--warn-ink); background: var(--warn-bg); }
.count-input.saved { border-color: #2e844a; }
.notice-box { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid #f3d9b1; border-radius: 4px; padding: 10px 14px; margin: 10px 0; }
.info-box { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 10px 14px; margin: 10px 0; color: var(--muted); font-size: 12.5px; }

/* home */
.home { display: grid; grid-template-columns: 1fr 1.9fr 1fr; gap: 24px; padding: 24px 40px; }
.home h2 { font-size: 24px; font-weight: 400; margin: 0 0 10px; }
.home .panel { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 14px; }
.home .links { display: grid; grid-template-columns: 1fr; gap: 14px; }
.home .links.two { grid-template-columns: 1fr 1fr; }
.home .link { display: flex; gap: 10px; align-items: flex-start; }
.home .link .icon { width: 36px; height: 36px; border-radius: 4px; display: flex; align-items: center; justify-content: center; flex: none; }
.home .link .icon svg { width: 22px; height: 22px; }
.home .link a { font-size: 15px; }
.home .link .hint { font-size: 12px; color: var(--ink); }
.home .sep { border-top: 1px solid var(--line-2); grid-column: 1 / -1; margin: 2px 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 0 40px 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .v.neg { color: var(--neg); }

/* settings */
.settings { display: grid; grid-template-columns: 180px 1fr; gap: 24px; align-items: start; }
.settings .side a { display: block; padding: 6px 12px; border-radius: 14px; color: var(--link); margin-bottom: 4px; }
.settings .side a.active { background: var(--brand); color: #fff; }
.settings h2 { font-size: 20px; font-weight: 400; margin: 0 0 12px; }

/* columns chooser */
.col-chooser { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 6px 14px; padding: 12px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; margin-bottom: 12px; }
.col-chooser label { display: flex; gap: 6px; align-items: center; font-size: 12.5px; }
.col-chooser .foot { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding-top: 6px; border-top: 1px solid var(--line-2); }

/* login */
.login { max-width: 380px; margin: 70px auto; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 26px 28px; box-shadow: var(--shadow); }
.login .brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.login label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.login input { width: 100%; }
.login .btn { width: 100%; justify-content: center; margin-top: 14px; }
.login .err { color: var(--neg); margin: 8px 0 0; }
.login .prefs { display: flex; justify-content: space-between; margin-top: 14px; font-size: 12px; }
.login .prefs a { color: var(--muted); }
.login .prefs a.active { color: var(--ink); font-weight: 700; }
.pw { position: relative; }
.pw .eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--muted); cursor: pointer; }

@media (max-width: 1000px) {
  .two-col, .detail-top, .home, .settings { grid-template-columns: 1fr; }
  .home { padding: 16px; }
  .stats { margin: 0 0 14px; }
  .supplier-row { grid-template-columns: 1fr 1fr; }
  .supplier-row > b { grid-column: 1 / -1; text-align: left; }
}
@media (max-width: 700px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 4px; }
  .menus { flex-wrap: wrap; }
  .menu-btn { padding: 8px; }
  main { padding: 0 8px 16px; }
  .step .row3 { grid-template-columns: 1fr; }
}
@media print {
  .topbar, footer, .head-actions, .filters, .pager, .tabs, .toast { display: none !important; }
  main { padding: 0; }
}
