:root {
  --color-bg: #fafafa;
  --color-surface: #ffffff;
  --color-text: #1c1b1f;
  --color-text-muted: #6f6a75;
  --color-border: #e6e1e5;
  --color-primary: #6750a4;
  --color-primary-text: #ffffff;
  --color-danger: #ba1a1a;
  --nav-height: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #141218;
    --color-surface: #1d1b20;
    --color-text: #e6e1e5;
    --color-text-muted: #948f99;
    --color-border: #3a3740;
    --color-primary: #d0bcff;
    --color-primary-text: #381e72;
    --color-danger: #ffb4ab;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  overscroll-behavior-y: none;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
}

/* ---------- Layout ---------- */

.page-content {
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom, 0px) + 16px);
  max-width: 640px;
  margin: 0 auto;
}

h1 {
  font-size: 22px;
  margin: 8px 0 16px;
}

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 16px;
}

.empty-state {
  color: var(--color-text-muted);
  font-size: 14px;
}

.account-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.account-list__item {
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}

.account-list__item:last-child {
  border-bottom: none;
}

/* ---------- Bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  z-index: 10;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--color-text-muted);
  min-height: 48px;
}

.nav-item svg {
  width: 22px;
  height: 22px;
}

.nav-item.active {
  color: var(--color-primary);
}

.nav-item[aria-disabled="true"] {
  opacity: 0.35;
  pointer-events: none;
}

.nav-item-add {
  position: relative;
}

.nav-item-add svg {
  width: 28px;
  height: 28px;
  background: var(--color-primary);
  color: var(--color-primary-text);
  border-radius: 50%;
  padding: 8px;
  width: 44px;
  height: 44px;
  margin-top: -20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* ---------- Auth / login page ---------- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
}

.login-page {
  width: 100%;
  max-width: 360px;
}

.login-subtitle {
  color: var(--color-text-muted);
  font-size: 14px;
  margin-top: 0;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 24px;
}

.login-form label {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 8px;
}

.login-form input {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 16px;
}

.login-form button {
  margin-top: 16px;
  padding: 12px;
  border-radius: 24px;
  border: none;
  background: var(--color-primary);
  color: var(--color-primary-text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.form-error {
  color: var(--color-danger);
  font-size: 13px;
  margin: 4px 0 0;
}

/* ---------- Flash messages ---------- */

.flash-list {
  margin-bottom: 12px;
}

.flash-message {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 8px;
  background: var(--color-primary);
  color: var(--color-primary-text);
  transition: opacity 0.3s ease;
}

.flash-message--error {
  background: var(--color-danger);
  color: #ffffff;
}

.flash-message--hidden {
  opacity: 0;
}

/* ---------- Headers / small buttons ---------- */

.row-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title {
  font-size: 15px;
  color: var(--color-text-muted);
  margin: 20px 0 8px;
}

.link-small {
  font-size: 13px;
  color: var(--color-primary);
}

.btn-small {
  font-size: 14px;
  color: var(--color-primary);
  font-weight: 600;
}

.badge {
  font-size: 11px;
  font-weight: 400;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1px 6px;
}

/* ---------- Lists (accounts / categories / transactions) ---------- */

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
  color: inherit;
}

.list-row:last-child {
  border-bottom: none;
}

.list-row--link {
  cursor: pointer;
}

.icon-badge {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-badge svg {
  width: 20px;
  height: 20px;
}

.list-row__main {
  flex: 1;
  min-width: 0;
}

.list-row__title {
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-row__meta {
  font-size: 12px;
  color: var(--color-text-muted);
}

.list-row__amount {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

.list-row__amount.positive {
  color: #2e7d32;
}

.list-row__amount.negative {
  color: var(--color-danger);
}

.list-row__action {
  font-size: 13px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.empty-state a {
  color: var(--color-primary);
  text-decoration: underline;
}

/* ---------- Home page cards ---------- */

.balance-card {
  text-align: center;
}

.balance-label {
  font-size: 13px;
  color: var(--color-text-muted);
}

.balance-value {
  font-size: 32px;
  font-weight: 700;
  margin-top: 4px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.stat-row--diff {
  border-top: 1px solid var(--color-border);
  margin-top: 4px;
  padding-top: 10px;
  font-weight: 600;
}

.positive {
  color: #2e7d32;
}

.negative {
  color: var(--color-danger);
}

/* ---------- Generic entity forms ---------- */

.entity-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}

.form-field label {
  font-size: 13px;
  color: var(--color-text-muted);
}

.form-field--checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.form-input,
.form-field select,
.form-field input[type="text"],
.form-field input[type="number"],
.form-field input[type="date"] {
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 16px;
  width: 100%;
}

.form-field input[type="color"] {
  width: 100%;
  height: 44px;
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.btn-primary,
.btn-secondary,
.btn-danger {
  padding: 12px;
  border-radius: 24px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
  margin-top: 8px;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--color-primary);
  color: var(--color-primary);
}

.btn-danger {
  background: transparent;
  border: 1px solid var(--color-danger);
  color: var(--color-danger);
  margin-top: 8px;
}

.transaction-extra-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ---------- Transaction type picker ---------- */

.type-choice {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 16px;
}

.type-choice__item {
  display: block;
  text-align: center;
  padding: 20px;
  border-radius: 16px;
  font-size: 17px;
  font-weight: 600;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.type-choice__item--expense {
  color: var(--color-danger);
}

.type-choice__item--income {
  color: #2e7d32;
}

/* ---------- Transaction form amount field ---------- */

.amount-field {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0 16px;
}

.amount-input {
  border: none;
  background: transparent;
  font-size: 40px;
  font-weight: 700;
  text-align: center;
  width: 100%;
  color: var(--color-text);
  -moz-appearance: textfield;
}

.amount-input::-webkit-outer-spin-button,
.amount-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.amount-suffix {
  position: absolute;
  right: calc(50% - 90px);
  font-size: 24px;
  color: var(--color-text-muted);
  pointer-events: none;
}

/* ---------- Filters (history / statistics) ---------- */

.filter-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

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

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

.filter-row .btn-primary,
.filter-row .btn-secondary {
  width: auto;
  padding: 10px 16px;
}

.period-range {
  color: var(--color-text-muted);
  font-size: 13px;
  margin: -8px 0 16px;
}

.chart-wrap {
  position: relative;
  height: 220px;
  margin-bottom: 12px;
}

/* ---------- Desktop ---------- */

@media (min-width: 900px) {
  .page-content {
    max-width: 720px;
    padding: 32px;
    padding-bottom: 32px;
  }

  .bottom-nav {
    left: 50%;
    transform: translateX(-50%);
    max-width: 480px;
    bottom: 24px;
    border: 1px solid var(--color-border);
    border-radius: 28px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  }
}
