:root {
  --bg: #f4f2ed; --card: #ffffff; --ink: #1a1815; --ink2: #5b564d; --line: #dcd8cf; --soft: #ebe8e1;
  --brand: #171613; --brand-ink: #ffffff; --gold: #9b752b;
  --ok: #24733a; --ok-bg: #e3f3e6; --bad: #b3261e; --bad-bg: #fbe7e5; --warn: #94570a; --warn-bg: #fdf0d8; --info: #1b5aa8; --info-bg: #e2edfa;
  --shadow: 0 6px 24px rgba(28, 24, 18, .07);
  --r: 16px; --fs: 18px;
  color-scheme: only light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 var(--fs)/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 30px; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 22px; font-weight: 750; }
h3 { font-size: 19px; font-weight: 700; }
a { color: var(--info); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot-msg { padding: 60px 20px; text-align: center; color: var(--ink2); }
[hidden] { display: none !important; }

/* ---------- каркас ---------- */
.shell { min-height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.side { position: sticky; top: 0; height: 100vh; overflow: auto; background: var(--card); border-right: 1px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 10px 18px; font-weight: 800; letter-spacing: .1em; font-size: 20px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: var(--brand); display: grid; place-items: center; }
.brand-mark svg { width: 24px; height: 24px; fill: #c9a24a; }
.nav a { display: flex; align-items: center; gap: 14px; padding: 14px 14px; border-radius: 14px; color: var(--ink); text-decoration: none; font-weight: 600; min-height: 52px; }
.nav a svg { width: 24px; height: 24px; flex: 0 0 24px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav a:hover { background: var(--soft); }
.nav a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); }
.nav .badge-count { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px; min-width: 26px; padding: 0 8px; height: 26px; display: grid; place-items: center; font-size: 14px; font-weight: 700; }
.side-foot { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.me-name { font-weight: 700; }
.me-role { color: var(--ink2); font-size: 15px; }
.shell > div, .grid > *, .card, .stack > * { min-width: 0; }
.main { min-width: 0; padding: 28px clamp(16px, 3vw, 44px) 90px; max-width: 1280px; width: 100%; }
.topbar { display: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.page-head .sub { color: var(--ink2); margin-top: 4px; font-size: 17px; }
.head-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.bottom-nav { display: none; }

/* ---------- элементы ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.page > * + * { margin-top: 16px; }
.page > .page-head + * { margin-top: 0; }
.page > .btn.small + .page-head { margin-top: 14px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack { display: grid; gap: 16px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.muted { color: var(--ink2); }
.small { font-size: 15px; }
.big { font-size: 34px; font-weight: 800; letter-spacing: -.01em; line-height: 1.1; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 14px; padding: 12px 20px; min-height: 52px; font-weight: 650; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; transition: transform .1s, background .15s; }
.btn:hover { background: var(--soft); }
.btn:active { transform: scale(.985); }
.btn svg { width: 22px; height: 22px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { opacity: .9; background: var(--brand); }
.btn.tg { background: #2a8fd6; border-color: #2a8fd6; color: #fff; font-size: 20px; min-height: 64px; padding: 14px 30px; }
.btn.tg:hover { background: #2380c2; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; }
.btn.good { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.small { min-height: 42px; padding: 8px 14px; font-size: 16px; border-radius: 12px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.link-btn { appearance: none; background: none; border: 0; padding: 0; color: var(--info); font-weight: 600; cursor: pointer; text-decoration: underline; }

label.field { display: grid; gap: 7px; }
label.field > span.lbl { font-weight: 650; }
.hint { color: var(--ink2); font-size: 15px; }
input[type="text"], input[type="number"], input[type="search"], input[type="tel"], input[type="date"], input[type="email"], select, textarea {
  width: 100%; min-height: 52px; padding: 12px 16px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--card); outline: none;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 14%, transparent); }
input[type="checkbox"], input[type="radio"] { width: 24px; height: 24px; accent-color: var(--brand); flex: 0 0 24px; }
.check { display: flex; align-items: center; gap: 12px; min-height: 44px; cursor: pointer; font-weight: 600; }
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .wide { grid-column: 1 / -1; }
.switch { position: relative; width: 62px; height: 36px; flex: 0 0 62px; }
.switch input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--line); transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 4px; left: 4px; width: 28px; height: 28px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(26px); }
.switch input:focus-visible + i { outline: 3px solid var(--info); outline-offset: 2px; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px; font-size: 15px; font-weight: 650; white-space: nowrap; background: var(--soft); color: var(--ink); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { appearance: none; border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 9px 16px; min-height: 44px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; }
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip .n { font-size: 14px; opacity: .75; }

.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 15px; color: var(--ink2); font-weight: 650; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--soft); }
.tbl td.num, .tbl th.num { text-align: right; }

.list { display: grid; gap: 12px; }
.item { display: grid; gap: 6px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); text-decoration: none; color: inherit; cursor: pointer; }
.item:hover { border-color: var(--brand); }
.item { grid-template-columns: minmax(0, 1fr); }
.item > * { min-width: 0; overflow-wrap: anywhere; }
.item .top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.item .title { font-weight: 700; }

.todo { display: flex; align-items: center; gap: 16px; padding: 18px 20px; border-radius: var(--r); border: 1.5px solid var(--line); background: var(--card); text-decoration: none; color: inherit; min-height: 84px; }
.todo:hover { border-color: var(--brand); }
.todo .n { font-size: 36px; font-weight: 800; min-width: 56px; text-align: center; line-height: 1; }
.todo.hot { border-color: var(--bad); background: var(--bad-bg); }
.todo.hot .n { color: var(--bad); }
.todo.calm .n { color: var(--ink2); }
.todo .t { font-weight: 700; }
.todo .d { color: var(--ink2); font-size: 15px; }

.kpi .lbl { color: var(--ink2); font-weight: 600; font-size: 16px; }
.kpi .val { margin-top: 4px; }
.kpi .sub { color: var(--ink2); font-size: 15px; margin-top: 4px; }

.pgrid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.pcard { border: 1px solid var(--line); border-radius: var(--r); background: var(--card); overflow: hidden; display: flex; flex-direction: column; cursor: pointer; }
.pcard:hover { border-color: var(--brand); }
.pcard .img { aspect-ratio: 1 / 1; background: var(--soft); display: grid; place-items: center; color: var(--ink2); overflow: hidden; }
.pcard .img img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.pcard .body { padding: 14px 16px 16px; display: grid; gap: 8px; flex: 1; }
.pcard .nm { font-weight: 700; line-height: 1.3; }
.pcard.off { opacity: .6; }
.pcard .foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.photo-row { display: flex; flex-wrap: wrap; gap: 12px; }
.photo { width: 116px; height: 116px; border-radius: 14px; border: 1.5px solid var(--line); background: #fff; position: relative; overflow: hidden; }
.photo img { width: 100%; height: 100%; object-fit: contain; }
.photo .x { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(0,0,0,.7); color: #fff; font-size: 20px; line-height: 1; cursor: pointer; }
.photo .main { width: auto; max-width: none; min-width: 0; position: absolute; left: 4px; bottom: 4px; background: var(--brand); color: var(--brand-ink); border-radius: 8px; padding: 2px 8px; font-size: 13px; font-weight: 700; }
.photo-add { display: grid; place-items: center; text-align: center; color: var(--ink2); cursor: pointer; font-weight: 650; font-size: 15px; border-style: dashed; }
.photo-add:hover { border-color: var(--brand); color: var(--ink); }

.kv { display: grid; grid-template-columns: minmax(120px, 190px) minmax(0, 1fr); gap: 8px 16px; }
.kv dt { color: var(--ink2); }
.kv dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

.tags { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px; border: 1.5px solid var(--line); border-radius: 14px; background: var(--card); min-height: 52px; }
.tags .tag { background: var(--soft); border-radius: 10px; padding: 6px 8px 6px 12px; display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.tags .tag button { border: 0; background: none; cursor: pointer; font-size: 20px; line-height: 1; padding: 0 4px; color: var(--ink2); }
.tags input { border: 0 !important; box-shadow: none !important; flex: 1; min-width: 120px; min-height: 40px; padding: 4px 8px; background: transparent; }
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 46px; gap: 10px; align-items: center; }
.pair .del { min-height: 46px; padding: 0; }

.timeline { display: grid; gap: 12px; }
.tl { display: grid; grid-template-columns: 14px 1fr; gap: 12px; align-items: start; }
.tl::before { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); margin-top: 7px; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--ink2); font-size: 12px; font-family: inherit; }
.chart .bar { fill: var(--gold); }
.chart .bar2 { fill: var(--info); opacity: .8; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.hbar { display: grid; grid-template-columns: minmax(90px, 1.2fr) minmax(0, 3fr) auto; gap: 12px; align-items: center; padding: 6px 0; }
.hbar .track { height: 12px; border-radius: 6px; background: var(--soft); overflow: hidden; }
.hbar .fill { height: 100%; background: var(--gold); border-radius: 6px; }

.notice { padding: 16px 18px; border-radius: 14px; background: var(--info-bg); color: var(--info); font-weight: 600; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.empty { text-align: center; padding: 44px 16px; color: var(--ink2); }
.empty .em { font-size: 44px; margin-bottom: 8px; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; margin: 46px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 18px; }

.toasts { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); display: grid; gap: 10px; z-index: 100; width: min(92vw, 440px); pointer-events: none; }
.toast { background: var(--brand); color: var(--brand-ink); padding: 16px 20px; border-radius: 14px; font-weight: 650; box-shadow: 0 10px 30px rgba(0,0,0,.25); pointer-events: auto; }
.toast.bad { background: var(--bad); color: #fff; }
.modal-back { position: fixed; inset: 0; background: rgba(15, 14, 12, .55); z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--card); border-radius: 20px; padding: 26px; width: min(560px, 100%); max-height: 92vh; overflow: auto; display: grid; gap: 18px; }
.modal.wide { width: min(860px, 100%); }
.modal-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: flex-end; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(560px, 100%); text-align: center; display: grid; gap: 22px; padding: 38px 30px; }
.login-card .brand { justify-content: center; }
.bignum { font-size: 84px; font-weight: 800; letter-spacing: .05em; line-height: 1; padding: 18px; border-radius: 22px; background: var(--soft); }
.steps { text-align: left; display: grid; gap: 14px; counter-reset: st; }
.steps li { list-style: none; display: grid; grid-template-columns: 40px 1fr; gap: 14px; align-items: start; }
.steps li::before { counter-increment: st; content: counter(st); width: 40px; height: 40px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-weight: 800; }
.steps ol { margin: 0; padding: 0; display: grid; gap: 14px; }

/* ---------- мобильная версия ---------- */
@media (max-width: 1100px) { .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  :root { --fs: 17px; }
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .side.open { display: flex; position: fixed; inset: 0; z-index: 80; height: 100%; width: 100%; padding-top: 70px; }
  .topbar { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 70; background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .topbar .brand { padding: 0; font-size: 17px; }
  .topbar .brand-mark { width: 34px; height: 34px; }
  .main { padding: 18px 14px 110px; }
  h1 { font-size: 25px; }
  .grid.c2, .grid.c3, .grid.c4, .form-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { margin-top: 10px; font-size: 15px; }
  .bottom-nav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .bottom-nav a, .bottom-nav button { appearance: none; border: 0; background: none; display: grid; justify-items: center; gap: 2px; padding: 9px 4px 10px; color: var(--ink2); text-decoration: none; font-size: 13px; font-weight: 650; min-height: 64px; cursor: pointer; position: relative; }
  .bottom-nav svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .bottom-nav [aria-current="page"] { color: var(--ink); }
  .bottom-nav .dot { position: absolute; top: 6px; left: calc(50% + 8px); background: var(--bad); color: #fff; border-radius: 999px; min-width: 20px; height: 20px; font-size: 12px; display: grid; place-items: center; padding: 0 5px; }
  .toasts { bottom: 100px; }
  .hide-m { display: none !important; }
  .spacer { display: none !important; }
  .bignum { font-size: 68px; }
  .pair { grid-template-columns: minmax(0, 1fr) 46px; }
  .pick-row { grid-template-columns: 1fr; }
  .pair input:first-child { grid-column: 1 / -1; }
  .modal { padding: 20px; border-radius: 18px; }
  /* пальцем попадать удобно: все нажимаемые элементы не меньше 40px */
  .switch input { inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); }
  summary { min-height: 44px; padding: 10px 0; cursor: pointer; }
  .kv dd a, .item a:not(.btn), .page a:not(.btn):not(.item):not(.todo):not(.pcard) { display: inline-block; padding: 10px 0; }
  .photo .x { width: 40px; height: 40px; }
  .tags .tag button { min-width: 40px; min-height: 40px; }
}
@media (min-width: 861px) { .show-m { display: none !important; } }
.pick-list { max-height: 260px; overflow: auto; border: 1.5px solid var(--line); border-radius: 14px; padding: 4px 14px; background: var(--card); }
.scope-names { margin-top: 6px; }
.pick-row { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 10px; align-items: center; padding: 4px 0; }
.pick-row input[type="number"] { min-height: 44px; padding: 8px 12px; }
.price-lines { gap: 6px; }
.line-item { display: grid; gap: 4px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.line-item:last-child { border-bottom: 0; }
@media print { .side, .topbar, .bottom-nav, .head-actions, .toasts { display: none !important; } .shell { display: block; } }

.codebox { font-size: 30px !important; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums; }
.or-line { text-align: center; margin: 12px 0; }

.issue-text { flex: 1 1 200px; min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
