:root {
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f6f3ee;
  --text: #242424;
  --muted: #6f6a64;
  --border: #ddd6cc;
  --accent: #2f6f73;
  --income: #2f7d45;
  --expense: #c84b45;
  --shadow: none;
  --radius: 8px;
  color-scheme: light;
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 255, 255, 0.96), rgba(251, 250, 247, 0.94) 42%, var(--bg) 100%);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  max-width: 520px;
  margin: 0 auto;
  padding: calc(26px + env(safe-area-inset-top)) 18px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: center;
  gap: 16px;
  margin: 0 -18px 18px;
  padding: 0 18px 20px;
  border-bottom: 1px solid rgba(221, 214, 204, 0.85);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
  font-size: 34px;
  line-height: 1;
  font-weight: 750;
  letter-spacing: 0;
  text-align: center;
}

h2 {
  margin-bottom: 0;
  font-size: 22px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 12px;
  font-size: 16px;
}

.content {
  display: block;
}

.view {
  display: none;
}

.view-active {
  display: block;
}

.summary-panel,
.filter-panel,
.backup-panel,
.analysis-block,
.dialog-card {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: var(--shadow);
}

.summary-panel {
  padding: 14px 0 0;
  margin-bottom: 18px;
}

.free-money-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 0;
  border-bottom: 1px solid var(--border);
  border-top: 1px solid var(--border);
}

.free-money-row span {
  display: grid;
  gap: 3px;
}

.free-money-row small {
  color: var(--muted);
  font-size: 12px;
}

.free-money-row > strong {
  font-size: 24px;
  white-space: nowrap;
}

.summary-grid span,
.metric span,
.transaction-main small,
.category-row small,
.budget-row span,
.progress-row span {
  color: var(--muted);
  font-size: 13px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  padding: 10px 0 24px;
}

.summary-grid div {
  display: grid;
  gap: 16px;
  justify-items: center;
  padding: 0 10px;
  text-align: center;
  border-right: 1px solid var(--border);
}

.summary-grid div:last-child {
  border-right: 0;
}

.summary-grid strong {
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
}

