/* ===== VARIABLES & RESET ===== */
:root {
  --bg: #f5f4f0;
  --bg2: #eceae4;
  --surface: #ffffff;
  --surface2: #f9f8f5;
  --border: #e2e0d8;
  --text: #1a1916;
  --text2: #6b6860;
  --text3: #9b9890;
  --green: #2d7a4f;
  --green-light: #e8f5ee;
  --green-mid: #4caf80;
  --red: #c0392b;
  --red-light: #fdecea;
  --red-mid: #e05a4a;
  --gold: #c9943a;
  --gold-light: #fdf3e3;
  --blue: #2563a8;
  --blue-light: #e8f0fc;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #111110;
  --bg2: #1a1916;
  --surface: #222220;
  --surface2: #2a2926;
  --border: #333330;
  --text: #f0ede8;
  --text2: #9b9890;
  --text3: #6b6860;
  --green-light: #0d2b1a;
  --red-light: #2b0d0a;
  --gold-light: #2b1e0a;
  --blue-light: #0a1525;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}
input, select, textarea, button { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }
a { text-decoration: none; color: inherit; }

/* ===== LAYOUT ===== */
.app-wrapper { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition), background var(--transition);
  box-shadow: var(--shadow-sm);
}
.sidebar-logo {
  padding: 28px 24px 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.4rem;
  color: var(--text);
  letter-spacing: -0.02em;
}
.sidebar-logo span { color: var(--green); }
.sidebar-logo p {
  font-size: 0.72rem; color: var(--text3);
  margin-top: 2px; text-transform: uppercase; letter-spacing: 0.08em;
}
.nav-section { padding: 16px 12px 8px; }
.nav-label {
  font-size: 0.65rem; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding: 0 12px 8px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text2); font-size: 0.875rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition);
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--bg2); color: var(--text); }
.nav-item.active { background: var(--green-light); color: var(--green); }
.nav-item .icon { font-size: 1.1rem; width: 22px; text-align: center; }
.sidebar-footer {
  margin-top: auto; padding: 16px 12px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.theme-toggle {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.8rem; color: var(--text2);
  background: var(--bg2); border-radius: 20px;
  padding: 6px 12px; cursor: pointer; transition: all var(--transition);
}
.theme-toggle:hover { color: var(--text); }

/* ===== MAIN ===== */
.main { margin-left: 240px; flex: 1; min-height: 100vh; }

.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 16px 32px; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow-sm);
}
.topbar-title {
  font-family: 'DM Serif Display', serif;
  font-size: 1.5rem; letter-spacing: -0.02em;
}
.topbar-actions { display: flex; gap: 10px; align-items: center; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--radius-sm);
  font-size: 0.875rem; font-weight: 500;
  transition: all var(--transition); cursor: pointer;
}
.btn-primary { background: var(--green); color: white; }
.btn-primary:hover { background: #256b44; transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg2); }
.btn-danger { background: var(--red-light); color: var(--red); }
.btn-danger:hover { background: var(--red); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

/* ===== PAGES ===== */
.page { padding: 32px; display: none; }
.page.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== CARD ===== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow-sm); transition: all var(--transition);
}
.card:hover { box-shadow: var(--shadow); }

/* ===== METRIC CARDS ===== */
.metrics-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 20px; margin-bottom: 28px;
}
.metric-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px 28px;
  box-shadow: var(--shadow-sm); transition: all var(--transition);
  position: relative; overflow: hidden;
}
.metric-card::before {
  content: ''; position: absolute; top: 0; right: 0;
  width: 80px; height: 80px;
  border-radius: 0 var(--radius) 0 80px; opacity: 0.08;
}
.metric-card.income::before { background: var(--green); }
.metric-card.expense::before { background: var(--red); }
.metric-card.balance::before { background: var(--blue); }
.metric-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.metric-label {
  font-size: 0.75rem; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; margin-bottom: 8px;
}
.metric-value {
  font-family: 'DM Serif Display', serif;
  font-size: 2rem; letter-spacing: -0.03em; line-height: 1;
}
.metric-value.income { color: var(--green); }
.metric-value.expense { color: var(--red); }
.metric-value.balance { color: var(--blue); }
.metric-sub { font-size: 0.75rem; color: var(--text3); margin-top: 8px; }
.metric-icon { font-size: 1.5rem; margin-bottom: 12px; }

