:root {
  --bg: #f6f6f4; --panel: #ffffff; --ink: #1d1d1b; --muted: #6b6b66; --line: #e3e2dd;
  --accent: #1f6f4a; --accent-ink: #ffffff; --warn: #a15c00; --warn-bg: #fff3df;
  --bad: #b3261e; --bad-bg: #fde8e6; --good: #1f6f4a; --good-bg: #e3f3ea; --info-bg: #e8eefb; --info: #2848a0;
  --radius: 8px; font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615; --panel: #1f1f1d; --ink: #ecebe6; --muted: #9c9b95; --line: #33322f;
    --accent: #4fb582; --accent-ink: #0d1a13; --warn: #f0b25a; --warn-bg: #3a2a12;
    --bad: #f28b82; --bad-bg: #3b1d1a; --good: #7fd3a6; --good-bg: #183327; --info-bg: #1d2640; --info: #9db4f2;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif; line-height: 1.45; }
a { color: inherit; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.pad { padding: 24px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.topbar { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--panel);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; text-decoration: none; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; padding: 6px 10px; border-radius: 6px; color: var(--muted); }
.topbar nav a.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.who { margin-left: auto; display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: .9rem; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 60px; }
.head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; display: block; }
.tile .label { color: var(--muted); font-size: .85rem; }
.tile .value { font-size: 1.6rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: .8rem; }
a.tile:hover { border-color: var(--accent); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 7px 12px; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; padding: 0; text-decoration: underline; color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
.search { flex: 1 1 220px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .8rem; background: var(--panel); position: sticky; top: 0; cursor: default; white-space: nowrap; }
th[data-sort] { cursor: pointer; }
th[data-sort]:hover { color: var(--ink); }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--bg); }
tr.dim td { opacity: .55; }
tfoot td { font-weight: 650; border-bottom: 0; }

.chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--bg); color: var(--muted); }
.chip.good { background: var(--good-bg); color: var(--good); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.chip.info { background: var(--info-bg); color: var(--info); }

.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }
.form label.wide { grid-column: 1 / -1; }
.form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: .92rem; }
.form input, .form select { width: 100%; }
.form label.check input { width: auto; margin: 0; }
.form label.check { align-self: end; padding-bottom: 8px; }

.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 90px 1fr 110px; gap: 10px; align-items: center; font-size: .88rem; }
.bar .track { background: var(--bg); border-radius: 4px; height: 18px; overflow: hidden; }
.bar .fill { background: var(--accent); height: 100%; border-radius: 4px; }

.lines input, .lines select { width: 100%; padding: 5px 6px; }
.lines td { padding: 5px 6px; }
.lines .qty { width: 70px; } .lines .cost { width: 90px; }
.lines [data-f="variant"] { min-width: 260px; }
.lines [data-f="currency"] { min-width: 72px; }
.lines [data-f="product_id"] { min-width: 200px; max-width: 260px; }
.lines [data-f="price_basis"] { min-width: 150px; }

.login { max-width: 380px; margin: 12vh auto; }
.login input { width: 100%; margin: 10px 0; }
.note { font-size: .85rem; color: var(--muted); }
.warnbox { background: var(--warn-bg); color: var(--warn); border-radius: 6px; padding: 8px 12px; font-size: .88rem; margin-bottom: 12px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 8px; font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.error { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .bar { grid-template-columns: 60px 1fr 90px; }
  .topbar { gap: 8px; }
}
