:root {
  --bg: #f4f6fb; --card: #fff; --fg: #1c2233; --muted: #6b7489; --border: #e3e7f0;
  --accent: #4f7cff; --accent-soft: #e8eeff; --green: #1f9d63; --red: #e0464e; --orange: #e98a15;
  --radius: 14px; --shadow: 0 1px 3px rgba(20, 30, 60, .06), 0 4px 14px rgba(20, 30, 60, .05);
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151d; --card: #1b1f2a; --fg: #e8ebf3; --muted: #8b93a7; --border: #2a3040;
    --accent: #6d93ff; --accent-soft: #232c45; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- каркас ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 58px; }
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 8px 14px; border-radius: 10px; color: var(--muted);
  display: flex; gap: 6px; align-items: center; font-weight: 500; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }
main { max-width: 980px; margin: 0 auto; padding: 20px 16px 40px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

@media (max-width: 720px) {
  .topbar { position: static; height: 52px; }
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; background: var(--card);
    border-top: 1px solid var(--border); height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); justify-content: space-around; gap: 0; }
  .tabs button { flex-direction: column; gap: 0; font-size: 11px; padding: 6px 2px; flex: 1; border-radius: 0; background: none !important; }
  .tabs button .ico { font-size: 21px; filter: grayscale(1); opacity: .6; }
  .tabs button.active .ico { filter: none; opacity: 1; }
  main { padding: 14px 12px calc(var(--nav-h) + 30px + env(safe-area-inset-bottom)); }
  /* iOS Safari приближает страницу при фокусе на поле со шрифтом < 16px */
  input, select, textarea { font-size: 16px !important; }
}

