/* Stock management on the web. A desk-sized page that still works on a phone
 * held in front of a shelf: the tables fold into cards below 720px.
 *
 * The owner's page's tokens and brand green, so the two read as one shop.
 * Light by default, dark when the device asks. */
:root {
  --bg: #f2f4f6; --card: #ffffff; --line: #e2e7ec; --ink: #15202b; --muted: #66768a;
  --brand: #0f7b5f; --brand-2: #0a5c47; --on-brand: #ffffff; --soft: #e6f3ee; --press: #eef1f4;
  --ok: #158f5f; --warn: #c07414; --bad: #d23f3f;
  --ok-bg: #e3f5ec; --warn-bg: #fdf0dc; --bad-bg: #fce6e6;
  --shadow: 0 1px 2px rgba(20, 32, 43, .06), 0 4px 14px rgba(20, 32, 43, .05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1418; --card: #172028; --line: #253039; --ink: #e9eef2; --muted: #93a3b1;
    --brand: #23a684; --brand-2: #0f7b5f; --soft: #12302a; --press: #1d2831;
    --ok: #3ccf98; --warn: #f0b35a; --bad: #ff7070;
    --ok-bg: #143d2e; --warn-bg: #4a3213; --bad-bg: #4a1d1d;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
input, select, button { font: inherit; color: inherit; }

/* ── header ─────────────────────────────────────────────────────── */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); }
.brandline { display: flex; align-items: center; gap: 10px; flex: none; }
.brandline b { font-size: 17px; }
.brandline small { color: var(--muted); }
.mark { width: 32px; height: 32px; border-radius: 9px; background: var(--brand); color: var(--on-brand);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
.tabs { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button:hover { background: var(--press); }
.tabs button.active { background: var(--soft); color: var(--brand); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--brand); color: var(--on-brand); font-size: 12px; line-height: 20px; text-align: center; }
.acct { flex: none; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--brand); color: var(--on-brand); font-weight: 700; cursor: pointer; }

