:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #16201c;
  --muted: #5d6b66;
  --line: #dfe6e3;
  --accent: #168060;
  --accent-soft: #e3f2ec;
  --debt: #d64545;
  --debt-soft: #fbe9e9;
  --radius: 14px;
  --nav-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715; --card: #1a2320; --text: #e6ece9; --muted: #95a39e; --line: #2c3833;
    --accent: #2fae86; --accent-soft: #1d3a30; --debt: #f06a6a; --debt-soft: #3c2224;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 22px 4px 10px; }
h3 { font-size: 1rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.debt { color: var(--debt); }
.pad { padding: 12px 16px; margin: 0; }

/* Шапка */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--accent); color: #fff;
}
.brand { color: #fff; font-weight: 700; text-decoration: none; }
.topbar-title { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; font-size: 1.4rem; padding: 0 4px; }
.menu summary::-webkit-details-marker { display: none; }
.menu-items {
  position: absolute; right: 0; top: 40px; min-width: 220px; background: var(--card); color: var(--text);
  border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.18); padding: 6px; display: flex; flex-direction: column;
}
.menu-items a, .menu-items .linklike { padding: 12px; color: var(--text); text-decoration: none; border-radius: 10px; text-align: left; }
.menu-items a:hover, .menu-items .linklike:hover { background: var(--bg); }
.menu-user { padding: 10px 12px; font-size: .85rem; color: var(--muted); border-bottom: 1px solid var(--line); }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; }

.container { max-width: 720px; margin: 0 auto; padding: 12px 16px; }

/* Нижняя навигация */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: .72rem; color: var(--muted); text-decoration: none; gap: 2px;
}
.bottomnav a span { font-size: 1.3rem; line-height: 1; }
.bottomnav a.active { color: var(--accent); font-weight: 600; }
.bottomnav a.add span { background: var(--accent); color: #fff; border-radius: 50%; width: 30px; height: 30px; display: grid; place-items: center; font-size: 1.2rem; }

.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 15;
  width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: #fff; text-decoration: none;
  display: grid; place-items: center; font-size: 2rem; box-shadow: 0 6px 18px rgba(0,0,0,.25);
}

/* Сообщения */
.messages { max-width: 720px; margin: 10px auto 0; padding: 0 16px; }
.msg { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; background: var(--accent-soft); }
.msg-error { background: var(--debt-soft); color: var(--debt); }

/* Карточки */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.card.empty { text-align: center; padding: 32px 16px; }
.login { margin-top: 10vh; }

/* Формы */
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=month], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.login label { margin-bottom: 14px; }
.login input { margin-top: 4px; }
.field { margin-bottom: 14px; }
.field.check label { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 1rem; }
.field .error { color: var(--debt); font-size: .85rem; margin-top: 4px; }
.has-error input, .has-error select { border-color: var(--debt); }
.amount-input { font-size: 2rem !important; font-weight: 600; text-align: center; padding: 14px !important; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.segmented { display: flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; min-height: 46px; margin-bottom: 12px; }
.field .segmented { margin-bottom: 0; }
.seg { flex: 1; margin: 0; position: relative; display: flex; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { flex: 1; display: grid; place-items: center; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: .95rem; padding: 6px; }
.seg input:checked + span { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg-debt input:checked + span { color: var(--debt); }
.seg-paid input:checked + span { color: var(--accent); }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 10px 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: var(--debt); border-color: var(--debt); color: #fff; }
.btn.danger-outline { color: var(--debt); border-color: var(--debt); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.small { min-height: 34px; padding: 6px 10px; font-size: .85rem; }
.btn.icon { min-width: 44px; padding: 0; font-size: 1.4rem; }
.btn.block { display: flex; width: 100%; margin: 12px 0; }
.btn:disabled { opacity: .6; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.actions .btn { flex: 1; }
.meta { margin: 16px 0 4px; }

/* Списки */
.list { list-style: none; margin: 0; padding: 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--card); }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; color: inherit; text-decoration: none; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.row-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.amount { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { font: inherit; font-size: .72rem; border: 0; border-radius: 20px; padding: 3px 9px; cursor: pointer; }
.badge-paid { background: var(--accent-soft); color: var(--accent); }
.badge-debt { background: var(--debt-soft); color: var(--debt); }
span.badge { cursor: default; }

.day { margin-bottom: 12px; border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.day-head { display: flex; justify-content: space-between; padding: 8px 16px; font-size: .85rem; color: var(--muted); background: var(--card); border-bottom: 1px solid var(--line); }
.day-head span:last-child { font-variant-numeric: tabular-nums; }

.project-switch { margin-bottom: 10px; }
.project-switch select { font-weight: 600; }
.monthbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.monthbar form, .monthbar input, .monthbar select { flex: 1; }
.monthpick input { text-align: center; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.summary.three > div:first-child { grid-column: 1 / -1; }
.summary > div { background: var(--card); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; min-width: 0; }
.summary b { font-size: 1.25rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }

.chips { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.chip { padding: 7px 14px; border-radius: 20px; background: var(--card); color: var(--muted); text-decoration: none; border: 1px solid var(--line); white-space: nowrap; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Дерево категорий */
.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree > li { padding: 6px 16px 10px; border-bottom: 1px solid var(--line); }
.tree ul { padding-left: 16px; }
.tree-row { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.inline-add { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.inline-add input, .inline-add select { min-height: 38px; padding: 7px 10px; flex: 1; min-width: 0; }
.inline-add.top { padding: 12px 16px; margin: 0; border-top: 1px solid var(--line); }
.share-actions { flex-direction: row; align-items: center; }
.share-actions select { min-height: 34px; padding: 4px 8px; width: auto; font-size: .85rem; }

/* Отчёт */
.report-filter .field { margin-bottom: 12px; }
.report-head { margin: 4px 4px 12px; }
.report-head h2 { margin: 0; }
.total-debt b { font-variant-numeric: tabular-nums; }
.chart-box { position: relative; margin-bottom: 12px; }
.chart-box.pie { height: 300px; }
.chart-box.bars { height: 260px; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tr.sub td { color: var(--muted); padding-left: 24px; font-size: .85rem; }
.table tfoot th { border-bottom: 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 8px; }

@media (min-width: 720px) {
  .expense-form { max-width: 520px; margin: 0 auto; }
}
