:root {
  --bg: #f5f6f8; --card: #ffffff; --text: #1d2330; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2f6fde; --accent-soft: #e6eefc; --good: #1f8a4c; --bad: #c8382e;
  --c1: #2f6fde; --c2: #e08a1e; --c3: #1f9e8f; --c4: #c8382e;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --card: #1b2029; --text: #e6e9ef; --muted: #9098a8; --line: #2b313d;
    --accent: #6c9cf0; --accent-soft: #24324d; --good: #4cc282; --bad: #ef6b60;
    --c1: #6c9cf0; --c2: #f0a547; --c3: #3fc2b1; --c4: #ef6b60;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --card: #1b2029; --text: #e6e9ef; --muted: #9098a8; --line: #2b313d;
  --accent: #6c9cf0; --accent-soft: #24324d; --good: #4cc282; --bad: #ef6b60;
  --c1: #6c9cf0; --c2: #f0a547; --c3: #3fc2b1; --c4: #ef6b60;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h2 { font-size: 22px; } h3 { font-size: 16px; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 13px; }

.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; }
.top nav { display: flex; gap: 4px; flex-wrap: wrap; }
.top nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); }
.top nav a.on, .top nav a:hover { background: var(--accent-soft); color: var(--accent); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; min-width: 0; }
.narrow { max-width: 420px; }
.login { max-width: 360px; margin: 12vh auto 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login label, .narrow label { margin-bottom: 12px; }
input, select, button { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; padding: 9px 16px; }
button.danger[type="submit"] { background: transparent; border-color: var(--bad); color: var(--bad); padding: 5px 10px; }
textarea { font: 13px/1.4 ui-monospace, Consolas, monospace; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; resize: vertical; }
.narrow { max-width: 560px; }
.err { color: var(--bad); } .okmsg { color: var(--good); }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; cursor: pointer; padding: 7px 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.seg button:disabled { color: var(--muted); cursor: not-allowed; opacity: .6; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .k { font-size: 13px; color: var(--muted); }
.tile .v { font-size: 24px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.tile .d { font-size: 13px; }
.up { color: var(--good); } .down { color: var(--bad); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 480px), 1fr)); gap: 16px; }
.grid2 > .card { margin-bottom: 0; } .grid2 { margin-bottom: 16px; }
.chart { position: relative; height: 280px; }

.tablewrap { overflow-x: auto; max-height: 520px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--card); }
.r { text-align: right; white-space: nowrap; }
td img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; display: block; }
.name { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; background: var(--accent-soft); }
.tag.ok { color: var(--good); } .tag.bad { color: var(--bad); }
.neg { color: var(--bad); }
.pos { color: var(--good); }
.wbonly { display: none; } body.is-wb .wbonly { display: inline; }
.warn { color: #b7791f; white-space: nowrap; }

.cardhead { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 10px; }
.cardhead h3 { margin: 0 auto 0 0; }
.filters .grow { flex: 1 1 220px; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--accent-soft); }
th.sort { cursor: pointer; user-select: none; }
th.sort:hover { color: var(--text); }
th.asc::after { content: " ▲"; font-size: 10px; } th.desc::after { content: " ▼"; font-size: 10px; }
thead tr.total td { position: sticky; top: 35px; background: var(--card); font-weight: 600; border-bottom: 2px solid var(--line); z-index: 1; }
thead th { z-index: 2; }
.tablewrap.tall { max-height: 75vh; }
.prodhead { display: flex; gap: 16px; align-items: center; }
.prodhead img { width: 96px; height: 96px; object-fit: cover; border-radius: 10px; flex: none; }
.prodhead h2 { margin: 0 0 4px; }
@media (max-width: 600px) { .prodhead img { width: 64px; height: 64px; } }

/* costs */
img.thumb { width: 36px; height: 48px; object-fit: cover; border-radius: 4px; display: block; }
label.check { flex-direction: row; align-items: center; gap: 6px; }
td.nowrap { white-space: nowrap; }
td.name { max-width: 360px; }
input.cost { width: 100px; text-align: right; }
button.save, button.reset { cursor: pointer; padding: 5px 10px; }

/* costs v2 */
table.costs input.cost { width: 78px; text-align: right; padding: 4px 6px; }
table.costs input.cost::placeholder { color: var(--muted); opacity: .7; }
table.costs input.cost.dirty { border-color: var(--accent); background: var(--accent-soft); }
table.costs td.art { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.savebar { position: sticky; top: 0; z-index: 5; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin: 10px 0; box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.savebar #dirty { font-weight: 600; margin-right: auto; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; padding: 8px 16px; }
#undo { cursor: pointer; }
.secret { font-family: monospace; font-size: 16px; padding: 10px 14px; border: 1px dashed var(--accent); border-radius: 8px; display: inline-block; }
.labels-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
table.lbl input.qty { width: 64px; text-align: right; }
form.inline { display: inline; }
form.inline input { padding: 4px 8px; }

/* меню v2 */
.top { position: sticky; top: 0; z-index: 20; }
.top nav.mainnav { align-items: center; }
.top .item { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); cursor: pointer; display: inline-block; }
.top .item.on, .top .item:hover, details.dd.on > summary, details.dd[open] > summary { background: var(--accent-soft); color: var(--accent); }
details.dd { position: relative; }
details.dd > summary { list-style: none; user-select: none; }
details.dd > summary::-webkit-details-marker { display: none; }
details.dd > summary::after { content: " ▾"; font-size: 11px; }
.ddm { position: absolute; top: calc(100% + 6px); left: 0; min-width: 210px; background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 6px; display: flex; flex-direction: column; z-index: 30; }
.top nav .ddm a { padding: 8px 10px; border-radius: 6px; color: var(--text); }
.top nav .ddm a.on, .top nav .ddm a:hover { background: var(--accent-soft); color: var(--accent); }
.top .who { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.top .logout { border: 1px solid var(--line); }
@media (max-width: 700px) { .ddm { position: fixed; left: 16px; right: 16px; top: auto; } .top .who { margin-left: 0; } }

/* реклама */
.ozonly { display: inline; } body.is-wb .ozonly { display: none; }
.seg.tabs { margin: 8px 0 12px; }
.prod { display: flex; gap: 8px; align-items: center; }
.prod img { width: 32px; height: 42px; object-fit: cover; border-radius: 4px; }
.minuslist { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0; max-height: 260px; overflow: auto; }

/* цены и остатки */
tr.changed td { background: var(--accent-soft); }
.holdrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line, #e5e7eb); }
.holdrow .holdmsg { flex-basis: 100%; }
.savebar #barinfo { margin-right: auto; }
table.inner { width: auto; min-width: 70%; font-size: 13px; background: var(--accent-soft); border-radius: 8px; }
table.inner th, table.inner td { padding: 4px 10px; }
