/* Одна таблица стилей на весь сервис. Цвета — CSS-переменные, тёмная тема
   переопределяет их же. Интерфейс мобильный: узкая колонка и на десктопе. */
:root {
  --bg-1: #f6f8fb;
  --bg-2: #eef2f8;
  --card: #ffffff;
  --text: #16202e;
  --muted: #6a7688;
  --border: #dfe5ee;
  --accent: #1f5fbf;
  --accent-soft: #e8f0fd;
  --up: #12874b;
  --up-soft: #e6f5ec;
  --down: #c92c3c;
  --down-soft: #fdeaec;
  --error-bg: #fdeaec;
  --error-border: #f3c2c8;
  --error-text: #8e1c28;
  --notice-bg: #eef6ff;
  --notice-border: #c9dffb;
  --shadow: 0 1px 2px rgba(16, 32, 56, .06), 0 8px 24px rgba(16, 32, 56, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-1: #0e131b;
    --bg-2: #131a24;
    --card: #172029;
    --text: #e7edf5;
    --muted: #93a1b4;
    --border: #263241;
    --accent: #6aa8ff;
    --accent-soft: #1b2b41;
    --up: #3ecf8e;
    --up-soft: #14301f;
    --down: #ff6b7a;
    --down-soft: #34161b;
    --error-bg: #34161b;
    --error-border: #5d2730;
    --error-text: #ffb3bc;
    --notice-bg: #17273a;
    --notice-border: #27405e;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  background-attachment: fixed;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.3rem; margin: 0 0 .6rem; }
h2 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: .5rem 0; }

.page { max-width: 560px; margin: 0 auto; padding: .9rem 1rem 2rem; }
.page.with-tabbar { padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
.page-title { text-align: center; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: .9rem 1rem; margin: 0 0 .8rem; box-shadow: var(--shadow);
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.up { color: var(--up); }
.down { color: var(--down); }

.error, .notice { padding: .6rem .8rem; border-radius: 10px; margin: .6rem 0; }
.error { background: var(--error-bg); border: 1px solid var(--error-border); color: var(--error-text); }
.notice { background: var(--notice-bg); border: 1px solid var(--notice-border); }

button {
  font: inherit; cursor: pointer; border-radius: 10px; padding: .55rem 1rem;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; }
.danger { color: var(--down); border-color: var(--down); background: none; width: 100%; }
.linklike {
  background: none; border: none; padding: 0; color: var(--accent); cursor: pointer;
  font: inherit;
}
.linklike:hover { text-decoration: underline; }

input, select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem;
}

/* --- Вход --- */
.auth-page { display: grid; place-items: center; min-height: 70vh; }
.auth-card {
  width: 100%; max-width: 360px; text-align: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 16px;
  padding: 1.6rem 1.4rem; box-shadow: var(--shadow);
}
.auth-logo {
  width: 56px; height: 56px; margin: 0 auto .6rem; display: grid; place-items: center;
  border-radius: 16px; background: var(--accent); color: #fff;
  font-size: 1.7rem; font-weight: 700;
}
.auth-brand { margin: 0 0 .4rem; }
.auth-hint { color: var(--muted); margin: 0 0 1rem; }
.auth-input {
  width: 100%; text-align: center; font-size: 1.05rem; margin-bottom: .7rem;
}
.auth-code { font-size: 1.6rem; letter-spacing: .35em; }
.auth-submit { width: 100%; background: var(--accent); border-color: var(--accent); color: #fff; }

/* --- Итоги месяца --- */
.totals { display: flex; text-align: center; padding: .7rem .4rem; }
.totals-cell { flex: 1; display: grid; gap: .15rem; }
.totals-label { font-size: .8rem; color: var(--muted); }
.totals-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* --- Быстрый ввод --- */
.amount-row {
  display: flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem .9rem;
}
.amount-input {
  border: none; background: none; outline: none; text-align: center;
  font-size: 2.2rem; font-weight: 600; width: 100%; max-width: 300px;
  padding: .1rem 0; font-variant-numeric: tabular-nums;
}
.amount-cur { font-size: 1.6rem; color: var(--muted); }

.kind-radio { position: absolute; opacity: 0; pointer-events: none; }
.kind-toggle {
  display: flex; background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: .25rem; margin: 0 0 .8rem; gap: .25rem;
}
.kind-toggle label {
  flex: 1; text-align: center; padding: .45rem 0; border-radius: 9px;
  color: var(--muted); cursor: pointer; user-select: none;
}
#kind-expense:checked ~ .kind-toggle label[for="kind-expense"] {
  background: var(--down-soft); color: var(--down); font-weight: 600;
}
#kind-income:checked ~ .kind-toggle label[for="kind-income"] {
  background: var(--up-soft); color: var(--up); font-weight: 600;
}
#kind-expense:checked ~ .cat-grid[data-kind="income"] { display: none; }
#kind-income:checked ~ .cat-grid[data-kind="expense"] { display: none; }

.cat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem;
  margin: 0 0 .8rem;
}
.cat {
  display: grid; gap: .15rem; justify-items: center; padding: .55rem .2rem;
  border-radius: 12px; border: 1px solid var(--border); background: var(--card);
  box-shadow: var(--shadow);
}
.cat:active { background: var(--accent-soft); border-color: var(--accent); }
.cat-emoji { font-size: 1.5rem; line-height: 1.2; }
.cat-name {
  font-size: .72rem; color: var(--muted); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.extra { margin: 0 0 1rem; }
.extra summary { color: var(--muted); cursor: pointer; padding: .2rem 0; }
.extra-fields { display: grid; gap: .5rem; grid-template-columns: auto 1fr; margin-top: .5rem; }

/* --- Список операций --- */
.today h2 { margin: .4rem 0 .5rem; }
.tx-list { display: grid; gap: .4rem; }
.tx {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  color: var(--text);
}
.tx:hover { text-decoration: none; border-color: var(--accent); }
.tx-emoji { font-size: 1.25rem; }
.tx-main { flex: 1; min-width: 0; display: grid; }
.tx-cat { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-note {
  font-size: .8rem; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tx-amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }

/* --- История --- */
.month-nav {
  display: flex; align-items: center; justify-content: center; gap: .4rem;
  margin: 0 0 .7rem;
}
.month-arrow {
  display: grid; place-items: center; width: 38px; height: 38px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--card);
  font-size: 1.2rem; color: var(--text);
}
.month-arrow:hover { text-decoration: none; border-color: var(--accent); }
.month-title { min-width: 10rem; text-align: center; font-weight: 600; font-size: 1.1rem; }

.day-group { margin: 0 0 .9rem; }
.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0 .2rem .35rem; color: var(--muted); font-size: .9rem;
}

