:root {
  --bg: #f4f6f9; --panel: #ffffff; --border: #d9dee7; --accent: #2563eb;
  --accent-soft: #e8efff; --text: #1f2937; --muted: #8a93a3; --danger: #dc2626; --ok: #16a34a;
  --purple: #7c3aed; --purple-soft: #f3ecfe; --green: #059669; --green-soft: #e9f8f2;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.topbar { display: flex; align-items: center; gap: 24px; background: #1e293b; padding: 0 20px; height: 52px; }
.brand { color: #fff; font-weight: 700; letter-spacing: .5px; }
.tabs { display: flex; gap: 6px; height: 100%; }
.tab { border: 0; background: transparent; color: #cbd5e1; padding: 0 18px; font-size: 14px; cursor: pointer; border-bottom: 3px solid transparent; }
.tab.active { color: #fff; border-bottom-color: var(--accent); background: rgba(255,255,255,.06); }
.workspace { padding: 16px; }
/* Минимальные ширины колонок (решение владельца, сессия 3): 25% / 35% / 25%,
   чтобы длинные наименования не могли схлопнуть колонку почти в ноль;
   .col { min-width: 0 } — длинные таблицы скроллятся внутри .tbl-wrap */
.three-cols { display: grid; grid-template-columns: minmax(25%, 1fr) minmax(35%, 1fr) minmax(25%, 1fr); gap: 16px; align-items: start; }
.col { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px; min-width: 0; }
.col-title { margin: 4px 0 10px; font-size: 15px; }
.filter-row { margin-bottom: 10px; }
input[type="text"], input[type="number"], input[type="date"] {
  width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff;
}
input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.tbl-wrap { max-height: 250px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.txn-fullwidth { grid-column: 1 / -1; }
.txn-wrap { max-height: 420px; }
.txn-party { display: block; }
.txn-bank { display: block; color: var(--muted); font-size: 11px; }
.txn-link { cursor: pointer; text-decoration: underline dotted; }
.txn-link:hover { color: #2563eb; }
.txn-purpose { font-size: 12px; color: #475569; max-width: 360px; }
/* панель фильтров юрлиц: select чуть компактнее текстового поля */
#entities-flow { font-size: 13px; padding: 6px 8px; }
.txn-note { margin-top: 6px; color: var(--muted); font-size: 11.5px; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { position: sticky; top: 0; background: #eef1f6; text-align: left; font-weight: 600; padding: 7px 9px; border-bottom: 1px solid var(--border); }
.data-table td { padding: 6px 9px; border-bottom: 1px solid #eef0f4; white-space: nowrap; }
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: #f2f6ff; }
.data-table tbody tr.selected { background: var(--accent-soft); }
.data-table tbody tr.selected td:first-child { font-weight: 600; }
.empty-note { padding: 10px; color: var(--muted); font-style: italic; }
.muted { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: #47536b; }
.full { grid-column: 1 / -1; }
.inn-row { display: flex; gap: 14px; }
.inn-row label { flex: 1; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.btn-row button { padding: 8px 14px; border: 1px solid var(--border); background: #fff; border-radius: 7px; cursor: pointer; font: inherit; }
.btn-row button:hover:not(:disabled) { background: #f2f6ff; }
.btn-row button:disabled { opacity: .45; cursor: not-allowed; }
#btn-save { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#btn-save:disabled { background: #c7d2ec; border-color: #c7d2ec; }
#btn-delete { color: var(--danger); }
#btn-delete:disabled { color: #9aa3ad; }
.form-message { margin-top: 12px; padding: 8px 10px; border-radius: 7px; background: #eef6ff; color: #1d4ed8; }
.form-message.error { background: #fdecec; color: var(--danger); }
.status-active { color: var(--ok); font-weight: 600; }
.status-ended { color: #b45309; }
.placeholder { background: var(--panel); border: 1px dashed var(--border); border-radius: 10px; padding: 48px; text-align: center; color: var(--muted); font-size: 16px; }
@media (max-width: 1100px) { .three-cols { grid-template-columns: 1fr; } }

/* ==== Учет договора (уровень договора) ==== */
.accounting-block { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; background: #fafbfd; }
.acc-title { margin: 0 0 4px; font-size: 13.5px; font-weight: 600; }
.acc-hint { margin: 0 0 8px; font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.acc-note { font-size: 11px; color: var(--muted); font-style: italic; }

/* ==== Вкладка «группы» (P2a): фиолетовый акцент #7c3aed ==== */
.tab-groups.active { color: #fff; border-bottom-color: var(--purple); background: rgba(255,255,255,.06); }
.tab-groups:hover:not(.active) { color: #fff; }
.readonly-input { background: #f3f4f6; color: #374151; }
#view-groups .col-title { color: var(--purple); }
#view-groups .col:nth-child(2) { border-left: 3px solid var(--purple); }
#view-groups input:focus { outline: 2px solid var(--purple-soft); border-color: var(--purple); }
#view-groups .data-table tbody tr:hover { background: var(--purple-soft); }
#view-groups .data-table tbody tr.selected { background: var(--purple-soft); }
#view-groups .data-table tbody tr.selected td:first-child { font-weight: 600; }
#btn-group-save { background: var(--purple); border-color: var(--purple); color: #fff; font-weight: 600; }
#btn-group-save:disabled { background: #ddd2f4; border-color: #ddd2f4; }
#btn-member-add { color: var(--purple); border-color: var(--purple); }
#btn-member-add:disabled { color: #b6a8d8; border-color: var(--border); }
#btn-member-remove, #btn-group-delete { color: var(--danger); }
#btn-member-remove:disabled, #btn-group-delete:disabled { color: #9aa3ad; }
.member-divider { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
#groups-message { background: #f3ecfe; color: #6d28d9; }
#groups-message.error { background: #fdecec; color: var(--danger); }

/* ==== Вкладка «отчеты» (P2b): зелёный акцент #059669 ==== */
#view-reports { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 16px; align-items: start; }
#view-reports.hidden { display: none; }
.tab-reports.active { color: #fff; border-bottom-color: var(--green); background: rgba(255,255,255,.06); }
#view-reports .col-title { color: var(--green); }
.form-grid.one-col { grid-template-columns: 1fr; }
select { width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; }
select:focus { outline: 2px solid var(--accent-soft); border-color: var(--green); }
.rpt-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grain-hint { margin-top: -2px; font-size: 11px; color: var(--muted); font-style: italic; line-height: 1.45; }
select option:disabled { color: #b3bac4; }
.chk-row { display: flex; gap: 8px; align-items: flex-start; margin-top: 12px; font-size: 12.5px; color: #47536b; }
.chk-row input { width: auto; margin-top: 2px; }
#rpt-build { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; padding: 8px 14px; border-radius: 7px; cursor: pointer; font: inherit; border-width: 1px; }
#rpt-build:disabled { background: #b9dccd; border-color: #b9dccd; color: #f2fff8; cursor: not-allowed; }
#rpt-message { background: #e9f8f2; color: #047857; }
#rpt-message.error { background: #fdecec; color: var(--danger); }
.rpt-scope { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; }
.rpt-scope .scope-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px dashed #e6eaf0; }
.rpt-scope .scope-row:last-child { border-bottom: 0; }
.rpt-scope .scope-kop { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rpt-scope .scope-row.off { opacity: .45; }
.rpt-scope .scope-cb { flex: 0 0 auto; margin: 1px 0 0; cursor: pointer; }
.rpt-scope .scope-name { cursor: pointer; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-scope .scope-kop { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
.rpt-scope .scope-io { display: flex; gap: 8px; }
.rpt-scope .scope-in { color: #047857; }
.rpt-scope .scope-out { color: #b91c1c; }
.rpt-scope .scope-row.off .scope-in, .rpt-scope .scope-row.off .scope-out { color: #64748b; }
.rpt-scope .scope-intra { font-size: 11px; color: #8a93a3; }
.rpt-scope .scope-off-note { margin-top: 4px; font-size: 11.5px; color: #b45309; }
.rpt-legend { max-height: 300px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px; }
.legend-toggle-all { font: inherit; font-size: 11px; padding: 1px 8px;
  border: 1px solid #c9d4e2; border-radius: 10px; background: #fff;
  color: #35507a; cursor: pointer; margin-right: 8px; }
.legend-toggle-all:hover { background: #eef3fa; }
.legend-toggle-all:disabled { opacity: .45; cursor: default; }
.rpt-hint { display: flex; align-items: center; flex-wrap: wrap; }
.legend-row { display: flex; align-items: center; gap: 7px; padding: 3px 4px; border-radius: 6px; cursor: pointer; font-size: 12px; }
.legend-row:hover { background: #f4f7fa; }
.legend-row.off { opacity: .4; }
.legend-row .swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; border: 1px solid rgba(0,0,0,.15); }
.legend-row .lg-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .lg-kop { font-variant-numeric: tabular-nums; white-space: nowrap; color: #47536b; }
.legend-arrow { font-size: 11px; width: 12px; text-align: center; flex: 0 0 auto; }
.legend-arrow.in { color: var(--green); }
.legend-arrow.out { color: var(--danger); }
.rpt-hint { margin-top: 6px; font-size: 11px; color: var(--muted); font-style: italic; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 8px 10px; }
.kpi.k-in { border-left-color: var(--green); }
.kpi.k-out { border-left-color: var(--danger); }
.kpi.k-net { border-left-color: #0ea5e9; }
.kpi.k-acc { border-left-color: #7c3aed; }
.kpi .k-label { font-size: 11px; color: var(--muted); }
.kpi .k-value { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .k-sub { font-size: 11px; color: var(--muted); }
.rpt-main { display: flex; flex-direction: column; gap: 10px; }
.chart-box { position: relative; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px; }
#rpt-chart { display: block; width: 100%; height: 560px; }
.rpt-tooltip { position: absolute; z-index: 5; pointer-events: none; background: #ffffff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 18px rgba(15, 23, 42, .12); padding: 8px 10px; font-size: 12px; max-width: 340px; }
.rpt-tooltip .tt-date { font-weight: 700; margin-bottom: 4px; }
.rpt-tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.rpt-tooltip .tt-sum { margin-left: auto; font-variant-numeric: tabular-nums; }
.rpt-tooltip .tt-total { margin-top: 4px; padding-top: 4px; border-top: 1px solid #eef0f4; font-weight: 600; }
.rpt-note { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
@media (max-width: 1100px) { #view-reports { grid-template-columns: 1fr; } }

/* ---- drill-down под графиком (A9): транзакции интервала/сегмента ---- */
.rpt-drill { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: #fff; }
.rpt-drill .drill-head { display: flex; align-items: flex-start; gap: 10px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.rpt-drill .drill-title { font-weight: 700; font-size: 14px; }
.rpt-drill .drill-title .drill-seg { color: var(--green); }
.rpt-drill .drill-hint { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 2px; }
.rpt-drill .drill-close { margin-left: auto; flex: none; border: 1px solid var(--border); background: #f7f9fb; border-radius: 6px; padding: 4px 9px; cursor: pointer; font: inherit; font-size: 12px; }
.rpt-drill .drill-muted { font-size: 11.5px; color: var(--muted); margin-top: 6px; }
.rpt-drill .drill-block { margin-top: 12px; }
.rpt-drill .drill-block-title { display: flex; gap: 8px; font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.rpt-drill .drill-count { color: var(--muted); font-weight: 400; font-size: 11.5px; }
.rpt-drill .drill-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.rpt-drill .drill-table th { text-align: left; padding: 5px 8px; background: #f1f5f9; border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap; }
.rpt-drill .drill-table th.on { background: #e2e8f0; }
.rpt-drill .drill-table th .drill-arrow { font-size: 9px; margin-left: 3px; color: var(--green); }
.rpt-drill .drill-table td { padding: 4px 8px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.rpt-drill .drill-table td.drill-sum { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rpt-drill .drill-table td.drill-our { max-width: 200px; color: #334155; }
.rpt-drill .drill-table td.drill-cp { max-width: 640px; }
.rpt-drill .drill-table .drill-purp { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rpt-drill .drill-table .drill-kind { display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 4px; background: #eef2f7; color: #334155; font-size: 10.5px; }
.rpt-drill .drill-table tfoot td { font-weight: 700; background: #f8fafc; border-bottom: 0; }
.rpt-drill .drill-balance { margin-top: 10px; font-weight: 700; font-size: 13.5px; }

/* A24: вкладка «загрузка» */
.import-wrap { max-width: 900px; margin: 0 auto; padding: 16px; }
.import-h3 { font-size: 14px; margin: 14px 0 6px; }
.import-block { margin-bottom: 10px; }
.import-dir-list { max-height: 220px; overflow: auto; border: 1px solid #334155;
  border-radius: 6px; padding: 8px; font-size: 13px; }
.import-dir-row { display: block; margin: 2px 0; }
.import-actions { display: flex; gap: 10px; margin: 12px 0; }
.import-message { margin: 8px 0; font-size: 13px; }
.import-message.error { color: #f87171; }
.import-result { border: 1px solid #334155; border-radius: 6px; padding: 10px;
  font-size: 13px; margin-top: 8px; }
.import-item { margin-top: 4px; }
.import-conflict, .import-error { color: #f87171; }
.import-added { color: #4ade80; }

/* A24.2: журнал анализа и прогресс-бар */
.import-log { max-height: 260px; overflow: auto; border: 1px solid #334155;
  border-radius: 6px; padding: 8px 10px; font: 12px/1.5 ui-monospace, monospace;
  white-space: pre-wrap; margin-bottom: 10px; }
.import-log-line.head { color: #93c5fd; }
.import-log-line.added { color: #4ade80; }
.import-log-line.conflict, .import-log-line.error { color: #f87171; }
.import-log-line.dim { color: #64748b; }
.import-progress { position: relative; height: 18px; border: 1px solid #334155;
  border-radius: 9px; overflow: hidden; margin: 8px 0; background: #0f172a; }
.import-progress-bar { height: 100%; width: 0%; background: #2563eb;
  transition: width 0.2s ease; }
.import-progress-text { position: absolute; inset: 0; text-align: center;
  font-size: 12px; line-height: 18px; color: #e2e8f0; }

/* A25 «особенности учёта» */
.rules-wrap { max-width: 1240px; margin: 0 auto; padding: 16px; }
.rules-cols { display: flex; gap: 18px; align-items: flex-start; }
.rules-left { flex: 0 0 420px; }
.rules-right { flex: 1; min-width: 0; }
.rules-list { max-height: 420px; overflow: auto; border: 1px solid #334155;
  border-radius: 6px; padding: 6px; font-size: 12px; }
.rules-row { padding: 5px 6px; border-radius: 4px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 8px; }
.rules-row:hover { background: #1e293b; }
.rules-row.sel { background: #1d4ed8; }
.rules-row.off { opacity: .45; text-decoration: line-through; }
.rules-actions { display: flex; gap: 10px; margin: 10px 0; }
.rules-editor { border: 1px solid #334155; border-radius: 6px; padding: 10px;
  font-size: 12px; min-height: 120px; }
.rules-ed-row { margin: 6px 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.rules-ed-mini { width: 130px; }
.rules-cond { display: flex; gap: 6px; margin: 6px 0; align-items: center; flex-wrap: wrap; }
.rules-test-input { width: 100%; background: #0f172a; color: #e2e8f0;
  border: 1px solid #334155; border-radius: 6px; padding: 6px; font-size: 12px; }
.rules-test-out { margin-top: 6px; font-size: 12px; }
.rules-test-line { padding: 2px 0; }
.rules-test-line.hit { color: #4ade80; }
.rules-test-line.dim { color: #64748b; }
.rules-test-line.head { color: #93c5fd; font-weight: 600; }
.rules-test-line.conflict { color: #f87171; }
.rules-impact { border: 1px solid #334155; border-radius: 6px; padding: 8px;
  margin-top: 8px; font-size: 12px; }
.btn-mini { padding: 2px 8px; font-size: 11px; }

/* A28: кнопка пользователя в шапке */
.auth-who { margin-left: 12px; border: 1px solid #d8dee9; background: #fff; border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px; color: #334155; }
.auth-who:hover { background: #f1f5f9; }
