/* ============================================================
   FINANZAS FAMILIARES – app.css
   Sistema de Finanzas de la Familia Mayo
   ============================================================ */

/* ---------- VARIABLES ------------------------------------ */
:root {
  --primary:      #e91e8c;
  --primary-dark: #ad1373;
  --primary-light:#f48fb1;
  --secondary:    #1976d2;
  --success:      #2e7d32;
  --warning:      #f57f17;
  --danger:       #c62828;
  --bg:           #fafafa;
  --surface:      #ffffff;
  --sidebar-bg:   #1a1a2e;
  --sidebar-text: #e8eaf6;
  --sidebar-w:    260px;
  --text:         #212121;
  --text-muted:   #757575;
  --border:       #e0e0e0;
  --shadow:       0 2px 8px rgba(0,0,0,0.08);
  --radius:       10px;
  --radius-lg:    16px;
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:    'Courier New', monospace;
  --transition:   all 0.22s ease;
}

/* ---------- RESET ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; overflow-x: hidden; }
button { cursor: pointer; font-family: inherit; }
a { text-decoration: none; color: inherit; }
input, select, textarea { font-family: inherit; }
img { max-width: 100%; }

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

/* ---------- SIDEBAR -------------------------------------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  overflow-y: auto;
  transition: transform 0.28s ease;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.18); border-radius: 4px; }

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.sidebar-logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary-light);
  letter-spacing: 0.3px;
  line-height: 1.3;
}
.sidebar-logo span { display: block; font-size: 0.75rem; color: rgba(255,255,255,0.5); font-weight: 400; margin-top: 2px; }

.sidebar-nav { padding: 12px 0; flex: 1; }
.nav-section-title {
  padding: 10px 20px 4px;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.35);
  font-weight: 600;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
  font-size: 0.88rem;
  color: rgba(255,255,255,0.75);
  user-select: none;
}
.nav-item:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
}
.nav-item.active {
  background: rgba(233,30,140,0.18);
  border-left-color: var(--primary);
  color: #fff;
}
.nav-item .nav-icon { font-size: 1.1rem; width: 22px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  border-radius: 10px;
  padding: 2px 7px;
  font-size: 0.7rem;
  font-weight: 700;
}

.sidebar-footer {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.07);
  font-size: 0.73rem;
  color: rgba(255,255,255,0.3);
}

/* ---------- MAIN CONTENT --------------------------------- */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}
.topbar-title { font-size: 1.2rem; font-weight: 700; color: var(--text); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-date { font-size: 0.8rem; color: var(--text-muted); }

/* Hamburger */
.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text);
  padding: 4px;
}

.page-content {
  padding: 24px 28px;
  flex: 1;
}

/* ---------- BUTTONS -------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-primary   { background: var(--primary);   color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { filter: brightness(1.1); }
.btn-success   { background: var(--success);   color: #fff; }
.btn-success:hover { filter: brightness(1.1); }
.btn-danger    { background: var(--danger);    color: #fff; }
.btn-outline   { background: transparent; border: 2px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost     { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: rgba(233,30,140,0.07); }
.btn-sm        { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg        { padding: 12px 24px; font-size: 1rem; }
.btn-icon      { padding: 8px; border-radius: 50%; }
.btn:disabled  { opacity: 0.45; cursor: not-allowed; }

/* ---------- CARDS ---------------------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 18px 22px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.card-body { padding: 20px 22px; }

/* ---------- STAT CARDS ----------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-left: 4px solid var(--primary);
  transition: var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); }
.stat-card.verde  { border-left-color: var(--success); }
.stat-card.azul   { border-left-color: var(--secondary); }
.stat-card.rojo   { border-left-color: var(--danger); }
.stat-card.naranja{ border-left-color: var(--warning); }
.stat-card.morado { border-left-color: #7b1fa2; }

.stat-label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-sub   { font-size: 0.75rem; color: var(--text-muted); }
.stat-icon  { font-size: 1.8rem; align-self: flex-start; margin-left: auto; }

/* ---------- SALUD FINANCIERA ----------------------------- */
.salud-container {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}
.salud-header { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.salud-emoji  { font-size: 2.2rem; }
.salud-titulo { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); font-weight: 600; }
.salud-nivel  { font-size: 1.4rem; font-weight: 800; }
.salud-puntaje { font-size: 0.85rem; color: var(--text-muted); }

.barra-salud-bg {
  background: #f0f0f0;
  border-radius: 100px;
  height: 12px;
  overflow: hidden;
  margin-bottom: 14px;
}
.barra-salud-fill {
  height: 100%;
  border-radius: 100px;
  transition: width 0.8s cubic-bezier(0.4,0,0.2,1);
}
.salud-factores { display: flex; flex-wrap: wrap; gap: 8px; }
.factor-tag {
  padding: 4px 11px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}
