/* Палитра: голубой, серый, молочный, тёмный шоколад */
:root {
  --milk: #fbf7ee;
  --milk-2: #f4eee1;
  --paper: #fffdf8;
  --choc: #3b2a22;
  --choc-2: #5a4337;
  --blue: #6fa8cf;
  --blue-d: #3f7fab;
  --blue-l: #dcebf5;
  --blue-xl: #eef5fa;
  --grey: #8a8d91;
  --grey-l: #e4e2dd;
  --red: #b5473a;
  --red-l: #f6e1dd;
  --amber: #a8741a;
  --amber-l: #f8ecd2;
  --green: #4f7d4a;
  --green-l: #e3eedf;
  font-size: 15px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--milk); color: var(--choc);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.4;
}
a { color: var(--blue-d); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Каркас */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--choc); color: var(--milk); padding: 18px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { font-weight: 700; font-size: 18px; padding: 0 20px 4px; }
.side .sub { color: #c9b8ab; font-size: 12px; padding: 0 20px 16px; }
.side h4 { margin: 18px 20px 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #b59f90; font-weight: 600; }
.side a { display: block; padding: 8px 20px; color: var(--milk); border-left: 3px solid transparent; }
.side a:hover { background: var(--choc-2); text-decoration: none; }
.side a.on { background: var(--choc-2); border-left-color: var(--blue); }
.side .muted { color: #b59f90; font-size: 12px; padding: 14px 20px; }
.main { padding: 22px 28px 60px; min-width: 0; }
h1 { font-size: 24px; margin: 0 0 4px; font-weight: 650; }
h2 { font-size: 18px; margin: 26px 0 10px; }
.lead { color: var(--grey); margin: 0 0 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* Кнопки */
.btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--grey-l); background: var(--paper);
  color: var(--choc); font: inherit; cursor: pointer; text-decoration: none !important; }
.btn:hover { border-color: var(--blue); }
.btn.primary { background: var(--blue-d); border-color: var(--blue-d); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #356f97; }
.btn.danger { color: var(--red); border-color: #e3c3bd; }
.btn.small { padding: 4px 9px; font-size: 13px; }

/* Сообщения */
.msg { padding: 10px 14px; border-radius: 8px; margin-bottom: 10px; }
.msg.success { background: var(--green-l); }
.msg.error { background: var(--red-l); color: #6e2219; }
.msg.warning { background: var(--amber-l); }
.msg.info { background: var(--blue-l); }

/* Карточки */
.card { background: var(--paper); border: 1px solid var(--grey-l); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin: 14px 0 18px; }
.stat { background: var(--paper); border: 1px solid var(--grey-l); border-radius: 12px; padding: 12px 14px; }
.stat .l { font-size: 12px; color: var(--grey); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 20px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 13px; color: var(--grey); }
.stat.accent { background: var(--blue-xl); border-color: var(--blue-l); }

/* Вкладки месяцев */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 12px 0 16px; align-items: center; }
.tabs a { padding: 6px 12px; border-radius: 999px; background: var(--paper); border: 1px solid var(--grey-l); color: var(--choc); font-size: 14px; }
.tabs a.on { background: var(--blue-d); color: #fff; border-color: var(--blue-d); font-weight: 600; }
.tabs a:hover { text-decoration: none; border-color: var(--blue); }
.tabs .year { font-weight: 700; margin: 0 6px; }
.seg { display: inline-flex; border: 1px solid var(--grey-l); border-radius: 8px; overflow: hidden; }
.seg a { padding: 6px 12px; color: var(--choc); background: var(--paper); }
.seg a.on { background: var(--blue-l); font-weight: 600; }

/* Таблицы */
.tablewrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--grey-l); border-radius: 12px; }
table.t { border-collapse: collapse; width: 100%; font-size: 13.5px; }
table.t th, table.t td { padding: 6px 8px; border-bottom: 1px solid #efebe3; vertical-align: top; }
table.t thead th { background: var(--blue-l); text-align: left; font-weight: 600; position: sticky; top: 0; white-space: nowrap; }
table.t thead tr.grp th { background: var(--blue); color: #fff; text-align: center; font-size: 12px; letter-spacing: .03em; }
table.t td.n, table.t th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.cat td { background: var(--milk-2); font-weight: 650; }
table.t tr.sum td { background: var(--milk-2); font-weight: 650; border-top: 2px solid var(--grey-l); }
table.t tr.total td { background: var(--blue-l); font-weight: 700; font-size: 14px; }
table.t tr:hover td { background: var(--blue-xl); }
table.t tr.cat:hover td, table.t tr.sum:hover td { background: var(--milk-2); }
table.t td.b { border-left: 2px solid var(--grey-l); }
table.t .muted, .muted { color: var(--grey); }
.zero { color: #c3c0ba; }
.neg { color: var(--red); font-weight: 600; }
.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--grey-l); color: var(--choc-2); white-space: nowrap; }
.tag.blue { background: var(--blue-l); }
.tag.red { background: var(--red-l); color: var(--red); }
.tag.amber { background: var(--amber-l); color: var(--amber); }
.tag.green { background: var(--green-l); color: var(--green); }
.small { font-size: 12px; }

/* Формы */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; }
.field label { display: block; font-size: 12.5px; color: var(--choc-2); margin-bottom: 3px; font-weight: 600; }
.field .help { font-size: 11.5px; color: var(--grey); margin-top: 2px; }
.field .err, .errorlist { color: var(--red); font-size: 12px; margin: 2px 0 0; padding: 0; list-style: none; }
input[type=text], input[type=date], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #d6d1c7; border-radius: 7px; background: #fff; font: inherit; color: var(--choc);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-l); border-color: var(--blue); }
input.num { text-align: right; font-variant-numeric: tabular-nums; }
input.short { max-width: 70px; }
table.lines td { padding: 4px 5px; }
table.lines input, table.lines select { padding: 5px 6px; font-size: 13px; }
table.lines tr.deleted td { opacity: .35; text-decoration: line-through; }
.has-error input, .has-error select { border-color: var(--red); background: #fff6f4; }
.calc { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; color: var(--choc-2); }
.actions { display: flex; gap: 10px; margin-top: 18px; align-items: center; position: sticky; bottom: 0; background: var(--milk); padding: 12px 0; border-top: 1px solid var(--grey-l); }
details summary { cursor: pointer; color: var(--blue-d); }

.login { max-width: 360px; margin: 12vh auto; }

@media print {
  .side, .no-print, .actions, .tabs, .btn { display: none !important; }
  .layout { display: block; }
  .main { padding: 0; }
  body { background: #fff; font-size: 11px; }
  .tablewrap { border: 0; overflow: visible; }
  table.t { font-size: 9.5px; }
  table.t th, table.t td { padding: 2px 4px; }
}
table.lines input.num { min-width: 72px; }
table.lines input.short { min-width: 54px; }

/* Закреплённая шапка таблиц отчётов: таблица прокручивается внутри своего окна */
.tablewrap.sticky { max-height: calc(100vh - 90px); overflow: auto; }
.tablewrap.sticky thead th { position: sticky; top: 0; z-index: 2; }
.tablewrap.sticky thead tr.grp + tr th { top: var(--head1, 27px); }
@media print { .tablewrap.sticky { max-height: none; overflow: visible; } }

/* Оплата фактуры: зелёный — оплачено, жёлтый — частично, красный — не оплачено */
select.pay { width: auto; padding: 4px 8px; border-radius: 999px; font-weight: 600; font-size: 13px; cursor: pointer; }
select.pay-paid { background: #dcefd8; color: #2f6b2a; border-color: #b9dcb2; }
select.pay-partial { background: #fbeec4; color: #8a6210; border-color: #ecd68d; }
select.pay-unpaid { background: #f6d9d4; color: #9b3326; border-color: #e7b5ad; }
.print-only { display: none; }
@media print { .print-only { display: inline; } }

table.lines select.kind { min-width: 160px; }
table.lines select.receipt, table.lines select[name$="-category"] { min-width: 190px; }
.fifohint { background: var(--blue-l); padding: 8px 12px; border-radius: 8px; }
.fifohint .t td { padding: 3px 8px; }
