/* Bill Maker — интерфейс «серый металлик».
   Раскладка: боковая панель-навигация + рабочая область; в редакторе счёта форма слева, живой лист A4 справа.
   Материал: шлифованная сталь — градиентные панели, металлические кромки (градиентная рамка),
   внутренний блик сверху и мягкие многослойные тени. */

@font-face { font-family: "Inter Variable"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(/static/fonts/inter-cyrillic-wght-normal.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Inter Variable"; font-style: normal; font-display: swap; font-weight: 100 900;
  src: url(/static/fonts/inter-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Unbounded Variable"; font-style: normal; font-display: swap; font-weight: 200 900;
  src: url(/static/fonts/unbounded-cyrillic-wght-normal.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Unbounded Variable"; font-style: normal; font-display: swap; font-weight: 200 900;
  src: url(/static/fonts/unbounded-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --font-display: "Unbounded Variable", "Unbounded", "Inter Variable", system-ui, sans-serif;
  --font-body: "Inter Variable", "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* светлая сталь */
  --bg: #d5dae0;
  --bg-2: #c4cad2;
  --sheen: rgba(255, 255, 255, .75);
  --brush: rgba(255, 255, 255, .16);
  --panel-a: #fbfcfd;
  --panel-b: #e8ecf0;
  --panel-flat: #f3f5f7;
  --edge-hi: rgba(255, 255, 255, .98);
  --edge-lo: rgba(96, 108, 122, .42);
  --inner-hi: rgba(255, 255, 255, .95);
  --line: rgba(34, 44, 56, .1);
  --line-2: rgba(34, 44, 56, .18);
  --fg: #171c22;
  --fg-2: #47515c;
  --fg-3: #77818c;
  --accent: #3f5f86;
  --accent-soft: rgba(63, 95, 134, .12);
  --ring: rgba(63, 95, 134, .32);
  --field: #ffffff;
  --field-edge: rgba(34, 44, 56, .2);
  --field-inset: rgba(20, 30, 40, .07);
  --chrome-a: #ffffff;
  --chrome-b: #dde2e7;
  --chrome-fg: #1f252c;
  --pri-a: #4a525c;
  --pri-b: #1d2227;
  --pri-fg: #f4f6f8;
  --pri-hi: rgba(255, 255, 255, .28);
  --side-a: #2f353c;
  --side-b: #1b1f24;
  --side-fg: #d9dee3;
  --side-fg-2: #8f99a4;
  --side-hi: rgba(255, 255, 255, .09);
  --shadow-1: 0 1px 2px rgba(18, 26, 36, .08), 0 10px 28px -14px rgba(18, 26, 36, .38);
  --shadow-2: 0 2px 6px rgba(18, 26, 36, .1), 0 30px 60px -20px rgba(18, 26, 36, .5);
  --ok: #24724a; --ok-soft: rgba(36, 114, 74, .13);
  --warn: #9a620c; --warn-soft: rgba(176, 116, 18, .15);
  --bad: #a83434; --bad-soft: rgba(168, 52, 52, .12);
  --info: #2c5d9c; --info-soft: rgba(44, 93, 156, .13);
  --mute-soft: rgba(70, 82, 96, .12);
  --paper-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 18px 40px -12px rgba(18, 26, 36, .45);
  --overlay: rgba(28, 34, 42, .42);
  --radius: 16px;
  --radius-s: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c; --bg-2: #0d0f12; --sheen: rgba(170, 186, 204, .09); --brush: rgba(255, 255, 255, .018);
    --panel-a: #2a2f36; --panel-b: #1e2227; --panel-flat: #23272d;
    --edge-hi: rgba(255, 255, 255, .2); --edge-lo: rgba(0, 0, 0, .55); --inner-hi: rgba(255, 255, 255, .07);
    --line: rgba(255, 255, 255, .07); --line-2: rgba(255, 255, 255, .13);
    --fg: #e7eaee; --fg-2: #a8b0b9; --fg-3: #77808a;
    --accent: #93b2d8; --accent-soft: rgba(147, 178, 216, .13); --ring: rgba(147, 178, 216, .35);
    --field: #16191d; --field-edge: rgba(255, 255, 255, .13); --field-inset: rgba(0, 0, 0, .35);
    --chrome-a: #3a4048; --chrome-b: #2a2f35; --chrome-fg: #e7eaee;
    --pri-a: #f2f4f6; --pri-b: #aeb6bf; --pri-fg: #14171b; --pri-hi: rgba(255, 255, 255, .9);
    --side-a: #1e2227; --side-b: #121418; --side-fg: #d9dee3; --side-fg-2: #7f8994; --side-hi: rgba(255, 255, 255, .06);
    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 30px -14px rgba(0, 0, 0, .8);
    --shadow-2: 0 2px 6px rgba(0, 0, 0, .45), 0 30px 60px -20px rgba(0, 0, 0, .9);
    --ok: #6cc596; --ok-soft: rgba(108, 197, 150, .14);
    --warn: #e2b05a; --warn-soft: rgba(226, 176, 90, .14);
    --bad: #ee8a8a; --bad-soft: rgba(238, 138, 138, .13);
    --info: #8fb6ec; --info-soft: rgba(143, 182, 236, .14);
    --mute-soft: rgba(200, 210, 222, .1);
    --paper-shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 22px 50px -14px rgba(0, 0, 0, .9);
    --overlay: rgba(4, 6, 8, .6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15181c; --bg-2: #0d0f12; --sheen: rgba(170, 186, 204, .09); --brush: rgba(255, 255, 255, .018);
  --panel-a: #2a2f36; --panel-b: #1e2227; --panel-flat: #23272d;
  --edge-hi: rgba(255, 255, 255, .2); --edge-lo: rgba(0, 0, 0, .55); --inner-hi: rgba(255, 255, 255, .07);
  --line: rgba(255, 255, 255, .07); --line-2: rgba(255, 255, 255, .13);
  --fg: #e7eaee; --fg-2: #a8b0b9; --fg-3: #77808a;
  --accent: #93b2d8; --accent-soft: rgba(147, 178, 216, .13); --ring: rgba(147, 178, 216, .35);
  --field: #16191d; --field-edge: rgba(255, 255, 255, .13); --field-inset: rgba(0, 0, 0, .35);
  --chrome-a: #3a4048; --chrome-b: #2a2f35; --chrome-fg: #e7eaee;
  --pri-a: #f2f4f6; --pri-b: #aeb6bf; --pri-fg: #14171b; --pri-hi: rgba(255, 255, 255, .9);
  --side-a: #1e2227; --side-b: #121418; --side-fg: #d9dee3; --side-fg-2: #7f8994; --side-hi: rgba(255, 255, 255, .06);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 30px -14px rgba(0, 0, 0, .8);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .45), 0 30px 60px -20px rgba(0, 0, 0, .9);
  --ok: #6cc596; --ok-soft: rgba(108, 197, 150, .14);
  --warn: #e2b05a; --warn-soft: rgba(226, 176, 90, .14);
  --bad: #ee8a8a; --bad-soft: rgba(238, 138, 138, .13);
  --info: #8fb6ec; --info-soft: rgba(143, 182, 236, .14);
  --mute-soft: rgba(200, 210, 222, .1);
  --paper-shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 22px 50px -14px rgba(0, 0, 0, .9);
  --overlay: rgba(4, 6, 8, .6);
  color-scheme: dark;
}

/* ---------- основа ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%; font: 14px/1.45 var(--font-body); color: var(--fg);
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 18% -8%, var(--sheen), transparent 62%),
    repeating-linear-gradient(90deg, var(--brush) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, var(--bg), var(--bg-2));
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
.num, .money { font-variant-numeric: tabular-nums; }
.money { white-space: nowrap; }
.muted { color: var(--fg-3); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.i-s { width: 15px; height: 15px; }

/* металлическая панель: градиентная заливка + градиентная кромка */
.card, .metal {
  background:
    linear-gradient(180deg, var(--panel-a), var(--panel-b)) padding-box,
    linear-gradient(165deg, var(--edge-hi), var(--edge-lo) 55%, var(--edge-hi)) border-box;
  border: 1px solid transparent;
  border-radius: var(--radius);
  box-shadow: var(--shadow-1), inset 0 1px 0 var(--inner-hi);
}

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 15px;
  border-radius: var(--radius-s); border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  font-weight: 560; letter-spacing: .005em; color: var(--chrome-fg); text-decoration: none !important;
  background:
    linear-gradient(180deg, var(--chrome-a), var(--chrome-b)) padding-box,
    linear-gradient(180deg, var(--edge-hi), var(--edge-lo)) border-box;
  box-shadow: 0 1px 2px rgba(10, 16, 24, .14), inset 0 1px 0 var(--inner-hi);
  transition: filter .15s, transform .08s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.04); }
.btn:active { transform: translateY(1px); box-shadow: inset 0 1px 3px rgba(10, 16, 24, .25); }
.btn:disabled { opacity: .5; cursor: default; filter: none; transform: none; }
.btn.primary {
  color: var(--pri-fg);
  background:
    linear-gradient(180deg, var(--pri-a), var(--pri-b)) padding-box,
    linear-gradient(180deg, var(--pri-hi), rgba(0, 0, 0, .5)) border-box;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 6px 16px -8px rgba(0, 0, 0, .55), inset 0 1px 0 var(--pri-hi);
}
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; box-shadow: none; border-color: transparent; color: var(--fg-2); }
.btn.ghost:hover { background: var(--mute-soft); filter: none; }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; gap: 6px; }
.btn.icon { width: 38px; padding: 0; }
.btn.sm.icon { width: 32px; }
.btn .kbd { margin-left: 2px; }
.kbd { font: 600 11px/1 var(--font-body); padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--fg-3); background: var(--mute-soft); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- поля ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span, .lbl { font-size: 12px; font-weight: 600; color: var(--fg-2); letter-spacing: .02em; }
.field .hint { font-size: 12px; color: var(--fg-3); font-weight: 400; }
.inp, select.inp, textarea.inp {
  width: 100%; min-width: 0; height: 38px; padding: 0 11px; border-radius: var(--radius-s);
  background: var(--field); border: 1px solid var(--field-edge);
  box-shadow: inset 0 1px 2px var(--field-inset);
  transition: border-color .15s, box-shadow .15s;
}
textarea.inp { height: auto; min-height: 64px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
select.inp { padding-right: 30px; appearance: none; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-3) 50%), linear-gradient(135deg, var(--fg-3) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px; background-size: 5px 5px; background-repeat: no-repeat; }
.inp:focus { outline: none; border-color: var(--accent); box-shadow: inset 0 1px 2px var(--field-inset), 0 0 0 3px var(--ring); }
.inp:disabled, .inp[readonly] { opacity: .75; }
.inp.err { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.inp.num { text-align: right; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; font-weight: 500; }
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch { width: 38px; height: 22px; border-radius: 22px; flex: none; position: relative; border: 1px solid var(--field-edge);
  background: var(--field); box-shadow: inset 0 1px 3px var(--field-inset); transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: linear-gradient(180deg, var(--chrome-a), var(--chrome-b)); box-shadow: 0 1px 3px rgba(0, 0, 0, .35); transition: transform .2s; }
.check input:checked + .switch { background: var(--accent); border-color: var(--accent); }
.check input:checked + .switch::after { transform: translateX(16px); }
.check input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* сегментированный переключатель */
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--field); border: 1px solid var(--field-edge);
  box-shadow: inset 0 1px 3px var(--field-inset); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 12px; border-radius: 9px; cursor: pointer; color: var(--fg-2); font-weight: 550; font-size: 13px; }
