/* =========================================================
   FINOVA — Hoja de estilos profesional
   Tema oscuro con acento dorado. Responsive (PC + móvil).
   ========================================================= */

:root {
  --bg-0: #020617;
  --bg-1: #0b1224;
  --bg-2: #0f172a;
  --bg-3: #1e293b;
  --bg-4: #334155;
  --line: rgba(148, 163, 184, 0.12);
  --line-strong: rgba(148, 163, 184, 0.22);

  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --text-mute: #64748b;

  --gold: #fbbf24;
  --gold-2: #f59e0b;
  --gold-3: #d97706;

  --green: #10b981;
  --red: #ef4444;
  --blue: #3b82f6;
  --violet: #8b5cf6;

  --shadow-1: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-2: 0 12px 28px rgba(0, 0, 0, 0.45);
  --radius: 14px;
  --radius-sm: 10px;

  --sidebar-w: 252px;
  --header-h: 64px;

  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  -webkit-overflow-scrolling: touch;
  overflow-x: hidden;
}
html { min-height: 100%; }
body {
  min-height: 100vh;
  /* dvh respeta correctamente la barra dinámica del navegador móvil */
  min-height: 100dvh;
}

/* Pull-to-refresh activo por defecto. Solo se bloquea cuando hay un modal abierto
   (para que al deslizar dentro del modal no se recargue la página de fondo). */
body.modal-open {
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
}
body.modal-open .modal-bg {
  touch-action: auto;
  overscroll-behavior: contain;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-2); }

button { font-family: inherit; }

/* ---------- Layout principal ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 22px 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.brand img { width: 38px; height: 38px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name {
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--gold);
  font-size: 16px;
}
.brand-tag {
  font-size: 10.5px;
  text-transform: uppercase;
  color: var(--text-mute);
  letter-spacing: 1px;
}
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  font-size: 13.5px;
  transition: all .15s ease;
}
.nav button:hover { background: var(--bg-3); color: var(--text); }
.nav button.active {
  background: linear-gradient(180deg, rgba(251, 191, 36, 0.10), rgba(251, 191, 36, 0.04));
  color: var(--gold);
  border-color: rgba(251, 191, 36, 0.18);
}
.nav button svg { width: 18px; height: 18px; flex: none; }

.sidebar-footer {
  padding: 10px;
  font-size: 11.5px;
  color: var(--text-mute);
  border-top: 1px solid var(--line);
  margin-top: 8px;
}
.bcv-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 11.5px;
  color: var(--gold);
  margin-bottom: 6px;
  font-family: var(--font-mono);
}
.bcv-pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

/* ---------- Header ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }
.header {
  position: sticky;
  top: 0;
  background: rgba(11, 18, 36, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 30;
}
.header h1 {
  font-size: 17px;
  margin: 0;
  font-weight: 600;
  letter-spacing: .2px;
}
.header-right { display: flex; align-items: center; gap: 10px; }

.btn {
  border: 1px solid var(--line-strong);
  background: var(--bg-3);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all .15s;
}
.btn:hover { background: var(--bg-4); border-color: var(--gold); }
.btn svg { width: 16px; height: 16px; }
.btn-primary {
  background: linear-gradient(180deg, var(--gold), var(--gold-3));
  color: #1a1306;
  border: none;
  font-weight: 600;
}
.btn-primary:hover { filter: brightness(1.06); border: none; }
.btn-ghost { background: transparent; }
.btn-danger { background: rgba(239, 68, 68, 0.15); border-color: rgba(239,68,68,0.3); color: #fecaca; }
.btn-danger:hover { background: rgba(239,68,68,0.25); border-color: rgba(239,68,68,0.5); }

/* ---------- Content area ---------- */
.content {
  padding: 24px;
  max-width: 1500px;
  width: 100%;
  margin: 0 auto;
}
.section { display: none; }
.section.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity:0; transform: translateY(4px); } to { opacity:1; transform:none; } }

.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-mute);
  margin: 22px 0 10px;
  font-weight: 600;
}