/* ── screens ────────────────────────────────────────────────────── */
.view { display: none; max-width: 1180px; margin: 0 auto; padding: 16px 20px 40px; }
.view.active { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card h3 { margin: 0 0 12px; font-size: 15px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.card h3 small { font-weight: 400; color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 13.5px; margin: 6px 0 0; }
.hint.pad { margin: 0; padding: 10px 16px; }
.hint.center { text-align: center; }
.hint.warn { color: var(--warn); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar .search { flex: 1 1 320px; }
.search { position: relative; display: flex; align-items: center; }
.search svg { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; padding: 10px 12px 10px 40px; }

input, select { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
input[type=number] { font-variant-numeric: tabular-nums; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(125px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); }
.tile small { display: block; color: var(--muted); font-size: 12.5px; }
.tile b { font-size: 18px; font-variant-numeric: tabular-nums; }
.tile b.warn { color: var(--warn); }

/* ── buttons ────────────────────────────────────────────────────── */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 16px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--press); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: none; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btnrow { display: flex; gap: 8px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.btnrow.end { justify-content: flex-end; }
.grow { flex: 1; }

/* ── tables ─────────────────────────────────────────────────────── */
.grid { width: 100%; border-collapse: collapse; }
.grid th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.grid .acts { text-align: right; white-space: nowrap; width: 1%; }
.grid .acts .btn + .btn { margin-left: 4px; }
.grid tbody tr.dim td { opacity: .55; }
.grid td small { display: block; color: var(--muted); font-size: 12.5px; }
.grid td.name b { font-weight: 600; }
.grid td.name { cursor: pointer; }
.grid td.name:hover b { color: var(--brand); text-decoration: underline; }
.lines input { width: 110px; text-align: right; }
.card:not(.flush) .grid th:first-child, .card:not(.flush) .grid td:first-child { padding-left: 0; }
.card:not(.flush) .grid th:last-child, .card:not(.flush) .grid td:last-child { padding-right: 0; }

.tag { display: inline-block; white-space: nowrap; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 6px; background: var(--press); color: var(--muted); vertical-align: middle; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.up { color: var(--ok); }
.down { color: var(--bad); }

/* ── history ────────────────────────────────────────────────────── */
.datef { display: flex; align-items: center; gap: 6px; margin: 0; }
.datef > span { margin: 0; font-size: 13px; color: var(--muted); }
.datef input { width: auto; }
.btnrow.center { justify-content: center; margin: 10px 0; }
.grid small.chg { display: block; color: var(--ink); font-size: 13px; }
.grid td.when { white-space: nowrap; color: var(--muted); font-size: 13px; }
.grid td.note { color: var(--muted); font-size: 13px; max-width: 280px; }
#historyTable td.by { white-space: nowrap; }
.grid td.change small:not(.chg) { display: inline; }
#view-history > .hint { margin: -4px 2px 12px; }

/* ── pickers: scan or search, then choose ───────────────────────── */
.picker { position: relative; margin-bottom: 12px; }
.suggest { position: absolute; z-index: 4; left: 0; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .18); max-height: 360px; overflow-y: auto; }
.suggest button { display: flex; width: 100%; gap: 12px; justify-content: space-between; align-items: center; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: none; padding: 9px 14px; cursor: pointer; }
.suggest button:last-child { border-bottom: 0; }
.suggest button:hover, .suggest button.hot { background: var(--soft); }
.suggest small { color: var(--muted); }
.suggest .none { padding: 12px 14px; color: var(--muted); }

.counting { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; padding: 14px; border-radius: 12px; background: var(--soft); margin-bottom: 12px; }
.counting .what { flex: 1 1 240px; }
.counting .what b { display: block; font-size: 17px; }
.counting .what small { color: var(--muted); }
.counting .sys { text-align: center; }
.counting .sys small { display: block; color: var(--muted); font-size: 12px; }
.counting .sys b { font-size: 22px; font-variant-numeric: tabular-nums; }
.counting input { width: 130px; font-size: 20px; text-align: right; }
label.narrow { display: block; max-width: 360px; }

/* ── forms ──────────────────────────────────────────────────────── */
label { display: block; margin-bottom: 12px; }
label > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
label > span small { font-weight: 400; color: var(--muted); }
label input, label select { width: 100%; }
/* align-items: end keeps side-by-side boxes level when one label wraps. */
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; align-items: end; }
.form3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }
.form2 .wide { grid-column: 1 / -1; }

.banner { padding: 9px 12px; border-radius: 10px; font-size: 14px; margin: 8px 0; }
.banner.err { background: var(--bad-bg); color: var(--bad); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }

/* ── dialog ─────────────────────────────────────────────────────── */
.dialog { position: fixed; inset: 0; z-index: 20; background: rgba(10, 16, 22, .5); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; overflow-y: auto; }
.dialogbox { background: var(--card); border-radius: 16px; padding: 18px 20px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dialogbox.wide { max-width: 860px; }
.dialogbox h2 { margin: 0; font-size: 19px; }
.dialogbox > .hint { margin: 4px 0 14px; }
.moves { max-height: 60vh; overflow-y: auto; }

/* ── toast ──────────────────────────────────────────────────────── */
.toast { position: fixed; z-index: 30; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(640px, calc(100% - 32px));
  padding: 11px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: 0 10px 30px rgba(0, 0, 0, .25); font-size: 14px; }
.toast.err { background: var(--bad); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }

/* ── sign in ────────────────────────────────────────────────────── */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.loginbox { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand .mark { width: 44px; height: 44px; font-size: 20px; border-radius: 12px; }
.brand h1 { margin: 0; font-size: 20px; }
.brand .hint { margin: 0; }

/* ── a tablet, or anything too narrow for the product table ─────── */
/* Below 900px the name column was squeezed to a word a line by the four
 * buttons beside it, so each product becomes a card: the name across the
 * top, the code under it, price / cost / on hand side by side, and the four
 * actions as one row of equal buttons big enough for a thumb. */
@media (max-width: 900px) {
  /* The shop's name and four tabs stop fitting on one line about here, so
   * the tabs take a row of their own. */
  .top { padding: 8px 16px; flex-wrap: wrap; gap: 8px; }
  .brandline { flex: 1; min-width: 0; }
  .brandline b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .tabs { order: 3; flex-basis: 100%; }
  .tabs button { flex: 1; }
  .view { padding: 12px 16px 40px; }
  #productTable thead { display: none; }
  #productTable, #productTable tbody, #productTable td { display: block; width: auto; }
  #productTable tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  #productTable tr:last-child { border-bottom: 0; }
  #productTable td { padding: 0; border: 0; min-width: 0; }
  #productTable td.name, #productTable td.code, #productTable td.acts { grid-column: 1 / -1; }
  #productTable td.name b { font-size: 16px; }
  #productTable td.code { color: var(--muted); font-size: 13px; }
  #productTable td.code small { display: inline; margin-left: 8px; }
  #productTable td.code::before { content: "Code "; }
  #productTable td.fig { text-align: left; font-size: 15px; }
  #productTable td.fig::before { content: attr(data-l); display: block; color: var(--muted); font-size: 12px; }
  #productTable td.acts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; text-align: left; }
  #productTable td.acts .btn { margin: 0; padding: 9px 4px; font-size: 13.5px; }
  #productTable tr.dim td.acts { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* History stacks the same way below 900: six columns squeezed a product
   * name to four lines at tablet width. When and what on one line, the
   * product under it, then what changed, then who and why. */
  #view-history .toolbar .search { flex-basis: 100%; }
  #view-history .toolbar #hKind { flex: 1 1 160px; }
  .datef { flex: 1 1 150px; }
  .datef input { flex: 1; min-width: 0; }
  #historyTable thead { display: none; }
  #historyTable, #historyTable tbody { display: block; }
  #historyTable tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  #historyTable tr:last-child { border-bottom: 0; }
  #historyTable td { display: block; padding: 0; border: 0; }
  #historyTable td.when { order: 1; }
  #historyTable td.kind { order: 2; }
  #historyTable td.name { order: 3; flex-basis: 100%; }
  #historyTable td.change { order: 4; flex-basis: 100%; }
  #historyTable td.by { order: 5; }
  #historyTable td.by::before { content: "By "; color: var(--muted); font-size: 12px; }
  #historyTable td.note { order: 6; max-width: none; }
}

/* ── a phone in front of a shelf ────────────────────────────────── */
@media (max-width: 720px) {
  /* Four tabs across a 320px screen: "Receive delivery" says "Receive". */
  .tabs { gap: 2px; }
  .tabs button { padding: 9px 4px; }
  .tabs .long { display: none; }
  /* Search on a row of its own, the filter and Add sharing the next: at 390
   * the search's 320px basis left the filter a sliver beside it. */
  .toolbar .search { flex-basis: 100%; }
  .toolbar select, .toolbar .btn { flex: 1; }
  .toolbar .btn, .toolbar select, .search input { min-height: 44px; }

  /* The five figures two to a row, so the products are on the first screen. */
  .tiles { grid-template-columns: 1fr 1fr; gap: 8px; }
  .tile { padding: 8px 12px; }
  .tile b { font-size: 16px; }
  .tile:last-child:nth-child(odd) { grid-column: 1 / -1; }

  /* The other tables' rows fold the same way, more simply. */
  .grid thead { display: none; }
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: auto; }
  .grid tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
  .card:not(.flush) .grid tr { padding: 10px 0; }
  .grid tr:last-child { border-bottom: 0; }
  .grid td { padding: 0 !important; border: 0; }
  .grid td.name { flex-basis: 100%; }
  .grid td.n { text-align: left; }
  .grid td[data-l]:not(.fig)::before { content: attr(data-l) " "; color: var(--muted); font-size: 12px; }
  .grid .acts { flex-basis: 100%; width: auto; text-align: left; padding-top: 4px !important; }
  .grid .acts .btn { padding: 8px 12px; }
  #productTable tr { display: grid; }
  #productTable td.acts { display: grid; }
  #productTable td.code::before { content: "Code "; }
  /* A delivery line: the name, what is on hand, then quantity and cost side
   * by side with their labels above, so both boxes are a thumb wide. */
  .grid.lines tr { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
  .grid.lines td.name, .grid.lines td.acts, .grid.lines td:nth-child(2) { grid-column: 1 / -1; }
  .grid.lines td:nth-child(3)::before, .grid.lines td:nth-child(4)::before { display: block; margin-bottom: 3px; }
  .grid.lines input { width: 100%; min-height: 44px; text-align: left; }
  .grid.lines td.acts { text-align: right; padding-top: 0 !important; }

  /* A history entry: when and what on one line, the product under it, then
   * what changed, then who and why. */
  .datef input { min-height: 44px; }
  #view-history .toolbar #hKind { flex-basis: 100%; }
  #productHistory td.change { flex-basis: 100%; }

  /* A dialog is a sheet from the bottom; its own buttons share the width. */
  .dialog { padding: 0; align-items: flex-end; }
  .dialogbox { border-radius: 16px 16px 0 0; max-height: 92vh; overflow-y: auto; padding: 16px; }
  .dialogbox .btnrow .grow { flex-basis: 100%; display: flex; gap: 8px; }
  .dialogbox .btnrow .grow:empty { display: none; }
  .dialogbox .btnrow > .btn { flex: 1; min-height: 44px; }
  .form2 { grid-template-columns: 1fr 1fr; }
  .counting input { width: 100%; }
  .counting label { flex: 1 1 120px; }
  .counting .btn { min-height: 44px; }
}
@media (max-width: 340px) {
  .form2 { grid-template-columns: 1fr; }
}
