/* Домоуправител – вход. Mobile-first. */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e4e7ec;
  --line-strong: #d0d5dd;
  --text: #101828;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e6f4f1;
  --ok: #16a34a;
  --ok-soft: #e8f6ed;
  --warn: #d97706;
  --warn-soft: #fdf3e3;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --info-soft: #eef2ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #151b23;
    --surface-2: #1c232d;
    --line: #262f3b;
    --line-strong: #344050;
    --text: #e6e9ee;
    --muted: #9aa4b2;
    --faint: #6b7686;
    --accent: #2bb3a3;
    --accent-ink: #04201c;
    --accent-soft: #11302c;
    --ok: #34c56b;
    --ok-soft: #12291b;
    --warn: #f0a33b;
    --warn-soft: #2e2312;
    --bad: #f26363;
    --bad-soft: #321718;
    --info-soft: #1b2140;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font); font-feature-settings: "tnum" 1, "cv11" 1;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.45rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 600; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.hide-sm { display: none !important; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

/* ---------- каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .in { max-width: 1040px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); }
.brand .logo svg { width: 18px; height: 18px; }
.topbar .sp { flex: 1; }
.wrap { max-width: 1040px; margin: 0 auto; padding: 16px 16px 96px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .9rem; margin-top: 2px; }

/* ---------- карти и решетки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head .sub { color: var(--muted); font-size: .85rem; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 14px 16px 0; }
.grid { display: grid; gap: 12px; }
.grid > .card + .card { margin-top: 0; }
.g2 { grid-template-columns: 1fr 1fr; }
.stack > * + * { margin-top: 12px; }
.section { margin-top: 20px; }
.section > h2 { margin: 0 0 10px; }

/* ---------- статистики ---------- */
.stat .label { font-size: .8rem; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.stat .value small { font-size: .85rem; font-weight: 500; color: var(--muted); }
.stat .hint { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.stat.ok .value { color: var(--ok); }
.stat.bad .value { color: var(--bad); }

.hero { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; }
.ring { position: relative; width: 132px; height: 132px; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 12; }
.ring .rt { stroke: var(--surface-2); }
.ring .bar { stroke: var(--accent); stroke-linecap: round; transition: stroke-dashoffset 1.4s cubic-bezier(.22, 1, .36, 1); }
.ring .lbl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring .lbl b { display: block; font-size: 1.7rem; font-weight: 750; letter-spacing: -.03em; line-height: 1; }
.ring .lbl span { font-size: .72rem; color: var(--muted); }
.hero-stats { display: grid; gap: 10px; }

/* ---------- лентови диаграми ---------- */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: baseline; }
.bar-row .name { font-size: .9rem; }
.bar-row .amt { font-weight: 600; font-size: .9rem; }
.bar-row .meta { grid-column: 1 / -1; font-size: .78rem; color: var(--muted); }
.track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.track i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width 1.1s cubic-bezier(.22, 1, .36, 1); }
.track i.ok { background: var(--ok); }
.track i.warn { background: var(--warn); }

.spark { display: flex; align-items: flex-end; gap: 6px; height: 64px; }
.spark .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.spark .col i { width: 100%; max-width: 34px; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); border-radius: 6px 6px 3px 3px; height: 0; transition: height 1s cubic-bezier(.22, 1, .36, 1); }
.spark .col.cur i { background: var(--accent); border-color: var(--accent); }
.spark .col span { font-size: .68rem; color: var(--muted); }