.seg button[aria-pressed="true"] { color: var(--chrome-fg);
  background: linear-gradient(180deg, var(--chrome-a), var(--chrome-b)); box-shadow: 0 1px 2px rgba(0, 0, 0, .18), inset 0 1px 0 var(--inner-hi); }

/* ---------- каркас приложения ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; padding: 18px 14px;
  color: var(--side-fg);
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .018) 0 1px, transparent 1px 3px),
    linear-gradient(180deg, var(--side-a), var(--side-b));
  border-right: 1px solid rgba(0, 0, 0, .35);
  box-shadow: inset -1px 0 0 var(--side-hi), 6px 0 24px -12px rgba(0, 0, 0, .45);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 18px; color: inherit; text-decoration: none !important; }
.brand svg { width: 38px; height: 38px; flex: none; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, .45)); }
.brand b { display: block; font: 700 15px/1.1 var(--font-display); letter-spacing: .04em;
  background: linear-gradient(180deg, #ffffff, #9aa4af); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand small { display: block; color: var(--side-fg-2); font-size: 11.5px; margin-top: 3px; letter-spacing: .03em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-sep { margin: 14px 10px 6px; font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--side-fg-2); font-weight: 650; }
.nav a { display: flex; align-items: center; gap: 11px; height: 40px; padding: 0 11px; border-radius: 11px; color: var(--side-fg-2);
  font-weight: 540; text-decoration: none; border: 1px solid transparent; transition: color .15s, background .15s; }
.nav a:hover { color: var(--side-fg); background: rgba(255, 255, 255, .045); }
.nav a.on {
  color: #fff;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .13), rgba(255, 255, 255, .04)) padding-box,
    linear-gradient(180deg, rgba(255, 255, 255, .28), rgba(255, 255, 255, .04)) border-box;
  box-shadow: 0 4px 14px -6px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .12);
}
.nav a .count { margin-left: auto; font-size: 11.5px; color: var(--side-fg-2); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.me { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 13px; color: inherit; text-decoration: none !important;
  background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .06); }
.me:hover { background: rgba(255, 255, 255, .07); }
.ava { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; font: 700 13px var(--font-display);
  color: #1b1f24; background: linear-gradient(180deg, #f5f7f9, #a7b0ba); box-shadow: inset 0 1px 0 #fff, 0 2px 6px rgba(0, 0, 0, .4); }
.me b { display: block; font-size: 13px; font-weight: 600; color: var(--side-fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me small { display: block; font-size: 11.5px; color: var(--side-fg-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-tools { display: flex; gap: 6px; }
.side-tools button { flex: 1; height: 34px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .07); background: rgba(255, 255, 255, .03);
  color: var(--side-fg-2); display: inline-flex; align-items: center; justify-content: center; gap: 7px; cursor: pointer; font-size: 12.5px; }
.side-tools button:hover { color: var(--side-fg); background: rgba(255, 255, 255, .07); }
.ver { font-size: 11px; color: var(--side-fg-2); text-align: center; opacity: .7; }

.main { min-width: 0; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 12px;
  padding-block: 12px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px));
  background: linear-gradient(180deg, color-mix(in srgb, var(--bg) 92%, transparent), color-mix(in srgb, var(--bg) 70%, transparent));
  backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  border-bottom: 1px solid var(--line);
}
.top h1 { margin: 0; font: 650 19px/1.2 var(--font-display); letter-spacing: .01em; text-wrap: balance; }
.top .crumb { color: var(--fg-3); font-size: 12.5px; }
.searchbtn { display: flex; align-items: center; gap: 10px; height: 38px; min-width: 240px; padding: 0 12px; border-radius: 11px; cursor: pointer;
  color: var(--fg-3); background: var(--field); border: 1px solid var(--field-edge); box-shadow: inset 0 1px 2px var(--field-inset); }
.searchbtn span { flex: 1; text-align: left; }
.burger { display: none; }
.view { padding-block: 22px 60px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); min-width: 0; }
.view-in { max-width: 1320px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

/* ---------- общие блоки ---------- */
.sec { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.sec-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sec-h h2, .sec-h h3 { margin: 0; font: 650 14.5px/1.25 var(--font-display); letter-spacing: .015em; }
.sec-h .sub { color: var(--fg-3); font-size: 12.5px; }
.sec-h .end { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.eyebrow { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-weight: 650; color: var(--fg-3); }
.empty { padding: 34px 20px; text-align: center; color: var(--fg-3); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty b { color: var(--fg); font-size: 15px; font-weight: 600; }
.notice { display: flex; align-items: center; gap: 11px; padding: 11px 14px; border-radius: 12px; background: var(--info-soft); color: var(--fg); border: 1px solid var(--line); flex-wrap: wrap; }
.notice.warn { background: var(--warn-soft); }
.notice .i { color: var(--info); }
.notice.warn .i { color: var(--warn); }
.notice .end { margin-left: auto; }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 30px; font-size: 12px; font-weight: 620; white-space: nowrap; border: 1px solid transparent; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent); }
.pill.draft { color: var(--fg-2); background: var(--mute-soft); }
.pill.issued { color: var(--info); background: var(--info-soft); }
.pill.paid { color: var(--ok); background: var(--ok-soft); }
.pill.cancelled { color: var(--bad); background: var(--bad-soft); }
button.pill { cursor: pointer; }
button.pill:hover { border-color: currentColor; }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 7px; font-size: 11.5px; font-weight: 600; background: var(--mute-soft); color: var(--fg-2); }
.tag.admin { background: var(--accent-soft); color: var(--accent); }

