:root {
  --bg: #f4f5f0;
  --panel: #ffffff;
  --ink: #1f2a1c;
  --muted: #6b7466;
  --line: #dfe3d8;
  --brand: #3d6b2f;
  --brand-2: #5a8f45;
  --brand-soft: #e7f0e1;
  --warn: #b7791f;
  --warn-soft: #fdf3dc;
  --bad: #b23b31;
  --bad-soft: #fbe6e3;
  --ok: #2f7a3a;
  --ok-soft: #e2f3e4;
  --info-soft: #e6eef8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; line-height: 1.4; }
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; background: #fff; min-height: 34px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: -1px; border-color: transparent; }
input[type=checkbox] { min-height: 0; width: 18px; height: 18px; accent-color: var(--brand); vertical-align: middle; }
textarea { width: 100%; min-height: 90px; }
label { display: inline-flex; gap: 6px; align-items: center; }
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 12px; cursor: pointer; min-height: 34px; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: #e6b9b4; }
.btn.small { padding: 2px 8px; min-height: 26px; font-size: .85rem; }
.btn.link { border: none; background: none; color: var(--brand); padding: 0 4px; min-height: 0; text-decoration: underline; }
.btn[disabled] { opacity: .55; cursor: default; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.spread { justify-content: space-between; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* ---------- каркас */
.layout { display: flex; min-height: 100vh; }
.side { width: 220px; background: #24331f; color: #e8eee3; flex-shrink: 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .logo { padding: 16px 16px 10px; font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.side .logo small { display: block; font-weight: 400; color: #a9b8a1; font-size: .8rem; margin-top: 2px; }
.side nav a { display: block; padding: 8px 16px; color: #dfe7d9; text-decoration: none; border-left: 3px solid transparent; }
.side nav a:hover { background: rgba(255,255,255,.06); }
.side nav a.active { background: rgba(255,255,255,.1); border-left-color: #9fd17f; color: #fff; }
.side nav .sep { height: 1px; background: rgba(255,255,255,.1); margin: 6px 12px; }
.side .me { margin-top: auto; padding: 12px 16px; font-size: .85rem; color: #b8c6b0; border-top: 1px solid rgba(255,255,255,.1); }
.side .me button { color: #dfe7d9; border-color: rgba(255,255,255,.25); background: transparent; margin-top: 6px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { padding: 18px 22px 10px; flex: 1; min-width: 0; }
footer.foot { padding: 10px 22px 16px; color: var(--muted); font-size: .8rem; }

@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; background: #24331f; color: #fff; padding: 8px 12px; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 7px; padding: 4px 10px; }
  .content { padding: 12px 12px 8px; }
  footer.foot { padding: 8px 12px 14px; }
}

/* ---------- панели, карточки */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.card .k { color: var(--muted); font-size: .8rem; }
.card .v { font-size: 1.25rem; font-weight: 650; margin-top: 2px; }
.card .s { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.card.good { background: var(--ok-soft); border-color: #bcdcc1; }
.card.warn { background: var(--warn-soft); border-color: #ecd49d; }
.card.bad { background: var(--bad-soft); border-color: #e9bdb7; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .sp { flex: 1; }
.toolbar select, .toolbar input { max-width: 100%; }
@media (max-width: 600px) { .toolbar #store { flex: 1 1 100%; order: -1; } }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs button { border: none; background: none; padding: 8px 12px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs button.active { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 20px; font-size: .75rem; background: #eef0ea; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: #2d5b8f; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--info-soft); margin: 8px 0 12px; }
.note.warn { background: var(--warn-soft); }
.note.bad { background: var(--bad-soft); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- таблицы */
.tw { overflow: auto; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; max-height: calc(100vh - 210px); }
.tw.free { max-height: none; }
table.t { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: middle; background: #fff; }
table.t th { position: sticky; top: 0; z-index: 2; background: #f0f2ec; font-weight: 600; font-size: .82rem; color: #3e4a39; white-space: nowrap; }
table.t td.num, table.t th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.t .sticky { position: sticky; left: 0; z-index: 1; }
table.t th.sticky { z-index: 3; }
table.t tr.total td { font-weight: 650; background: #f6f8f3; }
table.t tr.sub td { background: #fafbf8; }
table.t tr:hover td { background: #fafcf7; }
table.t tr.locked td { background: #f7f8f5; }
table.t tr.daystart td { border-top: 2px solid #cfd6c7; }
table.t tr.weekend td.sticky { color: var(--bad); }
table.t tr.clickable { cursor: pointer; }
table.t td input:not([type=checkbox]), table.t td select { min-height: 28px; padding: 3px 6px; width: 100%; border-color: transparent; background: transparent; }
table.t td input:not([type=checkbox]):hover, table.t td select:hover { border-color: var(--line); background: #fff; }
table.t td input:focus { background: #fff; }
table.t td input[disabled] { color: var(--ink); }
table.t td.c-name { min-width: 190px; }
table.t td.c-phone { min-width: 165px; }
table.t td.c-w { width: 70px; }
table.t td.c-money { min-width: 105px; }
table.t td.c-cm { min-width: 150px; }
td.pos { color: var(--ok); }
td.neg { color: var(--bad); }
.st { width: 22px; text-align: center; font-size: .9rem; }
.st .saving { color: var(--muted); }
.st .ok { color: var(--ok); }
.st .err { color: var(--bad); cursor: help; }
.paycell { text-align: left; cursor: pointer; white-space: nowrap; min-width: 140px; padding: 3px 6px; border-radius: 6px; border: 1px dashed transparent; }
.paycell:hover { border-color: var(--line); background: #fff; }
.paycell.empty { color: #9aa394; }
.docs { display: inline-flex; gap: 3px; }
.docs span { display: inline-block; width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 5px; font-size: .72rem; background: #eef0ea; color: #9aa394; cursor: pointer; user-select: none; }
.docs span.on { background: var(--ok-soft); color: var(--ok); font-weight: 700; }
.docs.ro span { cursor: default; }
.collapse-h { cursor: pointer; user-select: none; padding: 8px 10px; background: #eef1ea; border-radius: 8px; margin: 10px 0 6px; font-weight: 600; display: flex; justify-content: space-between; }
.collapse-h > span:first-child::before { content: '▸ '; }
.collapse-h.open > span:first-child::before { content: '▾ '; }

/* ---------- автоподсказка */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 50; left: 0; top: 100%; min-width: 280px; max-height: 280px; overflow: auto; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.ac-list div { padding: 6px 10px; cursor: pointer; }
.ac-list div:hover, .ac-list div.hl { background: var(--brand-soft); }
.ac-list div small { color: var(--muted); margin-left: 6px; }

/* ---------- окна */
.modal-bg { position: fixed; inset: 0; background: rgba(20,30,15,.4); z-index: 2000; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.25); width: 100%; max-width: 520px; padding: 18px; }
.modal.wide { max-width: 920px; }
.modal h2 { margin-top: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.form { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; align-items: center; }
.form > label { justify-content: flex-start; color: var(--muted); font-size: .9rem; }
.form input, .form select { width: 100%; }
@media (max-width: 520px) { .form { grid-template-columns: 1fr; } }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: none; background: #fff; padding: 6px 12px; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: none; }
.seg button.on { background: var(--brand); color: #fff; }

/* ---------- уведомления */
#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 2100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 28px)); }
.toast { background: #24331f; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }

/* ---------- сводка дня */
.day-group { margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border-radius: 8px; padding: 5px 9px; font-size: .85rem; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.chip b { margin-right: 4px; }
.chip.ok { background: var(--ok-soft); border-color: #bcdcc1; }
.chip.contract { background: var(--info-soft); border-color: #c3d4ea; }
.chip.nofarmer { background: var(--warn-soft); border-color: #ecd49d; }
.chip.nofact { background: #fff7e6; border-color: #f0dcae; }
.chip.empty { background: var(--bad-soft); border-color: #e9bdb7; }
.bar { height: 8px; background: #e7eae2; border-radius: 6px; overflow: hidden; min-width: 80px; }
.bar > i { display: block; height: 100%; background: var(--brand-2); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }

/* ---------- сетка супер-лент */
table.grid td.d, table.grid th.d { width: 26px; min-width: 26px; padding: 3px 2px; text-align: center; font-size: .75rem; }
table.grid td.d.on { background: #cfe8c4; }
table.grid td.d.prev { background: #e9f3e4; }

/* ---------- вход */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, #e9efe2, #f6f4ea); }
.login { background: #fff; border-radius: 14px; padding: 26px; width: 100%; max-width: 360px; box-shadow: 0 10px 40px rgba(0,0,0,.08); }
.login h1 { text-align: center; }
.login .sub { text-align: center; color: var(--muted); margin: -6px 0 18px; font-size: .9rem; }
.login input { width: 100%; margin-bottom: 10px; }
.login .btn { width: 100%; }
.login .err { color: var(--bad); min-height: 1.3em; margin-bottom: 6px; font-size: .9rem; }
.login .ver { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 14px; }

@media print { .side, .topbar, .toolbar, footer.foot { display: none !important; } .tw { max-height: none; border: none; } }
#map { isolation: isolate; }
/* номера магазинов на карте */
.mk-wrap { background: none; border: none; }
.mk { display: inline-block; transform: translate(-50%, -50%); padding: 1px 5px; border-radius: 9px; color: #fff; font: 600 11px/15px system-ui, sans-serif;
  white-space: nowrap; border: 1.5px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.45); cursor: pointer; }
.mk.mk-approx { border-style: dashed; border-color: #222; }
.mk.mk-edit { cursor: move; outline: 2px solid rgba(0,0,0,.35); }
