:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f0f2f5;
  --surface-glass: rgba(255, 255, 255, 0.72);
  --text: #0f172a;
  --text-secondary: #64748b;
  --border: rgba(15, 23, 42, 0.08);
  --accent: #0f172a;
  --accent-contrast: #ffffff;
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, 0.12);
  --indigo: #6366f1;
  --indigo-soft: rgba(99, 102, 241, 0.12);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 12px 32px -8px rgba(15, 23, 42, 0.08);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
}

[data-theme="dark"] {
  --bg: #090d16;
  --surface: #111827;
  --surface-muted: #1b2436;
  --surface-glass: rgba(255, 255, 255, 0.08);
  --text: #f8fafc;
  --text-secondary: #94a3b8;
  --border: rgba(248, 250, 252, 0.09);
  --accent: #f8fafc;
  --accent-contrast: #090d16;
  --emerald: #34d399;
  --emerald-soft: rgba(52, 211, 153, 0.14);
  --indigo: #818cf8;
  --indigo-soft: rgba(129, 140, 248, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 18px 40px -12px rgba(0, 0, 0, 0.55);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

.app-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 20px max(36px, env(safe-area-inset-bottom));
}

/* Cabeçalho */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.brand-mark svg {
  width: 20px;
  height: 20px;
}

.brand-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.pill-btn:hover {
  transform: translateY(-1px);
}

/* Botão translúcido de alternância de tema */
.theme-toggle {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.2s ease, background-color 0.25s ease;
}

.theme-toggle:hover {
  transform: scale(1.05);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  opacity: 0.85;
}

[data-theme="light"] .icon-moon,
[data-theme="dark"] .icon-sun {
  display: none;
}

/* Layout em grid responsivo */
.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
}

@media (min-width: 820px) {
  .main-grid {
    grid-template-columns: 1.35fr 1fr;
    align-items: start;
  }

  .card-hero {
    grid-column: 1 / -1;
  }
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  transition: background-color 0.25s ease, border-color 0.25s ease;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.card-header-compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.balance-row {
  display: flex;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

.balance-value {
  margin: 0;
  font-size: clamp(1.85rem, 4vw, 2.5rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.trend-badge {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--emerald);
  background: var(--emerald-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.period-tabs {
  display: inline-flex;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 999px;
  gap: 4px;
}

.period-tab {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.period-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.chart-container {
  position: relative;
  height: 230px;
  width: 100%;
  margin-bottom: 20px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

@media (max-width: 540px) {
  .mini-stats {
    grid-template-columns: 1fr;
  }
}

.mini-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mini-stat-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.mini-stat-value {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Previsão IA */
.ai-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-spark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--indigo-soft);
  color: var(--indigo);
  font-size: 1rem;
}

.card-title {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card-subtitle {
  margin: 2px 0 0;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--indigo);
  background: var(--indigo-soft);
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.ai-projection-box {
  background: var(--surface-muted);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 18px;
}

.ai-projection-label {
  margin: 0 0 4px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.ai-projection-value {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.ai-projection-note {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-secondary);
}

.ai-projection-note strong {
  color: var(--text);
}

.budget-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.budget-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.8125rem;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.budget-meta span:first-child {
  font-weight: 500;
  color: var(--text);
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--text);
  transition: width 0.35s ease;
}

.progress-fill.accent-soft {
  background: var(--indigo);
}

.progress-fill.accent-emerald {
  background: var(--emerald);
}

/* Reserva Automática */
.amount-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr) 1.2fr;
  gap: 8px;
  margin-bottom: 14px;
}

@media (max-width: 460px) {
  .amount-selector {
    grid-template-columns: repeat(2, 1fr);
  }
}

.amount-chip {
  border: 1px solid var(--border);
  background: var(--surface-muted);
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.amount-chip.active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.custom-amount-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.custom-amount-wrap input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  outline: none;
  padding: 9px 0;
}

.smart-save-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  padding: 15px 18px;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}

.smart-save-btn:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

.smart-save-btn:active {
  transform: scale(0.99);
}

.btn-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 0 4px var(--emerald-soft);
}

.feedback-banner {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--emerald-soft);
  color: var(--emerald);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
}

.hidden {
  display: none !important;
}

.history-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.history-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.text-link-btn {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.activity-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.activity-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: 0.8125rem;
}

.activity-label {
  font-weight: 500;
}

.activity-date {
  display: block;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.activity-amount {
  font-weight: 600;
  color: var(--emerald);
}
