:root {
  color-scheme: light;
  --bg: #f3f7f2;
  --surface: #ffffff;
  --surface-soft: #e9f3e9;
  --ink: #18221b;
  --muted: #68746b;
  --green: #23854b;
  --green-dark: #176b3a;
  --green-soft: #d7edda;
  --red: #c25050;
  --red-soft: #f7e1de;
  --line: #dce5dc;
  --shadow: 0 16px 42px rgba(35, 73, 47, .1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111713;
  --surface: #1a231d;
  --surface-soft: #213027;
  --ink: #edf5ef;
  --muted: #a4b1a7;
  --green: #62c884;
  --green-dark: #80d89b;
  --green-soft: #244c31;
  --red: #f28a84;
  --red-soft: #4a2928;
  --line: #2d3a31;
  --shadow: 0 16px 42px rgba(0, 0, 0, .26);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; }
button, input, select { font: inherit; }
button { color: inherit; }
.app { width: min(100%, 680px); margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 18px calc(94px + var(--safe-bottom)); }
.gate { min-height: 100vh; display: grid; place-content: center; justify-items: center; gap: 10px; text-align: center; padding: 32px; }
.gate h1 { margin: 10px 0 0; font-size: 30px; }
.gate p { max-width: 330px; margin: 0; color: var(--muted); line-height: 1.5; }
.brand-mark { width: 68px; height: 68px; display: grid; place-items: center; border-radius: 22px; background: var(--green); color: white; font-size: 35px; font-weight: 750; transform: rotate(-4deg); box-shadow: var(--shadow); }
.loader { width: 24px; height: 24px; margin-top: 16px; border: 3px solid var(--green-soft); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.topbar, .identity, .section-heading, .sheet-title-row { display: flex; align-items: center; justify-content: space-between; }
.identity { justify-content: flex-start; gap: 12px; }
.avatar { width: 44px; height: 44px; border-radius: 15px; display: grid; place-items: center; background: var(--green-soft); color: var(--green-dark); font-weight: 800; }
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.identity strong { font-size: 17px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); font-size: 22px; cursor: pointer; }
.workspace-row { margin: 24px 0 14px; display: grid; gap: 7px; }
.workspace-row label { color: var(--muted); font-size: 12px; font-weight: 650; }
select, input { width: 100%; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 13px 14px; outline: none; }
select:focus, input:focus { border-color: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 16%, transparent); }

.balance-card { position: relative; overflow: hidden; min-height: 212px; padding: 24px; border-radius: 28px 28px 28px 8px; background: var(--green-dark); color: white; box-shadow: var(--shadow); }
.balance-card::after { content: "₽"; position: absolute; right: -18px; top: -34px; color: rgba(255,255,255,.08); font-size: 170px; font-weight: 800; transform: rotate(10deg); }
.balance-card p { margin: 0; color: rgba(255,255,255,.72); }
.balance-card h2 { position: relative; z-index: 1; margin: 8px 0 26px; font-size: clamp(36px, 10vw, 52px); letter-spacing: -.04em; }
.status-label { position: absolute; top: 24px; right: 24px; padding: 6px 9px; border: 1px solid rgba(255,255,255,.25); border-radius: 9px; font-size: 11px; }
.balance-actions { position: relative; z-index: 1; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.balance-actions button { border: 0; border-radius: 15px; padding: 13px; background: white; color: var(--green-dark); font-weight: 750; cursor: pointer; }
.balance-actions .secondary-action { background: rgba(255,255,255,.14); color: white; border: 1px solid rgba(255,255,255,.24); }
.balance-actions .receipt-action { grid-column: 1 / -1; background: rgba(255,255,255,.14); color: white; border: 1px solid rgba(255,255,255,.24); }
.balance-actions span { font-size: 21px; vertical-align: -1px; margin-right: 3px; }

.period-tabs { display: grid; grid-template-columns: repeat(3, 1fr); margin: 18px 0; padding: 4px; border-radius: 15px; background: var(--surface-soft); }
.period-tabs button { border: 0; background: transparent; padding: 10px 7px; border-radius: 11px; color: var(--muted); font-size: 13px; font-weight: 700; cursor: pointer; }
.period-tabs button.selected { background: var(--surface); color: var(--ink); box-shadow: 0 3px 12px rgba(33, 70, 44, .08); }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary-grid article { display: flex; gap: 10px; align-items: center; padding: 16px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.summary-grid p { margin: 0 0 3px; color: var(--muted); font-size: 12px; }
.summary-grid strong { font-size: clamp(15px, 4vw, 19px); }
.summary-sign { width: 32px; height: 32px; flex: 0 0 32px; display: grid; place-items: center; border-radius: 11px; font-size: 21px; font-weight: 500; }
.income-sign { color: var(--green); background: var(--green-soft); }
.expense-sign { color: var(--red); background: var(--red-soft); }

.panel { margin-top: 16px; padding: 20px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); }
.section-heading h3, .panel h3 { margin: 0; font-size: 17px; }
.legend { display: flex; gap: 12px; color: var(--muted); font-size: 10px; }
.legend span::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; }
.legend-income::before { background: var(--green); }
.legend-expense::before { background: var(--red); }
.chart-wrap { height: 190px; margin-top: 16px; }
.chart-wrap canvas { width: 100%; height: 100%; }
.empty-note { margin: -108px 0 83px; text-align: center; color: var(--muted); font-size: 13px; }
.text-button { border: 0; background: transparent; color: var(--green); font-size: 13px; font-weight: 750; cursor: pointer; }
.transaction-list { margin-top: 12px; }
.transaction-item { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 11px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.transaction-item:last-child { border-bottom: 0; }
.transaction-symbol { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; font-size: 20px; font-weight: 500; }
.transaction-item.income .transaction-symbol { background: var(--green-soft); color: var(--green); }
.transaction-item.expense .transaction-symbol { background: var(--red-soft); color: var(--red); }
.transaction-copy strong, .transaction-copy span { display: block; }
.transaction-copy span, .transaction-amount small { margin-top: 3px; color: var(--muted); font-size: 11px; }
.transaction-amount { text-align: right; }
.transaction-amount strong, .transaction-amount small { display: block; }
.transaction-item.income .transaction-amount strong { color: var(--green); }
.empty-state { padding: 30px 10px; text-align: center; color: var(--muted); }

.view { display: none; }
.view.active-view { display: block; }
.page-heading { margin: 32px 2px 20px; }
.page-heading h2 { margin: 4px 0 8px; font-size: 30px; letter-spacing: -.02em; }
.page-heading > p:last-child { margin: 0; color: var(--muted); line-height: 1.45; }
.standalone-list { padding: 4px 18px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); }
.category-item { margin-bottom: 14px; }
.category-item header { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: 13px; }
.category-bar { width: 100%; height: 8px; overflow: hidden; border: 0; border-radius: 4px; background: var(--line); appearance: none; }
.category-bar::-webkit-progress-bar { background: var(--line); }
.category-bar::-webkit-progress-value { background: var(--green); border-radius: 4px; }
.category-bar::-moz-progress-bar { background: var(--green); border-radius: 4px; }
.category-list { padding: 20px; border: 1px solid var(--line); border-radius: 24px; background: var(--surface); }
.workspace-list-item { display: flex; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid var(--line); }
.workspace-list-item:last-child { border-bottom: 0; }
.workspace-list-item span { color: var(--muted); font-size: 12px; }
.privacy-card { margin-top: 16px; padding: 20px; border-radius: 8px 24px 24px 24px; background: var(--green-soft); color: var(--green-dark); }
.privacy-card p { margin: 8px 0 0; font-size: 13px; line-height: 1.5; }

