:root {
  color-scheme: light;
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f0f3f7; --line: #dde3ea;
  --text: #191919; --text-2: #5f6670; --accent: #1b64be; --accent-ink: #ffffff;
  --s1: #257de0; --s2: #f47230; --neg: #c62828; --good: #0b7a24; --warn: #a15c00;
  --grid: #e6e9ee; --shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121315; --surface: #191919; --surface-2: #222426; --line: #33373c;
    --text: #efefef; --text-2: #9c9c9c; --accent: #338ced; --accent-ink: #0b0b0b;
    --s1: #338ced; --s2: #e76624; --neg: #ff6b6b; --good: #3ecf5c; --warn: #f0a640;
    --grid: #2a2d31; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; text-align: center; color: var(--text-2); }

/* шапка */
.top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 54px; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; margin-right: 8px; color: var(--text); }
.brand small { font-weight: 400; color: var(--text-2); margin-left: 6px; }
.nav { display: flex; gap: 2px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 8px 10px; border-radius: 8px; color: var(--text-2); white-space: nowrap; position: relative; }
.nav a.on { color: var(--text); background: var(--surface-2); font-weight: 600; }
.nav a:hover { color: var(--text); }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--neg); color: #fff;
  font-size: 11px; line-height: 18px; text-align: center; margin-left: 4px; font-weight: 600; }
.badge.soft { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.icon-btn { background: none; border: 0; padding: 8px; border-radius: 8px; cursor: pointer; position: relative; color: var(--text-2); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn .badge { position: absolute; top: 2px; right: -2px; }
.who { color: var(--text-2); font-size: 13px; white-space: nowrap; }

main { max-width: 1240px; margin: 0 auto; padding: 16px 12px 80px; }
h1 { font-size: 22px; margin: 4px 0 14px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
h1 .grow { flex: 1; }
h1 .btn { font-size: 15px; }
h1 .muted.small { font-weight: 400; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.tile .lbl { color: var(--text-2); font-size: 13px; }
.tile .val { font-size: 24px; font-weight: 700; margin: 2px 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile .delta { font-size: 12px; color: var(--text-2); }
.tile.link { cursor: pointer; }
.tile.link:hover { border-color: var(--accent); }
.neg { color: var(--neg); }
.pos { color: var(--good); }
.mt { margin-top: 12px; }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.danger { color: var(--neg); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--text-2); gap: 2px; }
input, select, textarea { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--text-2); }
.form label.full { grid-column: 1 / -1; }
.form .check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form textarea { min-height: 64px; resize: vertical; }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 14px; }
.actions .left { margin-right: auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 18px; cursor: pointer; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* таблицы */
.tbl-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
.t th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--line);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
.t td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.t tr.click { cursor: pointer; }
.t tr.click:hover td { background: var(--surface-2); }
.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t .nowrap { white-space: nowrap; }
.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.t tr.sel td { background: var(--surface-2); }
.t .sub { color: var(--text-2); font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; border: 1px solid var(--line); white-space: nowrap; }
.pill.new { border-color: var(--warn); color: var(--warn); }
.pill.approved { border-color: var(--s1); color: var(--accent); }
.pill.paid, .pill.ok { border-color: var(--good); color: var(--good); }
.pill.rejected, .pill.cancelled { color: var(--text-2); }
.pill.unchk { border-color: var(--warn); color: var(--warn); }
.more { text-align: center; margin: 12px 0; }
.empty { padding: 26px; text-align: center; color: var(--text-2); }

/* окно */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-start;
  justify-content: center; padding: 5vh 10px; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 14px; padding: 18px; width: 100%; max-width: 620px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.wide { max-width: 860px; }
.modal h2 { font-size: 18px; margin-bottom: 14px; }
.err { color: var(--neg); margin-top: 8px; white-space: pre-wrap; }
#toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px;
  border-radius: 10px; z-index: 60; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; }
#toast.on { opacity: 1; }
.secret { font: 600 20px/1.3 ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 10px 14px; border-radius: 8px;
  letter-spacing: 1px; user-select: all; }

/* вход */
.login { max-width: 360px; margin: 12vh auto; }
.login h1 { justify-content: center; }
.login .form { grid-template-columns: 1fr; }

/* диаграммы */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .ax { fill: var(--text-2); font-size: 11px; }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .b1 { fill: var(--s1); }
.chart .b2 { fill: var(--s2); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--text); fill-opacity: .05; }
.chart .lbl { fill: var(--text); font-size: 12px; }
.chart .lbl2 { fill: var(--text-2); font-size: 12px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--text-2); margin-bottom: 6px; flex-wrap: wrap; align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend .sw1 { background: var(--s1); } .legend .sw2 { background: var(--s2); }
.legend .grow { flex: 1; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; font-size: 12px; box-shadow: 0 4px 14px rgba(0,0,0,.15); white-space: nowrap; z-index: 5; display: none; }
.tip b { display: block; margin-bottom: 2px; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; }
.hb { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 6px 10px; align-items: center; font-size: 13px; }
.hb .bar { height: 14px; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hb .bar.o { background: var(--s2); }
.hb .v { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hb .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* права в роли */
.perm-group { margin: 10px 0 4px; font-weight: 600; font-size: 13px; }
.perm { display: flex; gap: 8px; align-items: flex-start; padding: 3px 0; font-size: 14px; }
.perm input { margin-top: 3px; }
.notif { padding: 10px 4px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.notif.unread b::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  margin-right: 6px; }
.notif .muted { font-size: 13px; }

@media (max-width: 720px) {
  .top { flex-wrap: wrap; height: auto; padding: 6px 8px 0; }
  .top .nav { order: 9; flex-basis: 100%; padding-bottom: 4px; }
  .top .brand { flex: 1; }
  .who { display: none; }
  .brand small { display: none; }
  main { padding: 12px 8px 80px; }
  .tile .val { font-size: 20px; }
  .hide-m { display: none; }
}
@media print { .top, .filters, .btn { display: none !important; } }
