/* ============ Учёт оборотов — премиальный тёмный финтех-стиль ============ */

:root {
  /* Фиксированная тёмная палитра */
  --bg: #0e141b;            /* фон приложения */
  --surface: #1a222c;       /* карточки */
  --surface-2: #232e3a;     /* вторичные поверхности */
  --text: #eef2f6;          /* основной текст (16.4:1 на фоне) */
  --muted: #8b98a5;         /* вторичный текст (>= 4.6:1 на всех поверхностях) */

  /* Акценты графиков (валидированы dataviz на #0e141b: deutan dE 11, все >= 3:1) */
  --green: #2caf65;         /* обороты — метки */
  --red: #bd4234;           /* расходы — метки */
  --blue: #3987e5;          /* баланс / примари — метки */

  /* Светлые ступени тех же оттенков — для текста сумм (>= 5.4:1 на поверхностях) */
  --green-text: #55c978;
  --red-text: #ff7a6b;
  --blue-text: #6ab3f8;

  --border: rgba(255, 255, 255, 0.06);
  --radius: 16px;
  --nav-h: 62px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

html { color-scheme: dark; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#app { max-width: 480px; margin: 0 auto; }

#content {
  padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 34px);
}

.tab { display: none; }
.tab.active { display: block; animation: fade-in 0.2s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- Типографика ---------- */

h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }

h2 {
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 22px 0 10px;
}

.hint { color: var(--muted); font-size: 13px; }
.greeting-sub { margin-top: 3px; }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.card.full { grid-column: 1 / -1; }

/* Лёгкий градиентный tint в цвет метрики (4% alpha) */
.card.tint-green { background: linear-gradient(135deg, rgba(44, 175, 101, 0.05), rgba(44, 175, 101, 0.02) 55%, rgba(44, 175, 101, 0)), var(--surface); }
.card.tint-red   { background: linear-gradient(135deg, rgba(189, 66, 52, 0.05),  rgba(189, 66, 52, 0.02) 55%,  rgba(189, 66, 52, 0)),  var(--surface); }
.card.tint-blue  { background: linear-gradient(135deg, rgba(57, 135, 229, 0.05), rgba(57, 135, 229, 0.02) 55%, rgba(57, 135, 229, 0)), var(--surface); }

.metric-head { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }

.icon-chip {
  flex: none;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 11px;
}
.icon-chip svg { display: block; }
.icon-chip.ic-green { background: rgba(44, 175, 101, 0.14); color: var(--green-text); }
.icon-chip.ic-red   { background: rgba(189, 66, 52, 0.15);  color: var(--red-text); }
.icon-chip.ic-blue  { background: rgba(57, 135, 229, 0.14); color: var(--blue-text); }

.stat-label { color: var(--muted); font-size: 12px; letter-spacing: 0.01em; }
.metric-head .stat-label { flex: 1; min-width: 0; }

.stat-value {
  font-size: 26px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}
.stat-sub { color: var(--muted); font-size: 11.5px; margin-top: 5px; }

