/* ComandoCentral — Sistema de diseño v2 (refresh visual)
   Paleta dark azulado profundo + acento azul corporativo (#3B82F6).
   Estética Linear/Vercel: jerarquía clara, espaciado consistente, sutileza.
   Las variables viejas (--bg-primary, --accent, etc.) se mantienen como
   alias para no romper estilos inline en modules.js / index.html. */

:root {
  /* === BACKGROUNDS === */
  --bg-base: #0A0E1A;
  --bg-surface: #131826;
  --bg-surface-hover: #1A2030;
  --bg-elevated: #1F2638;
  --bg-sidebar: #0E1320;

  /* === BORDERS === */
  --border-subtle: #1F2638;
  --border-default: #2A3346;
  --border-strong: #3B4660;

  /* === TEXT === */
  --text-primary: #E6E9EF;
  --text-secondary: #9099A8;
  --text-tertiary: #5A6378;
  --text-disabled: #3D4658;

  /* === ACCENT (azul corporativo) === */
  --accent-primary: #3B82F6;
  --accent-hover: #5A95F9;
  --accent-active: #2563EB;
  --accent-muted: rgba(59, 130, 246, 0.10);
  --accent-glow: rgba(59, 130, 246, 0.15);

  /* === STATUS === */
  --success: #22C55E;
  --success-muted: rgba(34, 197, 94, 0.12);
  --warning: #F59E0B;
  --warning-muted: rgba(245, 158, 11, 0.12);
  --danger: #EF4444;
  --danger-muted: rgba(239, 68, 68, 0.12);

  /* === SEMANTIC FINANCIEROS === */
  --ingreso: var(--success);
  --gasto: var(--danger);
  --neutro: var(--text-secondary);

  /* === SPACING === */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;

  /* === TYPOGRAPHY === */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Cascadia Mono', Menlo, Consolas, monospace;
  --text-xs: 11px;
  --text-sm: 13px;
  --text-base: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 28px;
  --text-3xl: 36px;
  --lh-xs: 16px;
  --lh-sm: 20px;
  --lh-base: 21px;
  --lh-lg: 24px;
  --lh-xl: 28px;
  --lh-2xl: 36px;
  --lh-3xl: 44px;

  /* === RADIUS === */
  --radius-sm: 6px;
  --radius: 8px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* === SHADOWS === */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.30);
  --shadow: 0 4px 12px rgba(0,0,0,0.40);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.50);
  --shadow-glow: 0 0 0 3px var(--accent-glow);

  /* === TRANSITIONS === */
  --transition-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 300ms cubic-bezier(0.4, 0, 0.2, 1);

  /* === LAYOUT === */
  --sidebar-width: 240px;
  --header-height: 56px;
  --content-max-width: 1400px;

  /* === ALIASES retro-compat (no borrar; los usa código existente) === */
  --bg-primary: var(--bg-base);
  --bg-secondary: var(--bg-surface);
  --bg-card: var(--bg-surface);
  --bg-input: var(--bg-elevated);
  --accent: var(--accent-primary);
  --border: var(--border-default);
}

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

html, body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--lh-base);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Tabular numbers para columnas de plata */
.num, .card-value, .kpi-value, .extracto-monto, .presup-value,
.presup-bloque-total, .presup-item-monto {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
}

a { color: var(--accent-primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--accent-hover); }

/* Selección */
::selection { background: var(--accent-glow); color: var(--text-primary); }

/* Scrollbars (webkit) — finos, sutiles */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Focus visible global */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-glow);
}
button:focus { outline: none; }

/* ========== LOGIN ========== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 20%, rgba(59, 130, 246, 0.08), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(59, 130, 246, 0.05), transparent 50%),
    var(--bg-base);
}

.login-box {
  background: var(--bg-surface);
  padding: var(--space-10);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  margin: var(--space-5);
}

.login-box h1 {
  text-align: center;
  margin-bottom: var(--space-2);
  color: var(--text-primary);
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-box .subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: var(--space-8);
  font-size: var(--text-sm);
}

/* ========== LAYOUT ========== */
.app-container { display: none; }
.app-container.active { display: flex; min-height: 100vh; background: var(--bg-base); }

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-slow);
}

.sidebar-header {
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}

.sidebar-header h2 {
  color: var(--text-primary);
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.sidebar-header h2::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  box-shadow: 0 0 8px var(--accent-glow);
}

