:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --ink: #1d1f23;
  --muted: #6b6f76;
  --line: #e3e1da;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --neg: #b3261e;
  --pos: #1e7a46;
  --warn: #9a6200;
  --ok-bg: #e8f4ec;
  --skip-bg: #f1efe8;
  --err-bg: #fbeae8;
  --near-bg: #fff4cc;
  --near: #d9a400;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a; --surface: #1d2024; --ink: #e8e6e1; --muted: #9a9ea6; --line: #2e3238;
    --accent: #6fa8d6; --accent-ink: #0d1114; --neg: #f08a80; --pos: #6cc88f; --warn: #e0b45c;
    --ok-bg: #1b2e23; --skip-bg: #25272b; --err-bg: #3a1f1d; --near-bg: #3a3214; --near: #e0b45c;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { font-size: 26px; font-weight: 600; margin: 0 0 4px; }
h2 { font-size: 18px; font-weight: 600; margin: 0 0 12px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
.warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar__inner { margin: 0 auto; padding: 8px 20px; display: flex; gap: 16px; align-items: center; }
.brand { font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap; flex-shrink: 0; }
.nav { display: flex; gap: 2px; flex: 1 1 auto; flex-wrap: wrap; min-width: 0; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.nav a.active { background: var(--bg); font-weight: 600; }
/* имя пользователя и «Выйти» — всегда справа в верхней строке */
.who { display: flex; gap: 10px; align-items: center; margin-left: auto; flex-shrink: 0; white-space: nowrap; font-size: 14px; }
.who form { margin: 0; }
.who__name { color: var(--ink); text-decoration: none; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.who__name::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--pos); }
.who__name:hover { text-decoration: underline; }
.who__logout { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 5px 12px;
  font: inherit; font-size: 13px; color: var(--ink); cursor: pointer; }
.who__logout:hover { border-color: var(--neg); color: var(--neg); }
/* меню — точно по центру: название слева и блок пользователя справа одинаковой «резиновой» ширины */
@media (min-width: 901px) {
  .brand, .who { flex: 1 1 0; }
  .who { justify-content: flex-end; }
  .nav { flex: 0 1 auto; justify-content: center; }
}
@media (max-width: 900px) {
  .topbar__inner { flex-wrap: wrap; padding: 8px 16px; gap: 8px 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .who__name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; display: inline-block; }
  .who__name::before { display: none; }
}

.page { max-width: 1200px; margin: 0 auto; padding: 24px 16px 64px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-top: 20px; }

.btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 9px 18px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: progress; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }
.link--danger { color: var(--neg) !important; }

input, select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%;
}
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

.alert { border-radius: 8px; padding: 10px 14px; margin: 14px 0; }
.alert--error { background: var(--err-bg); color: var(--neg); }
.alert--ok { background: var(--ok-bg); }
.alert--skipped { background: var(--skip-bg); color: var(--muted); }
input[readonly] { background: transparent; border-color: transparent; }

.login { max-width: 360px; margin: 10vh auto 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }

