:root {
  --bg-main: #0b0f19;
  --bg-card: #151c2c;
  --bg-card-elevated: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: rgba(255, 255, 255, 0.08);

  /* Dynamic Scope Colors (Default: Personal = Emerald) */
  --scope-primary: #10b981;
  --scope-primary-dark: #059669;
  --scope-glow: rgba(16, 185, 129, 0.22);
  --scope-gradient: linear-gradient(135deg, #059669 0%, #047857 100%);

  --income-color: #34d399;
  --expense-color: #fb7185;
  --warning-color: #fbbf24;
  --danger-color: #f43f5e;
  --radius-lg: 18px;
  --radius-md: 12px;
}

/* Tema Visual Distintivo por Modo para evitar confundir cuentas */
body[data-scope="personal"] {
  --scope-primary: #10b981;
  --scope-primary-dark: #059669;
  --scope-glow: rgba(16, 185, 129, 0.22);
  --scope-gradient: linear-gradient(135deg, #059669 0%, #065f46 100%);
}

body[data-scope="business"] {
  --scope-primary: #3b82f6;
  --scope-primary-dark: #2563eb;
  --scope-glow: rgba(59, 130, 246, 0.24);
  --scope-gradient: linear-gradient(135deg, #2563eb 0%, #1e40af 100%);
}

body[data-scope="combined"] {
  --scope-primary: #8b5cf6;
  --scope-primary-dark: #7c3aed;
  --scope-glow: rgba(139, 92, 246, 0.24);
  --scope-gradient: linear-gradient(135deg, #7c3aed 0%, #4c1d95 100%);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.45;
  overflow-x: hidden;
}

.app-shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 140px;
  position: relative;
}

/* Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(11, 15, 25, 0.88);
  backdrop-filter: blur(14px);
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border-color);
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: var(--scope-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  box-shadow: 0 4px 14px var(--scope-glow);
  transition: all 0.25s ease;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--scope-primary);
  font-weight: 600;
}

.cloud-btn {
  background: var(--bg-card-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 6px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.cloud-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
}

.cloud-dot.online {
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* Scope Switcher */
.scope-switcher {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: var(--bg-card);
  padding: 4px;
  border-radius: 13px;
  border: 1px solid var(--border-color);
  gap: 4px;
}

.scope-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 9px 6px;
  border-radius: 9px;
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.scope-tab.active {
  background: var(--scope-gradient);
  color: #fff;
  box-shadow: 0 3px 10px var(--scope-glow);
}

/* Main Content */
.main-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hidden {
  display: none !important;
}

/* Alert Banner */
.alert-banner {
  background: rgba(244, 63, 94, 0.14);
  border: 1px solid rgba(244, 63, 94, 0.4);
  color: #fda4af;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  font-weight: 500;
}

/* Hero Card */
.hero-card {
  background: var(--scope-gradient);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: 0 10px 28px var(--scope-glow);
  transition: background 0.3s ease;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.hero-label {
  font-size: 0.82rem;
  opacity: 0.9;
  font-weight: 500;
}

.scope-pill {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  background: rgba(0, 0, 0, 0.26);
  padding: 3px 8px;
  border-radius: 99px;
}

.hero-amount {
  font-size: 2.15rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 14px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  background: rgba(0, 0, 0, 0.22);
  padding: 11px;
  border-radius: 12px;
  margin-bottom: 12px;
}

.metric-box {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.72rem;
  opacity: 0.85;
}

.metric-value {
  font-size: 1rem;
  font-weight: 700;
  margin-top: 2px;
}

.hero-debt-strip {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
}

.debt-strip-label {
  opacity: 0.85;
}

/* Comparison Grid (Combined Mode) */
.comparison-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.comparison-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 13px;
  border: 1px solid var(--border-color);
}

.personal-card {
  border-top: 3px solid #10b981;
}

.business-card {
  border-top: 3px solid #3b82f6;
}

.comp-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.comp-badge {
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
}

.comp-balance {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.comp-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 3px;
}

.comp-row strong {
  color: var(--text-main);
}

.comp-row.debt strong {
  color: var(--warning-color);
}

/* Section Headers & Pills */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.filter-pills {
  display: flex;
  gap: 6px;
}

.pill {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.pill.active {
  background: var(--scope-primary);
  color: #fff;
  border-color: transparent;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 15px;
  margin-bottom: 14px;
}

.card h3 {
  font-size: 0.92rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.card-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

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

.small {
  font-size: 0.78rem;
}

/* Category Bars */
.category-bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.cat-bar-top {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
}

.progress-track {
  width: 100%;
  height: 7px;
  background: var(--bg-card-elevated);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--scope-primary);
  border-radius: 99px;
  transition: width 0.3s ease;
}

/* Items List (Transactions & Debts) */
.items-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.item-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.item-left {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.item-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--bg-card-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.item-info {
  min-width: 0;
}

.item-title {
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 2px;
}

.scope-tag {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
}

.scope-tag.personal {
  background: rgba(16, 185, 129, 0.16);
  color: #34d399;
}

.scope-tag.business {
  background: rgba(59, 130, 246, 0.18);
  color: #60a5fa;
}

.item-right {
  text-align: right;
  flex-shrink: 0;
}

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

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

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

.delete-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  margin-top: 4px;
}

.delete-btn:hover {
  color: var(--danger-color);
}

/* Debt Card Specifics */
.debt-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.debt-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.debt-amounts {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.debt-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 6px;
  border-top: 1px solid var(--border-color);
}

.btn-small {
  background: var(--scope-primary);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

/* Floating Action Buttons */
.fab-container {
  position: fixed;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  padding: 0 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  pointer-events: none;
  z-index: 25;
}

.fab {
  pointer-events: auto;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  gap: 6px;
}

.fab-primary {
  background: var(--scope-gradient);
  color: #fff;
}

.fab-secondary {
  background: var(--bg-card-elevated);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 8px 12px 12px;
  z-index: 30;
}

.nav-item {
  background: none;
  border: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px;
}

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

.nav-icon {
  font-size: 1.2rem;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  background: var(--bg-card);
  width: 100%;
  max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 20px 18px 28px;
  max-height: 90vh;
  overflow-y: auto;
  border-top: 1px solid var(--border-color);
}

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

.close-btn {
  background: var(--bg-card-elevated);
  border: none;
  color: var(--text-main);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
}

/* Forms */
.form-group {
  margin-bottom: 13px;
}

.form-group label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 600;
}

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

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="password"],
input[type="url"],
select {
  width: 100%;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: inherit;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg-main);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  gap: 4px;
}

.seg-option input {
  display: none;
}

.seg-option span {
  display: block;
  text-align: center;
  padding: 8px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}

.seg-option input:checked + span {
  background: var(--scope-primary);
  color: #fff;
}

.btn-primary {
  background: var(--scope-gradient);
  color: #fff;
  border: none;
  padding: 13px 16px;
  border-radius: 11px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-secondary {
  background: var(--bg-card-elevated);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 11px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
  text-align: center;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.2);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.4);
  padding: 11px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.82rem;
  cursor: pointer;
}

.full-width {
  width: 100%;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

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

.sql-helper {
  margin-top: 16px;
  background: var(--bg-main);
  padding: 10px;
  border-radius: 10px;
  font-size: 0.78rem;
}

.sql-helper summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--scope-primary);
}

.sql-helper pre {
  margin-top: 8px;
  font-size: 0.7rem;
  overflow-x: auto;
  color: #cbd5e1;
  background: #050811;
  padding: 8px;
  border-radius: 6px;
}

.empty-state {
  text-align: center;
  padding: 28px 16px;
  color: var(--text-muted);
  font-size: 0.85rem;
}
