/* Layout: one working column; dense ledger table on desktop, stacked cards on phones.
   Ledger feel: monospaced figures, hairline rules, one emerald accent; marketplace badges in their own colours. */
:root {
  --bg: #f2f4f6; --surface: #ffffff; --surface-2: #f7f9fa; --ink: #111820; --muted: #4f5c69; --faint: #5f6b7d;
  --line: #e0e5ea; --line-strong: #cbd3da;
  --accent: #0a6b57; --accent-ink: #ffffff; --accent-soft: #e3f2ee;
  --good: #1a7a40; --good-soft: #e5f4ea; --warn: #8a5200; --warn-soft: #fbf0dc; --bad: #b42318; --bad-soft: #fdeceb;
  --ym: #ffd233; --ym-ink: #3a2e00; --oz: #1a5dff; --oz-ink: #ffffff;
  --edit: #fff7d6; --bar: #0f1a20; --bar-ink: #eef3f5; --toast-err: #b42318;
  --shadow: 0 1px 2px rgba(17, 24, 32, .06), 0 8px 24px rgba(17, 24, 32, .08);
  --f-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-num: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --r: 10px; --top-h: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1216; --surface: #141b21; --surface-2: #1a232a; --ink: #e6ecf0; --muted: #a3b0bb; --faint: #97a5b2;
    --line: #25303a; --line-strong: #34414c;
    --accent: #3cbf9c; --accent-ink: #062a21; --accent-soft: #173a31;
    --good: #57c785; --good-soft: #15301f; --warn: #f0b45a; --warn-soft: #3a2a10; --bad: #ff8a7f; --bad-soft: #3b1714;
    --ym: #ffd233; --ym-ink: #2a2100; --oz: #3567db; --oz-ink: #ffffff;
    --edit: #3a3412; --bar: #e9eff2; --bar-ink: #0f1a20; --toast-err: #b42318;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1216; --surface: #141b21; --surface-2: #1a232a; --ink: #e6ecf0; --muted: #a3b0bb; --faint: #97a5b2;
  --line: #25303a; --line-strong: #34414c;
  --accent: #3cbf9c; --accent-ink: #062a21; --accent-soft: #173a31;
  --good: #57c785; --good-soft: #15301f; --warn: #f0b45a; --warn-soft: #3a2a10; --bad: #ff8a7f; --bad-soft: #3b1714;
  --ym: #ffd233; --ym-ink: #2a2100; --oz: #3567db; --oz-ink: #ffffff;
  --edit: #3a3412; --bar: #e9eff2; --bar-ink: #0f1a20; --toast-err: #b42318;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 var(--f-ui); -webkit-font-smoothing: antialiased; overflow-x: hidden; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -.01em; text-wrap: balance; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; font-weight: 600; }
.muted { color: var(--muted); margin: 4px 0 0; max-width: 70ch; }
.num, .mono { font-family: var(--f-num); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* gate */
.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right)) 24px max(16px, env(safe-area-inset-left)); }
.gate-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.gate-sub { margin: -4px 0 4px; color: var(--muted); }
.form-error { color: var(--bad); margin: 0; min-height: 1.2em; }

