/* ===================================================================
   FinanzApp - Modern Expense & Budget Tracker Stylesheet
   =================================================================== */

:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: rgba(17, 24, 39, 0.85);
  --bg-card-hover: rgba(31, 41, 55, 0.95);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  --color-income: #10b981;
  --color-income-bg: rgba(16, 185, 129, 0.12);
  --color-expense: #ef4444;
  --color-expense-bg: rgba(239, 68, 68, 0.12);
  --color-balance: #3b82f6;
  --color-balance-bg: rgba(59, 130, 246, 0.12);
  --color-warning: #f59e0b;
  --color-warning-bg: rgba(245, 158, 11, 0.12);

  --accent-primary: #6366f1;
  --accent-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px -2px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 10px 30px -4px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  --transition-fast: 0.18s ease;
  --transition-normal: 0.3s ease;
}

[data-theme="light"] {
  --bg-primary: #f3f4f6;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.9);
  --bg-card-hover: #ffffff;
  --bg-glass: rgba(0, 0, 0, 0.02);
  --border-color: rgba(0, 0, 0, 0.08);

  --text-primary: #111827;
  --text-secondary: #4b5563;
  /* #9ca3af daba 2.5:1 sobre blanco, por debajo del minimo legible. */
  --text-muted: #6b7280;

  /* Los colores de monto estaban pensados para fondo oscuro y sobre blanco
     quedaban ilegibles: el verde de los ingresos daba 2.5:1 y el ambar de las
     alertas 2.1:1. Estos tonos mas oscuros pasan de 4.5:1 manteniendo el
     mismo lenguaje de color. */
  --color-income: #047857;
  --color-expense: #dc2626;
  --color-balance: #2563eb;
  --color-warning: #b45309;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  background-image: 
    radial-gradient(circle at 10% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(217, 70, 239, 0.06) 0%, transparent 45%);
  background-attachment: fixed;
}

/* ===================================================================
   Lock Screen & Profile PIN Login
   =================================================================== */

.lock-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-primary);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.lock-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.lock-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  animation: fadeIn 0.4s ease;
}

.profiles-picker {
  display: flex;
  gap: 1.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.profile-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  border: 2px solid var(--border-color);
  transition: all var(--transition-fast);
  width: 140px;
}

.profile-card:hover, .profile-card.selected {
  border-color: var(--accent-primary);
  transform: translateY(-4px);
  box-shadow: var(--shadow-glow);
}

.profile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-md);
}

.profile-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
}

.pin-keypad-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.25rem;
  width: 100%;
}

.pin-dots {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-bottom: 0.5rem;
}

.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--text-muted);
  transition: all var(--transition-fast);
}

.pin-dot.filled {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.6);
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  width: 240px;
}

.keypad-btn {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.keypad-btn:hover {
  background: var(--bg-glass);
  border-color: var(--accent-primary);
  transform: scale(1.05);
}

.keypad-btn:active {
  transform: scale(0.95);
  background: var(--accent-primary);
  color: #fff;
}

.keypad-btn.action-btn {
  font-size: 1.1rem;
  color: var(--text-muted);
}

/* User Badge in App Header / Sidebar */
.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.user-profile-badge:hover {
  border-color: var(--accent-primary);
  background: var(--bg-card-hover);
}

.user-badge-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: #fff;
  font-weight: 700;
}

.user-badge-name {
  font-size: 0.85rem;
  font-weight: 600;
}

/* Shared Balance Widget */
.shared-balance-card {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.12) 0%, rgba(217, 70, 239, 0.08) 100%);
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.shared-balance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.shared-user-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.settlement-alert {
  background: var(--bg-secondary);
  border-left: 4px solid var(--accent-primary);
  padding: 0.85rem 1.2rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-primary);
}

/* Layout & App Shell */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 50;
  transition: transform var(--transition-normal);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 0.5rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  box-shadow: var(--shadow-glow);
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #fff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .brand-title {
  background: linear-gradient(135deg, #111827 0%, #4f46e5 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--color-balance-bg);
  color: var(--color-balance);
  padding: 2px 6px;
  border-radius: var(--radius-full);
}

/* Nav Menu */
.nav-menu {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex: 1;
}

.nav-item button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.nav-item button:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
  transform: translateX(3px);
}

.nav-item.active button {
  background: var(--accent-gradient);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-glow);
}

.nav-item button i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

