/* Тёмная премиум-тема (не зависит от темы Telegram, чтобы вид был стабильным). */
:root {
  --bg: #0d0e12;
  --surface: #16181f;
  --surface-2: #1e212a;
  --surface-3: #262a35;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: #f3f4f7;
  --muted: #8b93a3;
  --faint: #5b6373;

  --red: #ff5d5d;
  --red-soft: rgba(255, 93, 93, 0.14);
  --green: #35d18b;
  --green-soft: rgba(53, 209, 139, 0.14);
  --accent: #6d7bff;
  --accent-2: #8b6dff;
  --accent-soft: rgba(109, 123, 255, 0.16);

  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

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

html, body { background: var(--bg); }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
  padding-bottom: 84px;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* --- Верхняя панель --- */
#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 14px 16px 12px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(13, 14, 18, 0));
}
.rate { font-size: 12.5px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.currency-switch { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
.currency-switch button {
  border: none; background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s ease;
}
.currency-switch button.active { background: var(--accent); color: #fff; box-shadow: 0 2px 8px var(--accent-soft); }

/* --- Контент --- */
#content { padding: 8px 16px 16px; max-width: 640px; margin: 0 auto; }
.loader { text-align: center; color: var(--muted); padding: 48px 0; }

.section-title { font-size: 12px; color: var(--faint); margin: 22px 4px 10px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.hint-inline { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--faint); }

/* Переключатель периода */
.period-switch { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 12px; border: 1px solid var(--border); margin-bottom: 14px; }
.period-switch button { flex: 1; border: none; background: transparent; color: var(--muted); padding: 9px; border-radius: 9px; font-size: 13.5px; font-weight: 600; cursor: pointer; transition: all .15s; }
.period-switch button.active { background: var(--surface-3); color: var(--text); }

.tag { display: inline-block; font-size: 10px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 2px 6px; border-radius: 6px; vertical-align: middle; letter-spacing: .03em; }
.tag-credit { color: var(--red); background: var(--red-soft); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }

/* --- Герой: свободные деньги --- */
.hero {
  position: relative;
  background: radial-gradient(120% 140% at 100% 0%, rgba(109,123,255,0.18) 0%, rgba(139,109,255,0.06) 40%, transparent 70%), var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 20px 20px 22px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hero .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.hero-value { font-size: 38px; font-weight: 800; margin-top: 6px; letter-spacing: -1px; white-space: nowrap; }
.hero-sub { font-size: 13px; color: var(--muted); margin-top: 10px; display: flex; align-items: center; gap: 6px; }
.hero-sub b { color: var(--text); }

/* --- Плитки сумм --- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.tile-top { display: flex; align-items: center; justify-content: space-between; }
.tile .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.tile .value { font-size: 22px; font-weight: 800; margin-top: 8px; white-space: nowrap; letter-spacing: -0.5px; }
.value.expense { color: var(--red); }
.value.income { color: var(--green); }
.value.neutral { color: var(--text); }

.badge { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 15px; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.card-wide { position: relative; }
.card-wide .spark { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); opacity: .9; }

/* --- Разбивка по категориям --- */
.cat-row { margin-bottom: 14px; }
.cat-row:last-child { margin-bottom: 2px; }
.cat-row .cat-head { display: flex; justify-content: space-between; font-size: 14.5px; margin-bottom: 7px; }
.cat-row .cat-head b { font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: rgba(255,255,255,0.06); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 6px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

/* --- Список операций --- */
.tx { display: flex; align-items: center; gap: 12px; padding: 13px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px; cursor: pointer; transition: background .15s; }
.tx:active { background: var(--surface-2); }
.tx .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px; flex: 0 0 auto; background: var(--surface-2); }
.tx .left { flex: 1; min-width: 0; }
.tx .left .title { font-size: 15.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .left .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tx .amt.expense { color: var(--red); }
.tx .amt.income { color: var(--green); }
.tx .amt.transfer { color: var(--muted); }

/* --- Счета --- */
.acc { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.acc:last-child { border-bottom: none; }
.acc .ic { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); font-size: 17px; flex: 0 0 auto; }
.acc .nm { flex: 1; }
.acc .nm .sub { font-size: 12px; color: var(--muted); }
.acc .val { text-align: right; }
.acc .val b { font-variant-numeric: tabular-nums; }
.acc .val .sub { font-size: 12px; color: var(--muted); }

/* --- Цели --- */
.goal .goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.goal .goal-name { font-size: 18px; font-weight: 800; }
.goal .goal-target { color: var(--muted); font-size: 13.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.progress { height: 12px; background: rgba(255,255,255,0.06); border-radius: 8px; overflow: hidden; margin: 12px 0 7px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--green), #6de3b0); }
.goal .meta { font-size: 12.5px; color: var(--muted); }
.stage { display: flex; justify-content: space-between; font-size: 13.5px; padding: 8px 0; border-top: 1px dashed var(--border); font-variant-numeric: tabular-nums; }
.stage.done { color: var(--green); }
.stage.failed { color: var(--red); }
.chip-btn { display:inline-block; margin-top:12px; margin-right:8px; padding:9px 14px; border-radius:10px; border:1px solid var(--border); background:var(--surface-2); color:var(--text); font-size:13.5px; font-weight:600; cursor:pointer; }
.chip-btn.danger { color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 44px 16px; line-height: 1.5; }

/* --- FAB --- */
.fab {
  position: fixed; right: 18px; bottom: 92px; z-index: 20;
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
  font-size: 30px; line-height: 1; cursor: pointer;
  box-shadow: 0 6px 20px rgba(109,123,255,0.45);
}
.fab:active { transform: scale(0.95); }
.hidden { display: none !important; }

/* --- Нижние вкладки --- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 15;
  display: flex; background: rgba(16,17,22,0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabbar button {
  flex: 1; border: none; background: none; color: var(--faint);
  padding: 10px 0 12px; font-size: 11px; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: color .15s;
}
#tabbar button span { font-size: 21px; filter: grayscale(0.4); transition: filter .15s; }
#tabbar button.active { color: var(--accent); }
#tabbar button.active span { filter: grayscale(0); }

/* --- Модалка --- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 30; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--surface); width: 100%; max-width: 640px; border-radius: 22px 22px 0 0; padding: 22px 18px calc(22px + env(safe-area-inset-bottom)); max-height: 92vh; overflow-y: auto; border-top: 1px solid var(--border-strong); animation: slideup .22s ease; }
@keyframes slideup { from { transform: translateY(30px); } }
.modal h3 { margin: 0 0 4px; font-size: 20px; }
.modal .grab { width: 40px; height: 4px; background: var(--surface-3); border-radius: 3px; margin: -6px auto 14px; }
.modal label { display: block; font-size: 12.5px; color: var(--muted); margin: 14px 0 6px; font-weight: 600; }
.modal input, .modal select, .modal textarea {
  width: 100%; padding: 13px; border-radius: 11px; border: 1px solid var(--border-strong);
  background: var(--surface-2); color: var(--text); font-size: 16px; outline: none;
}
.modal input:focus, .modal select:focus { border-color: var(--accent); }
.type-toggle { display: flex; gap: 6px; margin-top: 4px; }
.type-toggle button { flex: 1; padding: 11px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer; }
.type-toggle button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.modal .actions { display: flex; gap: 10px; margin-top: 22px; }
.modal .actions button { flex: 1; padding: 14px; border-radius: 13px; border: none; font-size: 16px; font-weight: 700; cursor: pointer; }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.row2 { display: flex; gap: 10px; }
.row2 > div { flex: 1; }
