/* ═══════════════════════════════════════════════════════════
   MisGastos – Premium Dark-Mode Stylesheet
   ═══════════════════════════════════════════════════════════ */

/* ── CSS Reset ─────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  touch-action: manipulation;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

/* ── Custom Properties ─────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-primary: #0a0a1a;
  --bg-secondary: #0f0f2e;
  --bg-input: #141430;

  /* Surfaces (glassmorphism) */
  --surface: rgba(255, 255, 255, 0.05);
  --surface-hover: rgba(255, 255, 255, 0.08);
  --surface-active: rgba(255, 255, 255, 0.10);
  --surface-border: rgba(255, 255, 255, 0.10);
  --surface-border-hover: rgba(255, 255, 255, 0.18);

  /* Text */
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  /* Accent */
  --accent-purple: #8b5cf6;
  --accent-purple-light: #a78bfa;
  --accent-purple-dim: rgba(139, 92, 246, 0.15);
  --accent-purple-glow: rgba(139, 92, 246, 0.4);
  --accent-green: #10b981;
  --accent-green-dim: rgba(16, 185, 129, 0.15);
  --accent-red: #ef4444;
  --accent-red-dim: rgba(239, 68, 68, 0.15);
  --accent-amber: #f59e0b;
  --accent-amber-dim: rgba(245, 158, 11, 0.15);
  --accent-blue: #3b82f6;

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

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-pill: 100px;

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow-purple: 0 0 20px rgba(139, 92, 246, 0.3);

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
  --transition-smooth: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --max-width: 600px;
  --header-height: 64px;
  --tab-height: 72px;

  /* Safe area */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Body & Global ─────────────────────────────────────── */
body {
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

::selection {
  background: var(--accent-purple);
  color: white;
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(139, 92, 246, 0.3);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(139, 92, 246, 0.5);
}

/* ── APP HEADER ────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(10, 10, 26, 0.8);
  backdrop-filter: blur(20px) saturate(1.8);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  border-bottom: 1px solid var(--surface-border);
  padding: 0 var(--space-md);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-height) + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: center;
}

.month-nav {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.month-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-base);
  border: 1px solid transparent;
}

.month-arrow:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--surface-border);
  transform: scale(1.05);
}

.month-arrow:active {
  transform: scale(0.95);
}

.month-label {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  min-width: 180px;
  text-align: center;
  user-select: none;
}

/* ── APP CONTENT ───────────────────────────────────────── */
.app-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: var(--space-md) var(--space-md) calc(var(--tab-height) + var(--safe-bottom) + var(--space-xl));
  min-height: calc(100vh - var(--header-height));
  min-height: calc(100dvh - var(--header-height));
}

/* ── Views ─────────────────────────────────────────────── */
.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

.view-header {
  margin-bottom: var(--space-lg);
}

.view-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ── TAB BAR ───────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(10, 10, 26, 0.85);
  backdrop-filter: blur(24px) saturate(1.8);
  -webkit-backdrop-filter: blur(24px) saturate(1.8);
  border-top: 1px solid var(--surface-border);
}

.tab-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 0;
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn svg {
  transition: all var(--transition-base);
}

.tab-btn span {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.tab-btn.active {
  color: var(--accent-purple-light);
}

.tab-btn.active svg {
  filter: drop-shadow(0 0 8px var(--accent-purple-glow));
}

.tab-btn.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 3px;
  background: var(--accent-purple);
  border-radius: 0 0 4px 4px;
}

.tab-btn:not(.active):hover {
  color: var(--text-secondary);
}

/* ── CARDS / SURFACES (Glassmorphism) ──────────────────── */
.glass-card {
  background: var(--surface);
  backdrop-filter: blur(12px) saturate(1.4);
  -webkit-backdrop-filter: blur(12px) saturate(1.4);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--transition-smooth);
}

.glass-card:hover {
  background: var(--surface-hover);
  border-color: var(--surface-border-hover);
}

