/* Палитра намеренно спокойная: этот экран смотрят, когда волнуются о деньгах.
   Красного нет нигде — плохой месяц показывается словами, а не тревогой. */
:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --border: #e4e1da;
  --text: #1b1d20;
  --muted: #6d747e;
  --accent: #2f7d5f;
  --accent-soft: #e2efe9;
  --warm: #a06b3a;
  --warm-soft: #f5ebdf;
  --shadow: 0 1px 2px rgba(20, 22, 26, 0.05), 0 10px 30px rgba(20, 22, 26, 0.05);
  --radius: 16px;
  --radius-sm: 10px;

  /* Цвета графика проверены валидатором палитры и различимы при всех видах
     дальтонизма (ΔE 9.2 при дейтеранопии). Прежняя зелёно-коричневая пара давала
     ΔE 4.8 — человек с таким зрением не отличал доход от расхода.
     Зелёный светлее 3:1 к белому фону, поэтому точные суммы всегда показаны
     в строке над графиком, а не только по наведению. */
  --chart-in: #1baf7a;
  --chart-out: #eb6834;
  /* Кнопка необратимого действия. Не красная — приложение не пугает,
     но темнее --warm, чтобы белый текст читался (5.9:1 против 3.4:1). */
  --danger: #9c4221;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --chart-in: #199e70;
    --chart-out: #d95926;
    --danger: #b4531f;
    --bg: #131518;
    --surface: #1b1e22;
    --surface-2: #23272c;
    --border: #2d3238;
    --text: #e9e7e3;
    --muted: #98a0aa;
    --accent: #58b98f;
    --accent-soft: #1e3830;
    --warm: #c99a63;
    --warm-soft: #33291d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme='dark'] {
  --chart-in: #199e70;
  --chart-out: #d95926;
  --danger: #b4531f;
  --bg: #131518;
  --surface: #1b1e22;
  --surface-2: #23272c;
  --border: #2d3238;
  --text: #e9e7e3;
  --muted: #98a0aa;
  --accent: #58b98f;
  --accent-soft: #1e3830;
  --warm: #c99a63;
  --warm-soft: #33291d;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}

.page { max-width: 640px; margin: 0 auto; padding: 16px; }
.hidden { display: none !important; }

/* ── шапка ─────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 8px 0 20px;
}
.topbar__title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.topbar__actions { display: flex; align-items: center; gap: 4px; }

/* ── карточки ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 14px;
}
.card__title {
  font-size: 13px; font-weight: 600; letter-spacing: 0.02em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 14px;
}

/* ── главный блок ──────────────────────────────────────── */
.hero { text-align: center; padding: 28px 20px 24px; }
.hero__label { font-size: 15px; color: var(--muted); margin-bottom: 6px; }
.hero__amount {
  font-size: clamp(38px, 11vw, 54px); font-weight: 650;
  letter-spacing: -0.03em; line-height: 1.05; margin-bottom: 22px;
}
.hero__runway { font-size: 21px; font-weight: 600; margin-bottom: 4px; }
.hero__note + .hero__runway { margin-top: 18px; }
.hero__note { font-size: 14px; color: var(--muted); max-width: 34ch; margin: 0 auto; }

.runway-bar {
  height: 10px; border-radius: 99px; background: var(--surface-2);
  overflow: hidden; margin: 16px auto 10px; max-width: 320px;
}
.runway-bar__fill { height: 100%; border-radius: 99px; background: var(--accent); transition: width 0.4s ease; }

/* ── плитки ────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 10px; text-align: center;
  /* Без этого длинное слово распирает ячейку и страница едет вбок. */
  min-width: 0;
}
.tile__value { font-size: 19px; font-weight: 620; letter-spacing: -0.02em; }
.tile__label {
  font-size: 12px; color: var(--muted); margin-top: 4px; line-height: 1.3;
  overflow-wrap: anywhere; hyphens: auto;
}

/* ── копилки ───────────────────────────────────────────── */
.envelope { padding: 12px 0; border-bottom: 1px solid var(--border); }
.envelope:last-child { border-bottom: none; padding-bottom: 0; }
.envelope:first-child { padding-top: 0; }
.envelope__head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.envelope__name { font-weight: 550; }
.envelope__amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.envelope__target { color: var(--muted); font-weight: 400; }
.envelope__bar { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.envelope__fill { height: 100%; border-radius: 99px; background: var(--accent); }
.envelope--obligation .envelope__fill { background: var(--warm); }
.envelope__hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

/*/* ── списки ────────────────────────────────────────────── */
.row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; padding-bottom: 0; }
.row:first-child { padding-top: 0; }
.row__main { min-width: 0; }
.row__title { font-weight: 500; overflow-wrap: anywhere; }
.row__sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.row__amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 550; }
.row__amount--in { color: var(--accent); }
.row__amount--out { color: var(--warm); }

.empty { color: var(--muted); font-size: 14px; text-align: center; padding: 8px 0; }