/* ---------- сградата по етажи ---------- */
.building { display: grid; gap: 6px; }
.floor { display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(0, 1fr); gap: 6px; align-items: stretch; }
.floor .fl { font-size: .72rem; color: var(--faint); display: grid; place-items: center; font-weight: 600; }
.apt {
  position: relative; display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font-size: .85rem; min-height: 44px;
}
a.apt:hover { text-decoration: none; border-color: var(--line-strong); }
.apt b { font-weight: 650; white-space: nowrap; }
.apt .s { white-space: nowrap; }
.apt .who { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.apt .who small { font-size: .74rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apt .s { font-size: .75rem; font-weight: 600; }
.apt.paid { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.apt.paid .s { color: var(--ok); }
.apt.due { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.apt.due .s { color: var(--warn); }
.apt.late { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.apt.late .s { color: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .78rem; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- чипове ---------- */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.chip.ok, .chip.paid { background: var(--ok-soft); color: var(--ok); }
.chip.warn, .chip.due { background: var(--warn-soft); color: var(--warn); }
.chip.bad, .chip.late { background: var(--bad-soft); color: var(--bad); }
.chip.neutral { background: var(--surface-2); color: var(--muted); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- бутони и форми ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 42px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font: 600 .9rem var(--font); cursor: pointer;
  text-decoration: none !important; white-space: nowrap; transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 34px; padding: 0 12px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn svg { width: 17px; height: 17px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field { margin-bottom: 12px; }
.input, select, textarea {
  width: 100%; height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 16px var(--font); /* 16px – без zoom в iOS */
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
.input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.input.amount { text-align: right; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 9px; font-size: .9rem; color: var(--text); font-weight: 500; margin: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg label { margin: 0; }
.seg input { display: none; }
.seg span { display: block; padding: 9px 14px; font-size: .88rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg input:checked + span { background: var(--accent-soft); color: var(--accent); }

/* ПИН */
.pin-box { display: flex; gap: 8px; justify-content: center; }
.pin-box input {
  width: 46px; height: 56px; text-align: center; font: 700 1.4rem var(--font);
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--surface); color: var(--text);
}
.pin-box input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

/* ---------- списъци и таблици ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .t { font-weight: 600; font-size: .92rem; }
.list .d { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.list a.rowlink { color: inherit; display: contents; }
.ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--muted); flex: none; font-weight: 700; font-size: .85rem; }
.ico.ok { background: var(--ok-soft); color: var(--ok); }
.ico.accent { background: var(--accent-soft); color: var(--accent); }
.ico svg { width: 18px; height: 18px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.t th, table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.t th { font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
table.t td.num, table.t th.num { text-align: right; }
table.t tfoot td { font-weight: 700; background: var(--surface-2); border-bottom: 0; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
table.sheet th { white-space: normal; min-width: 72px; vertical-align: bottom; }
table.sheet td:first-child, table.sheet th:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.sheet th:first-child { background: var(--surface-2); }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.kv .total { border-top: 1px solid var(--line); padding-top: 8px; font-size: 1rem; color: var(--text); }

/* ---------- съобщения ---------- */
.flash { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 12px; font-size: .9rem; border: 1px solid; animation: drop .35s ease-out; }
.flash.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.flash.err { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); color: var(--bad); }
.flash.info { background: var(--info-soft); border-color: var(--line); }
@keyframes drop { from { opacity: 0; transform: translateY(-6px); } }
.empty { text-align: center; color: var(--muted); padding: 24px 12px; font-size: .9rem; }
.note-bubble { background: var(--surface-2); border-radius: 12px 12px 12px 4px; padding: 10px 12px; font-size: .9rem; white-space: pre-wrap; }
.note-bubble.reply { background: var(--accent-soft); border-radius: 12px 12px 4px 12px; margin-left: 24px; }
.note-meta { font-size: .74rem; color: var(--faint); margin: 4px 2px 10px; }
.callout { background: var(--accent-soft); border-radius: var(--radius-sm); padding: 12px 14px; font-size: .88rem; }
.callout b { color: var(--text); }
.copy { cursor: pointer; border-bottom: 1px dashed var(--line-strong); }
details.fold summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; }
details.fold summary::-webkit-details-marker { display: none; }
details.fold summary::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint); transform: rotate(45deg); transition: transform .2s; margin-right: 4px; }
details.fold[open] summary::after { transform: rotate(-135deg); }
details.fold + details.fold { border-top: 1px solid var(--line); }
details.fold .body { padding: 0 16px 14px; }

/* ---------- навигация (админ) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 7px; font-size: .68rem; font-weight: 600; color: var(--muted); position: relative; }
.tabbar a:hover { text-decoration: none; }
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.on { color: var(--accent); }
.tabbar .dot { position: absolute; top: 5px; right: calc(50% - 16px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 99px; background: var(--bad); color: #fff; font-size: .62rem; display: grid; place-items: center; }
.sidenav { display: none; }
.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.more-grid a { display: flex; align-items: center; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); font-weight: 600; font-size: .9rem; }
.more-grid a svg { width: 20px; height: 20px; flex: none; color: var(--accent); }
.more-grid a:hover { text-decoration: none; border-color: var(--line-strong); }

/* ---------- вход ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth .box { width: 100%; max-width: 380px; }
.auth .logo-lg { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; margin: 0 auto 16px; }
.auth .logo-lg svg { width: 30px; height: 30px; }
.auth h1 { text-align: center; margin-bottom: 4px; }
.auth .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }

/* ---------- анимации ---------- */
.reveal { animation: rise .55s cubic-bezier(.22, 1, .36, 1) both; animation-delay: calc(var(--i, 0) * 60ms); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.building .apt { animation: pop .45s cubic-bezier(.22, 1, .36, 1) both; animation-delay: calc(var(--i, 0) * 28ms + 150ms); }
@keyframes pop { from { opacity: 0; transform: scale(.94); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- по-широки екрани ---------- */
@media (min-width: 640px) {
  .hide-sm { display: revert !important; }
  .btn.hide-sm { display: inline-flex !important; }
  .wrap { padding: 24px 24px 48px; }
  .grid.g3 { grid-template-columns: repeat(3, 1fr); }
  .grid.g4 { grid-template-columns: repeat(4, 1fr); }
  .grid.split { grid-template-columns: 1.15fr 1fr; align-items: start; }
  .ring { width: 150px; height: 150px; }
  .more-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1000px) {
  body.admin .tabbar { display: none; }
  body.admin .layout { display: grid; grid-template-columns: 220px 1fr; max-width: 1280px; margin: 0 auto; }
  body.admin .sidenav { display: block; position: sticky; top: 51px; height: calc(100vh - 51px); padding: 18px 12px; border-right: 1px solid var(--line); overflow-y: auto; }
  .sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: .9rem; }
  .sidenav a svg { width: 18px; height: 18px; }
  .sidenav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
  .sidenav a.on { background: var(--accent-soft); color: var(--accent); }
  .sidenav .grp { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 14px 12px 6px; font-weight: 700; }
  .sidenav .badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 99px; font-size: .7rem; padding: 0 7px; }
  body.admin .wrap { max-width: 1060px; margin: 0; padding-bottom: 48px; }
  body.admin .more-page { display: none; }
}

/* ---------- печат ---------- */
@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  .topbar, .tabbar, .sidenav, .no-print, .btn { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; }
  .reveal, .building .apt { animation: none; }
  a { color: #000; }
}

/* касова книга */
table.cb { table-layout: fixed; }
table.cb th { white-space: normal; font-size: .68rem; }
table.cb th:first-child, table.cb td:first-child { width: auto; }
table.cb th:nth-child(2), table.cb th:nth-child(3) { width: 26%; }
table.cb td { overflow-wrap: anywhere; }
@media (min-width: 640px) { table.cb th:nth-child(2), table.cb th:nth-child(3) { width: 18%; } }
table.cb tr.muted-row td { color: var(--muted); }
table.cb tr.sum td { font-weight: 600; background: var(--surface-2); }
table.cb tr.total td { font-weight: 800; font-size: 1rem; border-top: 2px solid var(--text); border-bottom: 0; }
@media print {
  .cashbook { break-inside: avoid; margin-bottom: 18px; border-top: 1px solid #000 !important; padding-top: 8px; }
  table.cb tr.sum td { background: #f2f2f2; }
}
