/* ТоргУчёт — тема и общие компоненты. Токены и вид карточки ленты — из утверждённого
   прототипа frontend/prototype/feed.html. Цвета — только переменными темы. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --text: #1d2433;
  --muted: #667085;
  --accent: #2f6fed;
  --accent-soft: #e8f0fe;
  --plus: #12805c;
  --minus: #c4321c;
  --minus-soft: #fdecea;
  --ok: #12805c;
  --ok-soft: #e6f4ee;
  --primary: #12805c;
  --primary-hover: #0e6b4c;
  --on-primary: #ffffff;
  --wait: #475467;
  --wait-soft: #eef0f3;
  --alert: #a15c07;
  --alert-soft: #fdf1e3;
  --on-alert: #ffffff;
  --overlay: rgba(16, 24, 40, .35);
  --skeleton: #e9ecf1;
  --radius: 12px;
  --radius-s: 8px;
  --control: 36px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-pop: 0 10px 28px rgba(16, 24, 40, .16);
  --topbar: 56px;
  --tabbar: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151b; --surface: #1a1f27; --surface-2: #20262f; --line: #2c333e; --line-strong: #3a4250;
    --text: #e8ebf0; --muted: #98a2b3; --accent: #6b9bff; --accent-soft: #1f2b44;
    --plus: #4cc38a; --minus: #ff7a66; --minus-soft: #3a1f1a; --ok: #4cc38a; --ok-soft: #173126;
    --primary: #2f9e74; --primary-hover: #37b083; --on-primary: #ffffff;
    --wait: #b4bcc8; --wait-soft: #262c35; --alert: #f0a54a; --alert-soft: #3a2a14; --on-alert: #1d1407;
    --overlay: rgba(0, 0, 0, .55); --skeleton: #262c35; --shadow: none; --shadow-pop: 0 10px 28px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151b; --surface: #1a1f27; --surface-2: #20262f; --line: #2c333e; --line-strong: #3a4250;
  --text: #e8ebf0; --muted: #98a2b3; --accent: #6b9bff; --accent-soft: #1f2b44;
  --plus: #4cc38a; --minus: #ff7a66; --minus-soft: #3a1f1a; --ok: #4cc38a; --ok-soft: #173126;
  --primary: #2f9e74; --primary-hover: #37b083; --on-primary: #ffffff;
  --wait: #b4bcc8; --wait-soft: #262c35; --alert: #f0a54a; --alert-soft: #3a2a14; --on-alert: #1d1407;
  --overlay: rgba(0, 0, 0, .55); --skeleton: #262c35; --shadow: none; --shadow-pop: 0 10px 28px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- основа ---------- */
* { box-sizing: border-box; }
html { scrollbar-gutter: stable; -webkit-text-size-adjust: 100%; }
html.has-layer { overflow: hidden; }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.muted { color: var(--muted); }
.warn { color: var(--alert); }
.icon { flex: none; display: block; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- кнопки ---------- */
.btn {
  height: var(--control); padding: 0 14px; border-radius: var(--radius-s); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-weight: 500; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none;
  transition: background-color .12s, border-color .12s, color .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--line-strong); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); border-color: transparent; }
.btn-danger { color: var(--minus); border-color: var(--line); }
.btn-danger:hover:not(:disabled) { background: var(--minus-soft); border-color: var(--minus); }
.btn:disabled { opacity: .4; }
.btn[aria-busy="true"] { opacity: .6; cursor: progress; }
.two-step { display: inline-grid; place-items: center; }
.two-step > span { grid-area: 1 / 1; }
.two-step .ts-second { visibility: hidden; }
.two-step.armed .ts-first { visibility: hidden; }
.two-step.armed .ts-second { visibility: visible; }
.two-step.armed, .two-step.armed:hover:not(:disabled) { background: var(--alert); border-color: var(--alert); color: var(--on-alert); }
.btn-inline { height: auto; min-height: 0; padding: 0 2px; border: 0; }
.icon-btn {
  width: var(--control); height: var(--control); flex: none; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); display: grid; place-items: center; color: var(--muted); padding: 0;
}
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* ---------- оболочка ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--topbar); padding: 0 20px;
  display: flex; align-items: center; gap: 16px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.logo { font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: var(--text); text-decoration: none; flex: none; }