/* ── кнопки ────────────────────────────────────────────── */
.button {
  font: inherit; font-weight: 550; cursor: pointer;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  padding: 11px 16px; min-height: 44px; transition: background 0.15s ease, border-color 0.15s ease;
}
.button:hover { background: var(--surface-2); }
.button:disabled { opacity: 0.55; cursor: default; }
.button--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button--primary:hover { background: var(--accent); filter: brightness(1.06); }
.button--ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 10px 12px; }
.button--ghost:hover { background: var(--surface-2); color: var(--text); }
.button--wide { width: 100%; }
.button--danger { color: var(--warm); }

.fab {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  z-index: 20; padding: 14px 28px; font-size: 16px; font-weight: 600;
  border: none; border-radius: 99px; background: var(--accent); color: #fff;
  cursor: pointer; box-shadow: 0 6px 24px rgba(47, 125, 95, 0.35);
}
.fab:hover { filter: brightness(1.06); }

/* ── формы ─────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field__label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field__input, .field__select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.field__input:focus, .field__select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field__input--amount { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; }
.field__hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.tab {
  font: inherit; font-size: 14px; cursor: pointer; padding: 11px 15px;
  min-height: 44px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--muted);
}
.tab[aria-selected='true'] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }

.notice {
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: 14px;
  background: var(--warm-soft); color: var(--warm); margin-bottom: 14px;
}
.notice--calm { background: var(--accent-soft); color: var(--accent); }

/* ── шторка ────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(16, 18, 21, 0.45); backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 640px;
  border-radius: 22px 22px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: 92vh; overflow-y: auto; box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.2);
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up { from { transform: translateY(14px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } .runway-bar__fill { transition: none; } }
.sheet__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.sheet__title { font-size: 18px; font-weight: 620; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 22px; } }


code {
  background: var(--surface-2); padding: 2px 6px; border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}

/* Раскладки, которые раньше жили в атрибуте style — его режет строгий CSP. */
.row__actions { display: flex; align-items: center; gap: 8px; }
.row__remove {
  color: var(--muted); font-size: 18px; line-height: 1;
  min-width: 44px; min-height: 44px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.row__remove:hover { color: var(--warm); }
.sheet__intro { margin: 0 0 16px; }

.row--muted .row__title,
.row--muted .row__amount { color: var(--muted); font-weight: 500; }

.checkbox {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted); cursor: pointer;
  padding: 6px 0 10px;
}
.checkbox__box { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; margin: 0; }

.card__add {
  margin-top: 14px;
  border-style: dashed;
  color: var(--muted);
  font-weight: 500;
}
.card__add:hover { color: var(--text); border-style: solid; }

/* ── график по месяцам ─────────────────────────────────── */
.chart__key { width: 9px; height: 9px; border-radius: 3px; flex: none; align-self: center; }
.chart__key--in { background: var(--chart-in); }
.chart__key--out { background: var(--chart-out); }

.chart { --chart-height: 132px; position: relative; padding-left: 44px; }
.chart__scale { position: absolute; left: 44px; right: 0; top: 0; height: var(--chart-height); }
.chart__gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); }
.chart__tick {
  position: absolute; right: calc(100% + 8px); transform: translateY(-50%);
  font-size: 11px; color: var(--muted); white-space: nowrap;
}

.chart__plot { position: relative; display: flex; align-items: flex-end; gap: 2px; }
.chart__month {
  flex: 1 1 0; min-width: 0; border-radius: 6px; padding-top: 4px;
  transition: background 0.12s ease;
}
.chart__month:hover, .chart__month:focus-visible { background: var(--surface-2); outline: none; }
.chart__month--current .chart__month-label { color: var(--text); font-weight: 600; }

/* Столбцы тонкие и с зазором: разделяет их фон, а не обводка. */
.chart__bars { height: var(--chart-height); display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.chart__bar { flex: 1 1 0; max-width: 13px; border-radius: 4px 4px 0 0; }
.chart__bar--in { background: var(--chart-in); }
.chart__bar--out { background: var(--chart-out); }

.chart__month-label {
  text-align: center; font-size: 11px; color: var(--muted);
  padding: 6px 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) { .chart__month { transition: none; } }

/* ── страница входа ────────────────────────────────────── */
/* Фон один и тот же в обеих темах — он фирменный. Текст на нём всегда тёмный:
   фон светлый, и кремовые буквы давали бы контраст 1,4:1, то есть нечитаемо.
   Тёмно-коричневый даёт 5,2:1 на самом светлом участке. */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 26px; padding: 36px 16px calc(36px + env(safe-area-inset-bottom));
  /* Узкая версия — обрезанная левая полоса исходника: на вертикальном экране
     свинки оказываются над карточкой и под ней, а не уезжают за кадр. */
  background-image: url('/auth-bg-narrow.jpg');
  background-size: cover;
  background-position: center;
  background-color: #f4998f;
}
@media (min-width: 700px) {
  .login { background-image: url('/auth-bg.jpg'); }
}