.dropzone {
  margin-top: 18px; display: flex; gap: 16px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 2px dashed var(--line); border-radius: var(--radius); padding: 20px;
}
.dropzone.drag { border-color: var(--accent); }
.dropzone input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.dropzone__label { flex: 1; min-width: 220px; cursor: pointer; font-size: 15px; color: var(--ink); display: block; }
.dropzone__label strong { color: var(--accent); text-decoration: underline; }
.dropzone__list { display: block; margin-top: 6px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

.summary { margin: 0 0 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 13px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.file { overflow-wrap: anywhere; max-width: 260px; }
tr.status-ok td:first-child { box-shadow: inset 3px 0 var(--pos); }
tr.status-skipped td:first-child { box-shadow: inset 3px 0 var(--muted); }
tr.status-error td:first-child { box-shadow: inset 3px 0 var(--neg); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.badge--ok { background: var(--ok-bg); color: var(--pos); }
.badge--skipped { background: var(--skip-bg); color: var(--muted); }
.badge--error { background: var(--err-bg); color: var(--neg); }

.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin: 18px 0; }
.filters label { min-width: 140px; }
.filters .grow { flex: 1; min-width: 200px; }
.filters .link { align-self: center; }
.totals { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.total { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; display: flex; flex-direction: column; min-width: 200px; }
.total span { color: var(--muted); font-size: 13px; }
.total b { font-size: 20px; }
.total small { color: var(--muted); }
.ops { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ops td.purpose { max-width: 520px; color: var(--muted); font-size: 13px; }
.pager { display: flex; gap: 16px; justify-content: center; margin-top: 18px; color: var(--muted); }

.pill { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; background: var(--neg); color: #fff; font-size: 12px; font-weight: 600; text-align: center; line-height: 18px; }
.xlsx-link { float: right; margin: 0 0 8px 16px; padding: 7px 14px; font-size: 14px; text-decoration: none; }
@media (max-width: 640px) { .xlsx-link { float: none; display: inline-block; margin: 0 0 12px; } }
.btn--danger { background: var(--neg); color: #fff; }
.row-del { font-size: 12px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.row-del:hover { color: var(--neg); text-decoration: underline; }
.usage { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.btn--ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.alert--error a, .alert--ok a { color: inherit; font-weight: 600; }

.code { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.code--none { color: var(--warn); font-weight: 500; }
.code-name { color: var(--muted); font-size: 13px; }
.codecell { min-width: 150px; max-width: 240px; font-size: 13px; }
.codecell a { text-decoration: none; color: inherit; }
.codecell a:hover .code { text-decoration: underline; }
.code-select { max-width: 100%; }

/* Поиск по статьям (static/combobox.js) */
.combo { position: relative; flex: 1 1 280px; min-width: 0; }
.filters .combo { flex: 0 1 auto; min-width: 260px; }
.combo__input {
  padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.combo__list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 320px; overflow-y: auto; margin: 0; padding: 4px; list-style: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.combo__item { padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 14px; color: var(--ink); line-height: 1.35; }
.combo__item b { font-variant-numeric: tabular-nums; margin-right: 4px; }
.combo__item.is-active { background: var(--bg); }
.combo__item.is-selected { box-shadow: inset 3px 0 var(--accent); }
.combo__empty { padding: 8px 10px; color: var(--muted); font-size: 13px; }

.props { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; margin: 0; }
.props dt { color: var(--muted); font-size: 13px; }
.props dd { margin: 0; overflow-wrap: anywhere; }
.sub { font-size: 15px; font-weight: 600; margin: 20px 0 0; }
.assign { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; max-width: 720px; }
.assign__row { display: flex; gap: 8px; flex-wrap: wrap; }
.assign__row .code-select { flex: 1 1 280px; width: auto; }
.assign__row .combo { flex: 1 1 280px; }
.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); cursor: pointer; width: fit-content; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.hint { margin: 0; font-size: 13px; color: var(--muted); }
.hint--warn { color: var(--warn); }
.assign__remember { display: none; flex-direction: column; gap: 6px; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 8px 8px 0; }
.assign:has(input[name=remember]:checked) .assign__remember { display: flex; }
.assign:has(input[name=remember]:checked) .hint--one { display: none; }

.uncl { display: flex; flex-direction: column; gap: 12px; }
.uncl__item { margin-top: 0; }
.uncl__head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.uncl__head .small { margin-left: 6px; }
.uncl__head div.small { margin-left: 0; }
.uncl .purpose { color: var(--muted); font-size: 13px; margin: 8px 0 12px; overflow-wrap: anywhere; }

.month-nav { display: flex; align-items: center; gap: 14px; }
.month-nav a { font-size: 22px; text-decoration: none; padding: 0 6px; }
.month-nav h1 { margin: 0; }
.limits td { vertical-align: middle; }
/* название статьи: выглядит как текст, при наведении/щелчке — поле ввода */
.name-cell { min-width: 220px; }
.name-input { border-color: transparent; background: transparent; padding: 5px 8px; margin-left: -9px; width: 100%;
  font-size: 14px; color: var(--ink); text-overflow: ellipsis; }
.name-input:hover { border-color: var(--line); }
.name-input:focus { border-color: var(--accent); background: var(--surface); outline: none; }
/* комментарий: в колонке — короткая надпись-кнопка, по щелчку под строкой статьи
   раскрывается отдельная строка с полем на всю ширину таблицы (static/comments.js) */
.comment-col { width: 150px; max-width: 150px; }
.cmt-toggle { display: block; max-width: 150px; padding: 3px 6px; border: 0; border-radius: 6px; background: none;
  font: inherit; font-size: 12px; color: var(--ink); text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cmt-toggle:hover { background: var(--bg); }
.cmt-toggle--empty { color: var(--muted); }
.cmt-toggle[aria-expanded="true"] { background: var(--bg); color: var(--accent); }
.limits tr.has-open-cmt td { border-bottom-color: transparent; }
.cmt-row td { padding-top: 0; }
.cmt-row__box { display: flex; gap: 12px; align-items: flex-start; padding: 8px 12px; background: var(--bg);
  border-radius: 8px; }
.cmt-row__label { font-size: 12px; color: var(--muted); flex: 0 0 170px; padding-top: 6px; }
.cmt-row__text { flex: 1; min-height: 52px; font-size: 13px; padding: 6px 8px; resize: vertical; }
.cmt-row__read { flex: 1; font-size: 13px; white-space: pre-line; padding-top: 4px; }
@media (max-width: 640px) { .cmt-row__box { flex-direction: column; } .cmt-row__label { flex-basis: auto; } }
.limits-search { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; margin: 0 0 12px; }
.limits-search label { flex: 0 1 420px; }
/* пустые статьи скрыты, пока не нажато «Показать все» и не идёт поиск */
#limits-form:not(.show-idle):not(.searching) tr.idle { display: none; }
#limits-form tr.no-match { display: none; }
.limits tr.over td { background: var(--err-bg); }
.limits tr.near td { background: var(--near-bg); }
.bar__fill--near { background: var(--near); }
.bar__fill--plan { background: var(--accent); }
.bar__fill--done { background: var(--pos); }
.limits tr.done td { background: var(--ok-bg); }
h2 + .table-wrap, .table-wrap + .form-foot { margin-top: 8px; }
.tabs { display: flex; gap: 4px; margin: 12px 0 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; color: var(--ink); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { border-bottom-color: var(--accent); font-weight: 600; }
.manual-form { display: flex; flex-direction: column; gap: 4px; }
.manual-form .filters { margin: 6px 0; }
.issued__pw { font-size: 20px; font-weight: 700; letter-spacing: 1px; padding: 2px 8px; background: var(--surface); border-radius: 6px; user-select: all; }
.issued .small { margin-top: 6px; }
.user-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-row input[name=name] { width: 220px; }
.user-row select { width: auto; }
.users td { vertical-align: middle; }
tr.muted td { opacity: .6; }
.uncl__delete, .card-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 12px;
  padding-top: 10px; border-top: 1px dashed var(--line); }
.reason-input { width: auto; flex: 0 1 300px; font-size: 13px; padding: 5px 8px; }
.inline-form { display: inline; margin-left: 10px; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; align-self: center; }
.presets a { padding: 5px 10px; border: 1px solid var(--line); border-radius: 99px; font-size: 13px; text-decoration: none; color: var(--ink); }
.presets a.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.template-box { margin: 0 0 16px; padding: 12px 18px; }
.template-box summary { cursor: pointer; }
.template-box ol { margin: 10px 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.file-input { width: auto; flex: 1 1 260px; }
.alert ul { margin: 8px 0 0; padding-left: 20px; }
.manual-form__kind { display: flex; gap: 20px; flex-wrap: wrap; align-items: center; }
.manual-form__sep { width: 1px; height: 20px; background: var(--line); }
.month-nav h2 { margin: 0; }
.month-nav + .totals { margin-top: 12px; }
.manual-form:has(input[name=kind][value=income]:checked) .only-expense,
.manual-form:has(input[name=kind][value=expense]:checked) .only-income { display: none; }
.legend { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; color: var(--muted); margin: -4px 0 14px; }
.legend__swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; border: 1px solid var(--line); }
.legend__swatch--near { background: var(--near-bg); }
.legend__swatch--over { background: var(--err-bg); margin-left: 12px; }
.money-input { width: 130px; text-align: right; padding: 5px 8px; font-variant-numeric: tabular-nums; }
.bar-col { width: 110px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--pos); }
.bar__fill--over { background: var(--neg); }
.form-foot { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; margin-top: 14px; }
.inline-note { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 0 0 14px; color: var(--muted); }

@media (max-width: 640px) {
  .props { grid-template-columns: 1fr; gap: 2px; }
  .props dd { margin-bottom: 8px; }
  .bar-col { display: none; }
  .page { padding: 16px 16px 48px; }
  h1 { font-size: 22px; }
  .filters label { min-width: 0; flex: 1 1 140px; }
  .total { min-width: 0; flex: 1 1 100%; }
}
