/* =====================================================
   FINANZAS PERSONALES - DESIGN SYSTEM
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  /* Colores */
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255,255,255,0.04);
  --bg-card-hover: rgba(255,255,255,0.07);
  --border: rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.15);

  --accent-purple: #8b5cf6;
  --accent-cyan: #06b6d4;
  --accent-green: #10b981;
  --accent-red: #f43f5e;
  --accent-yellow: #f59e0b;
  --accent-blue: #3b82f6;
  --accent-pink: #ec4899;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --gradient-primary: linear-gradient(135deg, #8b5cf6, #06b6d4);
  --gradient-green: linear-gradient(135deg, #10b981, #06b6d4);
  --gradient-red: linear-gradient(135deg, #f43f5e, #f59e0b);

  /* Espaciado */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Bordes */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  /* Sombras */
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-purple: 0 0 30px rgba(139,92,246,0.15);
  --shadow-cyan: 0 0 30px rgba(6,182,212,0.15);

  /* Sidebar */
  --sidebar-width: 240px;
  --bottom-nav-height: 64px;
}

/* ======================== RESET ======================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* ======================== SCROLLBAR ======================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--accent-purple); border-radius: 3px; }

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

/* === SIDEBAR (desktop) === */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
  transition: transform 0.3s ease;
}

.sidebar-logo {
  padding: var(--space-lg) var(--space-md);
  border-bottom: 1px solid var(--border);
}
.sidebar-logo h1 {
  font-size: 16px;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.sidebar-logo p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav {
  padding: var(--space-md) var(--space-sm);
  flex: 1;
}
.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: var(--space-sm) var(--space-sm);
  margin-top: var(--space-sm);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  margin-bottom: 2px;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}
.nav-item.active {
  background: rgba(139,92,246,0.15);
  color: var(--accent-purple);
  border: 1px solid rgba(139,92,246,0.2);
}
.nav-item .nav-icon { font-size: 16px; width: 20px; text-align: center; }

/* === MAIN CONTENT === */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--space-xl);
  min-height: 100vh;
}

/* === PAGES === */
.page { display: none; }
.page.active { display: block; }

/* === PAGE HEADER === */
.page-header {
  margin-bottom: var(--space-xl);
}
.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}
.page-header p {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}
.page-header-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
}

/* ======================== CARDS ======================== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  backdrop-filter: blur(10px);
  transition: all 0.2s;
}
.card:hover {
  border-color: var(--border-hover);
  background: var(--bg-card-hover);
}
.card-sm { padding: var(--space-md); border-radius: var(--radius-md); }

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  position: relative;
  overflow: hidden;
  transition: all 0.25s;
}
.metric-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: var(--gradient-primary);
}
.metric-card:hover {
  transform: translateY(-2px);
  border-color: rgba(139,92,246,0.3);
  box-shadow: var(--shadow-purple);
}
.metric-card.green::before { background: var(--gradient-green); }
.metric-card.green:hover { border-color: rgba(16,185,129,0.3); box-shadow: var(--shadow-cyan); }
.metric-card.red::before { background: var(--gradient-red); }
.metric-card.red:hover { border-color: rgba(244,63,94,0.3); box-shadow: 0 0 30px rgba(244,63,94,0.15); }

.metric-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: var(--space-xs);
}
.metric-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.metric-value.green { color: var(--accent-green); }
.metric-value.red { color: var(--accent-red); }
.metric-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}
.metric-icon {
  position: absolute;
  right: var(--space-lg);
  top: 50%;
  transform: translateY(-50%);
  font-size: 28px;
  opacity: 0.15;
}

/* ======================== GRIDS ======================== */
.grid-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-xl);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-md); }

/* ======================== BUTTONS ======================== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: 9px var(--space-md);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--gradient-primary);
  color: white;
  box-shadow: 0 0 20px rgba(139,92,246,0.3);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 30px rgba(139,92,246,0.5);
}
.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-card-hover); border-color: var(--border-hover); }
.btn-danger { background: rgba(244,63,94,0.15); color: var(--accent-red); border: 1px solid rgba(244,63,94,0.2); }
.btn-danger:hover { background: rgba(244,63,94,0.25); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-icon { padding: 8px; }

/* ======================== FORMS ======================== */
.form-group { margin-bottom: var(--space-md); }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.form-control {
  width: 100%;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: 10px var(--space-md);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s;
}
.form-control:focus {
  border-color: var(--accent-purple);
  background: rgba(139,92,246,0.05);
  box-shadow: 0 0 0 3px rgba(139,92,246,0.1);
}
.form-control option { background: var(--bg-secondary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-md); }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-md); }

/* ======================== TABLES ======================== */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead {
  background: rgba(255,255,255,0.03);
  position: sticky;
  top: 0;
  z-index: 1;
}
th {
  padding: var(--space-md);
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 12px var(--space-md);
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-primary);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-card-hover); }
.td-muted { color: var(--text-muted); }
.td-accent { color: var(--accent-purple); font-weight: 600; }

