/* Tabak — one system for phone (Telegram Mini App) and desktop browser.
   Colours come from the Telegram theme at runtime (themeParams); the html classes below stand in for it.
   Layout follows width, not the client: under 1024px one column with a bottom tab bar and MainButton,
   from 1024px a side navigation, tables and side panels. */

html {
  --page: #efeff4; --section: #ffffff; --fg: #000000; --muted: #6d6d72; --line: #e5e5ea; --field: #8a8a8e;
  --chip: #e9e9ee; --primary: #2481cc; --on-primary: #ffffff; --link: #1f6fb2; --ring: #2481cc;
  --danger: #c4161c; --danger-bg: #fdecec; --ok: #17663a; --scrim: rgba(0, 0, 0, .45);
  --st-blue-bg: #e0ecff; --st-blue: #1e4fae;
  --st-amber-bg: #fdf0d5; --st-amber: #8a4b00;
  --st-teal-bg: #d7f5ef; --st-teal: #0f5e52;
  --st-green-bg: #dcf5e3; --st-green: #17663a;
  --st-red-bg: #fde4e4; --st-red: #a11d1d;
  --st-gray-bg: #ececee; --st-gray: #48484d;
  --nav-w: 232px;
  color-scheme: light;
}
html.t-light {
  --page: #f4f4f5; --fg: #0a0a0a; --muted: #636366; --line: #e4e4e7; --chip: #ececee;
  --primary: #171717; --link: #0a0a0a; --ring: #1d4ed8;
}
html.t-dark {
  --page: #000000; --section: #1c1c1e; --fg: #ffffff; --muted: #98989f; --line: #38383a; --field: #6e6e73;
  --chip: #2c2c2e; --primary: #3e88f7; --link: #6aaeff; --ring: #6aaeff; --danger: #ff6b6b; --danger-bg: #3a1a1b;
  --ok: #86e0a2; --scrim: rgba(0, 0, 0, .6);
  --st-blue-bg: #1d2f4f; --st-blue: #9cc3ff;
  --st-amber-bg: #3d2e12; --st-amber: #f5c86b;
  --st-teal-bg: #12352f; --st-teal: #7fe0cc;
  --st-green-bg: #163521; --st-green: #86e0a2;
  --st-red-bg: #44191a; --st-red: #ff9b9b;
  --st-gray-bg: #2c2c2e; --st-gray: #c7c7cc;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { overflow-x: clip; }
body {
  margin: 0; min-height: 100dvh; background: var(--page); color: var(--fg);
  font-family: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 15px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--link); }
:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }
::selection { background: var(--st-blue-bg); }
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
ul, ol { list-style: none; padding: 0; }
button, input, select { font: inherit; color: inherit; }

/* icons */
.i { width: 20px; height: 20px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i-s { width: 16px; height: 16px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* shell: phone = column + bottom bars; desktop = side nav + content */
.shell { min-height: 100dvh; display: flex; flex-direction: column; }
.content { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
.nav { position: sticky; bottom: 0; z-index: 20; order: 2; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); padding: 4px 8px calc(6px + env(safe-area-inset-bottom, 0px)); background: var(--section); border-top: 1px solid var(--line); }
.nav .brand, .nav .nav-foot { display: none; }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 52px; border-radius: 10px; color: var(--muted); font-size: 12px; text-decoration: none; }
.nav a[aria-current="page"] { color: var(--primary); font-weight: 500; }
html.t-light .nav a[aria-current="page"] { color: var(--fg); }
.mainbar { position: sticky; bottom: 0; z-index: 21; display: flex; flex-direction: column; gap: 6px; padding: 8px 16px calc(12px + env(safe-area-inset-bottom, 0px)); background: var(--section); border-top: 1px solid var(--line); }
.shell:has(.nav) .mainbar { bottom: calc(63px + env(safe-area-inset-bottom, 0px)); }
.mainbtn { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 50px; padding: 0 18px; border: 0; border-radius: 12px; background: var(--primary); color: var(--on-primary); font-weight: 600; text-decoration: none; cursor: pointer; }
a.mainbtn { color: var(--on-primary); }
.mainbtn.split { justify-content: space-between; }
.mainbtn[aria-disabled="true"] { background: var(--chip); color: var(--muted); cursor: default; }
.mainbar .hint { font-size: 13px; color: var(--muted); text-align: center; }
.desk { display: none !important; }

@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); }
  .nav { position: sticky; top: 0; bottom: auto; order: 0; height: 100dvh; display: flex; flex-direction: column; gap: 2px; padding: 18px 12px; border-top: 0; border-right: 1px solid var(--line); }
  .nav .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 600; font-size: 17px; color: var(--fg); }
  .nav .brand i { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 9px; background: var(--primary); color: var(--on-primary); font-style: normal; font-size: 14px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 10px; min-height: 40px; padding: 0 10px; font-size: 15px; color: var(--fg); }
  .nav a[aria-current="page"] { background: var(--chip); color: var(--fg); }
  .nav .nav-foot { display: flex; flex-direction: column; gap: 2px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
  .nav .nav-foot span { padding: 0 10px; }
  .mainbar { display: none; }
  .phone { display: none !important; }
  .desk { display: revert !important; }
}