/* header */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.top-inner { max-width: 1440px; margin: 0 auto; display: flex; align-items: center; gap: 16px; padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.brand-lg { font-size: 20px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.tabs { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.tab { border: 0; background: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); cursor: pointer; white-space: nowrap; font-weight: 500; }
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sync { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; color: var(--muted); white-space: nowrap; font-size: 13px; }
.sync:hover { border-color: var(--line-strong); color: var(--ink); }
.undo-btn { margin-left: auto; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 12px; min-height: 32px;
  cursor: pointer; color: var(--muted); white-space: nowrap; font-size: 13px; }
.undo-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.undo-btn:disabled { opacity: .5; cursor: default; }
.undo-btn + .sync { margin-left: 0; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.sync-dot.is-old { background: var(--warn); }
.sync-dot.is-run { background: var(--accent); animation: pulse 1s infinite alternate; }
.sync-dot.is-err { background: var(--bad); }
@keyframes pulse { to { opacity: .3; } }
/* «CRM обновилась»: part of the sticky header, so it stays in sight until the page is reloaded */
.update-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 12px; padding: 6px max(16px, env(safe-area-inset-right)) 6px max(16px, env(safe-area-inset-left));
  background: var(--warn-soft); color: var(--warn); border-top: 1px solid var(--line); font-size: 13px; font-weight: 500; text-align: center; }
#app.has-update { --top-h: 99px; }

.wrap { max-width: 1440px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right)) calc(120px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }

/* toolbar */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.search { flex: 1 1 260px; min-width: 0; height: 38px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); }
.select { height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); max-width: 100%; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 0 14px; height: 36px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.is-on { background: var(--ink); color: var(--surface); }
.hint { display: block; font-size: 12px; color: var(--faint); margin-top: 4px; font-weight: 400; }
.hint b { color: var(--muted); font-family: var(--f-num); }
.hint .link, .share-auto .link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0 2px; font-size: 12px; }
.share-auto { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; margin: 4px 0 14px; }
.msel { position: relative; }
.msel-btn { min-width: 170px; text-align: left; cursor: pointer; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.msel-btn::after { content: " \25BE"; color: var(--faint); }
.msel-btn.is-on { border-color: var(--accent); background: var(--accent-soft); }
.msel-panel { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; width: min(380px, calc(100vw - 32px)); max-height: min(70vh, 560px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r); box-shadow: var(--shadow); padding: 10px; }
.msel-q { width: 100%; margin-bottom: 8px; }
.msel-actions { display: flex; justify-content: space-between; gap: 6px; margin-bottom: 4px; }
.msel-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin: 10px 4px 2px; }
.msel-head .link { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.msel-list label { display: flex; gap: 8px; align-items: center; padding: 6px 4px; border-radius: 6px; cursor: pointer; }
.msel-list label:hover { background: var(--surface-2); }
.msel-list input { width: 16px; height: 16px; flex: none; }
.msel-list .cnt { margin-left: auto; color: var(--faint); font-family: var(--f-num); font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 12px; cursor: pointer; color: var(--muted); font-size: 13px; }
.chip.is-on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.summary { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.summary b { color: var(--ink); font-family: var(--f-num); font-weight: 600; }

.bulk { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; }
.bulk-label { color: var(--muted); }
.pct-input { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); padding-right: 8px; }
.pct-input input { width: 70px; border: 0; background: none; height: 34px; padding: 0 4px 0 10px; font-family: var(--f-num); text-align: right; min-width: 0; }
.pct-input span { color: var(--faint); }
.pct-input:focus-within { border-color: var(--accent); }
.pct-input input.is-edited { background: var(--edit); border-radius: 7px 0 0 7px; }      /* substituted, not saved yet */
.check { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-ghost { border-color: transparent; background: none; }
.btn-wide { width: 100%; height: 42px; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.icon-btn { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); width: 36px; height: 36px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }
.link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font: inherit; }

/* table */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; min-width: 980px; }
.grid th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tr.is-edited td { background: var(--edit); }
.grid .num { text-align: right; white-space: nowrap; }
.c-name { min-width: 300px; }
.pname { font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pmeta { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 3px; color: var(--faint); font-size: 12px; }
.pmeta .mono { font-size: 11.5px; }
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 4px; letter-spacing: .02em; }
.badge-ym { background: var(--ym); color: var(--ym-ink); }
.badge-oz { background: var(--oz); color: var(--oz-ink); }
.st { font-size: 11.5px; color: var(--warn); }
.cost-btn { border: 0; background: none; padding: 2px 0; cursor: pointer; font-family: var(--f-num); color: var(--ink); text-align: right; border-bottom: 1px dashed var(--line-strong); }
.cost-btn.is-missing { color: var(--warn); font-family: var(--f-ui); font-size: 13px; }
.price-in { width: 108px; height: 32px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); padding: 0 8px; text-align: right; font-family: var(--f-num); }
.price-in.is-edited { border-color: var(--warn); }
.price-in.is-invalid { border-color: var(--bad); background: var(--bad-soft); }
.price-in:focus, .price-in.is-edited:focus, .price-in.is-invalid:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.sub { display: block; color: var(--faint); font-size: 11.5px; font-family: var(--f-num); }
.sub.sent { color: var(--warn); }
.sub.stale { color: var(--warn); font-family: var(--f-ui); }
.sub.jump { color: var(--bad); font-weight: 600; }
.pill { display: inline-block; min-width: 58px; text-align: right; padding: 2px 8px; border-radius: 999px; font-family: var(--f-num); font-size: 12.5px; font-weight: 600; }
.pill-good { background: var(--good-soft); color: var(--good); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-none { color: var(--faint); background: var(--surface-2); }
.to-target { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 4px 8px; font-family: var(--f-num); cursor: pointer; color: var(--accent); }
.to-target:hover { border-color: var(--accent); }
.empty { padding: 40px 16px; text-align: center; color: var(--muted); }

/* wide screens: the table fits, so the header can stick under the top bar */
@media (min-width: 1200px) {
  .table-wrap { overflow: visible; }
  .grid th { position: sticky; top: var(--top-h); z-index: 5; }
}

/* phone: rows become cards */
@media (max-width: 860px) {
  input, select, textarea { font-size: 16px; }          /* no auto-zoom on iPhone */
  /* the tabs: one row that scrolls sideways, not two or three rows of header */
  .tabs { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; overscroll-behavior-x: contain; margin: 0 -4px; padding: 0 4px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; }
  .top-inner { flex-wrap: wrap; gap: 8px 12px; }
  .brand-name { display: none; }
  .sync { margin-left: auto; }
  .undo-btn + .sync { margin-left: 0; }
  .table-wrap { background: none; border: 0; overflow: visible; }
  .grid { min-width: 0; }
  .grid thead { display: none; }
  .grid, .grid tbody, .grid tr, .grid td { display: block; width: 100%; }
  .grid tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px; padding: 12px; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px 12px; }
  .grid tr.is-edited { background: var(--edit); }
  .grid tr.is-edited td { background: none; }
  .grid td { border: 0; padding: 0; min-width: 0; }
  .grid td.c-name { grid-column: 1 / -1; min-width: 0; }
  .grid .num { text-align: left; }
  .grid td[data-l]::before { content: attr(data-l); display: block; font-size: 11px; color: var(--faint); margin-bottom: 2px; font-family: var(--f-ui); }
  .price-in { width: 100%; }
  .bulk-label { flex-basis: 100%; }
  .toolbar .select { flex: 1 1 140px; }
  .toolbar .msel { flex: 1 1 140px; }
  .msel-btn { width: 100%; max-width: none; }
  .msel-panel { width: calc(100vw - 32px); }
  /* fingers: what is pressed often gets at least 40 px */
  .to-target, .cost-btn { min-height: 40px; min-width: 44px; display: inline-flex; align-items: center; }
  .to-target { padding: 0 12px; }
  .chip { min-height: 40px; padding: 0 14px; display: inline-flex; align-items: center; }
}