/* Cloud Status Widget in Sidebar */
.cloud-status-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.9rem;
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cloud-status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9ca3af;
  display: inline-block;
  box-shadow: 0 0 6px rgba(156, 163, 175, 0.4);
}

.status-dot.online {
  background: var(--color-income);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.7);
  animation: pulse-green 2s infinite;
}

.status-dot.offline {
  background: var(--color-warning);
  box-shadow: 0 0 8px rgba(245, 158, 11, 0.7);
}

@keyframes pulse-green {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.cloud-status-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-cloud-config {
  font-size: 0.75rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg-glass);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.btn-cloud-config:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

/* Main Content Area */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-height: 100vh;
  overflow-y: auto;
}

/* Header */
.top-header {
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: rgba(17, 24, 39, 0.4);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 40;
}

[data-theme="light"] .top-header {
  background: rgba(255, 255, 255, 0.8);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.mobile-nav-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.25rem;
  cursor: pointer;
}

.page-title {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Month Filter Selector */
.month-selector {
  display: flex;
  align-items: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.5rem;
  gap: 0.5rem;
}

.month-selector button {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.month-selector button:hover {
  background: var(--bg-glass);
  color: var(--text-primary);
}

.month-display {
  font-weight: 600;
  font-size: 0.9rem;
  min-width: 130px;
  text-align: center;
  color: var(--text-primary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.65rem 1.2rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-icon-only {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  cursor: pointer;
}

.btn-icon-only:hover {
  color: var(--text-primary);
  border-color: var(--accent-primary);
}

/* Content Container */
.content-body {
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* Tab Views */
.tab-view {
  display: none;
  flex-direction: column;
  gap: 2rem;
  animation: fadeIn 0.25s ease forwards;
}

.tab-view.active {
  display: flex;
}

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

/* Summary Stat Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.25rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.stat-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: var(--shadow-md);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 4px;
}

.stat-card.card-balance::before { background: var(--color-balance); }
.stat-card.card-income::before { background: var(--color-income); }
.stat-card.card-expense::before { background: var(--color-expense); }
.stat-card.card-savings::before { background: var(--accent-primary); }

.stat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.stat-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-icon-wrapper {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.card-balance .stat-icon-wrapper { background: var(--color-balance-bg); color: var(--color-balance); }
.card-income .stat-icon-wrapper { background: var(--color-income-bg); color: var(--color-income); }
.card-expense .stat-icon-wrapper { background: var(--color-expense-bg); color: var(--color-expense); }
.card-savings .stat-icon-wrapper { background: rgba(99, 102, 241, 0.15); color: var(--accent-primary); }

.stat-value {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin-bottom: 0.35rem;
}

.stat-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

/* Dashboard Charts Grid */
.dashboard-charts-grid {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 1.5rem;
}

@media (max-width: 1024px) {
  .dashboard-charts-grid {
    grid-template-columns: 1fr;
  }
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: var(--shadow-sm);
}

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

.chart-title {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-title i {
  color: var(--accent-primary);
}

.chart-container {
  position: relative;
  width: 100%;
  min-height: 280px;
  max-height: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Budget Progress Section */
.budget-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.budget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.25rem;
}

.budget-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: all var(--transition-fast);
}

.budget-card:hover {
  border-color: rgba(255, 255, 255, 0.15);
}

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

.budget-category-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.category-badge-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: #fff;
}

.budget-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.budget-status-pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-full);
}

.pill-ok {
  background: var(--color-income-bg);
  color: var(--color-income);
}

.pill-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.pill-danger {
  background: var(--color-expense-bg);
  color: var(--color-expense);
  animation: pulse-danger 1.5s infinite;
}

@keyframes pulse-danger {
  0% { opacity: 0.8; }
  50% { opacity: 1; }
  100% { opacity: 0.8; }
}

.budget-values {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.budget-values strong {
  color: var(--text-primary);
  font-size: 1.05rem;
}

.progress-bar-bg {
  width: 100%;
  height: 10px;
  background: var(--bg-glass);
  border-radius: var(--radius-full);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-fill-ok { background: var(--color-income); }
.progress-fill-warning { background: var(--color-warning); }
.progress-fill-danger { background: var(--color-expense); }

/* Transactions Table & List */
.transactions-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.filters-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.search-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-input-wrapper i {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 1rem 0.65rem 2.6rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition-fast);
}

.search-input:focus {
  border-color: var(--border-focus);
}

.filters-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.select-filter {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.88rem;
  outline: none;
  cursor: pointer;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.tx-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.tx-table th {
  padding: 0.85rem 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
}

.tx-table td {
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.92rem;
  vertical-align: middle;
}

.tx-table tbody tr {
  transition: background var(--transition-fast);
}

.tx-table tbody tr:hover {
  background: var(--bg-glass);
}

.tx-info {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.tx-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  flex-shrink: 0;
}

.tx-desc-title {
  font-weight: 600;
  color: var(--text-primary);
}

.tx-desc-category {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.tx-amount {
  font-weight: 700;
  font-size: 1rem;
  white-space: nowrap;
}

.tx-amount.income {
  color: var(--color-income);
}

.tx-amount.expense {
  color: var(--color-expense);
}

.tx-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--bg-glass);
  color: var(--text-secondary);
}

.payer-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 2px 7px;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  color: #fff;
}

.tx-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-action {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.btn-action:hover {
  color: var(--text-primary);
  background: var(--bg-glass);
}

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

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
  color: var(--text-muted);
  gap: 0.85rem;
}

.empty-state i {
  font-size: 3rem;
  color: var(--text-secondary);
  opacity: 0.5;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
}

.modal-footer {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Form Styles */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

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

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-control {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-fast);
  width: 100%;
}

.form-control:focus {
  border-color: var(--border-focus);
}

/* Type Toggle Buttons */
.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-primary);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  gap: 4px;
}