/* ---------- таблицы ---------- */
.tbl-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
.tbl th { text-align: left; font-size: 11.5px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-3);
  padding: 9px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--fg); }
.tbl th .arr { opacity: .8; margin-left: 4px; }
.tbl td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--accent-soft); }
.tbl td.r, .tbl th.r { text-align: right; }
.tbl td .sub { display: block; font-size: 12px; color: var(--fg-3); }
.tbl .acts { white-space: nowrap; text-align: right; }
.tbl .acts .btn { opacity: .75; }
.tbl tr:hover .acts .btn { opacity: 1; }
.tbl-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--fg-2); font-size: 13px; }
.cell-strong { font-weight: 600; }
.cell-num { font: 650 13px var(--font-display); letter-spacing: .02em; }

/* ---------- фильтры ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters .inp { height: 36px; }
.search { position: relative; flex: 1 1 260px; min-width: 200px; }
.search .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--fg-3); pointer-events: none; }
.search .inp { padding-left: 36px; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: 10px; cursor: pointer; font-weight: 550; font-size: 13px;
  border: 1px solid var(--field-edge); background: var(--field); color: var(--fg-2); }
.chip[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.dates { display: flex; align-items: center; gap: 6px; }
.dates .inp { width: 142px; }

/* ---------- главная ---------- */
.hello h2 { margin: 0; font: 650 clamp(20px, 2.4vw, 27px)/1.15 var(--font-display); letter-spacing: .01em; text-wrap: balance; }
.hello p { margin: 6px 0 0; color: var(--fg-2); }
.hello { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 8px; min-width: 0; text-decoration: none !important; color: inherit; transition: transform .15s, box-shadow .15s; }
a.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-2), inset 0 1px 0 var(--inner-hi); }
.kpi .k-l { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--fg-2); font-weight: 560; }
.kpi .k-l .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--fg-3); }
.kpi .k-v { font: 650 clamp(18px, 1.9vw, 24px)/1.1 var(--font-display); letter-spacing: .01em; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-v small { font: 500 13px var(--font-body); color: var(--fg-3); margin-left: 4px; }
.kpi .k-s { font-size: 12.5px; color: var(--fg-3); }
.dash { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 18px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { fill: url(#barGrad); }
.chart .bar.cur { fill: url(#barGradCur); }
.chart .gl { stroke: var(--line-2); stroke-dasharray: 3 4; }
.chart text { fill: var(--fg-3); font: 500 11px var(--font-body); }
.chart text.v { fill: var(--fg-2); font-weight: 650; font-size: 11.5px; }
.chart text.v.cur { fill: var(--fg); }
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none !important; min-width: 0; }
.li:last-child { border-bottom: 0; }
a.li:hover { background: var(--accent-soft); border-radius: 10px; }
.li .t { flex: 1; min-width: 0; }
.li .t b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .t small { display: block; color: var(--fg-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .m { text-align: right; }
.meter { height: 6px; border-radius: 6px; background: var(--mute-soft); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--fg-3), var(--accent)); }
.quick { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.quick a { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 13px; color: inherit; text-decoration: none !important; font-weight: 600; font-size: 13px;
  background: var(--field); border: 1px solid var(--line-2); transition: border-color .15s, transform .15s; }
.quick a:hover { border-color: var(--accent); transform: translateY(-1px); }
.quick a .i { color: var(--accent); width: 20px; height: 20px; }

/* ---------- редактор счёта ---------- */
.ed { display: flex; flex-direction: column; gap: 16px; }
.ed-bar { position: sticky; top: 66px; z-index: 12; display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; flex-wrap: wrap; }
.ed-bar h2 { margin: 0; font: 650 16px/1.2 var(--font-display); letter-spacing: .01em; }
.ed-bar .meta { font-size: 12px; color: var(--fg-3); }
.ed-bar .end { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.savestate { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--fg-3); }
.savestate::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.savestate.dirty::before { background: var(--warn); }
.savestate.new::before { background: var(--fg-3); }
.ed-tabs { display: none; }
.ed-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(380px, 0.92fr); gap: 18px; align-items: start; }
.ed-form { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.ed-pv { position: sticky; top: 136px; padding: 14px; display: flex; flex-direction: column; gap: 12px; min-width: 0; max-height: calc(100vh - 152px); }
.pv-tools { display: flex; align-items: center; gap: 8px; }
.pv-tools .busy { font-size: 12px; color: var(--fg-3); display: inline-flex; align-items: center; gap: 6px; }
.pv-stage { flex: 1 1 auto; min-height: 0; position: relative; overflow: auto; border-radius: 12px; padding: 14px;
  background: repeating-linear-gradient(135deg, var(--mute-soft) 0 2px, transparent 2px 9px), var(--panel-flat);
  box-shadow: inset 0 2px 8px var(--field-inset); }
.pv-fit { position: relative; margin: 0 auto; }
.pv-paper { position: absolute; top: 0; left: 0; transform-origin: 0 0; box-shadow: var(--paper-shadow); border-radius: 2px; background: #fff; }
.spin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.party { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 14px; padding: 12px 14px; border-radius: 12px; background: var(--field);
  border: 1px solid var(--line-2); font-size: 13px; }
.party dt { color: var(--fg-3); }
.party dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.party .edit { grid-column: 3; grid-row: 1; }
.party .name { grid-column: 1 / 3; font-weight: 650; font-size: 14px; margin-bottom: 4px; }

/* позиции */
.items { display: flex; flex-direction: column; gap: 10px; }
.it { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 0 10px; padding: 10px 12px 12px 6px; border-radius: 13px; background: var(--field);
  border: 1px solid var(--line-2); box-shadow: 0 1px 2px rgba(10, 16, 24, .05); position: relative; transition: opacity .15s, box-shadow .15s; }
.it.dragging { opacity: .35; }
.it.ghost { position: fixed; z-index: 100; pointer-events: none; opacity: .95; box-shadow: var(--shadow-2); }
.it-grip { display: flex; flex-direction: column; align-items: center; gap: 6px; padding-top: 8px; color: var(--fg-3); cursor: grab; touch-action: none; user-select: none; border-radius: 8px; }
.it-grip:hover { color: var(--fg); background: var(--mute-soft); }
.it-grip:active { cursor: grabbing; }
.it-no { font: 650 12px var(--font-display); color: var(--fg-2); }
.it-main { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.it-l1 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(120px, .42fr); gap: 8px; }
.it-l2 { display: grid; grid-template-columns: 92px 84px 108px 104px minmax(96px, 1fr) auto; gap: 8px; align-items: end; }
.it-l2 .field > span { font-size: 11px; font-weight: 600; color: var(--fg-3); }
.it .inp { height: 36px; }
.it textarea.inp { min-height: 36px; height: 36px; resize: none; overflow: hidden; padding-top: 8px; padding-bottom: 7px; }
.it-sum { text-align: right; display: flex; flex-direction: column; gap: 5px; }
.it-sum span { font-size: 11px; font-weight: 600; color: var(--fg-3); }
.it-sum b { font: 650 14px/36px var(--font-display); letter-spacing: .01em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.it-act { display: flex; gap: 2px; }
.drop-line { height: 3px; border-radius: 3px; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); position: relative; margin: -6px 0; }
.drop-line::after { content: "Переместить сюда"; position: absolute; right: 8px; top: -9px; font-size: 11px; font-weight: 650; color: var(--accent);
  background: var(--panel-a); padding: 1px 7px; border-radius: 6px; border: 1px solid var(--accent); }
.items-foot { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tot { padding: 12px 14px; border-radius: 12px; background: var(--field); border: 1px solid var(--line-2); min-width: 0; }
.tot span { display: block; font-size: 11.5px; font-weight: 600; color: var(--fg-3); letter-spacing: .03em; }
.tot b { display: block; font: 650 17px/1.3 var(--font-display); font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tot.grand { background:
    linear-gradient(180deg, var(--pri-a), var(--pri-b)) padding-box,
    linear-gradient(180deg, var(--pri-hi), rgba(0, 0, 0, .5)) border-box;
  border: 1px solid transparent; color: var(--pri-fg); box-shadow: 0 8px 20px -10px rgba(0, 0, 0, .6), inset 0 1px 0 var(--pri-hi); }
.tot.grand span { color: color-mix(in srgb, var(--pri-fg) 70%, transparent); }
.words { font-size: 13px; color: var(--fg-2); font-style: italic; }

/* выпадающие подсказки (контрагенты, продукция) */
.cb { position: relative; min-width: 0; }
.cb-list { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 60; max-height: 320px; overflow: auto; padding: 6px; display: flex; flex-direction: column; gap: 2px; min-width: 280px; }
.cb-opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer; min-width: 0; }
.cb-opt .t { flex: 1; min-width: 0; }
.cb-opt b { display: block; font-weight: 600; font-size: 13px; overflow-wrap: anywhere; }
.cb-opt small { display: block; font-size: 12px; color: var(--fg-3); overflow-wrap: anywhere; }
.cb-opt .r { font-size: 12.5px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cb-opt.on { background: var(--accent-soft); }
.cb-opt.add { color: var(--accent); font-weight: 600; }
.cb-empty { padding: 10px; color: var(--fg-3); font-size: 13px; }

/* ---------- всплывающие окна ---------- */
.ov { position: fixed; inset: 0; z-index: 200; background: var(--overlay); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; animation: fade .16s ease-out; overflow: auto; }
.ov.drawer-ov { padding: 0; justify-content: flex-end; align-items: stretch; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(10px) scale(.985); opacity: 0; } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.dlg { width: 100%; max-width: 520px; display: flex; flex-direction: column; box-shadow: var(--shadow-2), inset 0 1px 0 var(--inner-hi); animation: rise .2s ease-out; }
.dlg.wide { max-width: 760px; }
.dlg.xwide { max-width: 1000px; }
.drawer { width: min(560px, 100%); height: 100%; border-radius: 18px 0 0 18px; display: flex; flex-direction: column; animation: slide .22s ease-out; box-shadow: var(--shadow-2); }
.dlg-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px 12px; }
.dlg-h h3 { margin: 0; font: 650 15.5px/1.3 var(--font-display); flex: 1; min-width: 0; letter-spacing: .01em; }
.dlg-b { padding: 4px 18px 18px; display: flex; flex-direction: column; gap: 14px; overflow: auto; min-height: 0; }
.drawer .dlg-b { flex: 1; }
.dlg-f { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.dlg-f .left { margin-right: auto; }
.creds { font: 13px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace; padding: 12px 14px; border-radius: 10px; background: var(--field); border: 1px solid var(--line-2); white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; }
.menu { position: fixed; z-index: 250; padding: 6px; min-width: 200px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow-2), inset 0 1px 0 var(--inner-hi); animation: rise .12s ease-out; }
.menu button { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border: 0; background: transparent; border-radius: 8px; cursor: pointer; text-align: left; font-weight: 520; }
.menu button:hover, .menu button:focus-visible { background: var(--accent-soft); outline: none; }
.menu button.danger { color: var(--bad); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

.toasts { position: fixed; z-index: 400; right: max(16px, env(safe-area-inset-right, 0px)); bottom: max(16px, env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; max-width: min(440px, calc(100vw - 32px)); padding: 11px 14px; border-radius: 13px; font-weight: 520; animation: rise .2s ease-out; }
.toast .i { flex: none; }
.toast.ok .i { color: var(--ok); }
.toast.err .i { color: var(--bad); }
.toast.warn .i { color: var(--warn); }
.toast .btn { margin-left: 6px; }

/* командная строка */
.cmd { max-width: 640px; }
.cmd-in { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.cmd-in input { flex: 1; border: 0; background: transparent; font-size: 16px; outline: none; min-width: 0; }
.cmd-res { max-height: 60vh; overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.cmd-g { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--fg-3); font-weight: 650; padding: 10px 10px 4px; }

/* загрузка изображений организации */
.imgs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.slot { display: flex; flex-direction: column; gap: 8px; padding: 10px; border-radius: 12px; border: 1px dashed var(--line-2); background: var(--field); min-width: 0; transition: border-color .15s, background .15s; }
.slot.over { border-color: var(--accent); background: var(--accent-soft); }
.slot .pic { height: 92px; border-radius: 8px; display: grid; place-items: center; overflow: hidden;
  background: repeating-conic-gradient(#eef0f3 0 25%, #ffffff 0 50%) 0 0 / 14px 14px; }
.slot .pic img { max-width: 100%; max-height: 100%; object-fit: contain; }
.slot .pic .muted { font-size: 12px; }
.slot b { font-size: 12.5px; }
.slot .btn-row { gap: 4px; }
.orgs { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.org { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.org h3 { margin: 0; font: 650 15px/1.3 var(--font-display); }
.org dl { margin: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.org dt { color: var(--fg-3); }
.org dd { margin: 0; overflow-wrap: anywhere; }
.org .thumbs { display: flex; gap: 8px; }
.org .thumbs div { width: 64px; height: 48px; border-radius: 8px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line-2);
  background: repeating-conic-gradient(#eef0f3 0 25%, #ffffff 0 50%) 0 0 / 10px 10px; font-size: 10.5px; color: #8b939c; text-align: center; }
.org .thumbs img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* журнал и история */
.log { display: flex; flex-direction: column; }
.log-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 4px 16px; padding: 11px 2px; border-bottom: 1px solid var(--line); }
.log-row time { color: var(--fg-3); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.log-row .who { font-weight: 600; }
.log-row .what { color: var(--fg); }
.log-row details { grid-column: 2; font-size: 12.5px; color: var(--fg-2); }
.log-row summary { cursor: pointer; color: var(--accent); }
.chg { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 12px; margin-top: 6px; }
.chg s { color: var(--fg-3); }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.login-card { width: min(420px, 100%); padding: 30px 28px 26px; display: flex; flex-direction: column; gap: 18px; box-shadow: var(--shadow-2), inset 0 1px 0 var(--inner-hi); }
.login-logo { display: flex; align-items: center; gap: 14px; }
.login-logo svg { width: 52px; height: 52px; filter: drop-shadow(0 6px 12px rgba(0, 0, 0, .35)); }
.login-logo b { display: block; font: 750 21px/1.1 var(--font-display); letter-spacing: .03em;
  background: linear-gradient(180deg, var(--fg), var(--fg-3)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.login-logo small { color: var(--fg-3); font-size: 12.5px; }
.login h1 { margin: 0; font: 650 17px/1.3 var(--font-display); }
.login p { margin: 0; color: var(--fg-2); }
.pass { position: relative; }
.pass .inp { padding-right: 42px; }
.pass button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: transparent; width: 34px; height: 30px; cursor: pointer; color: var(--fg-3); border-radius: 8px; }
.pass button:hover { color: var(--fg); }
.form-err { color: var(--bad); font-size: 13px; font-weight: 550; min-height: 18px; }
.login .foot { text-align: center; font-size: 12px; color: var(--fg-3); }

/* скелетон загрузки */
.skel { border-radius: 10px; background: linear-gradient(90deg, var(--mute-soft), var(--line), var(--mute-soft)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- адаптивность ---------- */
@media (max-width: 1240px) {
  .ed-grid { grid-template-columns: minmax(0, 1fr); }
  .ed-tabs { display: flex; }
  .ed-grid[data-tab="form"] .ed-pv { display: none; }
  .ed-grid[data-tab="preview"] .ed-form { display: none; }
  .ed-pv { position: static; max-height: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 264px; transform: translateX(-102%); transition: transform .22s ease-out;
    padding-top: max(18px, env(safe-area-inset-top, 0px)); padding-left: max(14px, env(safe-area-inset-left, 0px)); }
  .app.nav-open .side { transform: none; }
  .app.nav-open::after { content: ""; position: fixed; inset: 0; background: var(--overlay); z-index: 19; }
  .burger { display: inline-flex; }
  .top { top: env(safe-area-inset-top, 0px); padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .view { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  .searchbtn { min-width: 0; }
  .searchbtn span, .searchbtn .kbd { display: none; }
  .dash { grid-template-columns: minmax(0, 1fr); }
  .ed-bar { top: calc(62px + env(safe-area-inset-top, 0px)); }
}
@media (max-width: 720px) {
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .quick { grid-template-columns: minmax(0, 1fr); }
  .it-l1 { grid-template-columns: minmax(0, 1fr); }
  .it-l2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .it-sum { text-align: left; }
  .it-act { justify-content: flex-end; align-self: end; }
  .totals { grid-template-columns: minmax(0, 1fr); }
  .imgs { grid-template-columns: minmax(0, 1fr); }
  .top h1 { font-size: 16px; }
  .sec { padding: 16px 14px; }
  .tbl-wrap { margin: 0 -14px; padding: 0 14px; }
  .hide-s { display: none !important; }
  .log-row { grid-template-columns: minmax(0, 1fr); }
  .log-row details { grid-column: 1; }
  .ed-bar { position: static; }
  .drawer { border-radius: 0; }
  .dates .inp { width: 128px; }
  .orgs { grid-template-columns: minmax(0, 1fr); }
  .party { grid-template-columns: auto minmax(0, 1fr); }
  .party .edit { grid-column: 1 / -1; grid-row: auto; justify-self: start; }
}

@media print {
  body { background: #fff; }
  .side, .top, .ed-bar, .ed-form, .ed-tabs, .pv-tools { display: none !important; }
}
