/* Компоненты оболочки и повторяющиеся блоки. Экраны из них собираются и
   своих цветов не заводят. */

/* ─────────────────────────── оболочка ─────────────────────────── */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: calc(var(--safe-top) + 14px) calc(var(--page-pad) + var(--safe-right)) 12px
    calc(var(--page-pad) + var(--safe-left));
  background: color-mix(in srgb, var(--bg-base) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--fast) var(--ease);
}

/* Полоса под шапкой появляется, только когда под неё что-то уехало. */
.app-header[data-scrolled="true"] {
  border-bottom-color: var(--line);
}

.app-header__title {
  flex: 1;
  min-width: 0;
  font-size: var(--size-title);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.app-header__actions {
  display: flex;
  gap: var(--gap-xs);
}

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 4px calc(var(--page-pad) + var(--safe-right))
    calc(var(--tabbar-height) + var(--safe-bottom) + 28px) calc(var(--page-pad) + var(--safe-left));
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.stack--tight {
  gap: var(--gap-sm);
}

.stack--loose {
  gap: var(--gap-lg);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
}

.row--between {
  justify-content: space-between;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap-sm);
}

/* ─────────────────────────── нижняя навигация ─────────────────────────── */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  gap: 2px;
  padding: 6px calc(8px + var(--safe-right)) calc(6px + var(--safe-bottom))
    calc(8px + var(--safe-left));
  background: color-mix(in srgb, var(--bg-base) 88%, transparent);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}

.tabbar__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: var(--tap);
  padding: 6px 2px;
  border-radius: var(--radius-control);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  transition: color var(--fast) var(--ease);
}

.tabbar__item[aria-current="page"] {
  color: var(--accent);
}

.tabbar__icon {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* «+» — самое частое действие, поэтому он центральный и приподнятый. */
.tabbar__add {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  margin: 0 auto 4px;
  border-radius: 20px;
  background: linear-gradient(160deg, var(--accent-strong), var(--accent));
  color: #fff;
  box-shadow: var(--shadow-raised);
  transition: transform var(--fast) var(--ease);
}

.tabbar__add:active {
  transform: scale(0.94);
}

.tabbar__add svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

/* ─────────────────────────── карточки ─────────────────────────── */

.card {
  padding: var(--gap-lg);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background-color: var(--bg-elevated);
  background-image: var(--card-sheen);
}

.card--flush {
  padding: 10px var(--gap);
}

/* Шапка карточки: подпись слева, счётчик справа. */
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-sm);
  padding: 6px 2px 10px;
}

.card__label {
  color: var(--text-muted);
  font-size: var(--size-caption);
  font-weight: 500;
  letter-spacing: 0.01em;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--gap-sm);
  margin: var(--gap-lg) 2px var(--gap-sm);
  font-size: var(--size-section);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.section-title:first-child {
  margin-top: 0;
}

.section-title__link {
  font-size: var(--size-caption);
  font-weight: 500;
  color: var(--text-muted);
}

/* ─────────────────────────── кнопки ─────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 20px;
  border-radius: var(--radius-control);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: var(--size-body);
  font-weight: 500;
  transition: transform var(--fast) var(--ease), opacity var(--fast) var(--ease),
    background-color var(--fast) var(--ease);
}

.btn:active {
  transform: scale(0.985);
}

.btn[disabled] {
  opacity: 0.45;
  pointer-events: none;
}

.btn--primary {
  background: linear-gradient(160deg, var(--accent-strong), var(--accent));
  border-color: transparent;
  color: #fff;
  font-weight: 600;
}

.btn--danger {
  color: var(--negative);
  border-color: color-mix(in srgb, var(--negative) 35%, transparent);
  background: var(--negative-soft);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn--block {
  width: 100%;
}

.btn--small {
  min-height: 38px;
  padding: 0 14px;
  font-size: var(--size-label);
}

/* Кнопка-иконка в шапке: 44×44 — минимум для пальца. */
.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-control);
  color: var(--text-muted);
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.icon-btn:hover {
  background: var(--line-soft);
  color: var(--text);
}

.icon-btn svg {
  width: 21px;
  height: 21px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ─────────────────────────── поля ввода ─────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field__label {
  color: var(--text-muted);
  font-size: var(--size-caption);
  font-weight: 500;
}

.field__error {
  color: var(--negative);
  font-size: var(--size-caption);
}

.input,
.select {
  width: 100%;
  min-height: var(--tap);
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--bg-sunken);
  color: var(--text);
  /* iOS увеличивает страницу, если поле мельче 16px. */
  font-size: 16px;
  transition: border-color var(--fast) var(--ease);
}

