:root {
  color-scheme: light;
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-2: #edf3f4;
  --ink: #15233a;
  --muted: #64748b;
  --line: #dce5e8;
  --green: #087f75;
  --green-strong: #05655d;
  --blue: #2b63d9;
  --red: #dc2626;
  --amber: #d97706;
  --shadow: 0 8px 24px rgba(26, 46, 66, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
}
body[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #111827;
  --surface-2: #1e293b;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #334155;
  background: var(--bg);
}
body[data-theme="dark"] .account,
body[data-theme="dark"] .tx,
body[data-theme="dark"] .budget,
body[data-theme="dark"] .report-item,
body[data-theme="dark"] .chart-card,
body[data-theme="dark"] .month-stats article,
body[data-theme="dark"] .quick-action,
body[data-theme="dark"] .fab-choice,
body[data-theme="dark"] .settings-card,
body[data-theme="dark"] dialog {
  background: #111827;
}
body[data-theme="dark"] .tabs {
  background: rgba(17, 24, 39, .84);
}
body[data-theme="dark"] .voice-box {
  background: #102c2a;
}
body[data-theme="dark"] .voice-box.listening {
  background: #12332e;
}
body[data-theme="dark"] .quick-action.income span,
body[data-theme="dark"] .fab-choice.income span { background: rgba(34, 197, 94, .14); }
body[data-theme="dark"] .quick-action.expense span,
body[data-theme="dark"] .fab-choice.expense span { background: rgba(248, 113, 113, .14); }
body[data-theme="dark"] .quick-action.voice span,
body[data-theme="dark"] .fab-choice.voice span { background: rgba(96, 165, 250, .15); }
body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea,
body[data-theme="dark"] .icon-btn,
body[data-theme="dark"] .secondary {
  background: #0f172a;
  color: var(--ink);
}
body[data-theme="dark"] .tab.active,
body[data-theme="dark"] .primary,
body[data-theme="dark"] .fab {
  background: #14b8a6;
  color: #042f2e;
}
body[data-theme="dark"] .amount-income { color: #34d399; }
body[data-theme="dark"] .amount-expense { color: #fb7185; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .72; }
.shell {
  width: min(100%, 960px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(96px + env(safe-area-inset-bottom));
}
.topbar, .section-head, .dialog-head, .filters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.profile-head {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.avatar-btn, .avatar-large {
  border: 0;
  padding: 0;
  overflow: hidden;
  color: white;
  background: var(--green);
  box-shadow: 0 6px 16px rgba(8, 127, 117, .22);
}
.avatar-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}
.avatar-large {
  width: 68px;
  height: 68px;
  border-radius: 50%;
}
.avatar-btn span, .avatar-large span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-weight: 900;
  font-size: 19px;
}
.avatar-large span { font-size: 25px; }
.avatar-btn img, .avatar-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.eyebrow, .balance-panel p, .hint, small {
  color: var(--muted);
  margin: 0;
}
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 25px; }
h2 { font-size: 17px; }
.icon-btn {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  display: grid;
  place-items: center;
  font-weight: 900;
}
.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.install-btn {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: white;
  background: var(--green);
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 6px 16px rgba(8, 127, 117, .2);
}
.balance-panel {
  margin-top: 16px;
  padding: 22px 20px 17px;
  border-radius: 8px;
  color: white;
  background: #0b776e;
  box-shadow: 0 12px 28px rgba(8, 127, 117, .2);
}
.balance-panel p, .balance-panel small { color: rgba(255,255,255,.78); }
.balance-panel strong {
  display: block;
  margin-top: 6px;
  font-size: 34px;
}
.save-track {
  height: 8px;
  margin: 20px 0 8px;
  border-radius: 999px;
  background: rgba(255,255,255,.24);
  overflow: hidden;
}
.save-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: white;
}
.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin: 16px 0 12px;
}
.quick-action {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  font-weight: 900;
  line-height: 1.15;
  box-shadow: 0 4px 14px rgba(26, 46, 66, .05);
}
.quick-action span {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
}
.quick-action.income span { color: var(--green); background: #dcfce7; }
.quick-action.expense span { color: var(--red); background: #fee2e2; }
.quick-action.voice span { color: var(--blue); background: #dbeafe; }
.quick-action.receipt span { color: #a16207; background: #fef3c7; }
.month-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}
.month-stats article {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: none;
}
.month-stats b {
  display: block;
  margin-top: 8px;
  font-size: 20px;
  overflow-wrap: anywhere;
}
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin: 16px 0 18px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.tab {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}
.tab.active {
  color: white;
  background: var(--green);
}
.view { display: none; }
.view.active { display: block; }
.section-head { margin: 20px 0 10px; }
select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 11px 12px;
  color: var(--ink);
  outline: none;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, .13);
}
.account-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}
.account, .tx, .budget, .report-item, .chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: none;
}
.account { padding: 15px; }
.account span { display: inline-flex; width: 10px; height: 10px; border-radius: 50%; }
.account b { display: block; margin-top: 7px; font-size: 19px; }
.account small { display: block; margin-top: 5px; }
.chart-card {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 16px;
  align-items: center;
  padding: 16px;
}
.donut {
  width: 132px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(#0f766e 0 100%);
  position: relative;
}
.donut::after {
  content: "";
  position: absolute;
  inset: 28px;
  border-radius: 50%;
  background: var(--surface);
}
.legend, .report-list, .budget-list, .tx-list {
  display: grid;
  gap: 10px;
}
.legend-item, .tx, .budget, .report-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}
.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex: 0 0 auto;
}
.tx-left, .legend-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.tx-left div, .legend-left div { min-width: 0; }
.tx strong, .legend strong { display: block; overflow-wrap: anywhere; }
.tx small { display: block; }
.tx-actions { display: flex; gap: 6px; margin-left: auto; }
.tx-action { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); }
.load-more { width: 100%; margin-top: 12px; }
.auth-dialog::backdrop { background: rgba(15, 23, 42, .72); }
.auth-dialog h2 { text-align: center; margin: 0; }
body[data-theme="dark"] .fab-choice,
body[data-theme="dark"] .secondary,
body[data-theme="dark"] .settings-card { background: #111c2f; color: #f8fafc; }
.amount-expense { color: var(--red); }
.amount-income { color: var(--green); }
.filters {
  align-items: stretch;
  margin-bottom: 12px;
}
.filters input { flex: 1; }
.filters select { width: 122px; }
.bars {
  display: grid;
  grid-template-columns: repeat(7, minmax(28px, 1fr));
  gap: 8px;
  align-items: end;
  min-height: 190px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.bar {
  display: grid;
  align-items: end;
  gap: 5px;
  height: 160px;
}
.bar span {
  display: block;
  border-radius: 6px 6px 2px 2px;
  min-height: 4px;
}
.bar small { text-align: center; font-size: 11px; }
.budget { display: block; }
.budget-top { display: flex; justify-content: space-between; gap: 10px; }
.progress {
  height: 9px;
  margin-top: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
}
.ghost {
  border: 0;
  background: transparent;
  color: var(--green);
  font-weight: 700;
}
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--green);
  box-shadow: 0 12px 26px rgba(8, 127, 117, .3);
  font-size: 32px;
  display: grid;
  place-items: center;
  line-height: 1;
}
.fab-menu {
  display: grid;
  gap: 12px;
  padding: 16px;
}
.fab-choice {
  display: grid;
  grid-template-columns: 46px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  text-align: left;
  color: var(--ink);
  padding: 10px 12px;
}
.fab-choice span {
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 20px;
}
.fab-choice b { color: var(--ink); }
.fab-choice small { display: block; }
.fab-choice.income span { color: var(--green); background: #dcfce7; }
.fab-choice.expense span { color: var(--red); background: #fee2e2; }
.fab-choice.voice span { color: var(--blue); background: #dbeafe; }
.fab-choice.receipt span { color: #a16207; background: #fef3c7; }
dialog {
  width: min(94vw, 580px);
  max-height: 90vh;
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 22px 70px rgba(15, 23, 42, .26);
  color: var(--ink);
  overflow: auto;
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
.quick-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}
.voice-box {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: 8px;
  background: #eef7f5;
}
.voice-box > div { min-width: 0; }
.voice-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: stretch; }
.voice-retry-btn { min-height: 48px; padding: 0 18px; border: 1px solid var(--teal); border-radius: 8px; background: var(--surface); color: var(--teal); font: inherit; font-weight: 800; cursor: pointer; }
.voice-retry-btn:active { transform: translateY(1px); }
.voice-box strong, .settings-card strong { color: var(--ink); }
.voice-box p { margin: 3px 0 0; color: var(--muted); }
.settings-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}
.settings-nav { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.settings-nav button { min-height: 42px; padding: 0 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--muted); font-weight: 800; white-space: nowrap; }
.settings-nav button.active { background: var(--green); border-color: var(--green); color: white; }
.profile-editor {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wallet-settings {
  display: grid;
  gap: 12px;
}
.wallet-setting-row {
  display: grid;
  grid-template-columns: 12px 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.inline-manager { display: grid; grid-template-columns: 1fr 1fr auto; gap: 10px; padding: 12px 0; }
.manager-list { display: grid; gap: 8px; }
.manager-item { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; }
.manager-item strong { flex: 1; }
.danger-link { border: 0; background: transparent; color: var(--red); min-width: 44px; min-height: 44px; }
.wallet-setting-row .danger-link { white-space: nowrap; }
.wallet-setting-row .dot {
  align-self: center;
}
.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
}
.check-row input {
  width: 18px;
  height: 18px;
  padding: 0;
}
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.mic {
  flex: 0 0 auto;
  width: 54px;
  height: 54px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--green);
  font-size: 24px;
}
.mic.listening { animation: pulse 1s infinite; background: var(--red); }
@keyframes pulse { 50% { transform: scale(1.06); } }
.voice-box.listening {
  outline: 2px solid rgba(15, 118, 110, .24);
  background: #ecfdf5;
}
.quick-action:active,
.tx-action:active,
.fab:active,
.primary:active,
.secondary:active {
  transform: translateY(1px);
}
.voice-level {
  display: none;
  align-items: end;
  gap: 3px;
  height: 22px;
  margin-top: 8px;
}
.voice-box.listening .voice-level { display: flex; }
.voice-level span {
  width: 4px;
  border-radius: 999px;
  background: var(--green);
  animation: voiceWave .76s infinite ease-in-out;
}
.voice-level span:nth-child(1) { height: 8px; animation-delay: 0s; }
.voice-level span:nth-child(2) { height: 16px; animation-delay: .08s; }
.voice-level span:nth-child(3) { height: 11px; animation-delay: .16s; }
.voice-level span:nth-child(4) { height: 20px; animation-delay: .24s; }
.voice-level span:nth-child(5) { height: 13px; animation-delay: .32s; }
@keyframes voiceWave {
  0%, 100% { transform: scaleY(.45); opacity: .55; }
  50% { transform: scaleY(1); opacity: 1; }
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-wide { grid-column: 1 / -1; }
.receipt-sheet {
  display: grid;
  gap: 16px;
  padding: 18px;
}
.receipt-step {
  display: grid;
  gap: 14px;
}
.receipt-step[hidden] { display: none; }
.receipt-source-btn { width: 100%; }
.receipt-camera-mark {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  margin: 8px auto 2px;
  border-radius: 50%;
  color: var(--green);
  background: #dff5f1;
  font-size: 30px;
}
#receiptSourceStep { text-align: center; }
.receipt-photo-frame {
  display: grid;
  place-items: center;
  min-height: 260px;
  max-height: 52vh;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf2f4;
}
.receipt-photo-frame img {
  display: block;
  max-width: 100%;
  max-height: 52vh;
  object-fit: contain;
}
.receipt-photo-frame.viewer { min-height: 320px; }
.receipt-loader {
  width: 48px;
  height: 48px;
  margin: 44px auto 6px;
  border: 4px solid #cfe9e5;
  border-top-color: var(--green);
  border-radius: 50%;
  animation: receiptSpin .8s linear infinite;
}
#receiptLoadingStep { min-height: 220px; place-content: center; text-align: center; }
@keyframes receiptSpin { to { transform: rotate(360deg); } }
.receipt-result-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.receipt-result-head img {
  width: 64px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: cover;
}
.receipt-warning {
  margin: 0;
  padding: 11px 12px;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  color: #92400e;
  background: #fffbeb;
  font-size: 13px;
  font-weight: 750;
}
.receipt-ocr-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--muted);
}
.receipt-ocr-details summary { cursor: pointer; font-weight: 750; }
.receipt-ocr-details pre {
  margin: 12px 0 0;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink);
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.receipt-viewer-meta { display: grid; gap: 4px; }
.receipt-action { color: #a16207; }
body[data-theme="dark"] .receipt-camera-mark { background: #183c38; color: #5eead4; }
body[data-theme="dark"] .receipt-photo-frame { background: #0b1220; }
body[data-theme="dark"] .receipt-warning { background: #3b2b0d; border-color: #b45309; color: #fde68a; }
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.primary, .secondary {
  min-height: 46px;
  border-radius: 8px;
  font-weight: 800;
  padding: 0 16px;
}
.primary {
  border: 0;
  color: white;
  background: var(--green);
}
.primary:hover, .install-btn:hover { background: var(--green-strong); }
.secondary {
  border: 1px solid var(--green);
  color: var(--green);
  background: white;
}
.welcome-form {
  text-align: center;
}
.welcome-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 4px auto 0;
  border-radius: 50%;
  color: white;
  background: var(--green);
  font-size: 31px;
  font-weight: 900;
}
.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: 560px;
  margin: 0 auto;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 18px 42px rgba(15, 23, 42, .18);
  font-weight: 800;
}

@media (max-width: 640px) {
  .shell { padding: max(14px, env(safe-area-inset-top)) 12px calc(96px + env(safe-area-inset-bottom)); }
  .topbar { align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .install-btn { min-height: 34px; padding-inline: 12px; }
  .balance-panel { padding: 20px 18px 16px; }
  .balance-panel strong { font-size: 30px; }
  .quick-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .quick-action { min-height: 104px; font-size: 15px; padding: 12px 8px; gap: 10px; }
  .quick-action span { width: 40px; height: 40px; font-size: 18px; }
  .month-stats article { padding: 13px; }
  .month-stats b { font-size: 18px; }
  .tabs { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 14px 0 18px; }
  .tab { min-height: 46px; padding: 0 3px; font-size: 12px; }
  .account-list { grid-template-columns: repeat(2, minmax(0, 1fr)); overflow: visible; }
  .account { min-height: 146px; padding: 16px; }
  .account p { font-size: 16px; }
  .account b { font-size: 20px; }
  .chart-card { grid-template-columns: 1fr; }
  .donut { margin: 0 auto; }
  .form-grid { grid-template-columns: 1fr; }
  .voice-actions { grid-template-columns: 1fr; }
  .form-wide { grid-column: auto; }
  .wallet-setting-row { grid-template-columns: 12px 1fr; }
  .wallet-setting-row label:last-child { grid-column: 2; }
  .wallet-setting-row .danger-link { grid-column: 2; justify-self: start; }
  .inline-manager { grid-template-columns: 1fr; }
  .button-row { grid-template-columns: 1fr; }
  .filters { display: grid; }
  .filters select { width: 100%; }
  dialog { width: 100%; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: 12px 12px 0 0; }
  .receipt-dialog { max-height: 96dvh; }
  .receipt-sheet { padding: 16px 14px calc(18px + env(safe-area-inset-bottom)); }
  .receipt-photo-frame { min-height: 220px; max-height: 42dvh; }
  .receipt-photo-frame img { max-height: 42dvh; }
  .receipt-result-actions { position: sticky; bottom: 0; padding-top: 8px; background: var(--surface); }
  .quick-form { gap: 14px; padding: 18px 16px calc(22px + env(safe-area-inset-bottom)); }
  .quick-form label { font-size: 15px; }
  .quick-form input, .quick-form select, .quick-form textarea { min-height: 54px; font-size: 17px; }
  .settings-nav { margin-inline: -2px; }
  .auth-dialog { width: min(92vw, 440px); margin: auto; border-radius: 8px; }
  .tx { align-items: flex-start; flex-wrap: wrap; }
  .tx-actions { width: 100%; justify-content: flex-end; }
}

@media (max-width: 420px) {
  .topbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .profile-head h1 { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 21px; }
  .top-actions { flex-wrap: nowrap; gap: 6px; }
  .install-btn { min-width: 0; padding-inline: 8px; font-size: 12px; }
  .icon-btn { width: 38px; height: 38px; }
  .account-list { grid-template-columns: 1fr; }
  .account { min-height: 126px; }
  .account b { overflow-wrap: anywhere; }
}