.type-btn {
  background: transparent;
  border: none;
  padding: 0.6rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.type-btn.active.expense {
  background: var(--color-expense);
  color: #fff;
}

.type-btn.active.income {
  background: var(--color-income);
  color: #fff;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  z-index: 2000;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  animation: slideToast 0.3s ease;
  min-width: 260px;
}

.toast-success i { color: var(--color-income); }
.toast-error i { color: var(--color-expense); }
.toast-info i { color: var(--color-balance); }

@keyframes slideToast {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive Overrides */
@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }

  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .mobile-nav-toggle {
    display: block;
  }

  .content-body {
    padding: 1rem;
  }

  .top-header {
    padding: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .shared-balance-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 540px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  
  .header-actions {
    width: 100%;
    justify-content: space-between;
  }
}

/* ==========================================
   PANTALLA DE ACCESO (Firebase Auth)
   ========================================== */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  text-align: left;
}

.btn-block {
  width: 100%;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 0.25rem;
}

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

.auth-message {
  font-size: 0.85rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* El atributo hidden debe ganarle al display:flex de arriba. */
.auth-message[hidden] {
  display: none;
}

.auth-message.success {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* ==========================================
   COMPONENTES v3: liquidación, tags, acciones
   ========================================== */

/* Botón compacto */
.btn-sm {
  font-size: 0.8rem;
  padding: 0.45rem 0.85rem;
}

/* Aviso de presupuesto heredado del mes anterior */
.inherited-note {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.3);
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Fila de botones al pie de una tarjeta */
.card-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  align-items: center;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
}

/* Etiquetas "Cuota 3/12" y "Recurrente" en la tabla */
.tx-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.35rem;
  white-space: nowrap;
}

.tx-tag.installment {
  background: rgba(139, 92, 246, 0.18);
  color: #c4b5fd;
}

.tx-tag.recurring {
  background: rgba(20, 184, 166, 0.18);
  color: #5eead4;
}

