:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #ef4444;
  --color-income: #16a34a;
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-text: #111827;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #111318;
    --color-surface: #1c1f26;
    --color-text: #f3f4f6;
    --color-muted: #9ca3af;
    --color-border: #2a2e37;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

#app-root {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  position: relative;
  background: var(--color-bg);
  padding-bottom: 76px;
}

#app-view {
  padding: 16px 16px 8px;
}

.loading, .empty-state {
  color: var(--color-muted);
  text-align: center;
  padding: 24px 0;
}

.error-banner {
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.error-text {
  color: var(--color-danger);
  font-size: 0.85rem;
  min-height: 1.2em;
}

/* Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.page-header h1 {
  font-size: 1.4rem;
  margin: 0;
}

/* Cards */
.card, .summary-card, .account-group, .recent-transactions, section {
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.summary-card {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.summary-card > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1;
}
.summary-card .label {
  font-size: 0.75rem;
  color: var(--color-muted);
  margin-bottom: 4px;
}
.summary-card .value {
  font-weight: 600;
  font-size: 1.05rem;
}

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

.group-summary {
  padding: 8px 16px;
}
.group-row, .account-row, .rate-row, .category-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.group-row:last-child, .account-row:last-child, .rate-row:last-child, .category-row:last-child {
  border-bottom: none;
}

.account-group h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Transactions list */
.tx-row {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.tx-row:last-child { border-bottom: none; }
.tx-icon { font-size: 1.3rem; text-align: center; }
.tx-name { font-weight: 500; }
.tx-note { grid-column: 2; font-size: 0.8rem; color: var(--color-muted); margin-top: -4px; }
.tx-amount { font-weight: 600; text-align: right; }

/* Forms */
.stacked-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
input, select, textarea {
  font-size: 1rem;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: -1px;
}

.btn-primary, .btn-secondary, .btn-text {
  font-size: 1rem;
  padding: 12px 16px;
  border-radius: 10px;
  border: none;
  cursor: pointer;
}
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
}
.btn-primary:active { background: var(--color-primary-dark); }
.btn-secondary {
  background: var(--color-border);
  color: var(--color-text);
}
.btn-text {
  background: none;
  color: var(--color-primary);
  padding: 8px;
}
.btn-text.danger { color: var(--color-danger); }

/* Segmented control */
.segmented-control {
  display: flex;
  background: var(--color-border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
}
.seg-btn {
  flex: 1;
  border: none;
  background: none;
  padding: 10px;
  border-radius: 8px;
  font-size: 0.95rem;
  color: var(--color-muted);
  cursor: pointer;
}
.seg-btn.active {
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* Auth screen */
.auth-screen {
  padding-top: 40px;
  text-align: center;
}
.auth-screen h1 {
  margin-bottom: 24px;
}
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--color-border);
  color: var(--color-muted);
  cursor: pointer;
  font-size: 0.95rem;
}
.tab-btn.active {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

/* FAB */
.fab {
  position: fixed;
  right: calc(50% - 240px + 20px);
  bottom: 84px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}
@media (max-width: 480px) {
  .fab { right: 20px; }
}

/* Tab bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
}
.tab-bar a {
  flex: 1;
  text-align: center;
  text-decoration: none;
  color: var(--color-muted);
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.tab-bar a .tab-icon { font-size: 1.3rem; }
.tab-bar a.active { color: var(--color-primary); font-weight: 600; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 20px;
  width: 100%;
  max-width: 480px;
}

/* Chart legend */
#breakdown-chart {
  display: block;
  margin: 0 auto 16px;
  max-width: 100%;
}
.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}
.legend-row:last-child { border-bottom: none; }
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.legend-row span:nth-child(2) { flex: 1; }
