:root {
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f7f7fa;
  --text: #111114;
  --muted: #8a8a93;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #0a84ff;
  --accent-soft: rgba(10, 132, 255, 0.12);
  --ok: #1f9d55;
  --ok-soft: rgba(31, 157, 85, 0.12);
  --bad: #e5484d;
  --bad-soft: rgba(229, 72, 77, 0.12);
  --warn: #c27c0e;
  --warn-soft: rgba(245, 166, 35, 0.16);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f12;
    --surface: #1a1a1f;
    --surface-2: #222228;
    --text: #f2f2f5;
    --muted: #8e8e98;
    --line: rgba(255, 255, 255, 0.09);
    --accent: #3b9bff;
    --accent-soft: rgba(59, 155, 255, 0.16);
    --ok: #3ecf7a;
    --ok-soft: rgba(62, 207, 122, 0.14);
    --bad: #ff6b6f;
    --bad-soft: rgba(255, 107, 111, 0.14);
    --warn: #f5b84a;
    --warn-soft: rgba(245, 184, 74, 0.14);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg { width: 20px; height: 20px; flex: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-danger { color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: transparent; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-block { width: 100%; height: 44px; }
.icon-btn {
  width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- Чипы / бейджи ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px; border-radius: 999px;
  font-size: 13px; font-weight: 600; white-space: nowrap;
  border: 0; font-family: inherit; background: var(--surface-2); color: var(--muted);
}
button.chip { cursor: pointer; }
button.chip:hover { filter: brightness(.96); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip-ok { background: var(--ok-soft); color: var(--ok); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-wait { background: var(--surface-2); color: var(--muted); }
.chip-accent { background: var(--accent-soft); color: var(--accent); }

.plate {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  border: 1.5px solid var(--text); font: 600 13px/1.4 ui-monospace, "SF Mono", Consolas, monospace;
  letter-spacing: .5px; white-space: nowrap;
}

/* ---------- Вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; padding: 28px;
  background: var(--surface); border-radius: 20px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card .muted { margin: -6px 0 6px; }
.form-error { color: var(--bad); margin: 0; font-size: 14px; text-align: center; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; letter-spacing: -.3px; }
.brand-lg { font-size: 22px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 17px;
}

/* ---------- Формы ---------- */
label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
input, select, textarea {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-weight: 500; font-size: 14px; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* ---------- Каркас ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 20px;
  padding: 20px 12px; background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar .brand { padding: 0 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav button, .nav-logout {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border: 0; border-radius: 10px;
  background: transparent; color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-align: left;
}
.nav button:hover, .nav-logout:hover { background: var(--surface-2); }
.nav button svg, .nav-logout svg { color: var(--muted); }
.nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav button.active svg { color: var(--accent); }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--bad); color: #fff; font-size: 12px; display: grid; place-items: center;
}
.nav-badge-soft { background: var(--warn-soft); color: var(--warn); }
.nav-logout { color: var(--muted); }

.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: -.5px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.view { padding: 4px 28px 40px; display: flex; flex-direction: column; gap: 20px; max-width: 1280px; }

/* ---------- Карточки ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 0; }
.card-head h2, .section-title { margin: 0; font-size: 17px; letter-spacing: -.2px; }
.section-title { margin-bottom: -8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; cursor: default; }
button.stat { text-align: left; font: inherit; color: inherit; cursor: pointer; }
button.stat:hover { border-color: var(--accent); }
.stat b { font-size: 28px; letter-spacing: -.8px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat.ok b { color: var(--ok); } .stat.bad b { color: var(--bad); } .stat.warn b { color: var(--warn); }

.list { list-style: none; margin: 0; padding: 6px 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { color: var(--muted); font-size: 13px; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }

/* ---------- Устройства ---------- */
.devices { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.device {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 12px;
  padding: 16px; min-height: 120px; text-align: left;
  font: inherit; color: var(--text); cursor: pointer;
  transition: border-color .15s, background .15s, transform .06s;
}
.device:hover { border-color: var(--accent); }
.device:active { transform: scale(.985); }
.device:disabled { cursor: not-allowed; opacity: .7; }
.device .ico { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); }
.device .ico svg { width: 22px; height: 22px; }
.device b { font-size: 16px; }
.device small { color: var(--muted); font-size: 13px; margin-top: -10px; }
.device .relay-dot { position: absolute; top: 16px; right: 16px; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.device .relay-dot.on { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.device.sent { border-color: var(--ok); background: var(--ok-soft); }
.device.sent .ico { background: var(--ok); color: #fff; }
.device.busy { border-color: var(--warn); background: var(--warn-soft); }
.device.primary .ico { background: var(--accent-soft); color: var(--accent); }

.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.kv div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.kv span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.kv b { font-size: 15px; font-variant-numeric: tabular-nums; }

.log { font: 13px/1.7 ui-monospace, Consolas, monospace; max-height: 220px; overflow: auto; padding: 12px 20px 16px; color: var(--muted); }
.log div b { color: var(--text); font-weight: 600; }

/* ---------- Таблица жителей ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.toolbar .search { flex: 1 1 220px; position: relative; }
.toolbar select { width: auto; min-width: 120px; }
.toolbar .spacer { flex: 1; }

.bulkbar {
  position: sticky; top: 70px; z-index: 4;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 12px;
  background: var(--accent); color: #fff; box-shadow: 0 8px 24px rgba(10, 132, 255, .25);
}
.bulkbar b { margin-right: 6px; }
.bulkbar .btn { height: 32px; background: rgba(255,255,255,.16); border-color: transparent; color: #fff; }
.bulkbar .btn:hover { background: rgba(255,255,255,.26); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  position: sticky; top: 0;
  text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface);
}
td { padding: 10px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
tr:first-child td { border-top: 0; }
tbody tr:hover td { background: var(--surface-2); }
tr.apt-start td { border-top: 1px solid color-mix(in srgb, var(--text) 18%, transparent); }
tr.is-blocked td { opacity: .62; }
tr.is-selected td { background: var(--accent-soft) !important; }
td.c-check, th.c-check { width: 40px; padding-right: 0; }
td.c-apt { white-space: nowrap; width: 96px; }
td.c-apt b { font-size: 16px; font-variant-numeric: tabular-nums; }
td.c-status { width: 1%; }
td.c-status .chip { margin: 2px 4px 2px 0; }
td.c-actions { width: 1%; }
td.c-apt small, td.c-name small { display: block; color: var(--muted); font-size: 12px; }
td.c-name { font-weight: 600; }
td.c-phone { white-space: nowrap; font-variant-numeric: tabular-nums; }
td.c-actions { white-space: nowrap; text-align: right; }
.warn-dot { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-left: 6px; border-radius: 50%; background: var(--warn-soft); color: var(--warn); font-size: 12px; font-weight: 800; vertical-align: middle; }
.table-foot { padding: 12px 16px; color: var(--muted); font-size: 13px; border-top: 1px solid var(--line); }

/* ---------- Сообщения ---------- */
.msg { padding: 16px 20px; border-top: 1px solid var(--line); display: flex; gap: 14px; }
.msg:first-child { border-top: 0; }
.msg .grow { flex: 1; min-width: 0; }
.msg h3 { margin: 0 0 4px; font-size: 16px; }
.msg p { margin: 0 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; }
.msg.important { box-shadow: inset 3px 0 0 var(--bad); }

/* ---------- Порядок в данных ---------- */
.diff { font-size: 14px; }
.diff del { color: var(--bad); text-decoration: line-through; background: var(--bad-soft); padding: 0 4px; border-radius: 4px; }
.diff ins { color: var(--ok); text-decoration: none; background: var(--ok-soft); padding: 0 4px; border-radius: 4px; }
.diff .field { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; margin-right: 6px; }
.diff-row + .diff-row { margin-top: 4px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- Диалоги ---------- */
.dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 64px rgba(0,0,0,.24);
  overflow-x: hidden;
}
.dialog::backdrop { background: rgba(0, 0, 0, .36); backdrop-filter: blur(2px); }
.dialog form { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog h2 { margin: 0; font-size: 20px; letter-spacing: -.3px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span-2 { grid-column: span 2; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.dialog .small { margin: 0; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; }
.segmented label { display: block; position: relative; overflow: hidden; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 7px 4px; border-radius: 8px; color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.segmented input:checked + span { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); color: var(--accent); }
.recipients { display: flex; flex-wrap: wrap; gap: 6px; max-height: 110px; overflow: auto; }

/* ---------- Тосты ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Мобильная версия ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 10; height: auto;
    flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line);
    overflow-x: auto; scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .sidebar .brand span:last-child { display: none; }
  .sidebar .brand { padding: 0; }
  .nav { flex-direction: row; gap: 4px; }
  .nav button, .nav-logout { white-space: nowrap; padding: 8px 10px; }
  .nav-logout span { display: none; }
  .topbar { position: static; padding: 16px; flex-wrap: wrap; }
  .topbar h1 { font-size: 22px; }
  .topbar-right .btn span { display: none; }
  .view { padding: 0 16px 32px; }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .bulkbar { top: 60px; }

  /* таблица → карточки */
  .table-wrap table, .table-wrap tbody { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tr {
    display: grid; grid-template-columns: 32px 1fr auto; gap: 4px 10px; align-items: center;
    padding: 12px 14px; border-top: 1px solid var(--line);
  }
  .table-wrap tbody tr:first-child { border-top: 0; }
  .table-wrap td { padding: 0; border: 0; background: none !important; }
  .table-wrap td.c-check { grid-row: span 3; align-self: start; padding-top: 2px; }
  .table-wrap td.c-name { grid-column: 2; }
  .table-wrap td.c-apt { grid-column: 3; text-align: right; }
  .table-wrap td.c-apt small { display: inline; margin-left: 4px; }
  .table-wrap td.c-phone, .table-wrap td.c-car { grid-column: 2 / span 2; }
  .table-wrap td.c-status { grid-column: 2 / span 2; display: flex; gap: 6px; flex-wrap: wrap; }
  .table-wrap td.c-status, .table-wrap td.c-actions { width: auto; }
  .table-wrap td.c-actions { grid-column: 2 / span 2; text-align: left; margin-left: -8px; }
  .table-wrap tr.is-selected { background: var(--accent-soft); }
  .table-wrap.plain tr { grid-template-columns: 1fr auto; }
  .table-wrap.plain td:first-child { grid-row: auto; }
  .table-wrap.plain td { grid-column: auto !important; }

  .toasts { left: 16px; right: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
}

/* ---------- Оплаты: вкладки и прогресс ---------- */
.tabs { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; gap: 2px; }
.tabs button { border: 0; background: transparent; color: var(--text); font: inherit; font-size: 14px; font-weight: 600; padding: 7px 14px; border-radius: 8px; cursor: pointer; }
.tabs button.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.bar { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.ok i { background: var(--ok); }
.bar.warn i { background: var(--warn); }
.bar.bad i { background: var(--bad); }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .bar { flex: 1; margin: 0; }
.list li.clickable { cursor: pointer; }
.list li.clickable:hover { background: var(--surface-2); }
.list li .bar { max-width: 420px; }

/* =========================================================
   Оплаты v2: счета, проверка отметок, детали счёта
========================================================= */
.stack { display: flex; flex-direction: column; gap: 16px; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.bad { color: var(--bad); }
.hint { margin: 0; color: var(--muted); font-size: 14px; }
.hint b { color: var(--text); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-sm svg { width: 16px; height: 16px; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover { background: var(--ok); filter: brightness(1.08); }
.btn-ghost.btn-danger:hover { background: var(--bad-soft); }
.nav-badge-warn { background: var(--warn); color: #fff; }

.tabs-scroll { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.tabs-scroll::-webkit-scrollbar { display: none; }
.tabs button { white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tabs-sm button { padding: 5px 12px; font-size: 13px; }
.tab-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; font-size: 12px; display: inline-grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tab-count.warn { background: var(--warn-soft); color: var(--warn); }
.tab-count.bad { background: var(--bad-soft); color: var(--bad); }
.tab-count.ok { background: var(--ok-soft); color: var(--ok); }
.tab-count.plain { background: var(--line); color: var(--muted); }

.notice {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 14px 16px; border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; color: inherit; text-align: left;
}
button.notice { cursor: pointer; }
.notice .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.notice-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
button.notice-warn:hover { border-color: var(--warn); }
.notice-ico { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--warn); color: #fff; flex: none; }
.notice .btn { flex: none; }

.empty-state { padding: 40px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty-state h3 { margin: 4px 0 0; font-size: 18px; }
.empty-state p { margin: 0 0 8px; max-width: 460px; }
.empty-ico { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty-ico.ok { background: var(--ok-soft); color: var(--ok); }
.empty-ico svg { width: 26px; height: 26px; }

.stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat b.num { font-size: 24px; }

/* Сегментная полоса: зелёный — оплачено, жёлтый — на проверке, остальное (красное) — не оплачено */
.seg { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--bad-soft); margin: 12px 0 8px; }
.seg-lg { height: 12px; border-radius: 6px; margin: 16px 0 14px; }
.seg i { display: block; height: 100%; }
.seg i.ok { background: var(--ok); }
.seg i.warn { background: var(--warn); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.legend b { font-variant-numeric: tabular-nums; }
.dot.ok, .dot.warn, .dot.bad { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); opacity: .55; }

.bills { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 14px; }
.bill { padding: 16px 18px; cursor: pointer; display: flex; flex-direction: column; transition: border-color .12s, transform .06s; outline: none; }
.bill:hover, .bill:focus-visible { border-color: var(--accent); }
.bill:active { transform: scale(.995); }
.bill.is-overdue { box-shadow: inset 3px 0 0 var(--bad), var(--shadow); }
.bill-top { display: flex; align-items: flex-start; gap: 12px; }
.bill-top .grow { flex: 1; min-width: 0; }
.bill h3 { margin: 0 0 2px; font-size: 16px; overflow-wrap: anywhere; }
.bill-head h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.3px; overflow-wrap: anywhere; }
.bill .sub, .bill-head .sub { color: var(--muted); font-size: 13px; }
.bill .sub b, .bill-head .sub b { color: var(--text); }
.bill-text { margin: 10px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.bill-foot { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: auto; padding-top: 12px; font-size: 14px; }
.bill-money { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.bill-money div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; min-width: 0; }
.bill-money span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.bill-money b { font-size: 17px; }
.bill-money .ok b { color: var(--ok); } .bill-money .warn b { color: var(--warn); } .bill-money .bad b { color: var(--bad); }

.pay-summary { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: 14px; }
.pay-summary b { font-size: 17px; }

/* Таблицы оплат */
.ptable td { vertical-align: top; }
.ptable td.c-check, .ptable th.c-check { width: 40px; padding-right: 0; }
.ptable td.c-check input { margin-top: 3px; }
.ptable td.c-apt { white-space: nowrap; width: 90px; }
.ptable td.c-apt b { font-size: 16px; font-variant-numeric: tabular-nums; }
.ptable td.c-apt small { display: block; color: var(--muted); font-size: 12px; }
.ptable td.c-status .chip { margin-bottom: 4px; }
.ptable td.c-when { white-space: nowrap; }
.ptable td.c-act { white-space: nowrap; text-align: right; width: 1%; }
.ptable td.c-act .btn + .btn { margin-left: 6px; }
.ptable td.c-sum { white-space: nowrap; }
.ptable td.c-bar .seg { margin: 4px 0 4px; }
.ptable tr.is-selected td { background: var(--accent-soft) !important; }
.m-label { display: none; }

/* =========================================================
   Адаптивность
========================================================= */
/* Широкие экраны */
@media (min-width: 1600px) {
  .view { max-width: 1480px; }
  .app { grid-template-columns: 260px 1fr; }
}

/* Ноутбуки и планшеты в альбомной ориентации: меню — только иконки */
@media (min-width: 901px) and (max-width: 1180px) {
  .app { grid-template-columns: 76px 1fr; }
  .sidebar { padding: 16px 10px; align-items: center; }
  .sidebar .brand span:last-child { display: none; }
  .sidebar .brand { padding: 0; justify-content: center; }
  .nav { width: 100%; }
  .nav button, .nav-logout { position: relative; justify-content: center; padding: 11px 0; width: 100%; }
  .nav button span, .nav-logout span { display: none; }
  .nav-badge { position: absolute; top: 3px; right: 6px; margin: 0; min-width: 18px; height: 18px; font-size: 11px; padding: 0 5px; }
  .topbar { padding: 16px 22px; }
  .view { padding: 4px 22px 36px; }
  .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bill-money { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1180px) {
  .ptable td.c-act { white-space: normal; }
  .ptable td.c-act .btn { margin: 2px 0 2px 6px; }
}

/* Планшет в портретной ориентации и телефоны */
@media (max-width: 900px) {
  .sidebar {
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
    mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent);
  }
  .nav-badge { margin-left: 2px; }
  .stats-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bill-money { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar .search { flex-basis: 100%; }
  .toolbar select { flex: 1 1 140px; }
  .dialog-actions .btn { flex: 1; }

  /* Таблицы оплат → карточки */
  .ptable, .ptable tbody { display: block; }
  .ptable thead { display: none; }
  .ptable tr {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: start;
    padding: 14px 16px; border-top: 1px solid var(--line);
  }
  .ptable tbody tr:first-child { border-top: 0; }
  .ptable tr:has(> td.c-check) { grid-template-columns: 26px minmax(0, 1fr) auto; }
  .ptable td { padding: 0; border: 0; background: none !important; grid-column: 1 / -1; }
  .ptable tr:has(> td.c-check) td { grid-column: 2 / -1; }
  .ptable tr:has(> td.c-check) td.c-check { grid-column: 1; grid-row: 1 / span 6; width: auto; }
  .ptable td.c-apt { width: auto; grid-column: 1 !important; }
  .ptable tr:has(> td.c-check) td.c-apt { grid-column: 2 !important; }
  .ptable td.c-apt small { display: inline; margin-left: 6px; }
  .ptable td.c-sum.r, .ptable td.c-when { grid-column: -2 / -1 !important; grid-row: 1; text-align: right; }
  .ptable td.c-act { text-align: left; width: auto; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
  .ptable td.c-act .btn { margin: 0; flex: 1 1 auto; }
  .ptable td.c-act .btn + .btn { margin-left: 0; }
  .ptable tr.is-selected { background: var(--accent-soft); }
  .ptable tr.is-selected td { background: none !important; }
  .ptable td.c-status, .ptable td.c-act, .ptable td.c-who, .ptable td.c-bill { width: auto !important; }
  .ptable td.c-status { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; }
  .ptable td.c-status .chip { margin: 0; }
  .ptable td.c-status .small { flex-basis: 100%; }
  .ptable td[colspan] { grid-column: 1 / -1 !important; }
  .m-label { display: inline; color: var(--muted); font-size: 13px; }
  .ptable td.c-n, .ptable td.c-sum:not(.r) { font-size: 14px; }

  /* Панель массовых действий — внизу экрана, под большим пальцем */
  .bulkbar {
    position: fixed; top: auto; left: 12px; right: 12px; bottom: max(12px, env(safe-area-inset-bottom)); z-index: 20;
    max-height: 45vh; overflow-y: auto;
  }
  .bulkbar b { flex-basis: 100%; }
  .bulkbar .btn { flex: 1 1 auto; }
  .view:has(.bulkbar) { padding-bottom: 200px; }
}

/* Телефоны */
@media (max-width: 600px) {
  input, select, textarea { font-size: 16px; }
  .topbar { padding: 12px 16px 8px; }
  .topbar h1 { font-size: 21px; }
  #deviceChip { height: 26px; font-size: 12px; padding: 0 8px; }
  .view {
    gap: 14px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    padding-bottom: max(32px, env(safe-area-inset-bottom));
  }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat b { font-size: 22px; }
  .stat b.num { font-size: 17px; letter-spacing: -.3px; }
  .stat span { font-size: 12px; }
  .card-head { padding: 14px 16px 0; }
  .list li { padding: 10px 16px; }
  .card-pad { padding: 16px; }
  .devices { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .device { min-height: 104px; padding: 14px; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar { gap: 8px; }
  .toolbar > .btn { flex: 1 1 auto; }
  .toolbar > .spacer { display: none; }
  .toolbar > .tabs { flex: 1 1 100%; }
  .toolbar > .btn-ghost:first-child { flex: 0 0 auto; }
  .tabs-scroll { display: flex; }
  .notice { flex-wrap: wrap; padding: 12px 14px; }
  .notice .grow { flex-basis: calc(100% - 52px); }
  .notice > .btn { flex: 1 1 auto; }
  .bill { padding: 14px 16px; }
  .bill-top { flex-direction: column; gap: 6px; }
  .bill-head h2 { font-size: 18px; }
  .bill-money b { font-size: 15px; }
  .msg { padding: 14px 16px; }
  .empty-state { padding: 32px 18px; }

  /* Диалоги — шторка снизу на всю ширину */
  .dialog {
    width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: 92vh;
    border-radius: 18px 18px 0 0;
  }
  .dialog form { padding: 18px 16px max(18px, env(safe-area-inset-bottom)); }
  .dialog-actions { position: sticky; bottom: 0; background: var(--surface); margin: 0 -16px -4px; padding: 8px 16px 0; }
  .segmented span { font-size: 12px; padding: 8px 2px; }
}

/* Совсем узкие экраны */
@media (max-width: 380px) {
  .topbar-right .chip { display: none; }
}

/* ---------- Проверка чека ---------- */
.code { font-family: ui-monospace, "SF Mono", Consolas, monospace; letter-spacing: .3px; }
div.code { color: var(--muted); margin-top: 2px; }
.dialog-wide { width: min(860px, calc(100vw - 32px)); }
.dialog-actions .spacer { flex: 1; }
.claim-grid { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.claim-img {
  min-height: 240px; max-height: 62vh; overflow: auto; border-radius: 12px; background: var(--surface-2);
  display: grid; place-items: center; padding: 8px; border: 1px solid var(--line);
}
.claim-img img { display: block; max-width: 100%; height: auto; border-radius: 8px; }
.claim-facts { display: flex; flex-direction: column; gap: 8px; }
.claim-facts > div { background: var(--surface-2); border-radius: 10px; padding: 8px 12px; display: flex; flex-direction: column; gap: 1px; }
.claim-facts span { color: var(--muted); font-size: 12px; font-weight: 600; }
.claim-facts b { font-size: 15px; overflow-wrap: anywhere; }
.claim-facts .is-bad { background: var(--bad-soft); }
.claim-facts .is-bad b, .claim-facts em { color: var(--bad); }
.claim-facts em { font-style: normal; font-size: 12px; font-weight: 700; }
.claim-warn { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; background: var(--bad-soft); color: var(--bad); font-size: 14px; }
#claimBody > .muted { margin: 12px 0 0; }
.ptable td.c-receipt { white-space: nowrap; }
@media (max-width: 700px) {
  .claim-grid { grid-template-columns: 1fr; }
  .claim-img { min-height: 160px; max-height: 46vh; }
  .dialog-actions .spacer { display: none; }
  .dialog-actions { flex-wrap: wrap; }
  .dialog-actions [data-decide="confirm"] { flex-basis: 100%; order: -1; }
}
