/* ============================================================
   Семейный бюджет — тёмная тема, mobile-first, макс. 520px
   ============================================================ */

:root {
  /* Фоны */
  --bg-0: #0f0f11;
  --bg-1: #17171a;
  --bg-2: #1e1e22;
  --bg-3: #26262b;

  /* Текст */
  --fg-0: #f0f0f0;
  --fg-1: #8a8a94;
  --fg-2: #555560;

  /* Смысловые цвета */
  --income:  #2dd98a;
  --expense: #ff5b5b;
  --blue:    #5b9fff;
  --yellow:  #ffb347;
  --pink:    #ff7eb3;
  --teal:    #3de8d0;

  --line: rgba(255, 255, 255, 0.07);
  --line-strong: rgba(255, 255, 255, 0.13);

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;

  --shell: 520px;
  --tabbar-h: 62px;

  --font: 'Geologica', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--fg-0);
  font-family: var(--font);
  font-weight: 400;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button { cursor: pointer; border: none; background: none; }
[hidden] { display: none !important; }

.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------ загрузка */

.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg-0);
  z-index: 100;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--bg-3);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------ вход */

.auth {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth__card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}

.auth__logo {
  width: 68px;
  height: 68px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  font-size: 30px;
  border-radius: 22px;
  background: linear-gradient(145deg, var(--teal), var(--blue));
  color: var(--bg-0);
  font-weight: 600;
}

.auth__title { margin: 0 0 6px; font-size: 24px; font-weight: 600; }
.auth__sub { margin: 0 0 28px; color: var(--fg-1); font-size: 14px; }
.auth__error {
  margin-top: 16px;
  color: var(--expense);
  font-size: 13px;
  line-height: 1.5;
}

/* ------------------------------------------------ каркас */

.app {
  max-width: var(--shell);
  margin: 0 auto;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(15, 15, 17, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.topbar__left { display: flex; align-items: center; gap: 2px; }

.topbar__month {
  font-size: 16px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  text-transform: capitalize;
}
.topbar__month:active { background: var(--bg-2); }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  color: var(--fg-1);
  font-size: 20px;
  line-height: 1;
}
.icon-btn:active { background: var(--bg-2); }

.view { padding: 16px 14px 24px; }

/* ------------------------------------------------ таббар + FAB */

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--shell);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(23, 23, 26, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  z-index: 30;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 10.5px;
  color: var(--fg-2);
  transition: color 0.15s;
}
.tab__ico { font-size: 18px; line-height: 1; }
.tab.is-active { color: var(--fg-0); }

.fab {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(calc(var(--shell) / 2 - 78px));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(91, 159, 255, 0.35);
  z-index: 31;
}
.fab:active { transform: translateX(calc(var(--shell) / 2 - 78px)) scale(0.94); }

@media (max-width: 520px) {
  .fab { left: auto; right: 18px; transform: none; }
  .fab:active { transform: scale(0.94); }
}

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

.card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 16px;
}
.card + .card { margin-top: 12px; }

.card__label {
  font-size: 12px;
  color: var(--fg-1);
  margin-bottom: 6px;
}

.balance {
  text-align: center;
  padding: 22px 16px;
  background: linear-gradient(160deg, var(--bg-2), var(--bg-1));
}
.balance__value { font-size: 32px; font-weight: 500; letter-spacing: -0.5px; }
.balance__sub { margin-top: 6px; font-size: 12px; color: var(--fg-1); }

.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.stat { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-md); padding: 14px; }
.stat__label { font-size: 12px; color: var(--fg-1); }
.stat__value { margin-top: 4px; font-size: 19px; font-weight: 500; }
.stat--in .stat__value { color: var(--income); }
.stat--out .stat__value { color: var(--expense); }

.section-title {
  margin: 24px 0 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-1);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ------------------------------------------------ операции */

.tx-group__date {
  margin: 18px 0 8px;
  font-size: 12px;
  color: var(--fg-1);
  text-transform: capitalize;
}

.tx {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  width: 100%;
  text-align: left;
}
.tx + .tx { margin-top: 8px; }
.tx:active { background: var(--bg-2); }

.tx__ico {
  flex: 0 0 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 17px;
  background: var(--bg-3);
}

.tx__body { flex: 1; min-width: 0; }
.tx__title {
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx__meta {
  font-size: 11.5px;
  color: var(--fg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx__amount { font-size: 15px; font-weight: 500; white-space: nowrap; }
.tx__amount--in { color: var(--income); }
.tx__amount--out { color: var(--fg-0); }
.tx__converted { display: block; font-size: 11px; color: var(--fg-2); text-align: right; font-weight: 400; }

/* ------------------------------------------------ элементы форм */

.field { margin-bottom: 14px; }
.field__label { display: block; font-size: 12px; color: var(--fg-1); margin-bottom: 6px; }

.input, .select, .textarea {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  outline: none;
  transition: border-color 0.15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--blue); }
.textarea { resize: vertical; min-height: 62px; }

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-1) 50%),
                    linear-gradient(135deg, var(--fg-1) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 36px;
}