/* panels */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; margin-bottom: 14px; min-width: 0; }
.panel-head { margin-bottom: 12px; }
textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface-2); font-family: var(--f-num); font-size: 13px; resize: vertical; }
textarea:focus { border-color: var(--accent); outline: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.field { display: grid; gap: 6px; }
.field > span:first-child { font-size: 12.5px; color: var(--muted); }
.field input:not([type=checkbox]) { height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; background: var(--surface); min-width: 0; }
.field .pct-input input { height: 34px; border: 0; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px 18px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv .k { color: var(--muted); }
@media (max-width: 480px) { .kv { grid-template-columns: 1fr; gap: 2px; } .kv .k { margin-top: 6px; } }

/* cost list */
.cost-group { margin-bottom: 18px; }
.cost-group h3 { margin-top: 6px; }
.cost-table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; table-layout: fixed; }
.cost-table td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.cost-table td:nth-child(2) { width: 230px; }
.cost-table td:nth-child(3) { width: 110px; }
.cost-table td:nth-child(4) { width: 150px; }
.cost-table tr:last-child td { border-bottom: 0; }
.cost-table .ctitle { min-width: 0; overflow-wrap: anywhere; }
.cost-in { width: 120px; height: 32px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); padding: 0 8px; text-align: right; font-family: var(--f-num); }
.cost-in:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.cost-in.is-saved { border-color: var(--good); }
.linked { color: var(--faint); font-size: 12.5px; white-space: nowrap; }
.cost-scroll { overflow-x: auto; min-width: 0; }
@media (max-width: 640px) {
  .cost-table, .cost-table tbody, .cost-table tr, .cost-table td { display: block; width: 100%; }
  .cost-table tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .cost-table td, .cost-table td:nth-child(n) { padding: 0; border: 0; width: auto; }
  .cost-table .ctitle { grid-column: 1 / -1; }
  .linked { white-space: normal; }
}
.state { font-size: 12px; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.state-new { background: var(--accent-soft); color: var(--accent); }
.state-changed { background: var(--warn-soft); color: var(--warn); }
.state-same { background: var(--surface-2); color: var(--faint); }
.state-up { background: var(--bad-soft); color: var(--bad); font-family: var(--f-num); white-space: nowrap; }
.state-down { background: var(--good-soft); color: var(--good); font-family: var(--f-num); white-space: nowrap; }
.flag { color: var(--bad); font-size: 12.5px; overflow-wrap: anywhere; }

/* change bar */
.changebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 0 max(12px, env(safe-area-inset-right)) calc(12px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); pointer-events: none; }
.changebar-inner { pointer-events: auto; max-width: 760px; margin: 0 auto; background: var(--bar); color: var(--bar-ink); border-radius: 14px; padding: 10px 10px 10px 18px; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow); flex-wrap: wrap; }
.changebar-inner span { flex: 1; min-width: 140px; }
.btn-on-dark { color: var(--bar-ink); }