/* Узкая горизонтальная карточка (Активных участников) */
.card.slim { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.card.slim .stat-label { flex: 1; font-size: 13px; }
.card.slim .stat-value { font-size: 21px; }

.money { font-variant-numeric: tabular-nums; }
.money .cur {
  display: inline-block;
  font-size: 0.58em;
  font-weight: 500;
  color: var(--muted);
  margin-left: 5px;
  white-space: nowrap;
  overflow-wrap: normal;
}
.money.green { color: var(--green-text); }
.money.red { color: var(--red-text); }
.money.blue { color: var(--blue-text); }

.loading { color: var(--muted); text-align: center; padding: 30px 0; }

/* ---------- Пустые состояния ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  text-align: center;
  padding: 30px 18px;
  background: var(--surface);
  border: 1px dashed rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  font-size: 14px;
}
.empty svg { opacity: 0.55; }

/* ---------- Кнопки ---------- */

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

.btn {
  display: block;
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  background: linear-gradient(180deg, #2c6fc9, #2360ae);
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.btn:active { transform: scale(0.98); filter: brightness(1.08); }
.btn[disabled] { opacity: 0.55; }

.quick-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.quick-btn {
  min-height: 48px;
  border-radius: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 4px;
  transition: background 0.15s ease, transform 0.15s ease;
}
.quick-btn:active { transform: scale(0.98); background: var(--surface-2); }
.quick-btn.q-turnover { color: var(--green-text); }
.quick-btn.q-expense { color: var(--red-text); }
.quick-btn.q-balance { color: var(--blue-text); }

.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 2px 0 16px;
}
.detail-head h1 { margin: 0; font-size: 22px; line-height: 1.2; }
.detail-head .hint { margin-top: 2px; }
.detail-title { min-width: 0; }
.detail-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn-back {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  transition: background 0.15s ease, transform 0.15s ease;
}
.btn-back:active { background: var(--surface-2); transform: scale(0.94); }

/* ---------- Сегмент-контролы ---------- */

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 4px;
  margin-top: 14px;
}
.segmented button {
  min-height: 44px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  padding: 4px 2px;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

/* Периоды: активный — синяя подложка */
.segmented button.active {
  background: rgba(57, 135, 229, 0.16);
  color: var(--blue-text);
  box-shadow: inset 0 0 0 1px rgba(57, 135, 229, 0.35);
}

/* Тип записи: активный сегмент окрашен в цвет типа */
.kind-seg button.active[data-kind="turnover"] {
  background: rgba(44, 175, 101, 0.15);
  color: var(--green-text);
  box-shadow: inset 0 0 0 1px rgba(44, 175, 101, 0.4);
}
.kind-seg button.active[data-kind="expense"] {
  background: rgba(189, 66, 52, 0.17);
  color: var(--red-text);
  box-shadow: inset 0 0 0 1px rgba(189, 66, 52, 0.45);
}
.kind-seg button.active[data-kind="balance"] {
  background: rgba(57, 135, 229, 0.16);
  color: var(--blue-text);
  box-shadow: inset 0 0 0 1px rgba(57, 135, 229, 0.4);
}

.custom-range { display: none; gap: 8px; margin-top: 10px; }
.custom-range.visible { display: flex; }
.custom-range label { flex: 1; display: block; min-width: 0; }
.custom-range .hint { display: block; margin-bottom: 4px; font-size: 12px; }

/* ---------- Формы ---------- */

.field { margin-top: 16px; }
.field-label {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

input[type="text"], input[type="date"] {
  width: 100%;
  min-height: 48px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  font-size: 16px;
  padding: 10px 14px;
  outline: none;
  color-scheme: dark;
  transition: border-color 0.15s ease;
}
input:focus { border-color: var(--blue); }
input::placeholder { color: var(--muted); }

/* Поле суммы — крупное, по центру */
.amount-wrap { position: relative; }
.amount-input {
  width: 100%;
  min-height: 66px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  font-size: 30px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 10px 58px;
  transition: border-color 0.15s ease;
}
.amount-input:focus { border-color: var(--blue); }
.amount-input::placeholder { color: var(--muted); font-weight: 500; }

/* «±» для баланса: на мобильных decimal-клавиатурах нет клавиши минуса */
.amount-wrap .sign-toggle {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--blue-text);
  font-size: 21px;
  font-weight: 700;
  line-height: 1;
  z-index: 1;
  transition: background 0.15s ease, color 0.15s ease;
}
.amount-wrap .sign-toggle:active { background: rgba(57, 135, 229, 0.2); }
.amount-wrap .unit {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.balance-hint { margin-top: 8px; }

/* ---------- Чипы категорий ---------- */

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

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
/* Выбранный чип — рамка и фон в цвет текущего типа */
.chips.kind-turnover .chip.selected {
  border-color: var(--green);
  background: rgba(44, 175, 101, 0.12);
  color: var(--green-text);
}
.chips.kind-expense .chip.selected {
  border-color: var(--red);
  background: rgba(189, 66, 52, 0.13);
  color: var(--red-text);
}
/* Пара «выбор + удаление»: одна визуальная пилюля из двух соседних кнопок.
   Обе кнопки — полноценные touch-цели >= 44px, без вложенных контролов. */
.chip-pair {
  display: inline-flex;
  align-items: stretch;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  transition: background 0.15s ease, border-color 0.15s ease;
}
.chip-pair .chip {
  background: none;
  border: none;
  border-radius: 12px 0 0 12px;
  padding-right: 10px;
}
.chip-pair .chip-x {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  border-left: 1px solid var(--border);
  border-radius: 0 12px 12px 0;
  color: var(--text);
  opacity: 0.65;
  font-size: 15px;
  line-height: 1;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.chip-pair .chip-x:active { opacity: 1; background: rgba(0, 0, 0, 0.25); }

/* Выбранная пара — рамка и фон в цвет текущего типа */
.chips.kind-turnover .chip-pair.selected {
  border-color: var(--green);
  background: rgba(44, 175, 101, 0.12);
}
.chips.kind-turnover .chip-pair.selected .chip,
.chips.kind-turnover .chip-pair.selected .chip-x { color: var(--green-text); }
.chips.kind-expense .chip-pair.selected {
  border-color: var(--red);
  background: rgba(189, 66, 52, 0.13);
}
.chips.kind-expense .chip-pair.selected .chip,
.chips.kind-expense .chip-pair.selected .chip-x { color: var(--red-text); }

.chip.chip-add { color: var(--blue-text); border-style: dashed; }

.chip-input-row { display: flex; gap: 8px; margin-top: 10px; }
.chip-input-row input { flex: 1; }
.chip-input-row .btn { width: auto; padding: 0 18px; min-height: 48px; }

/* ---------- Списки записей ---------- */

.entry-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.entry {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 6px 10px 12px;
}
.entry-main { flex: 1; min-width: 0; }
.entry-cat {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.entry-date { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.entry-amount { flex: none; font-size: 15px; font-weight: 700; text-align: right; }
.entry-del {
  flex: none;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  border-radius: 11px;
  transition: color 0.15s ease, background 0.15s ease;
}
.entry-del:active { color: var(--red-text); background: rgba(189, 66, 52, 0.15); }

/* ---------- Графики ---------- */

.chart-card { margin-top: 12px; padding: 14px 10px 8px; position: relative; }
.chart-legend { display: flex; gap: 16px; padding: 0 6px 10px; }
.chart-legend .lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.chart-legend .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chart-legend .dot.turnover { background: var(--green); }
.chart-legend .dot.expense { background: var(--red); }

.chart-svg-wrap { position: relative; }
.chart-svg-wrap svg { display: block; width: 100%; height: auto; }

.chart-tooltip {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  background: rgba(9, 14, 19, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
  display: none;
}
.chart-tooltip.visible { display: block; }
.chart-tooltip .tt-date { color: var(--muted); margin-bottom: 3px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.chart-tooltip .tt-row .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }

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

/* Горизонтальные категорийные полосы */
.cat-bars { display: flex; flex-direction: column; gap: 11px; }
.cat-bar-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; margin-bottom: 5px; }
.cat-bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-bar-sum { flex: none; font-weight: 600; font-variant-numeric: tabular-nums; }
.cat-bar-track { height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.06); overflow: hidden; }
.cat-bar-fill { height: 100%; border-radius: 4px; min-width: 2px; }
.cat-bar-fill.turnover { background: var(--green); }
.cat-bar-fill.expense { background: var(--red); }

/* ---------- Админ: карточки участников ---------- */

.user-cards { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.user-card {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: background 0.15s ease, transform 0.15s ease;
}
.user-card:active { background: var(--surface-2); transform: scale(0.99); }

.user-head { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.user-info { flex: 1; min-width: 0; }
.user-name {
  display: block;
  font-weight: 600;
  font-size: 14.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-username {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 11px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.stat-mini { min-width: 0; }
.stat-mini .sm-label {
  display: block;
  color: var(--muted);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 2px;
}
.stat-mini .sm-val {
  display: block;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.stat-mini .sm-val.hint { color: var(--muted); }

/* ---------- Нижняя навигация: плавающая пилюля ---------- */

#bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  width: min(calc(100% - 24px), 440px);
  display: flex;
  gap: 2px;
  background: #1a222c;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  padding: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  z-index: 20;
}
.nav-btn {
  flex: 1;
  min-height: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
  transition: color 0.18s ease, background 0.18s ease;
}
.nav-btn.active {
  color: var(--blue-text);
  background: rgba(57, 135, 229, 0.14);
}
.nav-btn[hidden] { display: none; }

/* ---------- Тост: тёмная плашка с цветной полоской статуса ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 26px);
  transform: translateX(-50%) translateY(8px);
  max-width: min(90vw, 420px);
  background: #101820;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-left: 3px solid var(--green);
  color: var(--text);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14px;
  text-align: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
}
#toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-left-color: var(--red-text); }
