* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #1f2937;
  --pos: #047857;
  --neg: #b91c1c;
  --shadow: 0 1px 2px rgba(0,0,0,.06);
  --bank-tochka: #7e22ce;
  --bank-sber: #15803d;
  --bank-tinkoff: #eab308;
  --bank-yandex: #dc2626;
  --bank-cash: #6b7280;
  --bank-goal: #2563eb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #111827;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #1f2937;
    --accent: #f3f4f6;
    --pos: #34d399;
    --neg: #f87171;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
html, body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
.container { max-width: 720px; margin: 0 auto; padding: 12px; }
.card { background: var(--surface); border-radius: 12px; padding: 16px; margin: 10px 0; box-shadow: var(--shadow); }
h1 { font-size: 22px; font-weight: 600; }
h2 { font-size: 14px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin: 8px 0 10px; }
.muted { color: var(--muted); font-size: 13px; }
.tabular { font-variant-numeric: tabular-nums; }

.app-header { display: flex; align-items: center; gap: 8px; padding: 8px 4px 14px; }
.app-header h1 { flex: 1; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 14px; cursor: pointer; color: var(--text);
}
.icon-btn:hover { background: var(--bg); }
.sync-status {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%; font-size: 14px;
  background: var(--bg); cursor: default; user-select: none;
}
.sync-status.syncing { background: #fef3c7; color: #92400e; }
.sync-status.ok { background: #d1fae5; color: #065f46; }
.sync-status.error { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) {
  .sync-status.syncing { background: rgba(251,191,36,.2); color: #fde68a; }
  .sync-status.ok { background: rgba(52,211,153,.18); color: #6ee7b7; }
  .sync-status.error { background: rgba(248,113,113,.18); color: #fca5a5; }
}

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom); z-index: 50;
}
.nav-item { background: none; border: none; padding: 12px 0; font-size: 13px; color: var(--muted); cursor: pointer; }
.nav-item.active { color: var(--text); font-weight: 600; }

.total-card {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 75%, transparent));
  color: var(--bg);
  text-align: center;
  padding: 20px 16px;
}
.total-card .label { font-size: 13px; opacity: 0.8; }
.total-card .amount { font-size: 28px; font-weight: 600; margin-top: 6px; }

.group { margin-top: 14px; }
.group-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 4px; cursor: pointer; user-select: none;
}
.group-name { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.group-total { font-variant-numeric: tabular-nums; font-size: 14px; }
.account-row {
  display: flex; align-items: center; gap: 10px; padding: 10px 4px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.account-row:last-child { border-bottom: none; }
.account-row:hover { background: var(--bg); }
.account-row.sub { padding-left: 28px; }
.bank-dot {
  width: 24px; height: 24px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: white; font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.bank-dot.tochka { background: var(--bank-tochka); }
.bank-dot.sber   { background: var(--bank-sber); }
.bank-dot.tinkoff{ background: var(--bank-tinkoff); color: #1a1a1a; }
.bank-dot.yandex { background: var(--bank-yandex); }
.bank-dot.cash   { background: var(--bank-cash); }
.bank-dot.goal   { background: var(--bank-goal); }
.account-name { flex: 1; font-size: 14px; }
.account-balance { font-variant-numeric: tabular-nums; font-size: 14px; }
.account-balance.pos { color: var(--pos); }
.account-balance.neg { color: var(--neg); }

.tx-row {
  display: flex; gap: 10px; padding: 12px 4px;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.tx-row:last-child { border-bottom: none; }
.tx-row:hover { background: var(--bg); }
.tx-icon { font-size: 22px; line-height: 1; flex-shrink: 0; width: 28px; text-align: center; }
.tx-body { flex: 1; min-width: 0; }
.tx-title { font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tx-amount { font-variant-numeric: tabular-nums; font-size: 14px; font-weight: 500; align-self: center; text-align: right; }
.tx-amount.pos { color: var(--pos); }
.tx-amount.neg { color: var(--neg); }
.tx-summary { padding: 6px 4px 10px; }
.tx-pager { display: flex; gap: 8px; justify-content: center; padding: 12px 0 4px; }
.tx-pager button { padding: 6px 14px; font-size: 13px; }

.filters { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.filters input, .filters select {
  flex: 1; min-width: 100px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  font-size: 14px; font-family: inherit;
}

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .emoji { font-size: 48px; opacity: 0.3; }
.empty p { margin-top: 12px; font-size: 14px; }

.skeleton {
  background: linear-gradient(90deg, var(--border) 0%, var(--surface) 50%, var(--border) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  height: 14px; border-radius: 4px; margin: 6px 0;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none; z-index: 100; }
.drawer.open { display: block; }
.drawer-content {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-radius: 16px 16px 0 0;
  padding: 16px; max-height: 90vh; overflow-y: auto;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
.drawer-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto 12px; }
.drawer-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }

.dropzone {
  border: 2px dashed var(--border); border-radius: 12px;
  padding: 32px 20px; text-align: center; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover, .dropzone.hover { background: var(--bg); border-color: var(--accent); }
.dropzone-icon { font-size: 36px; opacity: 0.5; }
.dropzone-text { margin-top: 8px; color: var(--muted); font-size: 14px; }

.import-status { margin-top: 14px; padding: 14px; border-radius: 8px; background: var(--bg); font-size: 14px; line-height: 1.5; }
.import-status.error { background: #fee2e2; color: #991b1b; }
.import-status.ok { background: #d1fae5; color: #065f46; }
@media (prefers-color-scheme: dark) {
  .import-status.error { background: rgba(239,68,68,0.15); color: #fca5a5; }
  .import-status.ok { background: rgba(52,211,153,0.15); color: #6ee7b7; }
}
.import-status pre { white-space: pre-wrap; font-family: inherit; font-size: 13px; }

.btn {
  display: inline-block; padding: 12px 16px;
  border: none; border-radius: 8px;
  background: var(--accent); color: var(--bg);
  font-size: 14px; font-weight: 500;
  cursor: pointer; font-family: inherit;
}
.btn:active { opacity: 0.85; }
.btn-block { display: block; width: 100%; }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-danger { background: var(--neg); color: white; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.action-bar { display: flex; gap: 8px; margin: 8px 0 4px; }
.action-bar .btn { flex: 1; padding: 10px 12px; font-size: 13px; }

.row-menu {
  background: transparent; border: none; font-size: 18px;
  color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; flex-shrink: 0;
}
.row-menu:hover { background: var(--bg); color: var(--text); }

.form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 12px; color: var(--muted); font-weight: 500; }
.form-row input, .form-row select, .form-row textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 14px; font-family: inherit;
}
.form-row textarea { min-height: 60px; resize: vertical; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }
.form-actions .btn { flex: 1; }
.form-error {
  padding: 10px 12px; border-radius: 8px;
  background: rgba(239,68,68,0.1); color: var(--neg);
  font-size: 13px;
}

#stats { display: grid; gap: 6px; }
#stats div { display: flex; justify-content: space-between; font-size: 14px; }
#stats div span:last-child { font-variant-numeric: tabular-nums; }

.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  padding: 10px 18px; border-radius: 24px;
  background: rgba(0,0,0,.8); color: white; font-size: 13px;
  z-index: 200; max-width: 80%; text-align: center;
}
.toast.error { background: #b91c1c; }

.import-row { padding: 8px 4px; font-size: 13px; border-bottom: 1px solid var(--border); }
.import-row:last-child { border-bottom: none; }
.import-row .name { font-weight: 500; }
.import-row .meta { color: var(--muted); font-size: 12px; }
.account-picker {
  display: grid; grid-template-columns: 1fr; gap: 6px;
  max-height: 240px; overflow-y: auto;
  margin: 8px 0; padding: 4px;
  border: 1px solid var(--border); border-radius: 8px;
}
.account-picker label { display: flex; gap: 8px; padding: 8px; cursor: pointer; border-radius: 6px; }
.account-picker label:hover { background: var(--bg); }
.account-picker input[type="radio"] { margin-top: 2px; }
