/* ===== Tema: variáveis de cor ===== */
:root {
  /* Paleta base azul + amarelo */
  --blue: #1e5fd4;
  --blue-dark: #123a86;
  --blue-light: #4a86f0;
  --yellow: #f5c518;
  --yellow-dark: #d9a900;

  /* Tema claro (padrão) */
  --bg: #eef3fb;
  --bg-elevated: #ffffff;
  --text: #16233a;
  --text-muted: #5c6b82;
  --border: #dce4f2;
  --shadow: 0 8px 24px rgba(30, 95, 212, 0.08);

  --primary: var(--blue);
  --primary-contrast: #ffffff;
  --accent: var(--yellow);

  --income: #159e6a;
  --expense: #e0453f;
  --income-bg: rgba(21, 158, 106, 0.12);
  --expense-bg: rgba(224, 69, 63, 0.12);
}

:root[data-theme="dark"] {
  --bg: #0d1526;
  --bg-elevated: #16233d;
  --text: #eaf0fb;
  --text-muted: #9aabc6;
  --border: #263651;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);

  --blue: #4a86f0;
  --blue-light: #6fa1f5;
  --primary: #4a86f0;
  --accent: var(--yellow);

  --income: #34d399;
  --expense: #f87171;
  --income-bg: rgba(52, 211, 153, 0.14);
  --expense-bg: rgba(248, 113, 113, 0.14);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s ease, color 0.3s ease;
}

/* ===== Topbar ===== */
.topbar {
  background: linear-gradient(135deg, var(--blue-dark), var(--blue));
  color: #fff;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 4px 20px rgba(18, 58, 134, 0.3);
}

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

.logo {
  font-size: 34px;
  background: var(--yellow);
  border-radius: 14px;
  padding: 6px 10px;
  line-height: 1;
  box-shadow: 0 4px 12px rgba(245, 197, 24, 0.4);
}

.topbar h1 {
  font-size: 1.4rem;
  font-weight: 700;
}

.subtitle {
  font-size: 0.82rem;
  opacity: 0.85;
}

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

.month-filter {
  border: none;
  border-radius: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}
.month-filter::-webkit-calendar-picker-indicator {
  filter: invert(1);
  cursor: pointer;
}

.theme-toggle {
  border: none;
  background: var(--yellow);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 4px 12px rgba(245, 197, 24, 0.35);
}
.theme-toggle:hover {
  transform: translateY(-2px) rotate(-8deg);
}

/* ===== Container ===== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

/* ===== Cards de resumo ===== */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--bg-elevated);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 5px;
}
.card-balance::before {
  background: var(--blue);
}
.card-income::before {
  background: var(--income);
}
.card-expense::before {
  background: var(--expense);
}

.card-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.card-value {
  font-size: 1.7rem;
  font-weight: 800;
}
.card-balance .card-value {
  color: var(--blue);
}
.card-income .card-value {
  color: var(--income);
}
.card-expense .card-value {
  color: var(--expense);
}

/* ===== Layout ===== */
.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 22px;
  align-items: start;
}

.panel {
  background: var(--bg-elevated);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.panel h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

/* ===== Formulário ===== */
.type-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.type-option {
  position: relative;
  cursor: pointer;
}
.type-option input {
  position: absolute;
  opacity: 0;
}
.type-option span {
  display: block;
  text-align: center;
  padding: 10px;
  border-radius: 10px;
  border: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s ease;
}
.type-receita input:checked + span {
  border-color: var(--income);
  background: var(--income-bg);
  color: var(--income);
}
.type-despesa input:checked + span {
  border-color: var(--expense);
  background: var(--expense-bg);
  color: var(--expense);
}

.field {
  display: block;
  margin-bottom: 14px;
}
.field span {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input,
.field select,
.filters select {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:focus,
.field select:focus,
.filters select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 134, 240, 0.18);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}
.btn {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s ease, filter 0.2s ease;
}
.btn:active {
  transform: scale(0.98);
}
.btn-primary {
  background: var(--primary);
  color: var(--primary-contrast);
}
.btn-primary:hover {
  filter: brightness(1.08);
}
.btn-ghost {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  flex: 0 0 auto;
  padding: 12px 18px;
}

.form-error {
  margin-top: 12px;
  color: var(--expense);
  background: var(--expense-bg);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.85rem;
}

/* ===== Lista ===== */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.list-header h2 {
  margin-bottom: 0;
}
.filters select {
  width: auto;
}

/* ===== Gráfico ===== */
.chart-wrap {
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg);
  border-radius: 12px;
  border: 1px solid var(--border);
}
.chart-wrap h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.chart {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bar-row {
  display: grid;
  grid-template-columns: 100px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
}
.bar-label {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  background: var(--border);
  border-radius: 6px;
  height: 12px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--blue), var(--yellow));
  transition: width 0.5s ease;
}
.bar-value {
  font-weight: 700;
  white-space: nowrap;
}

/* ===== Transações ===== */
.transaction-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.transaction-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}
.transaction-item:hover {
  transform: translateX(3px);
  box-shadow: var(--shadow);
}
.ti-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.ti-icon.receita {
  background: var(--income-bg);
}
.ti-icon.despesa {
  background: var(--expense-bg);
}
.ti-info {
  flex: 1;
  min-width: 0;
}
.ti-desc {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ti-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.ti-tag {
  background: rgba(30, 95, 212, 0.1);
  color: var(--primary);
  padding: 1px 8px;
  border-radius: 20px;
  font-weight: 600;
}
.ti-amount {
  font-weight: 800;
  font-size: 1.05rem;
  white-space: nowrap;
}
.ti-amount.receita {
  color: var(--income);
}
.ti-amount.despesa {
  color: var(--expense);
}
.ti-actions {
  display: flex;
  gap: 6px;
}
.icon-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  padding: 6px;
  border-radius: 8px;
  opacity: 0.6;
  transition: opacity 0.2s ease, background 0.2s ease;
}
.icon-btn:hover {
  opacity: 1;
  background: var(--border);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 0.95rem;
}

/* ===== Responsivo ===== */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .cards {
    grid-template-columns: 1fr;
  }
}