.login__brand { text-align: center; max-width: 330px; }
/* Скругление у плитки логотипа своё, поэтому здесь радиус лишь чуть
   подрезает края, а не рисует вторую рамку поверх первой. */
/* Плитка розовая и фон розовый, поэтому край очерчиваем сами: тонкая светлая
   линия по контуру плюс плотная тень. Белую подложку не возвращаем — именно
   от неё и надо было избавиться. */
.login__logo {
  width: 124px; height: 124px; border-radius: 28px; display: block; margin: 0 auto;
  box-shadow:
    0 0 0 1.5px rgba(255, 255, 255, 0.55),
    0 6px 14px rgba(120, 45, 30, 0.22),
    0 18px 40px rgba(120, 45, 30, 0.28);
}
.login__title {
  color: #3d2117; font-size: 22px; font-weight: 700;
  letter-spacing: -0.01em; margin: 20px 0 6px;
}
.login__subtitle { color: #5a2b1e; font-size: 14px; margin: 0; line-height: 1.45; }
.login__card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 22px 20px;
  box-shadow: 0 18px 44px rgba(90, 43, 30, 0.28);
}
.login__card .tabs { margin-bottom: 20px; }
/* Кнопка «Записать» на экране входа не нужна — убираем её отступ снизу. */
body.is-auth { padding-bottom: 0; }

/* Заголовок, месяц и легенда-читалка над графиком */
.chart__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 10px; }
.chart__head .card__title { margin: 0; }
.chart__month-current { font-size: 13px; color: var(--muted); }

.chart__readout { display: flex; flex-wrap: wrap; gap: 4px 22px; margin-bottom: 16px; }
.chart__series { display: inline-flex; align-items: baseline; gap: 7px; font-size: 13px; }
.chart__series-label { color: var(--muted); }
.chart__series-value { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

/* ── узкие экраны ──────────────────────────────────────── */
@media (max-width: 360px) {
  .page { padding: 12px; }
  .card { padding: 16px 14px; }
  .tile__value { font-size: 17px; }
  .tile__label { font-size: 11px; }
  .hero { padding: 24px 14px 20px; }
  .topbar__actions .button { padding: 10px 8px; }
}

/* В альбомной ориентации на телефоне шторка не должна занимать весь экран. */
@media (max-height: 480px) {
  .sheet { max-height: 96vh; padding-top: 16px; }
  .login { padding-top: 20px; padding-bottom: 20px; }
  .login__logo { width: 76px; height: 76px; border-radius: 18px; }
  .login__title { font-size: 19px; margin-top: 12px; }
}

/* ── настройки ─────────────────────────────────────────── */
/* Разделы отделены фоном и рамкой, а формы добавления спрятаны за кнопкой:
   без этого всё шло сплошным полотном из пяти форм подряд. */
.settings { display: flex; flex-direction: column; gap: 14px; }

.settings-section {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); padding: 16px 14px;
}
.settings-section__title {
  margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; color: var(--text);
}
.settings-section__hint { margin: 3px 0 0; font-size: 12.5px; color: var(--muted); }
.settings-section__body { margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }

/* Строки внутри раздела лежат на «бумаге», чтобы отделяться от фона раздела. */
.settings-section__body > div:not(.disclosure):not(:empty),
.settings-section__body > form {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.settings-section__body > .empty { margin: 0; }

.settings-row + .settings-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.settings-row .row { border-bottom: none; padding: 0; }
.settings-row__note { font-size: 12px; color: var(--muted); margin-top: 4px; }
.settings-people .row + .row { border-top: 1px solid var(--border); }

/* Поле и кнопка стоят в одном ряду и выровнены по нижнему краю поля,
   а подсказка уходит отдельной строкой под ними: иначе кнопка вставала
   вровень с подсказкой и висела в воздухе. */
.settings-inline__row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.settings-inline__row .field { flex: 1 1 170px; margin-bottom: 0; }
.settings-inline__row .button { flex: none; }
.settings-inline .field__hint { margin-top: 8px; }

.disclosure { display: flex; flex-direction: column; gap: 12px; }
.disclosure__body > form { display: block; }
.disclosure .card__add { margin-top: 0; }

/* ── подтверждение необратимых действий ────────────────── */
/* Слой выше шторки: подтверждение открывается поверх настроек,
   а не вместо них — иначе человек терял бы контекст. */
.confirm-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(16, 18, 21, 0.55); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.confirm {
  background: var(--surface); border-radius: 18px; padding: 22px 20px;
  width: 100%; max-width: 360px; box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}
.confirm__title { font-size: 17px; font-weight: 650; margin-bottom: 8px; }
.confirm__message { font-size: 14px; color: var(--muted); margin: 0 0 16px; line-height: 1.45; }
.confirm__actions { display: flex; gap: 10px; margin-top: 4px; }
.confirm__actions .button { flex: 1 1 0; }

.button--danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.button--danger-solid:hover { filter: brightness(1.08); background: var(--danger); }
.button--danger-solid:disabled { opacity: 0.45; }
