:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #5f6b67;
  --line: #e2e7e5;
  --brand: #0f766e;
  --brand-dark: #0b5c56;
  --brand-soft: #e6f4f2;
  --danger: #c2410c;
  --danger-soft: #fff1e8;
  --ok: #15803d;
  --ok-soft: #e9f7ee;
  --warn: #a16207;
  --warn-soft: #fef8e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 22, 0.06), 0 4px 16px rgba(16, 24, 22, 0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }

/* ---------- Каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--brand); color: #fff;
  padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
}
.topbar .title { font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .sub { font-weight: 400; opacity: 0.85; font-size: 14px; }
.topbar button { background: rgba(255,255,255,0.16); border: 0; color: #fff; border-radius: 10px; padding: 7px 12px; cursor: pointer; }
.topbar button:hover { background: rgba(255,255,255,0.26); }
.back { font-size: 20px; line-height: 1; padding: 6px 10px !important; }

.page { max-width: 560px; margin: 0 auto; padding: 16px 16px 48px; display: grid; gap: 14px; }
.page.wide { max-width: 1180px; }
.page > * { min-width: 0; } /* иначе широкая таблица растягивает страницу на телефоне */

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card > * + * { margin-top: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

.tabs { display: flex; gap: 4px; background: var(--brand-dark); padding: 0 12px; overflow-x: auto; }
.tabs a { color: rgba(255,255,255,0.8); text-decoration: none; padding: 10px 12px; border-bottom: 3px solid transparent; white-space: nowrap; font-size: 15px; }
.tabs a.active { color: #fff; border-bottom-color: #fde047; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: #fde047; color: #3b3200; font-size: 12px; font-weight: 700; text-align: center; line-height: 20px; margin-left: 4px; }

/* ---------- Формы и кнопки ---------- */
label.field { display: grid; gap: 5px; font-size: 14px; color: var(--muted); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fff; font-size: 16px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
textarea { min-height: 90px; resize: vertical; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 140px; }
.row > .status, .row > .chip { flex: 0 0 auto; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 11px; padding: 12px 16px; cursor: pointer; font-weight: 600; text-decoration: none;
  background: var(--brand); color: #fff; min-height: 46px;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.block { width: 100%; }
.btn.secondary { background: var(--brand-soft); color: var(--brand-dark); }
.btn.secondary:hover { background: #d3ece8; }
.btn.ghost { background: transparent; color: var(--brand-dark); border: 1px solid var(--line); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.sm { min-height: 34px; padding: 6px 10px; font-size: 14px; border-radius: 9px; }
.btn.wa { background: #25d366; color: #fff; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 0; text-decoration: underline; }

.seg { display: flex; background: var(--bg); border-radius: 11px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.seg button.on { background: #fff; color: var(--text); box-shadow: var(--shadow); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.status { display: inline-block; font-size: 12px; font-weight: 650; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.s-pending { background: var(--warn-soft); color: var(--warn); }
.s-accepted, .s-confirmed { background: var(--ok-soft); color: var(--ok); }
.s-rejected { background: var(--danger-soft); color: var(--danger); }
.s-none { background: #eef1f0; color: var(--muted); }

.callout { border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.callout.info { background: var(--brand-soft); color: var(--brand-dark); }
.callout.warn { background: var(--warn-soft); color: #6b4a03; }
.callout.err { background: var(--danger-soft); color: var(--danger); }

/* ---------- Жилец ---------- */
.balance { text-align: center; padding: 22px 16px; }
.balance .label { color: var(--muted); font-size: 14px; }
.balance .value { font-size: 34px; font-weight: 750; letter-spacing: -0.5px; margin-top: 2px; }
.balance.debt .value { color: var(--danger); }
.balance.ok .value { color: var(--ok); }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 15px; }
.kv > :nth-child(odd) { color: var(--muted); }
.list { display: grid; }
.list-item { display: flex; gap: 12px; justify-content: space-between; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
.big-input { font-size: 28px; text-align: center; letter-spacing: 1px; font-variant-numeric: tabular-nums; padding: 14px; }
.photo-pick { border: 2px dashed var(--line); border-radius: 12px; padding: 18px; text-align: center; cursor: pointer; color: var(--muted); display: block; }
.photo-pick:hover { border-color: var(--brand); }
.photo-pick input { display: none; }
.preview { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; margin: 0 auto; }

.step { display: grid; grid-template-columns: 32px 1fr; gap: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
.step[hidden] { display: none; }
.step-n { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.step-body { display: grid; gap: 10px; min-width: 0; }
.btn.big { min-height: 56px; font-size: 18px; border-radius: 14px; margin-top: 14px; }
details > summary { cursor: pointer; color: var(--brand-dark); }
details.card > summary { color: var(--text); }

/* ---------- Таблицы управляющей ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 13px; }
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.3px; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:hover td { background: #fafbfb; }
.debt { color: var(--danger); font-weight: 600; }
.overpaid { color: var(--ok); font-weight: 600; }
.actions { display: flex; gap: 4px; flex-wrap: nowrap; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 32px; height: 32px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; text-decoration: none; color: inherit; }
.icon-btn:hover { border-color: var(--brand); }
.icon-btn.ok { color: var(--ok); }
.icon-btn.no { color: var(--danger); }

.pay-card { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: start; }
.pay-card + .pay-card { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }

/* ---------- Окна и уведомления ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 20, 18, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); max-width: 520px; width: 100%; max-height: 92vh; overflow: auto; padding: 18px; display: grid; gap: 12px; }
.modal.photo { max-width: 900px; }
.modal img { max-width: 100%; border-radius: 8px; display: block; margin: 0 auto; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #17201d; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 60; max-width: calc(100% - 32px); box-shadow: var(--shadow); }
.toast.err { background: var(--danger); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 400px; display: grid; gap: 14px; }
.logo { display: flex; align-items: center; gap: 12px; justify-content: center; margin-bottom: 4px; }
.logo img { width: 48px; height: 48px; }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  h1 { font-size: 20px; }
}

/* Быстрый переход к квартире (обход по этажам) */
.quick-open { display: flex; gap: 8px; max-width: 1180px; margin: 12px auto 0; padding: 0 16px; }
.quick-open input { max-width: 200px; font-size: 18px; padding: 8px 12px; }
.quick-open .btn { min-height: 44px; }

/* Телефон с кодом страны */
.phone-field { display: flex; gap: 6px; }
.phone-field select { flex: 0 0 auto; width: auto; max-width: 120px; padding-left: 8px; padding-right: 4px; }
.phone-field input { flex: 1; min-width: 0; }