[data-theme="light"] .tx-tag.installment { color: #6d28d9; }
[data-theme="light"] .tx-tag.recurring { color: #0f766e; }

/* Recurrente pausado */
.budget-card.is-paused {
  opacity: 0.6;
}

/* Panel de cuenta en Ajustes */
.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

/* Contenedor de cada perfil editable en Ajustes */
.cloud-guide-step {
  display: flex;
  flex-direction: column;
  padding: 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

@media (max-width: 768px) {
  #userProfilesEditor {
    grid-template-columns: 1fr !important;
  }
}

/* ==========================================================================
   MÓVIL
   --------------------------------------------------------------------------
   Tres decisiones que guían todo lo de abajo:

   1. En un teléfono, la tabla de transacciones se convierte en tarjetas. Con
      seis columnas necesitaba 807px dentro de un contenedor de 293px, así que
      el monto — el dato que uno va a buscar — quedaba fuera de pantalla.
   2. Los controles del encabezado se reparten en dos filas y el botón de
      "nuevo movimiento" pasa a ser flotante, al alcance del pulgar.
   3. Aparece una barra inferior con las cuatro pestañas de uso diario, para
      no tener que abrir el menú lateral cada vez.
   ========================================================================== */

/* Alto de la barra inferior, para que el contenido no quede debajo. */
:root {
  --bottom-nav-height: 4rem;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* Elementos que sólo existen en móvil. */
.bottom-nav,
.fab,
.sidebar-backdrop {
  display: none;
}

body.no-scroll {
  overflow: hidden;
}

/* iOS hace zoom al enfocar cualquier campo con fuente menor a 16px, y deja la
   pantalla corrida. 16px es el mínimo que lo evita. */
@media (max-width: 860px) {
  .form-control,
  .search-input,
  .select-filter {
    font-size: 16px;
  }
}

/* El cuerpo del modal debe poder desplazarse: con el teclado abierto el alto
   disponible se reduce a la mitad y el botón de guardar queda inalcanzable. */
.modal-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 860px) {

  /* ---------- Zona segura (notch e indicador de inicio) ----------
     La app declara apple-mobile-web-app-status-bar-style: black-translucent,
     así que instalada como PWA el contenido pasa por debajo del reloj. */
  .top-header {
    padding-top: calc(0.75rem + var(--safe-top));
  }

  .sidebar {
    padding-top: calc(1.25rem + var(--safe-top));
  }

  /* ---------- Encabezado en dos filas ---------- */
  .top-header {
    flex-wrap: wrap;
    gap: 0.6rem;
    padding-left: 0.85rem;
    padding-right: 0.85rem;
    padding-bottom: 0.6rem;
  }

  .header-left {
    flex: 1 1 auto;
    min-width: 0;
    gap: 0.5rem;
  }

  .page-title {
    font-size: 1.05rem;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .header-actions {
    flex: 0 0 auto;
    width: auto;
    gap: 0.4rem;
  }

  /* El selector de mes ocupa su propia fila completa: es el control que más
     se usa y así queda cómodo para el pulgar. */
  .month-selector {
    order: 10;
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .month-selector button {
    min-width: 44px;
    min-height: 44px;
  }

  /* El botón grande de "Nuevo Movimiento" se reemplaza por el flotante. */
  .btn-new-tx {
    display: none;
  }

  /* Insignia de usuario compacta: sólo el avatar. */
  .user-badge-name,
  .user-profile-badge i {
    display: none;
  }

  .user-profile-badge {
    padding: 0.3rem;
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
  }

  /* ---------- Zonas de toque ---------- */
  .mobile-nav-toggle {
    min-width: 44px;
    min-height: 44px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
  }

  .btn-icon-only {
    min-width: 44px;
    min-height: 44px;
  }

  .btn-action {
    min-width: 40px;
    min-height: 40px;
  }

  .btn {
    min-height: 44px;
  }

  /* ---------- Barra lateral con fondo ---------- */
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
  }

  .sidebar-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    z-index: 999;
  }

  /* ---------- Contenido ---------- */
  .content-body {
    padding: 0.85rem;
    /* Espacio para que la barra inferior y el botón flotante no tapen nada. */
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 1.5rem);
  }

  /* Dos tarjetas de resumen por fila: cuatro apiladas obligaban a recorrer
     media pantalla por dato. */
  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem;
  }

  .stat-card {
    padding: 0.9rem;
  }

  .stat-value {
    font-size: 1.3rem;
  }

  .stat-label {
    font-size: 0.68rem;
  }

  .chart-card,
  .budget-section,
  .transactions-container {
    padding: 1rem;
  }

  .chart-title {
    font-size: 1rem;
  }

  /* Encabezados de sección: el botón baja en vez de apretarse al costado. */
  .chart-header {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  .chart-header > .btn {
    width: 100%;
  }

  /* ---------- Filtros ---------- */
  .filters-bar {
    gap: 0.6rem;
  }

  .filters-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    width: 100%;
  }

  .select-filter {
    width: 100%;
    min-height: 44px;
  }

  /* La categoría y el botón de exportar ocupan la fila completa. */
  #txCategoryFilter,
  .filters-group .btn {
    grid-column: 1 / -1;
  }

  /* ---------- La tabla se vuelve una lista de tarjetas ---------- */
  .table-responsive {
    overflow: visible;
  }

  .tx-table thead {
    display: none;
  }

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

  .tx-table tbody tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.45rem 0.6rem;
    padding: 0.85rem 0.9rem;
    margin-bottom: 0.7rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
  }

  .tx-table tbody tr:hover {
    background: var(--bg-secondary);
  }

  .tx-table td {
    display: block;
    border: none;
    padding: 0;
  }

  /* Orden dentro de la tarjeta:
     fila 1  concepto y categoría
     fila 2  monto (destacado) ......... acciones
     fila 3  fecha · quién pagó · método */
  .cell-concepto {
    order: 1;
    flex: 1 1 100%;
  }

  .cell-monto {
    order: 2;
    flex: 0 0 auto;
    margin-right: auto;
    font-size: 1.15rem;
  }

  .cell-acciones {
    order: 3;
    flex: 0 0 auto;
  }

  /* Salto de línea forzado. flex-grow no sirve para esto: el navegador ya
     acomodó la fecha en la línea del monto antes de repartir el espacio
     sobrante. Un pseudo-elemento de ancho completo sí empuja lo que sigue a
     una fila nueva, y así todas las tarjetas quedan alineadas igual sin
     importar el largo del monto. */
  .tx-table tbody tr::after {
    content: '';
    order: 4;
    flex: 1 1 100%;
    height: 0;
    margin: 0;
  }

  .cell-fecha   { order: 5; }
  .cell-pagador { order: 6; }
  .cell-metodo  { order: 7; }

  .cell-fecha,
  .cell-pagador,
  .cell-metodo {
    flex: 0 0 auto;
  }

  .tx-desc-title {
    white-space: normal;
  }

  /* ---------- Barra inferior ---------- */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 900;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    padding-bottom: var(--safe-bottom);
    /* Sin backdrop-filter: en Safari sobre elementos fijos parpadea al hacer scroll. */
  }

  .bottom-nav-item {
    flex: 1 1 0;
    min-width: 0;
    min-height: var(--bottom-nav-height);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.4rem 0.15rem;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.62rem;
    font-weight: 600;
    transition: color var(--transition-fast);
  }

  .bottom-nav-item i {
    font-size: 1.15rem;
  }

  .bottom-nav-item span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .bottom-nav-item.active {
    color: var(--accent-primary);
  }

  /* ---------- Botón flotante ---------- */
  .fab {
    display: flex;
    position: fixed;
    right: 1rem;
    bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 1rem);
    z-index: 901;
    width: 56px;
    height: 56px;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 50%;
    background: var(--accent-gradient);
    color: #fff;
    font-size: 1.4rem;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.5);
  }

  .fab:active {
    transform: scale(0.94);
  }

  /* ---------- Modales a pantalla casi completa ---------- */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card {
    width: 100%;
    max-width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .modal-body {
    max-height: none;
  }

  .modal-footer {
    padding-bottom: calc(1rem + var(--safe-bottom));
    flex-direction: column-reverse;
    gap: 0.5rem;
  }

  .modal-footer .btn {
    width: 100%;
  }

  /* La pantalla de acceso también respeta la zona segura. */
  .lock-screen {
    padding: calc(1.5rem + var(--safe-top)) 1.5rem calc(1.5rem + var(--safe-bottom));
  }
}

