:root {
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-color: #e2e8f0;
  --border-hover: #cbd5e1;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;

  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #a7f3d0;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fde68a;

  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --transition: all 0.2s ease-in-out;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

img, svg {
  max-width: 100%;
  height: auto;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* APP LAYOUT */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
}

/* BARRA LATERAL DE NAVEGACIÓN */
.app-header {
  width: 260px;
  min-width: 260px;
  max-width: 260px;
  flex-shrink: 0;
  background-color: var(--bg-card);
  border-right: 1px solid var(--border-color);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
  padding-left: 6px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.brand-logo {
  width: 38px;
  height: 38px;
  min-width: 38px;
  max-width: 38px;
  min-height: 38px;
  max-height: 38px;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.15);
}

.brand-logo img,
.brand-logo-img {
  width: 38px !important;
  height: 38px !important;
  min-width: 38px !important;
  min-height: 38px !important;
  max-width: 38px !important;
  max-height: 38px !important;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

.brand-info h1 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.main-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  text-align: left;
}

.nav-btn:hover {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

.nav-btn.active {
  background-color: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}

.badge-dot {
  width: 8px;
  height: 8px;
  background-color: var(--warning);
  border-radius: 50%;
  position: absolute;
  right: 14px;
}

.header-action {
  padding-top: 18px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-logout {
  width: 100%;
  color: var(--text-muted);
  justify-content: center;
  gap: 8px;
  font-size: 0.84rem;
}

.btn-logout:hover {
  color: var(--danger);
  background-color: #fef2f2;
}

.mobile-logout-btn {
  display: none;
}

/* ÁREA PRINCIPAL */
.app-main {
  flex: 1;
  padding: 24px 32px;
  max-width: 1360px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

/* TOPBAR */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 16px;
  width: 100%;
}

.topbar-title h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.text-muted {
  color: var(--text-muted);
}

.text-sm {
  font-size: 0.85rem;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.month-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

/* VISTAS */
.content-view {
  display: none;
  width: 100%;
  min-width: 0;
}

.content-view.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* KPI GRID FLUIDO Y ADAPTABLE */
.kpi-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
  width: 100%;
}

.kpi-card {
  background: var(--bg-card);
  padding: 16px 18px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: var(--transition);
  min-width: 0;
  overflow: hidden;
}

.kpi-card:hover {
  box-shadow: var(--shadow-md);
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  gap: 6px;
}

.kpi-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-icon {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-income { background-color: var(--success-bg); color: var(--success); }
.icon-expense { background-color: #fef2f2; color: #dc2626; }
.icon-balance { background-color: var(--primary-light); color: var(--primary); }
.icon-rate { background-color: #eff6ff; color: #2563eb; }
.icon-saved { background-color: #ecfdf5; color: #059669; }

.kpi-card-highlight {
  border-color: #a7f3d0;
  background: linear-gradient(180deg, #ffffff 0%, #f0fdf4 100%);
}

.kpi-value {
  font-size: clamp(1.2rem, 1.8vw, 1.55rem);
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.5px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.kpi-footnote {
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.kpi-progress {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
  margin: 6px 0;
}

.kpi-progress-fill {
  height: 100%;
  background-color: var(--success);
  border-radius: 99px;
  transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ALERT BANNER */
.alert-banner {
  padding: 12px 18px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.alert-danger {
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: #b91c1c;
}

.alert-warning {
  background-color: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: #b45309;
}

/* GRÁFICOS */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
  width: 100%;
  min-width: 0;
}

.chart-card {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
  gap: 8px;
}

.chart-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chart-body {
  position: relative;
  height: 270px;
  width: 100%;
  min-width: 0;
}

.chart-body canvas {
  width: 100% !important;
  height: 100% !important;
  max-width: 100% !important;
}

.chart-body-tall {
  height: 270px;
}

.dashboard-secondary-grid {
  display: grid;
  grid-template-columns: 1.8fr 1.2fr;
  gap: 20px;
  width: 100%;
  min-width: 0;
}

.top-categories-card {
  background: var(--bg-card);
  padding: 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
  overflow: hidden;
}

.top-categories-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 12px;
}

.cat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cat-item-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 500;
}

.cat-bar-bg {
  width: 100%;
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
}

.cat-bar-fill {
  height: 100%;
  background-color: var(--primary);
  border-radius: 99px;
}

/* SECCIONES Y TABLAS */
.two-column-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.section-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 24px;
}

.card-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  gap: 12px;
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 160px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg-app);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.list-item:hover {
  background: #ffffff;
  border-color: var(--border-hover);
  box-shadow: var(--shadow-sm);
}

.item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.item-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.item-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
}

.item-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.item-amount {
  font-weight: 700;
  font-size: 1.05rem;
}

.item-actions {
  display: flex;
  gap: 6px;
}

.action-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.action-icon-btn:hover {
  color: var(--text-main);
  background: var(--bg-subtle);
}

.action-icon-btn.btn-delete:hover {
  color: var(--danger);
  background: var(--danger-bg);
}

.card-footer-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px dashed var(--border-color);
  font-size: 0.95rem;
  color: var(--text-muted);
}

.card-footer-total strong {
  font-size: 1.2rem;
  color: var(--text-main);
}

/* TABLA GASTOS VARIABLES */
.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  gap: 12px;
  flex: 1;
  max-width: 600px;
}

.search-input {
  flex: 2;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.9rem;
}

.data-table th {
  padding: 12px 14px;
  background-color: var(--bg-app);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
}

.data-table tbody tr:hover {
  background-color: #fafbfc;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.badge-category {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* CONSEJOS Y ALERTAS */
.advice-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.subsection-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-main);
}

.advice-cards-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.advice-card {
  background: var(--bg-card);
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: var(--transition);
}

.advice-card:hover {
  box-shadow: var(--shadow-md);
}

.advice-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.advice-tag {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}

.advice-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-main);
}

.advice-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.advice-alert-danger {
  border-left: 4px solid var(--danger);
}
.advice-alert-danger .advice-tag {
  background: var(--danger-bg);
  color: var(--danger);
}

.advice-alert-warning {
  border-left: 4px solid var(--warning);
}
.advice-alert-warning .advice-tag {
  background: var(--warning-bg);
  color: #b45309;
}

.advice-alert-info {
  border-left: 4px solid var(--primary);
}
.advice-alert-info .advice-tag {
  background: var(--primary-light);
  color: var(--primary);
}

/* BOTONES Y FORMULARIOS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-outline {
  background-color: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background-color: var(--bg-subtle);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background-color: var(--bg-subtle);
  color: var(--text-main);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.82rem;
}

.text-input, .select-input {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: #ffffff;
  color: var(--text-main);
  outline: none;
  transition: var(--transition);
  width: 100%;
}

.text-input:focus, .select-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* MODALES */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: fadeIn 0.15s ease;
}

