:root {
  --bg: #f6f4f0;
  --card: #ffffff;
  --text: #22201c;
  --muted: #6f6a62;
  --line: #e4dfd6;
  --brand: #8a5a2b;
  --brand-ink: #ffffff;
  --in: #1f7a46;
  --in-bg: #e5f4ea;
  --out: #b3401f;
  --out-bg: #fbe9e3;
  --rez: #8a5a00;
  --rez-bg: #fff3d4;
  --adj: #4a5a8a;
  --adj-bg: #e8ecf7;
  --group: #efe9df;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18; --card: #24221f; --text: #ece8e1; --muted: #a39d93; --line: #3a3732;
    --brand: #c48a4f; --brand-ink: #1b1a18;
    --in: #6fcf97; --in-bg: #1f3a2a; --out: #f09a7e; --out-bg: #3d2520;
    --rez: #f2c46b; --rez-bg: #3b311b; --adj: #a5b4e8; --adj-bg: #262c40; --group: #2d2a26;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }

.top { display: flex; align-items: center; gap: 1.2rem; padding: .6rem 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; color: var(--text); }
.top nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.top nav a { padding: .35rem .7rem; border-radius: 6px; color: var(--text); }
.top nav a.on, .top nav a:hover { background: var(--group); text-decoration: none; }
.who { margin-left: auto; color: var(--muted); font-size: .9em; }
.badge { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 9px; background: var(--rez-bg); color: var(--rez); font-size: .8em; font-weight: 700; text-align: center; }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.flash { padding: .6rem .9rem; border-radius: var(--radius); background: var(--in-bg); color: var(--in); margin-bottom: 1rem; }
.flash.err { background: var(--out-bg); color: var(--out); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; margin: 0 0 1rem; }
.card.narrow { max-width: 380px; margin: 3rem auto; }
.card.mid { max-width: 760px; }
label { display: block; margin-bottom: .8rem; font-size: .9em; color: var(--muted); }
label.check { display: inline-flex; gap: .4rem; align-items: center; margin: 0; color: var(--text); }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .5rem .6rem; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
input[type=checkbox], input[type=radio] { display: inline; width: auto; margin: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.grid2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 1rem; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0 1rem; }
.seg { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.seg label { margin: 0; padding: .5rem .8rem; border: 1px solid var(--line); border-radius: 6px; color: var(--text); display: flex; gap: .4rem; align-items: center; cursor: pointer; }
.seg label:has(input:checked) { border-color: var(--brand); background: var(--group); }

.btn { display: inline-block; padding: .5rem .9rem; border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.in { background: var(--in-bg); color: var(--in); border-color: transparent; font-weight: 600; }
.btn.out { background: var(--out-bg); color: var(--out); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--out); }
.btn.small { padding: .2rem .5rem; font-size: .85em; }
.btn.ghost { border-color: transparent; background: none; }
form.inline { display: inline; }
.row-actions { display: flex; justify-content: space-between; gap: 1rem; }

.filters { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: .6rem; }
.filters input[type=search] { flex: 1 1 260px; margin: 0; }
.filters select, .filters input[type=date] { width: auto; margin: 0; }
.filters label { display: flex; align-items: center; gap: .3rem; margin: 0; }
.spacer { flex: 1; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .4rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8em; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--card); position: sticky; top: 0; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.zero { color: var(--muted); opacity: .5; }
td.neg, .neg { color: var(--out); }
td.pos { color: var(--in); }
td.rez { color: var(--rez); font-weight: 600; }
td.rez a { color: inherit; text-decoration: underline dotted; }
a.tile { color: inherit; text-decoration: none; }
a.tile.rez:hover { outline: 2px solid var(--rez); }
td.unit { color: var(--muted); font-size: .85em; }
td.brand { white-space: nowrap; font-size: .9em; }
td.brand a { color: var(--muted); }
.sku { font-family: ui-monospace, Consolas, monospace; font-size: .92em; }
tr.group td { background: var(--group); font-weight: 600; font-size: .85em; padding: .35rem .6rem; }
table.stock tr.row { cursor: pointer; }
table.stock tr.row:hover td { background: var(--bg); }
tr.is-rez td { background: color-mix(in srgb, var(--rez-bg) 60%, transparent); }
tr.late td { background: var(--out-bg); }

.tag { display: inline-block; padding: .05rem .45rem; border-radius: 4px; font-size: .8em; font-weight: 600; white-space: nowrap; }
.tag.in { background: var(--in-bg); color: var(--in); }
.tag.out { background: var(--out-bg); color: var(--out); }
.tag.rezervets { background: var(--rez-bg); color: var(--rez); }
.tag.adj { background: var(--adj-bg); color: var(--adj); }

.crumbs { margin: 0 0 .4rem; font-size: .9em; color: var(--muted); }
.head { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; }
.note { background: var(--rez-bg); padding: .5rem .8rem; border-radius: 6px; }
.tiles { display: flex; gap: .7rem; flex-wrap: wrap; margin: 1rem 0; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem 1rem; min-width: 120px; }
.tile span { display: block; font-size: .8em; color: var(--muted); text-transform: uppercase; }
.tile b { display: block; font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); }
.tile.total { border-color: var(--brand); }
.tile.rez { background: var(--rez-bg); border-color: transparent; }
.tile.rez b, .tile.rez span { color: var(--rez); }
.tile.neg b { color: var(--out); }
details.secret { margin: 1.4rem 0 0; }
details.secret > summary { cursor: pointer; font-weight: 600; font-size: 1.1rem; padding: .4rem 0; list-style: none; }
details.secret > summary::-webkit-details-marker { display: none; }
details.secret > summary::before { content: "+"; display: inline-block; width: 1.4em; height: 1.4em; margin-right: .5rem; text-align: center; line-height: 1.35em; border: 1px solid var(--line); border-radius: 4px; background: var(--card); }
details.secret[open] > summary::before { content: "−"; }
details.secret[open] > summary .small { display: none; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.pager { display: flex; gap: .5rem; justify-content: center; }

@media (max-width: 700px) {
  .grid2, .grid4 { grid-template-columns: 1fr; }
  .head { flex-direction: column; }
  .who { margin-left: 0; width: 100%; }
  th, td { padding: .35rem .4rem; }
  .card.narrow { margin: 1.5rem auto; }
}
