:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201c;
  --muted: #66736d;
  --line: #e3e8e5;
  --accent: #0f9d74;
  --accent-ink: #ffffff;
  --accent-soft: #e2f4ee;
  --danger: #d64545;
  --warn-soft: #fff4e0;
  --warn: #b26a00;
  --bad-soft: #fde9e9;
  --good-soft: #e2f4ee;
  --info-soft: #e8f0fd;
  --info: #2f5fb3;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1311;
    --card: #171e1b;
    --text: #e8eeeb;
    --muted: #93a19a;
    --line: #26302c;
    --accent: #2ec493;
    --accent-ink: #062218;
    --accent-soft: #143a2e;
    --warn-soft: #3a2c12;
    --warn: #f0b350;
    --bad-soft: #3d1a1a;
    --good-soft: #143a2e;
    --info-soft: #172840;
    --info: #8ab4f8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

/* ---------- шапка ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 4px 0 14px;
}
.room-btn {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  background: none; border: 0; padding: 6px 0; text-align: left;
}
.room-btn .avatar { flex: none; }
.room-btn b { display: block; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-btn small { color: var(--muted); font-size: 13px; }
.avatar {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--accent-soft); font-size: 20px;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; font-size: 18px; flex: none;
}

/* ---------- карточки ---------- */
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); margin-bottom: 14px;
  border: 1px solid var(--line);
}
.card h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.summary .label { color: var(--muted); font-size: 14px; }
.summary .big { font-size: 34px; font-weight: 700; letter-spacing: -.5px; margin: 2px 0 10px; }
.progress { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s; }
.progress.over > div { background: var(--danger); }
.summary .row { display: flex; justify-content: space-between; margin-top: 8px; font-size: 14px; color: var(--muted); }

/* ---------- ввод расхода ---------- */
.amount-field {
  display: flex; align-items: baseline; gap: 8px;
  border-bottom: 2px solid var(--line); padding: 4px 0 6px; margin-bottom: 16px;
}
.amount-field:focus-within { border-color: var(--accent); }
.amount-field input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none;
  font-size: 40px; font-weight: 700; letter-spacing: -.5px; padding: 0;
}
.amount-field span { font-size: 22px; color: var(--muted); font-weight: 600; }

.cats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.cat {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 14px;
  padding: 10px 4px 8px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12.5px; line-height: 1.15; text-align: center; transition: transform .1s;
}
.cat .e { font-size: 24px; }
.cat:active { transform: scale(.96); }
.cat.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }

.extra { display: flex; gap: 8px; margin-bottom: 14px; }
.input {
  width: 100%; border: 1.5px solid var(--line); background: var(--bg); border-radius: 12px;
  padding: 12px 14px; outline: 0; min-width: 0;
}
.input:focus { border-color: var(--accent); }
.extra .note { flex: 1; }
.extra .date { flex: 0 0 140px; }