.modal-dialog {
  background: var(--bg-card);
  width: 90%;
  max-width: 460px;
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 600;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px;
}

.btn-close:hover {
  color: var(--text-main);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}

/* TOASTS */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  box-shadow: var(--shadow-md);
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Reglas base para elementos móviles en desktop */
.mobile-sub {
  display: none;
}

.mobile-fab {
  display: none;
}

/* PIE DE PÁGINA (FOOTER) */
.app-footer {
  margin-top: 48px;
  padding: 24px 16px;
  border-top: 1px solid var(--border-color);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.6;
}

.app-footer strong {
  color: var(--text-main);
  font-weight: 600;
}

/* ============================================================
   SISTEMA DE ADAPTACIÓN RESPONSIVA Y MÓVIL (Mobile & Tablet)
   ============================================================ */

/* Reglas globales anti-desbordamiento */
html, body {
  max-width: 100vw;
  overflow-x: hidden;
}

canvas {
  max-width: 100% !important;
}

/* 1. TABLETS Y PANTALLAS MEDIANAS (hasta 1150px) */
@media (max-width: 1150px) {
  .app-main {
    padding: 20px 24px;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .kpi-card-highlight {
    grid-column: 1 / -1;
  }

  .charts-grid,
  .dashboard-secondary-grid,
  .two-column-layout,
  .advice-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
}

/* 2. DISPOSITIVOS MÓVILES (hasta 860px) */
@media (max-width: 860px) {
  * {
    -webkit-tap-highlight-color: transparent;
  }

  .app-container {
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    overflow-x: hidden;
  }

  /* Barra superior compacta */
  .app-header {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 12px 16px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    background: #ffffff;
    z-index: 30;
  }

  .mobile-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    cursor: pointer;
    transition: var(--transition);
  }

  .mobile-logout-btn:active {
    background-color: #fef2f2;
    color: var(--danger);
  }

  .brand {
    margin-bottom: 0;
    gap: 10px;
    padding-left: 0;
  }

  .brand-logo {
    width: 32px;
    height: 32px;
    min-width: 32px;
    max-width: 32px;
    min-height: 32px;
    max-height: 32px;
    flex-shrink: 0;
  }

  .brand-logo img,
  .brand-logo-img {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
  }

  .brand-info h1 {
    font-size: 1.05rem;
  }

  .brand-sub {
    font-size: 0.7rem;
  }

  .header-action {
    display: none;
  }

  /* Barra de navegación inferior fija (Bottom Nav) */
  .main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    align-items: center;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)) 4px;
    z-index: 50;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.05);
  }

  .nav-btn {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 3px;
    padding: 6px 8px;
    font-size: 0.68rem;
    font-weight: 500;
    min-width: 60px;
    text-align: center;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
  }

  .nav-btn svg {
    width: 20px;
    height: 20px;
  }

  .nav-btn.active {
    background-color: var(--primary-light);
    color: var(--primary);
  }

  .badge-dot {
    top: 4px;
    right: 18px;
    width: 7px;
    height: 7px;
  }

  /* Contenedor principal móvil */
  .app-main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 14px 14px calc(80px + env(safe-area-inset-bottom, 0px)) 14px;
    overflow-x: hidden;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 14px;
  }

  .topbar-title h2 {
    font-size: 1.25rem;
  }

  .topbar-title p {
    font-size: 0.8rem;
  }

  .topbar-controls {
    width: 100%;
    justify-content: space-between;
    padding: 6px 12px;
  }

  /* Tarjetas de gráficos móviles */
  .chart-card,
  .top-categories-card,
  .section-card {
    padding: 16px 14px;
    border-radius: var(--radius-md);
    width: 100%;
    min-width: 0;
    overflow: hidden;
  }

  .chart-body,
  .chart-body-tall {
    height: 230px;
    width: 100%;
    min-width: 0;
  }

  /* Formato feed para gastos variables */
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 14px;
  }

  .filter-group {
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    gap: 8px;
  }

  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody {
    display: block;
    width: 100%;
  }

  .data-table tr.expense-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    margin-bottom: 8px;
    box-shadow: var(--shadow-sm);
  }

  .col-date,
  .col-category,
  .col-notes {
    display: none;
  }

  .col-concept {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    padding: 0 !important;
    border: none !important;
  }

  .concept-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-main);
  }

  .mobile-sub {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }

  .mobile-sub .badge-category {
    font-size: 0.68rem;
    padding: 2px 6px;
  }

  .mobile-date-text,
  .mobile-note-text {
    font-size: 0.72rem;
    color: var(--text-muted);
  }

  .col-amount {
    border: none !important;
    padding: 0 8px 0 10px !important;
    font-size: 1rem;
    white-space: nowrap;
  }

  .col-actions {
    border: none !important;
    padding: 0 !important;
    display: flex;
    align-items: center;
    gap: 2px;
  }

  .action-icon-btn {
    padding: 6px;
  }

  /* Modales Bottom Sheet */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }

  .modal-dialog {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 20px 20px 0 0;
    padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0px)) 18px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 -10px 25px rgba(0, 0, 0, 0.15);
    animation: slideUpSheet 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .text-input,
  .select-input {
    font-size: 16px;
    padding: 10px 12px;
  }

  /* Botón Flotante */
  .mobile-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 18px;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background-color: var(--primary);
    color: #ffffff;
    border: none;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
    cursor: pointer;
    z-index: 45;
    transition: transform 0.15s ease, background-color 0.15s ease;
  }

  .mobile-fab:active {
    transform: scale(0.92);
    background-color: var(--primary-hover);
  }

  .toast-container {
    bottom: calc(64px + env(safe-area-inset-bottom, 0px));
    left: 16px;
    right: 16px;
    align-items: center;
  }

  .toast {
    width: 100%;
    text-align: center;
  }
}

