/* Личные финансы — «тихий терминал».
   Тёмный графит с тёплым янтарным акцентом, книжная антиква в заголовках,
   моноширинные табличные цифры. Всё держится на плотности и тонких линиях,
   а не на цветных плашках: это рабочий инструмент, а не витрина. */

@import url("https://fonts.googleapis.com/css2?family=Literata:opsz,wght@7..72,400;7..72,600;7..72,700&family=IBM+Plex+Mono:wght@400;500;600&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap");

:root {
  --ink: #0e1216;
  --surface: #151b22;
  --surface-2: #1b232c;
  --surface-3: #222c37;
  --line: #2b3742;
  --line-soft: #212b35;
  --text: #e7ecf1;
  --text-dim: #9aa8b5;
  --text-faint: #6b7b89;
  --amber: #e0a04a;
  --amber-soft: rgba(224, 160, 74, 0.14);
  --green: #58b28a;
  --green-soft: rgba(88, 178, 138, 0.14);
  --red: #d4715a;
  --red-soft: rgba(212, 113, 90, 0.14);
  --blue: #6d93c4;
  --violet: #9481c4;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 18px 40px -24px rgba(0, 0, 0, 0.9);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Literata", Georgia, serif;
  --sidebar: 232px;
}

:root[data-theme="light"] {
  --ink: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #f7f4ed;
  --surface-3: #efeae0;
  --line: #ddd6c8;
  --line-soft: #e7e1d5;
  --text: #21262c;
  --text-dim: #5d6771;
  --text-faint: #8b949d;
  --amber: #b57620;
  --amber-soft: rgba(181, 118, 32, 0.12);
  --green: #2f7d59;
  --green-soft: rgba(47, 125, 89, 0.12);
  --red: #b2492f;
  --red-soft: rgba(178, 73, 47, 0.12);
  --blue: #3f6699;
  --violet: #6d5aa3;
  --shadow: 0 16px 34px -26px rgba(40, 33, 20, 0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background:
    radial-gradient(1100px 620px at 82% -8%, rgba(224, 160, 74, 0.07), transparent 60%),
    radial-gradient(900px 500px at 8% 106%, rgba(109, 147, 196, 0.06), transparent 62%),
    var(--ink);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button { font-family: inherit; }

/* ─────────────── каркас ─────────────── */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line-soft);
  padding: 20px 12px 24px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), transparent 40%);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 10px 18px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 14px;
}

.brand__mark {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  color: var(--amber);
  line-height: 1;
}

.brand__text {
  font-family: var(--serif);
  font-size: 15px;
  letter-spacing: 0.01em;
}

.brand__sub {
  display: block;
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-top: 2px;
}

.nav-group__title {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
  box-shadow: inset 2px 0 0 var(--amber);
}

.nav-item__icon { width: 16px; text-align: center; opacity: 0.85; font-size: 13px; }

.nav-item__badge {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--red-soft);
  color: var(--red);
}

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--ink) 86%, transparent);
}