/* ── SUMMARY CARDS (Dashboard) ─────────────────────────── */
.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.summary-card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.summary-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.summary-card.ars::before {
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-blue));
}

.summary-card.usd::before {
  background: linear-gradient(90deg, var(--accent-amber), #f97316);
}

.summary-card-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.summary-card-amount {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.summary-card.ars .summary-card-amount {
  color: var(--text-primary);
}

.summary-card.usd .summary-card-amount {
  color: var(--accent-amber);
}

.summary-card-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── DONUT CHART SECTION ───────────────────────────────── */
.chart-section {
  margin-bottom: var(--space-lg);
}

.chart-container {
  display: flex;
  justify-content: center;
  padding: var(--space-lg) 0;
}

.chart-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-xs) var(--space-sm);
  padding: 0 var(--space-sm) var(--space-sm);
  max-height: 130px;
  overflow-y: auto;
  align-content: start;
}

/* Custom scrollbar for the legend */
.chart-legend::-webkit-scrollbar {
  width: 4px;
}
.chart-legend::-webkit-scrollbar-track {
  background: transparent;
}
.chart-legend::-webkit-scrollbar-thumb {
  background: var(--surface-border-hover);
  border-radius: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 0.8rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-label {
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.legend-value {
  color: var(--text-primary);
  font-weight: 600;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* ── SECTION HEADERS ───────────────────────────────────── */
.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.section-title-icon {
  width: 20px;
  height: 20px;
  color: var(--accent-purple-light);
}

/* ── EXPENSE LIST ──────────────────────────────────────── */
.expense-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.expense-group-header {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: var(--space-md) 0 var(--space-xs);
}

.expense-item {
  display: flex;
  align-items: center;
  gap: 10px; /* Reduced gap to keep text closer to the emoji on mobile */
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 12px;
  transition: all var(--transition-base);
  position: relative;
}

.expense-item:hover {
  background: var(--surface-hover);
  border-color: var(--surface-border-hover);
}

.expense-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
  flex-shrink: 0;
  background: var(--surface);
}

.expense-info {
  flex: 1;
  min-width: 0;
}

.expense-description {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.expense-meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-top: 2px;
}

.expense-category-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

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

.expense-amount {
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
  text-align: right;
}

.expense-amount.ars {
  color: var(--text-primary);
}

.expense-amount.income {
  color: var(--accent-green);
}

.expense-amount.usd {
  color: var(--accent-amber);
}

.expense-actions {
  display: flex;
  gap: var(--space-xs);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.expense-item:hover .expense-actions {
  opacity: 1;
}

.expense-action-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.expense-action-btn:hover {
  color: var(--text-primary);
  background: var(--surface-active);
}

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

/* ── BADGES ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.6rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge-fixed {
  background: var(--accent-purple-dim);
  color: var(--accent-purple-light);
}

.badge-installment {
  background: var(--accent-amber-dim);
  color: var(--accent-amber);
}

.badge-one-time {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
}

/* ── PROGRESS BAR ──────────────────────────────────────── */
.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-top: var(--space-sm);
}

.progress-bar-fill {
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-purple), var(--accent-purple-light));
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.progress-bar-fill.amber {
  background: linear-gradient(90deg, var(--accent-amber), #fbbf24);
}

/* ── FORM STYLES ───────────────────────────────────────── */
.expense-form {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  padding: var(--space-lg);
}

.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.form-row {
  display: flex;
  gap: var(--space-md);
}

.flex-1 {
  flex: 1;
}

.currency-group {
  width: 110px;
  flex-shrink: 0;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="month"],
select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition-base);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

input::placeholder {
  color: var(--text-muted);
}

input:focus,
select:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px var(--accent-purple-dim), var(--shadow-sm);
}

