/* Layout: шапка с вкладками сверху, рабочая область — таблицы/карточки; на телефоне таблицы становятся карточками */
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --line: #dde2ea;
  --fg: #17202e;
  --muted: #5b6676;
  --accent: #2f5fa7;
  --accent-fg: #ffffff;
  --accent-soft: #e3ecf8;
  --ok: #1f7a4d;
  --ok-soft: #dff2e7;
  --warn: #9a5b06;
  --warn-soft: #fbeed6;
  --danger: #b3261e;
  --danger-soft: #fbe4e2;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .06);
  --font: 'Golos Text', 'Segoe UI', Roboto, Arial, sans-serif;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #161d27;
    --surface-2: #1c2532;
    --line: #2a3442;
    --fg: #e6ebf2;
    --muted: #93a0b3;
    --accent: #79a6eb;
    --accent-fg: #0b1526;
    --accent-soft: #1c2b44;
    --ok: #5cc98f;
    --ok-soft: #15301f;
    --warn: #e3a64a;
    --warn-soft: #35270f;
    --danger: #f08a80;
    --danger-soft: #3a1a18;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
.only-m { display: none; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.boot { padding: 48px 16px; text-align: center; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Шапка ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.top-row, .tabs, main, .demo-bar {
  max-width: 1200px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.top-row { display: flex; align-items: center; gap: 12px; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; flex: none; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-user { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.top-user .who { text-align: right; line-height: 1.2; min-width: 0; }
.top-user .who b { display: block; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 10px 14px; font-weight: 500; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--fg); }
.tab[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.demo-bar { padding-block: 8px; font-size: 13px; color: var(--warn); background: var(--warn-soft); max-width: none; }
.demo-bar .inner { max-width: 1200px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }

main { padding-block: 20px 48px; display: flex; flex-direction: column; gap: 18px; }
h1 { font-size: 22px; margin: 0; font-weight: 700; text-wrap: balance; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.page-head .spacer { flex: 1; }

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500;
  white-space: nowrap; min-height: 38px;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.icon { padding: 4px 8px; min-height: 30px; color: var(--muted); }
.btn.icon:hover { color: var(--fg); }
.btn:disabled { opacity: .5; cursor: default; }

label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; min-width: 0; }
.input, select.input, textarea.input {
  width: 100%; min-height: 40px;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  border-radius: 8px; padding: 8px 10px; font-size: 15px;
}
textarea.input { min-height: 64px; resize: vertical; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--fg); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- Период ---------- */
.period { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 7px; cursor: pointer; font-weight: 500; color: var(--muted); font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: var(--shadow); }
.period-nav { display: inline-flex; align-items: center; gap: 4px; }
.period-label { font-weight: 600; min-width: 150px; text-align: center; font-size: 14px; }
.period-custom { display: inline-flex; gap: 6px; align-items: center; }
.period-custom .input { width: auto; min-height: 36px; padding: 5px 8px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters select.input { width: auto; min-width: 150px; min-height: 36px; padding: 5px 8px; }

/* ---------- Карточки-итоги ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 860px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi .lbl { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .sub { font-size: 13px; color: var(--muted); }
.kpi.warn .val { color: var(--warn); }
.kpi.ok .val { color: var(--ok); }

/* ---------- Панели и таблицы ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th {
  text-align: left; font-weight: 600; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap;
}
table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: var(--surface-2); }
table.t .n { text-align: right; white-space: nowrap; }
table.t tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 0; }
table.t .actions { text-align: right; white-space: nowrap; width: 1%; }
table.t .cb { width: 1%; }
.row-sub { font-size: 13px; color: var(--muted); }
tr.is-inactive td { opacity: .6; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* Статусы */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 0; white-space: nowrap; line-height: 1.5;
}
.pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.paid { background: var(--ok-soft); color: var(--ok); }
.pill.unpaid { background: var(--warn-soft); color: var(--warn); }
.pill.low { background: var(--danger-soft); color: var(--danger); }
.pill.neutral { background: var(--surface-2); color: var(--muted); }
.pill.in { background: var(--ok-soft); color: var(--ok); }
.pill.out { background: var(--accent-soft); color: var(--accent); }
button.pill { cursor: pointer; }
button.pill:hover { filter: brightness(.96); }
.role { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.amt-warn { color: var(--warn); font-weight: 600; }
.amt-ok { color: var(--ok); }

.bulk {
  position: sticky; bottom: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--accent-soft); border-top: 1px solid var(--line);
}
.bulk b { font-variant-numeric: tabular-nums; }

.alert-list { display: flex; flex-direction: column; }
.alert-list .row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--line); align-items: center; }
.alert-list .row:last-child { border-bottom: 0; }

/* ---------- Таблицы → карточки на телефоне ---------- */
@media (max-width: 680px) {
  table.t.stack thead { display: none; }
  table.t.stack, table.t.stack tbody, table.t.stack tr, table.t.stack td, table.t.stack tfoot { display: block; width: 100%; }
  table.t.stack tr { padding: 10px 14px; border-bottom: 1px solid var(--line); position: relative; display: flex; flex-direction: column; }
  table.t.stack td.main { order: -1; }
  table.t.stack td.hide-m { display: none; }
  table.t.stack .only-m { display: block; }
  table.t.stack td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.t.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; flex: none; }
  table.t.stack td.main { display: block; text-align: left; font-weight: 600; padding-right: 32px; }
  table.t.stack td.main::before { content: none; }
  table.t.stack td.cb { position: absolute; right: 12px; top: 10px; width: auto; padding: 0; }
  table.t.stack td.cb::before { content: none; }
  table.t.stack td.actions { justify-content: flex-end; width: 100%; padding-top: 6px; }
  table.t.stack td.actions::before { content: none; }
  table.t.stack td.n { text-align: right; }
  table.t.stack tbody tr:hover td { background: none; }
  table.t.stack tfoot tr { background: var(--surface-2); }
  table.t.stack tfoot td:empty { display: none; }
}

/* ---------- Модальное окно ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 15, 25, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: max(24px, env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 24px max(12px, env(safe-area-inset-left, 0px));
  overflow-y: auto;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; border: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--line); }
.modal-foot .left { margin-right: auto; }
.sum-preview { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; display: flex; justify-content: space-between; font-weight: 600; }
.form-error { color: var(--danger); font-size: 14px; }

/* ---------- Вход ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 26px; display: flex; flex-direction: column; gap: 16px; }
.auth .brand { font-size: 19px; }
.auth form { display: flex; flex-direction: column; gap: 12px; }
.auth .note { font-size: 14px; color: var(--muted); }
.auth .note.ok { color: var(--ok); }

/* ---------- Уведомление ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 60;
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
#toast.err { background: var(--danger); color: #fff; }

.subtabs { display: flex; gap: 6px; }

@media (prefers-reduced-motion: no-preference) {
  .modal { animation: pop .14s ease-out; }
  @keyframes pop { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
}