.factor-tag.bueno       { background: #e8f5e9; color: #2e7d32; }
.factor-tag.advertencia { background: #fff8e1; color: #f57f17; }
.factor-tag.malo        { background: #ffebee; color: #c62828; }

/* ---------- ALERTAS -------------------------------------- */
.alertas-lista { display: flex; flex-direction: column; gap: 8px; }
.alerta-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 0.875rem;
}
.alerta-item.vencido  { background: #ffebee; border-left: 4px solid var(--danger); }
.alerta-item.hoy      { background: #fff3e0; border-left: 4px solid var(--warning); }
.alerta-item.proximo  { background: #e3f2fd; border-left: 4px solid var(--secondary); }
.alerta-badge { font-weight: 700; min-width: 38px; font-size: 0.8rem; }
.alerta-badge.vencido  { color: var(--danger); }
.alerta-badge.hoy      { color: var(--warning); }
.alerta-badge.proximo  { color: var(--secondary); }
.alerta-titulo  { font-weight: 600; }
.alerta-sub     { font-size: 0.77rem; color: var(--text-muted); }

/* ---------- TABLAS --------------------------------------- */
.tabla-container { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; min-width: 540px; }
th {
  background: #f5f5f5;
  padding: 11px 14px;
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  font-weight: 700;
  white-space: nowrap;
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

.monto-ingreso { color: var(--success); font-weight: 700; }
.monto-gasto   { color: var(--danger);  font-weight: 700; }
.monto-neutral { color: var(--text);    font-weight: 700; }

/* ---------- TARJETAS DE CRÉDITO (visual) ----------------- */
.tarjetas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.credit-card {
  border-radius: 14px;
  padding: 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
  min-height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  cursor: pointer;
  transition: var(--transition);
}
.credit-card:hover { transform: translateY(-3px); box-shadow: 0 8px 28px rgba(0,0,0,0.22); }
.credit-card::before {
  content: '';
  position: absolute;
  top: -30%;
  right: -15%;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
}
.cc-banco  { font-size: 0.78rem; opacity: 0.85; text-transform: uppercase; letter-spacing: 1px; }
.cc-nombre { font-size: 1.1rem;  font-weight: 700; margin-top: 4px; }
.cc-tipo   { font-size: 0.7rem;  opacity: 0.7; text-transform: uppercase; }
.cc-bottom { display: flex; align-items: flex-end; justify-content: space-between; }
.cc-deuda  { font-size: 0.7rem; opacity: 0.8; }
.cc-monto  { font-size: 1.4rem; font-weight: 800; line-height: 1; }
.cc-pago   { font-size: 0.7rem; opacity: 0.8; text-align: right; }
.cc-dia    { font-size: 1.1rem; font-weight: 700; }
.cc-badge-vencido {
  position: absolute; top: 10px; right: 10px;
  background: var(--danger); color: #fff;
  border-radius: 6px; padding: 2px 8px; font-size: 0.7rem; font-weight: 700;
}
.cc-badge-proximo {
  position: absolute; top: 10px; right: 10px;
  background: var(--warning); color: #fff;
  border-radius: 6px; padding: 2px 8px; font-size: 0.7rem; font-weight: 700;
}

/* ---------- FORMULARIOS ---------------------------------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
label { font-size: 0.82rem; font-weight: 600; color: var(--text); }
.form-control {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: var(--transition);
  background: var(--surface);
  color: var(--text);
  width: 100%;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(233,30,140,0.1); }
.form-control:invalid:not(:placeholder-shown) { border-color: var(--danger); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: 0.75rem; color: var(--text-muted); }
.form-error { font-size: 0.75rem; color: var(--danger); }

.section-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ---------- TABS ----------------------------------------- */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 2px; }
.tab {
  padding: 10px 18px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
  white-space: nowrap;
}
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- BADGES --------------------------------------- */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-danger  { background: #ffebee; color: #c62828; }
.badge-warning { background: #fff8e1; color: #f57f17; }
.badge-info    { background: #e3f2fd; color: #1565c0; }
.badge-purple  { background: #f3e5f5; color: #6a1b9a; }
.badge-orange  { background: #fff3e0; color: #e65100; }
.badge-gray    { background: #f5f5f5; color: #616161; }

/* ---------- PERSONA CHIPS -------------------------------- */
.persona-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 600;
}
.persona-cristi   { background: rgba(233,30,140,0.13);  color: #ad1373; }
.persona-carlos   { background: rgba(25,118,210,0.13);  color: #1565c0; }
.persona-hijos    { background: rgba(56,142,60,0.13);   color: #2e7d32; }
.persona-negocio  { background: rgba(245,124,0,0.13);   color: #e65100; }
.persona-mascotas { background: rgba(123,31,162,0.13);  color: #6a1b9a; }
.persona-familiar { background: rgba(69,90,100,0.13);   color: #37474f; }

/* ---------- FILTROS / TOOLBAR ---------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.toolbar .lbl { font-size: 0.82rem; color: var(--text-muted); font-weight: 600; }
.select-sm {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.select-sm:focus { outline: none; border-color: var(--primary); }
.input-sm {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  background: var(--surface);
}
.input-sm:focus { outline: none; border-color: var(--primary); }

/* ---------- MODAL ---------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform 0.2s;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.3rem; color: var(--text-muted); padding: 4px 8px; border-radius: 6px; }
.modal-close:hover { background: #f5f5f5; }
.modal-body   { padding: 20px 24px; }
.modal-footer { padding: 14px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- EMPTY STATE ---------------------------------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 3.5rem; margin-bottom: 14px; }
.empty-state h3    { font-size: 1.1rem; color: var(--text); margin-bottom: 6px; }
.empty-state p     { font-size: 0.875rem; }

/* ---------- TOAST ---------------------------------------- */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  display: flex; align-items: center; gap: 10px;
  min-width: 220px;
  animation: toastIn 0.22s ease;
}
.toast.success { background: var(--success); }
.toast.danger  { background: var(--danger);  }
.toast.warning { background: #e65100; }
@keyframes toastIn {
  from { transform: translateX(100px); opacity: 0; }
  to   { transform: translateX(0);     opacity: 1; }
}

/* ---------- CALENDARIO MINI ------------------------------ */
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  font-size: 0.77rem;
}
.cal-header-day { text-align: center; font-weight: 700; color: var(--text-muted); padding: 4px 0; }
.cal-day {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px;
  cursor: default;
  transition: var(--transition);
  position: relative;
}
.cal-day.hoy { background: var(--primary); color: #fff; font-weight: 700; }
.cal-day.tiene-pago { background: #fff3e0; color: #e65100; font-weight: 700; cursor: pointer; }
.cal-day.tiene-pago:hover { background: #ffe0b2; }
.cal-day.vacio { pointer-events: none; }
.cal-dot {
  position: absolute; bottom: 2px;
  width: 4px; height: 4px; border-radius: 50%; background: var(--danger);
}

/* ---------- PROGRESS BARS -------------------------------- */
.progress-bar-bg { background: #f0f0f0; border-radius: 100px; height: 8px; overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 100px; transition: width 0.6s ease; }
.progress-verde  { background: var(--success); }
.progress-rojo   { background: var(--danger);  }
.progress-naranja{ background: var(--warning); }
.progress-azul   { background: var(--secondary); }

/* ---------- RESUMEN POR PERSONA -------------------------- */
.persona-resumen-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.persona-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border-top: 4px solid var(--primary);
}
.persona-card-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 8px; }
.persona-card-monto{ font-size: 1.3rem; font-weight: 800; }

/* ---------- GRAFICA BARRAS SIMPLE (CSS only) ------------- */
.barras-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 120px;
  padding: 0 4px;
}
.barra-item {
  display: flex; flex-direction: column; align-items: center;
  flex: 1; gap: 4px;
}
.barra-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  background: var(--primary);
  transition: height 0.6s ease;
  min-height: 4px;
}
.barra-label { font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; }
.barra-val   { font-size: 0.7rem; font-weight: 700; color: var(--text); }

/* ---------- SIDEBAR MOBILE ------------------------------- */
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
}

/* ---------- RESPONSIVE ----------------------------------- */
@media (max-width: 900px) {
  :root { --sidebar-w: 260px; }
  .main-content { margin-left: 0; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .hamburger { display: block; }
  .page-content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 560px) {
  .stats-grid { grid-template-columns: 1fr; }
  .tarjetas-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: flex-start; }
  table { min-width: 100%; font-size: 0.8rem; }
}

/* ---------- UTILIDADES ----------------------------------- */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--text-muted); }
.text-success{ color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning{ color: var(--warning); }
.text-bold   { font-weight: 700; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex  { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-center  { display: flex; align-items: center; justify-content: center; }
.gap-8   { gap: 8px; }
.gap-12  { gap: 12px; }
.hidden  { display: none !important; }
.w-full  { width: 100%; }
