/* Apex back office
   Ink sidebar, cool white desk, carbon-copy blue for actions, docket yellow only for
   "this needs you". Numbers are tabular so money lines up. */
/* Public Sans (SIL OFL), self-hosted so the back office works without outside CDNs */
@font-face { font-family: "Public Sans"; font-weight: 400; font-style: normal; font-display: swap; src: url("fonts/public-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 500; font-style: normal; font-display: swap; src: url("fonts/public-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 600; font-style: normal; font-display: swap; src: url("fonts/public-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 700; font-style: normal; font-display: swap; src: url("fonts/public-sans-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Public Sans"; font-weight: 800; font-style: normal; font-display: swap; src: url("fonts/public-sans-latin-800-normal.woff2") format("woff2"); }

:root {
  --ink: #1b2733;
  --ink-2: #2b3a4a;
  --desk: #f2f4f7;
  --paper: #ffffff;
  --rule: #d8dee6;
  --rule-2: #e9edf2;
  --text: #1b2733;
  --muted: #5d6a79;
  --carbon: #2747c9;
  --carbon-tint: #e8edfc;
  --docket: #f5c518;
  --docket-tint: #fff6cc;
  --profit: #157a4a;
  --profit-tint: #e3f4ea;
  --thin: #a86200;
  --thin-tint: #fdf0dc;
  --loss: #b8322a;
  --loss-tint: #fbe5e3;
  --radius: 6px;
  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font); font-size: 14px; line-height: 1.45; color: var(--text);
  background: var(--desk); font-variant-numeric: tabular-nums;
}
[x-cloak] { display: none !important; }
a { color: var(--carbon); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; line-height: 1.2; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 650; margin: 0 0 10px; }
h3 { font-size: 14px; font-weight: 650; margin: 0 0 8px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
:focus-visible { outline: 2px solid var(--carbon); outline-offset: 2px; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #cfd8e3; display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
.brand { color: #fff; font-weight: 800; font-size: 20px; letter-spacing: -0.02em; padding: 2px 10px 16px; }
.brand span { font-weight: 400; color: #8fa1b5; font-size: 13px; display: block; letter-spacing: 0; }
.side a { color: #cfd8e3; padding: 9px 10px; border-radius: var(--radius); display: block; font-weight: 500; }
.side a:hover { background: var(--ink-2); text-decoration: none; color: #fff; }
.side a.on { background: #fff; color: var(--ink); }
.side .foot { margin-top: auto; font-size: 12.5px; padding: 10px; color: #8fa1b5; }
.side .foot button { color: #cfd8e3; padding: 0; background: none; border: 0; font: inherit; cursor: pointer; text-decoration: underline; }
.main { padding: 24px 28px 60px; min-width: 0; }
.pagehead { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.pagehead .grow { flex: 1; }
.pagehead .sub { color: var(--muted); margin-top: 4px; }
.crumb { font-size: 13px; color: var(--muted); margin-bottom: 4px; display: block; }

/* ---------- controls */
button, .btn {
  font: inherit; font-weight: 600; border-radius: var(--radius); border: 1px solid var(--rule);
  background: var(--paper); color: var(--text); padding: 7px 13px; cursor: pointer; line-height: 1.3;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover { border-color: #b9c3cf; }
button.primary { background: var(--carbon); border-color: var(--carbon); color: #fff; }
button.primary:hover { background: #1f3aa8; }
button.danger { color: var(--loss); }
button.link { border: 0; background: none; padding: 0; color: var(--carbon); font-weight: 600; }
button.link.danger { color: var(--loss); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.sm { padding: 4px 9px; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--paper); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 7px 9px; width: 100%; font-variant-numeric: tabular-nums;
}
input:focus, select:focus, textarea:focus { border-color: var(--carbon); outline: none; box-shadow: 0 0 0 3px var(--carbon-tint); }
input.num { text-align: right; }
input.tight { padding: 5px 7px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; font-weight: 500; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.row > .fit, .row > button, .row > .btn { flex: 0 0 auto; min-width: 0; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.check input { width: auto; }

/* ---------- surfaces */
.panel { background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.panel.flush { padding: 0; overflow: hidden; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--rule); margin-bottom: 16px; overflow-x: auto; }
.tabs button { flex: 0 0 auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 9px 14px; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--carbon); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--rule); background: #fafbfc; }
td { padding: 9px 12px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7f9fc; }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }

/* ---------- chips */
.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--rule-2); color: var(--muted); white-space: nowrap; }
.chip.good { background: var(--profit-tint); color: var(--profit); }
.chip.thin { background: var(--thin-tint); color: var(--thin); }
.chip.bad { background: var(--loss-tint); color: var(--loss); }
.chip.blue { background: var(--carbon-tint); color: var(--carbon); }
.chip.wait { background: var(--docket-tint); color: #7a5b00; }
.up { color: var(--loss); font-weight: 600; }
.down { color: var(--profit); font-weight: 600; }

/* ---------- receiving lines: the carbon-copy edge tells you who matched the line */
table.lines { border-collapse: separate; border-spacing: 0; }
.lines tr > td:first-child { padding-left: 16px; }
.lines tr.m-supplier_code > td:first-child,
.lines tr.m-barcode > td:first-child,
.lines tr.m-description > td:first-child { box-shadow: inset 4px 0 0 var(--carbon); }
.lines tr.m-manual > td:first-child, .lines tr.m-new > td:first-child { box-shadow: inset 4px 0 0 var(--profit); }
.lines tr.m-none > td { background: var(--docket-tint); }
.lines tr.m-none > td:first-child { box-shadow: inset 4px 0 0 var(--docket); }
.lines tr.expand > td { padding-left: 16px; }
.lines tr.open td { border-bottom: 0; }
.lines .desc { font-weight: 600; }
.lines .meta { font-size: 12.5px; color: var(--muted); }
.lines input.tight { width: 82px; }
.lines .sugg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.lines .sugg button { font-weight: 500; font-size: 12.5px; padding: 3px 9px; background: var(--paper); }
.lines .sugg button b { font-weight: 650; }
.expand td { background: #f8f9fb; padding: 14px 16px 18px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* ---------- sizes editor */
.sizes th, .sizes td { padding: 6px 6px; }
.sizes input, .sizes select { padding: 5px 7px; }
.sizes .w-name { width: 96px; } .sizes .w-bc { width: 128px; } .sizes .w-pack { width: 56px; }
.sizes .w-meth { width: 106px; } .sizes .w-val { width: 70px; } .sizes .w-rnd { width: 108px; }
.sizes th { white-space: nowrap; }
.sizes .result { font-weight: 700; font-size: 15px; }
.sizes .err { color: var(--loss); font-size: 12px; }
.costline { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 10px; font-size: 13px; }
.costline b { font-size: 15px; }

/* ---------- recipe (link items) */
.recipe-total { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; margin-bottom: 16px; }
.recipe-total div { background: var(--paper); padding: 12px 14px; }
.recipe-total .label { font-size: 12.5px; color: var(--muted); }
.recipe-total .val { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }

/* ---------- picker */
.picker { position: relative; }
.picker .drop { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px); background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; box-shadow: 0 8px 24px rgba(27,39,51,.14); max-height: 300px; overflow: auto; }
.picker .opt { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.picker .opt:hover, .picker .opt.on { background: var(--carbon-tint); }
.picker .opt small { color: var(--muted); }

/* ---------- misc */
.notice { padding: 10px 12px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13.5px; }
.notice.warn { background: var(--docket-tint); border: 1px solid #f0dc8a; }
.notice.err { background: var(--loss-tint); border: 1px solid #f1c2bd; color: #7f1f19; }
.notice.ok { background: var(--profit-tint); border: 1px solid #b9e2cb; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 100; max-width: 420px; }
.toast.err { background: var(--loss); }
.overlay { position: fixed; inset: 0; background: rgba(27,39,51,.42); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--paper); border-radius: 10px; padding: 20px; width: min(560px, 100%); max-height: 90vh; overflow: auto; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.reading { display: flex; gap: 12px; align-items: center; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--carbon-tint); border-top-color: var(--carbon); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.login { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 16px; }
.login .card { background: var(--paper); border-radius: 12px; padding: 28px; width: min(380px, 100%); }
.login h1 { margin-bottom: 4px; }
.login form { display: grid; gap: 12px; margin-top: 18px; }

.totals { display: flex; gap: 28px; flex-wrap: wrap; }
.totals div .label { font-size: 12.5px; color: var(--muted); }
.totals div .val { font-size: 18px; font-weight: 700; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 0 10px 0 4px; }
  .brand span { display: none; }
  .side .foot { margin: 0 0 0 auto; padding: 0 6px; }
  .main { padding: 16px 12px 40px; }
  .table-wrap { overflow-x: auto; }
  .recipe-total { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- settings */
.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--rule); font-weight: 500; }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--carbon); color: #fff; }
.setting { display: grid; grid-template-columns: minmax(0, 1fr) 280px 160px; gap: 16px; align-items: center; padding: 12px 0 12px 12px; border-top: 1px solid var(--rule-2); border-left: 3px solid transparent; }
.setting:first-of-type { border-top: 0; }
.setting.set { border-left-color: var(--carbon); }
.setting .inherit { color: var(--muted); margin-top: 2px; }
.setting-reset { text-align: right; }
.savebar { position: sticky; bottom: 12px; display: flex; gap: 10px; align-items: center; justify-content: flex-end; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.savebar span { margin-right: auto; }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px 4px; }
.panel-head h2 { margin: 0; }
.code { font-size: 34px; font-weight: 800; letter-spacing: 0.08em; padding: 16px; background: var(--carbon-tint); color: var(--carbon); border-radius: 10px; margin: 8px 0; font-variant-numeric: tabular-nums; }
.modal.wide { width: min(820px, 100%); }
.permgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 28px; margin-top: 16px; }
.perm { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; }
.perm input { margin-top: 3px; }
.perm small { display: block; }
.perm.off { color: var(--muted); }
tr.flagged td { background: var(--loss-tint); }
@media (max-width: 860px) {
  .setting { grid-template-columns: 1fr; gap: 8px; }
  .setting-reset { text-align: left; }
  .permgrid { grid-template-columns: 1fr; }
}

/* ---------- reports */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--paper); border: 1px solid var(--rule); border-radius: 8px; padding: 14px 16px; }
.tile .label { font-size: 12.5px; color: var(--muted); }
.tile .val { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; margin-top: 2px; }
.tile .sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.tile.lead { border-top: 3px solid var(--carbon); }
.chartgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chartgrid > .panel { margin-bottom: 16px; min-width: 0; }
.chartwrap { position: relative; overflow-x: auto; }
.chart { width: 100%; display: block; }
.chart path { fill: var(--carbon); }
.chart .bar:hover path { fill: #1f3aa8; }
.chart .hit { fill: transparent; }
.chart .grid { stroke: var(--rule-2); stroke-width: 1; }
.chart .base { stroke: var(--rule); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.tip { position: absolute; pointer-events: none; transform: translate(-50%, calc(-100% - 10px)); background: var(--ink); color: #fff; padding: 6px 10px; border-radius: 6px; font-size: 12.5px; white-space: nowrap; z-index: 5; }
.share { display: flex; align-items: center; gap: 8px; }
.share i { display: block; height: 8px; background: var(--carbon); border-radius: 0 4px 4px 0; min-width: 2px; }
.share span { font-size: 12.5px; color: var(--muted); }
table.sortable th { cursor: pointer; user-select: none; }
.filters .seg { flex-wrap: wrap; }
.tile .val { white-space: nowrap; }
@media (max-width: 1000px) { .chartgrid { grid-template-columns: 1fr; } }
@media (max-width: 600px) {
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 10px 12px; }
  .tile .val { font-size: 18px; }
  .filters .seg button { padding: 6px 10px; font-size: 13px; }
}
