:root {
  color-scheme: light;
  --bg: #d7dbe0;
  --surface: #fafafa;
  --border: #d9dce1;
  --frame-bg: #f1f2f4;
  --text-primary: #202124;
  --text-secondary: #5f6368;
  --text-muted: #858a91;
  --accent: #2a78d6;
  --danger: #e34948;
  --grid: #dfe1e5;
  --series-income: #2a78d6;
  --series-expense: #eb6834;
  --series-balance: #2a78d6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.4;
}

.app-header {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.app-header h1 {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  font-size: 1.4rem;
  white-space: nowrap;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.app-header-sep {
  color: var(--border);
  font-weight: 600;
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.side-calculator {
  display: none;
  position: fixed;
  top: 96px;
  left: max(16px, calc(50% - 706px));
  width: 196px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.side-calculator-title {
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.calculator-display {
  display: block;
  width: 100%;
  min-height: 38px;
  margin-bottom: 10px;
  padding: 7px 9px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text-primary);
  font-size: 1.1rem;
  line-height: 1.3;
  text-align: right;
  white-space: nowrap;
}

.calculator-expression {
  display: block;
  min-height: 18px;
  padding: 0 4px 3px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  text-align: right;
  white-space: nowrap;
}

.calculator-keys { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }

.calculator-key {
  min-height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.9rem;
}

.calculator-key:hover { background: #cfd3d9; }
.calculator-key-action { color: var(--text-secondary); }
.calculator-key-action.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.calculator-key-equals { background: var(--accent); border-color: var(--accent); color: #fff; }
.calculator-key-equals:hover { background: #2167b8; }
.calculator-key-zero { grid-column: span 2; }

@media (min-width: 1440px) { .side-calculator { display: block; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
}

.card h2 { margin-top: 0; font-size: 1.05rem; }

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

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

input[type="text"], input[type="number"], input[type="date"], select {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 0.9rem;
  min-width: 120px;
}

.recurrence-form, .oneoff-form {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
}

.installment-fields {
  display: flex;
  gap: 14px;
}

.hidden { display: none !important; }

.form-actions { display: flex; gap: 8px; }

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text-primary); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); padding: 4px 10px; font-size: 0.8rem; cursor: pointer; }
.btn-edit { background: transparent; color: var(--accent); border: 1px solid var(--accent); padding: 4px 10px; font-size: 0.8rem; margin-right: 6px; cursor: pointer; }

.btn-icon-sm {
  background: transparent;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-icon-sm:hover { background: var(--bg); }
.btn-icon-edit { color: var(--accent); }
.btn-icon-delete { color: var(--danger); }

.table-scroll { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-top: 10px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-secondary); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }

.amount-expense { color: var(--danger); }
.amount-income { color: #0ca30c; }

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

.chart-block { margin-bottom: 22px; }
.chart-block h3 { font-size: 0.85rem; color: var(--text-secondary); margin: 0 0 8px; font-weight: 600; }

.viz-legend { display: flex; gap: 16px; font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 6px; }
.viz-legend-item { display: flex; align-items: center; gap: 6px; }
.viz-legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

.viz-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.78rem;
  color: var(--text-primary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  white-space: nowrap;
  z-index: 10;
}

.chart-svg-wrap { position: relative; }

/* ---------- Extrato mensal ---------- */

.extrato-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.month-nav { display: flex; align-items: center; gap: 10px; }

.transaction-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

#transactionForm input[type="text"],
#transactionForm input[type="number"],
#transactionForm input[type="date"],
#transactionForm select {
  background: #fff;
}

.tx-primary-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.tx-conditional-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.tx-primary-row label { min-width: 0; }
.tx-primary-row select { width: 100px; min-width: 0; }
.tx-primary-row input[type="number"] { width: 90px; min-width: 0; }
.tx-primary-row input[type="date"] { width: 150px; min-width: 130px; }
.tx-primary-row #txAmount { width: 100px; min-width: 0; text-align: right; }

.tx-primary-row .tx-desc-field { flex: 1 1 auto; }
.tx-primary-row .tx-desc-field input { width: 100%; min-width: 0; }

input[type="date"]::-webkit-calendar-picker-indicator { cursor: pointer; }

.tx-label-spacer {
  display: block;
  font-size: 0.8rem;
  line-height: 1.4;
  visibility: hidden;
}

.tx-recur-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  white-space: nowrap;
}

.tx-checkbox-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 38px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.btn-check {
  background: transparent;
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #1fa34a;
}
.btn-check:hover { background: var(--bg); }

.extrato-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
}

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 0.85rem;
}

.month-label { font-weight: 600; font-size: 1rem; min-width: 140px; text-align: center; }

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-header-row h2 { margin: 0; }
.section-header-actions { display: flex; gap: 8px; }

#extratoTable { table-layout: fixed; width: 100%; border-collapse: separate; border-spacing: 0; }
#extratoTable col.col-desc { width: auto; }
#extratoTable col.col-value { width: 130px; }
#extratoTable col.col-actions { width: 64px; }

@media (max-width: 480px) {
  #extratoTable col.col-value { width: 110px; }
  #extratoTable col.col-actions { width: 56px; }
}

#extratoTable td, #extratoTable th { white-space: normal; }
#extratoTable td.extrato-value, #extratoTable th:nth-child(2) {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#extratoTable td.extrato-actions, #extratoTable th:last-child { white-space: nowrap; text-align: right; padding-left: 4px; padding-right: 4px; }
#extratoTable td.extrato-actions .btn-icon-sm { width: 22px; height: 22px; padding: 0; }
#extratoTable td.extrato-actions .btn-icon-edit { margin-right: 2px; }

#extratoTable tr.extrato-date-row td {
  padding-top: 16px;
  border-bottom: none;
}

.extrato-date-badge {
  display: inline-block;
  font-weight: 600;
  font-size: 0.78rem;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #737984;
  color: #fff;
}

#extratoTable tr.extrato-summary-row td {
  color: var(--text-secondary);
  font-size: 0.85rem;
  border-top: none;
  border-bottom: 1px dashed var(--border);
  padding-top: 8px;
  padding-bottom: 12px;
}

