:root {
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e2e2e2;
  --bg: #ffffff;
  --accent: #1f6feb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

.topbar {
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
}

.brand {
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px;
}

h1 { font-size: 22px; margin: 0 0 8px; }
.lead { margin: 0 0 4px; }
.muted { color: var(--muted); font-size: 13px; }

/* --- навигация --- */
.topbar { display: flex; align-items: center; gap: 24px; }
.nav { display: flex; gap: 16px; font-size: 14px; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a:hover { color: var(--ink); }
.badge {
  background: var(--accent); color: #fff; border-radius: 10px;
  padding: 0 6px; font-size: 12px;
}

/* --- данные набираются моноширинным --- */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.num { text-align: right; }

/* --- таблицы --- */
.grid { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 14px; }
.grid th {
  text-align: left; font-weight: 600; color: var(--muted);
  border-bottom: 1px solid var(--line); padding: 8px 10px;
}
.grid td { border-bottom: 1px solid var(--line); padding: 8px 10px; vertical-align: top; }
.grid tfoot td { font-weight: 600; }

/* --- статусы: цвета одинаковы во всех экранах --- */
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; }
.pill-pending   { background: #eee; color: #555; }
.pill-parsed    { background: #fff3cd; color: #7a5b00; }
.pill-confirmed { background: #e3f6e5; color: #1d6b2b; }
.pill-failed    { background: #fde8e8; color: #9b1c1c; }
.pill-rejected  { background: #eee; color: #777; }

/* --- загрузка --- */
.dropzone { margin-top: 16px; }
.dropzone-inner {
  display: flex; flex-direction: column; gap: 4px; align-items: center;
  border: 2px dashed var(--line); border-radius: 6px; padding: 28px; cursor: pointer;
}
.dropzone-inner input { display: none; }

/* --- экран подтверждения --- */
.confirm-head { display: flex; align-items: center; gap: 12px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 16px; }
.pdf-pane iframe { width: 100%; height: 78vh; border: 1px solid var(--line); }
.form-pane label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.form-pane input, .form-pane textarea, .form-pane select {
  display: block; width: 100%; margin-top: 3px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 2px; font-size: 14px; color: var(--ink);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox { display: flex; align-items: center; gap: 6px; }
.checkbox input { width: auto; margin: 0; }
.items input { margin: 0; }

.warnings { list-style: none; padding: 0; margin: 12px 0; }
.warnings li { padding: 6px 10px; border-left: 3px solid; margin-bottom: 4px; font-size: 13px; }
.warn-warning  { border-color: #d9a406; background: #fffbeb; }
.warn-critical { border-color: #dc2626; background: #fef2f2; }
.alert { background: #fef2f2; border-left: 3px solid #dc2626; padding: 8px 12px; }
.error { color: #9b1c1c; font-size: 13px; }

.actions { display: flex; gap: 10px; margin-top: 14px; }
button.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 2px;
  padding: 8px 16px; font-size: 14px; cursor: pointer;
}
button.ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 2px; padding: 8px 16px; font-size: 14px; cursor: pointer;
}
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; }
[x-cloak] { display: none !important; }

/* Счета приходят на телефон — инбокс и подтверждение должны быть читаемы */
@media (max-width: 760px) {
  .two-col { grid-template-columns: 1fr; }
  .pdf-pane iframe { height: 44vh; }
  .field-row { grid-template-columns: 1fr; }
  .nav { gap: 10px; font-size: 13px; }
}

/* Дорожка grid по умолчанию не уже своего содержимого (min-width: auto), поэтому
   широкая таблица позиций распирала колонку и давала горизонтальную прокрутку
   на телефоне. min-width: 0 снимает это; сама таблица при нехватке места
   прокручивается внутри себя, а не тащит за собой всю страницу. */
.two-col > * { min-width: 0; }
.items { table-layout: fixed; }
.items td, .items th { overflow: hidden; }

/* --- фильтры и вкладки --- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 4px;
}
.filters label { display: block; font-size: 12px; color: var(--muted); }
.filters input, .filters select {
  display: block; margin-top: 3px; padding: 5px 7px;
  border: 1px solid var(--line); border-radius: 2px; font-size: 13px;
}
.ghost-link { color: var(--muted); font-size: 13px; text-decoration: none; align-self: center; }
.tabs { display: flex; gap: 14px; margin-top: 10px; font-size: 14px; }
.tabs a { color: var(--muted); text-decoration: none; padding-bottom: 3px; }
.tabs a.active { color: var(--ink); border-bottom: 2px solid var(--accent); }

/* --- инлайн-правка прямо в ячейке --- */
select.inline, input.inline {
  border: 1px solid transparent; background: transparent; padding: 3px 5px;
  font-size: 13px; width: 100%; border-radius: 2px; color: var(--ink);
}
select.inline:hover, input.inline:hover { border-color: var(--line); }
select.inline:focus, input.inline:focus { border-color: var(--accent); outline: none; }

.purpose { max-width: 380px; font-size: 13px; color: var(--muted); }
.accent { color: var(--accent); font-weight: 600; }
.links-cell { background: #fafafa; padding: 0; }
.links-box { padding: 10px 14px; }
.grid.compact td, .grid.compact th { padding: 4px 8px; font-size: 13px; }
.link-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 8px; }
.link-form label { font-size: 12px; color: var(--muted); }
.link-form input, .link-form select {
  display: block; margin-top: 3px; padding: 5px 7px;
  border: 1px solid var(--line); border-radius: 2px; font-size: 13px;
}

@media (max-width: 760px) {
  .filters { flex-direction: column; align-items: stretch; }
  .purpose { max-width: none; }
}

/* --- плитки дашборда --- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 16px; }
.tile { border: 1px solid var(--line); border-radius: 4px; padding: 14px; }
.tile-label { font-size: 13px; color: var(--muted); }
.tile-amount { font-size: 20px; font-weight: 600; margin: 4px 0 2px; }

.charts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-top: 22px; }
.chart-box { border: 1px solid var(--line); border-radius: 4px; padding: 14px; min-width: 0; }
.chart-box h2 { font-size: 14px; margin: 0 0 10px; color: var(--muted); font-weight: 600; }
/* Высоту задаёт обёртка, а не сам canvas: CSS-ограничения прямо на canvas
   расходятся с тем, как Chart.js считает размеры, и столбцы оказываются
   нарисованы за пределами области — данные есть, а график пустой. */
.chart-wrap { position: relative; height: 220px; }
.empty { margin-top: 22px; }
h2 { font-size: 16px; margin-top: 26px; }

/* Счета приходят на телефон — дашборд обязан читаться и там */
@media (max-width: 760px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .charts { grid-template-columns: 1fr; }
  .tile-amount { font-size: 17px; }
}

/* --- вход --- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box {
  width: 300px; padding: 26px; border: 1px solid var(--line); border-radius: 6px;
}
.login-box h1 { font-size: 18px; margin: 0 0 16px; }
.login-box label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; }
.login-box input {
  display: block; width: 100%; margin-top: 4px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 2px; font-size: 14px;
}
.login-box button { width: 100%; }

/* --- настройки --- */
.panel { border: 1px solid var(--line); border-radius: 4px; padding: 14px 16px; margin-top: 16px; }
.panel h2 { margin-top: 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* --- копилки объектов --- */
.pots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0; }
.pot {
  display: block; border: 1px solid var(--line); border-radius: 6px; padding: 14px;
  text-decoration: none; color: var(--ink);
}
.pot:hover { border-color: var(--accent); }
.pot-over { border-color: #dc2626; }
.pot-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.pot-code {
  color: #fff; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.pot-name { font-weight: 600; font-size: 14px; }

/* Полоса — не украшение: она показывает, какая часть присланных денег уже
   израсходована или законтрактована. Красная — потратили больше, чем пришло. */
.pot-bar { height: 6px; background: #eee; border-radius: 3px; overflow: hidden; margin-bottom: 12px; }
.pot-fill { height: 100%; background: var(--accent); }
.pot-fill.over { background: #dc2626; }

.pot-main { margin-bottom: 10px; }
.pot-label { font-size: 12px; color: var(--muted); }
.pot-amount { font-size: 21px; font-weight: 600; }
.negative { color: #dc2626; }
.positive { color: #1d6b2b; }

.pot-rows { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 0; font-size: 12px; }
.pot-rows dt { color: var(--muted); }
.pot-rows dd { margin: 0; text-align: right; }
.pot-rows .strong { font-weight: 600; color: var(--ink); }
.pot-foot { margin-top: 10px; }

.alert-soft {
  background: #fffbeb; border-left: 3px solid #d9a406; padding: 9px 12px;
  font-size: 13px; margin-top: 16px;
}
.project-badge {
  display: inline-block; padding: 1px 7px; border: 1px solid; border-radius: 3px; font-size: 12px;
}

@media (max-width: 900px) { .pots { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .pots { grid-template-columns: 1fr; } }
