:root {
  --bg: #F2F3EF;
  --card: #FFFFFF;
  --ink: #16181D;
  --muted: #646a75;
  --line: #DADCD5;
  --label: #1B2BA8;
  --label-ink: #FFFFFF;
  --sticker: #FFD23F;
  --sticker-ink: #2A2200;
  --danger: #B42323;
  --ok: #17703F;
  --warn-bg: #FFF4CC;
  --radius: 12px;
  --tabs-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161B; --card: #1D2027; --ink: #ECEDEF; --muted: #9AA0AA; --line: #2E323B;
    --label: #8C9CFF; --label-ink: #0E1230; --danger: #FF7A7A; --ok: #5FD18F; --warn-bg: #3A3216;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14161B; --card: #1D2027; --ink: #ECEDEF; --muted: #9AA0AA; --line: #2E323B;
  --label: #8C9CFF; --label-ink: #0E1230; --danger: #FF7A7A; --ok: #5FD18F; --warn-bg: #3A3216;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 16px/1.45 Onest, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--label); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.hidden { display: none !important; }

/* ---------- верх и низ ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 800; color: var(--ink); }
.brand svg { color: var(--ink); }
.top-title { margin-left: auto; color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; font-size: .72rem; color: var(--muted); }
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--label); font-weight: 600; }
.tabs .tab-scan svg { width: 52px; height: 52px; padding: 12px; margin-top: -22px; border-radius: 50%; background: var(--label); color: var(--label-ink); stroke: var(--label-ink); box-shadow: 0 0 0 5px var(--bg); }
.tabs .tab-scan span { margin-top: -1px; }

main { max-width: 760px; margin: 0 auto; padding: 16px; outline: none; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* ---------- элементы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--label); color: var(--label-ink); border-color: var(--label); }
.btn.sale { background: var(--sticker); color: var(--sticker-ink); border-color: var(--sticker); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 56px; font-size: 1.05rem; }

.field { display: block; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
}
textarea.input { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.grid2 > * { min-width: 0; }
input[type="date"].input { min-width: 0; -webkit-appearance: none; appearance: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.panel.flush { padding: 0; overflow: hidden; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card);
  font-size: .9rem; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }

/* ---------- поиск ---------- */
.search { position: relative; }
.search .input { padding-left: 42px; min-height: 50px; font-size: 1.05rem; }
.search svg { position: absolute; left: 13px; top: 50%; translate: 0 -50%; width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2; }

/* ---------- список пластинок ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 12px; align-items: center; padding: 10px 14px; text-decoration: none; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item:active { background: color-mix(in srgb, var(--line) 40%, transparent); }
.item .t { min-width: 0; flex: 1; }
.item .artist { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .album { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { font-size: .82rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.out { opacity: .55; }

/* Конверт: обложка или «пустой» диск с наклейкой-лейблом */
.cover { flex: none; width: 56px; height: 56px; border-radius: 4px; background: var(--ink); position: relative; overflow: hidden; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.empty::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: repeating-radial-gradient(circle, #2b2e36 0 1px, #1a1c22 1px 3px); }
.cover.empty::after { content: ""; position: absolute; inset: 21px; border-radius: 50%; background: var(--hue, var(--label)); }
.cover.lg { width: 100%; height: auto; aspect-ratio: 1; border-radius: 6px; }
.cover.lg.empty::before { inset: 8%; }
.cover.lg.empty::after { inset: 37%; }

/* Ценник-наклейка: главный узнаваемый элемент */
.sticker {
  flex: none; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 62px;
  padding: 5px 8px; border-radius: 6px; background: var(--sticker); color: var(--sticker-ink); rotate: -3deg;
  font-weight: 800; line-height: 1.05; box-shadow: 0 1px 0 rgba(0,0,0,.12);
}
.sticker small { font-weight: 600; font-size: .72rem; opacity: .8; }
.sticker.none { background: transparent; color: var(--muted); border: 1.5px dashed var(--line); box-shadow: none; rotate: 0deg; }
.sticker.lg { font-size: 1.6rem; padding: 10px 16px; min-width: 110px; rotate: -4deg; }
.sticker.lg small { font-size: .85rem; }

/* ---------- карточка ---------- */
.card-head { display: grid; grid-template-columns: 140px 1fr; gap: 16px; align-items: start; }
@media (min-width: 600px) { .card-head { grid-template-columns: 220px 1fr; } }
.card-head h1 { font-size: 1.35rem; }
.card-head .album-t { font-size: 1.15rem; font-weight: 500; margin-top: 2px; }
.code { font-weight: 700; letter-spacing: .04em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.qty-line { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.qty-num { font-size: 2.6rem; font-weight: 800; line-height: 1; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tracks { margin: 0; padding: 0; list-style: none; columns: 1; }
@media (min-width: 600px) { .tracks { columns: 2; column-gap: 24px; } }
.tracks li { display: flex; gap: 10px; padding: 3px 0; break-inside: avoid; }
.tracks .pos { color: var(--muted); width: 2.2em; flex: none; }
.tracks .dur { margin-left: auto; color: var(--muted); }
details > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details > summary::after { content: "+"; color: var(--muted); font-weight: 400; font-size: 1.3rem; }
details[open] > summary::after { content: "−"; }
details[open] > summary { margin-bottom: 10px; }

.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: flex; gap: 10px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.hist li:last-child { border-bottom: 0; }
.delta { font-weight: 800; width: 2.6em; flex: none; }
.delta.minus { color: var(--danger); }
.delta.plus { color: var(--ok); }

/* ---------- сканер ---------- */
.scanner { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .aim { position: absolute; left: 10%; right: 10%; top: 38%; bottom: 38%; border: 2px solid rgba(255,255,255,.85); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.35); }
.scanner .aim::after { content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 2px; background: var(--sticker); opacity: .9; }
.scanner .msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: #fff; }
.scanner.compact { aspect-ratio: 2 / 1; }
.scanner.compact .aim { top: 30%; bottom: 30%; }
.scanner.flash .aim { border-color: var(--sticker); box-shadow: 0 0 0 999px rgba(255,210,63,.25); }
.mode { display: grid; grid-template-columns: 1fr 1fr; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; }
.mode button { border: 0; background: none; min-height: 40px; border-radius: 8px; font-weight: 600; cursor: pointer; color: var(--muted); }
.mode button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

.result { display: flex; gap: 12px; align-items: center; }
.warn { background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; font-size: .92rem; }
.bad { color: var(--danger); font-weight: 600; }
.good { color: var(--ok); font-weight: 600; }

/* ---------- ревизия ---------- */
.progress { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--label); transition: width .3s; }
.big-count { font-size: 3rem; font-weight: 800; line-height: 1; }
.scanlog { list-style: none; padding: 0; margin: 0; }
.scanlog li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .92rem; }
.scanlog li:last-child { border-bottom: 0; }

/* ---------- Discogs ---------- */
.candidates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.cand { text-align: left; padding: 0; border: 1px solid var(--line); background: var(--card); border-radius: 10px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.cand img, .cand .noimg { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--line); display: block; }
.cand .ct { padding: 8px 10px 10px; font-size: .85rem; }
.cand .ct b { display: block; font-size: .9rem; line-height: 1.25; margin-bottom: 2px; }
.cand.match { border-color: var(--label); box-shadow: 0 0 0 1px var(--label); }
.cand:disabled { opacity: .5; }

/* ---------- прочее ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.stats > div { background: var(--card); padding: 14px 16px; }
.stats b { display: block; font-size: 1.5rem; font-weight: 800; }
.menu { list-style: none; margin: 0; padding: 0; }
.menu a, .menu button { display: flex; width: 100%; justify-content: space-between; align-items: center; padding: 15px 16px; border: 0; background: none; text-align: left; text-decoration: none; border-bottom: 1px solid var(--line); cursor: pointer; }
.menu li:last-child a, .menu li:last-child button { border-bottom: 0; }
.empty-state { text-align: center; padding: 36px 16px; }
.empty-state p { color: var(--muted); max-width: 32ch; margin: 8px auto 16px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; }
.table td.n { text-align: right; white-space: nowrap; }

/* ---------- накопитель сканера ---------- */
.empty-note p { margin: 4px 0 0; }
.basket .bk-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.bk-item { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.bk-item .t { flex: 1; min-width: 0; text-decoration: none; }
.bk-item .artist { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-item .album { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bk-item .meta { font-size: .82rem; color: var(--muted); }
.bk-item.short .meta { color: var(--danger); font-weight: 600; }
.bk-item.fresh { background: color-mix(in srgb, var(--sticker) 24%, var(--card)); }
.bk-ctl { flex-basis: 100%; display: flex; align-items: center; gap: 10px; padding-left: 68px; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.stepper button { width: 42px; height: 42px; border: 0; background: none; font-size: 1.25rem; cursor: pointer; }
.stepper span { min-width: 2.2em; text-align: center; font-weight: 800; }
.price-in { position: relative; display: block; width: 120px; }
.price-in .input { min-height: 42px; padding-right: 28px; text-align: right; }
.price-in span { position: absolute; right: 10px; top: 50%; translate: 0 -50%; color: var(--muted); }
.x { flex: none; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 1.35rem; line-height: 1; cursor: pointer; }
.bk-foot { padding: 14px; border-top: 1px solid var(--line); }
.mode.three { grid-template-columns: repeat(3, 1fr); }

/* ---------- продажи ---------- */
.src-row + .src-row { margin-top: 10px; }
.src-row .row { gap: 12px; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: var(--label); }

/* ---------- этикетки ---------- */
.labels { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.lbl { position: relative; margin: 0; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.lbl img { display: block; width: 100%; height: auto; aspect-ratio: 58 / 40; background: #fff; border-radius: 3px; box-shadow: 0 0 0 1px var(--line); }
.lbl figcaption { margin-top: 6px; }
.lbl .x { position: absolute; top: -10px; right: -10px; width: 34px; height: 34px; font-size: 1.15rem; }

#print-area { display: none; }
@media print {
  @page { size: 58mm 40mm; margin: 0; }
  html, body { background: #fff !important; padding: 0 !important; margin: 0 !important; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; }
  #print-area .pl { width: 58mm; height: 40mm; overflow: hidden; break-after: page; page-break-after: always; }
  #print-area .pl:last-child { break-after: auto; page-break-after: auto; }
  #print-area img { display: block; width: 58mm; height: 40mm; image-rendering: pixelated; }
}

/* ---------- отчёты ---------- */
.mode a { display: flex; align-items: center; justify-content: center; min-height: 40px; border-radius: 8px; font-weight: 600; color: var(--muted); text-decoration: none; }
.mode a[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
h3 { font-size: 1rem; font-weight: 700; }
.mv { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: .92rem; }
.mv:last-child { border-bottom: 0; }
.mv a { text-decoration: none; min-width: 0; }
.mv .delta { padding-top: 1px; }
.mv .r { text-align: right; white-space: nowrap; flex: none; }
.scroll-x { overflow-x: auto; }
.mv .r { display: flex; flex-direction: column; align-items: flex-end; }
.mv .bal { font-size: 1.3rem; line-height: 1.1; }
.turn-card h3 { margin-bottom: 8px; }
.turn-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 8px; }
.turn-grid span { display: block; font-size: .78rem; color: var(--muted); }
.turn-grid b { font-size: 1.2rem; }
.turn-pair { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 12px; }
@media (min-width: 640px) { .turn-pair { grid-template-columns: 1fr 1fr; } }
.table.turn { font-size: .88rem; }
.table.turn th, .table.turn td { padding: 9px 8px; white-space: nowrap; }
.table.turn tr.tot td { font-weight: 700; border-bottom: 0; }
.table .plus { color: var(--ok); } .table .minus { color: var(--danger); }

/* ---------- сканер: найдено по штрихкоду ---------- */
.pick .list { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.pick .item { width: 100%; background: var(--card); border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; font: inherit; color: inherit; }
.pick li:last-child .item { border-bottom: 0; }
.pick .item.sel { background: color-mix(in srgb, var(--label) 12%, var(--card)); box-shadow: inset 3px 0 0 var(--label); }
.pick .item .artist { white-space: normal; }
.pick.done { border-color: var(--ok); }
.qf { padding-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 14px); translate: -50% 20px; z-index: 50;
  max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .2s, translate .2s;
}
.toast.show { opacity: 1; translate: -50% 0; }
.toast.error { background: var(--danger); color: #fff; }

.login { max-width: 360px; margin: 10vh auto 0; }
.login .disc { width: 72px; height: 72px; margin-bottom: 16px; }

.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--label); animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { rotate: 360deg; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
}
@media (min-width: 900px) {
  .tabs { left: 50%; right: auto; width: 520px; translate: -50% 0; bottom: 14px; border: 1px solid var(--line); border-radius: 16px; height: var(--tabs-h); padding-bottom: 0; }
}
