:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --on-surface: #1a1a1a;
  --muted: #5f6368;
  --primary: #1565c0;
  --on-primary: #ffffff;
  --border: #e0e0e0;
  --error: #c62828;
  --debt: #c62828;
  --credit: #2e7d32;
  --font-scale: 1;
  font-size: calc(16px * var(--font-scale));
}
[data-theme="dark"] {
  --bg: #121212;
  --surface: #1e1e1e;
  --on-surface: #eaeaea;
  --muted: #9aa0a6;
  --primary: #64b5f6;
  --on-primary: #06243d;
  --border: #333;
  --error: #ef5350;
  --debt: #ef5350;
  --credit: #66bb6a;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--on-surface);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--primary); color: var(--on-primary);
  display: flex; align-items: center; gap: .5rem; padding: max(env(safe-area-inset-top), .5rem) 1rem .75rem;
  font-size: 1.1rem; font-weight: 600; }
.topbar .grow { flex: 1; }
.topbar button { background: rgba(255,255,255,.18); color: var(--on-primary); border: 0;
  border-radius: 8px; padding: .45rem .8rem; font-size: .9rem; }
.topbar .back { background: transparent; padding: .3rem .5rem; font-size: 1.1rem; }

.content { padding: 1rem; padding-bottom: 2rem; }

.tabs { display: flex; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky;
  top: 0; }
.tabs button { flex: 1; background: none; border: 0; padding: .9rem .3rem; color: var(--muted);
  font-size: .95rem; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

label.field { display: block; margin-bottom: .7rem; }
label.field span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
input, select { width: 100%; padding: .7rem .8rem; font-size: 1rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); color: var(--on-surface); }
input:focus, select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.row2 { display: flex; gap: .6rem; }
.row2 > * { flex: 1; }

/* Рядок чіпів з одним активним варіантом (напр. парність будинків). */
.chips { display: flex; gap: .6rem; margin-bottom: .7rem; }
.chips .chip { flex: 1; width: auto; padding: .55rem .3rem; font-size: .9rem; text-align: center;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--on-surface); }
.chips .chip.active { border-color: var(--primary); background: var(--primary); color: var(--on-primary); font-weight: 600; }

button.btn { width: 100%; padding: .8rem; font-size: 1rem; border: 0; border-radius: 10px;
  background: var(--primary); color: var(--on-primary); font-weight: 600; }
button.btn.secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
button.btn.small { width: auto; padding: .5rem .9rem; font-size: .9rem; }

.checkbox { display: flex; align-items: center; gap: .5rem; margin: .3rem 0; }
.checkbox input { width: auto; }

.count { font-size: .8rem; color: var(--muted); margin: .4rem 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: .9rem; margin-bottom: .6rem; }
.card.tap:active { background: var(--bg); }
.card .title { font-weight: 600; margin-bottom: .2rem; }
.card .sub { color: var(--muted); font-size: .9rem; }
.balance.debt { color: var(--debt); font-weight: 600; }
.balance.credit { color: var(--credit); }
.phone { color: var(--primary); text-decoration: underline; }
.overdue { color: var(--error); font-weight: 600; }
.comment { color: var(--muted); font-size: .85rem; white-space: pre-wrap; }
.comment.collapsed { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

.section-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 1rem; margin-bottom: 1rem; }
.section-card h3 { margin: 0 0 .7rem; font-size: 1rem; }
.note { font-size: .8rem; color: var(--muted); }
.status { font-size: .9rem; padding: .6rem; background: var(--surface); border-radius: 10px; border: 1px solid var(--border); }

.meter { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .9rem; margin-bottom: .7rem; }
.meter .num { font-weight: 600; }
.meter .last { color: var(--muted); font-size: .9rem; margin: .2rem 0; }
.meter .entry { display: flex; gap: .5rem; align-items: flex-end; margin-top: .5rem; }
.meter .entry label.field { flex: 1; margin: 0; }
.meter .saved { color: var(--credit); font-size: .9rem; margin-top: .4rem; }
.err { color: var(--error); font-size: .85rem; margin-top: .25rem; }

.fontbtns { display: flex; gap: .5rem; flex-wrap: wrap; }
.fontbtns button { flex: 1; }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex;
  align-items: center; justify-content: center; padding: 1.5rem; z-index: 50; }
.dialog { background: var(--surface); border-radius: 14px; padding: 1.2rem; max-width: 420px; width: 100%; }
.dialog h3 { margin: 0 0 .6rem; }
.dialog p { margin: 0 0 1rem; color: var(--on-surface); }
.dialog .actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; }
.dialog .actions button { background: none; border: 0; color: var(--primary); font-weight: 600;
  padding: .5rem .8rem; font-size: 1rem; }

.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.expired { padding: 2rem 1.5rem; }
.expired h2 { margin-top: 0; }
.switch-row { display: flex; align-items: center; gap: .6rem; margin: .5rem 0; }
.switch-row input { width: auto; transform: scale(1.3); }

.fab-top { position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: var(--on-primary);
  border: 0; font-size: 1.6rem; line-height: 1; display: none; box-shadow: 0 3px 10px rgba(0,0,0,.35); z-index: 30; }
.fab-top.show { display: block; }

/* ---- список виділених у результатах пошуку ---- */
.row-sel { display: flex; align-items: stretch; gap: .6rem; }
.row-sel .rowcheck { width: auto; align-self: center; transform: scale(1.3); flex: 0 0 auto; }
.row-sel .row-body { flex: 1; min-width: 0; }
.row-sel .row-body.tap:active { background: var(--bg); }

.selrow { display: flex; align-items: center; gap: .6rem; margin-top: .4rem; flex-wrap: wrap; }
.iconbtn { background: transparent; border: 1px solid var(--border); border-radius: 8px;
  padding: .35rem .55rem; font-size: 1.05rem; color: var(--on-surface); }
.hint-credit { color: var(--credit); font-size: .75rem; font-weight: 600; }

/* ---- картка: інфо-рядки, пароль, прописано ---- */
.kv { font-size: .9rem; margin: .1rem 0; }
.regpw { display: flex; flex-wrap: wrap; gap: .3rem 1.2rem; margin: .2rem 0; align-items: center; }
.pw { color: var(--primary); font-size: .9rem; cursor: pointer; user-select: none; }

/* ---- результат контакту ---- */
.contact-head { color: var(--primary); font-weight: 600; padding: .3rem 0; cursor: pointer; }
.contact-list { display: flex; flex-direction: column; gap: .1rem; margin-top: .3rem; }
.radio-row { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; }
.radio-row input { width: auto; transform: scale(1.2); }

/* ---- нижній рядок лічильника (стан + фото) ---- */
.meter-bottom { display: flex; align-items: center; gap: .6rem; margin-top: .5rem; }
.meter-bottom .saved { flex: 1; margin: 0; }
.meter-bottom > span { flex: 1; }

/* ---- тост ---- */
.toast { position: fixed; left: 50%; bottom: 2rem; transform: translateX(-50%) translateY(1rem);
  background: rgba(0,0,0,.85); color: #fff; padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
  opacity: 0; transition: opacity .2s, transform .2s; z-index: 100; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