/* ===== DASHBOARD GRID & CHARTS ===== */
.dashboard-grid {
  display: grid; grid-template-columns: 1.4fr 1fr;
  gap: 24px; margin-bottom: 28px;
}
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  box-shadow: var(--shadow-sm);
  /* FIX: altura fija para evitar expansión infinita */
  min-height: 0;
}
.chart-title {
  font-size: 0.875rem; font-weight: 600; color: var(--text2);
  margin-bottom: 20px; text-transform: uppercase; letter-spacing: 0.06em;
}
/* Contenedor con altura fija para el canvas */
.chart-canvas-wrapper {
  position: relative;
  height: 260px;   /* altura fija invariable */
  width: 100%;
}
.chart-canvas-wrapper canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ===== TRANSACTION TABLE ===== */
.transaction-filters {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
  margin-bottom: 20px;
}
.filter-input {
  padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 0.875rem;
  transition: all var(--transition); outline: none;
}
.filter-input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(45,122,79,0.12); }
.search-box { flex: 1; min-width: 200px; }
.transactions-table { width: 100%; border-collapse: collapse; }
.transactions-table th {
  text-align: left; padding: 10px 16px;
  font-size: 0.72rem; color: var(--text3);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.transactions-table td {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-size: 0.875rem; vertical-align: middle;
}
.transactions-table tr:last-child td { border-bottom: none; }
.transactions-table tr:hover td { background: var(--surface2); }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 20px;
  font-size: 0.72rem; font-weight: 600;
}
.badge-income { background: var(--green-light); color: var(--green); }
.badge-expense { background: var(--red-light); color: var(--red); }
.badge-yes { background: var(--blue-light); color: var(--blue); }
.badge-no { background: var(--gold-light); color: var(--gold); }
.amount-income { color: var(--green); font-weight: 600; }
.amount-expense { color: var(--red); font-weight: 600; }

.action-btn {
  padding: 5px 8px; border-radius: 6px; font-size: 0.75rem;
  transition: all var(--transition); margin-left: 4px;
}
.action-btn:hover { transform: scale(1.1); }
.edit-btn { color: var(--blue); background: var(--blue-light); }
.delete-btn { color: var(--red); background: var(--red-light); }

/* ===== FORM ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: 0.8rem; font-weight: 600; color: var(--text2); }
.form-input {
  padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text); font-size: 0.9rem;
  transition: all var(--transition); outline: none;
}
.form-input:focus {
  border-color: var(--green); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(45,122,79,0.12);
}
.radio-group { display: flex; gap: 8px; }
.radio-btn {
  padding: 8px 16px; border-radius: 8px; font-size: 0.85rem; font-weight: 500;
  border: 2px solid var(--border); cursor: pointer;
  transition: all var(--transition); color: var(--text2);
}
.radio-btn.income-btn.selected { border-color: var(--green); background: var(--green-light); color: var(--green); }
.radio-btn.expense-btn.selected { border-color: var(--red); background: var(--red-light); color: var(--red); }

/* ===== BUDGET ===== */
.budget-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.budget-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 18px 20px;
}
.budget-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.budget-cat { font-weight: 600; font-size: 0.9rem; }
.budget-amounts { font-size: 0.8rem; color: var(--text2); }
.progress-bar {
  height: 8px; background: var(--border);
  border-radius: 4px; overflow: hidden; margin: 10px 0 6px;
}
.progress-fill {
  height: 100%; border-radius: 4px;
  transition: width 0.6s cubic-bezier(0.4,0,0.2,1);
}
.progress-fill.ok { background: var(--green); }
.progress-fill.warn { background: var(--gold); }
.progress-fill.over { background: var(--red); }
.budget-diff { font-size: 0.78rem; font-weight: 600; }
.budget-diff.positive { color: var(--green); }
.budget-diff.negative { color: var(--red); }

/* ===== CREDIT CARDS ===== */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px; }
.credit-card-item {
  background: linear-gradient(135deg, #1a2436 0%, #2d3f5c 100%);
  border-radius: var(--radius); padding: 24px; color: white;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.credit-card-item:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }
.credit-card-item::before {
  content: ''; position: absolute;
  width: 200px; height: 200px; border-radius: 50%;
  background: rgba(255,255,255,0.04);
  top: -60px; right: -60px;
}
.card-bank { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.6; margin-bottom: 20px; }
.card-amount { font-family: 'DM Serif Display', serif; font-size: 1.8rem; margin-bottom: 4px; }
.card-sub { font-size: 0.8rem; opacity: 0.6; }
.card-installments { margin-top: 20px; display: flex; justify-content: space-between; align-items: flex-end; }
.card-field-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.5; margin-bottom: 3px; }
.card-field-value { font-size: 0.9rem; font-weight: 600; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; }
.card-action-btn {
  padding: 6px 12px; border-radius: 6px; font-size: 0.75rem; font-weight: 600;
  background: rgba(255,255,255,0.1); color: white; cursor: pointer;
  transition: all var(--transition); border: 1px solid rgba(255,255,255,0.15);
}
.card-action-btn:hover { background: rgba(255,255,255,0.2); }