.summary-grid span {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.income-text {
  color: var(--income);
}

.expense-text {
  color: var(--expense);
}

.balance-text {
  color: var(--text);
}

.quick-entry {
  display: grid;
  gap: 10px;
  margin: 0 0 26px;
}

.filter-row,
.dialog-actions {
  display: flex;
  gap: 8px;
}

.filter-row > * {
  flex: 1;
}

.primary-button,
.secondary-button,
.small-button,
.danger-button,
.icon-button,
.segment,
.nav-item,
.file-import {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 42px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.add-transaction-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  min-height: 64px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(90deg, #257174, #1f777a);
  color: #fff;
  box-shadow: 0 10px 20px rgba(47, 111, 115, 0.17);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.add-transaction-button svg {
  width: 29px;
  height: 29px;
  padding: 4px;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 999px;
}

.secondary-button,
.small-button,
.file-import {
  background: var(--surface-2);
}

.danger-button {
  border-color: rgba(200, 75, 69, 0.35);
  color: var(--expense);
  background: #fff7f6;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  justify-self: end;
  color: var(--accent);
  border: 2px solid rgba(47, 111, 115, 0.85);
  border-radius: 999px;
  background: transparent;
}

.topbar-left {
  justify-self: start;
  color: var(--text);
  border: 0;
}

.topbar-left svg {
  width: 31px;
  height: 31px;
  stroke-width: 1.9;
}

.icon-button.quiet {
  border: 0;
  background: transparent;
  box-shadow: none;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.month-hero {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  margin: 0 0 28px;
}

.month-arrow {
  border: 0;
  background: transparent;
  color: var(--text);
}

.month-arrow {
  display: grid;
  place-items: center;
  min-height: 44px;
}

.month-arrow svg {
  width: 34px;
  height: 34px;
  stroke-width: 1.8;
}

.month-title {
  display: grid;
  align-items: center;
  justify-content: center;
  gap: 3px 7px;
  min-height: 48px;
  font-size: 28px;
  font-weight: 800;
  text-transform: capitalize;
}

.month-title span {
  grid-row: 1;
}

.month-title small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: none;
}

.filter-panel {
  display: grid;
  gap: 10px;
  padding: 18px 0 0;
  margin: 18px 0 0;
  border-top: 1px solid var(--border);
  border-bottom: 0;
}

.utility-filter {
  margin-top: 520px;
}

.filter-panel summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  list-style: none;
}

.filter-panel summary::-webkit-details-marker {
  display: none;
}

.filter-panel[open] summary {
  margin-bottom: 8px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.35;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47, 111, 115, 0.14);
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 30px 0 16px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
}

.transaction-list,
.category-list,
.recurring-list,
.account-list {
  display: grid;
  gap: 0;
}

.transaction-row,
.category-row,
.recurring-row,
.account-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 14px 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.category-row {
  grid-template-columns: auto 1fr;
}

.recurring-row {
  grid-template-columns: auto 1fr auto;
}

.account-row {
  grid-template-columns: 1fr auto;
}

.account-row-active strong {
  color: var(--accent);
}

.transaction-main,
.category-row span:last-child,
.recurring-row span:nth-child(2),
.account-row span:first-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.transaction-main strong,
.category-row strong,
.recurring-row strong,
.account-row strong {
  overflow-wrap: anywhere;
}

.recurring-row small,
.account-row small {
  color: var(--muted);
  font-size: 12px;
}

.settings-block {
  padding: 18px 0 6px;
  border-top: 1px solid var(--border);
}

.settings-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.settings-heading h3 {
  margin: 0;
}

.settings-heading span {
  color: var(--muted);
  font-size: 13px;
}

.settings-form {
  display: grid;
  gap: 12px;
}

.settings-form label,
.settings-select {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.settings-form input,
.settings-select select {
  width: 100%;
}

.category-dot {
  width: 9px;
  height: 42px;
  border-radius: 999px;
  background: var(--dot);
}

.empty-state,
.mini-empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  background: rgba(255, 255, 255, 0.28);
  color: var(--muted);
}

.empty-state {
  display: grid;
  gap: 10px;
  min-height: 174px;
  place-items: center;
  text-align: center;
}

.empty-state svg {
  width: 42px;
  height: 42px;
  color: #93a7a8;
  stroke-width: 1.5;
}

.empty-state strong {
  color: var(--text);
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  display: grid;
  gap: 6px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 14px;
  background: var(--surface);
}

.metric strong {
  font-size: 20px;
}

.metric.good strong {
  color: var(--income);
}

.metric.bad strong {
  color: var(--expense);
}

.metric.balance strong {
  color: var(--text);
}

.analysis-block {
  padding: 18px 0;
  margin-top: 0;
  border-top: 1px solid var(--border);
}

.progress-row,
.budget-row {
  display: grid;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.budget-preview {
  display: grid;
  gap: 8px;
}

.budget-preview-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  padding: 14px 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.budget-preview-row > div {
  display: grid;
  gap: 7px;
}

.budget-preview-row small {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.budget-empty {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 15px 0;
  background: transparent;
  color: var(--accent);
  text-align: left;
}

.budget-empty span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid currentColor;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
}

.progress-row:last-child,
.budget-row:last-child {
  border-bottom: 0;
}

.progress-row div:first-child,
.budget-row div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.budget-row small {
  color: var(--muted);
  font-size: 12px;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}

.stat-row:last-child {
  border-bottom: 0;
}

.stat-row span {
  display: grid;
  gap: 3px;
}

.stat-row small {
  color: var(--muted);
  font-size: 12px;
}

.stat-row > strong {
  white-space: nowrap;
}

.cashflow-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cashflow-row:last-child {
  border-bottom: 0;
}

.cashflow-row span:nth-child(2) {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.cashflow-row small {
  color: var(--muted);
  font-size: 12px;
}

.cashflow-row strong {
  overflow-wrap: anywhere;
}

.date-chip {
  min-width: 46px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 7px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.year-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.year-category-list {
  margin-top: 12px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #eee8df;
}

.progress-track span {
  display: block;
  height: 100%;
}

.progress-track .over {
  background: var(--expense) !important;
}

.trend-bars {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  align-items: end;
  min-height: 150px;
}

.trend-item {
  display: grid;
  gap: 6px;
  align-items: end;
  text-align: center;
}

.trend-item span {
  width: 100%;
  min-height: 8px;
  border-radius: 6px 6px 2px 2px;
  background: var(--accent);
}

.trend-item small {
  color: var(--muted);
  font-size: 11px;
}

.trend-item strong {
  font-size: 11px;
  font-weight: 700;
}

.backup-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.backup-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.file-import {
  display: grid;
  place-items: center;
  min-height: 42px;
  color: var(--text);
}

.file-import input {
  display: none;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  width: min(520px, 100%);
  padding: 9px 12px calc(10px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  border-top: 1px solid var(--border);
  background: rgba(251, 250, 247, 0.94);
  backdrop-filter: blur(18px);
}

.nav-item {
  display: grid;
  place-items: center;
  gap: 5px;
  min-height: 58px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.nav-item svg {
  width: 28px;
  height: 28px;
  stroke-width: 1.8;
}

.nav-active {
  color: var(--accent);
  background: transparent;
}

.dialog {
  width: min(92vw, 460px);
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 28px);
  border: 0;
  padding: 0;
  background: transparent;
  overflow: hidden;
}

.dialog::backdrop {
  background: rgba(36, 33, 29, 0.32);
  backdrop-filter: blur(4px);
}

.dialog-card {
  display: grid;
  gap: 12px;
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

.dialog-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.segment {
  border: 0;
  background: transparent;
}

.segment-active[data-transaction-type="expense"] {
  background: var(--expense);
  color: #fff;
}

.segment-active[data-transaction-type="income"] {
  background: var(--income);
  color: #fff;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.dialog-actions {
  position: sticky;
  bottom: calc(-16px - env(safe-area-inset-bottom));
  justify-content: flex-end;
  flex-wrap: wrap;
  margin: 4px -16px calc(-16px - env(safe-area-inset-bottom));
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.dialog-actions button {
  padding: 0 14px;
}

.hidden {
  display: none !important;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 14px;
  transform: translate(-50%, 18px);
  border-radius: var(--radius);
  background: var(--text);
  color: white;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (min-width: 760px) {
  body {
    background:
      linear-gradient(90deg, rgba(47, 111, 115, 0.08), transparent 24%, transparent 76%, rgba(200, 75, 69, 0.07)),
      var(--bg);
  }

  .app-shell {
    padding-top: 28px;
  }
}
