/* ============================================
   MoneyFlow - Estilos
   ============================================ */

:root {
  --bg: #0a0e1a;
  --bg-2: #0f172a;
  --surface: #1e293b;
  --surface-2: #293548;
  --border: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-mute: #64748b;
  --primary: #6366f1;
  --primary-2: #818cf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --purple: #a855f7;
  --pink: #ec4899;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 25px -5px rgba(0,0,0,0.3), 0 8px 10px -6px rgba(0,0,0,0.2);
  --shadow-lg: 0 25px 50px -12px rgba(0,0,0,0.5);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ===== LOGIN ===== */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at top, #1e293b 0%, #0a0e1a 50%);
  padding: 20px;
  z-index: 100;
}
.login-box {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  box-shadow: var(--shadow-lg);
}
.login-brand { text-align: center; margin-bottom: 32px; }
.login-icon { font-size: 48px; margin-bottom: 12px; }
.login-brand h1 { font-size: 28px; font-weight: 800; margin-bottom: 4px; background: linear-gradient(135deg, #818cf8, #ec4899); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.login-brand p { color: var(--text-dim); font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; }
.login-form label span { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.login-form input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  transition: border 0.15s;
}
.login-form input:focus { outline: none; border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; text-align: center; }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--purple));
  color: white;
  font-weight: 600;
  padding: 12px;
  border-radius: var(--radius-sm);
  transition: transform 0.1s, opacity 0.15s;
  font-size: 14px;
}
.btn-primary:hover { transform: translateY(-1px); opacity: 0.92; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

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

.sidebar {
  width: 240px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-icon { font-size: 28px; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-weight: 800; font-size: 16px; }
.brand-text span { color: var(--text-dim); font-size: 12px; }

.sidebar-nav { flex: 1; padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active {
  background: linear-gradient(90deg, rgba(99,102,241,0.15), rgba(168,85,247,0.05));
  color: white;
  border-left: 3px solid var(--primary);
  padding-left: 9px;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.btn-logout {
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-dim);
  font-weight: 500;
  transition: background 0.15s;
}
.btn-logout:hover { background: var(--danger); color: white; }

.topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar h2 { font-size: 17px; font-weight: 700; }
.menu-toggle {
  background: var(--surface);
  color: var(--text);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
}

.main { flex: 1; min-width: 0; }
.route-content { padding: 24px 28px; max-width: 1400px; margin: 0 auto; }

/* ===== HEADERS de página ===== */
.page-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px; gap: 16px; flex-wrap: wrap;
}
.page-head h1 { font-size: 24px; font-weight: 800; }
.page-head p { color: var(--text-dim); font-size: 14px; margin-top: 4px; }

.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ===== BOTONES ===== */
.btn { padding: 9px 16px; border-radius: var(--radius-sm); font-weight: 500; font-size: 14px; transition: all 0.15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-add { background: var(--primary); color: white; }
.btn-add:hover { background: var(--primary-2); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-icon { width: 32px; height: 32px; padding: 0; display: flex; align-items: center; justify-content: center; }

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card h3 { font-size: 15px; font-weight: 600; margin-bottom: 12px; color: var(--text); }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-head h3 { margin: 0; }

/* ===== KPIs ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--accent, var(--primary));
}
.kpi.success { --accent: var(--success); }
.kpi.danger { --accent: var(--danger); }
.kpi.warning { --accent: var(--warning); }
.kpi.info { --accent: var(--info); }
.kpi-label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; margin-bottom: 8px; }
.kpi-value { font-size: 26px; font-weight: 800; line-height: 1.1; }
.kpi-value.small { font-size: 20px; }
.kpi-sub { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.kpi-icon { position: absolute; top: 14px; right: 14px; font-size: 24px; opacity: 0.3; }

/* ===== GRID ===== */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 2fr 1fr; }
@media (max-width: 980px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ===== TABLA ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 12px; text-align: left; font-size: 13px; }
.table th { font-weight: 600; color: var(--text-dim); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; border-bottom: 1px solid var(--border); }
.table tbody tr { border-bottom: 1px solid rgba(51, 65, 85, 0.4); transition: background 0.1s; }
.table tbody tr:hover { background: rgba(51, 65, 85, 0.3); }
.table tbody tr:last-child { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions button { padding: 4px 8px; font-size: 12px; border-radius: 6px; margin-left: 4px; }
.table-empty { padding: 40px; text-align: center; color: var(--text-dim); }

/* ===== TAG / chip ===== */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 100px; font-size: 11px; font-weight: 600;
  background: var(--surface-2); color: var(--text);
}
.tag-fijo { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; }
.tag-variable { background: rgba(168, 85, 247, 0.15); color: #d8b4fe; }
.tag-success { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
.tag-danger { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.tag-warning { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }

/* ===== FORM ===== */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row.full { grid-template-columns: 1fr; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
.form label { display: flex; flex-direction: column; gap: 6px; }
.form label span { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.form input, .form select, .form textarea {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  width: 100%;
}
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--primary); }
.form textarea { resize: vertical; min-height: 60px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 17px; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 16px;
  transition: background 0.15s;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; }

/* ===== TOASTS ===== */
.toast-container {
  position: fixed; top: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 300;
  max-width: calc(100vw - 40px);
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  min-width: 240px;
  animation: slideIn 0.2s ease-out;
  box-shadow: var(--shadow);
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ===== Filtros ===== */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filters select, .filters input {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.filters label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-dim); }

/* ===== Toggle ===== */
.toggle-group {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}
.toggle-group button {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-dim);
  transition: all 0.15s;
}
.toggle-group button.active {
  background: var(--primary);
  color: white;
}

/* ===== Progress bar ===== */
.progress {
  width: 100%; height: 8px;
  background: var(--bg-2);
  border-radius: 100px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent, var(--primary));
  border-radius: 100px;
  transition: width 0.3s ease;
}
.progress.thick { height: 12px; }

/* ===== Meta card ===== */
.meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.meta-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.meta-icon { font-size: 26px; }
.meta-info h4 { font-size: 14px; font-weight: 600; }
.meta-info .small { font-size: 12px; color: var(--text-dim); }
.meta-amounts { display: flex; justify-content: space-between; margin-bottom: 8px; font-size: 13px; }
.meta-amounts strong { font-weight: 700; }
.meta-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 12px; color: var(--text-dim); }

/* ===== Tarjeta crédito ===== */
.tarjeta-card {
  background: linear-gradient(135deg, var(--c1, var(--primary)) 0%, var(--c2, var(--purple)) 100%);
  border-radius: var(--radius);
  padding: 20px;
  color: white;
  position: relative;
  overflow: hidden;
  min-height: 160px;
  display: flex; flex-direction: column; justify-content: space-between;
}
.tarjeta-card::before {
  content: ''; position: absolute; top: -20px; right: -20px;
  width: 100px; height: 100px; border-radius: 50%;
  background: rgba(255,255,255,0.1);
}
.tarjeta-card .nombre { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.tarjeta-card .banco { font-size: 12px; opacity: 0.85; }
.tarjeta-card .uso { display: flex; justify-content: space-between; font-size: 12px; opacity: 0.85; margin-bottom: 4px; }
.tarjeta-card .saldo { font-size: 20px; font-weight: 800; }
.tarjeta-card .progress { background: rgba(0,0,0,0.25); margin-top: 8px; }
.tarjeta-card .progress-fill { background: white; }
.tarjeta-card.peligro { animation: pulse-bg 2s infinite; }
@keyframes pulse-bg { 0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); } 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }

/* ===== Heatmap ===== */
.heatmap-wrap { overflow-x: auto; }
.heatmap {
  display: grid;
  grid-template-columns: 180px repeat(12, minmax(50px, 1fr));
  gap: 2px;
  min-width: 800px;
}
.heatmap .cell { padding: 8px 6px; font-size: 11px; text-align: center; border-radius: 4px; }
.heatmap .head { font-weight: 700; color: var(--text-dim); background: transparent; }
.heatmap .label { text-align: left; padding-left: 8px; font-weight: 500; display: flex; align-items: center; gap: 6px; background: var(--bg-2); border-radius: 4px; }
.heatmap .value { background: var(--surface); color: var(--text-dim); font-variant-numeric: tabular-nums; }
.heatmap .value.h1 { background: rgba(239, 68, 68, 0.4); color: white; font-weight: 600; }
.heatmap .value.h2 { background: rgba(239, 68, 68, 0.3); color: white; }
.heatmap .value.h3 { background: rgba(239, 68, 68, 0.2); }
.heatmap .value.h4 { background: rgba(239, 68, 68, 0.1); }
.heatmap .value.h5 { background: rgba(239, 68, 68, 0.05); }

/* ===== Categoría con barra ===== */
.cat-bar-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(51, 65, 85, 0.3);
}
.cat-bar-row:last-child { border-bottom: none; }
.cat-bar-row .ico { font-size: 20px; width: 28px; text-align: center; }
.cat-bar-row .info { flex: 1; min-width: 0; }
.cat-bar-row .nombre { font-weight: 600; font-size: 13px; margin-bottom: 4px; display: flex; justify-content: space-between; }
.cat-bar-row .nombre span:last-child { color: var(--text-dim); }
.cat-bar-row .over { color: var(--danger) !important; }

/* ===== Chart container ===== */
.chart-container { position: relative; height: 280px; }
.chart-container.tall { height: 340px; }
.chart-container.short { height: 200px; }

/* ===== Color picker mini ===== */
.color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.color-grid button {
  height: 30px;
  border-radius: 6px;
  border: 2px solid transparent;
  transition: transform 0.1s, border 0.15s;
}
.color-grid button:hover { transform: scale(1.1); }
.color-grid button.active { border-color: white; transform: scale(1.1); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: -260px;
    transition: left 0.25s;
  }
  .sidebar.open { left: 0; box-shadow: var(--shadow-lg); }
  .topbar { display: flex; }
  .route-content { padding: 16px; }
  .page-head h1 { font-size: 20px; }
  .kpi-value { font-size: 22px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .filters { padding: 10px; }
  .modal-box { max-height: 95vh; }
}

@media (max-width: 480px) {
  .kpis { grid-template-columns: 1fr; }
  .toast-container { top: 10px; right: 10px; left: 10px; }
  .toast { min-width: 0; }
}

/* ===== Loader ===== */
.loader {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-page {
  display: flex; align-items: center; justify-content: center;
  padding: 60px;
  color: var(--text-dim);
}
.loading-page .loader { margin-right: 12px; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-state p { font-size: 13px; }