/* ---------- KPI cards ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}
.kpi {
  background: linear-gradient(180deg, var(--bg-2), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--gold), transparent);
  opacity: .55;
}
.kpi.green::before { background: linear-gradient(90deg, var(--green), transparent); }
.kpi.red::before { background: linear-gradient(90deg, var(--red), transparent); }
.kpi.blue::before { background: linear-gradient(90deg, var(--blue), transparent); }
.kpi.violet::before { background: linear-gradient(90deg, var(--violet), transparent); }

.kpi-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-mute);
  display: flex; align-items: center; gap: 8px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 700;
  font-family: var(--font-mono);
  margin-top: 6px;
  color: var(--text);
}
.kpi-value.green { color: var(--green); }
.kpi-value.red { color: var(--red); }
.kpi-value.gold { color: var(--gold); }
.kpi-sub { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-title {
  font-size: 14.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title svg { width: 18px; height: 18px; color: var(--gold); }

/* ---------- Tabla ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th, .tbl td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.tbl th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-mute);
  font-weight: 600;
  background: var(--bg-1);
  position: sticky;
  top: 0;
}
.tbl tr:hover td { background: rgba(251, 191, 36, 0.04); }
.tbl td.num { text-align: right; font-family: var(--font-mono); }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.badge.ingreso { background: rgba(16,185,129,.15); color: #6ee7b7; }
.badge.gasto { background: rgba(239,68,68,.15); color: #fca5a5; }
.badge.ahorro { background: rgba(139,92,246,.15); color: #c4b5fd; }
.badge .dot { width:6px; height:6px; border-radius:50%; }

.row-actions {
  display: flex; gap: 6px; justify-content: flex-end;
}
.icon-btn {
  background: transparent; border: 1px solid var(--line);
  color: var(--text-dim);
  width: 30px; height: 30px;
  display:inline-flex; align-items:center; justify-content:center;
  border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { color: var(--gold); border-color: var(--gold); }
.icon-btn.del:hover { color: var(--red); border-color: var(--red); }
.icon-btn svg { width: 14px; height: 14px; }

/* ---------- Form ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-mute);
  font-weight: 600;
}
.field input, .field select, .field textarea {
  background: var(--bg-1);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color .15s, background .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--gold);
  background: var(--bg-2);
}
.field textarea { min-height: 70px; resize: vertical; }

.form-actions {
  display: flex; gap: 10px; justify-content: flex-end;
  margin-top: 14px;
}

/* ---------- Filtros ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.filters .field { min-width: 140px; flex: 1; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--bg-3);
  border: 1px solid var(--line);
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-dim);
}
.chip.active { background: var(--gold); color: #1a1306; border-color: var(--gold); font-weight:600; }

/* ---------- Charts ---------- */
.charts {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
}
@media (max-width: 1024px) { .charts { grid-template-columns: 1fr; } }
canvas { max-width: 100%; }

/* ---------- IA panel ---------- */
.ia-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}
@media (max-width: 1024px) { .ia-grid { grid-template-columns: 1fr; } }

.plan-md {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 18px;
  font-size: 13.5px;
  line-height: 1.7;
  max-height: 580px;
  overflow-y: auto;
}
.plan-md h2 { color: var(--gold); font-size: 15px; margin: 18px 0 8px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.plan-md h2:first-child { margin-top: 0; }
.plan-md h3 { color: var(--text); font-size: 14px; margin: 12px 0 6px; }
.plan-md p { margin: 6px 0; }
.plan-md ul, .plan-md ol { padding-left: 22px; margin: 6px 0; }
.plan-md table { width: 100%; border-collapse: collapse; margin: 8px 0; font-size: 12.5px; }
.plan-md th, .plan-md td { padding: 8px 10px; border: 1px solid var(--line); text-align: left; }
.plan-md th { background: var(--bg-3); color: var(--gold); font-weight: 600; }
.plan-md code { background: var(--bg-3); padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); font-size: 12px; }