.btn {
  width: 100%; border: 0; border-radius: 14px; padding: 15px; font-weight: 700; font-size: 17px;
  background: var(--accent); color: var(--accent-ink);
}
.btn:disabled { opacity: .45; }
.btn.ghost { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.btn.danger { background: var(--bad-soft); color: var(--danger); font-weight: 600; }
.btn + .btn { margin-top: 10px; }

/* ---------- список ---------- */
.day { margin-top: 6px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 10px 2px 4px; }
.item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.day .item:first-of-type { border-top: 0; }
.item .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 19px; flex: none; }
.item .t { flex: 1; min-width: 0; }
.item .t b { font-weight: 600; display: block; }
.item .t small { color: var(--muted); font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .a { font-weight: 700; white-space: nowrap; }
.item .del { border: 0; background: none; color: var(--muted); font-size: 18px; padding: 6px; margin-right: -6px; }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.empty .e { font-size: 40px; display: block; margin-bottom: 6px; }

/* ---------- статистика ---------- */
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px; border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.kpi small { color: var(--muted); font-size: 12px; display: block; }
.kpi b { font-size: 17px; display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .delta { font-size: 12px; font-weight: 600; }
.up { color: var(--danger); } .down { color: var(--accent); }

.donut-wrap { display: flex; gap: 18px; align-items: center; }
.donut { flex: none; width: 140px; height: 140px; position: relative; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut .center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut .center b { font-size: 15px; }
.donut .center small { font-size: 11px; color: var(--muted); }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.lg { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.lg i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.lg span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lg b { font-weight: 600; white-space: nowrap; }
.lg em { font-style: normal; color: var(--muted); font-size: 12px; width: 34px; text-align: right; }
@media (max-width: 380px) { .donut-wrap { flex-direction: column; align-items: stretch; } .donut { align-self: center; } }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 130px; padding-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.bars .b div { background: var(--accent); border-radius: 4px 4px 1px 1px; min-height: 2px; opacity: .85; }
.bars .b.today div { opacity: 1; }
.bars .b.zero div { background: var(--line); }
.bars-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

.hbar { margin: 10px 0; }
.hbar .h { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.hbar .track { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.hbar .track div { height: 100%; border-radius: 99px; }

/* ---------- советы ---------- */
.tip { display: flex; gap: 12px; padding: 14px; border-radius: 16px; margin-bottom: 10px; }
.tip .e { font-size: 24px; line-height: 1; flex: none; }
.tip b { display: block; margin-bottom: 2px; }
.tip p { margin: 0; font-size: 14.5px; }
.tip.good { background: var(--good-soft); }
.tip.warn { background: var(--warn-soft); }
.tip.bad { background: var(--bad-soft); }
.tip.info { background: var(--info-soft); }

/* ---------- комната ---------- */
.code-box { display: flex; align-items: center; gap: 10px; background: var(--accent-soft); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.code-box b { font-size: 26px; letter-spacing: 4px; flex: 1; font-family: ui-monospace, Menlo, monospace; }
.member { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.member .avatar { width: 34px; height: 34px; font-size: 15px; font-weight: 700; border-radius: 50%; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.room-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-bottom: 0; text-align: left; }
.room-row:first-child { border-top: 0; }
.room-row .t { flex: 1; min-width: 0; }
.room-row .t small { display: block; color: var(--muted); font-size: 13px; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 99px; background: var(--accent-soft); font-weight: 600; }

/* ---------- нижняя навигация ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-in { max-width: 560px; margin: 0 auto; display: flex; }
.nav button {
  flex: 1; border: 0; background: none; padding: 9px 0 8px; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 11.5px; color: var(--muted); font-weight: 600;
}
.nav button .e { font-size: 21px; filter: grayscale(1); opacity: .7; }
.nav button.on { color: var(--accent); }
.nav button.on .e { filter: none; opacity: 1; }

/* ---------- приветствие ---------- */
.hero { text-align: center; padding: 28px 8px 18px; }
.hero .logo { font-size: 56px; }
.hero h1 { font-size: 28px; margin: 8px 0 6px; letter-spacing: -.5px; }
.hero p { color: var(--muted); margin: 0; }
.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.choice button { border: 1.5px solid var(--line); background: var(--card); border-radius: 14px; padding: 14px 8px; text-align: center; }
.choice button .e { font-size: 28px; display: block; }
.choice button small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.choice button.on { border-color: var(--accent); background: var(--accent-soft); }
.tabs-mini { display: flex; gap: 6px; margin-bottom: 16px; }
.err { color: var(--danger); font-size: 14px; margin: -4px 0 10px; min-height: 1em; }

/* ---------- модалка / тост ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); max-height: 85vh; overflow: auto; animation: up .2s ease-out; }
@media (min-width: 600px) { .sheet-bg { align-items: center; } .sheet { border-radius: 22px; } }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet h2 { margin: 0 0 12px; font-size: 19px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 84px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30;
  max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.2);
}
