:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --in: #22c55e;
  --out: #ef4444;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(88px + var(--safe-b));
}

h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h2.section { margin: 22px 4px 10px; color: var(--muted); font-size: .9rem; text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.center { text-align: center; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}

/* Карточки */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

/* Формы */
label { display: block; margin-bottom: 12px; font-size: .85rem; color: var(--muted); }
input, select {
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text);
  font-size: 16px; /* >=16px чтобы iOS не зумил */
}
input:focus, select:focus { outline: none; border-color: var(--primary); }
input[type=color] { padding: 4px; height: 46px; }
input[type=radio] { width: auto; margin: 0 6px 0 0; }

.type-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.type-toggle label {
  flex: 1; margin: 0; padding: 12px; text-align: center;
  background: var(--surface-2); border-radius: 10px; color: var(--text);
  display: flex; align-items: center; justify-content: center;
}

.row { display: flex; gap: 10px; }
.grow { flex: 1; }
.w-icon { width: 78px; }
.w-color { width: 78px; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; border: none; border-radius: 10px; padding: 12px 16px;
  font-size: .95rem; font-weight: 600; cursor: pointer; color: var(--text);
  background: var(--surface-2);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-ghost { background: transparent; color: var(--muted); padding: 8px 10px; }
.btn-block { width: 100%; }
.btn-del { background: transparent; color: var(--muted); padding: 8px 10px; font-size: 1rem; }
.btn-del:hover { color: var(--out); }
.inline { display: inline; margin: 0; }

/* Сегменты периода */
.seg { display: flex; gap: 6px; background: var(--surface); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.seg a { flex: 1; text-align: center; padding: 10px; border-radius: 9px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .9rem; }
.seg a.on { background: var(--primary); color: #fff; }

/* Статистика */
.cards-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: .72rem; color: var(--muted); }
.stat-val { font-size: 1rem; font-weight: 700; }
.stat-in .stat-val { color: var(--in); }
.stat-out .stat-val { color: var(--out); }

/* Список транзакций */
.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx { display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 12px; padding: 12px; }
.tx-icon { width: 40px; height: 40px; flex: none; border-radius: 10px; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; }
.tx-main { flex: 1; min-width: 0; }
.tx-top { display: flex; justify-content: space-between; gap: 8px; }
.tx-cat { font-weight: 600; }
.tx-amt { font-weight: 700; white-space: nowrap; }
.tx-in .tx-amt { color: var(--in); }
.tx-out .tx-amt { color: var(--out); }
.tx-sub { font-size: .78rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.chip { background: var(--surface-2); padding: 1px 8px; border-radius: 20px; font-size: .72rem; }

/* Фильтры и форма добавления */
.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.filters select { margin: 0; font-size: .85rem; padding: 10px; }
.addform { display: none; }
.addform.open { display: block; }

/* Категории */
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.cat-item { display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 10px; padding: 10px 12px; }
.cat-ic { font-size: 1.2rem; }
.cat-name { flex: 1; font-weight: 600; font-size: .9rem; }

/* Нижняя навигация */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; background: var(--surface);
  border-top: 1px solid var(--surface-2);
  padding-bottom: var(--safe-b);
  z-index: 40;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 0; color: var(--muted); text-decoration: none; font-size: .7rem;
}
.tab.active { color: var(--primary); }
.tab-ic { font-size: 1.25rem; }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(78px + var(--safe-b));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 1.8rem;
  display: flex; align-items: center; justify-content: center;
  text-decoration: none; box-shadow: 0 6px 20px rgba(59,130,246,.45); z-index: 30;
}

/* Авторизация */
.auth { max-width: 380px; margin: 8vh auto 0; text-align: center; }
.auth-logo { font-size: 3rem; }
.auth h1 { margin: 8px 0 4px; }
.auth .card { margin-top: 20px; text-align: left; }
.alert { background: rgba(239,68,68,.15); color: #fca5a5; padding: 12px; border-radius: 10px; margin: 12px 0; font-size: .9rem; }

canvas { max-width: 100%; }