.chat {
  display: flex; flex-direction: column;
  height: 580px;
}
.chat-msgs {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.msg.user { align-self: flex-end; background: var(--gold); color: #1a1306; }
.msg.bot { align-self: flex-start; background: var(--bg-3); border: 1px solid var(--line); }
.msg.thinking { color: var(--text-mute); font-style: italic; }
.chat-input {
  display: flex; gap: 8px; margin-top: 10px;
}
.chat-input input {
  flex: 1;
  background: var(--bg-1);
  border: 1px solid var(--line-strong);
  color: var(--text);
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.chat-input input:focus { outline: none; border-color: var(--gold); }

/* ---------- Toast ---------- */
.toast-zone {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 9999;
}
.toast {
  background: var(--bg-3);
  border: 1px solid var(--line-strong);
  border-left: 3px solid var(--gold);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  min-width: 240px;
  box-shadow: var(--shadow-2);
  animation: slideIn .25s ease;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes slideIn { from { transform: translateX(20px); opacity:0; } to { transform:none; opacity:1; } }

/* ---------- Modal ---------- */
.modal-bg {
  position: fixed; inset: 0;
  background: rgba(2, 6, 23, 0.7);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--bg-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  padding: 22px;
  box-shadow: var(--shadow-2);
  animation: fade .2s ease;
}
.modal h3 { margin: 0 0 14px; font-size: 16px; }

/* ---------- Mobile bottom nav ---------- */
.mobile-bar { display: none; }

/* ============= Responsive ============= */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -260px;
    transition: left .22s ease;
    z-index: 200;
    width: 252px;
  }
  .sidebar.open { left: 0; }
  .header { padding: 0 14px; }
  .content { padding: 14px 14px 90px; }
  .menu-toggle { display: inline-flex; }
  .mobile-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg-2);
    border-top: 1px solid var(--line-strong);
    padding: 8px 4px env(safe-area-inset-bottom, 8px);
    justify-content: space-around;
    z-index: 50;
  }
  .mobile-bar button {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-mute);
    font-size: 10px;
    padding: 6px 4px;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
    cursor: pointer;
  }
  .mobile-bar button.active { color: var(--gold); }
  .mobile-bar svg { width: 22px; height: 22px; }
  .kpi-value { font-size: 22px; }
  .kpis { gap: 10px; }
}
@media (min-width: 901px) { .menu-toggle { display: none; } }

.menu-toggle {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--text);
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-mute);
  font-size: 13px;
}
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(251, 191, 36, .3);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Dialog (confirm/prompt/alert) ---------- */
.dlg {
  max-width: 440px;
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2), 0 0 0 1px rgba(251,191,36,.08);
}
.dlg .dlg-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.dlg h3 {
  margin: 0;
  font-size: 15.5px;
  letter-spacing: .2px;
  color: var(--text);
}
.dlg-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
  background: linear-gradient(180deg, rgba(251,191,36,.18), rgba(251,191,36,.04));
  border: 1px solid rgba(251,191,36,.22);
  color: var(--gold);
}
.dlg-icon svg { width: 22px; height: 22px; }
.dlg-icon.danger {
  background: linear-gradient(180deg, rgba(239,68,68,.20), rgba(239,68,68,.05));
  border-color: rgba(239,68,68,.30);
  color: #fca5a5;
}
.dlg-icon.info {
  background: linear-gradient(180deg, rgba(59,130,246,.18), rgba(59,130,246,.05));
  border-color: rgba(59,130,246,.28);
  color: #93c5fd;
}
.dlg-icon.success {
  background: linear-gradient(180deg, rgba(16,185,129,.18), rgba(16,185,129,.05));
  border-color: rgba(16,185,129,.28);
  color: #6ee7b7;
}
#dlgBox.danger #dlgOk {
  background: linear-gradient(180deg, #ef4444, #b91c1c);
  color: #fff;
}
#dlgBox.danger #dlgOk:hover { filter: brightness(1.06); }

/* tasa convertir */
.converter {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  align-items: end;
  gap: 10px;
}
@media (max-width: 700px) { .converter { grid-template-columns: 1fr; } }
.swap-btn {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--gold);
  width: 38px; height: 38px;
  border-radius: 50%;
  cursor: pointer;
}