.sidebar-header .user-info {
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  margin-top: var(--space-1);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-3) 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.nav-item {
  display: flex;
  align-items: center;
  padding: var(--space-2) var(--space-4);
  margin: 0 var(--space-2);
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 500;
  border-left: 0;
  user-select: none;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent-muted);
  color: var(--accent-primary);
  font-weight: 600;
}

.nav-item i {
  width: 18px;
  margin-right: var(--space-3);
  text-align: center;
  font-size: 14px;
  opacity: 0.85;
}

.nav-item.active i { opacity: 1; }

.sidebar-footer {
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* Main content */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Header (top bar) */
.header {
  height: var(--header-height);
  background: rgba(10, 14, 26, 0.80);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-6);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--text-lg);
  cursor: pointer;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.menu-toggle:hover { background: var(--bg-elevated); color: var(--text-primary); }

/* Header search */
.header-search { position: relative; display: flex; align-items: center; }
.header-search-icon {
  position: absolute;
  left: var(--space-3);
  color: var(--text-tertiary);
  font-size: 12px;
  pointer-events: none;
}
.header-search input.form-control {
  width: 240px;
  padding: 6px var(--space-3) 6px var(--space-8);
  font-size: var(--text-sm);
  background: var(--bg-elevated);
  border-color: var(--border-subtle);
}
.header-search input.form-control:focus { border-color: var(--accent-primary); }
.header-search-results {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  width: 360px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  margin-top: var(--space-1);
  max-height: 320px;
  overflow-y: auto;
  z-index: 100;
  box-shadow: var(--shadow-lg);
}

/* Content area */
.content {
  padding: var(--space-6);
  flex: 1;
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  animation: fade-in var(--transition) both;
}

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

/* ========== COMPONENTS ========== */

/* Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  transition: border-color var(--transition), background var(--transition);
}

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

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-3);
  gap: var(--space-2);
}

.card-title {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.card-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  background: var(--accent-muted);
  color: var(--accent-primary);
}

.card-value {
  font-size: var(--text-2xl);
  line-height: var(--lh-2xl);
  font-weight: 700;
  margin-bottom: var(--space-1);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.card-detail {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: var(--lh-sm);
}

.card-positive { color: var(--success) !important; }
.card-negative { color: var(--danger) !important; }
.card-neutral  { color: var(--accent-primary) !important; }

/* KPI cards (variante explícita) */
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: border-color var(--transition);
}
.kpi-card:hover { border-color: var(--border-strong); }
.kpi-card .kpi-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  font-weight: 600;
}
.kpi-card .kpi-value {
  font-size: var(--text-3xl);
  line-height: var(--lh-3xl);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}
.kpi-card .kpi-sub {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}
.kpi-card .kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  font-weight: 600;
}
.kpi-delta.up   { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

/* Forms */
.form-group { margin-bottom: var(--space-4); }

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

.form-control {
  width: 100%;
  padding: 10px var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: inherit;
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control::placeholder { color: var(--text-tertiary); }

.form-control:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: var(--shadow-glow);
}

.form-control:disabled {
  color: var(--text-disabled);
  cursor: not-allowed;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239099A8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
  cursor: pointer;
}

textarea.form-control { resize: vertical; min-height: 80px; line-height: 1.5; }

/* Buttons */
.btn {
  padding: 8px var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 20px;
  transition: background var(--transition-fast), border-color var(--transition-fast),
              color var(--transition-fast), transform var(--transition-fast),
              box-shadow var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  white-space: nowrap;
  user-select: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:disabled:active { transform: none; }

.btn-primary {
  background: var(--accent-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { background: var(--accent-active); }

.btn-secondary {
  background: transparent;
  border-color: var(--border-default);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--bg-elevated); border-color: var(--border-strong); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(1.08); }

.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }

.btn-warning { background: var(--warning); color: #1a1100; }
.btn-warning:hover { filter: brightness(1.08); }

/* Outline = alias semántico de secondary, lo usa muchísimo código viejo */
.btn-outline {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}
.btn-outline:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-sm { padding: 6px var(--space-3); font-size: var(--text-xs); line-height: 16px; }

/* Tables */
.table-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-3);
}

.table-header h3 {
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

th, td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
  line-height: var(--lh-sm);
  vertical-align: middle;
}

th {
  background: transparent;
  color: var(--text-tertiary);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom-color: var(--border-default);
}

tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: var(--bg-surface-hover); }
tbody tr:last-child td { border-bottom: none; }

