/* Стиль iOS: системные цвета Apple, сгруппированные списки, крупные заголовки.
   Тёмная тема включается по Telegram (класс html.dark) или по настройке системы. */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card2: #f2f2f7;
  --text: #000000;
  --hint: #8e8e93;
  --hint2: rgba(60, 60, 67, .3);
  --sep: rgba(60, 60, 67, .2);
  --fill: rgba(118, 118, 128, .12);
  --blue: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --yellow: #ffcc00;
  --purple: #af52de;
  --indigo: #5856d6;
  --teal: #30b0c7;
  --pink: #ff2d55;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);

  /* имена, которые используют модули */
  --accent: var(--blue);
  --accent-text: #fff;
  --link: var(--blue);
  --income: var(--green);
  --danger: var(--red);
  --soft: var(--fill);

  --radius: 12px;
  --tabs-h: 50px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, "Segoe UI", Roboto, sans-serif;
  font-synthesis: none;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #000000; --card: #1c1c1e; --card2: #2c2c2e; --text: #ffffff; --hint: #8e8e93;
    --hint2: rgba(235, 235, 245, .3); --sep: rgba(84, 84, 88, .6); --fill: rgba(118, 118, 128, .24);
    --blue: #0a84ff; --green: #30d158; --red: #ff453a; --orange: #ff9f0a; --yellow: #ffd60a;
    --purple: #bf5af2; --indigo: #5e5ce6; --teal: #40c8e0; --pink: #ff375f; --shadow: none;
    color-scheme: dark;
  }
}
html.dark {
  --bg: #000000; --card: #1c1c1e; --card2: #2c2c2e; --text: #ffffff; --hint: #8e8e93;
  --hint2: rgba(235, 235, 245, .3); --sep: rgba(84, 84, 88, .6); --fill: rgba(118, 118, 128, .24);
  --blue: #0a84ff; --green: #30d158; --red: #ff453a; --orange: #ff9f0a; --yellow: #ffd60a;
  --purple: #bf5af2; --indigo: #5e5ce6; --teal: #40c8e0; --pink: #ff375f; --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.29 var(--font);
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { min-height: 100vh; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; letter-spacing: inherit; }
input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
svg { display: block; }

.num { font-variant-numeric: tabular-nums; }
.hint { color: var(--hint); }
.income { color: var(--income); }
.danger { color: var(--danger); }

main {
  padding: 0 16px calc(var(--tabs-h) + var(--safe-b) + 90px);
  max-width: 640px;
  margin: 0 auto;
}
.view { display: none; animation: fade .2s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------------------------------------------------------------- блоки */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--hint);
  margin: 24px 16px 7px;
}
.section-title.big {
  text-transform: none;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.02em;
  margin: 26px 4px 8px;
}
.section-title button { text-transform: none; color: var(--link); font-size: 15px; letter-spacing: -.01em; }
.footnote { font-size: 13px; color: var(--hint); margin: 7px 16px 0; line-height: 1.35; }

.list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow); }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 16px;
  width: 100%;
  text-align: left;
  position: relative;
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0;
  left: 60px;
  right: 0;
  border-top: .5px solid var(--sep);
}
.row.plain + .row.plain::before, .list.plain .row + .row::before { left: 16px; }
button.row:active, .row[role="button"]:active { background: var(--fill); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.row-end { text-align: right; flex-shrink: 0; color: var(--text); }
.row-end.hint { color: var(--hint); }
.chev { width: 8px; height: 13px; flex-shrink: 0; fill: none; stroke: var(--hint2); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* иконка-плитка как в «Настройках» iOS */
.ico {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 17px;
  line-height: 1;
  flex-shrink: 0;
  background: var(--c, var(--hint));
  color: #fff;
}
.ico.lg { width: 44px; height: 44px; border-radius: 11px; font-size: 23px; }
.ico.round { border-radius: 50%; }

/* ---------------------------------------------------------------- кнопки */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 50px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  background: var(--accent);
  color: var(--accent-text);
  transition: opacity .15s;
}
.btn:active { opacity: .7; }
.btn.secondary { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.btn.tinted-green { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.btn.gray { background: var(--fill); color: var(--text); }
.btn.ghost { background: none; color: var(--link); font-weight: 400; }
.btn.danger-btn { background: none; color: var(--danger); font-weight: 400; }
.btn:disabled { opacity: .4; }
.btn.small { min-height: 34px; width: auto; padding: 0 14px; font-size: 15px; border-radius: 999px; }
.link-btn { color: var(--link); font-size: 17px; }

.add-row { color: var(--link); }
.add-row .ico { background: none; color: var(--link); font-size: 26px; font-weight: 300; }

.empty { text-align: center; padding: 36px 24px; color: var(--hint); font-size: 15px; }
.empty img { width: 110px; height: 110px; margin: 0 auto 12px; opacity: .9; }
.empty b { display: block; color: var(--text); font-size: 20px; font-weight: 600; margin-bottom: 6px; letter-spacing: -.02em; }

.loading { display: none; justify-content: center; padding: 120px 0; }
.loading.show { display: flex; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--fill); border-top-color: var(--hint);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fatal { text-align: center; padding: 120px 24px; }
.fatal b { display: block; font-size: 20px; margin-bottom: 8px; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  transform: translate(-50%, -20px);
  background: color-mix(in srgb, var(--card) 80%, transparent);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--text);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .15);
  opacity: 0;
  pointer-events: none;
  transition: .25s cubic-bezier(.2, .8, .2, 1);
  z-index: 100;
  max-width: calc(100% - 32px);
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* сегментированный переключатель iOS */
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 0; position: relative; }
.seg button {
  flex: 1;
  padding: 6px 4px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: background .2s;
}
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 3px 1px rgba(0, 0, 0, .04); }
html.dark .seg button.on { background: #636366; }

/* переключатель iOS */
.switch {
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: var(--fill);
  position: relative;
  flex-shrink: 0;
  transition: background .25s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 3px 1px rgba(0, 0, 0, .06);
  transition: transform .25s cubic-bezier(.2, .8, .2, 1);
}
.switch.on { background: var(--green); }
.switch.on::after { transform: translateX(20px); }

.bar { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--c, var(--accent)); transition: width .4s ease; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: color-mix(in srgb, var(--c, var(--blue)) 15%, transparent);
  color: var(--c, var(--blue));
}
