:root {
  --bg: #f2f1ed;
  --surface: #ffffff;
  --surface-soft: #f7f6f2;
  --text: #191c1b;
  --muted: #717773;
  --line: #e4e3de;
  --green: #176b51;
  --green-bright: #3eaa80;
  --green-soft: #dceee6;
  --amber: #d69b36;
  --red: #d75d5d;
  --violet: #7766bd;
  --shadow: 0 12px 36px rgba(34, 42, 38, 0.07);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 90% 0%, rgba(23, 107, 81, 0.12), transparent 30%),
    var(--bg);
  color: var(--text);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  width: min(100%, 800px);
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px
    calc(48px + env(safe-area-inset-bottom));
}

.topbar,
.section-heading,
.hero-heading,
.transaction-title,
.transaction-meta,
.transaction-footer,
.debt-row,
.batch-row,
.obligation-card,
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  align-items: flex-start;
  margin: 4px 2px 16px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  margin-top: 3px;
  font-size: clamp(28px, 7vw, 40px);
  line-height: 1.05;
  letter-spacing: -0.045em;
}

h2 {
  margin-top: 2px;
  font-size: 21px;
  letter-spacing: -0.025em;
}

.eyebrow,
.card-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.mode-badge,
.count-pill,
.status,
.small-badge,
.change-pill {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.mode-badge {
  max-width: 45%;
  overflow: hidden;
  padding: 8px 10px;
  background: var(--green-soft);
  color: var(--green);
  text-overflow: ellipsis;
}

.tabbar {
  position: sticky;
  z-index: 5;
  top: max(8px, env(safe-area-inset-top));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 0 0 12px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: 0 7px 22px rgba(34, 42, 38, 0.06);
  backdrop-filter: blur(18px);
}

.tab-button {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 730;
  cursor: pointer;
}

.tab-button.active {
  background: var(--text);
  color: var(--surface);
}

.filters {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.filters label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.filters input,
.filters select {
  min-width: 0;
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.filters input:focus,
.filters select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(23, 107, 81, 0.12);
}

.tab-page {
  display: none;
}

.tab-page.active {
  display: block;
}

.hero-card,
.panel,
.status-card,
.obligation-card {
  border: 1px solid rgba(255, 255, 255, 0.65);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.hero-card {
  overflow: hidden;
  position: relative;
  border-radius: 25px;
  padding: 23px;
  background: linear-gradient(135deg, #163f35, #176e53);
  color: white;
}

.hero-card::after {
  content: "";
  position: absolute;
  width: 180px;
  height: 180px;
  right: -70px;
  top: -85px;
  border: 26px solid rgba(255, 255, 255, 0.08);
  border-radius: 50%;
}

.hero-card .card-label {
  color: rgba(255, 255, 255, 0.67);
}

.period-label {
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 13px;
}

.change-pill {
  position: relative;
  z-index: 1;
  padding: 7px 9px;
  background: rgba(255, 255, 255, 0.13);
  color: white;
}

.change-pill.up {
  background: rgba(255, 196, 122, 0.17);
  color: #ffe2b4;
}

.change-pill.down {
  background: rgba(184, 255, 220, 0.15);
  color: #c5f8dd;
}

.hero-amount {
  margin: 12px 0 22px;
  font-size: clamp(42px, 13vw, 64px);
  font-weight: 760;
  letter-spacing: -0.055em;
}

.hero-breakdown {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 24px;
  color: rgba(255, 255, 255, 0.67);
  font-size: 13px;
}

.hero-breakdown strong {
  display: block;
  color: white;
  font-size: 15px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.status-card {
  position: relative;
  border-radius: 17px;
  padding: 14px;
}

.status-card strong {
  display: block;
  margin-top: 12px;
  font-size: 23px;
  letter-spacing: -0.03em;
}

.status-card p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.metric-dot {
  display: block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.green { background: var(--green-bright); }
.amber { background: var(--amber); }
.red { background: var(--red); }

.obligation-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 10px;
}

.obligation-card {
  min-height: 92px;
  border-radius: 19px;
  padding: 16px;
}

.obligation-card strong {
  display: block;
  margin-top: 8px;
  font-size: 23px;
  letter-spacing: -0.035em;
}

.obligation-card.inactive {
  border-style: dashed;
  box-shadow: none;
  opacity: 0.72;
}

.small-badge {
  padding: 5px 7px;
  background: var(--surface-soft);
  color: var(--muted);
}

.arrow-chip {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 12px;
  background: var(--green-soft);
  color: var(--green);
  font-size: 18px;
  font-weight: 800;
}

.panel {
  margin-top: 12px;
  border-radius: 22px;
  padding: 19px;
}

.section-heading {
  align-items: flex-start;
  margin-bottom: 17px;
}

.count-pill {
  min-width: 30px;
  padding: 6px 9px;
  background: var(--surface-soft);
  color: var(--muted);
  text-align: center;
}

.chart-legend {
  display: flex;
  gap: 9px;
  color: var(--muted);
  font-size: 10px;
}

.chart-legend span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chart-legend i {
  display: inline-block;
  width: 15px;
  border-top: 2px solid var(--green);
}

.chart-legend .forecast-key {
  border-top: 2px dashed var(--violet);
}

#trajectory-chart {
  display: block;
  width: 100%;
  height: 210px;
}

.budget-copy {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.budget-copy strong {
  font-size: 26px;
  letter-spacing: -0.035em;
}

.budget-copy span,
.panel-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.budget-track {
  height: 11px;
  overflow: hidden;
  margin: 14px 0 10px;
  border-radius: 999px;
  background: var(--surface-soft);
}

.budget-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--green-bright));
  transition: width 350ms ease;
}

.budget-fill.over {
  background: linear-gradient(90deg, var(--amber), var(--red));
}

.category-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  padding: 9px 0;
}

.category-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.category-copy span,
.debt-row span,
.batch-row span,
.account-copy span,
.account-balance span {
  color: var(--muted);
  font-size: 12px;
}

.bar-track {
  grid-column: 1 / -1;
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1c8767, #6cbaa0);
}

.debt-row,
.batch-row,
.account-row {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.debt-row:first-child,
.batch-row:first-child,
.account-row:first-child {
  padding-top: 0;
  border-top: 0;
}

.debt-row:last-child,
.batch-row:last-child,
.account-row:last-child {
  padding-bottom: 0;
}

.debt-row > div,
.batch-row > div {
  display: flex;
  flex: 1;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.avatar,
.account-symbol {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  place-items: center;
  border-radius: 13px;
  background: #ece8fa;
  color: #5c4da4 !important;
  font-size: 15px !important;
  font-weight: 800;
  text-transform: uppercase;
}

.account-symbol {
  background: var(--green-soft);
  color: var(--green) !important;
}

.account-copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-direction: column;
  gap: 3px;
}

.account-balance {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: right;
}

.account-balance.muted strong {
  color: var(--muted);
  font-size: 12px;
}

.transaction-row {
  display: flex;
  gap: 11px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.transaction-row:first-child {
  padding-top: 0;
  border-top: 0;
}

.transaction-row:last-child {
  padding-bottom: 0;
}

.transaction-icon {
  display: grid;
  width: 39px;
  height: 39px;
  flex: 0 0 39px;
  place-items: center;
  border-radius: 13px;
  background: #e4f2ec;
  color: var(--green);
  font-size: 19px;
  font-weight: 800;
}

.transaction-icon.transfer {
  background: #eeeafa;
  color: #6351af;
}

.transaction-main {
  min-width: 0;
  flex: 1;
}

.transaction-title strong:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transaction-meta {
  justify-content: flex-start;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.transaction-meta span + span::before {
  content: "·";
  margin-right: 8px;
}

.transaction-footer {
  margin-top: 8px;
}

code {
  overflow: hidden;
  color: #7b817e;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 10px;
  text-overflow: ellipsis;
}

.status {
  padding: 5px 8px;
  background: var(--surface-soft);
  color: var(--muted);
  text-transform: capitalize;
}

.status.synced,
.status.imported,
.status.imported_corrected {
  background: #e2f2e9;
  color: #176548;
}

.status.pending,
.status.awaiting_import {
  background: #fff0d2;
  color: #8a5b0d;
}

.status.failed {
  background: #fde5e5;
  color: #a63d3d;
}

#balance-chart {
  display: block;
  width: 100%;
  height: 220px;
  margin-top: 8px;
}

.secondary-button,
.primary-button,
.icon-button {
  border: 0;
  cursor: pointer;
  font-weight: 750;
}

.secondary-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
}

.primary-button {
  width: 100%;
  min-height: 48px;
  border-radius: 14px;
  background: var(--green);
  color: white;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.balance-dialog {
  width: min(calc(100% - 24px), 460px);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.28);
}

.balance-dialog::backdrop {
  background: rgba(6, 12, 9, 0.58);
  backdrop-filter: blur(5px);
}

.balance-dialog form {
  display: grid;
  gap: 15px;
  padding: 22px;
}

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

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

.balance-dialog input,
.balance-dialog select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 0 12px;
  background: var(--surface-soft);
  color: var(--text);
}

.dialog-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.form-error {
  border-radius: 12px;
  padding: 10px;
  background: #fff0f0;
  color: #9c3636;
  font-size: 12px;
}

.loading-state,
.error-panel,
.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.spinner {
  display: block;
  width: 24px;
  height: 24px;
  margin: 0 auto 12px;
  border: 3px solid var(--line);
  border-top-color: var(--green);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.error-panel {
  border: 1px solid #f1caca;
  border-radius: 18px;
  background: #fff1f1;
  color: #8f3939;
}

.hidden {
  display: none !important;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 560px) {
  .app-shell {
    padding-inline: 12px;
  }

  .filters {
    grid-template-columns: 1.25fr 1fr;
  }

  .filters label:last-child {
    grid-column: 1 / -1;
  }

  .hero-card,
  .panel {
    border-radius: 20px;
  }

  .hero-amount {
    font-size: 48px;
  }

  .status-card {
    padding: 12px;
  }

  .status-card strong {
    font-size: 21px;
  }

  .obligation-grid {
    grid-template-columns: 1fr;
  }

  .chart-panel .section-heading {
    display: block;
  }

  .chart-legend {
    margin-top: 8px;
  }

  .transaction-meta {
    flex-wrap: wrap;
    gap: 2px 8px;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111614;
    --surface: #19201d;
    --surface-soft: #232b27;
    --text: #f0f3f1;
    --muted: #a2aaa6;
    --line: #303934;
    --shadow: none;
  }

  .hero-card {
    background: linear-gradient(135deg, #174236, #175e49);
  }

  .filters input,
  .filters select {
    color-scheme: dark;
  }

  .tabbar {
    border-color: rgba(255, 255, 255, 0.08);
    background: rgba(25, 32, 29, 0.88);
  }
}