.input:focus,
.select:focus {
  border-color: var(--accent);
  outline: none;
}

.input[aria-invalid="true"],
.select[aria-invalid="true"] {
  border-color: var(--negative);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a97b4' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 18px;
}

.select option {
  background: var(--bg-elevated);
  color: var(--text);
}

textarea.input {
  min-height: 84px;
  padding: 12px 15px;
  resize: vertical;
  line-height: 1.4;
}

/* Сумма — главное поле формы, поэтому она крупная и по центру. */
.amount-input {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 0 4px;
}

.amount-input__sign {
  font-size: 30px;
  font-weight: 600;
  color: var(--text-muted);
}

.amount-input__value {
  width: 100%;
  max-width: 260px;
  border: none;
  background: transparent;
  text-align: center;
  font-size: 40px;
  font-weight: 600;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.amount-input__value:focus {
  outline: none;
}

.amount-input__value::placeholder {
  color: var(--line);
}

/* ─────────────────────── чипы и переключатели ─────────────────────── */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips--scroll {
  flex-wrap: nowrap;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chips--scroll::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: var(--bg-sunken);
  color: var(--text-muted);
  font-size: var(--size-label);
  font-weight: 500;
  transition: color var(--fast) var(--ease), border-color var(--fast) var(--ease),
    background-color var(--fast) var(--ease);
}

.chip[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: var(--accent-soft);
  color: var(--text);
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-control);
  background: var(--bg-sunken);
  border: 1px solid var(--line);
}

.segmented__option {
  min-height: 40px;
  border-radius: 11px;
  color: var(--text-muted);
  font-size: var(--size-label);
  font-weight: 600;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}

.segmented__option[aria-pressed="true"] {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-raised);
}

.segmented__option[data-tone="expense"][aria-pressed="true"] {
  color: var(--negative);
}

.segmented__option[data-tone="income"][aria-pressed="true"] {
  color: var(--positive);
}

/* ─────────────────────────── строки списков ─────────────────────────── */

.list {
  display: flex;
  flex-direction: column;
}

.list__row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 58px;
  padding: 10px 0;
  text-align: left;
  border-bottom: 1px solid var(--line-soft);
}

.list__row:last-child {
  border-bottom: none;
}

.list__row--tappable {
  width: calc(100% + 16px);
  margin-left: -8px;
  margin-right: -8px;
  padding-left: 8px;
  padding-right: 8px;
  border-radius: 12px;
  transition: background-color var(--fast) var(--ease);
}

.list__row--tappable:active {
  background: var(--line-soft);
}

/* Строки собраны из span-ов, чтобы кнопка оставалась кнопкой: без явного
   display они встали бы в одну строку и название слиплось бы с подписью. */
.list__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.list__title {
  display: block;
  font-size: var(--size-body);
  font-weight: 500;
}

.list__note {
  display: block;
  color: var(--text-muted);
  font-size: var(--size-caption);
}

.list__amount {
  flex: 0 0 auto;
  font-size: var(--size-amount);
  font-weight: 500;
  white-space: nowrap;
}

/* Значок категории или счёта: эмодзи из справочника, а не набор картинок. */
.badge {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 13px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  font-size: 19px;
  line-height: 1;
}

.badge--accent {
  background: var(--accent-soft);
  border-color: transparent;
}

.badge--positive {
  background: var(--positive-soft);
  border-color: transparent;
}

.badge--negative {
  background: var(--negative-soft);
  border-color: transparent;
}

/* ─────────────────────────── состояния ─────────────────────────── */

/* Скелетон повторяет форму будущей карточки, а не крутится в пустоте
   (docs/DESIGN.md §9). */
.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background: var(--line);
  opacity: 0.5;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.09), transparent);
  animation: skeleton-sweep 1.4s infinite;
}

@keyframes skeleton-sweep {
  100% {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
  }
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--gap-sm);
  padding: var(--gap-xl) var(--gap);
  text-align: center;
}

.empty__icon {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  border-radius: 22px;
  background: var(--accent-soft);
  font-size: 28px;
}

.empty__title {
  font-size: 19px;
  font-weight: 600;
}

.empty__text {
  max-width: 320px;
  color: var(--text-muted);
  font-size: var(--size-label);
}

.error-state {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  padding: var(--gap-lg);
  border: 1px solid color-mix(in srgb, var(--negative) 32%, transparent);
  border-radius: var(--radius-card);
  background: var(--negative-soft);
}

.error-state__title {
  font-weight: 600;
}

.error-state__text {
  color: var(--text-muted);
  font-size: var(--size-label);
}

