:root {
  --brand: #c80000; --brand-ink: #fff; --brand-soft: #fbeaea; --brand-text: #c80000;
  --bg: #f5f5f6; --panel: #fff; --text: #1e2024; --muted: #6a6f78; --line: #e7e8eb; --line-strong: #d5d7dc; --hover: #f6f6f8;
  --ok: #17753f; --ok-bg: #e5f4ea; --warn: #a55300; --warn-bg: #fdf0dd; --bad: #c80000; --bad-bg: #fbe8e8;
  --shadow: 0 1px 2px rgba(20, 22, 28, .05);
  --r: 10px; color-scheme: light;
}
/* Dark palette: used when the user picks dark, or when they haven't picked and the system prefers dark. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --brand: #e01f1f; --brand-ink: #fff; --brand-soft: #35191b; --brand-text: #ff8078;
    --bg: #131416; --panel: #1b1c1f; --text: #ececee; --muted: #9a9ea8; --line: #2a2c31; --line-strong: #3a3d44; --hover: #23252a;
    --ok: #5fcf8d; --ok-bg: #15301f; --warn: #f1a54f; --warn-bg: #362813; --bad: #ff6b60; --bad-bg: #3a1a18;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme=dark] {
    --brand: #e01f1f; --brand-ink: #fff; --brand-soft: #35191b; --brand-text: #ff8078;
    --bg: #131416; --panel: #1b1c1f; --text: #ececee; --muted: #9a9ea8; --line: #2a2c31; --line-strong: #3a3d44; --hover: #23252a;
    --ok: #5fcf8d; --ok-bg: #15301f; --warn: #f1a54f; --warn-bg: #362813; --bad: #ff6b60; --bad-bg: #3a1a18;
    --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; line-height: 1.2; margin: 0; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 14px; font-weight: 650; }
p { margin: 0 0 12px; }

/* ---- layout: left sidebar + content ---- */
.app { display: flex; min-height: 100vh; }
.side { width: 240px; flex: none; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 18px 12px 14px;
  background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 2px 10px 18px; color: var(--text); font-weight: 700; font-size: 15px; }
.side .brand:hover { text-decoration: none; }
.side .brand img { height: 28px; width: auto; display: block; flex: none; }
.side .menu { display: flex; flex-direction: column; gap: 2px; }
.side .foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; padding-top: 12px; border-top: 1px solid var(--line); }
.side .item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; cursor: pointer;
  border: 0; background: none; width: 100%; text-align: left; min-height: 0; font-size: 14px; position: relative; }