.logo span { color: var(--accent); }
.nav { display: flex; gap: 4px; margin-left: 12px; min-width: 0; }
.nav a {
  height: var(--control); padding: 0 12px; border-radius: 8px; color: var(--muted); text-decoration: none;
  display: inline-flex; align-items: center; white-space: nowrap;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.has-company-switch { --topbar: 104px; }
.has-company-switch .topbar { position: static; height: 56px; }
.topbar-stack { position: sticky; top: 0; z-index: 20; }
.company-bar {
  height: 48px; padding: 4px 12px; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.company-bar > .combo { flex: 1; min-width: 0; max-width: 640px; }
.org-switch {
  height: var(--control); padding: 0 10px 0 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 280px;
}
.org-switch:hover { background: var(--surface-2); }
.org-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-btn { border: 0; background: none; padding: 2px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.avatar {
  position: relative; overflow: hidden;
  width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 600; color: #fff; line-height: 1; letter-spacing: .02em;
}
.avatar-photo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; }
.page { max-width: 1240px; margin: 0 auto; padding: 20px; }
.page-narrow { max-width: 900px; }
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-titles { flex: 1 1 260px; min-width: 0; }
.page-head h1 { font-size: 22px; line-height: 1.25; font-weight: 650; }
.page-sub { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.boot { padding: 80px 20px; display: grid; place-items: center; color: var(--muted); }

.tabbar { display: none; }

/* ---------- чипы ---------- */
.chips { position: relative; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; margin: -2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  height: 32px; padding: 0 12px; flex: none; border: 1px solid var(--line); border-radius: 16px;
  background: var(--surface); color: var(--text); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip:hover { border-color: var(--line-strong); }
.chip[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: var(--surface); }
.chip .count {
  min-width: 28px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 12px; font-weight: 600;
  display: inline-grid; place-items: center; background: var(--wait-soft); color: var(--wait);
  font-variant-numeric: tabular-nums;
}
.chip.chip-alert { border-color: var(--alert); }
.chip.chip-alert .count { background: var(--alert-soft); color: var(--alert); }
.chip[aria-pressed="true"] .count { background: var(--surface); color: var(--text); }
.chip-toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---------- лента ---------- */
.feed-layout {
  max-width: 1240px; margin: 0 auto; padding: 20px;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start;
}
.feed-layout.no-side { grid-template-columns: minmax(0, 820px); justify-content: center; }
.feed-main { min-width: 0; max-width: 860px; }
.composer {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.composer-input {
  flex: 1 1 120px; min-width: 0; height: 40px; border: 0; background: none; outline: none; padding: 0 4px;
}
.composer .icon-btn { width: 40px; height: 40px; }
.composer .btn-primary { height: 40px; padding: 0 16px; }
.composer-file {
  flex: 1 0 100%; order: 3; display: flex; align-items: center; gap: 8px; min-width: 0;
  padding: 6px 8px 6px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13px;
}
.composer-file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.composer-file .icon-btn { width: 28px; height: 28px; border: 0; background: none; }
.composer-hint { margin: 8px 4px 0; font-size: 12px; color: var(--muted); }
.feed-tools { display: flex; align-items: center; gap: 12px; margin: 16px 0 4px; }
.feed-tools .chips { flex: 1; min-width: 0; }
.feed-tools .btn { height: 32px; border-radius: 16px; padding: 0 12px; }
.new-plaque {
  position: sticky; top: calc(var(--topbar) + 8px); z-index: 5; display: flex; justify-content: center;
  height: 0; overflow: visible;
}
.new-plaque button {
  height: 32px; padding: 0 14px; border-radius: 16px; border: 0; background: var(--accent); color: #fff;
  font-weight: 600; box-shadow: var(--shadow-pop);
}
.day { margin: 20px 4px 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.feed-more { display: flex; justify-content: center; margin: 16px 0; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 10px; overflow: hidden;
}
.card.state-attention { border-left: 3px solid var(--alert); }
.card.state-waiting { border-left: 3px solid var(--wait); }
.card.state-cancelled, .card.state-dismissed { opacity: .6; }
.card.is-flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--surface); } }
.card-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px 0; }
.who { min-width: 0; flex: 1; }
.who-line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who b { font-weight: 600; }
.who .meta { font-size: 12px; color: var(--muted); }
.channel {
  height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; display: inline-flex; align-items: center;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); flex: none; white-space: nowrap;
}
.said {
  margin: 10px 14px 0; padding: 8px 12px; border-radius: 10px; background: var(--surface-2);
  font-size: 13px; display: flex; gap: 10px; align-items: center; min-width: 0;
}
.said-body { min-width: 0; flex: 1; display: grid; gap: 2px; }
.said-text {
  overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  cursor: default;
}
.said-text.is-open { -webkit-line-clamp: unset; display: block; }
.said-file { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.said-reply { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-btn { border: 0; padding: 0; background: none; flex: none; border-radius: 6px; }
.doc-thumb {
  width: 36px; height: 44px; flex: none; border-radius: 4px; border: 1px solid var(--line); overflow: hidden;
  display: grid; place-items: center; color: var(--muted); position: relative;
  background: repeating-linear-gradient(180deg, var(--surface) 0 5px, var(--line) 5px 6px);
}
.doc-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.doc-thumb.has-img .icon { visibility: hidden; }
.doc-thumb-large { width: 100%; height: 180px; border-radius: 10px; }
.doc-thumb-large img { object-fit: contain; background: var(--surface); }
.said-large { margin: 0; flex-direction: column; align-items: stretch; }
.said-large .doc-btn { width: 100%; }
.ops { display: grid; }
.op {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; padding: 12px 14px; align-items: center;
}
.op + .op { border-top: 1px dashed var(--line); }
.op.is-link { cursor: pointer; }
.op.is-link:hover { background: var(--surface-2); }
.op.is-cancelled .op-title, .op.is-cancelled .amount-value { text-decoration: line-through; text-decoration-color: var(--muted); }
.op-main { min-width: 0; }
.op-type { font-size: 12px; font-weight: 600; color: var(--accent); text-transform: uppercase; letter-spacing: .03em; }
.op-flag {
  margin-left: 8px; font-size: 11px; text-transform: none; letter-spacing: 0; font-weight: 600; color: var(--wait);
  background: var(--wait-soft); border-radius: 8px; padding: 1px 6px;
}
.op-title { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.op-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.op-pending { grid-template-columns: minmax(0, 1fr); }
.amount { font-size: 16px; text-align: right; align-self: center; }
.amount small { display: block; font-size: 12px; font-weight: 500; color: var(--muted); white-space: normal; max-width: 200px; margin-left: auto; }
.status {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 14px; border-top: 1px solid var(--line); font-size: 13px;
}
.badge {
  height: 24px; padding: 0 10px; border-radius: 12px; font-size: 12px; font-weight: 600; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 4px; flex: none;
}
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-wait { background: var(--wait-soft); color: var(--wait); }
.badge-alert { background: var(--alert-soft); color: var(--alert); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.reason { flex: 1 1 220px; min-width: 0; overflow-wrap: anywhere; }
.tags { flex: 1 1 220px; min-width: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 12px; color: var(--muted); white-space: nowrap; }
.tag + .tag::before { content: "·"; margin-right: 6px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.skeleton-block { display: grid; gap: 8px; padding: 4px 0; }
.skeleton { height: 12px; border-radius: 6px; background: var(--skeleton); }
.feed-skeleton .card { padding: 14px; }

/* ---------- правая колонка ленты ---------- */
.side { position: sticky; top: calc(var(--topbar) + 20px); display: grid; gap: 12px; min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.panel h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 6px 0; min-width: 0; }
.kpi + .kpi { border-top: 1px dashed var(--line); }
.kpi-label { min-width: 0; }
.kpi-value { font-size: 16px; font-weight: 500; text-align: right; }
.kpi .note { display: block; font-size: 12px; color: var(--muted); }
.people { display: flex; flex-direction: column; gap: 8px; }
.person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.person-name { min-width: 0; flex: 1; }
.person-name b, .person-name div { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person-name div { font-size: 12px; color: var(--muted); }
.person .count { color: var(--muted); font-size: 13px; }

/* ---------- слои: окно, панель, лист ---------- */
.layer { position: fixed; inset: 0; z-index: 40; display: flex; }
.scrim { position: absolute; inset: 0; background: var(--overlay); }
.sheet {
  position: relative; background: var(--surface); display: flex; flex-direction: column; min-height: 0;
  box-shadow: var(--shadow-pop); outline: none;
}
.layer-drawer { justify-content: flex-end; }
.sheet-drawer { width: min(560px, 100%); height: 100%; border-left: 1px solid var(--line); }
.layer-modal { align-items: center; justify-content: center; padding: 24px; }
.sheet-modal { width: min(760px, 100%); max-height: 100%; border-radius: var(--radius); border: 1px solid var(--line); }
.sheet-modal.is-narrow { width: min(520px, 100%); }
.layer-sheet { align-items: center; justify-content: center; padding: 24px; }
.sheet-sheet { width: min(420px, 100%); max-height: 100%; border-radius: var(--radius); }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--line); flex: none; }
.sheet-titles { flex: 1; min-width: 0; padding-top: 6px; }
.sheet-title { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.sheet-sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.sheet-body {
  flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px 20px; display: grid; gap: 20px;
  align-content: start; grid-auto-rows: max-content; grid-template-columns: minmax(0, 1fr); overscroll-behavior: contain;
}
.sheet-foot {
  flex: none; padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; align-items: center;
  justify-content: flex-end; flex-wrap: wrap; box-shadow: 0 -6px 12px -10px rgba(16, 24, 40, .25); background: var(--surface);
}
.sheet-foot .form-error { flex: 1 0 100%; }
.foot-spacer { flex: 1; }
.section { display: grid; gap: 8px; min-width: 0; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 0; }
.facts { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; min-width: 0; }
.op-card-main { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.op-card-main .status { border-top: 1px solid var(--line); }
.moves { display: grid; gap: 8px; }
.move { display: flex; gap: 12px; align-items: baseline; justify-content: space-between; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); min-width: 0; }
.move-what { min-width: 0; }
.move-what b { display: block; font-size: 13px; font-weight: 600; overflow-wrap: anywhere; }
.move-what span { font-size: 12px; color: var(--muted); }
.history { display: grid; gap: 8px; font-size: 13px; }
.history-row { display: grid; grid-template-columns: 128px minmax(0, 1fr); gap: 10px; }
.history-row .who-small { color: var(--muted); }
.card-error { padding: 12px; border-radius: 10px; background: var(--alert-soft); color: var(--alert); }

/* ---------- приглашение в бота ---------- */
.invite-box { display: grid; gap: 8px; justify-items: start; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
.invite-box .muted { margin: 0; font-size: 13px; }
.invite-result { display: grid; gap: 6px; width: 100%; }
.invite-result:empty { display: none; }
.invite-line { display: flex; gap: 8px; align-items: center; min-width: 0; }
.invite-code { flex: 1; min-width: 0; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line);
  font-size: 13px; overflow-wrap: anywhere; user-select: all; }

/* ---------- тосты ---------- */
.toasts {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80;
  display: grid; gap: 8px; width: min(520px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 8px 10px 14px;
  border-radius: 10px; background: var(--text); color: var(--surface); box-shadow: var(--shadow-pop);
}
.toast-error { background: var(--minus); color: #fff; }
.toast-ok { background: var(--ok); color: #fff; }
.toast-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast .icon-btn { width: 28px; height: 28px; border: 0; background: transparent; color: inherit; opacity: .85; }

/* ---------- всплывающие панели, меню ---------- */
.popover {
  position: fixed; z-index: 70; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-pop); overflow: hidden;
}
.menu { display: grid; padding: 6px; max-height: min(70vh, 560px); overflow-y: auto; min-width: 240px; }
.menu-title { padding: 10px 10px 4px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.menu-item {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 6px 10px; border: 0; border-radius: 8px;
  background: none; text-align: left; width: 100%;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-2); outline: none; }
.menu-item .icon { color: var(--muted); }
.menu-text { flex: 1; min-width: 0; display: grid; }
.menu-label { overflow-wrap: anywhere; }
.menu-sub { font-size: 12px; color: var(--muted); }
.menu-check { color: var(--accent); }
.menu-head { padding: 10px 10px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu-head b { display: block; }
.menu-head span { font-size: 12px; color: var(--muted); }
.sheet-sheet .menu { padding: 0; min-width: 0; max-height: none; overflow: visible; }
.sheet-sheet .sheet-body { padding: 8px 12px 16px; }

/* ---------- поля ---------- */
.form-grid { display: flex; flex-wrap: wrap; gap: 14px 16px; align-items: flex-start; }
.field { display: grid; gap: 6px; min-width: 0; }
.field.w-s { flex: 0 1 180px; }
.field.w-m { flex: 1 1 240px; max-width: 360px; }
.field.w-l { flex: 1 1 320px; max-width: 520px; }
.field.w-full { flex: 1 0 100%; }
.field-label { font-size: 13px; font-weight: 500; color: var(--text); }
.field-label:empty { display: none; }
.req { color: var(--alert); }
.field-hint { font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; }
.field-error, .form-error { font-size: 13px; color: var(--minus); overflow-wrap: anywhere; }
.form-error { padding: 8px 12px; border-radius: 8px; background: var(--minus-soft); }
.field.has-error .control, .field.has-error .combo-btn { border-color: var(--minus); }
.field.has-error .field-hint { display: none; }
.control {
  width: 100%; height: var(--control); padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-s);
  background: var(--surface); color: var(--text); min-width: 0;
}
textarea.control { height: auto; min-height: 60px; padding: 8px 10px; resize: vertical; line-height: 1.4; }
.control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.control:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.control-date { max-width: 180px; }
.control::placeholder { color: var(--muted); opacity: .8; }
.num-input { text-align: right; font-variant-numeric: tabular-nums; }
.affix { position: relative; display: block; min-width: 0; }
.affix.has-suffix .num-input { padding-right: 28px; }
.affix-suffix { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.affix:focus-within .affix-suffix { visibility: hidden; }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: var(--control); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.multi { display: flex; flex-wrap: wrap; gap: 8px; }
.combo { position: relative; min-width: 0; }
.combo-btn { display: flex; align-items: center; gap: 8px; text-align: left; cursor: pointer; padding-right: 8px; }
.combo-btn:disabled { cursor: not-allowed; }
.combo-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-value.is-placeholder { color: var(--muted); }
.combo-arrow { color: var(--muted); flex: none; display: grid; }
.combo-pop { width: max-content; min-width: 240px; }
.combo-panel { display: grid; }
.combo-search { height: 40px; border: 0; border-bottom: 1px solid var(--line); padding: 0 12px; background: var(--surface); outline: none; }
.combo-list { max-height: 300px; overflow-y: auto; padding: 4px; overscroll-behavior: contain; }
.combo-opt { display: grid; padding: 7px 10px; border-radius: 6px; cursor: pointer; min-height: 36px; align-content: center; }
.combo-opt.is-active { background: var(--surface-2); }
.combo-opt.is-selected .combo-opt-label { color: var(--accent); font-weight: 600; }
.combo-opt.is-empty .combo-opt-label { color: var(--muted); }
.combo-opt.is-create .combo-opt-label { color: var(--accent); }
.combo-opt-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-opt-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-empty { padding: 10px; color: var(--muted); }
.search { position: relative; flex: 1 1 220px; max-width: 360px; min-width: 0; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input { padding-left: 32px; }
.draft-host:empty { display: none; }
.draft-plaque {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 12px; border-radius: 10px;
  background: var(--alert-soft); color: var(--text); border: 1px solid var(--alert);
}
.draft-text { flex: 1 1 240px; min-width: 0; }
.draft-summary { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.draft-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- строки товаров ---------- */
.lines { display: grid; gap: 6px; min-width: 0; }
.lines-head, .line-row { display: grid; gap: 8px; align-items: center; }
.lines-head.with-price, .line-row.with-price { grid-template-columns: minmax(0, 1fr) 96px 44px 130px 120px var(--control); }
.lines-head.no-price, .line-row.no-price { grid-template-columns: minmax(0, 1fr) 110px 44px var(--control); }
.lines-head { font-size: 12px; color: var(--muted); font-weight: 600; }
.lines-head .r { text-align: right; }
.lines-rows { display: grid; gap: 6px; }
.lc { min-width: 0; }
.lc-cap { display: none; }
.line-unit { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.line-sum { display: block; text-align: right; }
.line-remove { border-color: transparent; background: none; }
.lines-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-left: -8px; }
.lines-total { color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- форма операции ---------- */
.type-groups { display: grid; gap: 16px; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.type-btn {
  display: grid; gap: 2px; text-align: left; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); min-height: 44px;
}
.type-btn:hover { border-color: var(--accent); background: var(--accent-soft); }
.type-btn b { font-weight: 600; }
.type-btn span { font-size: 12px; color: var(--muted); }
.form-type { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.form-type b { font-weight: 600; }
.source-note { display: grid; gap: 6px; }

/* ---------- таблицы ---------- */
.table-wrap { min-width: 0; }
table.data {
  width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
table.data th, table.data td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
table.data th {
  position: sticky; top: var(--topbar); z-index: 2; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted);
  vertical-align: bottom; line-height: 1.3;
}
table.data thead tr:first-child th:first-child { border-top-left-radius: var(--radius); }
table.data thead tr:first-child th:last-child { border-top-right-radius: var(--radius); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tfoot td { border-top: 1px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); font-weight: 500; }
table.data tfoot td.primary .cell-main { font-weight: 600; }
table.data tfoot tr:last-child td:first-child { border-bottom-left-radius: var(--radius); }
table.data tfoot tr:last-child td:last-child { border-bottom-right-radius: var(--radius); }
table.data .r { text-align: right; }
table.data .r .cell-main { font-variant-numeric: tabular-nums; }
table.data td.primary .cell-main { font-weight: 600; }
.cell { min-width: 0; }
.cell-main { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data.is-clickable tbody tr { cursor: pointer; }
table.data.is-clickable tbody tr:hover td { background: var(--surface-2); }
table.data tr.is-inactive td .cell-main { color: var(--muted); }
.table-empty { padding: 32px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.table-tools { display: flex; align-items: center; gap: 10px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.table-count { color: var(--muted); font-size: 13px; white-space: nowrap; }

/* ---------- справочники ---------- */
.refs-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; align-items: start; }
.kind-list { display: grid; gap: 2px; position: sticky; top: calc(var(--topbar) + 20px); }
.kind-list a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: var(--control);
  padding: 6px 10px; border-radius: 8px; color: var(--text); text-decoration: none;
}
.kind-list a:hover { background: var(--surface); }
.kind-list a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.kind-list .count { color: var(--muted); font-size: 12px; font-weight: 400; font-variant-numeric: tabular-nums; }
.kind-chips { display: none; }
.refs-title { font-size: 18px; font-weight: 600; line-height: var(--control); }
.tag-chip { display: inline-block; font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 8px; padding: 0 6px; margin-left: 6px; font-weight: 400; vertical-align: 1px; }

/* ---------- отчёты ---------- */
.report-tabs { margin-bottom: 16px; }
.params { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: flex-end; margin-bottom: 16px; }
.params .field.w-s { flex: 0 0 170px; }
.params .field.w-m { flex: 0 1 260px; }
.report-body { display: grid; gap: 20px; min-width: 0; }
.report-body h2 { font-size: 15px; font-weight: 600; margin: 4px 0 -8px; }
.balance { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 16px; max-width: 560px; }
.balance-row { display: grid; grid-template-columns: minmax(0, 1fr) max-content; gap: 16px; padding: 10px 0; align-items: baseline; }
.balance-row + .balance-row { border-top: 1px dashed var(--line); }
.balance-row.total { border-top: 1px solid var(--line-strong); font-weight: 600; }
.balance-row .note { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.balance-row .num { font-size: 16px; }
.check-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.report-error { padding: 14px 16px; border-radius: var(--radius); background: var(--alert-soft); color: var(--alert); }

/* ---------- вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 24px; display: grid; gap: 16px;
}
.auth-card .logo { font-size: 22px; }
.auth-card h1 { font-size: 18px; font-weight: 600; }
.auth-card form { display: grid; gap: 14px; }
.auth-card .field.w-m { max-width: none; }
.auth-card .btn-primary { width: 100%; }
.auth-note { margin: 0; font-size: 13px; color: var(--muted); }
.auth-message { padding: 8px 12px; border-radius: 8px; background: var(--alert-soft); color: var(--alert); font-size: 13px; }

/* ---------- ввод остатков ---------- */
.steps { display: grid; gap: 12px; }
.step { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; }
.step h2 { font-size: 15px; font-weight: 600; display: flex; gap: 10px; align-items: center; }
.step-n { width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 13px; flex: none; }
.step p { margin: 0; color: var(--muted); }
.step-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.file-pick { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.file-pick-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); max-width: 100%; }
.summary-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.summary-chip { padding: 4px 10px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); font-size: 13px; }
.issues { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.issues li { padding: 8px 12px; border-radius: 8px; background: var(--alert-soft); overflow-wrap: anywhere; }
.issues.is-error li { background: var(--minus-soft); color: var(--text); }
.issues.is-info li { background: var(--surface); border: 1px solid var(--line); }
.ok-box { padding: 12px 14px; border-radius: 10px; background: var(--ok-soft); color: var(--ok); display: flex; gap: 8px; align-items: flex-start; }

/* ---------- пустое состояние ---------- */
.empty { display: grid; justify-items: center; gap: 8px; padding: 40px 16px; text-align: center; color: var(--muted); }
.empty-icon { width: 52px; height: 52px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); display: grid; place-items: center; }
.empty-title { margin: 4px 0 0; font-weight: 600; color: var(--text); font-size: 15px; }
.empty-text { margin: 0; max-width: 420px; }
.roles-info { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-top: 16px; }
.roles-info summary { cursor: pointer; font-weight: 600; min-height: 28px; display: flex; align-items: center; }
.roles-info dl { margin: 8px 0 0; display: grid; gap: 10px; }
.roles-info dt { font-weight: 600; }
.roles-info dd { margin: 2px 0 0; color: var(--muted); }

/* ---------- планшет и телефон: нижнее меню ---------- */
@media (max-width: 1023px) {
  .nav { display: none; }
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar button {
    border: 0; background: none; color: var(--muted); font-size: 11px; text-decoration: none; min-width: 0;
    display: grid; justify-items: center; align-content: center; gap: 2px; padding: 0 2px;
  }
  .tabbar span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar [aria-current="page"] { color: var(--accent); font-weight: 600; }
  .tabbar .icon { width: 22px; height: 22px; }
  .page, .feed-layout { padding-bottom: calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); }
  .toasts { bottom: calc(var(--tabbar) + 12px + env(safe-area-inset-bottom)); }
  .feed-layout { grid-template-columns: minmax(0, 1fr); padding-top: 12px; gap: 12px; }
  .feed-layout.no-side { grid-template-columns: minmax(0, 1fr); }
  .feed-main { max-width: none; }
  .side { position: static; order: -1; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr); overflow-x: auto; scrollbar-width: none; }
  .side::-webkit-scrollbar { display: none; }
  .side .people-panel { display: none; }
  .refs-layout { grid-template-columns: minmax(0, 1fr); }
  .kind-list { display: none; }
  .kind-chips { display: flex; margin-bottom: 12px; }
}

@media (max-width: 599px) {
  :root { --control: 44px; }
  .topbar { padding: 0 12px; gap: 10px; }
  .page, .feed-layout { padding-left: 12px; padding-right: 12px; padding-top: 12px; }
  .page-head h1 { font-size: 19px; }
  .panel { padding: 12px 14px; }
  .side { grid-auto-columns: 82%; }
  .composer { padding: 6px; gap: 6px; }
  .composer-input, .composer .icon-btn, .composer .btn-primary { height: 44px; }
  .composer-input { padding: 0 2px; text-overflow: ellipsis; }
  .composer .icon-btn { width: 44px; }
  .composer .btn-primary { padding: 0 10px; }
  .org-switch { max-width: 150px; }
  .feed-tools { gap: 8px; }
  .chip, .feed-tools .btn { height: 44px; border-radius: 22px; }
  .feed-tools .btn { width: 44px; padding: 0; }
  .feed-tools .btn .btn-label { display: none; }
  .chips { mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); padding-right: 24px; }
  .card-head { padding: 12px 12px 0; }
  .said { margin: 10px 12px 0; }
  .op { padding: 12px; gap: 4px 12px; }
  .status { padding: 10px 12px; }
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 0; }
  .amount small { max-width: 130px; }
  /* окна и панели — на весь экран */
  .layer-modal, .layer-sheet { padding: 0; align-items: stretch; }
  .sheet-modal, .sheet-drawer { width: 100%; height: 100%; max-height: none; border-radius: 0; border: 0; }
  .layer-sheet { align-items: flex-end; }
  .sheet-sheet { width: 100%; max-height: 85vh; border-radius: var(--radius) var(--radius) 0 0; }
  .sheet-head { padding: 10px 12px 10px 16px; }
  /* длинное описание вида операции — две строки, полностью видно в подсказке */
  .sheet-sub { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  /* сообщения сверху: внизу на телефоне закреплены кнопки окон и меню */
  .toasts { top: calc(12px + env(safe-area-inset-top)); bottom: auto; }
  .sheet-body { padding: 14px 16px 20px; }
  .sheet-foot { padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
  .sheet-foot .btn { flex: 1 1 auto; }
  .foot-spacer { display: none; }
  .facts { grid-template-columns: 112px minmax(0, 1fr); }
  .history-row { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .field.w-s, .field.w-m, .field.w-l { flex: 1 1 100%; max-width: none; }
  .control-date { max-width: none; }
  .params .field.w-s, .params .field.w-m { flex: 1 1 140px; }
  .search { max-width: none; flex-basis: 100%; }
  .menu-item { min-height: 48px; }
  /* строки товаров — карточками */
  .lines-head { display: none; }
  .line-row {
    grid-template-columns: 1fr 1fr var(--control) !important; grid-template-areas: "item item remove" "qty price sum";
    padding: 10px; border: 1px solid var(--line); border-radius: 10px; gap: 8px;
  }
  .line-row.no-price { grid-template-areas: "item item remove" "qty unit unit"; }
  .lc-item { grid-area: item; }
  .lc-qty { grid-area: qty; }
  .lc-price { grid-area: price; }
  .lc-sum { grid-area: sum; display: flex; justify-content: space-between; align-items: baseline; }
  .line-row.with-price .lc-unit { display: none; }
  .line-row.no-price .lc-unit { grid-area: unit; align-self: end; padding-bottom: 12px; }
  .lc-remove { grid-area: remove; }
  .lc-cap { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
  .lc-sum .lc-cap { margin: 0; }
  .line-row.with-price { grid-template-areas: "item item remove" "qty price price" "sum sum sum"; }
  /* таблицы — карточками строк */
  table.data, table.data tbody, table.data tfoot, table.data tr, table.data td { display: block; width: 100%; }
  table.data { border: 0; background: none; }
  table.data thead, table.data colgroup { display: none; }
  table.data tr {
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; margin-bottom: 8px;
  }
  table.data td { padding: 3px 0; border: 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.data td::before { content: attr(data-label); color: var(--muted); text-align: left; flex: none; max-width: 48%; }
  table.data td .cell { min-width: 0; text-align: right; }
  table.data td .cell-main, table.data td .cell-sub { white-space: normal; overflow-wrap: anywhere; }
  table.data td.primary { display: block; text-align: left; padding-bottom: 6px; }
  table.data td.primary::before { content: none; }
  table.data td.primary .cell { text-align: left; }
  table.data td.is-blank { display: none; }
  table.data tfoot tr { background: var(--surface-2); }
  table.data tfoot td { border-top: 0; background: none; }
  table.data.is-clickable tbody tr:hover td { background: none; }
}
