/* Automic Finance — рабочий интерфейс. Нейтральные поверхности, линии 1px, цвет — на данных и главных действиях. */
:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #fafbfa;
  --hover: #f1f3f1;
  --active: #e9ecea;
  --line: #e4e7e4;
  --line-strong: #d3d8d4;
  --text: #0e1613;
  --text-2: #3c4743;
  --muted: #69756f;
  --faint: #98a29d;
  --accent: #0f766e;
  --accent-hover: #0b5f58;
  --accent-soft: #e5f2f0;
  --accent-text: #ffffff;
  --pos: #137a4b;
  --pos-soft: #e3f4ea;
  --neg: #b42318;
  --neg-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4dc;
  --info: #2557c7;
  --info-soft: #e8efff;
  --violet: #6d4ad8;
  --violet-soft: #efeaff;
  --c1: #2a78d6; --c2: #eb6834; --c3: #0f9d8a; --c4: #a855c9; --c5: #d9a400; --c6: #e0457b; --c7: #5b6bd6; --c8: #7a8a3c;
  --income: #0f9d6a;
  --expense: #e2683c;
  --grid: #eceeec;
  --radius: 14px;
  --radius-sm: 9px;
  --ring: 0 0 0 3px rgba(15, 118, 110, 0.22);
  --shadow-pop: 0 12px 32px rgba(16, 24, 20, 0.14), 0 2px 6px rgba(16, 24, 20, 0.06);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f0e; --surface: #121816; --surface-2: #151c1a; --hover: #1a2220; --active: #222c29; --line: #222b28; --line-strong: #2f3a36;
    --text: #edf2f0; --text-2: #c6d0cc; --muted: #93a19b; --faint: #66736e;
    --accent: #2bb3a3; --accent-hover: #46c8b8; --accent-soft: #12302c; --accent-text: #04201c;
    --pos: #5fd39a; --pos-soft: #10301f; --neg: #ff8a80; --neg-soft: #3a1715; --warn: #f5b84d; --warn-soft: #33260e; --info: #8fb0ff; --info-soft: #172446; --violet: #b49cff; --violet-soft: #251d45;
    --c1: #4c93ec; --c2: #f27d4d; --c3: #2fc0aa; --c4: #c27ee0; --c5: #e8c040; --c6: #f06a98; --c7: #8190f0; --c8: #a2b35a;
    --income: #3cc98f; --expense: #f2875c; --grid: #1e2624;
    --ring: 0 0 0 3px rgba(43, 179, 163, 0.3);
    --shadow-pop: 0 14px 36px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f0e; --surface: #121816; --surface-2: #151c1a; --hover: #1a2220; --active: #222c29; --line: #222b28; --line-strong: #2f3a36;
  --text: #edf2f0; --text-2: #c6d0cc; --muted: #93a19b; --faint: #66736e;
  --accent: #2bb3a3; --accent-hover: #46c8b8; --accent-soft: #12302c; --accent-text: #04201c;
  --pos: #5fd39a; --pos-soft: #10301f; --neg: #ff8a80; --neg-soft: #3a1715; --warn: #f5b84d; --warn-soft: #33260e; --info: #8fb0ff; --info-soft: #172446; --violet: #b49cff; --violet-soft: #251d45;
  --c1: #4c93ec; --c2: #f27d4d; --c3: #2fc0aa; --c4: #c27ee0; --c5: #e8c040; --c6: #f06a98; --c7: #8190f0; --c8: #a2b35a;
  --income: #3cc98f; --expense: #f2875c; --grid: #1e2624;
  --ring: 0 0 0 3px rgba(43, 179, 163, 0.3);
  --shadow-pop: 0 14px 36px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); font-feature-settings: "cv11", "ss01"; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.num, .money, td.r, .kpi-value { font-variant-numeric: tabular-nums; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
svg { display: block; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 15px; height: 15px; }
.icon.lg { width: 22px; height: 22px; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.app.ai-open { grid-template-columns: 252px 1fr 432px; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; font-size: 15px; line-height: 1.15; }
.brand-name small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; letter-spacing: 0; }
.org { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 11px; margin: 0 2px 10px; background: var(--surface-2); }
.org-ava { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #1f3b73, #3a7bd5); color: #fff; font-weight: 700; font-size: 12px; display: grid; place-items: center; flex: none; }
.org-name { font-weight: 600; font-size: 13px; line-height: 1.2; }
.org-sub { color: var(--muted); font-size: 11.5px; }
.nav-sec { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); font-weight: 600; padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px; color: var(--text-2); font-weight: 500; text-decoration: none; font-size: 13.5px; }
.nav a:hover { background: var(--hover); color: var(--text); }
.nav a.on { background: var(--active); color: var(--text); font-weight: 600; }
.nav a .icon { color: var(--muted); }
.nav a.on .icon { color: var(--accent); }
.nav .count { margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--muted); background: var(--hover); border-radius: 20px; padding: 0 7px; line-height: 19px; }
.nav .count.alert { color: var(--neg); background: var(--neg-soft); }
.side-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line); display: grid; gap: 2px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.demo-bar { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap; background: #10231f; color: #cfe9e4; font-size: 12.5px; padding: 6px 16px; }
.demo-bar b { color: #fff; font-weight: 600; }
.demo-bar button { background: none; border: 1px solid rgba(255, 255, 255, 0.25); color: #fff; border-radius: 20px; padding: 1px 10px; cursor: pointer; font-size: 12px; }
.demo-bar button:hover { background: rgba(255, 255, 255, 0.1); }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(10px); border-bottom: 1px solid transparent; }
.topbar.scrolled { border-bottom-color: var(--line); }
.menu-btn { display: none; }
.search { flex: 1; max-width: 460px; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; color: var(--muted); cursor: pointer; font-size: 13.5px; }
.search:hover { border-color: var(--line-strong); }
.search kbd { margin-left: auto; }
kbd { font: 600 11px var(--font); color: var(--muted); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px; padding: 0 5px; background: var(--surface-2); }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.seg-mini { display: flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg-mini button { border: 0; background: none; padding: 5px 9px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg-mini button.on { background: var(--active); color: var(--text); }
.ai-btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px 0 11px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; font-weight: 600; font-size: 13.5px; color: #fff; background: linear-gradient(135deg, #0f766e, #2f5fd0); }
.ai-btn:hover { filter: brightness(1.08); }
.ai-btn.on { background: var(--surface); color: var(--text); border-color: var(--line); }
.content { padding: 8px 28px 48px; width: 100%; max-width: 1440px; container-type: inline-size; container-name: content; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 10px 0 18px; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -0.02em; font-weight: 680; line-height: 1.2; }
.page-head .sub { color: var(--muted); margin-top: 3px; font-size: 13.5px; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 6px; align-items: center; }
.crumbs a { color: var(--muted); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Элементы ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--hover); border-color: var(--line-strong); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--neg); }
.btn.danger:hover { background: var(--neg-soft); border-color: transparent; }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--hover); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.icon-only { width: 36px; padding: 0; }
.btn.sm.icon-only { width: 30px; }
.btn.ai { color: var(--violet); }
.btn.ai:hover { background: var(--violet-soft); border-color: transparent; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 0; }
.card-h h3 { margin: 0; font-size: 14.5px; font-weight: 640; letter-spacing: -0.005em; }
.card-h .muted { font-size: 12.5px; }
.card-b { padding: 14px 18px 18px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
.mt { margin-top: 16px; }
.hr { height: 1px; background: var(--line); margin: 14px 0; }

.badge { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--hover); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.plain::before { display: none; }
.badge.paid, .badge.ok, .badge.booked, .badge.recognized { background: var(--pos-soft); color: var(--pos); }
.badge.overdue, .badge.failed { background: var(--neg-soft); color: var(--neg); }
.badge.sent, .badge.unpaid, .badge.due, .badge.processing { background: var(--info-soft); color: var(--info); }
.badge.partial, .badge.accruing, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.draft { background: var(--hover); color: var(--muted); }
.badge.ai { background: var(--violet-soft); color: var(--violet); }
.badge.ai::before { display: none; }

/* KPI */
.kpis { display: flex; flex-wrap: wrap; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.kpi { flex: 1 1 180px; padding: 16px 18px; background: var(--surface); min-width: 0; }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 22px; font-weight: 680; letter-spacing: -0.02em; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.lead .kpi-value { font-size: 26px; }
.kpi-foot { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.delta { font-weight: 650; font-size: 12px; }
.delta.up { color: var(--pos); }
.delta.down { color: var(--neg); }
.delta.up.bad { color: var(--neg); }
.delta.down.good { color: var(--pos); }

/* Сегменты, фильтры */
.seg { display: inline-flex; background: var(--hover); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 12px; font-weight: 600; font-size: 13.5px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: flex; gap: 7px; align-items: center; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs .tab-sum { font-weight: 500; color: var(--faint); font-size: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }

/* Поля */
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field small { color: var(--muted); font-size: 12px; }
.input, select.input, textarea.input { width: 100%; height: 36px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); outline: none; font-size: 13.5px; }
textarea.input { height: auto; min-height: 72px; padding: 9px 11px; resize: vertical; line-height: 1.45; }
.input:focus { border-color: var(--accent); box-shadow: var(--ring); }
.input.sm { height: 32px; font-size: 13px; }
.input.r { text-align: right; font-variant-numeric: tabular-nums; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.input-icon .input { padding-left: 34px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; font-size: 13.5px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Таблицы */
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface-2); position: sticky; top: 0; }
.t th.r, .t td.r { text-align: right; }
.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t tbody tr:last-child td { border-bottom: 0; }
.t tbody tr.click { cursor: pointer; }
.t tbody tr.click:hover td { background: var(--surface-2); }
.t tr.sel td { background: var(--accent-soft) !important; }
.t tr.hl td { animation: hl 2.4s ease-out; }
@keyframes hl { 0%, 40% { background: color-mix(in srgb, var(--warn-soft) 100%, transparent); } }
.t tfoot td { font-weight: 650; border-top: 1px solid var(--line-strong); border-bottom: 0; background: var(--surface-2); }
.t .cell-main { font-weight: 560; }
.t .cell-sub { font-size: 12px; color: var(--muted); }
.t td.amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; text-align: right; }
.t td.w1 { width: 1%; white-space: nowrap; }
.card > .table-wrap .t th:first-child, .card > .table-wrap .t td:first-child { padding-left: 18px; }
.card > .table-wrap .t th:last-child, .card > .table-wrap .t td:last-child { padding-right: 18px; }
.card > .table-wrap { border-radius: var(--radius); }
.card > .table-wrap .t th:first-child { border-top-left-radius: var(--radius); }
.card > .table-wrap .t th:last-child { border-top-right-radius: var(--radius); }
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty .icon { width: 32px; height: 32px; margin: 0 auto 10px; color: var(--faint); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }
.tx-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.tx-ico.income { background: var(--pos-soft); color: var(--pos); }
.tx-ico.expense { background: var(--neg-soft); color: var(--neg); }
.tx-ico.transfer { background: var(--info-soft); color: var(--info); }
.who { font-size: 11px; font-weight: 600; color: var(--violet); }

.bulk { position: sticky; bottom: 16px; z-index: 5; margin-top: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 10px 12px; background: var(--text); color: var(--bg); border-radius: 12px; box-shadow: var(--shadow-pop); }
.bulk .input { background: var(--surface); color: var(--text); width: auto; }

/* Списки */
.list { display: grid; }
.li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.li:last-child { border-bottom: 0; }
.li-main { flex: 1; min-width: 0; }
.li-title { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-amt { font-weight: 640; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
a.li { color: inherit; text-decoration: none; }
a.li:hover .li-title { color: var(--accent); }

.insight { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.insight:last-child { border-bottom: 0; }
.insight-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.insight-ico.warn { background: var(--warn-soft); color: var(--warn); }
.insight-ico.info { background: var(--info-soft); color: var(--info); }
.insight-ico.ok { background: var(--pos-soft); color: var(--pos); }
.ask-link { border: 0; background: none; padding: 0; margin-top: 4px; color: var(--violet); font-weight: 600; font-size: 12.5px; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; }
.ask-link:hover { text-decoration: underline; }

.bar { height: 7px; border-radius: 9px; background: var(--hover); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 9px; background: var(--accent); }
.bar.over > i { background: var(--neg); }
.bar.near > i { background: var(--warn); }

/* Графики */
.chart { width: 100%; position: relative; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-t { fill: var(--muted); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart .bar-in { fill: var(--income); }
.chart .bar-out { fill: var(--expense); }
.chart .line-profit { stroke: var(--text); stroke-width: 2; fill: none; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--text); fill-opacity: 0.04; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tip { position: absolute; z-index: 10; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 9px; padding: 8px 10px; font-size: 12px; line-height: 1.45; white-space: nowrap; box-shadow: var(--shadow-pop); transform: translate(-50%, calc(-100% - 10px)); }
.tip b { font-weight: 650; }
.tip .tr { display: flex; justify-content: space-between; gap: 14px; }
.donut-wrap { display: grid; grid-template-columns: 150px 1fr; gap: 18px; align-items: center; }
.donut-center { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.donut-total { font-size: 15px; font-weight: 700; fill: var(--text); font-family: var(--font); }
.s1 { fill: var(--c1); background: var(--c1); } .s2 { fill: var(--c2); background: var(--c2); } .s3 { fill: var(--c3); background: var(--c3); } .s4 { fill: var(--c4); background: var(--c4); }
.s5 { fill: var(--c5); background: var(--c5); } .s6 { fill: var(--c6); background: var(--c6); } .s7 { fill: var(--c7); background: var(--c7); } .s8 { fill: var(--c8); background: var(--c8); }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.hbar-label { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-val { font-size: 13px; font-weight: 620; text-align: right; font-variant-numeric: tabular-nums; }
.hbar-track { grid-column: 1 / -1; height: 6px; background: var(--hover); border-radius: 6px; overflow: hidden; margin-bottom: 8px; }
.hbar-track i { display: block; height: 100%; background: var(--c1); border-radius: 6px; }

/* Модальные окна и панели */
.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(8, 14, 12, 0.42); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; animation: fade 0.15s ease-out; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 560px; max-height: 88vh; overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-pop); animation: pop 0.18s ease-out; }
.modal.wide { max-width: 860px; }
@keyframes pop { from { transform: translateY(8px) scale(0.99); opacity: 0; } }
.modal-h { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.modal-h h3 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
.modal-b { padding: 12px 20px 8px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; flex-wrap: wrap; }
.drawer-ov { position: fixed; inset: 0; z-index: 55; background: rgba(8, 14, 12, 0.28); animation: fade 0.15s; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 56; width: min(480px, 100vw); background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; animation: slide 0.2s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer-b { padding: 4px 20px 16px; overflow-y: auto; flex: 1; }
.menu { position: absolute; z-index: 40; min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-pop); padding: 6px; }
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; border: 0; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-align: left; font-size: 13.5px; font-weight: 500; }
.menu button:hover { background: var(--hover); }
.menu button small { display: block; color: var(--muted); font-size: 12px; font-weight: 400; }
.toast-wrap { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 11px; font-size: 13.5px; box-shadow: var(--shadow-pop); display: flex; gap: 10px; align-items: center; animation: pop 0.2s; }
.toast.err { background: var(--neg); color: #fff; }

/* Палитра команд */
.palette { width: 100%; max-width: 620px; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-pop); overflow: hidden; animation: pop 0.15s; }
.palette-in { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.palette-in input { flex: 1; border: 0; outline: none; background: none; font-size: 15px; }
.palette-list { max-height: 56vh; overflow-y: auto; padding: 6px; }
.palette-group { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); padding: 10px 10px 4px; }
.palette-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; cursor: pointer; }
.palette-item.on { background: var(--hover); }
.palette-item .li-sub { margin-left: auto; }

/* ---------- ИИ-панель ---------- */
.ai-panel { position: sticky; top: 0; height: 100vh; background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.ai-panel.page { position: static; height: calc(100vh - 140px); border: 1px solid var(--line); border-radius: var(--radius); }
.ai-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--line); }
.ai-ava { width: 32px; height: 32px; border-radius: 10px; background: linear-gradient(135deg, #0f766e, #2f5fd0); color: #fff; display: grid; place-items: center; flex: none; }
.ai-title { font-weight: 650; font-size: 14px; line-height: 1.2; }
.ai-status { font-size: 11.5px; color: var(--muted); display: flex; gap: 5px; align-items: center; }
.ai-status i { width: 6px; height: 6px; border-radius: 50%; background: var(--pos); }
.ai-msgs { flex: 1; overflow-y: auto; padding: 16px 16px 8px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; flex-direction: column; gap: 8px; max-width: 100%; }
.msg.user { align-items: flex-end; }
.bubble { padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.55; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 5px; max-width: 88%; white-space: pre-wrap; }
.msg.assistant .bubble { padding: 0; }
.msg.system { align-items: center; }
.msg.system .bubble { background: var(--hover); color: var(--muted); font-size: 12.5px; padding: 5px 12px; }
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.file-chip { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; padding: 4px 9px; border-radius: 8px; background: var(--hover); border: 1px solid var(--line); max-width: 240px; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted); display: flex; }
.steps { display: grid; gap: 4px; }
.step { display: flex; gap: 8px; align-items: center; font-size: 12.5px; color: var(--muted); }
.step .icon { width: 14px; height: 14px; color: var(--pos); }
.spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.typing { display: inline-flex; gap: 4px; padding: 6px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }
.act-card { display: flex; gap: 10px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); text-decoration: none !important; color: inherit; }
.act-card:hover { border-color: var(--line-strong); }
.act-card .tx-ico { width: 28px; height: 28px; }
.act-title { font-weight: 600; font-size: 13px; }
.act-text { font-size: 12px; color: var(--muted); }
.rep-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); }
.rep-card-h { padding: 11px 12px 6px; }
.rep-card-h b { font-size: 13.5px; }
.rep-card-h p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.rep-card .chart { padding: 6px 10px 0; }
.rep-card .t { font-size: 12.5px; }
.rep-card .t td, .rep-card .t th { padding: 6px 10px; }
.rep-card-f { display: flex; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--line); background: var(--surface-2); }
.ai-empty { margin: auto 0; padding: 10px 2px; }
.ai-empty h4 { margin: 0 0 4px; font-size: 18px; letter-spacing: -0.01em; }
.ai-empty p { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.sugg { display: grid; gap: 6px; }
.sugg button { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 11px; padding: 9px 12px; cursor: pointer; font-size: 13px; display: flex; gap: 9px; align-items: center; }
.sugg button:hover { border-color: var(--violet); background: var(--violet-soft); }
.sugg .icon { color: var(--violet); }
.ai-undo { margin: 0 14px 8px; display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px 8px 12px; border-radius: 11px; background: var(--violet-soft); color: var(--violet); font-size: 12.5px; font-weight: 600; }
.composer { margin: 0 12px 12px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--surface); padding: 8px; }
.composer:focus-within { border-color: var(--accent); box-shadow: var(--ring); }
.composer textarea { width: 100%; border: 0; outline: none; background: none; resize: none; font-size: 13.5px; line-height: 1.45; max-height: 160px; min-height: 22px; padding: 4px 6px; display: block; }
.composer-f { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.composer-f .hint { font-size: 11.5px; color: var(--faint); margin-right: auto; padding-left: 4px; }
.send { width: 32px; height: 32px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; cursor: pointer; display: grid; place-items: center; }
.send:disabled { background: var(--line-strong); cursor: default; }
.drop-hint { position: absolute; inset: 0; z-index: 5; background: color-mix(in srgb, var(--accent-soft) 92%, transparent); border: 2px dashed var(--accent); border-radius: 12px; display: grid; place-items: center; color: var(--accent); font-weight: 650; }

/* Markdown */
.md { font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md li { margin: 2px 0; }
.md h1, .md h2, .md h3, .md h4 { font-size: 14px; margin: 12px 0 6px; }
.md code { font-size: 12.5px; background: var(--hover); padding: 1px 5px; border-radius: 5px; }
.md table { border-collapse: collapse; width: 100%; margin: 6px 0 10px; font-size: 12.5px; display: block; overflow-x: auto; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; white-space: nowrap; }
.md th { color: var(--muted); font-weight: 600; background: var(--surface-2); }
.md td.r, .md th.r { text-align: right; font-variant-numeric: tabular-nums; }
.md blockquote { margin: 0 0 8px; padding: 2px 12px; border-left: 3px solid var(--line-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 10px 0; }

/* Документы: счёт как лист */
.paper { background: #fff; color: #111; border-radius: 6px; padding: 40px 44px; font-size: 12.5px; line-height: 1.5; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.06); }
.paper h2 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.paper .p-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.paper .p-logo { display: flex; gap: 10px; align-items: center; font-weight: 700; font-size: 15px; }
.paper .p-logo i { width: 30px; height: 30px; border-radius: 8px; background: #1f3b73; display: inline-block; }
.paper .p-meta { text-align: right; color: #555; }
.paper .p-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin: 26px 0 18px; }
.paper .p-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.08em; color: #888; margin-bottom: 4px; font-weight: 600; }
.paper table { width: 100%; border-collapse: collapse; }
.paper th { text-align: left; font-size: 11px; color: #777; font-weight: 600; border-bottom: 1.5px solid #222; padding: 7px 6px; }
.paper td { border-bottom: 1px solid #e5e5e5; padding: 8px 6px; }
.paper .r { text-align: right; font-variant-numeric: tabular-nums; }
.paper .p-total { margin-left: auto; width: 260px; margin-top: 12px; }
.paper .p-total div { display: flex; justify-content: space-between; padding: 3px 6px; }
.paper .p-total .g { font-weight: 700; font-size: 15px; border-top: 1.5px solid #222; margin-top: 4px; padding-top: 8px; }
.paper .p-foot { margin-top: 30px; color: #666; font-size: 11.5px; display: flex; justify-content: space-between; gap: 20px; }
.paper .p-status { display: inline-block; border: 2px solid; border-radius: 6px; padding: 2px 10px; font-weight: 800; letter-spacing: 0.1em; font-size: 12px; transform: rotate(-4deg); }
.doc-preview { background: var(--hover); border-radius: 12px; overflow: hidden; display: grid; place-items: center; min-height: 420px; border: 1px solid var(--line); }
.doc-preview img { max-width: 100%; max-height: 78vh; display: block; }
.doc-preview iframe { width: 100%; height: 78vh; border: 0; background: #fff; }
.items-edit .t td { padding: 6px 6px; }
.items-edit .input { height: 32px; }
.conf { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.conf .bar { width: 90px; }
.warn-box { background: var(--warn-soft); color: var(--warn); border-radius: 11px; padding: 10px 12px; font-size: 13px; display: grid; gap: 4px; }
.info-box { background: var(--accent-soft); color: var(--accent); border-radius: 11px; padding: 10px 12px; font-size: 13px; }

.dropzone { border: 1.5px dashed var(--line-strong); border-radius: 16px; background: var(--surface); padding: 34px 20px; text-align: center; cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big-ico { width: 52px; height: 52px; border-radius: 15px; margin: 0 auto 12px; background: linear-gradient(135deg, #0f766e, #2f5fd0); color: #fff; display: grid; place-items: center; }
.dropzone h3 { margin: 0 0 4px; font-size: 17px; }
.samples { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.sample { display: flex; gap: 12px; align-items: center; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px; cursor: pointer; text-align: left; }
.sample:hover { border-color: var(--accent); }
.sample img { width: 46px; height: 58px; object-fit: cover; object-position: top; border-radius: 5px; border: 1px solid var(--line); background: #fff; }

.acc-card { padding: 16px 18px; display: grid; gap: 4px; }
.acc-type { width: 34px; height: 34px; border-radius: 10px; background: var(--hover); display: grid; place-items: center; color: var(--text-2); }
.acc-bal { font-size: 22px; font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.proj-card { padding: 16px 18px; display: grid; gap: 10px; text-decoration: none !important; color: inherit; }
.proj-card:hover { border-color: var(--line-strong); }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-row .k { font-size: 11.5px; color: var(--muted); }
.stat-row .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.cal-day { display: grid; grid-template-columns: 92px 1fr; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.cal-day:last-child { border-bottom: 0; }
.cal-date { font-weight: 650; }
.cal-date small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.integr { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.integr:last-child { border-bottom: 0; }
.integr-logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 13px; color: #fff; flex: none; }

/* ---------- Адаптив ---------- */
@media (max-width: 1280px) {
  .app.ai-open { grid-template-columns: 252px 1fr; }
  .app.ai-open .ai-panel:not(.page) { position: fixed; right: 0; top: 0; bottom: 0; width: min(432px, 100vw); z-index: 50; box-shadow: var(--shadow-pop); }
}
@media (max-width: 900px) {
  .app, .app.ai-open { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 272px; z-index: 70; transform: translateX(-100%); transition: transform 0.2s; box-shadow: var(--shadow-pop); }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 6px 16px 40px; }
  .search { max-width: none; }
  .search span, .search kbd { display: none; }
  .search { flex: 0 0 36px; padding: 0; justify-content: center; }
  .samples, .form-grid { grid-template-columns: 1fr; }
  .donut-wrap { grid-template-columns: 1fr; justify-items: center; }
  .ai-btn span { display: none; }
  .ai-btn { padding: 0 10px; }
  .hide-m { display: none !important; }
  .page-head h1 { font-size: 21px; }
  .cal-day { grid-template-columns: 1fr; gap: 6px; }
  .paper { padding: 22px 18px; }
  .paper .p-parties { grid-template-columns: 1fr; }
}

/* Сетка по ширине области содержимого (панель ИИ сужает её) */
@container content (max-width: 1180px) {
  .kpi { flex-basis: 220px; }
  .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main { grid-template-columns: 1fr; }
}
@container content (max-width: 900px) {
  .g2 { grid-template-columns: 1fr; }
  .builder { grid-template-columns: 1fr !important; }
}
@container content (max-width: 700px) {
  .kpi { flex-basis: 150px; padding: 13px 14px; }
  .g3 { grid-template-columns: 1fr; }
  .samples { grid-template-columns: 1fr; }
  .kpi-value { font-size: 19px; }
}
.rep-card .t td:first-child { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rep-card .t td, .rep-card .t th { white-space: nowrap; }

/* Печать: только документ */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .demo-bar, .ai-panel, .no-print, .toast-wrap { display: none !important; }
  .app, .app.ai-open { display: block; }
  .content { padding: 0; max-width: none; }
  .paper { box-shadow: none; padding: 0; }
}

/* Уточнения таблиц и фильтров */
.filters select.input { width: auto; min-width: 140px; max-width: 220px; }
.filters .input-icon .input { width: 100%; }
.t .cell-main, .t .cell-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 440px; }
.t td { white-space: nowrap; }
.t td.wrap-ok { white-space: normal; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
@container content (max-width: 1040px) {
  .hide-n { display: none !important; }
  .t .cell-main, .t .cell-sub { max-width: 260px; }
}
.split { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
.split > .sticky { position: sticky; top: 76px; }
@container content (max-width: 720px) { .split { grid-template-columns: 1fr; } .split > .sticky { position: static; } }
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
@container content (max-width: 700px) {
  .kpi.lead .kpi-value { font-size: 21px; }
  .t .cell-main, .t .cell-sub { max-width: 150px; }
  .t th, .t td { padding: 9px 8px; }
  .page-head { margin-bottom: 12px; }
  .head-actions { width: 100%; }
}
.split .t td:first-child { white-space: normal; min-width: 140px; }