/* ---------- общие элементы ---------- */
h1 { font-size: 24px; margin: 4px 0 16px; }
h2 { font-size: 17px; margin: 0 0 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.grid > .card + .card { margin-top: 0; }
.empty { color: var(--muted); text-align: center; padding: 18px 8px; font-size: 14px; }

.btn { border: 1px solid var(--border); background: var(--card); padding: 9px 15px; border-radius: 10px;
  font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; }
.icon-btn { border: 0; background: none; font-size: 20px; padding: 4px 10px; border-radius: 8px; color: var(--muted); }
.icon-btn:hover { background: var(--accent-soft); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip { border: 1px solid var(--border); background: var(--card); border-radius: 20px; padding: 6px 13px;
  font-size: 13px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill { font-size: 11px; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.avatar { width: 30px; height: 30px; border-radius: 50%; color: #fff; display: inline-flex; align-items: center;
  justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.avatar.lg { width: 46px; height: 46px; font-size: 19px; }
.avatar.none { background: var(--border); color: var(--muted); }

/* ---------- списки ---------- */
.list { display: flex; flex-direction: column; }
.item { display: flex; align-items: center; gap: 12px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.item:last-child { border-bottom: 0; }
.item .title { font-weight: 500; overflow-wrap: anywhere; }
.item .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 1px; }
.clickable { cursor: pointer; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border); background: none; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center; font-size: 13px; color: #fff; padding: 0; }
.check:hover { border-color: var(--green); }
.task.done .check { background: var(--green); border-color: var(--green); }
.task.done .title { text-decoration: line-through; color: var(--muted); }
.due.overdue { color: var(--red); font-weight: 600; }
.due.today { color: var(--orange); font-weight: 600; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  font-weight: 700; margin: 16px 0 2px; }
.group-title:first-child { margin-top: 0; }
.date-badge { width: 46px; text-align: center; flex-shrink: 0; border-radius: 10px; background: var(--accent-soft);
  color: var(--accent); padding: 4px 0; line-height: 1.1; }
.date-badge b { display: block; font-size: 18px; }
.date-badge span { font-size: 11px; }
.date-badge.bday { background: #ffeef3; color: #d63d72; }
@media (prefers-color-scheme: dark) { .date-badge.bday { background: #3d2230; color: #ff86ad; } }

/* ---------- статистика ---------- */
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; margin-top: 2px; white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--red); }
@media (max-width: 520px) { .grid-3 { grid-template-columns: 1fr 1fr; } .grid-3 > :last-child { grid-column: span 2; } .stat .value { font-size: 19px; } }

.bar { height: 8px; border-radius: 5px; background: var(--border); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.bar.over > i { background: var(--red); }
.bar.warn > i { background: var(--orange); }

.trend { display: flex; align-items: flex-end; gap: 10px; height: 140px; padding-top: 10px; }
.trend .col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; gap: 6px; }
.trend .bars { display: flex; gap: 3px; align-items: flex-end; flex: 1; width: 100%; justify-content: center; }
.trend .bars i { width: 40%; max-width: 18px; border-radius: 4px 4px 0 0; min-height: 2px; }
.trend .inc { background: var(--green); }
.trend .exp { background: var(--red); opacity: .85; }
.trend .lbl { font-size: 11px; color: var(--muted); }
.trend .col.cur .lbl { color: var(--fg); font-weight: 700; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav .name { font-weight: 700; font-size: 18px; min-width: 150px; text-align: center; text-transform: capitalize; }

/* ---------- календарь ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border);
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal .dow { background: var(--card); text-align: center; font-size: 12px; color: var(--muted); padding: 6px 0; font-weight: 600; }
.cal .day { background: var(--card); min-height: 92px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cal .day.other { background: var(--bg); }
.cal .day.other .num { opacity: .45; }
.cal .day.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.cal .num { font-size: 13px; font-weight: 600; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border-radius: 50%; }
.cal .day.today .num { background: var(--accent); color: #fff; }
.cal .ev { font-size: 11px; line-height: 1.3; padding: 1px 5px; border-radius: 4px; background: var(--accent-soft); color: var(--accent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .ev.bday { background: #ffeef3; color: #d63d72; }
.cal .ev.task { background: none; color: var(--muted); padding-left: 2px; }
.cal .more { font-size: 11px; color: var(--muted); padding-left: 4px; }
@media (prefers-color-scheme: dark) { .cal .ev.bday { background: #3d2230; color: #ff86ad; } }
@media (max-width: 720px) {
  .cal .day { min-height: 54px; align-items: center; }
  .cal .ev, .cal .more { display: none; }
  .cal .dots { display: flex !important; gap: 3px; }
}
.cal .dots { display: none; }
.cal .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.cal .dots i.bday { background: #d63d72; }
.cal .dots i.task { background: var(--muted); }

/* ---------- формы и модалка ---------- */
dialog { border: 0; padding: 0; border-radius: 18px; width: min(460px, calc(100vw - 24px)); max-height: calc(100vh - 40px);
  background: var(--card); color: var(--fg); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(15, 20, 35, .45); }
@media (max-width: 520px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; }
}
#modal-form { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { border: 1px solid var(--border); background: var(--bg); border-radius: 10px;
  padding: 10px 12px; width: 100%; outline: none; min-height: 42px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: vertical; min-height: 70px; }
.field input[type=color] { padding: 3px; height: 42px; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; }
.field.inline input { width: auto; min-height: 0; }
.field .hint { font-size: 12px; color: var(--muted); }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: flex; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg label { flex: 1; text-align: center; padding: 7px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--card); box-shadow: var(--shadow); color: var(--accent); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modal-actions .spacer { flex: 1; }
.err { color: var(--red); font-size: 13px; min-height: 0; }
.amount-input { font-size: 26px !important; font-weight: 700; text-align: center; }

/* ---------- вход ---------- */
.auth { max-width: 380px; margin: 8vh auto 0; }
.auth .logo { font-size: 48px; text-align: center; }
.auth h1 { text-align: center; margin-bottom: 4px; }
.auth p { text-align: center; margin-top: 0; }
.auth form { display: flex; flex-direction: column; gap: 14px; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px); transform: translateX(-50%) translateY(20px);
  background: #1c2233; color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 14px; opacity: 0;
  pointer-events: none; transition: .25s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.error { background: var(--red); }

.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); width: 56px; height: 56px;
  border-radius: 50%; background: var(--accent); color: #fff; border: 0; font-size: 30px; line-height: 1;
  box-shadow: 0 6px 20px rgba(79, 124, 255, .45); display: none; z-index: 9; }
@media (max-width: 720px) { .fab { display: block; } .desk-only { display: none !important; } }