input:hover:not(:focus),
select:hover:not(:focus) {
  border-color: var(--surface-border-hover);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* Color scheme for date/month inputs */
input[type="date"],
input[type="month"] {
  color-scheme: dark;
}

.emoji-input {
  font-size: 1.5rem;
  text-align: center;
  width: 80px !important;
}

/* ── Type Selector ─────────────────────────────────────── */
.type-selector {
  display: flex;
  background: var(--bg-input);
  border-radius: var(--radius-pill);
  padding: 4px;
  margin-bottom: var(--space-lg);
  border: 1px solid var(--surface-border);
}

.type-btn {
  flex: 1;
  padding: 10px 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-base);
}

.type-btn.active {
  background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
  color: white;
  box-shadow: 0 2px 12px rgba(139, 92, 246, 0.4);
}

.type-btn:not(.active):hover {
  color: var(--text-secondary);
  background: var(--surface);
}

/* ── AUTOCOMPLETE / SUGGESTIONS DROPDOWN ───────────────── */
.suggestions-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: rgba(18, 18, 42, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border-hover);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6), 0 4px 10px rgba(0, 0, 0, 0.4);
  max-height: 240px;
  overflow-y: auto;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.suggestions-dropdown.hidden {
  display: none !important;
}

.suggestion-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: all var(--transition-fast);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: var(--surface-hover);
}

.suggestion-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-sm);
}

.suggestion-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.suggestion-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.suggestion-badge {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.68rem;
}

/* ── Installment Preview ──────────────────────────────── */
.installment-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--accent-purple-dim);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
}

.installment-preview-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.installment-preview-amount {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent-purple-light);
  transition: all 0.2s ease;
}

.installment-preview-amount.highlight {
  transform: scale(1.1);
  color: white;
}

/* ── Primary Button ────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 14px 24px;
  border: none;
  background: linear-gradient(135deg, var(--accent-purple), #7c3aed);
  color: white;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-smooth);
  position: relative;
  overflow: hidden;
  margin-top: var(--space-sm);
}

.btn-primary::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 200%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
  transition: left 0.5s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow-purple), var(--shadow-md);
}

.btn-primary:hover::before {
  left: 100%;
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
  box-shadow: var(--shadow-sm);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ── Outline Button ────────────────────────────────────── */
.btn-outline {
  padding: 6px 12px;
  border: 1px solid var(--accent-purple);
  background: transparent;
  color: var(--accent-purple-light);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-base);
}

.btn-outline:hover {
  background: rgba(139, 92, 246, 0.15);
}

.btn-outline:active {
  transform: scale(0.98);
}

/* ── MODAL ─────────────────────────────────────────────── */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal.hidden {
  display: none;
}

.modal.visible {
  display: flex;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: var(--max-width);
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--bg-primary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: var(--space-lg);
  padding-bottom: calc(var(--space-lg) + var(--safe-bottom));
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-lg);
}

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

.modal-close {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.modal-form {
  background: transparent;
  border: none;
  padding: 0;
  backdrop-filter: none;
}

/* ── TOAST ─────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + var(--space-md));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
  width: calc(100% - var(--space-xl));
  max-width: var(--max-width);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: rgba(20, 20, 48, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  color: var(--text-primary);
  font-size: 0.85rem;
  font-weight: 500;
  animation: slideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1),
             fadeOut 0.3s ease 2.7s forwards;
  pointer-events: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  overflow: hidden;
}

.toast::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
}

.toast-success::before, .toast.success::before { background: var(--accent-green); }
.toast-error::before, .toast.error::before     { background: var(--accent-red); }
.toast-info::before, .toast.info::before       { background: var(--accent-purple); }

.toast-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.toast-message {
  flex: 1;
}

.toast-visible {
  opacity: 1;
  transform: translateY(0);
}

.toast-exit {
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
}

/* ── EMPTY STATE ───────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl) var(--space-lg);
  text-align: center;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.6;
}

.empty-state-emoji {
  font-size: 3rem;
  margin-bottom: var(--space-md);
  opacity: 0.6;
}

.empty-state p {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.empty-state-hint {
  font-size: 0.8rem !important;
  font-weight: 400 !important;
  color: var(--text-muted) !important;
}

.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

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

/* ── FIXED TOTALS ─────────────────────────────────────── */
.fixed-totals {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}

.fixed-total-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
}