/* header */
.top { display: flex; align-items: center; gap: 4px; padding: 6px 8px 0; }
.back { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 8px 0 4px; color: var(--link); text-decoration: none; }
.head { display: flex; flex-direction: column; gap: 8px; padding: 6px 16px 12px; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-width: 0; }
.h1 { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.h2 { font-size: 17px; font-weight: 600; }
.sub { font-size: 14px; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
@media (min-width: 1024px) {
  .top { padding: 18px 24px 0; }
  .head { padding: 6px 28px 16px; }
  .h1 { font-size: 30px; }
}

/* page body */
.body { display: flex; flex-direction: column; gap: 22px; padding: 4px 16px 24px; flex: 1 1 auto; min-width: 0; }
.wide { max-width: 1280px; width: 100%; }
@media (min-width: 1024px) { .body { padding: 8px 28px 40px; } }
.group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.group-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 4px; font-size: 13px; color: var(--muted); }
.group-h b { font-size: 17px; font-weight: 600; color: var(--fg); }
.foot { padding: 0 4px; font-size: 13px; color: var(--muted); }
.sec { background: var(--section); border-radius: 14px; overflow: hidden; }
.pad { padding: 14px 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.list > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 16px; width: 100%; color: inherit; text-decoration: none; background: transparent; border: 0; text-align: left; transition: background-color .15s; }
a.row:hover, button.row:hover { background: var(--chip); }
a.row[aria-current="true"] { background: var(--chip); }
.row-top { align-items: flex-start; }
.grow { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.t1 { font-weight: 500; overflow-wrap: break-word; }
.t2 { font-size: 13px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.chev { color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-variant-numeric: tabular-nums; }
.kv span:first-child { color: var(--muted); }
.kv-total { padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--line); font-weight: 600; font-size: 17px; }
.kv-total span:first-child { color: var(--fg); }
.cells { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); background: var(--page); border-radius: 10px; }
.cells > div { display: flex; flex-direction: column; gap: 1px; padding: 8px 10px; }
.cells > div + div { border-left: 1px solid var(--line); }
.cells dt, .cells .k { font-size: 12px; color: var(--muted); }
.cells dd, .cells .v { font-variant-numeric: tabular-nums; font-weight: 500; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats > div { display: flex; flex-direction: column; gap: 2px; padding: 12px 16px; }
.stats > div:nth-child(even) { border-left: 1px solid var(--line); }
.stats > div:nth-child(n+3) { border-top: 1px solid var(--line); }
@media (min-width: 1024px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stats > div + div { border-left: 1px solid var(--line); }
  .stats > div:nth-child(n+3) { border-top: 0; }
}
.big { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* split views: list + detail. Phone shows one at a time (:target), desktop shows both. */
.split { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.split-detail { display: none; }
.split:has(.split-detail:target) .split-list { display: none; }
.split-detail:target { display: flex; }
@media (min-width: 1024px) {
  .split { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); align-items: start; gap: 24px; }
  .split .split-list { display: flex !important; position: sticky; top: 16px; }
  .split .split-detail { display: flex; }
  .split .split-detail ~ .split-detail { display: none; }
  .split-only-phone { display: none !important; }
}

/* catalog: filters | list | order */
.cat { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
@media (min-width: 1024px) {
  .cat { display: grid; grid-template-columns: 250px minmax(0, 1fr) 320px; align-items: start; gap: 24px; }
  .cat > aside { position: sticky; top: 16px; max-height: calc(100dvh - 32px); overflow: auto; }
}
@media (min-width: 1024px) and (max-width: 1279px) { .cat { grid-template-columns: 230px minmax(0, 1fr) 290px; gap: 18px; } }
.flist { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
@media (min-width: 1280px) {
  .flist { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .flist > li { border-top: 0 !important; border-bottom: 1px solid var(--line); }
  .flist > li:nth-child(odd) { border-right: 1px solid var(--line); }
}

/* sheets on phone (filters, order, confirm) via :target; columns on desktop */
.sheet-wrap { display: none; }
.sheet-wrap:target { display: block; position: fixed; inset: 0; z-index: 50; }
.sheet-wrap .scrim { position: absolute; inset: 0; background: var(--scrim); }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88dvh; display: flex; flex-direction: column; background: var(--page); border-radius: 18px 18px 0 0; overflow: hidden; }
.sheet-scroll { flex: 1 1 auto; overflow: auto; display: flex; flex-direction: column; gap: 18px; padding: 0 16px 16px; }
.grab { width: 38px; height: 5px; margin: 8px auto 2px; border-radius: 3px; background: var(--field); opacity: .5; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 8px 8px 16px; }
.sheet .mainbar { position: static; display: flex; }
@media (min-width: 1024px) {
  .sheet-wrap.as-column { display: block; position: static; }
  .sheet-wrap.as-column .scrim, .sheet-wrap.as-column .grab, .sheet-wrap.as-column .close { display: none; }
  .sheet-wrap.as-column .sheet { position: static; max-height: none; border-radius: 0; background: transparent; }
  .sheet-wrap.as-column .sheet-h { padding: 0 4px 8px; }
  .sheet-wrap.as-column .sheet-scroll { padding: 0; overflow: visible; }
  .sheet-wrap.as-column .mainbar { padding: 12px 0 0; background: transparent; border: 0; }
  .sheet-wrap.as-dialog:target .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%, -50%); width: 480px; border-radius: 18px; }
}

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background-color .15s, color .15s; }
.btn-p { background: var(--primary); color: var(--on-primary); }
a.btn-p { color: var(--on-primary); }
.btn-s { background: var(--chip); color: var(--fg); }
a.btn-s { color: var(--fg); }
.btn-g { background: transparent; color: var(--link); padding: 0 8px; }
.btn-d { background: var(--danger-bg); color: var(--danger); }
.btn-w { width: 100%; }
.btn[aria-disabled="true"] { background: var(--chip); color: var(--muted); cursor: default; }
.btn-p:hover { filter: brightness(1.08); }
.btn-s:hover { background: var(--line); }
@media (min-width: 1024px) { .btn { min-height: 38px; border-radius: 10px; } }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: var(--fg); cursor: pointer; position: relative; transition: background-color .15s; }
.icon-btn:hover { background: var(--chip); }
.badge { position: absolute; top: 4px; right: 4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--primary); color: var(--on-primary); font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }

/* chips, tags, status */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 0 16px; scrollbar-width: none; }
.wrap { flex-wrap: wrap; overflow: visible; padding: 0; }
@media (min-width: 1024px) { .chips { padding: 0; flex-wrap: wrap; } }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--section); color: var(--fg); font-size: 14px; white-space: nowrap; cursor: pointer; text-decoration: none; transition: background-color .15s, color .15s; }
@media (min-width: 1024px) { .chip { min-height: 32px; padding: 0 12px; font-size: 13.5px; } }
.chip .n { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip.on { background: var(--fg); border-color: var(--fg); color: var(--section); }
.chip.on .n { color: inherit; opacity: .7; }
.chip[aria-disabled="true"] { opacity: .45; cursor: default; }
.tag { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; background: var(--chip); font-size: 12px; }
.sale { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; background: var(--st-red-bg); color: var(--st-red); font-size: 12px; font-weight: 600; white-space: nowrap; }
.st { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.st-blue { background: var(--st-blue-bg); color: var(--st-blue); }
.st-amber { background: var(--st-amber-bg); color: var(--st-amber); }
.st-teal { background: var(--st-teal-bg); color: var(--st-teal); }
.st-green { background: var(--st-green-bg); color: var(--st-green); }
.st-red { background: var(--st-red-bg); color: var(--st-red); }
.st-gray { background: var(--st-gray-bg); color: var(--st-gray); }
.flow { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; max-width: 520px; }
.flow i { display: block; height: 4px; border-radius: 2px; background: var(--chip); }
.flow i.done { background: var(--primary); }
.flow i.now { background: var(--primary); opacity: .45; }
.bar { height: 6px; border-radius: 999px; background: var(--chip); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--primary); }

/* controls */
.field { display: block; width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--field); border-radius: 12px; background: var(--section); color: var(--fg); }
.field::placeholder { color: var(--muted); opacity: .85; }
.field-s { width: 88px; height: 36px; text-align: right; border-radius: 9px; font-variant-numeric: tabular-nums; }
.search { position: relative; flex: 1 1 auto; min-width: 0; display: block; }
.search .i { position: absolute; left: 12px; top: 12px; color: var(--muted); }
.search .field { padding-left: 40px; border-color: transparent; background: var(--chip); }
@media (min-width: 1024px) { .field { height: 38px; border-radius: 10px; } .search .i { top: 9px; } }
.step { display: inline-flex; align-items: center; border-radius: 12px; background: var(--chip); flex-shrink: 0; }
.step button { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 12px; background: transparent; cursor: pointer; }
.step button:hover { background: var(--line); }
.step .q { min-width: 26px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
@media (min-width: 1024px) { .step button { width: 32px; height: 32px; border-radius: 9px; } .step { border-radius: 9px; } }
.add { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 12px; background: var(--chip); color: var(--fg); cursor: pointer; flex-shrink: 0; }
.add:hover { background: var(--line); }
@media (min-width: 1024px) { .add { width: 32px; height: 32px; border-radius: 9px; } }
.pack { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 12px; border-radius: 14px; background: var(--page); }
.pack.in { background: var(--st-blue-bg); }
.packs { display: flex; flex-wrap: wrap; gap: 8px; }
.seg { display: flex; padding: 3px; border-radius: 12px; background: var(--chip); }
.seg > * { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-height: 38px; padding: 0 8px; border: 0; border-radius: 9px; background: transparent; color: var(--fg); font-size: 14px; text-decoration: none; cursor: pointer; white-space: nowrap; }
.seg > .on { background: var(--section); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .14); }
.seg > [aria-disabled="true"] { color: var(--muted); opacity: .6; cursor: default; }
@media (min-width: 1024px) { .seg.tabs { display: inline-flex; align-self: flex-start; } .seg.tabs > * { flex: 0 0 auto; padding: 0 16px; min-height: 32px; } }
.switch { position: relative; width: 51px; height: 31px; border-radius: 16px; background: var(--chip); flex-shrink: 0; }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); }
.switch.on { background: var(--ok); }
.switch.on::after { left: 22px; }
.check { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--field); flex-shrink: 0; color: var(--on-primary); }
.check.on { background: var(--primary); border-color: var(--primary); }