/* Pantallas angostas de verdad (iPhone SE y similares). */
@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .bottom-nav-item {
    font-size: 0.56rem;
  }

  .bottom-nav-item span {
    letter-spacing: -0.02em;
  }
}

/* Quita el destello gris al tocar y evita el rebote de selección accidental
   en elementos que sólo se pulsan. */
button, .nav-item, .profile-card, .btn-action, .bottom-nav-item, .fab {
  -webkit-tap-highlight-color: transparent;
}

/* En pantallas táctiles los efectos :hover se quedan "pegados" tras tocar. */
@media (hover: none) {
  .btn-primary:hover,
  .btn-secondary:hover,
  .stat-card:hover,
  .budget-card:hover {
    transform: none;
  }
}

/* ==========================================================================
   AJUSTES TRAS PROBAR EN PANTALLA DE 375px
   ========================================================================== */

@media (max-width: 860px) {
  /* El encabezado quedaba en tres filas: el avatar y el tema caían solos en
     una fila intermedia. Con display:contents los hijos de .header-actions
     pasan a ser elementos directos del encabezado, así el avatar y el tema
     suben junto al título y sólo el selector de mes baja a su propia fila. */
  .header-actions {
    display: contents;
  }

  .user-profile-badge {
    order: 1;
  }

  .btn-icon-only {
    order: 2;
  }

  /* El botón flotante tapaba la última tarjeta: hay que dejar espacio para la
     barra inferior más el alto del botón. */
  .content-body {
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + 5.5rem);
  }
}

