:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-card-hover: #1c2a4a;
  --text-primary: #e8e8e8;
  --text-secondary: #a0a0b8;
  --text-muted: #6c6c80;
  --income: #2ecc71;
  --income-bg: rgba(46, 204, 113, 0.12);
  --expense: #e74c3c;
  --expense-bg: rgba(231, 76, 60, 0.12);
  --accent: #3498db;
  --accent-bg: rgba(52, 152, 219, 0.12);
  --border: rgba(255, 255, 255, 0.06);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  --radius: 14px;
  --radius-sm: 10px;
  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
}

/* Views */
.view {
  display: none;
  padding: 16px;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px);
  animation: fadeIn 0.2s ease;
}
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.view-header {
  padding: 12px 0 20px;
}
.view-header h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}
.header-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}
.home-header {
  display: flex;
  align-items: center;
  gap: 14px;
}
.home-logo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

/* Summary Cards */
.summary-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}
.summary-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
}
.summary-card.balance-card {
  grid-column: 1 / -1;
}
.card-label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.card-value {
  display: block;
  font-size: 22px;
  font-weight: 700;
}
.income-card .card-value { color: var(--income); }
.expense-card .card-value { color: var(--expense); }
.balance-card .card-value { color: var(--accent); }

/* Section blocks */
.section-block {
  margin-bottom: 24px;
}
.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

/* Category list */
.category-list {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.category-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.category-item:last-child { border-bottom: none; }
.category-item .cat-name {
  font-size: 14px;
  color: var(--text-primary);
}
.category-item .cat-value {
  font-size: 14px;
  font-weight: 600;
}
.category-item .cat-value.income-text { color: var(--income); }
.category-item .cat-value.expense-text { color: var(--expense); }
.category-list .empty-state {
  padding: 20px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Transaction list */
.transaction-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.transaction-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  cursor: pointer;
  transition: background 0.15s;
}
.transaction-item:active { background: var(--bg-card-hover); }
.tx-info {
  flex: 1;
  min-width: 0;
}
.tx-category {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
}
.tx-details {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-observation {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tx-amount {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  margin-left: 12px;
}
.tx-amount.income-text { color: var(--income); }
.tx-amount.expense-text { color: var(--expense); }

.date-group-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 0 4px;
}

.transaction-list .empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px 16px;
}

/* Period filters */
.period-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.period-filters::-webkit-scrollbar { display: none; }

.filter-btn, .chart-period-btn {
  flex-shrink: 0;
  padding: 10px 18px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn.active, .chart-period-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.custom-date-range {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  margin-bottom: 20px;
}
.date-input-group {
  flex: 1;
}
.date-input-group label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.date-input-group input {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
}
.btn-filter-apply {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

/* Charts */
.chart-section {
  margin-bottom: 32px;
}
.chart-container {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  display: flex;
  justify-content: center;
}
.chart-container canvas {
  max-width: 260px;
  max-height: 260px;
  width: 100%;
  height: auto;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 12px 0;
  justify-content: center;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Profile */
.profile-avatar {
  text-align: center;
  padding: 20px 0 28px;
}
.profile-logo {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
  margin-bottom: 12px;
}
.profile-avatar h2 {
  font-size: 20px;
}

.profile-stats {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
  overflow: hidden;
}
.profile-stat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.profile-stat:last-child { border-bottom: none; }
.stat-label { font-size: 14px; color: var(--text-secondary); }
.stat-value { font-size: 16px; font-weight: 700; }
.income-text { color: var(--income); }
.expense-text { color: var(--expense); }

.profile-info {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 16px;
}
.profile-info h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row span:last-child { color: var(--text-secondary); }

/* Bottom Navigation */
#bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  height: calc(var(--nav-height) + var(--safe-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  justify-content: space-around;
  padding-top: 8px;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  cursor: pointer;
  padding: 4px 12px;
  transition: color 0.15s;
  position: relative;
}
.nav-btn svg {
  width: 22px;
  height: 22px;
}
.nav-btn.active {
  color: var(--accent);
}
.nav-btn.add-btn {
  padding: 0;
}
.add-btn-circle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--income), #27ae60);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: -24px;
  box-shadow: 0 4px 16px rgba(46, 204, 113, 0.35);
  transition: transform 0.15s, box-shadow 0.15s;
}
.add-btn-circle:active {
  transform: scale(0.92);
}
.add-btn-circle svg {
  width: 28px;
  height: 28px;
  color: #fff;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  display: none;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal.active {
  display: flex;
}
.modal-content {
  background: var(--bg-secondary);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  padding: 24px 20px calc(20px + var(--safe-bottom));
  position: relative;
  animation: slideUp 0.25s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 28px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.modal-close:active { background: var(--border); }

.modal-step { display: none; }
.modal-step.active { display: block; }
.modal-step h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 24px;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 16px;
  padding: 4px 0;
}
.btn-back svg { width: 18px; height: 18px; }

/* Type buttons */
.type-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 32px 20px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.type-btn svg { width: 40px; height: 40px; }
.type-btn.income-btn:active,
.type-btn.income-btn:hover {
  border-color: var(--income);
  background: var(--income-bg);
}
.type-btn.income-btn svg { color: var(--income); }
.type-btn.expense-btn:active,
.type-btn.expense-btn:hover {
  border-color: var(--expense);
  background: var(--expense-bg);
}
.type-btn.expense-btn svg { color: var(--expense); }

/* Form */
.form-group {
  margin-bottom: 20px;
}
.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}
.amount-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  padding: 4px 16px;
  transition: border-color 0.15s;
}
.amount-input-wrapper:focus-within {
  border-color: var(--accent);
}
.currency-prefix {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-right: 8px;
}
#input-amount {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 32px;
  font-weight: 700;
  outline: none;
  padding: 12px 0;
  width: 100%;
}
#input-amount::placeholder { color: var(--text-muted); }

.pill-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.pill {
  padding: 10px 16px;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.pill.selected {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#input-installments {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2 4l4 4 4-4' fill='none' stroke='%23a0a0b8' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}

#input-observation {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  resize: vertical;
  outline: none;
  font-family: inherit;
}
#input-observation:focus { border-color: var(--accent); }

.custom-category-input {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  font-family: inherit;
  margin-top: 10px;
}
.custom-category-input:focus { border-color: var(--income); }

.btn-save {
  width: 100%;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 8px;
}
.btn-save:active { opacity: 0.85; }
.btn-save.income-save {
  background: var(--income);
  color: #fff;
}
.btn-save.expense-save {
  background: var(--expense);
  color: #fff;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 14px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  z-index: 300;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}
.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Responsive - wider layouts for desktop */
@media (min-width: 640px) {
  .summary-cards {
    grid-template-columns: 1fr 1fr 1fr;
  }
  .summary-card.balance-card {
    grid-column: auto;
  }
  .type-buttons {
    gap: 24px;
  }
  .type-btn {
    padding: 40px 24px;
  }
  .modal-content {
    border-radius: 20px;
    margin: auto;
    max-height: 80vh;
  }
  .modal {
    align-items: center;
  }
}

/* Loading spinner */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Delete button on transaction */
.tx-delete {
  background: none;
  border: none;
  color: var(--expense);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  margin-top: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.transaction-item:hover .tx-delete,
.transaction-item:active .tx-delete {
  opacity: 1;
}