/* ======================== BADGES ======================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.badge-purple { background: rgba(139,92,246,0.15); color: var(--accent-purple); }
.badge-cyan { background: rgba(6,182,212,0.15); color: var(--accent-cyan); }
.badge-green { background: rgba(16,185,129,0.15); color: var(--accent-green); }
.badge-red { background: rgba(244,63,94,0.15); color: var(--accent-red); }
.badge-yellow { background: rgba(245,158,11,0.15); color: var(--accent-yellow); }
.badge-blue { background: rgba(59,130,246,0.15); color: var(--accent-blue); }
.badge-pink { background: rgba(236,72,153,0.15); color: var(--accent-pink); }

/* ======================== MODAL ======================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: var(--space-md);
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md), var(--shadow-purple);
  animation: modalIn 0.25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer; padding: 4px; border-radius: 6px;
  transition: all 0.2s;
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-card); }
.modal-footer { display: flex; gap: var(--space-sm); justify-content: flex-end; margin-top: var(--space-lg); }

/* ======================== BOTTOM NAV (mobile) ======================== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  z-index: 100;
  backdrop-filter: blur(10px);
}
.bottom-nav-inner {
  display: flex;
  height: 100%;
}
.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  transition: all 0.2s;
  border: none;
  background: none;
  padding: 4px;
}
.bottom-nav-item .nav-icon { font-size: 20px; }
.bottom-nav-item.active { color: var(--accent-purple); }
.bottom-nav-item span:last-child { font-size: 9px; }

/* ======================== ALERT / TOAST ======================== */
.toast-container {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px var(--space-md);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s ease;
  min-width: 260px;
}
.toast.success { border-color: rgba(16,185,129,0.4); color: var(--accent-green); }
.toast.error { border-color: rgba(244,63,94,0.4); color: var(--accent-red); }
.toast.info { border-color: rgba(139,92,246,0.4); color: var(--accent-purple); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ======================== PROGRESS BAR ======================== */
.progress-bar {
  height: 6px;
  background: var(--bg-card);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--gradient-primary);
  transition: width 0.5s ease;
}
.progress-fill.green { background: var(--gradient-green); }
.progress-fill.red { background: var(--gradient-red); }

/* ======================== SWITCH ======================== */
.switch-wrapper { display: flex; align-items: center; gap: var(--space-sm); cursor: pointer; }
.switch {
  width: 40px; height: 22px;
  background: var(--text-muted);
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.switch.on { background: var(--accent-purple); }
.switch::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform 0.2s;
}
.switch.on::after { transform: translateX(18px); }

/* ======================== EMPTY STATE ======================== */
.empty-state {
  text-align: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: var(--space-md); opacity: 0.5; }
.empty-state p { font-size: 14px; }

/* ======================== CUOTAS INDICATOR ======================== */
.cuotas-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: rgba(139,92,246,0.1);
  border: 1px solid rgba(139,92,246,0.2);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent-purple);
}
.cuotas-chip.warning { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.2); color: var(--accent-yellow); }
.cuotas-chip.last { background: rgba(16,185,129,0.1); border-color: rgba(16,185,129,0.2); color: var(--accent-green); }

/* ======================== MONTH SELECTOR ======================== */
.month-selector {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px var(--space-md);
}
.month-selector button {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 16px; padding: 2px 4px; border-radius: 4px;
  transition: all 0.2s;
}
.month-selector button:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.month-selector span { font-size: 13px; font-weight: 600; min-width: 120px; text-align: center; }

/* ======================== LOADING ======================== */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
  color: var(--text-muted);
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: var(--space-sm);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ======================== INVESTMENT TYPE COLORS ======================== */
[data-tipo="accion"] { color: var(--accent-blue); }
[data-tipo="letra"] { color: var(--accent-yellow); }
[data-tipo="cripto"] { color: var(--accent-cyan); }
[data-tipo="cedear"] { color: var(--accent-purple); }
[data-tipo="fci"] { color: var(--accent-green); }
[data-tipo="bono"] { color: var(--accent-pink); }
[data-tipo="otro"] { color: var(--text-secondary); }

/* ======================== TARJETA CARD ======================== */
.tarjeta-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  position: relative;
  overflow: hidden;
  transition: all 0.25s;
}
.tarjeta-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.tarjeta-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* ======================== SEPARATOR ======================== */
.separator {
  height: 1px;
  background: var(--border);
  margin: var(--space-lg) 0;
}

/* ======================== TEXT UTILS ======================== */
.text-green { color: var(--accent-green) !important; }
.text-red { color: var(--accent-red) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-purple { color: var(--accent-purple) !important; }
.text-cyan { color: var(--accent-cyan) !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.font-mono { font-family: 'SF Mono', 'Fira Code', monospace; }

/* ======================== RESPONSIVE ======================== */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .main-content {
    margin-left: 0;
    padding: var(--space-md);
    padding-bottom: calc(var(--bottom-nav-height) + var(--space-md));
  }
  .grid-metrics { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-header-actions { flex-direction: column; align-items: flex-start; }
  .modal { padding: var(--space-lg); max-width: 100%; border-radius: var(--radius-lg); }
  .metric-value { font-size: 20px; }
  table { font-size: 12px; }
  th, td { padding: 10px var(--space-sm); }
}

@media (max-width: 420px) {
  .grid-metrics { grid-template-columns: 1fr; }
}