.table-actions {
  display: flex;
  gap: var(--space-1);
  justify-content: flex-end;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  animation: fade-in var(--transition-fast) both;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  margin: var(--space-5);
  animation: modal-pop var(--transition) both;
}

@keyframes modal-pop {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h3 {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-tertiary);
  font-size: var(--text-xl);
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.modal-close:hover { background: var(--bg-elevated); color: var(--text-primary); }

.modal-body { padding: var(--space-5) var(--space-6); }

.modal-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* Badges (alias del nuevo sistema .chip — se mantienen para retro-compat) */
.badge, .chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  line-height: 16px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-success, .chip-success { background: var(--success-muted); color: var(--success); }
.badge-danger,  .chip-danger  { background: var(--danger-muted);  color: var(--danger); }
.badge-warning, .chip-warning { background: var(--warning-muted); color: var(--warning); }
.badge-info,    .chip-accent  { background: var(--accent-muted);  color: var(--accent-primary); }
.chip-neutral { background: var(--bg-elevated); color: var(--text-secondary); }

/* Charts */
.chart-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}

.chart-container h3 {
  margin-bottom: var(--space-4);
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.charts-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

/* Filters */
.filters-bar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  align-items: center;
}

.filters-bar .form-control {
  width: auto;
  min-width: 150px;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius);
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  box-shadow: var(--shadow);
  font-size: var(--text-sm);
  font-weight: 500;
  animation: slideIn var(--transition-slow) ease;
  min-width: 250px;
  max-width: 360px;
}

.toast-success {
  background: var(--success-muted);
  border-color: rgba(34, 197, 94, 0.30);
  color: var(--success);
}
.toast-error {
  background: var(--danger-muted);
  border-color: rgba(239, 68, 68, 0.30);
  color: var(--danger);
}
.toast-warning {
  background: var(--warning-muted);
  border-color: rgba(245, 158, 11, 0.30);
  color: var(--warning);
}

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

/* Section header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-5);
  gap: var(--space-3);
  flex-wrap: wrap;
}

.section-header h2 {
  font-size: var(--text-xl);
  line-height: var(--lh-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-4);
}

.pagination button {
  padding: 6px var(--space-3);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  color: var(--text-primary);
  cursor: pointer;
  font-size: var(--text-sm);
  transition: all var(--transition-fast);
}

.pagination button:hover {
  border-color: var(--border-strong);
}

.pagination button.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-secondary);
}

.empty-state i {
  font-size: 48px;
  margin-bottom: var(--space-3);
  display: block;
  color: var(--text-tertiary);
  opacity: 0.5;
}

.empty-state p {
  font-size: var(--text-base);
  color: var(--text-secondary);
  margin-top: var(--space-2);
}

/* Loading state */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-12) var(--space-6);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.loading i { color: var(--accent-primary); font-size: var(--text-lg); }

/* Spinner reutilizable */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-default);
  border-top-color: var(--accent-primary);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Utilities */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger)  !important; }
.text-warning { color: var(--warning) !important; }
.text-accent  { color: var(--accent-primary) !important; }
.text-muted   { color: var(--text-secondary) !important; }
.text-mono    { font-family: var(--font-mono); font-feature-settings: 'tnum'; }

/* Calendar */
.cal-container {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.cal-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  background: var(--bg-elevated);
}

.cal-header div {
  padding: var(--space-3);
  text-align: center;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.cal-cell {
  min-height: 90px;
  border: 1px solid var(--border-subtle);
  padding: var(--space-1);
  font-size: var(--text-sm);
}

.cal-empty { background: var(--bg-base); }

.cal-today {
  background: var(--accent-muted);
}

.cal-day {
  font-weight: 600;
  margin-bottom: var(--space-1);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.cal-today .cal-day { color: var(--accent-primary); }

.cal-event {
  padding: 2px var(--space-1);
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--accent-muted);
  color: var(--accent-primary);
}

/* Search */
.search-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: var(--text-sm);
}

.search-item:hover { background: var(--bg-elevated); }
.search-item:last-child { border-bottom: none; }

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--space-12));
  max-height: 800px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.bot { justify-content: flex-start; }

.chat-bubble {
  max-width: 80%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.55;
  word-wrap: break-word;
}