/* --- Отчёт --- */
.report-section { padding-bottom: .5rem; }
.report-section h2 { display: flex; justify-content: space-between; }
.report-row { display: flex; gap: .6rem; align-items: center; padding: .35rem 0; }
.report-emoji { font-size: 1.2rem; }
.report-main { flex: 1; min-width: 0; }
.report-line { display: flex; justify-content: space-between; gap: .5rem; font-size: .95rem; }
.report-sum { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-track {
  height: 7px; border-radius: 4px; background: var(--bg-2);
  margin-top: .25rem; overflow: hidden;
}
.bar { height: 100%; border-radius: 4px; min-width: 2px; }
.bar.expense { background: var(--down); }
.bar.income { background: var(--up); }

/* --- Категории --- */
.cat-row { display: flex; gap: .4rem; align-items: center; margin: 0 0 .45rem; }
.cat-row-emoji { width: 3.2rem; text-align: center; padding: .45rem .2rem; }
.cat-row-name { flex: 1; min-width: 0; padding: .45rem .6rem; }
.cat-row button { padding: .45rem .6rem; }
.cat-add { margin-top: .7rem; }

/* --- Формы правки --- */
.edit-form { display: grid; gap: .7rem; }
.edit-form label { display: grid; gap: .25rem; font-size: .9rem; color: var(--muted); }
.edit-form input, .edit-form select { width: 100%; }

/* --- Таблицы (админка) --- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .35rem .5rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: .85rem; }

/* --- Загрузка выписок --- */
.period-row { display: flex; gap: .6rem; }
.period-row label { flex: 1; }
.batch { padding: .8rem 1rem; }
.batch-head { display: flex; justify-content: space-between; gap: .6rem; align-items: baseline; }
.batch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.batch-actions { display: flex; gap: 1rem; align-items: center; margin-top: .3rem; }
.batch-actions form { display: inline; }

/* Разбор выписки — экран для компьютера: таблица со всеми полями сразу, и
   колонка узкой мобильной вёрстки ей мала. */
.page-wide { max-width: 1100px; }
.review-tools { display: flex; gap: 1rem; margin: 0 0 .6rem; }
table.review th, table.review td { padding: .3rem .35rem; vertical-align: middle; }
table.review input[type="text"], table.review input[type="date"],
table.review select { width: 100%; padding: .35rem .45rem; }
table.review .check-cell { width: 2.2rem; text-align: center; }
table.review .check-cell input { width: 18px; height: 18px; }
table.review .date-cell { width: 9.5rem; }
table.review .kind-cell { width: 7rem; }
table.review .amount-cell { width: 7.5rem; }
table.review .amount-cell input {
  text-align: right; font-variant-numeric: tabular-nums;
}
table.review .cat-cell { width: 14rem; }
.review tr.dup { opacity: .72; }
.badge {
  display: inline-block; margin-top: .2rem; padding: .1rem .4rem; border-radius: 6px;
  background: var(--down-soft); color: var(--down); font-size: .72rem; white-space: nowrap;
}

/* --- Toast --- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(74px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: .8rem;
  background: var(--text); color: var(--bg-1);
  padding: .6rem 1rem; border-radius: 12px; box-shadow: var(--shadow);
  max-width: calc(100% - 2rem); z-index: 20;
}
.toast button {
  background: none; border: none; color: var(--accent);
  font-weight: 600; padding: 0; white-space: nowrap;
}
@media (prefers-color-scheme: dark) {
  .toast { background: #2a3646; color: var(--text); }
}

/* --- Нижний таб-бар --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--border);
  padding: .35rem 0 calc(.35rem + env(safe-area-inset-bottom));
}
.tab {
  display: grid; justify-items: center; gap: .05rem;
  color: var(--muted); font-size: .7rem; min-width: 4.2rem;
  padding: .15rem 0; border-radius: 10px;
}
.tab:hover { text-decoration: none; }
.tab-icon { font-size: 1.25rem; line-height: 1.2; }
.tab.active { color: var(--accent); font-weight: 600; }
