/* Финансовая CRM — светлая тема. Шрифт Golos Text (локально, см. fonts/). */

/* Вариативный Golos Text: один файл на веса 400–700, сабсеты по unicode-range */
@font-face {
  font-family: 'Golos Text';
  src: url('/fonts/golos-var-cyrillic.woff2') format('woff2');
  font-weight: 400 700; font-style: normal; font-display: swap;
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Golos Text';
  src: url('/fonts/golos-var-latin.woff2') format('woff2');
  font-weight: 400 700; font-style: normal; font-display: swap;
  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 {
  --bg: #F4F6F4;
  --surface: #FFFFFF;
  --surface-2: #FAFBFA;
  --border: #E3E8E4;
  --border-strong: #C9D2CC;
  --text: #1A2420;
  --text-soft: #58675F;
  --accent: #0E6B4E;
  --accent-hover: #0B5940;
  --accent-soft: #E6F2EC;
  --negative: #B23B31;
  --negative-soft: #F9ECEA;
  --positive: #0E6B4E;
  --shadow: 0 1px 2px rgba(26, 36, 32, .05), 0 4px 16px rgba(26, 36, 32, .06);
  --radius: 12px;
  /* Палитра категорий (донат + метки) — приглушённые, различимые */
  --cat-1: #2F7D5D; --cat-2: #B0883B; --cat-3: #4E77B2; --cat-4: #B25948;
  --cat-5: #7A67A8; --cat-6: #398B8B; --cat-7: #A05F86; --cat-8: #6F8A3D;
  --cat-9: #8A6F52; --cat-10: #4E6577; --cat-11: #9A7440; --cat-12: #737B84;
}

* { box-sizing: border-box; }
/* hidden обязан побеждать явные display:flex/grid на тех же элементах */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: 'Golos Text', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
h1, h2, h3 { margin: 0; font-weight: 700; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }

/* ── Каркас ──────────────────────────────────────────────────────────── */
#shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 20px 14px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 15px; padding: 2px 8px 18px; }
.brand-mark { margin-right: 6px; }
.nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px;
  color: var(--text); font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-ico { width: 20px; text-align: center; }
.sidebar-foot {
  border-top: 1px solid var(--border);
  padding-top: 12px; display: flex; flex-direction: column; gap: 10px;
}
.sidebar-actions { display: flex; gap: 6px; }
.sidebar-actions .btn { flex: 1; padding: 6px 8px; font-size: 12.5px; }

/* Нативный <dialog>: смена пароля */
.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  width: min(360px, 90vw);
}
.dialog::backdrop { background: rgba(26, 36, 32, 0.45); }
.dialog h2 { margin: 0 0 14px; font-size: 17px; }
.dialog label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--text-soft); }
.dialog input { width: 100%; margin-top: 4px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.me { flex: 1; min-width: 0; }
.me-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-role { color: var(--text-soft); font-size: 12px; }

.page { padding: 26px 32px 48px; max-width: 1280px; width: 100%; }

/* ── Кнопки и поля ───────────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn-primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }

input, select {
  font: inherit;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
label { display: block; font-weight: 500; margin-bottom: 12px; }
label > input, label > select { margin-top: 5px; }

/* ── Вход ────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--bg) 60%, var(--accent-soft));
  padding: 20px;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  width: 360px; padding: 32px;
}
.login-logo { font-size: 34px; }
.login-card h1 { font-size: 20px; margin: 10px 0 2px; }
.login-sub { color: var(--text-soft); margin: 0 0 20px; }
.login-error {
  background: var(--negative-soft); color: var(--negative);
  border-radius: 8px; padding: 9px 12px; margin-bottom: 12px; font-weight: 500;
}

/* ── Карточки и страницы ─────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.page-head {
  display: flex; align-items: center; gap: 14px; margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-head h1 { font-size: 22px; }
.page-head .spacer { flex: 1; }
.crumb { color: var(--text-soft); font-weight: 500; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 12px; font-weight: 500;
}
.badge.muted { background: var(--surface-2); color: var(--text-soft); }
.badge.warn { background: #F6E9D8; color: #8A5A1F; }

/* Сегментный контрол периодов */
.seg {
  display: inline-flex; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px; padding: 3px;
  gap: 2px;
}
.seg button {
  border: 0; background: transparent; border-radius: 7px;
  padding: 6px 12px; cursor: pointer; color: var(--text-soft); font-weight: 500;
  white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.active { background: var(--accent); color: #fff; }

/* KPI-строка карточки клиента: главная цифра первой */
.kpi-hero { display: flex; align-items: flex-end; gap: 26px; flex-wrap: wrap; }
.kpi-main .kpi-label { color: var(--text-soft); font-weight: 500; }
.kpi-main .kpi-value {
  font-size: 38px; font-weight: 700; letter-spacing: -.5px;
  font-variant-numeric: tabular-nums; line-height: 1.15;
}
.kpi-delta { font-weight: 500; padding-bottom: 7px; }
.kpi-delta.up { color: var(--negative); }     /* расходы выросли — плохо */
.kpi-delta.down { color: var(--positive); }   /* расходы упали — хорошо */
.kpi-delta.flat { color: var(--text-soft); }

/* Донат + легенда */
.donut-grid {
  display: grid; grid-template-columns: 240px 1fr; gap: 26px;
  align-items: center;
}
.donut-svg-box { position: relative; width: 220px; height: 220px; margin: 0 auto; }
.donut-svg-box svg { width: 100%; height: 100%; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; pointer-events: none;
}
.donut-center .dc-total { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-center .dc-label { color: var(--text-soft); font-size: 12px; }
.donut-seg { cursor: pointer; transition: opacity .15s; }
.donut-seg.dim { opacity: .25; }
.legend { display: flex; flex-direction: column; gap: 4px; }
.legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  grid-template-areas: "sw name sum" ". bar delta";
  column-gap: 10px; row-gap: 3px;
  align-items: center; padding: 7px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
}
.legend-row:hover { background: var(--surface-2); }
.legend-row.active { background: var(--accent-soft); border-color: var(--accent); }
.legend-row.dim { opacity: .4; }
.legend-sw { grid-area: sw; width: 12px; height: 12px; border-radius: 4px; }
.legend-name { grid-area: name; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-sum { grid-area: sum; font-variant-numeric: tabular-nums; font-weight: 500; }
.legend-sum .legend-pct { color: var(--text-soft); font-weight: 400; margin-left: 6px; }
.legend-bar { grid-area: bar; height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; }
.legend-bar i { display: block; height: 100%; border-radius: 2px; }
.legend-delta {
  grid-area: delta; font-size: 12px; font-variant-numeric: tabular-nums;
  color: var(--text-soft); text-align: right; white-space: nowrap;
}
.legend-delta.up { color: var(--negative); }
.legend-delta.down { color: var(--positive); }

/* Инсайт-плашка под KPI (идея Дзен-мани): вывод человеческим языком */
.insight {
  margin-top: 14px; padding: 10px 14px; border-radius: 10px;
  font-weight: 500; display: inline-block;
}
.insight.up { background: var(--negative-soft); color: var(--negative); }
.insight.down { background: var(--accent-soft); color: var(--accent); }
.insight.flat { background: var(--surface-2); color: var(--text-soft); }

.section-gap { margin-top: 20px; }
.muted { color: var(--text-soft); }
.empty-note {
  text-align: center; color: var(--text-soft); padding: 36px 10px;
}

/* Вкладки карточки клиента */
.tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tabs a {
  padding: 9px 16px; color: var(--text-soft); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Виджет цели */
.goal-card { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.goal-text .goal-title { font-weight: 700; font-size: 16px; }
.goal-text .goal-sub { color: var(--text-soft); }
.goal-bar {
  flex: 1; min-width: 220px; height: 10px; border-radius: 6px;
  background: var(--border); overflow: hidden;
}
.goal-bar i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.goal-pct { font-weight: 700; font-size: 18px; color: var(--accent); }

/* Плитки финансовой сводки */
.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
}
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; cursor: pointer; text-align: left; font: inherit;
  transition: border-color .15s;
}
.tile:hover { border-color: var(--accent); }
.tile.active { border-color: var(--accent); background: var(--accent-soft); }
.tile-label { color: var(--text-soft); font-weight: 500; }
.tile-value {
  font-size: 24px; font-weight: 700; margin-top: 4px;
  font-variant-numeric: tabular-nums; letter-spacing: -.3px;
}
.tile-sub { color: var(--text-soft); font-size: 12px; margin-top: 4px; }

/* Раскрытая панель статей */
.entry-row {
  display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px;
  align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.entry-row:last-child { border-bottom: 0; }
.entry-name { font-weight: 500; }
.entry-meta { color: var(--text-soft); font-size: 12px; margin-top: 2px; }
.entry-value { font-variant-numeric: tabular-nums; font-weight: 700; }
.entry-dyn { font-size: 12px; font-variant-numeric: tabular-nums; }
.entry-dyn.up { color: var(--positive); }     /* активы растут — хорошо */
.entry-dyn.down { color: var(--negative); }
.entry-dyn.lia-up { color: var(--negative); } /* пассивы растут — плохо */
.entry-dyn.lia-down { color: var(--positive); }
.icon-btn {
  border: 0; background: transparent; cursor: pointer; font-size: 14px;
  color: var(--text-soft); padding: 4px 6px; border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* График тренда расходов */
.trend-wrap { margin-top: 18px; }
.trend-legend { display: flex; gap: 16px; color: var(--text-soft); font-size: 12px; margin-top: 6px; }
.trend-legend .sw { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }

/* Отчёт по портфелю */
.report-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px; margin-top: 16px;
}
.report-item { background: var(--surface-2); border-radius: 10px; padding: 12px 14px; }
.report-item .ri-label { color: var(--text-soft); font-size: 12px; font-weight: 500; }
.report-item .ri-value { font-weight: 700; margin-top: 3px; }
.pnl-pos { color: var(--positive); }
.pnl-neg { color: var(--negative); }
.report-summary {
  margin-top: 14px; padding: 12px 16px;
  background: var(--surface-2); border-radius: 10px;
}

/* ── Совместимость с DataTable из Zekkert (классы компонента) ─────────── */
.tbl-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.tbl-toolbar { display: flex; gap: 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tbl-title { font-weight: 700; font-size: 16px; }
.tbl-search input { width: 220px; }
.tbl-wrap { overflow: auto; }
table.tbl { border-collapse: collapse; width: 100%; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tbl th { color: var(--text-soft); font-weight: 500; font-size: 12.5px; position: sticky; top: 0; background: var(--surface); cursor: pointer; user-select: none; }
.tbl tbody tr:hover { background: var(--surface-2); cursor: pointer; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-foot { padding: 10px 16px; color: var(--text-soft); font-size: 12.5px; }

/* Модалка (совместимо с modal.js Zekkert) */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 28, 24, .45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  width: min(480px, calc(100vw - 40px)); max-height: 86vh; overflow: auto;
  padding: 24px;
}
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* Тосты (toast.js) */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 90; }
.toast {
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-weight: 500;
}
.toast.error { background: var(--negative); }

/* ── Дашборд финансиста (по мотивам Flux/Orbix) ───────────────────────── */
.dash-preview-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin-bottom: 16px; padding: 10px 14px;
  background: var(--surface-2); border: 1px dashed var(--border-strong);
  border-radius: var(--radius); color: var(--text-soft); font-size: 13px;
}
.dash-head {
  border-radius: var(--radius);
  padding: 22px 24px 18px;
  margin-bottom: 16px;
  /* мягкое «свечение» шапки — приём Flux, но в нашем изумруде */
  background:
    radial-gradient(420px 150px at 12% 0%, rgba(14, 107, 78, .10), transparent 70%),
    radial-gradient(520px 190px at 88% 10%, rgba(176, 136, 59, .08), transparent 70%),
    var(--surface);
  border: 1px solid var(--border);
}
.dash-head h1 { font-size: 24px; }
.dash-head-sub { color: var(--text-soft); margin-top: 3px; }

.dash-kpis {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 12px;
}
.dash-kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px 12px;
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
}
.dash-kpi-label { color: var(--text-soft); font-size: 12.5px; }
.dash-kpi-value { font-size: 22px; letter-spacing: -.01em; }
.dash-kpi-foot {
  display: flex; align-items: center; gap: 8px; margin-top: auto;
  min-height: 34px; flex-wrap: wrap;
}
.dash-kpi-note { color: var(--text-soft); font-size: 12px; }
.dash-delta { font-weight: 600; font-size: 12.5px; }
.dash-delta.good { color: var(--accent); }
.dash-delta.bad { color: var(--negative); }
.dash-spark { width: 110px; height: 34px; margin-left: auto; color: var(--accent); opacity: .85; }

.dash-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
  min-width: 0;
}
.dash-card-title {
  font-size: 14.5px; font-weight: 600; margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.dash-count {
  background: var(--accent-soft); color: var(--accent); border-radius: 999px;
  font-size: 12px; padding: 1px 8px;
}
.dash-grid-2 { display: grid; grid-template-columns: 320px 1fr; gap: 12px; }
.dash-grid-2 > .dash-card { margin-bottom: 0; }
.dash-grid-2 { margin-bottom: 12px; }

.dash-gauge { text-align: center; }
.dash-gauge svg { width: 200px; max-width: 100%; }
.dash-gauge-num { font-size: 30px; font-weight: 700; fill: var(--text); }
.dash-gauge-sub { font-size: 11px; fill: var(--text-soft); }
.dash-gauge-note { color: var(--text-soft); font-size: 12.5px; margin-top: 6px; }

.dash-alerts { display: flex; flex-direction: column; }
.dash-alert {
  display: flex; align-items: baseline; gap: 10px;
  padding: 9px 8px; border-radius: 8px;
  color: inherit; text-decoration: none;
}
.dash-alert:hover { background: var(--surface-2); }
.dash-alert + .dash-alert { border-top: 1px solid var(--border); }
.dash-sev {
  width: 9px; height: 9px; border-radius: 50%; flex: none;
  align-self: center;
}
.dash-sev-red { background: var(--negative); }
.dash-sev-orange { background: #B0883B; }
.dash-sev-blue { background: #4E77B2; }
.dash-alert-ico { flex: none; }
.dash-alert-body { min-width: 0; }
.dash-alert-when { margin-left: auto; color: var(--text-soft); font-size: 12px; white-space: nowrap; }

.dash-hm { overflow-x: auto; }
.dash-hm-row {
  display: grid;
  grid-template-columns: 140px repeat(var(--hm-days, 14), 22px);
  gap: 4px; align-items: center; padding: 2px 0;
  color: inherit; text-decoration: none; border-radius: 6px;
}
.dash-hm-row:not(.dash-hm-head):hover { background: var(--surface-2); }
.dash-hm-head { color: var(--text-soft); font-size: 11px; }
.dash-hm-day { text-align: center; }
.dash-hm-name {
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-right: 6px;
}
.dash-hm-cell { width: 22px; height: 22px; border-radius: 5px; }
.dash-hm-cell.on { background: var(--accent); opacity: .82; }
.dash-hm-cell.off { background: var(--border); }

.dash-feed { display: flex; flex-direction: column; }
.dash-feed-row {
  display: flex; align-items: baseline; gap: 12px;
  padding: 8px 8px; border-radius: 8px;
  color: inherit; text-decoration: none;
}
.dash-feed-row:hover { background: var(--surface-2); }
.dash-feed-row + .dash-feed-row { border-top: 1px solid var(--border); }
.dash-feed-when { color: var(--text-soft); font-size: 12px; width: 52px; flex: none; }
.dash-feed-client { flex: none; white-space: nowrap; }
.dash-feed-cat { color: var(--text-soft); font-size: 13px; min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-feed-amount { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; flex: none; }
.dash-feed-row .badge { flex: none; }
/* Узкая колонка ленты (вариант Б): категорию прячем, остальное в одну строку */
.dash-col-feed .dash-feed-cat { display: none; }

.dash-grid-side { display: grid; grid-template-columns: 1fr 380px; gap: 12px; align-items: start; }
.dash-col-feed { margin-bottom: 0; }

@media (max-width: 1100px) {
  .dash-kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-grid-2 { grid-template-columns: 1fr; }
  .dash-grid-side { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  #shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; }
  .nav { flex-direction: row; }
  .donut-grid { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .dash-kpis { grid-template-columns: 1fr; }
}