/* 3. TELÉFONOS MÓVILES (hasta 600px) - ADAPTACIÓN ESPECÍFICA DE TARJETAS KPI */
@media (max-width: 600px) {
  .kpi-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 16px;
    width: 100%;
  }

  .kpi-card {
    padding: 12px 10px;
    border-radius: var(--radius-md);
  }

  .kpi-card-highlight {
    grid-column: 1 / -1;
    padding: 14px 16px;
  }

  .kpi-header {
    margin-bottom: 4px;
  }

  .kpi-label {
    font-size: 0.68rem;
    white-space: normal;
    line-height: 1.15;
  }

  .kpi-icon {
    width: 24px;
    height: 24px;
    min-width: 24px;
  }

  .kpi-icon svg {
    width: 14px;
    height: 14px;
  }

  .kpi-value {
    font-size: 1.15rem;
    margin-bottom: 2px;
  }

  .kpi-footnote {
    font-size: 0.68rem;
    white-space: normal;
    line-height: 1.15;
  }

  .app-footer {
    margin-top: 30px;
    padding: 16px 8px;
    font-size: 0.74rem;
  }
}

/* 4. TELÉFONOS PEQUEÑOS (hasta 380px) */
@media (max-width: 380px) {
  .kpi-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .kpi-card {
    padding: 12px 14px;
  }

  .kpi-value {
    font-size: 1.25rem;
  }
}