/* Полоса состояния сети и очереди — заметная, но не пугающая, и всегда с
   действием, а не только с сообщением (docs/DESIGN.md §9). Цвет задаёт
   тон: жёлтый — без сети, синий — идёт отправка, красный — нужен человек. */
.offline-bar {
  position: sticky;
  top: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 8px) var(--page-pad) 8px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: var(--size-caption);
  font-weight: 500;
  border-bottom: 1px solid color-mix(in srgb, var(--warning) 28%, transparent);
}

.offline-bar[data-tone="accent"] {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-bottom-color: color-mix(in srgb, var(--accent) 28%, transparent);
}

.offline-bar[data-tone="error"] {
  background: var(--negative-soft);
  color: var(--negative);
  border-bottom-color: color-mix(in srgb, var(--negative) 28%, transparent);
}

.offline-bar__text {
  flex: 1;
  min-width: 0;
}

.offline-bar__action {
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid currentColor;
  color: inherit;
  font-size: var(--size-caption);
  font-weight: 600;
  /* Полоса тонкая, а нажимать по ней придётся пальцем. */
  min-height: 28px;
}

/* Операция, которая ещё не ушла на сервер: она настоящая, но не подтверждённая,
   и выглядеть как подтверждённая не должна. */
.pending-row {
  opacity: 0.92;
}

.pending-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 600;
}

.pending-badge[data-tone="error"] {
  background: var(--negative-soft);
  color: var(--negative);
}

/* Отметка времени у данных, показанных из снимка. */
.stale-note {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 16px);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(420px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-control);
  border: 1px solid var(--line);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-raised);
  font-size: var(--size-label);
  animation: toast-in var(--slow) var(--ease);
}

.toast[data-tone="error"] {
  border-color: color-mix(in srgb, var(--negative) 40%, transparent);
  color: var(--negative);
}

.toast[data-tone="success"] {
  border-color: color-mix(in srgb, var(--positive) 40%, transparent);
}

/* Сообщение с кнопкой: по нему можно нажать, значит host должен пропускать
   события — сам host их гасит, чтобы не мешать экрану под собой. */
.toast--actionable {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-sm);
  pointer-events: auto;
}

.toast__action {
  flex: none;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: var(--size-caption);
  font-weight: 600;
  min-height: 32px;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ─────────────────────────── модальный лист ─────────────────────────── */

.sheet-host {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
}

.sheet-host[data-open="true"] {
  display: block;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: var(--bg-overlay);
  animation: fade-in var(--fast) var(--ease);
}

.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  border-radius: 26px 26px 0 0;
  border-top: 1px solid var(--line);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sheet);
  animation: sheet-up var(--slow) var(--ease);
}

@media (min-width: 720px) {
  .sheet {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    width: min(520px, calc(100vw - 48px));
    transform: translate(-50%, -50%);
    border-radius: var(--radius-card);
    border: 1px solid var(--line);
    animation: fade-in var(--fast) var(--ease);
  }
}

.sheet__grip {
  width: 38px;
  height: 4px;
  margin: 10px auto 2px;
  border-radius: var(--radius-pill);
  background: var(--line);
}

.sheet__header {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  padding: 8px var(--gap-lg) 4px;
}

.sheet__title {
  flex: 1;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--gap) var(--gap-lg);
  -webkit-overflow-scrolling: touch;
}

.sheet__footer {
  display: flex;
  gap: var(--gap-sm);
  padding: var(--gap) var(--gap-lg) calc(var(--gap) + var(--safe-bottom));
  border-top: 1px solid var(--line-soft);
}

.sheet__footer .btn {
  flex: 1;
}

@keyframes sheet-up {
  from {
    transform: translateY(14%);
    opacity: 0.6;
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* Меню действий внутри листа: «Добавить», «Ещё». */
.menu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.menu__item {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 58px;
  padding: 10px 14px;
  border-radius: var(--radius-control);
  text-align: left;
  transition: background-color var(--fast) var(--ease);
}

.menu__item:active {
  background: var(--line-soft);
}

.menu__item[disabled] {
  opacity: 0.42;
  pointer-events: none;
}

.menu__icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 14px;
  background: var(--bg-sunken);
  font-size: 20px;
}

/* Название и пояснение — разными строками: у span по умолчанию inline, и без
   этого «Ввести вручную» слипалось с «Работает без сети и без AI». */
.menu__title {
  display: block;
  font-weight: 500;
}

.menu__note {
  display: block;
  color: var(--text-muted);
  font-size: var(--size-caption);
  line-height: 1.3;
}
