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

:root {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-sidebar: #0f172a;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --accent-cyan: #0284c7;
  --color-credit: #16a34a;
  --color-debit: #dc2626;
  --border: #e2e8f0;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
}

.hidden { display: none !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: 0.88rem; }

/* AUTH SCREEN */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 100%);
}

.auth-card {
  background: var(--bg-card);
  width: 100%;
  max-width: 430px;
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.25);
}

.auth-brand {
  text-align: center;
  margin-bottom: 24px;
}

.brand-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.auth-brand h1 {
  font-size: 1.6rem;
  color: #0f172a;
}

.auth-brand p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #f1f5f9;
  padding: 4px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 10px;
  font-weight: 600;
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* LAYOUT */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 250px;
  background: var(--bg-sidebar);
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  flex-shrink: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  margin-bottom: 20px;
}

.logo-badge {
  background: var(--primary);
  color: white;
  font-weight: 800;
  padding: 8px 10px;
  border-radius: 8px;
}

.sidebar-header h2 { font-size: 1.15rem; }
.sidebar-header small { color: #94a3b8; font-size: 0.78rem; }

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

.nav-item {
  background: transparent;
  border: none;
  color: #cbd5e1;
  text-align: left;
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #ffffff;
}

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

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.1);
  padding-top: 16px;
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-meta { overflow: hidden; }
.user-meta strong {
  display: block;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-meta span {
  display: block;
  font-size: 0.75rem;
  color: #94a3b8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-content {
  flex: 1;
  padding: 24px 28px;
  overflow-y: auto;
  min-width: 0;
}

.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}

.top-header h1 { font-size: 1.5rem; }

.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  background: #e2e8f0;
}
.connection-status.connected { background: #dcfce7; color: #166534; }
.connection-status.disconnected { background: #fee2e2; color: #991b1b; }
.connection-status .dot {
  width: 8px; height: 8px; border-radius: 50%; background: currentColor;
}

.content-view { display: none; }
.content-view.active { display: block; }

/* CARDS & GRIDS */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card, .card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card { margin-bottom: 24px; }

.kpi-label { font-size: 0.85rem; color: var(--text-muted); }
.kpi-value { display: block; font-size: 1.65rem; margin: 6px 0; color: #0f172a; }
.kpi-sub { font-size: 0.78rem; color: var(--text-muted); }

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

.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.account-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.account-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.badge-group {
  background: #dbeafe;
  color: #1e40af;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}

.account-ccc {
  font-family: monospace;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.account-balance {
  font-size: 1.35rem;
  font-weight: 700;
}

.account-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* =========================================================
   ANÁLISIS Y GRÁFICOS (DISEÑO DE 2 COLUMNAS CON SELECTOR)
   ========================================================= */
.charts-workspace {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 20px;
  align-items: start;
}

.chart-selector-panel { margin-bottom: 0; }
.chart-selector-panel h3 { font-size: 1.05rem; margin-bottom: 6px; }

.selector-subtitle {
  font-size: 0.83rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.date-input-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.selector-list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.84rem;
  font-weight: 600;
  margin-top: 16px;
  margin-bottom: 8px;
  color: var(--text-main);
}

.quick-select-links {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent-cyan);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 0.78rem;
}
.link-btn:hover { text-decoration: underline; }

.account-selector-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.selector-account-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.selector-account-card:hover {
  border-color: #93c5fd;
  background: #eff6ff;
}

.selector-account-card.checked {
  border-color: var(--accent-cyan);
  background: #f0f9ff;
}

.selector-account-card input[type="checkbox"] {
  margin-top: 3px;
  accent-color: var(--accent-cyan);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.selector-acc-info { flex: 1; min-width: 0; }
.selector-acc-title {
  display: block;
  font-size: 0.88rem;
  font-weight: 700;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.selector-acc-ccc {
  display: block;
  font-family: monospace;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin: 2px 0;
}
.selector-acc-meta {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--accent-cyan);
}

.selector-footnote {
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.chart-main-panel { margin-bottom: 0; min-width: 0; }

.chart-main-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.chart-main-header h3 { font-size: 1.15rem; margin-bottom: 4px; }

.patrimonio-badge {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  color: #0369a1;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  white-space: nowrap;
}
.patrimonio-badge strong { font-size: 0.98rem; color: #0c4a6e; }

.consolidated-chart-box {
  position: relative;
  height: 450px;
  width: 100%;
}

/* FORMS & BUTTONS */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 5px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.92rem;
  background: #ffffff;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid #cbd5e1; color: inherit; }
.sidebar .btn-outline { border-color: rgba(255,255,255,0.25); color: #f8fafc; }
.sidebar .btn-outline:hover { background: rgba(255,255,255,0.1); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 10px; font-size: 0.8rem; }
.btn-block { width: 100%; }

/* TABLES & FILTERS */
.filters-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.filters-bar select, .filters-bar input { width: auto; min-width: 170px; }

.table-responsive { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.data-table th, .data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.data-table th { background: #f8fafc; font-weight: 600; color: var(--text-muted); }

.clickable-row {
  cursor: pointer;
  transition: background-color 0.14s ease;
}
.clickable-row:hover {
  background-color: #eff6ff;
}

.detail-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
  font-size: 0.76rem;
  font-weight: 600;
}
.clickable-row:hover .detail-pill {
  background: var(--primary);
  color: #ffffff;
}

.amount-credit { color: var(--color-credit); font-weight: 600; }
.amount-debit { color: var(--color-debit); font-weight: 600; }

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  font-size: 0.85rem;
}

/* UPLOAD */
.drop-zone {
  border: 2px dashed #94a3b8;
  border-radius: 10px;
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  margin: 16px 0;
  background: #f8fafc;
  transition: border-color 0.2s, background 0.2s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--primary);
  background: #eff6ff;
}
.drop-icon { font-size: 2.5rem; margin-bottom: 8px; }
.preview-box {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  background: #f8fafc;
  margin-top: 16px;
}
.preview-actions { display: flex; gap: 10px; margin-top: 14px; }

/* ALERTS & MODALS */
.alert {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; margin-top: 14px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  background: #fff;
  width: 100%;
  max-width: 450px;
  border-radius: 12px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.3);
}
.modal-card-lg {
  max-width: 720px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.btn-close {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* DETALLE DE MOVIMIENTO C43 */
.tx-hero-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 12px;
}
.tx-hero-amount {
  font-size: 1.75rem;
  font-weight: 800;
}
.tx-type-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}
.tx-type-badge.credit { background: #dcfce7; color: #166534; }
.tx-type-badge.debit { background: #fee2e2; color: #991b1b; }

.detail-section {
  margin-bottom: 18px;
}
.detail-section h4 {
  font-size: 0.92rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #334155;
  margin-bottom: 10px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 16px;
}
.detail-field {
  background: #f8fafc;
  padding: 9px 12px;
  border-radius: 7px;
  border: 1px solid #e2e8f0;
}
.detail-field-label {
  display: block;
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.detail-field-value {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: #0f172a;
  word-break: break-word;
}
.mono { font-family: monospace; }

.concept-lines-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.concept-line-item {
  display: flex;
  align-items: baseline;
  gap: 10px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.9rem;
}
.concept-line-tag {
  font-family: monospace;
  font-size: 0.76rem;
  font-weight: 700;
  background: #0284c7;
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

.empty-state { text-align: center; color: var(--text-muted); padding: 24px; }

@media (max-width: 960px) {
  .charts-workspace { grid-template-columns: 1fr; }
  .consolidated-chart-box { height: 340px; }
}

@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; }
}