.fixed-total-badge.ars {
  background: var(--accent-purple-dim);
  color: var(--accent-purple-light);
}

.fixed-total-badge.usd {
  background: var(--accent-amber-dim);
  color: var(--accent-amber);
}

/* ── INSTALLMENT CARD ─────────────────────────────────── */
.installment-card {
  flex-wrap: wrap;
}

.expense-amount-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

/* ── FIXED EXPENSES VIEW ──────────────────────────────── */
.fixed-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.fixed-summary-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  text-align: center;
}

.fixed-summary-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.fixed-summary-amount {
  font-size: 1.15rem;
  font-weight: 700;
}

.fixed-section {
  margin-bottom: var(--space-lg);
}

.fixed-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  transition: all var(--transition-base);
}

.fixed-item:hover {
  background: var(--surface-hover);
  border-color: var(--surface-border-hover);
}

.fixed-item-info {
  flex: 1;
  min-width: 0;
}

.fixed-item-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

.fixed-item-detail {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.fixed-item-amount {
  font-weight: 700;
  font-size: 0.95rem;
  text-align: right;
}

.installment-progress {
  margin-top: var(--space-xs);
}

.installment-label {
  font-size: 0.7rem;
  color: var(--accent-amber);
  font-weight: 600;
}

/* ── LOADING SPINNER ───────────────────────────────────── */
.loading-container {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-2xl);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--surface-border);
  border-top-color: var(--accent-purple);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── ANIMATIONS ────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

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

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── UTILITY CLASSES ───────────────────────────────────── */
.hidden {
  display: none !important;
}

.text-green  { color: var(--accent-green); }
.text-red    { color: var(--accent-red); }
.text-amber  { color: var(--accent-amber); }
.text-purple { color: var(--accent-purple-light); }
.text-muted  { color: var(--text-muted); }

/* ── RESPONSIVE – Tablet / Desktop ─────────────────────── */
@media (min-width: 768px) {
  :root {
    --max-width: 720px;
    --tab-height: 64px;
  }

  .app-content {
    padding: var(--space-lg) var(--space-xl) calc(var(--tab-height) + var(--safe-bottom) + var(--space-2xl));
  }

  .month-label {
    font-size: 1.4rem;
  }

  .summary-card-amount {
    font-size: 1.6rem;
  }

  .expense-actions {
    opacity: 0;
  }

  .modal-card {
    border-radius: var(--radius-xl);
    margin-bottom: var(--space-xl);
    max-width: 480px;
  }

  .chart-legend {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

@media (min-width: 1024px) {
  :root {
    --max-width: 800px;
  }

  .summary-grid {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-lg);
  }
}

/* ── SEARCH BAR ────────────────────────────────────────── */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-sm);
  transition: border-color var(--transition-base);
}

.search-bar:focus-within {
  border-color: var(--accent-purple);
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

.search-bar input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  min-width: 0;
}

.search-bar input::placeholder {
  color: var(--text-muted);
}

.filter-toggle-btn {
  background: none;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-base);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-toggle-btn:hover,
.filter-toggle-btn.active {
  color: var(--accent-purple-light);
  border-color: var(--accent-purple);
  background: rgba(192, 132, 252, 0.08);
}

/* ── FILTER PANEL ──────────────────────────────────────── */
.filter-panel {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.filter-row {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.filter-group {
  flex: 1;
  min-width: 0;
}

.filter-group label {
  display: block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.filter-group select,
.filter-group input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 0.8rem;
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition-base);
  color-scheme: dark;
}

.filter-group select option {
  background: #1a1a2e;
  color: var(--text-primary);
}

.filter-group select:focus,
.filter-group input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px var(--accent-purple-dim);
}