/* Dos tarjetas de resumen por fila hasta 360px; más angosto que eso, una. */
@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
}

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

/* Botón de filtros: sólo existe en móvil. */
.filters-toggle {
  display: none;
}

@media (max-width: 860px) {
  /* El título largo debe recortarse en vez de empujar los iconos a otra fila.
     flex-basis 0 es lo que permite que el bloque se encoja bajo su contenido. */
  .header-left {
    flex: 1 1 0;
    min-width: 0;
  }

  .page-title {
    min-width: 0;
    flex: 1 1 auto;
  }

  /* Filtros plegados: la búsqueda queda siempre a mano y el resto se abre a
     pedido. Antes se gastaban 400px de alto antes del primer movimiento. */
  .filters-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
    min-height: 44px;
    padding: 0.6rem 0.9rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
  }

  .filters-chevron {
    transition: transform var(--transition-fast);
    font-size: 0.75rem;
  }

  .filters-bar.filters-open .filters-chevron {
    transform: rotate(180deg);
  }

  .filters-bar .filters-group {
    display: none;
  }

  .filters-bar.filters-open .filters-group {
    display: grid;
  }
}

@media (max-width: 860px) {
  /* El modal se comporta como una hoja nativa: encabezado y pie fijos, y sólo
     el formulario se desplaza. Antes scrolleaba la tarjeta completa, así que
     en un teléfono chico había que recorrer todo el formulario para llegar al
     botón de guardar.
     El <form> envuelve al cuerpo y al pie, así que también tiene que ser
     columna flexible para que el reparto de alto llegue hasta el fondo. */
  .modal-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .modal-card > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
  }

  .modal-header,
  .modal-footer {
    flex: 0 0 auto;
  }

  /* min-height: 0 es lo que permite que un hijo flexible se encoja por debajo
     de su contenido y muestre su propia barra de desplazamiento. */
  .modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
  }
}

/* ==========================================================================
   v3.2 — Alertas, comparación, búsqueda global y registro rápido
   ========================================================================== */

