:root {
  --bg: #f6f6f4; --surface: #ffffff; --sunken: #f1f1ee; --ink: #16171a; --ink-2: #4a4d55; --muted: #80848e;
  --line: #e6e5e1; --line-2: #d9d8d3; --accent: #16171a; --accent-ink: #ffffff;
  --ok: #17804a; --ok-bg: #e7f4ec; --warn: #9a6100; --warn-bg: #fbf1de; --bad: #b42318; --bad-bg: #fdecea; --idle: #80848e; --idle-bg: #efefec;
  --r: 10px; --r-sm: 7px; --shadow: 0 1px 2px rgba(16, 17, 20, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1012; --surface: #17181b; --sunken: #1d1f23; --ink: #ecedef; --ink-2: #b9bcc3; --muted: #868a93;
    --line: #26282d; --line-2: #33363c; --accent: #ecedef; --accent-ink: #111214;
    --ok: #4cc386; --ok-bg: #15281e; --warn: #e2ad4c; --warn-bg: #2c2414; --bad: #f2786c; --bad-bg: #2f1917; --idle: #868a93; --idle-bg: #222429;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
.num, .amount, td.r, .kpi-v { font-variant-numeric: tabular-nums; }
a { color: inherit; }
button { font: inherit; }
input, select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm); padding: 8px 10px; min-height: 36px; outline: none; transition: border-color .12s, box-shadow .12s; }
input:focus, select:focus { border-color: var(--ink-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ink) 10%, transparent); }
input::placeholder { color: var(--muted); }

/* Кнопки */
.btn { text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); cursor: pointer; white-space: nowrap; font-weight: 500; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--sunken); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--bg)); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--ink-2); cursor: pointer; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 3px; }
.link:hover { color: var(--ink); text-decoration-color: currentColor; }

/* Вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 340px; display: grid; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.login-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.field input, .field select { width: 100%; }
.hint { font-size: 12.5px; color: var(--muted); }
.form-err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* Шапка */
.top { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.top-in { max-width: 1120px; margin: 0 auto; padding: 0 24px; display: flex; align-items: center; gap: 28px; height: 56px; }
.brand { font-weight: 650; letter-spacing: -.01em; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: var(--r-sm); font-weight: 500; white-space: nowrap; }
.nav a:hover { color: var(--ink); }
.nav a.on { color: var(--ink); background: var(--sunken); }
.who { display: flex; gap: 14px; align-items: center; color: var(--muted); font-size: 13px; white-space: nowrap; }

.main { max-width: 1120px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 22px; line-height: 1.2; font-weight: 650; letter-spacing: -.015em; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 4px; }
.sub { color: var(--muted); margin: 4px 0 0; }

/* Баланс */
.balance { display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); margin-bottom: 24px; }
.kpi { padding: 18px 20px; border-left: 1px solid var(--line); }
.kpi:first-child { border-left: 0; }
.kpi-l { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.kpi-v { font-size: 20px; font-weight: 600; margin-top: 4px; letter-spacing: -.01em; }
.kpi.main-kpi .kpi-v { font-size: 28px; }
.kpi-act { margin-top: 10px; }

/* Панель фильтров */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.seg { display: inline-flex; background: var(--sunken); border-radius: var(--r-sm); padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 11px; border-radius: 5px; color: var(--ink-2); cursor: pointer; font-weight: 500; font-size: 13px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.dates { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.dates input { width: 138px; }
.search { width: 190px; }
.summary { color: var(--ink-2); font-size: 13px; margin: 0 0 10px; }
.summary b { color: var(--ink); font-weight: 600; }

/* Таблица */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--sunken) 60%, transparent); }
th.r, td.r { text-align: right; }
td .sec { display: block; color: var(--muted); font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.status { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; padding: 2px 8px 2px 7px; border-radius: 999px; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-paid, .s-done { color: var(--ok); background: var(--ok-bg); }
.s-pending, .s-new-out { color: var(--warn); background: var(--warn-bg); }
.s-expired, .s-new, .s-failed { color: var(--idle); background: var(--idle-bg); }
.s-rejected { color: var(--bad); background: var(--bad-bg); }

/* Формы и разделы */
.cols { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 24px; align-items: start; }
.box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); padding: 20px; }
.box + .box { margin-top: 16px; }
.stack { display: grid; gap: 14px; min-width: 0; }
.stack > .btn { justify-self: start; }
.cols > * { min-width: 0; }
.result { min-width: 0; }
.det { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; display: block; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.result { display: flex; gap: 8px; align-items: center; background: var(--sunken); border-radius: var(--r-sm); padding: 8px 8px 8px 12px; }
.result code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.kv .total { font-weight: 600; color: var(--ink); }
.divider { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
pre.code { background: var(--sunken); border-radius: var(--r-sm); padding: 12px 14px; overflow-x: auto; font-size: 12.5px; line-height: 1.55; margin: 0; }
.note { font-size: 13px; color: var(--ink-2); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r-sm); font-size: 13.5px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.18); max-width: calc(100% - 32px); }

/* Телефон */
@media (max-width: 760px) {
  .top-in { padding: 0 16px; gap: 12px; height: auto; flex-wrap: wrap; padding-top: 10px; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; margin: 0 -6px; padding-bottom: 8px; }
  .main { padding: 20px 16px 56px; }
  .kpi { border-left: 0; border-top: 1px solid var(--line); padding: 14px 16px; }
  .kpi.main-kpi { grid-column: 1 / -1; border-top: 0; }
  .balance { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpi.main-kpi .kpi-v { font-size: 26px; }
  .kpi + .kpi + .kpi { border-left: 1px solid var(--line); }
  .kpi:not(.main-kpi) { padding: 12px 14px; }
  .kpi:not(.main-kpi) .kpi-v { font-size: 15px; }
  .kpi-l { font-size: 12px; }
  .stack > .btn-primary { justify-self: stretch; }
  .panel td[data-m="net"]::before { content: "зачислено "; color: var(--muted); font-size: 12px; }
  .det { max-width: 200px; }
  .result code { white-space: normal; word-break: break-all; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  .dates input { width: 128px; }
  .search { width: 100%; }
  .toolbar .grow { display: none; }
  /* таблица → список */
  .panel table, .panel tbody, .panel tr, .panel td { display: block; }
  .panel thead { display: none; }
  .panel tr { padding: 12px 16px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
  .panel tr:last-child { border-bottom: 0; }
  .panel td { padding: 0; border: 0; }
  .panel td.r { text-align: right; }
  .panel td[data-m="hide"] { display: none; }
  tbody tr:hover td { background: none; }
}
