:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #17202a;
  --muted: #66727f;
  --line: #dce2e8;
  --green: #1c9b67;
  --red: #d34f4f;
  --blue: #2c72d2;
  --yellow: #d9a21b;
  --shadow: 0 18px 45px rgba(22, 31, 42, 0.13);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101316;
  --surface: #1a2026;
  --surface-2: #252d34;
  --text: #f1f4f7;
  --muted: #a1acb7;
  --line: #303943;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.36);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

body.modal-lock {
  overflow: hidden;
}

.login-page {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-card {
  width: min(100%, 380px);
  display: grid;
  gap: 14px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100svh;
  max-width: 780px;
  margin: 0 auto;
  padding: 18px 16px 92px;
}

.topbar,
.section-head,
.sheet-head,
.balance-grid,
.quick-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  margin-bottom: 16px;
}

.eyebrow,
.muted,
.hint {
  color: var(--muted);
  margin: 0;
}

.eyebrow {
  font-size: 0.78rem;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 1.85rem;
}

h2 {
  font-size: 1.08rem;
}

h3 {
  margin: 6px 0 0;
  font-size: 1rem;
}

.icon-button,
.text-button,
.chip,
.nav-item {
  border: 0;
  color: var(--text);
  background: var(--surface-2);
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-size: 1.5rem;
  display: grid;
  place-items: center;
}

.summary,
.accounts-section,
.transactions-section {
  margin-bottom: 16px;
}

.summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.period-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.chip {
  min-height: 38px;
  border-radius: 999px;
}

.chip.active,
.nav-item.active {
  background: var(--text);
  color: var(--surface);
}

.balance-grid {
  align-items: flex-start;
}

.balance-grid strong {
  display: block;
  margin-top: 4px;
  font-size: 2rem;
}

.mini-stats {
  display: grid;
  gap: 6px;
  text-align: right;
  color: var(--muted);
  font-size: 0.92rem;
}

.mini-stats b {
  color: var(--text);
  display: block;
}

.chart-wrap {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 16px;
  align-items: center;
  margin-top: 18px;
}

.donut {
  width: 150px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: conic-gradient(var(--surface-2) 0 100%);
  position: relative;
}

.donut::after {
  content: "";
  position: absolute;
  inset: 32px;
  border-radius: 50%;
  background: var(--surface);
}

.legend {
  display: grid;
  gap: 8px;
}

.legend-row {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.9rem;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.action,
.primary-button {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  color: white;
  font-weight: 700;
}

.expense {
  background: var(--red);
}

.income {
  background: var(--green);
}

.transfer {
  background: var(--blue);
}

.accounts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.account-card,
.transaction,
.category-row,
.setting-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.account-card {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.account-card span,
.transaction span {
  color: var(--muted);
  font-size: 0.85rem;
}

.account-card strong {
  display: block;
  font-size: 1.2rem;
}

.card-actions,
.panel-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.small-button {
  min-height: 34px;
  border: 0;
  border-radius: 8px;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--text);
}

.section-head {
  margin: 18px 0 10px;
}

.text-button {
  min-height: 36px;
  border-radius: 999px;
  padding: 0 14px;
}

#accountFilter {
  max-width: 180px;
}

.search-input {
  margin-bottom: 10px;
}

.transactions {
  display: grid;
  gap: 8px;
}

.transaction {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(96px, auto);
  gap: 10px;
  align-items: center;
  padding: 10px;
}

.category-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 800;
}

.transaction-title {
  font-weight: 700;
}

.transaction-amount {
  max-width: 180px;
  text-align: right;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.transaction-actions {
  display: grid;
  gap: 6px;
  justify-items: end;
}

.row-buttons {
  display: flex;
  gap: 6px;
}

.row-buttons button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 800;
}

.transaction-amount.income {
  color: var(--green);
  background: transparent;
}

.transaction-amount.expense {
  color: var(--red);
  background: transparent;
}

.transaction-amount.transfer {
  color: var(--blue);
  background: transparent;
}

.bottom-nav {
  position: fixed;
  left: max(12px, calc((100vw - 780px) / 2 + 12px));
  right: max(12px, calc((100vw - 780px) / 2 + 12px));
  bottom: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.nav-item {
  min-height: 42px;
  border-radius: 8px;
}

dialog {
  width: min(94vw, 500px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

dialog.app-dialog-open {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100svh;
  max-width: none;
  max-height: none;
  display: grid;
  place-items: end center;
  margin: 0;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
  z-index: 30;
}

dialog.app-dialog-open .sheet {
  width: min(100%, 500px);
  max-height: calc(100svh - 32px);
  overflow: auto;
}

dialog.app-dialog-open .panel {
  max-height: calc(100svh - 32px);
}

.sheet {
  display: grid;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--surface-2);
  color: var(--text);
}

.field-title {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

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

.category-option {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 6px;
}

.category-option.active {
  outline: 3px solid var(--blue);
}

.transfer-fields {
  display: none;
  gap: 12px;
}

.transfer-fields.active {
  display: grid;
}

.primary-button {
  background: var(--text);
}

.danger-button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  background: var(--red);
  color: white;
  font-weight: 800;
}

.panel {
  max-height: 82svh;
  overflow: auto;
}

.category-row,
.setting-row {
  display: grid;
  grid-template-columns: 16px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  margin-bottom: 8px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr 130px 64px;
  gap: 8px;
  align-items: end;
  margin-bottom: 12px;
}

.inline-form button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  font-weight: 800;
}

.settings-block {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: 8px;
}

.settings-block h3 {
  margin: 0;
}

.report-grid {
  display: grid;
  gap: 10px;
}

.report-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.bar {
  height: 8px;
  margin-top: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--blue);
}

.import-label {
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.empty {
  padding: 26px 12px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.confirm-sheet {
  gap: 18px;
}

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

.toast-stack {
  position: fixed;
  left: max(12px, calc((100vw - 780px) / 2 + 12px));
  right: max(12px, calc((100vw - 780px) / 2 + 12px));
  bottom: 84px;
  display: grid;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
}

.toast {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.toast.error {
  background: var(--red);
}

.toast.success {
  background: var(--green);
}

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

  .chart-wrap {
    grid-template-columns: 126px 1fr;
    gap: 12px;
  }

  .donut {
    width: 126px;
  }

  .balance-grid {
    display: grid;
  }

  .mini-stats {
    grid-template-columns: repeat(2, 1fr);
    text-align: left;
  }

  .quick-actions,
  .accounts {
    grid-template-columns: 1fr;
  }

  .category-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .inline-form {
    grid-template-columns: 1fr;
  }
}