.side .item:hover { background: var(--hover); color: var(--text); text-decoration: none; }
.side .item.on { background: var(--brand-soft); color: var(--brand-text); }
.side .item.on::before { content: ''; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.side .item svg { width: 19px; height: 19px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side .account { display: flex; align-items: center; gap: 10px; padding: 10px 8px 2px; }
.side .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.side .who { min-width: 0; flex: 1; line-height: 1.25; }
.side .who b { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .who span { font-size: 12px; color: var(--muted); }
.side .account button { padding: 6px; min-height: 0; border: 0; background: none; color: var(--muted); border-radius: 8px; display: grid; place-items: center; }
.side .account button:hover { background: var(--hover); color: var(--text); }
.side .account svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.content { flex: 1; min-width: 0; }
main { max-width: 1680px; margin: 0 auto; padding: 32px 36px 72px; container-type: inline-size; }
@media (max-width: 1000px) {
  .side { width: 64px; padding-left: 8px; padding-right: 8px; align-items: stretch; }
  .side .brand { padding: 2px 4px 16px; justify-content: center; }
  .side .brand span, .side .item .label, .side .who { display: none; }
  .side .item { justify-content: center; padding: 11px 0; }
  .side .item.on::before { left: -8px; }
  .side .account { flex-direction: column; padding: 10px 0 0; gap: 6px; }
  main { padding: 24px 20px 56px; }
}
@media (max-width: 560px) { main { padding: 18px 12px 48px; } }
.head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 24px; }
.head .sub { color: var(--muted); margin-top: 2px; }
.stack > * + * { margin-top: 20px; }
.stack > :empty { display: none; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 20px; box-shadow: var(--shadow); }
.panel > :last-child { margin-bottom: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid2.tight { gap: 0 16px; }
.grid2.wide { grid-template-columns: 1.2fr 1fr; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 220px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.mt { margin-top: 16px; }
.divider { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* ---- forms ---- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=search], input[type=number], input[type=password], input[type=date], select, textarea {
  background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 12px; width: 100%; min-height: 38px;
}
input::placeholder { color: var(--muted); opacity: .8; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
input[type=number] { width: 84px; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }
select { width: auto; padding-right: 30px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
label.inline { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }

button { border: 1px solid var(--line-strong); background: var(--panel); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; min-height: 36px; }
button:hover { background: var(--hover); }
button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-bg); }
button.small { padding: 4px 10px; font-size: 12px; min-height: 28px; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--hover); color: var(--text); }
button:disabled { opacity: .45; cursor: default; }

.seg { display: inline-flex; background: var(--hover); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 7px; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td, tr:last-child > td { border-bottom: 0; }
table.click tbody tr { cursor: pointer; }
table.click tbody tr:hover { background: var(--hover); }
.scroll { overflow-x: auto; margin: 0 -12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sub { font-size: 12px; color: var(--muted); }

.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--hover); color: var(--muted); white-space: nowrap; line-height: 1.5; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.bti { background: var(--brand-soft); color: var(--brand-text); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.neg { color: var(--bad); font-weight: 700; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); color: var(--muted); }
.stat b { display: block; font-size: 28px; line-height: 1.1; color: var(--text); margin-bottom: 2px; letter-spacing: -.02em; }
.stat.alert b { color: var(--bad); }

/* ---- type-ahead ---- */
.ta { position: relative; }
.ta-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px; margin-top: 4px;
  box-shadow: 0 12px 32px rgba(0,0,0,.18); max-height: 380px; overflow-y: auto; padding: 4px; }
.ta-item { padding: 9px 12px; cursor: pointer; border-radius: 7px; display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.ta-item.on, .ta-item:hover { background: var(--hover); }
.ta-empty { padding: 12px; color: var(--muted); }

/* ---- orders ---- */
.order-card { border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 14px; overflow: hidden; background: var(--panel); }
.order-card:last-child { margin-bottom: 0; }
.order-card > header { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; background: var(--hover); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.order-card table td { padding: 10px 16px; }
.order-card header a { color: var(--text); }
.order-card header a:hover { color: var(--brand-text); }
.order-card .note { padding: 8px 16px 10px; border-top: 1px solid var(--line); }
tr.shipped td { color: var(--muted); }
.shipctl { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }
.shipctl input { width: 64px; padding: 4px 8px; min-height: 30px; }
.bticard { display: flex; gap: 12px; align-items: center; padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--brand-soft); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 9px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); color: #fff; }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--text); padding: 24px; width: min(680px, 94vw); max-height: 90vh; box-shadow: 0 24px 64px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 12, 16, .55); }
dialog h2 { font-size: 17px; }
dialog.wide { width: min(980px, 95vw); padding: 28px; }

.login { max-width: 360px; margin: 12vh auto 0; padding: 28px; }
.login .logo { display: block; height: 48px; margin: 0 0 20px; }
.err-text { color: var(--bad); margin: 0 0 12px; }

@media (max-width: 700px) { .panel { padding: 16px; } }
}

/* ---- dashboard tables ---- */
table.fixed { table-layout: fixed; }
table.fixed td { overflow-wrap: anywhere; }
.order-card table.fixed td { padding: 10px 8px; }
.order-card table.fixed td:first-child, .order-card table.fixed th:first-child { padding-left: 16px; }
.order-card table.fixed td:last-child { padding-right: 16px; }
.order-card table.fixed td.num { text-align: center; }
table.needed td.num, table.needed th.num { padding-left: 6px; padding-right: 6px; }

/* ---- item popup ---- */
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.dlg-head h2 { font-size: 20px; margin: 0 0 8px; letter-spacing: -.01em; }
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px; }
.tile { background: var(--hover); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.tile-v { font-size: 22px; font-weight: 700; line-height: 1.2; letter-spacing: -.01em; overflow-wrap: anywhere; }
.dlg-grid { display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: start; }
dialog h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
dl { margin: 0; }
.kv { display: grid; grid-template-columns: 124px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.grid3 input[type=number] { width: 100%; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 760px) { .tiles { grid-template-columns: repeat(2, 1fr); } .dlg-grid, .grid3 { grid-template-columns: 1fr; } }

.chart { position: relative; margin-top: 4px; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-svg .grid { stroke: var(--line); stroke-width: 1; }
.chart-svg .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart-svg .tick { fill: var(--muted); font-size: 11px; }
.chart-svg .peak { fill: var(--text); font-size: 11px; font-weight: 600; }
.chart-svg .empty { fill: var(--muted); font-size: 13px; }
.chart-svg .bar { fill: var(--brand); transition: filter .1s; }
.chart-svg .bar.hot { filter: brightness(1.2); }
.chart-svg .hit { cursor: default; }
.chart-tip { position: absolute; transform: translate(-50%, calc(-100% - 8px)); background: var(--text); color: var(--bg); padding: 6px 10px; border-radius: 7px; pointer-events: none; white-space: nowrap; font-size: 12px; z-index: 2; }
.chart-tip .sub { color: inherit; opacity: .7; }

.notice { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.notice.warn { background: var(--warn-bg); border-color: transparent; color: var(--warn); }
.notice.warn a { color: inherit; text-decoration: underline; font-weight: 600; }
input[type=time] { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; padding: 9px 12px; min-height: 38px; }
input[type=time]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
label.check { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.col { display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

/* ---- dashboard ---- */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(460px, 1fr)); gap: 14px; }
.cards .order-card { margin: 0; }
.stats { grid-template-columns: repeat(4, 1fr); }
@container (max-width: 1050px) { .dash-grid { grid-template-columns: 1fr; } }
@container (max-width: 700px) { .stats { grid-template-columns: repeat(2, 1fr); } .cards { grid-template-columns: 1fr; } }
@container (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.chartpanel .chart { margin-top: 8px; }
.narrow { max-width: 920px; }

/* ---- stock rows / locations ---- */
tr.negrow td { background: color-mix(in srgb, var(--bad) 6%, transparent); }
table.click tbody tr.negrow:hover td { background: color-mix(in srgb, var(--bad) 14%, transparent); }
.loc { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.loc i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,.28); flex: none; }
.loc.white i, .loc.black i { box-shadow: inset 0 0 0 1px var(--line-strong); }

dialog .kv { grid-template-columns: 130px 1fr; }
.tile-v .loc { font-size: 18px; }

/* ---- price list grid ---- */
.grid-wrap { max-height: calc(100vh - 330px); min-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); outline: none; }
.grid-wrap:focus-within { border-color: var(--line-strong); }
table.sheet { border-collapse: separate; border-spacing: 0; width: max-content; table-layout: fixed; font-size: 13px; }
table.sheet td, table.sheet th { padding: 5px 8px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--panel); text-transform: none; letter-spacing: 0; }
table.sheet td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.sheet td.err { color: var(--bad); font-weight: 600; }
table.sheet td.sel { outline: 2px solid var(--brand); outline-offset: -2px; }
table.sheet td.editing { padding: 0; }
table.sheet thead th, table.sheet thead td { position: sticky; top: 0; z-index: 3; background: var(--hover); font-weight: 600; color: var(--text); }
table.sheet thead tr:nth-child(2) th, table.sheet thead tr:nth-child(2) td { color: var(--muted); font-weight: 500; }
table.sheet th.rn { position: sticky; left: 0; z-index: 2; background: var(--hover); color: var(--muted); font-size: 11px; font-weight: 500; text-align: right; padding-left: 22px; }
table.sheet thead th.rn { z-index: 4; }
table.sheet tr.section td { font-weight: 700; background: color-mix(in srgb, var(--hover) 60%, var(--panel)); }
table.sheet tr.prod:hover td { background: var(--hover); }
table.sheet tr.flash td { animation: flash 2.4s ease-out; }
@keyframes flash { from { background: var(--brand-soft); } to { background: var(--panel); } }
.cell-input { width: 100%; border: 0; border-radius: 0; padding: 5px 8px; min-height: 0; font: inherit; background: var(--panel); box-shadow: inset 0 0 0 2px var(--brand); }
.cell-input:focus { box-shadow: inset 0 0 0 2px var(--brand); }
.fbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.fbar .addr { min-width: 54px; text-align: center; font-weight: 600; font-size: 12px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--hover); }
.fbar .fxl { color: var(--muted); font-style: italic; font-size: 13px; }
.fbar .fx { flex: 1; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.linkdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 0; padding: 0; min-height: 0; background: var(--muted); vertical-align: middle; cursor: pointer; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); }
p .linkdot { position: static; transform: none; cursor: default; margin: 0 2px 1px 8px; }
.linkdot.matched { background: var(--ok); }
.linkdot.suggested { background: #e0a020; }
.linkdot.unmatched { background: transparent; box-shadow: inset 0 0 0 2px var(--muted); }
.linkdot.not_stocked { background: transparent; box-shadow: inset 0 0 0 2px var(--line-strong); opacity: .7; }
table.sheet th.rn { position: sticky; }
.workings { margin-bottom: 16px; }
.pricecard { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--hover); }
.pricecard .kv { padding: 6px 0; grid-template-columns: 120px 1fr; }
.seg.tabs button { white-space: nowrap; }

/* ---- product page ---- */
.skuopt { text-align: left; padding: 16px; border-radius: 10px; }
.skuopt b { font-size: 16px; }
.pinput { max-width: 150px; text-align: right; font-variant-numeric: tabular-nums; }
table.calc td { padding: 7px 10px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px; overflow-wrap: anywhere; }
.pricecard, .pricing-block { }