.input--amount { font-family: var(--mono); font-size: 26px; font-weight: 500; text-align: center; padding: 16px; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }

.btn {
  padding: 13px 18px;
  border-radius: var(--r-sm);
  font-weight: 500;
  background: var(--bg-3);
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.7; }
.btn--wide { width: 100%; }
.btn--primary { background: var(--blue); color: #fff; }
.btn--danger { background: transparent; color: var(--expense); border: 1px solid rgba(255, 91, 91, 0.35); }
.btn--ghost { background: var(--bg-2); border: 1px solid var(--line); }
.btn[disabled] { opacity: 0.45; pointer-events: none; }

/* Переключатели (тип операции, валюта) */
.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: var(--r-sm);
}
.segmented button {
  flex: 1;
  padding: 9px 6px;
  border-radius: 7px;
  font-size: 13.5px;
  color: var(--fg-1);
  transition: background 0.15s, color 0.15s;
}
.segmented button.is-active { background: var(--bg-3); color: var(--fg-0); }
.segmented button.is-active[data-value="income"] { background: rgba(45, 217, 138, 0.16); color: var(--income); }
.segmented button.is-active[data-value="expense"] { background: rgba(255, 91, 91, 0.16); color: var(--expense); }

/* Категории плиткой */
.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 4px;
  border-radius: var(--r-sm);
  background: var(--bg-2);
  border: 1px solid transparent;
  font-size: 10.5px;
  color: var(--fg-1);
  text-align: center;
}
.cat__ico { font-size: 19px; }
.cat.is-active { border-color: currentColor; color: var(--fg-0); background: var(--bg-3); }

.chip {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--fg-1);
}
.chip.is-active { background: var(--bg-3); color: var(--fg-0); border-color: var(--line-strong); }
.chip--currency { font-family: var(--mono); font-weight: 500; color: var(--fg-0); }

.chip-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip-row .chip { flex: 0 0 auto; }

/* ------------------------------------------------ строки товаров чека */

.items { display: flex; flex-direction: column; gap: 8px; }

.item-row {
  display: grid;
  grid-template-columns: 1fr 54px 74px 30px;
  gap: 6px;
  align-items: center;
}
.item-row .input { padding: 9px 10px; font-size: 13px; }
.item-row .input--num { font-family: var(--mono); text-align: right; }
.item-row__del { color: var(--fg-2); font-size: 17px; height: 34px; border-radius: 8px; }
.item-row__del:active { background: var(--bg-3); color: var(--expense); }

.items__head {
  display: grid;
  grid-template-columns: 1fr 54px 74px 30px;
  gap: 6px;
  font-size: 10.5px;
  color: var(--fg-2);
  padding: 0 2px 2px;
}
.items__head span:nth-child(n+2) { text-align: right; }

/* ------------------------------------------------ шторка */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 50;
  animation: fade 0.18s ease;
}

.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--shell);
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-top: 1px solid var(--line-strong);
  z-index: 51;
  animation: slide-up 0.24s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.sheet__title { font-size: 16px; font-weight: 500; }
.sheet__body { padding: 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet__foot {
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex;
  gap: 10px;
}
.sheet__foot .btn { flex: 1; }

@keyframes slide-up { from { transform: translate(-50%, 100%); } }
@keyframes fade { from { opacity: 0; } }

/* ------------------------------------------------ уведомления */

.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 70;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: min(92vw, 480px);
}

.toast {
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: fade 0.18s ease;
}
.toast--error { background: rgba(255, 91, 91, 0.18); border-color: rgba(255, 91, 91, 0.4); color: #ffd0d0; }
.toast--ok { background: rgba(45, 217, 138, 0.16); border-color: rgba(45, 217, 138, 0.4); color: #b8f5d8; }

/* ------------------------------------------------ прочее */

.empty {
  text-align: center;
  padding: 44px 20px;
  color: var(--fg-2);
  font-size: 13.5px;
}
.empty__ico { font-size: 34px; display: block; margin-bottom: 10px; opacity: 0.5; }

.chart-box { position: relative; height: 240px; }

.bar-legend { margin-top: 14px; display: flex; flex-direction: column; gap: 9px; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.legend-name { flex: 1; color: var(--fg-1); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.legend-val { font-family: var(--mono); font-size: 12.5px; }

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  width: 100%;
  text-align: left;
}
.list-item + .list-item { margin-top: 8px; }
.list-item__sub { font-size: 11.5px; color: var(--fg-2); }

.scan-drop {
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  padding: 26px 16px;
  text-align: center;
  color: var(--fg-1);
  font-size: 13.5px;
  background: var(--bg-2);
}
.scan-drop__ico { font-size: 30px; display: block; margin-bottom: 8px; }

.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--fg-2); font-size: 11.5px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--line); }

.hint { font-size: 11.5px; color: var(--fg-2); margin-top: 6px; line-height: 1.5; }
