/* =============================================
   APP SHELL: SIDEBAR + MAIN
   ============================================= */
#contenedor-app {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.app-sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
  transition:
    width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.3s;
  overflow: hidden;
}

.sidebar-header {
  height: 66px;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  box-sizing: border-box;
}

.sidebar-brand {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.sidebar-brand em {
  color: var(--accent-green);
  font-style: normal;
}

.sidebar-logo-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: rgba(116, 197, 245, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--brand-celeste);
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0.75rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav::-webkit-scrollbar {
  width: 3px;
}
.sidebar-nav::-webkit-scrollbar-track {
  background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 99px;
}

.sidebar-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.75rem 0.6rem 0.25rem;
  white-space: nowrap;
}

.nav-link-sidebar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition:
    background 0.15s,
    color 0.15s;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  white-space: nowrap;
  position: relative;
}

.nav-link-sidebar:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.nav-link-sidebar.active {
  background: rgba(116, 197, 245, 0.1);
  color: var(--brand-celeste);
}

.nav-link-sidebar .nav-icon {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.nav-link-sidebar .nav-badge {
  margin-left: auto;
  font-size: 0.65rem;
  background: rgba(240, 68, 90, 0.15);
  color: var(--accent-red);
  border-radius: 99px;
  padding: 0.1rem 0.45rem;
  font-weight: 700;
}

.sidebar-footer {
  padding: 1rem 0.75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--radius-md);
  background: var(--bg-hover);
}

.sidebar-user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(167, 139, 250, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-violet);
  font-size: 0.8rem;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Main Content ---------- */
.app-main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  transition: margin-left 0.3s;
}

.main-topbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  height: 66px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  box-sizing: border-box;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(8px);
}

.topbar-title-group {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.topbar-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  color: var(--text-primary);
  font-weight: 400;
  letter-spacing: -0.3px;
  line-height: 1.2;
}

.topbar-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.25rem;
}

.main-content {
  padding: 2rem;
  max-width: 1400px;
}

/* =============================================
   MOBILE OVERLAY
   ============================================= */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 99;
  backdrop-filter: blur(2px);
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 900px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: 8px 0 40px rgba(0, 0, 0, 0.6);
  }
  .app-main {
    margin-left: 0;
  }
  .main-content {
    padding: 1.25rem;
    padding-bottom: 5.5rem;
  } /* espacio para la barra inferior */
  .sidebar-toggle {
    display: none;
  } /* reemplazada por la barra inferior */
  .sidebar-overlay.visible {
    display: block;
  }
  .bottom-nav {
    display: flex;
  } /* barra inferior visible solo en mobile */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }



  /* Los grids con columnas fijas inline colapsan en pantallas chicas */
  .kpi-grid[style*="repeat(3"],
  .kpi-grid[style*="repeat(5"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .kpi-grid[style*="repeat(3"],
  .kpi-grid[style*="repeat(5"] {
    grid-template-columns: 1fr !important;
  }

  #dashboard .kpi-grid {
    display: flex;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  #dashboard .kpi-grid::-webkit-scrollbar {
    height: 4px;
  }

  #dashboard .kpi-grid::-webkit-scrollbar-track {
    background: transparent;
  }

  #dashboard .kpi-grid::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 2px;
  }

  #dashboard .kpi-grid .kpi-card {
    flex: 0 0 100%;
    min-width: 0;
    scroll-snap-align: center;
  }
  .features-grid {
    grid-template-columns: 1fr;
  }
  .main-topbar {
    padding: 0.75rem 1rem;
  }
  .main-content {
    padding: 1rem;
    padding-bottom: 6rem;
  } /* mantener espacio para la barra inferior */

  /* KPIs más compactos */
  .kpi-card {
    padding: 1rem 1.1rem;
  }
  .kpi-value {
    font-size: 1.6rem;
  }

  /* Gráficos: altura controlada y contenedor que respeta el ancho */
  .chart-card {
    padding: 1rem;
  }
  .chart-card > div[style*="height"] {
    height: 260px !important;
  }

  /* La fila de 2 charts (Top categorías + Balance) se apila bien */
  .chart-card .chart-title {
    font-size: 0.65rem;
  }

  /* Topbar: el badge del mes puede ocupar mucho, lo achicamos */
  #topbarMes {
    font-size: 0.62rem !important;
  }
  .topbar-title {
    font-size: 1.05rem;
  }
  .topbar-subtitle {
    display: none;
  }

  /* Hint visual de scroll en tablas */
  .table-wrapper {
    position: relative;
  }

}

/* En cualquier pantalla angosta, los charts no deben pasarse del contenedor */
@media (max-width: 768px) {
  .chart-card canvas {
    max-width: 100% !important;
  }
}

/* =============================================
   PRIVACIDAD: ocultar valores con desenfoque (toggle del ojo)
   Afecta KPIs del dashboard, infolets, y los totales de
   Ingresos/Gastos/Ahorros/Cuotas/Mensuales (clase .total-value),
   más los montos de la tendencia de Ahorros.
   Los registros de las tablas NO se ven afectados.
   ============================================= */
.kpi-value,
.infolet-valor,
.total-value,
#resumenAhorrosMeses .summary-item > div {
  transition: filter 0.2s ease;
}

body.valores-ocultos .kpi-value,
body.valores-ocultos .infolet-valor,
body.valores-ocultos .total-value,
body.valores-ocultos #resumenAhorrosMeses .summary-item > div {
  filter: blur(8px);
  user-select: none;
  pointer-events: none;
}

/* =============================================
   BOTÓN FLOTANTE (FAB) — carga rápida Ingreso/Gasto
   ============================================= */
.fab-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1035;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.85rem;
  /* El área del contenedor no debe bloquear clics a los elementos
     que quedan detrás; solo los botones reales capturan eventos. */
  pointer-events: none;
}
@media (max-width: 900px) {
  .fab-container {
    bottom: 5.5rem; /* por encima de la barra de navegación inferior */
    right: 1.25rem;
  }
}

.fab-main {
  pointer-events: auto;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--brand-celeste);
  color: #041424;
  font-size: 1.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition:
    transform 0.25s ease,
    background 0.2s;
}
.fab-main:hover {
  background: #90d4f8;
}
.fab-container.abierto .fab-main {
  transform: rotate(45deg);
}

.fab-options {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  align-items: flex-end;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition:
    opacity 0.2s ease,
    transform 0.2s ease;
}
.fab-container.abierto .fab-options {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.fab-option {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}
.fab-option-label {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
.fab-option-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.fab-option-icon.ingreso {
  background: var(--accent-green);
}
.fab-option-icon.gasto {
  background: var(--accent-red);
}
.fab-option-icon.tarjeta {
  background: var(--accent-amber);
}

.fab-overlay {
  position: fixed;
  inset: 0;
  z-index: 1030;
  background: transparent;
  display: none;
}
.fab-overlay.visible {
  display: block;
}