.bottom-nav { position: fixed; z-index: 20; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 680px); display: grid; grid-template-columns: repeat(4, 1fr); padding: 8px 10px calc(8px + var(--safe-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(16px); }
.bottom-nav button { border: 0; background: transparent; color: var(--muted); padding: 4px 2px; font-size: 10px; cursor: pointer; }
.bottom-nav span { display: block; height: 27px; font-size: 21px; line-height: 24px; }
.bottom-nav button.active { color: var(--green); font-weight: 750; }

.sheet-backdrop { position: fixed; z-index: 40; inset: 0; background: rgba(10, 18, 12, .42); backdrop-filter: blur(3px); }
.sheet { position: fixed; z-index: 41; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 680px); padding: 10px 22px calc(24px + var(--safe-bottom)); border-radius: 28px 28px 0 0; background: var(--surface); box-shadow: 0 -20px 60px rgba(15, 40, 22, .22); }
.sheet-handle { width: 44px; height: 4px; margin: 0 auto 17px; border-radius: 2px; background: var(--line); }
.sheet h2 { margin: 3px 0 16px; font-size: 23px; }
.sheet form { display: grid; gap: 15px; }
.sheet label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.optional { float: right; font-weight: 500; }
.amount-field > div { display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.amount-field input { border: 0; padding: 4px 0 8px; font-size: 44px; font-weight: 750; letter-spacing: -.03em; box-shadow: none; }
.amount-field b { color: var(--muted); font-size: 25px; }
.primary-button { margin-top: 4px; border: 0; border-radius: 15px; padding: 15px; background: var(--green); color: white; font-weight: 800; cursor: pointer; }
.primary-button:disabled { opacity: .58; cursor: wait; }
.receipt-sheet { max-height: min(92vh, 760px); overflow-y: auto; }
.upload-zone { min-height: 146px; place-items: center; overflow: hidden; border: 1px dashed color-mix(in srgb, var(--green) 55%, var(--line)); border-radius: 20px; background: var(--surface-soft); text-align: center; cursor: pointer; }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-zone > span { display: grid; gap: 7px; padding: 22px; color: var(--green-dark); }
.upload-zone b { font-size: 15px; }
.upload-zone small { color: var(--muted); font-weight: 500; }
.upload-zone img { width: 100%; max-height: 220px; object-fit: contain; background: #eef2ee; }
.recognition-note { margin: -3px 0 0; padding: 11px 13px; border-radius: 12px; background: var(--green-soft); color: var(--green-dark); font-size: 12px; line-height: 1.4; }
.recognition-note.loading { opacity: .72; }
.receipt-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.receipt-fields label:last-child { grid-column: 1 / -1; }
.compact-amount { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.compact-amount input { border: 0; box-shadow: none; }
.compact-amount b { padding-right: 14px; color: var(--muted); }
.storage-note { margin: -5px 5px 0; color: var(--muted); font-size: 11px; line-height: 1.45; text-align: center; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: calc(88px + var(--safe-bottom)); transform: translateX(-50%); width: min(calc(100% - 36px), 520px); padding: 13px 16px; border-radius: 14px; background: var(--ink); color: var(--surface); text-align: center; font-size: 13px; box-shadow: var(--shadow); }

@media (max-width: 370px) {
  .app { padding-inline: 13px; }
  .balance-card { padding: 20px; }
  .summary-grid { gap: 8px; }
  .summary-grid article { padding: 12px; }
  .legend { display: none; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; scroll-behavior: auto !important; } }