#extratoTable tr.extrato-summary-row td strong { color: var(--text-primary); }

#extratoTable tr.day-frame-top td,
#extratoTable tr.day-frame-item td,
#extratoTable tr.day-frame-bottom td {
  background: var(--frame-bg);
  color: var(--text-primary);
}

#extratoTable tr.day-frame-bottom td strong { color: var(--text-primary); }
#extratoTable tr.day-frame-bottom .extrato-summary-label { color: var(--text-secondary); }
#extratoTable tr.day-frame-item .extrato-tag { color: var(--text-secondary); border-color: var(--border); }
#extratoTable tr.day-frame-item td.amount-expense { color: var(--danger); }
#extratoTable tr.day-frame-item td.amount-income { color: #0ca30c; }

#extratoTable tr.day-frame-top td:first-child,
#extratoTable tr.day-frame-item td:first-child,
#extratoTable tr.day-frame-bottom td:first-child {
  border-left: 1px solid var(--border);
}

#extratoTable tr.day-frame-top td:last-child,
#extratoTable tr.day-frame-item td:last-child,
#extratoTable tr.day-frame-bottom td:last-child {
  border-right: 1px solid var(--border);
}

#extratoTable tr.day-frame-top td:first-child {
  border-top: 1px solid var(--border);
  border-top-left-radius: 10px;
}
#extratoTable tr.day-frame-top td:last-child {
  border-top: 1px solid var(--border);
  border-top-right-radius: 10px;
}

#extratoTable tr.day-frame-bottom td {
  border-bottom: 1px solid var(--border) !important;
}
#extratoTable tr.day-frame-bottom td:first-child { border-bottom-left-radius: 10px; }
#extratoTable tr.day-frame-bottom td:last-child { border-bottom-right-radius: 10px; }

#extratoTable tr.day-frame-gap td {
  border: none;
  background: transparent;
  padding: 14px 0 0;
}

.extrato-summary-label {
  color: var(--text-secondary);
  font-weight: 400;
  margin-right: 10px;
}

.extrato-empty { color: var(--text-muted); font-size: 0.85rem; padding: 14px 0; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  max-width: 340px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.modal-box p { margin: 0 0 16px; font-size: 0.9rem; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
}