.topbar__title {
  font-family: var(--serif);
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar__sub { color: var(--text-faint); font-size: 12px; margin-top: 1px; }
.topbar__spacer { flex: 1; }

.view { padding: 22px 26px 60px; animation: rise 0.28s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ─────────────── элементы ─────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.1s ease;
}

.btn:hover { border-color: var(--amber); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--amber); border-color: var(--amber); color: #1b1508; font-weight: 600; }
.btn--primary:hover { background: color-mix(in srgb, var(--amber) 88%, #fff); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 3px 8px; font-size: 11.5px; }
.btn--danger:hover { border-color: var(--red); color: var(--red); }

input, select, textarea {
  font-family: var(--sans);
  font-size: 13px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.14s ease;
  max-width: 100%;
}

input:focus, select:focus, textarea:focus { outline: none; border-color: var(--amber); }
input[type="date"] { font-family: var(--mono); font-size: 12px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 11.5px; color: var(--text-dim); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 18px;
}

.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }

.segmented button {
  border: 0;
  padding: 5px 11px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}

.segmented button + button { border-left: 1px solid var(--line); }
.segmented button[aria-pressed="true"] { background: var(--amber-soft); color: var(--amber); font-weight: 600; }

/* ─────────────── карточки и метрики ─────────────── */

.grid { display: grid; gap: 14px; }
.grid--kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid--3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.card {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}

.card__title {
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card__title .btn { margin-left: auto; }

.kpi { display: flex; flex-direction: column; gap: 3px; }

.kpi__label {
  font-size: 10.5px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.kpi__value {
  font-family: var(--mono);
  font-size: 25px;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpi__value--lg { font-size: 30px; }
.kpi__hint { font-size: 11.5px; color: var(--text-dim); }

.kpi--accent { box-shadow: inset 0 0 0 1px var(--amber-soft); }
.kpi--accent .kpi__value { color: var(--amber); }

.pos { color: var(--green); }
.neg { color: var(--red); }
.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ─────────────── таблицы ─────────────── */

.table-wrap {
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: auto;
  max-height: 72vh;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface-2);
  text-align: left;
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 600;
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 7px 11px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

tbody tr:hover { background: var(--surface-2); }
tbody tr.is-selected { background: var(--amber-soft); }
tfoot td { padding: 9px 11px; border-top: 1px solid var(--line); font-weight: 600; background: var(--surface-2); }

td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
td.tight { white-space: nowrap; }
.cell-sub { display: block; font-size: 11px; color: var(--text-faint); margin-top: 1px; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--surface-3);
  color: var(--text-dim);
  white-space: nowrap;
}

.tag--transfer { background: var(--surface-3); color: var(--blue); }
.tag--new { background: var(--red-soft); color: var(--red); }
.tag--auto { background: var(--surface-3); color: var(--text-dim); }
.tag--manual { background: var(--green-soft); color: var(--green); }

.bar {
  height: 5px;
  border-radius: 3px;
  background: var(--surface-3);
  overflow: hidden;
  min-width: 56px;
}

.bar > span { display: block; height: 100%; background: var(--amber); }

/* ─────────────── графики ─────────────── */

.chart { width: 100%; display: block; overflow: visible; }
.chart text { font-family: var(--mono); font-size: 10px; fill: var(--text-faint); }
.chart .grid-line { stroke: var(--line-soft); stroke-width: 1; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .bar-in { fill: var(--green); }
.chart .bar-out { fill: var(--red); }
.chart .line { fill: none; stroke: var(--amber); stroke-width: 2; }
.chart .area { fill: url(#areaGrad); }
.chart .dot { fill: var(--amber); }

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 11.5px; color: var(--text-dim); margin-top: 8px; }
.legend > span::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 5px;
  background: currentColor;
}

/* ─────────────── модалка, тосты, прочее ─────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(6, 9, 12, 0.7);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 16px;
  z-index: 60;
  animation: fade 0.16s ease both;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: min(680px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: rise 0.2s ease both;
}

.modal__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
  position: sticky;
  top: 0;
  background: var(--surface);
}

.modal__title { font-family: var(--serif); font-size: 17px; font-weight: 600; }
.modal__body { padding: 16px 18px; display: grid; gap: 12px; }
.modal__foot {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 18px;
  border-top: 1px solid var(--line-soft);
  position: sticky;
  bottom: 0;
  background: var(--surface);
}

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form-grid--wide { grid-column: 1 / -1; }

.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 80; }

.toast {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: rise 0.18s ease both;
  max-width: 380px;
}

.toast--ok { border-left: 3px solid var(--green); }
.toast--err { border-left: 3px solid var(--red); }

.empty { padding: 40px 20px; text-align: center; color: var(--text-faint); }
.empty__title { font-family: var(--serif); font-size: 17px; color: var(--text-dim); margin-bottom: 6px; }

.dropzone {
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  color: var(--text-dim);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease;
}

.dropzone.is-over, .dropzone:hover { border-color: var(--amber); background: var(--surface-2); }

.split { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.row-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.14s ease; }
tr:hover .row-actions { opacity: 1; }

.checkbox { width: 14px; height: 14px; accent-color: var(--amber); cursor: pointer; }

/* Селекты прямо в ячейках реестра: разметка на лету, но без визуального шума */
.cell-select {
  width: 100%;
  padding: 2px 4px;
  font-size: 11.5px;
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

.cell-select:hover { border-color: var(--line); background: var(--surface-2); }
.cell-select:focus { color: var(--text); background: var(--surface-2); }
tr:hover .cell-select { border-color: var(--line-soft); }

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }

.rule-cond {
  display: grid;
  grid-template-columns: 1.1fr 1fr 1.6fr auto;
  gap: 6px;
  align-items: center;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading { display: flex; gap: 10px; align-items: center; color: var(--text-faint); padding: 30px; justify-content: center; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 2px;
  }
  .brand { grid-column: 1 / -1; }
  .nav-group__title { display: none; }
  .view, .topbar { padding-left: 14px; padding-right: 14px; }
}

/* ─────────────── вход и учётная запись ─────────────── */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1100px 520px at 50% -10%, rgba(224, 160, 74, 0.09), transparent 70%),
    var(--ink);
}

.login-card {
  width: 100%;
  max-width: 330px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 24px 22px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card__brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-card__submit { width: 100%; justify-content: center; margin-top: 2px; }
.login-card__note { color: var(--text-faint); font-size: 11px; text-align: center; }

.login-card__error {
  font-size: 12px;
  color: var(--red);
  background: var(--red-soft);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
}

/* Вход через Телеграм: кнопку рисует их скрипт, нам остаётся место под неё. */
.login-tg[hidden], .login-sep[hidden] { display: none; }

.login-tg { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.login-tg__slot { width: 100%; min-height: 40px; display: flex; align-items: center; justify-content: center; }
.login-tg__hint { color: var(--text-faint); font-size: 11px; text-align: center; }
.login-tg__link { width: 100%; justify-content: center; text-decoration: none; }

.login-sep {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-faint);
  font-size: 11px;
}

.login-sep::before, .login-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 3px 4px 3px 10px;
  border-left: 1px solid var(--line-soft);
  margin-left: 4px;
}

.topbar__user .who { display: flex; flex-direction: column; line-height: 1.25; text-align: right; }
.topbar__user .who b { font-size: 12px; font-weight: 600; }
.topbar__user .who span { font-size: 10.5px; color: var(--text-faint); }

.space-badge {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--amber);
  background: var(--amber-soft);
  border-radius: 999px;
  padding: 1px 8px;
}


/* Переключатель пространств: виден только владельцу движка.
   display:flex перебивает браузерное правило для [hidden] — гасим явно. */
.space-switch[hidden],
.foreign-bar[hidden] { display: none; }

.space-switch {
  display: flex;
  align-items: center;
  gap: 8px;
}
.space-switch__label {
  font-size: 12px;
  color: var(--muted);
}
.space-switch select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
}

/* Полоса «это чужое пространство»: заметная, но не кричащая. */
.foreign-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 18px 26px -8px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--amber);
  background: var(--amber-soft);
  color: var(--text);
  font-size: 13px;
}
.foreign-bar b { font-weight: 600; }
.foreign-bar .btn { margin-left: auto; }
