:root {
  --bg: #f6f3ef;
  --surface: #ffffff;
  --surface-2: #efebe5;
  --text: #1d1a17;
  --muted: #7a726a;
  --line: #e4ded6;
  --accent: #e2561f;
  --accent-ink: #ffffff;
  --accent-soft: #fde9df;
  --plus: #1f8a4c;
  --danger: #c0352b;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 4px 16px rgba(40, 30, 20, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1f1c19;
    --surface-2: #2a2622;
    --text: #f3eee8;
    --muted: #a39a90;
    --line: #34302b;
    --accent: #ff7a45;
    --accent-ink: #1b0f08;
    --accent-soft: #3a2117;
    --plus: #4cc483;
    --danger: #ff6b5e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + 32px);
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
.num { font-variant-numeric: tabular-nums; }

/* шапка */
.top {
  display: flex; align-items: center; gap: 8px;
  min-height: 52px; margin-bottom: 8px;
}
.top h1 { font-size: 22px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -.01em; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--surface); box-shadow: var(--shadow);
  display: grid; place-items: center; flex: none;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { transform: scale(.94); }
.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* итог */
.total { margin: 4px 4px 18px; }
.total .label { color: var(--muted); font-size: 14px; }
.total .sum { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.status-line { color: var(--muted); font-size: 13px; min-height: 18px; }
.status-line.err { color: var(--danger); }

/* карточки */
.cards { display: grid; gap: 12px; }
.card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px;
}
.card:active { background: var(--surface-2); }
.chip {
  width: 52px; height: 36px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, #2a2420, #120f0d);
  position: relative; overflow: hidden;
}
.chip::after {
  content: ""; position: absolute; inset: 7px auto auto 8px;
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 50% 50%, #f0a26b 0 45%, #2c3f8f 46% 60%, transparent 61%);
}
.card .meta { flex: 1; min-width: 0; }
.card .digits { font-weight: 600; font-size: 17px; letter-spacing: .04em; }
.card .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub.err { color: var(--danger); }
.card .bal { font-weight: 700; font-size: 19px; white-space: nowrap; }
.card .bal.stale { opacity: .45; }

.empty {
  text-align: center; color: var(--muted);
  padding: 40px 16px; background: var(--surface); border-radius: var(--radius);
}

/* кнопки */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px; border-radius: 14px; border: 0;
  font-weight: 600; font-size: 16px;
  background: var(--accent); color: var(--accent-ink);
}
.btn:disabled { opacity: .55; }
.btn:active:not(:disabled) { filter: brightness(.94); }
.btn.secondary { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.btn.ghost-danger { background: transparent; color: var(--danger); }
.stack { display: grid; gap: 12px; margin-top: 20px; }

/* экран карты */
.hero {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; margin-bottom: 20px;
}
.hero .label { color: var(--muted); font-size: 14px; }
.hero .sum { font-size: 38px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 4px; }

.day { margin: 18px 4px 6px; color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.ops { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.op { display: flex; gap: 12px; align-items: center; padding: 12px 16px; }
.op + .op { border-top: 1px solid var(--line); }
.op .what { flex: 1; min-width: 0; }
.op .place { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op .when { color: var(--muted); font-size: 13px; }
.op .amt { font-weight: 600; white-space: nowrap; }
.op .amt.plus { color: var(--plus); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 6px; vertical-align: 1px; }

/* формы */
.panel { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.panel + .panel { margin-top: 12px; }
.panel h2 { font-size: 17px; margin: 0 0 6px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 14px; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 14px; color: var(--muted); }
.field input {
  width: 100%; min-height: 50px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  font-size: 17px; outline: none;
}
.field input:focus { border-color: var(--accent); }
.drop {
  display: grid; place-items: center; gap: 6px; text-align: center;
  min-height: 120px; border: 2px dashed var(--line); border-radius: 14px;
  color: var(--muted); padding: 16px;
}
.drop strong { color: var(--accent); font-size: 16px; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.found { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); margin-bottom: 14px; font-size: 15px; }
.err-box { color: var(--danger); font-size: 14px; margin: 0 0 12px; }
.or { text-align: center; color: var(--muted); font-size: 13px; margin: 14px 0; }

.login { min-height: 80vh; display: grid; align-content: center; }
.login .logo { font-size: 28px; font-weight: 800; margin: 0 4px 16px; letter-spacing: -.02em; }
.login .logo span { color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0, 0, 0, .2);
}
.skeleton { height: 76px; border-radius: var(--radius); background: var(--surface); opacity: .6; }
