:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #14171a;
  --muted: #6b7280;
  --line: #e3e6ea;
  --hair: #e3e6ea;
  --accent: #1f5fd6;
  --up: #1a7f4b;
  --down: #b3261e;
  --warn-bg: #fff6e5;
  --warn-line: #e0a94a;
  --ok-bg: #eaf6ef;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- каркас ---------- */

.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 0 24px; height: 56px;
  background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.topbar nav { display: flex; gap: 20px; flex-wrap: wrap; }
.topbar nav a { color: var(--muted); font-size: 14px; }
.topbar nav a.active { color: var(--ink); font-weight: 600; }

main { max-width: 1100px; margin: 0 auto; padding: 28px 24px 60px; }

h1 { font-size: 24px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 17px; margin: 32px 0 12px; letter-spacing: -0.01em; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
.footnote { margin-top: 18px; }
.cur { color: var(--muted); font-weight: 400; }

/* ---------- кнопки и поля ---------- */

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-size: 14px; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { text-decoration: none; border-color: #c9ced6; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--down); border-color: #e7c4c1; }

input[type=text], input[type=password], input[type=number], input[type=date], select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font: inherit; color: var(--ink);
}
input:focus, select:focus { outline: 2px solid #b9cdf3; outline-offset: -1px; border-color: var(--accent); }
input.tiny { width: 70px; }
form.inline { display: inline; }
.error { color: var(--down); font-size: 13px; }

/* ---------- баннеры ---------- */

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: var(--radius);
  padding: 14px 18px; margin-bottom: 22px; flex-wrap: wrap;
}
.banner.ok { background: var(--ok-bg); border-color: #9ccbb0; }
.banner.warn { background: var(--warn-bg); }

.empty { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 40px; text-align: center; }
.empty h1 { margin-bottom: 10px; }
.empty p { color: var(--muted); max-width: 460px; margin: 0 auto 20px; }

/* ---------- итоги ---------- */

.totals {
  display: flex; gap: 40px; align-items: flex-end; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px 24px; margin-bottom: 20px;
}
.totals .label { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.total-main .value { font-size: 34px; font-weight: 700; letter-spacing: -0.03em; }
.total-entity .value { font-size: 20px; font-weight: 600; color: #374151; }

/* ---------- карточки счетов ---------- */

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px;
}
.card.stale { border-color: var(--warn-line); }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.entity {
  font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 5px; background: #eef2f7; color: #44546a;
}
.entity.ip { background: #f3eefc; color: #5b4b8a; }
.tag-tax {
  font-size: 11px; padding: 2px 6px; border-radius: 5px;
  background: #fdf0e3; color: #8a5a1f; font-weight: 600;
}
.total-entity.tax .value { color: #8a5a1f; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; }
.check input { width: 16px; height: 16px; }
.bank { font-weight: 600; }
.account-note { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.card .amount { font-size: 22px; font-weight: 600; margin: 8px 0 6px; letter-spacing: -0.02em; }
.card-foot { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.card-diff { margin-top: 8px; font-size: 12px; color: var(--down); }
.delta { font-size: 13px; font-weight: 600; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------- прогноз ---------- */

.forecast {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-top: 22px;
}
.forecast-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.forecast-head h2 { margin: 0 0 14px; }
.forecast-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 18px; }
.forecast-grid .label { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.forecast-grid .value { font-size: 20px; font-weight: 600; letter-spacing: -0.02em; }
.forecast-alarm {
  margin-top: 16px; padding: 12px 14px; border-radius: 8px;
  background: var(--warn-bg); border: 1px solid var(--warn-line); font-weight: 600;
}
.head-summary { font-size: 14px; color: var(--muted); }
.total-entity.alarm .value { color: var(--down); }

/* ---------- лента движений ---------- */

.event-new { align-items: center; margin-bottom: 8px; }
.ledger tr.done { opacity: 0.6; }
.ledger tr.late td { background: var(--warn-bg); }
.ledger td.actions { white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.date-mini { padding: 3px 6px; font-size: 12px; }
.weeks tr.alarm-row td { background: #fdecea; }

/* ---------- просроченные платежи ---------- */

.overdue-block {
  background: var(--panel); border: 1px solid var(--warn-line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 24px;
}
.overdue-block h2 { margin-top: 0; }
.overdue-block table { margin-top: 12px; }

/* ---------- месяц ---------- */

.breakdown { margin-bottom: 6px; }
.breakdown td:first-child a { font-weight: 500; }
.breakdown .sum-row td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: none; }
.breakdown .apart td { padding-top: 18px; }
.breakdown .muted { font-size: 13px; }

.month-group { margin-bottom: 28px; }
.group-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.group-head h2 { margin: 0 0 6px; }
.group-sums { display: flex; gap: 14px; align-items: baseline; font-size: 14px; }
.quick-forms { display: flex; flex-direction: column; gap: 12px; }
.account-form.quick {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.account-form.quick strong { min-width: 160px; }
.internal-box {
  display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; margin-top: 18px;
}

/* ---------- ввод списком ---------- */

.import-settings {
  display: flex; gap: 18px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 12px;
}
.check-inline { display: flex; align-items: center; gap: 8px; }
.check-inline > span { color: var(--muted); font-size: 13px; }
.import-text {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.6;
  resize: vertical;
}
.import-text:focus { outline: 2px solid #b9cdf3; border-color: var(--accent); }
.lead { max-width: 760px; }

.import-file {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  background: var(--panel); border: 1px dashed var(--accent); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 12px;
}
.import-file input[type=file] { font: inherit; font-size: 13px; }
.chosen { font-size: 13px; font-weight: 600; color: var(--accent); }
.save-btn {
  background: var(--up); border-color: var(--up); color: #fff;
  font-weight: 600; padding: 10px 18px;
}
.save-btn:hover { border-color: var(--up); filter: brightness(1.08); }
.banner.unsaved { background: var(--warn-bg); border-color: var(--warn-line); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.founder-total {
  display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--ink); border-radius: var(--radius);
  padding: 16px 20px; margin: -8px 0 28px;
}
.founder-nums { display: flex; gap: 24px; flex-wrap: wrap; font-size: 15px; }
.founder-nums .label { display: block; color: var(--muted); font-size: 12px; }

.diag {
  background: var(--panel); border: 1px solid var(--hair); border-radius: var(--radius);
  padding: 14px 18px; margin: -10px 0 20px;
}
.diag pre {
  margin: 6px 0 10px; padding: 10px 12px; background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px;
  font-size: 12px; line-height: 1.5; overflow-x: auto; white-space: pre;
}

.uncoded .code-input { width: 110px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.sticky-save {
  position: sticky; top: 56px; z-index: 5; background: var(--bg);
  padding: 12px 0; border-bottom: 1px solid var(--line); margin-bottom: 4px;
}

/* ---------- поиск в ленте ---------- */

.search { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search input[type=search] {
  width: 280px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit;
}
.period-row { margin-bottom: 18px; }

/* ---------- быстрая правка суммы ---------- */

.amount-edit { display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.amount-edit input {
  width: 130px; text-align: right; padding: 4px 8px; font: inherit;
  border: 1px solid transparent; border-radius: 6px; background: transparent;
}
.amount-edit input:hover { border-color: var(--line); background: #fff; }
.amount-edit input:focus { border-color: var(--accent); background: #fff; }
.amount-edit .sign { font-weight: 600; }
.amount-edit button { opacity: 0; transition: opacity .15s; }
.amount-edit:hover button, .amount-edit:focus-within button { opacity: 1; }

/* ---------- правка записи ---------- */

.edit-form {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 24px; max-width: 520px;
  display: flex; flex-direction: column; gap: 14px;
}
.edit-form label { display: grid; grid-template-columns: 140px 1fr; align-items: center; gap: 12px; }
.edit-form label span { color: var(--muted); font-size: 14px; }
.edit-form .form-actions { grid-template-columns: none; padding-top: 6px; }

/* ---------- проекты ---------- */

.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; }
.projects tr.active-row td:first-child { border-left: 3px solid var(--accent); }
.project-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; margin-bottom: 20px; }

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

.chart-block { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-top: 24px; }
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.chart-head h2 { margin: 0; }
.range { display: flex; gap: 10px; font-size: 13px; }
.range a { color: var(--muted); }
.range a.active { color: var(--ink); font-weight: 600; }
#chart { height: 320px; margin-top: 10px; }

/* ---------- форма ввода остатков ---------- */

.date-nav { display: flex; align-items: center; gap: 8px; }
.balances { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 20px 20px; }
.balance-row {
  display: grid; grid-template-columns: 220px 200px 1fr 200px; gap: 16px; align-items: center;
  padding: 16px 0; border-bottom: 1px solid var(--line);
}
.balance-row:last-of-type { border-bottom: none; }
.balance-row.match { background: linear-gradient(90deg, var(--ok-bg), transparent 60%); }
.balance-row.mismatch { background: linear-gradient(90deg, var(--warn-bg), transparent 60%); }
.balance-label { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.balance-input { display: flex; align-items: center; gap: 6px; }
.balance-input input { width: 150px; text-align: right; font-size: 16px; font-weight: 600; }
.balance-hint { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.balance-note input { width: 100%; }
.ok-text { color: var(--up); font-weight: 600; }
.warn-text { color: #a35c00; font-weight: 600; }
.form-actions { display: flex; align-items: center; gap: 16px; padding-top: 18px; flex-wrap: wrap; }

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

table { width: 100%; border-collapse: collapse; background: var(--panel); }
.diffs table, .history { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; }
td.date { white-space: nowrap; }
td.total { font-weight: 600; }
.cell-diff { display: block; font-size: 11px; color: var(--down); }
.table-scroll { overflow-x: auto; }

/* ---------- счета ---------- */

.account-list { display: flex; flex-direction: column; gap: 10px; }
.account-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px;
}
.account-row.archived { opacity: 0.55; }
.account-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.account-form input[type=text] { width: 180px; }

/* ---------- вход ---------- */

.login {
  max-width: 320px; margin: 80px auto; display: flex; flex-direction: column; gap: 14px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px;
}
.login h1 { text-align: center; }

/* ---------- мобильный ---------- */

@media (max-width: 780px) {
  main { padding: 18px 14px 50px; }
  .topbar { gap: 14px; padding: 0 14px; height: auto; min-height: 56px; flex-wrap: wrap; }
  .totals { gap: 20px; }
  .total-main .value { font-size: 26px; }
  .balance-row { grid-template-columns: 1fr; gap: 8px; padding: 14px 0; }
  .balance-input input { width: 100%; }
  .balance-row.match, .balance-row.mismatch { background: none; padding-left: 10px; border-left: 3px solid var(--up); }
  .balance-row.mismatch { border-left-color: var(--warn-line); }
  .account-form input[type=text] { width: 100%; }
}