/* modal */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal-back { position: absolute; inset: 0; background: rgba(10, 16, 20, .45); }
.modal-card { position: relative; width: min(980px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); min-width: 0; }
.modal-card:focus { outline: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 20px; overflow: auto; min-width: 0; min-height: 0; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; align-items: center; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal-foot .note { margin-right: auto; color: var(--muted); font-size: 13px; max-width: 60ch; flex: 1 1 240px; }
@media (max-width: 640px) {
  .modal { padding: 0; place-items: end stretch; }
  /* dvh: the visible height, so the iPhone address bar does not cut off the title and the «×» */
  .modal-card { width: 100%; max-height: 92vh; max-height: 92dvh; border-radius: 16px 16px 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .modal-body { padding: 12px 14px; }
}
.ptable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ptable th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ptable td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ptable .num { text-align: right; white-space: nowrap; }
.warn-list { margin: 4px 0 0; padding: 0; list-style: none; color: var(--warn); font-size: 12.5px; }
.warn-list li::before { content: "! "; font-weight: 700; }
.page-notes li::before { content: "• "; }
.confirm { display: inline-flex; gap: 6px; align-items: center; margin-top: 6px; padding: 4px 8px; border-radius: 6px; background: var(--bad-soft); color: var(--bad); font-weight: 600; font-size: 12.5px; cursor: pointer; }
/* a row that needs a tick: on top of the list, with a red edge so it cannot be overlooked */
.ptable tr.needs-tick td { background: var(--bad-soft); }
.ptable tr.needs-tick td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.ptable tr.needs-tick .confirm { background: var(--surface); border: 1px solid var(--bad); }
.need-left { color: var(--bad); font-weight: 600; font-size: 13px; padding: 4px 2px; }
#import-result.is-stale .cost-scroll, #import-result.is-stale > .muted { opacity: .45; }
.arrow { color: var(--faint); padding: 0 4px; }
.callout { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; }
.callout-good { background: var(--good-soft); color: var(--good); }
.callout-bad { background: var(--bad-soft); color: var(--bad); }
.notes-only { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 10px 12px; margin: 0 0 10px; }
.notes-only summary { cursor: pointer; }
.notes-only > ul { margin: 8px 0 0; padding-left: 18px; color: var(--ink); }
.notes-only > ul > li { margin: 6px 0; }
.notes-only > ul > li.loss { color: var(--bad); }
.notes-only ul ul { margin: 2px 0 0; padding-left: 16px; color: var(--muted); }
.promo-list { list-style: none; margin: 4px 0 0; padding: 0; font-size: 12.5px; }
.promo-list li + li { margin-top: 2px; }
.promo-out { color: var(--bad); font-weight: 600; }
.promo-in { color: var(--good); font-weight: 600; }
.promo-note { color: var(--muted); }
.promo-set { color: var(--accent); font-weight: 600; }
.promo-keep { color: var(--warn); }
.promo-level { color: var(--ink); font-weight: 600; }
.follow-box { margin: 0 0 12px; color: var(--ink); }
.pick-list { display: grid; gap: 2px; max-height: 50vh; overflow: auto; margin-top: 10px; }
.cost-edit { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 4px 0 14px; }
.cost-edit label { display: block; font-weight: 600; margin-bottom: 8px; }
.cost-edit-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cost-edit-row .price-in { width: 140px; min-height: 40px; }
.cost-edit .muted { margin: 8px 0 0; }
.shared-list { margin-top: 8px; }
.shared-list summary { cursor: pointer; color: var(--muted); }
.shared-list ul { margin: 6px 0 0; padding-left: 18px; max-height: 160px; overflow: auto; }
.pick-title { margin: 0 0 6px; font-weight: 600; }
.pick { text-align: left; border: 1px solid transparent; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; min-width: 0; }
.pick > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.pick:hover { background: var(--surface-2); border-color: var(--line); }
.pick.is-current { border-color: var(--accent); background: var(--accent-soft); }

/* batches */
.batch { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 10px; }
.batch-head { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 8px 14px 8px 0; }
.batch-toggle { flex: 1 1 320px; min-width: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; border: 0; background: none; text-align: left; padding: 6px 14px; cursor: pointer; border-radius: var(--r); }
.batch-toggle:hover { background: var(--surface-2); }
.batch-toggle .when { font-family: var(--f-num); color: var(--muted); font-size: 13px; }
.batch-toggle .grow { flex: 1; min-width: 120px; }
.batch-actions { display: flex; gap: 6px; margin-left: auto; }
.batch-body { padding: 0 14px 12px; overflow-x: auto; }
.sstate { font-size: 12px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; font-weight: 600; }
.s-verified { background: var(--good-soft); color: var(--good); }
.s-sent, .s-sending, .s-unknown, .s-unverified { background: var(--warn-soft); color: var(--warn); }
.s-failed, .s-partial, .s-mismatch, .s-return { background: var(--bad-soft); color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; min-width: 0; }
.tile .t-k { color: var(--muted); font-size: 12.5px; }
.tile .t-v { font-family: var(--f-num); font-size: 20px; font-weight: 600; margin-top: 2px; overflow-wrap: anywhere; }
.tile .t-s { color: var(--faint); font-size: 12px; margin-top: 2px; }
.tile.is-warn .t-v { color: var(--warn); }
@media (max-width: 480px) { .tile { padding: 10px 12px; } .tile .t-v { font-size: 17px; } }
.oitems { margin: 0; padding: 0; list-style: none; }
.oitems li + li { margin-top: 3px; }
.s-cancelled { background: var(--surface-2); color: var(--faint); }
.s-ship { background: var(--warn-soft); color: var(--warn); }
.s-done { background: var(--good-soft); color: var(--good); }
.s-way { background: var(--accent-soft); color: var(--accent); }
.grid tr.is-cancelled td { color: var(--faint); }
.stock-in { width: 84px; }
.ocost + .ocost { margin-top: 6px; }
.order-cost { width: 104px; }

.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.events li { display: grid; grid-template-columns: 110px 1fr; gap: 12px; min-width: 0; }
.events li span { overflow-wrap: anywhere; min-width: 0; }
.events time { color: var(--faint); font-family: var(--f-num); font-size: 12px; }
.events .ev-error { color: var(--bad); }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 60; width: fit-content; max-width: calc(100% - 32px); margin: 0 auto; background: var(--bar); color: var(--bar-ink); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); }
.toast.is-error { background: var(--toast-err); color: #fff; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* phone: later rules for elements whose base rule comes after the phone block */
@media (max-width: 860px) {
  textarea { font-size: 16px; }                                   /* no auto-zoom on iPhone */
  .toast { bottom: calc(130px + env(safe-area-inset-bottom)); }   /* above the two-row change bar */
  .tab { padding: 8px 9px; }
  .confirm { min-height: 40px; padding: 6px 12px; }               /* a tick is pressed with a finger */
  .confirm input { width: 20px; height: 20px; }
  .order-cost, .stock-in { width: 100%; }                         /* fill the card cell, never wider than it */
}
