:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --line: #e2e5ea;
  --text: #1d2126;
  --muted: #7b8391;
  --brand: #c0392b;
  --brand-dark: #96291e;
  --ok-bg: #e8f6ec;
  --ok-text: #1c7c3c;
  --err-bg: #fdecec;
  --err-text: #b3231b;
  --warn: #c98a00;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

/* ---------- шапка ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 18px;
  background: #22262b;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar a { color: #dfe3e8; }
.topbar .brand a { font-weight: 600; color: #fff; }
.topbar nav { display: flex; gap: 14px; flex: 1; flex-wrap: wrap; }
.topbar nav a.active { color: #fff; border-bottom: 2px solid var(--brand); padding-bottom: 2px; }
.userbox { display: flex; align-items: center; gap: 10px; color: #cfd4da; font-size: 13px; }
.userbox .role { color: #8b939d; font-style: normal; }

/* ---------- контейнер ---------- */

.container { padding: 18px; max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 22px 0 10px; }
h3 { font-size: 14px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.bad { color: var(--err-text); font-weight: 600; }
.good { color: var(--ok-text); }
.warn { color: var(--warn); }
.right { text-align: right; }

/* ---------- карточки ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.cards { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.card.kpi { flex: 1 1 170px; display: flex; flex-direction: column; gap: 4px; }
.card.kpi b { font-size: 19px; }
.card.kpi em { color: var(--muted); font-style: normal; font-size: 12px; }
.kpi-label { color: var(--muted); font-size: 12px; }
.forms { display: flex; gap: 12px; flex-wrap: wrap; }
.card.mini { flex: 1 1 280px; margin-bottom: 0; }

/* ---------- формы ---------- */

label { display: block; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
input, select, button { font: inherit; }
input[type=text], input[type=date], input[type=month], input[type=password], input[type=number], select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}
input.tiny { width: 100px; }
input.wide { width: 100%; }

button.btn, button.btn-primary {
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}
button.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.btn-primary:hover { background: var(--brand-dark); }
button.link { background: none; border: none; color: #cfd4da; cursor: pointer; padding: 0; }
button.link.danger { color: var(--err-text); }
button.link:hover { text-decoration: underline; }

.period { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period select { width: auto; }
.inline-fields { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.inline-fields label { margin-bottom: 0; }
.inline-form { display: inline-block; margin-bottom: 14px; }
.row-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row-actions { margin: 12px 0; }

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

.table-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table.grid { border-collapse: collapse; width: 100%; font-size: 13px; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 6px 8px; text-align: right; white-space: nowrap; }
table.grid th { background: #f0f2f5; position: sticky; top: 0; z-index: 10; font-weight: 600; }
table.grid td.left, table.grid th.left { text-align: left; }
table.grid tr.totals td { font-weight: 600; background: #eef1f4; }
table.grid.compact th, table.grid.compact td { text-align: left; }
table.grid.compact td.sum { text-align: right; }

/* ---------- сообщения ---------- */

.flash { padding: 9px 12px; border-radius: 6px; margin-bottom: 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.err { background: var(--err-bg); color: var(--err-text); }

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

.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: 320px; }
.login-card h1 { margin-bottom: 4px; }
.login-card button { width: 100%; margin-top: 6px; }

.footer { padding: 14px 18px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- вкладки админки ---------- */

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; color: var(--text); font-size: 13px;
}
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs a:hover { text-decoration: none; }

/* ---------- расшифровка начисления (кабинет) ---------- */

.comps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
details.comp {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
}
details.comp > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 14px;
  list-style: none;
}
details.comp > summary::-webkit-details-marker { display: none; }
details.comp > summary::before { content: "\25B8"; color: var(--muted); margin-right: 6px; }
details.comp[open] > summary::before { content: "\25BE"; }
details.comp > summary .comp-label { flex: 1; }
details.comp > summary .comp-sum { font-weight: 600; white-space: nowrap; }
details.comp.zero > summary .comp-sum { color: var(--muted); font-weight: 400; }
.comp-body { padding: 0 12px 12px; }
.comp-body .formula { margin: 0 0 8px; font-weight: 600; }
dl.inputs { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 0 0 10px; }
dl.inputs > div { display: flex; gap: 6px; }
dl.inputs dt { color: var(--muted); }
dl.inputs dd { margin: 0; }
.table-wrap.detail-wrap { max-height: none; }
table.detail td:first-child, table.detail th:first-child { text-align: left; }
.totals-table { margin-top: 8px; }

@media (max-width: 600px) {
  .container { padding: 12px; }
  h1 { font-size: 17px; }
  .card.kpi b { font-size: 17px; }
  dl.inputs { gap: 4px 12px; }
}