/* ---------- Avisos de presupuesto en el dashboard ---------- */
.budget-alerts {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

.budget-alert {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
}

.budget-alert i {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.budget-alert-text {
  flex: 1 1 auto;
  min-width: 0;
}

.budget-alert.is-near {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}

.budget-alert.is-over {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

[data-theme="light"] .budget-alert.is-near { color: #92400e; }
[data-theme="light"] .budget-alert.is-over { color: #991b1b; }

/* ---------- Variaciones contra el mes anterior ---------- */
.delta-good,
.delta-bad,
.delta-neutral {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-weight: 600;
}

.delta-good { color: var(--accent-success, #10b981); }
.delta-bad { color: var(--accent-danger, #ef4444); }
.delta-neutral { color: var(--text-muted); font-weight: 500; }

/* ---------- Aviso de búsqueda global ---------- */
.search-scope-note {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-size: 0.82rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.search-scope-note[hidden] {
  display: none;
}

/* ---------- Comparación por categoría ---------- */
.comparison-list {
  display: flex;
  flex-direction: column;
}

.comparison-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1rem;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border-color);
}

.comparison-row:last-child {
  border-bottom: none;
}

.comparison-cat {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

.comparison-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.comparison-avg {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.comparison-numbers {
  text-align: right;
}

.comparison-now {
  font-weight: 700;
  font-size: 0.95rem;
}

.comparison-prev {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.comparison-delta {
  min-width: 5.5rem;
  text-align: right;
  font-size: 0.82rem;
}

/* ---------- Atajos de categoría en el modal ---------- */
.quick-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.quick-categories[hidden] {
  display: none;
}

.quick-cat {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem;
  border-radius: 999px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.quick-cat:hover,
.quick-cat.active {
  border-color: var(--accent-primary);
  color: var(--text-primary);
}

@media (max-width: 860px) {
  /* La comparación se apila: tres columnas no caben en un teléfono. */
  .comparison-row {
    grid-template-columns: 1fr auto;
    gap: 0.5rem 0.75rem;
  }

  .comparison-cat {
    grid-column: 1 / -1;
  }

  .comparison-numbers {
    text-align: left;
  }

  .comparison-delta {
    text-align: right;
  }

  .btn-repeat {
    width: 100%;
  }

  .quick-cat {
    min-height: 40px;
  }
}

/* ---------- Editor de categorías ---------- */
.cat-group {
  margin-top: 1.25rem;
}

.cat-group-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.6rem;
}

.cat-group-title span {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}

.cat-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.5rem;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.cat-name {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cat-actions {
  display: flex;
  gap: 0.3rem;
  flex-shrink: 0;
}

/* Vista previa dentro del modal de categoría */
.cat-preview {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.9rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-weight: 700;
}

@media (max-width: 860px) {
  .cat-list {
    grid-template-columns: 1fr;
  }
}

/* Alertas compactas: la fila entera es el botón, en una sola línea. */
.budget-alert {
  width: 100%;
  text-align: left;
  font-family: inherit;
  cursor: pointer;
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
}

/* Puede usar dos líneas: forzarlo a una sola cortaba el monto disponible,
   que es justamente lo que uno quiere saber del aviso. */
.budget-alert-text {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.3;
}

.budget-alert-chevron {
  font-size: 0.7rem !important;
  opacity: 0.6;
}

.budget-alert.is-more {
  justify-content: center;
  background: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

@media (max-width: 860px) {
  .budget-alerts {
    gap: 0.4rem;
    margin-bottom: 1rem;
  }

  .budget-alert {
    font-size: 0.8rem;
    padding: 0.55rem 0.7rem;
    min-height: 44px;
  }
}

/* Nota bajo un perfil que no se puede editar desde esta sesion. */
.profile-note {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.76rem;
  line-height: 1.35;
  color: var(--text-muted);
  padding-top: 0.15rem;
}

.profile-note i {
  margin-top: 0.15rem;
  flex-shrink: 0;
}

/* ==========================================================================
   v4 — Cuentas por pagar y el numero del mes
   ========================================================================== */

/* La tarjeta grande con lo que queda: es el numero que resume el mes. */
.queda-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.queda-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.queda-monto {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.15;
}

.queda-monto.positivo { color: var(--color-income); }
.queda-monto.negativo { color: var(--color-expense); }

.queda-nota {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- Lista de cuentas del mes ---------- */
.bills-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.bill-card {
  padding: 0.9rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  /* La franja izquierda dice el estado de un vistazo. */
  border-left: 3px solid var(--text-muted);
}

.bill-card.estado-pendiente { border-left-color: var(--color-warning); }
.bill-card.estado-vencida   { border-left-color: var(--color-expense); }
.bill-card.estado-pagada    { border-left-color: var(--color-income); }

.bill-card.estado-pagada .bill-name {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
  color: var(--text-secondary);
}

.bill-main {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.bill-text {
  flex: 1 1 auto;
  min-width: 0;
}

.bill-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.bill-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.bill-amount {
  font-weight: 800;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.bill-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.7rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--border-color);
}

.bill-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

/* Etiquetas de estado en la tabla de movimientos */
.tx-tag.pendiente {
  background: rgba(245, 158, 11, 0.18);
  color: #fcd34d;
}

.tx-tag.vencida {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
}

[data-theme="light"] .tx-tag.pendiente { color: #92400e; }
[data-theme="light"] .tx-tag.vencida { color: #991b1b; }

@media (max-width: 860px) {
  .queda-card {
    padding: 1rem;
  }

  .queda-monto {
    font-size: 1.75rem;
  }

  .queda-card > .btn {
    width: 100%;
  }

  /* El monto baja bajo el nombre: en 375px no caben en la misma linea. */
  .bill-main {
    flex-wrap: wrap;
  }

  .bill-amount {
    width: 100%;
    text-align: left;
    padding-left: calc(38px + 0.75rem);
  }

  .bill-footer .btn {
    flex: 1 1 auto;
  }
}

/* Gasto estimado del mes: no tiene vencimiento, se consume de a poco. */
.bill-card.estado-estimado {
  border-left-color: var(--accent-primary);
}