/* notes, states */
.note { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--chip); font-size: 14px; }
.note-warn { background: var(--st-amber-bg); color: var(--st-amber); }
.note-err { background: var(--st-red-bg); color: var(--st-red); }
.note-ok { background: var(--st-green-bg); color: var(--st-green); }
.note-info { background: var(--st-blue-bg); color: var(--st-blue); }
.sk { display: block; height: 12px; border-radius: 6px; background: var(--chip); }
.empty { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 22px 18px; text-align: center; }
.empty .ico { display: inline-flex; align-items: center; justify-content: center; width: 48px; height: 48px; border-radius: 14px; background: var(--chip); color: var(--muted); }

/* tables (desktop) */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
.tbl thead th { position: sticky; top: 0; z-index: 1; background: var(--section); font-size: 12.5px; font-weight: 500; color: var(--muted); white-space: nowrap; }
.tbl tbody tr:hover { background: var(--page); }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .c { text-align: center; }
.tbl tfoot td { font-weight: 600; border-top: 1px solid var(--line); border-bottom: 0; background: var(--page); }
.tbl .art { font-family: 'Geist Mono', ui-monospace, Menlo, monospace; font-size: 12px; color: var(--muted); }
.tbl tr.brand-row td { background: var(--page); font-weight: 600; font-size: 13px; }
.tbl tr.sel { background: var(--st-blue-bg); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.kbd { display: inline-flex; align-items: center; padding: 0 6px; min-height: 20px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; font-size: 12px; color: var(--muted); }
.two-col { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
@media (min-width: 1024px) { .two-col { display: grid; grid-template-columns: minmax(0, 1fr) 320px; align-items: start; gap: 24px; } .two-col > aside { position: sticky; top: 16px; } }

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