.chat-bubble.user {
  background: var(--accent-primary);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.chat-bubble.bot {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
}

.chat-input-area {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  align-items: center;
}

.chat-input-area .form-control {
  flex: 1;
  border-radius: var(--radius-full);
  padding: 10px var(--space-4);
}

.chat-upload-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--accent-primary);
  font-size: var(--text-base);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.chat-upload-btn:hover { background: var(--accent-muted); border-color: var(--accent-primary); }

.chat-options {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.chat-sugerencias {
  margin-top: var(--space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

/* FAB - Floating Action Button */
.fab {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: var(--accent-primary);
  color: #fff;
  border: none;
  font-size: var(--text-lg);
  cursor: pointer;
  z-index: 90;
  box-shadow: 0 8px 24px rgba(59, 130, 246, 0.40), var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition-fast);
}

.fab:hover {
  transform: translateY(-2px) scale(1.04);
  background: var(--accent-hover);
  box-shadow: 0 12px 32px rgba(59, 130, 246, 0.50), var(--shadow-lg);
}

.fab:active { transform: translateY(-1px) scale(0.97); }

/* PWA install banner */
.pwa-install {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border-top: 1px solid var(--accent-primary);
  padding: var(--space-3) var(--space-5);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 300;
  font-size: var(--text-sm);
}

/* ========== RESPONSIVE ========== */

/* Safe areas for notch/status bar/nav bar */
@supports (padding-top: env(safe-area-inset-top)) {
  .header { padding-top: env(safe-area-inset-top); height: calc(var(--header-height) + env(safe-area-inset-top)); }
  .sidebar { padding-top: env(safe-area-inset-top); }
  .fab { bottom: calc(24px + env(safe-area-inset-bottom)); }
  .chat-input-area { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}

/* Android standalone (PWA/WebView) */
@media (display-mode: standalone) {
  .header { padding-top: 28px; height: calc(var(--header-height) + 28px); }
  .sidebar { padding-top: 28px; }
  .fab { bottom: 48px; }
  .chat-input-area { padding-bottom: 28px; }
  .modal-body { max-height: calc(90vh - 80px); }
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: block; }
  .cards-grid { grid-template-columns: 1fr 1fr; }
  .charts-row { grid-template-columns: 1fr; }
  .filters-bar { flex-direction: column; }
  .filters-bar .form-control { width: 100%; }
  th, td { padding: 8px 10px; font-size: 0.8em; }
  .content { padding-bottom: 80px; }
}

@media (max-width: 480px) {
  .cards-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; padding-bottom: 80px; }
}

/* ========== EXTRACTO BANCARIO ========== */
.extracto-upload-area {
  max-width: 600px;
  margin: 0 auto;
}

.extracto-ultimos {
  background: var(--bg-surface);
  border: 1px solid var(--accent-primary);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

.extracto-ultimos-titulo {
  font-weight: 600;
  margin-bottom: var(--space-3);
  color: var(--accent-primary);
  font-size: var(--text-sm);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.extracto-ultimos-tabla {
  width: 100%;
  border-collapse: collapse;
}

.extracto-ultimos-tabla td {
  padding: 6px var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--text-sm);
}

.extracto-ultimos-tabla tr:last-child td { border-bottom: none; }

.extracto-dropzone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-surface);
}

.extracto-dropzone:hover,
.extracto-dropzone.dragover {
  border-color: var(--accent-primary);
  background: var(--accent-muted);
}

.extracto-progress {
  max-width: 600px;
  margin: 0 auto var(--space-5);
}

.progress-bar-bg {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  height: 8px;
  overflow: hidden;
}

.progress-bar-fill {
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-hover));
  height: 100%;
  border-radius: var(--radius);
  transition: width var(--transition-slow) ease;
}