/* ===== SAVINGS ===== */
.savings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 20px; }
.saving-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  transition: all var(--transition); box-shadow: var(--shadow-sm);
}
.saving-item:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.saving-emoji { font-size: 2rem; margin-bottom: 12px; }
.saving-name { font-weight: 700; font-size: 1rem; margin-bottom: 4px; }
.saving-amounts { font-size: 0.82rem; color: var(--text2); margin-bottom: 14px; }
.saving-percent {
  display: flex; justify-content: space-between;
  font-size: 0.78rem; color: var(--text3); margin-bottom: 6px;
}
.saving-percent strong { color: var(--green); font-size: 0.85rem; }
.saving-actions { display: flex; gap: 8px; margin-top: 14px; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px; opacity: 0;
  transition: opacity var(--transition); pointer-events: none;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  padding: 32px; width: 100%; max-width: 560px;
  box-shadow: var(--shadow-lg); transform: translateY(20px);
  transition: transform var(--transition);
  max-height: 90vh; overflow-y: auto;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.modal-title { font-family: 'DM Serif Display', serif; font-size: 1.4rem; }
.modal-close {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg2); color: var(--text2); font-size: 1.1rem;
  transition: all var(--transition);
}
.modal-close:hover { background: var(--red-light); color: var(--red); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 10px;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px 18px;
  box-shadow: var(--shadow-lg); font-size: 0.875rem; font-weight: 500;
  display: flex; align-items: center; gap: 10px; min-width: 280px;
  animation: slideIn 0.3s ease;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error   { border-left: 4px solid var(--red); }
.toast.warning { border-left: 4px solid var(--gold); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes slideOut {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(100%); opacity: 0; }
}

/* ===== CONFIRM DIALOG ===== */
.confirm-dialog {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; padding: 20px; opacity: 0;
  transition: opacity var(--transition); pointer-events: none;
}
.confirm-dialog.open { opacity: 1; pointer-events: all; }
.confirm-box {
  background: var(--surface); border-radius: var(--radius);
  padding: 28px; max-width: 400px; width: 100%;
  box-shadow: var(--shadow-lg); text-align: center;
  transform: scale(0.9); transition: transform var(--transition);
}
.confirm-dialog.open .confirm-box { transform: scale(1); }
.confirm-icon { font-size: 2.5rem; margin-bottom: 14px; }
.confirm-title { font-family: 'DM Serif Display', serif; font-size: 1.2rem; margin-bottom: 8px; }
.confirm-text { font-size: 0.875rem; color: var(--text2); margin-bottom: 24px; }
.confirm-actions { display: flex; justify-content: center; gap: 12px; }

/* ===== SECTION HEADERS ===== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.section-title { font-family: 'DM Serif Display', serif; font-size: 1.3rem; }

/* ===== EMPTY STATE ===== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text3); }
.empty-state-icon { font-size: 3rem; margin-bottom: 14px; opacity: 0.4; }
.empty-state p { font-size: 0.9rem; }

/* ===== STAT PILL ===== */
.stat-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 600;
}
.pill-green { background: var(--green-light); color: var(--green); }
.pill-red   { background: var(--red-light);   color: var(--red);   }

/* ===== UPCOMING PAYMENTS ===== */
.upcoming-list { display: flex; flex-direction: column; gap: 12px; }
.upcoming-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; background: var(--surface2);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  transition: all var(--transition);
}
.upcoming-item:hover { border-color: var(--blue); background: var(--blue-light); }
.upcoming-info { flex: 1; }
.upcoming-name { font-weight: 600; font-size: 0.9rem; }
.upcoming-meta { font-size: 0.78rem; color: var(--text2); margin-top: 2px; }
.upcoming-amount { font-family: 'DM Serif Display', serif; font-size: 1.1rem; color: var(--red); font-weight: 600; }

/* ===== BUDGET ALERT ===== */
.budget-alert {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--red-light); border: 1px solid rgba(192,57,43,0.2);
  color: var(--red); font-size: 0.85rem; font-weight: 500;
  margin-bottom: 16px;
}

/* ===== MISC ===== */
.table-wrapper { overflow-x: auto; }
.section-divider { height: 1px; background: var(--border); margin: 24px 0; }
.export-row { display: flex; gap: 10px; margin-bottom: 20px; }
.mobile-menu-btn { display: none; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text3); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .metrics-grid   { grid-template-columns: 1fr 1fr; }
  .budget-grid    { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); width: 260px; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .metrics-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-group.full { grid-column: 1; }
  .page { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .mobile-menu-btn { display: flex; }
  .budget-grid { grid-template-columns: 1fr; }
  .chart-canvas-wrapper { height: 200px; }
}
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; display: none; }
.overlay.show { display: block; }
