/* app.css — веб-версия «Казна». Спокойная деловая палитра, таблицы с тонкой сеткой
   (как в Домино), крупные цели для пальца, масштаб шрифта переменной --fs (кнопки A−/A+). */
:root {
  --fs: 15px; --navy: #123a5e; --navy2: #0e2d47; --line: #c9ced4; --bg: #f4f6f8; --head: #e8eef5;
  --ok: #1a7d1a; --bad: #b00020; --warn: #c98a00; --muted: #667; --sel: #cfe0ff;
}
* { box-sizing: border-box; }
.hidden { display: none !important; }
html { font-size: var(--fs); }
body { margin: 0; font-family: "Segoe UI", Roboto, Arial, sans-serif; color: #1a1a1a; background: var(--bg); }
a { color: var(--navy); }
button, input, select, textarea { font: inherit; }

/* ---------- вход ---------- */
body.login { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: #fff; padding: 32px 36px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); width: min(380px, 92vw); }
.login-logo { font-size: 2rem; font-weight: 700; color: var(--navy); text-align: center; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.login-box label { display: block; margin: 10px 0 4px; color: #333; font-size: .95rem; }
.login-box input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-top: 4px; }
.login-msg { min-height: 1.4em; margin-top: 8px; color: var(--muted); text-align: center; }
.login-msg.err { color: var(--bad); }
.login-foot { color: #999; text-align: center; margin-top: 14px; font-size: .9rem; }

/* ---------- каркас ---------- */
.topbar { position: sticky; top: 0; z-index: 20; height: 52px; background: var(--navy); color: #fff; display: flex; align-items: center; gap: 12px; padding: 0 14px; }
/* ☰ видна всегда: на широком экране прячет и возвращает меню (body.nav-hidden), на узком — выдвигает его поверх (ISSUE-176) */
.burger { background: none; border: 0; color: #fff; font-size: 1.5rem; line-height: 1; cursor: pointer; padding: 4px 6px; margin-left: -6px; border-radius: 6px; }
.burger:hover { background: rgba(255,255,255,.14); }
.brand { font-weight: 700; font-size: 1.15rem; white-space: nowrap; }
.crumb { flex: 1; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.topbar .user { opacity: .9; margin: 0 4px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: .78rem; font-weight: 600; vertical-align: middle; }
.badge.test { background: var(--warn); color: #fff; }
.badge.st0 { background: #dfe3e8; color: #444; }
.badge.st1 { background: #d6efd6; color: var(--ok); }
.badge.st9 { background: #f3d6d6; color: var(--bad); }
.layout { display: flex; min-height: calc(100vh - 52px); }
/* меню закреплено под шапкой и листается само: не уезжает вместе с длинным документом, нижние пункты — прокруткой меню */
.sidebar { width: 250px; background: #fff; border-right: 1px solid var(--line); padding: 10px 0; flex-shrink: 0;
  position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto; scrollbar-width: thin; }   /* align-self не ставить: ломает выезжающее меню на узком экране */
@media (min-width: 901px) { body.nav-hidden .sidebar { display: none; } }
.sidebar .grp { padding: 10px 16px 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sidebar a { display: block; padding: 8px 16px 8px 24px; color: #222; text-decoration: none; border-left: 3px solid transparent; }
.sidebar a:hover { background: var(--bg); }
.sidebar a.active { background: #eaf1fb; border-left-color: var(--navy); color: var(--navy); font-weight: 600; }
.content { flex: 1; padding: 16px 20px 40px; min-width: 0; }
.loading { color: var(--muted); padding: 20px; }
h1.page { font-size: 1.45rem; color: var(--navy); margin: 0 0 12px; }
h1.page small { font-weight: 400; color: var(--muted); font-size: .8em; margin-left: 8px; }

/* ---------- кнопки, поля ---------- */
.btn { display: inline-block; padding: 8px 14px; border: 1px solid #b9c2cc; border-radius: 8px; background: #fff; color: #222; cursor: pointer; text-decoration: none; line-height: 1.2; }
.btn:hover { background: #f0f3f6; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy2); }
.btn.danger { color: var(--bad); border-color: #e0b4b4; }
.btn.small { padding: 4px 10px; font-size: .9rem; }
.btn.wide { width: 100%; margin-top: 14px; padding: 11px; }
.btn[disabled] { opacity: .45; cursor: default; }
.bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.bar .spacer { flex: 1; }
.bar input, .bar select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.bar input[type=text], .bar input[type=search] { min-width: 220px; }
.hint { color: var(--muted); font-size: .9rem; }

/* ---------- таблицы (сетка как в Домино) ---------- */
.tbl-wrap { overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; }
table.grid { border-collapse: collapse; width: 100%; font-size: .95rem; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; white-space: nowrap; }
table.grid th { background: var(--head); position: sticky; top: 0; z-index: 1; font-weight: 600; }
table.grid td.n, table.grid th.n { text-align: right; font-variant-numeric: tabular-nums; }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover { background: #f5f8fc; }
table.grid tr.st0 td { color: #666; }
table.grid tr.st1 td { color: var(--ok); }
table.grid td.wrap { white-space: normal; min-width: 220px; }
table.grid input { width: 90px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; text-align: right; }
.footer-line { margin-top: 8px; font-weight: 600; }
.count { color: var(--muted); margin-top: 6px; font-size: .9rem; }

/* ---------- документ / карточка ---------- */
.card { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px 22px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: .9rem; color: #444; }
.form label > input, .form label > select, .form label > textarea { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 1rem; }
.form label.full { grid-column: 1 / -1; }
.form .ro { padding: 7px 0; font-weight: 600; }
.form input:disabled, .form select:disabled, .form textarea:disabled { background: #f3f5f7; color: #555; }
.doc-head { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: baseline; margin-bottom: 8px; }
.doc-head .num { font-size: 1.35rem; font-weight: 700; color: var(--navy); }
.doc-head .who { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.note { background: #fff8e6; border: 1px solid #f0d99b; border-radius: 8px; padding: 8px 12px; margin: 8px 0; color: #6b5200; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 10px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 12px; cursor: pointer; color: #444; }
.tabs button.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }
.picker { position: relative; display: flex; gap: 6px; align-items: center; }
.picker input[type=search] { flex: 1; min-width: 0; }   /* подбор товара — на всю ширину строки, 📷 рядом */
.picker .drop { position: absolute; left: 0; right: 0; top: 100%; z-index: 15; background: #fff; border: 1px solid var(--line); border-radius: 8px; max-height: 300px; overflow: auto; box-shadow: 0 6px 18px rgba(0,0,0,.12); }
.picker .drop div { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid #eee; }
.picker .drop div:hover { background: var(--sel); }
.picker .drop small { color: var(--muted); }

/* ---------- всплывашки, модалки ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #222; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 14px rgba(0,0,0,.25); max-width: 380px; white-space: pre-line; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--bad); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-box { background: #fff; border-radius: 12px; padding: 20px 22px; width: min(520px, 94vw); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal-box h3 { margin: 0 0 10px; color: var(--navy); }
.modal-box textarea { width: 100%; min-height: 90px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.modal-box .actions { justify-content: flex-end; }
.modal-box .pre { white-space: pre-line; }

/* ---------- адаптив ---------- */
@media (max-width: 900px) {
  .burger { display: block; }
  .sidebar { position: fixed; top: 52px; left: 0; bottom: 0; height: auto; transform: translateX(-100%); transition: transform .2s; z-index: 30; overflow: auto; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .sidebar.open { transform: none; }
  .content { padding: 12px; }
  .crumb { display: none; }
  .topbar .user { display: none; }
}
/* ---------- печать ---------- */
/* ---- справка (ISSUE-186) */
.help-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.help-bar input { flex: 1 1 260px; max-width: 520px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; }
.help { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
.help-toc { position: sticky; top: 64px; max-height: calc(100vh - 80px); overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.help-toc a { display: block; padding: 6px 8px; border-radius: 6px; color: var(--navy); text-decoration: none; font-size: .95rem; }
.help-toc a:hover { background: var(--head); }
.help-toc a.active { background: var(--sel); font-weight: 600; }
.help-toc a.hidden, .help-body section.hidden { display: none; }
.help-body { min-width: 0; }
.help-body section { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 14px 20px 16px; margin-bottom: 14px; overflow-wrap: anywhere; }
.help-body h2 { font-size: 1.25rem; color: var(--navy); margin: 0 0 10px; }
.help-body h3 { font-size: 1.05rem; color: var(--navy2); margin: 16px 0 6px; }
.help-body p { margin: 6px 0; line-height: 1.5; max-width: 78ch; }
.help-body ol, .help-body ul { margin: 6px 0; padding-left: 22px; line-height: 1.5; max-width: 78ch; }
.help-body li { margin: 3px 0; }
.help-body .tbl-wrap { margin: 8px 0; }
.help-body table.grid td { white-space: normal; vertical-align: top; }
.help-body kbd { border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: #f7f8fa; font: inherit; font-size: .9em; }
.help-body .tip { background: #eef6ee; border: 1px solid #b9d8b9; border-radius: 8px; padding: 8px 12px; margin: 8px 0; max-width: 78ch; }
.help-body .warn { background: #fff8e6; border: 1px solid #f0d99b; border-radius: 8px; padding: 8px 12px; margin: 8px 0; color: #6b5200; max-width: 78ch; }
.help-who { margin-bottom: 10px; }
mark.hp { background: #ffe58a; padding: 0 1px; border-radius: 2px; }
@media (max-width: 900px) {
  .help { display: block; }
  .help-toc { position: static; max-height: none; margin-bottom: 12px; columns: 2; column-gap: 6px; }
  .help-toc a { break-inside: avoid; }
  .help-body section { padding: 12px 14px; }
}
@media (max-width: 520px) { .help-toc { columns: 1; } }
@media print {
  .help-toc, .help-who { display: none !important; }
  .help { display: block; }
  .help-body section { border: 0; padding: 0; }
  .help-body h2 { break-after: avoid; }
}
@media print {
  .topbar, .sidebar, .actions, .bar, #toasts, .modal { display: none !important; }
  .content { padding: 0; }
  .tbl-wrap { border: 0; overflow: visible; }
  table.grid th { position: static; }
  body { background: #fff; }
}

/* меню печати документа (простая форма + госформы по шаблонам) */
.menu-list { display: flex; flex-direction: column; gap: 6px; }
.menu-list .btn { text-align: left; }

/* сканер штрихкода камерой (кнопка у полей поиска, окно с видео) */
.btn.scan { padding: 6px 9px; font-size: 16px; line-height: 1; }
.scanbox { position: relative; width: 100%; background: #000; border-radius: 8px; overflow: hidden; }
.scanbox video { width: 100%; max-height: 60vh; display: block; }
.scanline { position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: rgba(255,80,80,.85); box-shadow: 0 0 8px rgba(255,80,80,.9); }

/* конструктор отчётов */
.qgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 900px) { .qgrid { grid-template-columns: 1fr; } }
.qcol { display: flex; flex-direction: column; }
.qlbl { font-size: 12px; color: var(--muted); margin: 6px 0 3px; font-weight: 600; }
.qchips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 5px 10px; border: 1px solid var(--line); border-radius: 14px; background: #fff; cursor: pointer; font-size: 13px; user-select: none; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.qrow { display: flex; gap: 6px; }
.qrow input { flex: 1; }

/* ---------- цвета строк документов (легенда, как в «Домино») ---------- */
table.grid tr.c-grey td { color: #666; }
table.grid tr.c-green td { color: var(--ok); }
table.grid tr.c-red td { color: var(--bad); font-weight: 600; }
table.grid tr.c-crimson td { color: #b5006f; font-weight: 600; }
table.grid tr.c-yellow td { background: #fff9c4; color: #5a4a00; }
.legend div { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.legend .sw { display: inline-block; width: 26px; height: 16px; border: 1px solid #999; border-radius: 3px; }
.legend .sw.c-red { background: var(--bad); } .legend .sw.c-crimson { background: #b5006f; } .legend .sw.c-yellow { background: #fff176; }
.legend .sw.c-green { background: var(--ok); } .legend .sw.c-grey { background: #999; }
.deplist { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 4px 12px; max-height: 50vh; overflow: auto; margin: 8px 0; }
.deplist label { display: flex; gap: 6px; align-items: center; padding: 4px 2px; cursor: pointer; }
.form .deplist label { flex-direction: row; font-size: 1rem; color: inherit; }   /* галочки подразделений в карточке пользователя */
.badge.flag { background: #e3f2fd; color: #0d47a1; font-weight: 500; }
.badge.flag.bad { background: #fce4ec; color: #880e4f; }
.note.bad { background: #fdecea; border-color: #f5b5b0; color: #8a1c14; }
.note.ok { background: #e8f5e9; border-color: #b7dfb9; color: #1b5e20; }
.form input.n { text-align: right; }
.modal-box.wide { width: min(1100px, 96vw); }
h1.page small { white-space: normal; }

/* вложения и встроенный редактор Collabora */
.fbtns { white-space: nowrap; } .fbtns .btn { margin-right: 4px; }
.modal-box.office-box { width: 96vw; height: 94vh; padding: 8px 10px; display: flex; flex-direction: column; }
.office-head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
iframe.office { flex: 1; width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* ---- приёмка перемещения (этап 2): цвет строки = отмечено / сошлось / не сошлось ---- */
table.recv tr.rv-ok td { background: #eaf7ee; }
table.recv tr.rv-bad td { background: #fdecec; }
table.recv tr.rv-none td { background: #fffbe8; }
table.recv input[data-k=qty2] { width: 70px; font-size: 1.05rem; text-align: right; }
table.recv .sm { display: none; }
.rv-btns { white-space: nowrap; }
.rv-btns .btn { min-width: 34px; margin-left: 4px; }
.rv-chk { display: inline-flex; gap: 4px; align-items: center; margin-right: 4px; }
.form.sides { margin-top: 10px; }
.rowin { display: flex; gap: 6px; }
.rowin input { flex: 1; min-width: 0; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 1rem; }
@media (max-width: 700px) {          /* приёмка на телефоне: без кода и цены, чтобы «Принято» и ± влезали */
  table.recv th:nth-child(2), table.recv td:nth-child(2), table.recv th:nth-child(7), table.recv td:nth-child(7) { display: none; }
  table.recv input[data-k=qty2] { width: 48px; }
  table.recv td, table.recv th { padding: 4px 5px; }
  table.recv td.wrap { min-width: 0; font-size: .9rem; }
  table.recv th { white-space: normal; font-size: .8rem; }
  .rv-btns .btn { min-width: 30px; margin-left: 2px; padding: 4px 6px; }
  table.recv .lg { display: none; }
  table.recv .sm { display: inline; }
  .rv-btns [data-d="-1"] { display: none; }   /* уменьшить — в поле «Принято», чтобы строка влезала */
  table.recv td:nth-child(1), table.recv th:nth-child(1) { padding: 4px 3px; }
  .rv-chk { font-size: 0; }           /* на узком экране — только галочка */
  .rv-chk input { font-size: 1rem; }
}

/* счётчик «ждёт меня» в меню (корзины, разборы, отправка, приёмка) */
#sidebar a .cnt { display: inline-block; min-width: 20px; margin-left: 6px; padding: 0 6px; border-radius: 10px; background: #c62828; color: #fff; font-size: .78rem; text-align: center; line-height: 18px; }

/* ---- установка цен (этап 4) ---- */
table.prices tr.sel td { background: #e6efff; }
table.prices tr.cur td:first-child { box-shadow: inset 3px 0 0 #1f5fbf; }
table.prices tr.fixed td { color: #888; }
table.prices td.up { color: #1b7a2e; } table.prices td.down { color: #b3261e; }
table.prices input[data-pn] { width: 100px; font-weight: 600; }
.differ { font-size: .75rem; color: #a86a00; border: 1px solid #e0c080; border-radius: 6px; padding: 0 4px; cursor: help; }
table.rules select { max-width: 220px; } table.rules input { width: 80px; } .nowrap { white-space: nowrap; }
#modalBox .tabs { margin-bottom: 8px; }
table.prices { min-width: 900px; }
.card .bar .picker { min-width: 260px; }

/* приход: расхождение накладной и факта (кол-во или цена), бонусная строка */
table.grid tr.mism td { background: #fdecec; }
table.grid tr.bonusrow td { color: #1b5e20; }
table.grid td.c { text-align: center; }

.bc-add { margin-top: 10px; }
.bc-add input[type=text] { min-width: 300px; }