.extracto-card {
  max-width: 600px;
  margin: 0 auto;
  background: var(--bg-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  border: 1px solid var(--border-default);
}

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

.extracto-monto {
  font-size: var(--text-2xl);
  line-height: var(--lh-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.extracto-original {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

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

.extracto-actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
}

.ext-sugerencias {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 200px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: var(--shadow);
}

.ext-sug-item {
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-subtle);
}

.ext-sug-item:hover, .ext-sug-item.active {
  background: var(--accent-muted);
  color: var(--accent-primary);
}

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

.ext-sug-crear {
  color: var(--accent-primary);
  font-weight: 600;
}

.ext-sug-crear i { margin-right: var(--space-2); }

.deuda-mensual {
  display: none;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
}

.deuda-mensual.active { display: block; }

.deuda-mensual table { margin: 0; }
.deuda-mensual th { font-size: var(--text-xs); color: var(--text-tertiary); }
.deuda-mensual td { font-size: var(--text-sm); }

@media (max-width: 600px) {
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .extracto-monto {
    font-size: 1.4em;
  }
  .extracto-card {
    padding: 16px;
  }
}

/* ========== PRESUPUESTO MENSUAL ========== */
.presup-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.presup-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  text-align: center;
  border: 1px solid var(--border-default);
  transition: border-color var(--transition);
}
.presup-card:hover { border-color: var(--border-strong); }
.presup-label {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.presup-value {
  font-size: var(--text-2xl);
  line-height: var(--lh-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.presup-layout {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: var(--space-5);
  align-items: start;
}

.presup-bloque {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-3);
  border: 1px solid var(--border-default);
  overflow: hidden;
  transition: border-color var(--transition);
}
.presup-bloque:hover { border-color: var(--border-strong); }
.presup-bloque-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.presup-bloque-header:hover {
  background: var(--bg-surface-hover);
}
.presup-bloque-title {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--text-primary);
}
.presup-bloque-count {
  color: var(--text-tertiary);
  font-size: var(--text-xs);
  font-weight: 500;
}
.presup-bloque-total {
  font-weight: 700;
  font-size: var(--text-lg);
  color: var(--accent-primary);
}
.presup-bloque-body {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-base);
}
.presup-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
  gap: var(--space-3);
}
.presup-item:last-child {
  border-bottom: none;
}
.presup-item-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.presup-item-name {
  font-weight: 500;
  font-size: var(--text-sm);
  color: var(--text-primary);
}
.presup-item-notas {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  font-style: italic;
}
.presup-item-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.presup-item-monto {
  font-weight: 600;
  min-width: 110px;
  text-align: right;
  font-size: var(--text-sm);
}

/* Chat IA */
.presup-chat-col {
  position: sticky;
  top: var(--space-3);
}
.presup-chat-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--space-12) - var(--header-height));
  min-height: 500px;
  overflow: hidden;
}
.presup-chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}
.presup-chat-header h3 {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.presup-chat-header h3::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--success);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}
.presup-chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
.presup-chat-empty {
  text-align: center;
  padding: var(--space-6) var(--space-3);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
}
.presup-msg {
  display: flex;
}
.presup-msg.user {
  justify-content: flex-end;
}
.presup-msg.assistant {
  justify-content: flex-start;
}
.presup-msg-bubble {
  max-width: 90%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  line-height: 1.55;
  word-wrap: break-word;
}
.presup-msg.user .presup-msg-bubble {
  background: var(--accent-primary);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}
.presup-msg.assistant .presup-msg-bubble {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: var(--radius-sm);
  color: var(--text-primary);
}
.presup-msg-bubble strong { color: var(--accent-primary); font-weight: 600; }
.presup-msg.user .presup-msg-bubble strong { color: #fff; }
.presup-msg-bubble code {
  background: rgba(0,0,0,0.3);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.92em;
  font-family: var(--font-mono);
}
.presup-chat-input {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}
.presup-chat-input input {
  flex: 1;
}

/* Tarjetas de gastos detectados en el chat */
.presup-gastos-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0;
}
.presup-gasto-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.presup-gasto-row {
  display: flex;
  gap: 6px;
  align-items: center;
}
.presup-gasto-desc { flex: 1; }
.presup-gasto-monto { width: 110px; }
.presup-gasto-cat { flex: 1; min-width: 0; }
.presup-gasto-card .form-control {
  font-size: 0.88em;
  padding: 4px 8px;
}

.btn-icon {
  background: none;
  border: 1px solid transparent;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius);
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
}
.btn-icon:hover {
  color: var(--accent-primary);
  background: var(--bg-elevated);
}

/* Quick Entry modal: tipo gasto/ingreso buttons en grid */
#qe-btn-gasto, #qe-btn-ingreso {
  transition: opacity var(--transition-fast), transform var(--transition-fast);
}

@media (max-width: 1024px) {
  .presup-layout {
    grid-template-columns: 1fr;
  }
  .presup-chat-col {
    position: static;
  }
  .presup-chat-card {
    height: 600px;
  }
  .presup-summary {
    grid-template-columns: 1fr;
  }
}