.filter-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-xs);
}

.btn-filter {
  flex: 1;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition-base);
}

.btn-filter.apply {
  background: linear-gradient(135deg, var(--accent-purple), var(--accent-purple-light));
  color: white;
}

.btn-filter.apply:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(139, 92, 246, 0.3);
}

.btn-filter.clear {
  background: var(--surface-hover);
  color: var(--text-secondary);
  border: 1px solid var(--surface-border);
}

.btn-filter.clear:hover {
  background: var(--surface-border);
}

/* ── SORT BAR ──────────────────────────────────────────── */
.sort-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.sort-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.sort-bar select {
  background: var(--bg-input);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: 0.78rem;
  font-family: var(--font);
  outline: none;
  cursor: pointer;
  color-scheme: dark;
}

.sort-bar select option {
  background: #1a1a2e;
  color: var(--text-primary);
}

/* ── RESULTS COUNT ─────────────────────────────────────── */
.results-count {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: var(--space-sm);
  outline: none;
  font-size: 0.9rem;
}

/* ── MULTI-SELECT TAGS ─────────────────────────────────── */
.filter-tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.filter-tag {
  display: inline-flex;
  align-items: center;
  background: var(--surface-hover);
  color: var(--text-primary);
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-light);
}

.filter-tag-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  margin-left: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}

.filter-tag-remove:hover {
  color: var(--accent-red);
}

/* ── PAYMENT METHOD BADGE ──────────────────────────────── */
.badge-payment {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: transparent;
  color: #a5b4fc;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge-payment.credito {
  color: #fda4af;
}

.badge-payment.debito {
  color: #86efac;
}

.badge-payment.mp {
  color: #93c5fd;
}

.badge-payment.efectivo {
  color: #fde68a;
}

.badge-payment.transferencia {
  color: #d8b4fe;
}

.badge-mp-icon {
  height: 14px;
  width: auto;
  object-fit: contain;
  vertical-align: middle;
  border-radius: 2px;
  flex-shrink: 0;
  opacity: 0.95;
}

.badge-efectivo-icon {
  height: 24px;
  width: auto;
  object-fit: contain;
  vertical-align: middle;
  flex-shrink: 0;
}

/* ── Mobile action buttons always visible ──────────────── */
@media (hover: none) and (pointer: coarse) {
  .expense-actions {
    opacity: 1;
  }
}

/* ── TOGGLE SWITCH ─────────────────────────────────────── */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--surface-active);
  transition: .3s;
  border-radius: 24px;
  border: 1px solid var(--surface-border);
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-primary);
  transition: .3s;
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-slider {
  background-color: var(--accent-purple);
  border-color: var(--accent-purple-light);
}

.toggle-switch input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* ── MOBILE OPTIMIZATIONS (iPhone & Small Screens) ─────── */
@media screen and (max-width: 480px) {
  .expense-item {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: 
      "info info"
      "amount actions";
    row-gap: var(--space-sm);
    padding: 12px;
    align-items: center;
  }
  
  .expense-icon {
    display: none;
  }
  
  .expense-info {
    grid-area: info;
    min-width: 0;
  }

  .expense-description {
    white-space: normal;
    overflow: visible;
  }
  
  .expense-amount {
    grid-area: amount;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-top: 4px;
  }
  
  .expense-actions {
    grid-area: actions;
    opacity: 1;
    align-self: end;
    margin-top: 4px;
  }
}

/* ── Sign Toggle Button ───────────────────────────────── */
.sign-toggle-btn {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 1.25rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  outline: none;
}

.sign-toggle-btn[data-sign="-"] {
  background: var(--accent-purple-dim);
  color: var(--accent-purple);
  border-color: var(--accent-purple-dim);
}

.sign-toggle-btn[data-sign="+"] {
  background: var(--accent-purple-light);
  color: #ffffff;
  border-color: var(--accent-purple-light);
  box-shadow: var(--shadow-glow-purple);
}
