/* Тёмная схема поверх переменных темы Telegram: приложение должно выглядеть
   продолжением мессенджера, а не чужой страницей внутри него. */
:root {
  color-scheme: dark;
  --bg: var(--tg-theme-bg-color, #17181c);
  --surface: var(--tg-theme-secondary-bg-color, #212329);
  --text: var(--tg-theme-text-color, #f2f3f5);
  --hint: var(--tg-theme-hint-color, #8b9099);
  --line: rgba(140, 145, 155, .16);
  --accent: #3ec9c0;
  --up: #ff6b6b;      /* трат стало больше */
  --down: #35c759;    /* трат стало меньше */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  margin: 0;
  padding: 0 0 calc(24px + var(--safe-bottom));
  font: 15px/1.45 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: contain;   /* чтобы прокрутка не тянула само приложение */
}

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; }

/* --- график периода --- */
.chart {
  padding: calc(12px + var(--safe-top)) 16px 8px;
  /* pan-y разрешает браузеру вертикальную прокрутку, а горизонталь оставляет нам.
     Само по себе этого мало: подтягивание страницы гасится в touchmove, где мы
     фиксируем направление жеста и отменяем прокрутку для своих движений. */
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;      /* долгое нажатие не зовёт системное меню */
}

.chart__period {
  display: block;
  margin: 0 auto;
  color: var(--hint);
  font-size: 14px;
}
.chart__period::after { content: " ⌄"; }

.chart__amount {
  text-align: center;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.chart__delta {
  text-align: center;
  font-size: 13.5px;
  color: var(--hint);
  min-height: 20px;
}
.chart__delta.is-up { color: var(--up); }
.chart__delta.is-down { color: var(--down); }

.chart__bars { display: block; width: 100%; height: 150px; margin-top: 14px; }
.chart__bar { fill: var(--accent); transition: opacity .12s ease; }
.chart__bar.is-empty { fill: var(--hint); opacity: .18; }
.chart__bar.is-dimmed { opacity: .28; }
.chart__bar.is-active { fill: #fff; opacity: 1; }
.chart__avg { stroke: var(--hint); stroke-width: .6; stroke-dasharray: 2 2; opacity: .7; }

.chart__axis { position: relative; height: 16px; margin-top: 2px; }
.chart__tick {
  position: absolute;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

/* --- чипы фильтров --- */
.chips {
  display: flex;
  gap: 8px;
  padding: 8px 16px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 60vw;
  padding: 8px 15px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--hint);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.chip__label { overflow: hidden; text-overflow: ellipsis; }
.chip__x {
  flex: 0 0 auto;
  /* Отступы делают крестик пальцем попадаемым, не увеличивая сам чип. */
  margin: -8px -7px -8px 0;
  padding: 8px 9px 8px 2px;
  font-size: 11px;
  opacity: .65;
}
.chip.is-active { background: var(--text); color: var(--bg); }

/* --- лента операций --- */
.feed { padding: 0 16px; }

.feed__day {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 4px 8px;
  font-size: 13px;
  color: var(--hint);
  font-variant-numeric: tabular-nums;
}

.op {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 14px;
  background: var(--surface);
  text-align: left;
}
.op + .op { margin-top: 2px; }
.op:active { opacity: .6; }

.op__icon {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 1.5px solid var(--line);
  font-size: 17px;
}

.op__text {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.op__sum {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.op__sum.is-income { color: var(--down); }

.feed__note {
  padding: 40px 16px;
  text-align: center;
  color: var(--hint);
  font-size: 14px;
}

.feed__sentinel { height: 1px; }

/* --- шторки --- */
.sheet__backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  background: rgba(0, 0, 0, 0);
  transition: background .2s ease;
}
.sheet__backdrop.is-open { background: rgba(0, 0, 0, .5); }

.sheet {
  width: 100%;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  transform: translateY(100%);
  transition: transform .22s cubic-bezier(.32, .72, 0, 1);
}
.is-open .sheet { transform: translateY(0); }

.sheet__grip {
  width: 36px; height: 4px;
  margin: 0 auto 10px;
  border-radius: 2px;
  background: var(--hint);
  opacity: .4;
}

.sheet__title {
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  padding-bottom: 10px;
}

.sheet__body { overflow-y: auto; -webkit-overflow-scrolling: touch; }

.sheet__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 14px 4px;
  text-align: left;
  font-size: 16px;
}
.sheet__row + .sheet__row { border-top: 1px solid var(--line); }
.sheet__row:active { opacity: .6; }
.sheet__row.is-current { color: var(--accent); }
.sheet__check { color: var(--accent); }

.sheet__line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 4px;
}

.sheet__field { position: relative; flex: 1 1 auto; min-width: 0; }

.sheet__input {
  width: 100%;
  padding: 12px 36px 12px 14px;   /* справа место под крестик */
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;          /* меньше 16px — iOS зумит страницу при фокусе */
  -webkit-appearance: none;
  appearance: none;
  outline: none;            /* системная синяя рамка чужая этой теме */
}
.sheet__input:focus { border-color: var(--accent); }
.sheet__input::placeholder { color: var(--hint); }

.sheet__clear {
  position: absolute;
  top: 50%; right: 7px;
  transform: translateY(-50%);
  width: 24px; height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--hint);
  font-size: 12px;
}
.sheet__clear[hidden] { display: none; }
.sheet__clear:active { opacity: .6; }

.sheet__submit {
  flex: 0 0 auto;
  padding: 13px 18px;
  border-radius: 12px;
  background: var(--accent);
  color: #0d1013;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
}
.sheet__submit:active { opacity: .8; }
