/* ═══════════════════════════════════════════════════
   FINANZAS v2 · Design System
   Refined Editorial Dark — uniform, consistent
═══════════════════════════════════════════════════ */

:root {
  --bg:         #0D0E14;
  --surface:    #13151F;
  --surface2:   #1A1D2A;
  --surface3:   #212438;
  --border:     #242738;
  --border2:    #2E3150;
  --text:       #E8EAF2;
  --text-2:     #8B91AE;
  --text-3:     #52587A;
  --gold:       #C8A84A;
  --gold-light: #E8C870;
  --gold-dim:   rgba(200,168,74,0.12);
  --accent:     #4E7EE8;
  --accent-dim: rgba(78,126,232,0.12);
  --green:      #2DBD71;
  --green-dim:  rgba(45,189,113,0.12);
  --red:        #E04C3A;
  --red-dim:    rgba(224,76,58,0.12);
  --warn:       #F0A020;
  --warn-dim:   rgba(240,160,32,0.12);
  --sidebar-w:  224px;
  --radius:     10px;
  --radius-sm:  6px;
  --font-d:     'DM Serif Display', Georgia, serif;
  --font-b:     'DM Sans', system-ui, sans-serif;
  --font-m:     'DM Mono', 'Courier New', monospace;
  --shadow:     0 4px 24px rgba(0,0,0,0.35);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-b);
  display: flex;
  min-height: 100vh;
  line-height: 1.5;
}

/* ── SCROLLBAR ────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }

/* ── SIDEBAR ──────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 26px 22px;
  border-bottom: 1px solid var(--border);
}

.logo-mark { color: var(--gold); font-size: 16px; }
.logo-text { font-family: var(--font-d); font-size: 17px; letter-spacing: 0.02em; }

.nav-links {
  list-style: none;
  padding: 16px 0;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 22px;
  color: var(--text-3);
  text-decoration: none;
  font-size: 0.855rem;
  font-weight: 400;
  transition: all 0.15s ease;
  border-left: 2px solid transparent;
  letter-spacing: 0.01em;
}

.nav-item:hover { color: var(--text-2); background: var(--surface2); border-left-color: var(--border2); }
.nav-item.active { color: var(--gold); border-left-color: var(--gold); background: var(--gold-dim); }
.nav-icon { font-size: 0.85rem; width: 16px; text-align: center; flex-shrink: 0; }

.sidebar-bottom {
  padding: 18px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn-report {
  background: var(--gold);
  color: #0D0E14;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-family: var(--font-b);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s;
  letter-spacing: 0.01em;
}

.btn-report:hover { background: var(--gold-light); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(200,168,74,0.3); }
.btn-arrow { font-size: 0.95rem; }

.last-update {
  font-size: 0.7rem;
  color: var(--text-3);
  text-align: center;
  font-family: var(--font-m);
}

/* ── MAIN ─────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px 38px;
  min-height: 100vh;
  max-width: calc(100vw - var(--sidebar-w));
}

/* ── PAGE HEADER ──────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 26px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border);
}

.page-title { font-family: var(--font-d); font-size: 1.95rem; font-weight: 400; line-height: 1.1; }
.page-sub { font-size: 0.75rem; color: var(--text-3); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.06em; }
.header-date { font-family: var(--font-m); font-size: 0.75rem; color: var(--text-3); padding-top: 6px; }

/* ── SECTIONS ─────────────────────────────────── */
.section { display: none; }
.section.active { display: block; animation: fadeUp 0.22s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── SECTION TOOLBAR ──────────────────────────── */
.section-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 10px;
}

.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar-hint { font-size: 0.75rem; color: var(--text-3); font-style: italic; }

/* ── KPI GRID ─────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: 2fr 1fr 1.2fr 1fr; gap: 14px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
}

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1.5px;
  background: var(--border2);
}

.kpi-main::after { background: linear-gradient(90deg, var(--gold) 0%, transparent 60%); }

.kpi-label { font-size: 0.69rem; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-3); margin-bottom: 9px; }
.kpi-value { font-family: var(--font-d); font-size: 1.65rem; line-height: 1; }
.kpi-sub { font-size: 0.72rem; color: var(--text-3); margin-top: 6px; font-family: var(--font-m); }
.kpi-warn-active { color: var(--warn) !important; }

.kpi-progress-wrap { margin-top: 8px; display: flex; flex-direction: column; gap: 5px; }
.kpi-progress-track { height: 3px; background: var(--surface3); border-radius: 99px; overflow: hidden; }
.kpi-progress-fill { height: 100%; background: var(--gold); border-radius: 99px; transition: width 0.8s ease; }

/* ── CARDS ────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 22px;
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: 0.87rem; font-weight: 500; color: var(--text); letter-spacing: 0.01em; }

.card-badge {
  font-size: 0.68rem;
  background: var(--gold-dim);
  color: var(--gold);
  border: 1px solid rgba(200,168,74,0.22);
  border-radius: 99px;
  padding: 2px 9px;
  font-family: var(--font-m);
  white-space: nowrap;
}

.card-badge-green { background: var(--green-dim); color: var(--green); border-color: rgba(45,189,113,0.22); }

/* ── GRID / SPACING ───────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mt-lg { margin-top: 18px; }
.mt-md { margin-top: 12px; }
.empty-state { padding: 28px; text-align: center; color: var(--text-3); font-size: 0.8rem; }

/* ── ALLOCATION BARS ──────────────────────────── */
.allocation-list { padding: 18px 22px; display: flex; flex-direction: column; gap: 11px; }

.alloc-row { display: flex; flex-direction: column; gap: 4px; }
.alloc-meta { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.alloc-name { font-size: 0.8rem; color: var(--text-2); flex: 1; }
.alloc-amt  { font-family: var(--font-m); font-size: 0.79rem; color: var(--text); }
.alloc-pct  { font-family: var(--font-m); font-size: 0.72rem; color: var(--text-3); min-width: 38px; text-align: right; }
.alloc-track { height: 3px; background: var(--surface3); border-radius: 99px; overflow: hidden; }
.alloc-fill { height: 100%; border-radius: 99px; transition: width 0.9s cubic-bezier(0.4,0,0.2,1); }

/* ── CHART ────────────────────────────────────── */
.chart-wrap { padding: 18px 22px; position: relative; height: 220px; }
.chart-tall  { height: 280px; }

/* ── ALERTS ───────────────────────────────────── */
.alerts-list { padding: 14px 22px; display: flex; flex-direction: column; gap: 7px; }

.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.8rem;
  padding: 10px 13px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
}

.alert-warn { background: var(--warn-dim); border: 1px solid rgba(240,160,32,0.2); color: var(--warn); }
.alert-info { background: var(--accent-dim); border: 1px solid rgba(78,126,232,0.2); color: var(--accent); }
.alert-ok   { background: var(--green-dim); border: 1px solid rgba(45,189,113,0.2); color: var(--green); }

/* ── NÚCLEO INVERSOR ──────────────────────────── */
.nucleo-grid { display: grid; grid-template-columns: repeat(4,1fr); }

.nucleo-item {
  padding: 18px 22px;
  border-right: 1px solid var(--border);
}

.nucleo-item:last-child { border-right: none; }
.nucleo-name   { font-size: 0.77rem; color: var(--text-2); margin-bottom: 5px; }
.nucleo-amount { font-family: var(--font-m); font-size: 1.05rem; color: var(--text); font-weight: 500; margin-bottom: 7px; }

.nucleo-tag {
  font-size: 0.67rem; padding: 2px 8px;
  border-radius: 99px; display: inline-block; font-family: var(--font-m);
}

.tag-auto { background: var(--gold-dim); color: var(--gold); }
.tag-flex { background: var(--accent-dim); color: var(--accent); }

/* ── POSICIONES ───────────────────────────────── */
.pos-block { margin-bottom: 16px; }

.pos-block-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 20px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
}

.pos-block-title { font-size: 0.8rem; font-weight: 600; color: var(--text); }
.pos-block-total { margin-left: auto; font-family: var(--font-m); font-size: 0.82rem; color: var(--gold); }

.pos-table-wrap { border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius); overflow: hidden; }

.pos-subtotal td { background: var(--surface2) !important; font-weight: 600 !important; color: var(--text) !important; font-size: 0.78rem !important; }
.pos-total td    { background: var(--bg) !important; font-weight: 700 !important; font-size: 0.88rem !important; color: var(--gold) !important; }

.editable-val { background: rgba(78,126,232,0.06) !important; }
.editable-val input {
  background: transparent; border: none;
  border-bottom: 1px solid var(--accent);
  color: var(--accent); font-family: var(--font-m); font-size: 0.82rem;
  width: 88px; text-align: right; outline: none; padding: 2px 0;
}

/* ── DATA TABLE ───────────────────────────────── */
.table-scroll { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }

.data-table th {
  text-align: left; padding: 10px 20px;
  font-size: 0.67rem; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface); font-weight: 500;
  white-space: nowrap;
}

.data-table td {
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  color: var(--text-2); vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface2); }
.empty-td { text-align: center; color: var(--text-3); padding: 28px !important; }

.td-mono  { font-family: var(--font-m); }
.td-bold  { font-weight: 600; color: var(--text) !important; }
.td-green { color: var(--green) !important; font-family: var(--font-m); }
.td-red   { color: var(--red)   !important; font-family: var(--font-m); }
.td-sub   { color: var(--text-3); font-size: 0.72rem; }
.td-del   { text-decoration: line-through; opacity: 0.45; }

.badge {
  font-size: 0.67rem; padding: 2px 7px; border-radius: 99px;
  font-family: var(--font-m); white-space: nowrap;
}
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-red   { background: var(--red-dim);   color: var(--red); }
.badge-gold  { background: var(--gold-dim);  color: var(--gold); }
.badge-blue  { background: var(--accent-dim);color: var(--accent); }

/* ── HISTORIAL ────────────────────────────────── */
.hist-delete { background: none; border: none; color: var(--text-3); cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 0.82rem; transition: color 0.15s; }
.hist-delete:hover { color: var(--red); }

/* ── IMPORT ───────────────────────────────────── */
.import-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }

.import-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex; flex-direction: column; gap: 14px;
}

.import-top { display: flex; gap: 14px; align-items: flex-start; }
.import-icon { font-size: 1.8rem; line-height: 1; flex-shrink: 0; }
.import-card h3 { font-size: 0.87rem; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.import-desc { font-size: 0.75rem; color: var(--text-3); line-height: 1.5; }
.import-desc code { display: block; margin-top: 3px; font-family: var(--font-m); font-size: 0.68rem; color: var(--text-3); }

.drop-zone {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 5px;
  border: 1.5px dashed var(--border2);
  border-radius: var(--radius-sm);
  padding: 18px 14px; cursor: pointer;
  transition: all 0.17s; text-align: center;
}

.drop-zone:hover, .drop-zone.drag-over { border-color: var(--gold); background: var(--gold-dim); }
.dz-icon { font-size: 1.3rem; color: var(--text-3); }
.dz-text { font-size: 0.78rem; color: var(--text-2); }
.dz-text em { color: var(--text-3); font-style: normal; font-family: var(--font-m); font-size: 0.7rem; }

.import-status { font-size: 0.73rem; min-height: 16px; font-family: var(--font-m); }
.import-status.ok  { color: var(--green); }
.import-status.err { color: var(--red); }

/* ── FILTER SELECT ────────────────────────────── */
.filter-select {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text-2); font-family: var(--font-b); font-size: 0.77rem;
  padding: 5px 10px; border-radius: var(--radius-sm); cursor: pointer;
  outline: none; transition: border-color 0.15s;
}
.filter-select:focus { border-color: var(--gold); color: var(--text); }

/* ── HIPOTECA ─────────────────────────────────── */
.hipoteca-detail { padding: 18px 22px; display: flex; flex-direction: column; gap: 9px; }

.hip-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.8rem; color: var(--text-2);
  padding-bottom: 9px; border-bottom: 1px solid var(--border);
}
.hip-row:last-child { border-bottom: none; padding-bottom: 0; }

.hip-total { color: var(--text); }
.hip-total strong { color: var(--gold); font-family: var(--font-m); font-size: 0.95rem; }
.hip-row strong { font-family: var(--font-m); color: var(--text); }

.acumulacion-grid { padding: 22px; display: flex; flex-direction: column; gap: 22px; }

.acum-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.acum-label  { font-size: 0.8rem; color: var(--text-2); }
.acum-value  { font-family: var(--font-m); font-size: 0.85rem; color: var(--text); }
.acum-bar-wrap { height: 5px; background: var(--surface3); border-radius: 99px; overflow: hidden; margin-bottom: 6px; }
.acum-bar { height: 100%; border-radius: 99px; transition: width 1s cubic-bezier(0.4,0,0.2,1); }
.acum-bar-gold { background: var(--gold); }
.acum-bar-blue { background: var(--accent); }
.acum-foot { font-size: 0.73rem; color: var(--text-3); }
.acum-foot strong { color: var(--text-2); }

/* ── BUTTONS ──────────────────────────────────── */
.btn-primary {
  background: var(--gold); color: #0D0E14;
  border: none; border-radius: var(--radius-sm);
  padding: 8px 16px; font-family: var(--font-b); font-size: 0.8rem; font-weight: 600;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-primary:hover { background: var(--gold-light); }

.btn-secondary {
  background: var(--surface2); color: var(--text-2);
  border: 1px solid var(--border2); border-radius: var(--radius-sm);
  padding: 7px 13px; font-family: var(--font-b); font-size: 0.8rem;
  cursor: pointer; transition: all 0.15s; white-space: nowrap;
}
.btn-secondary:hover { color: var(--text); border-color: var(--border); }

.btn-ghost {
  background: none; color: var(--text-3);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 13px; font-family: var(--font-b); font-size: 0.8rem;
  cursor: pointer; transition: all 0.15s;
}
.btn-ghost:hover { color: var(--text-2); }

/* ── MODAL ────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.72);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(5px);
}

.modal {
  background: var(--surface); border: 1px solid var(--border2);
  border-radius: var(--radius); width: 480px; max-width: 95vw;
  box-shadow: 0 28px 64px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 0.92rem; font-weight: 600; }

.modal-close {
  background: none; border: none; color: var(--text-3);
  cursor: pointer; font-size: 1rem; padding: 3px 6px; border-radius: 4px; transition: color 0.15s;
}
.modal-close:hover { color: var(--text); }

.modal-body { padding: 22px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-full  { grid-column: 1/-1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }

.form-group input, .form-group textarea {
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: var(--radius-sm); color: var(--text); font-family: var(--font-b);
  font-size: 0.83rem; padding: 8px 11px; outline: none; transition: border-color 0.15s; resize: none;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--gold); }

.modal-footer {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 14px 22px; border-top: 1px solid var(--border);
}

/* ── TOAST ────────────────────────────────────── */
.toast {
  position: fixed; bottom: 26px; right: 26px;
  background: var(--surface); border: 1px solid var(--border2);
  color: var(--text); font-size: 0.8rem;
  padding: 11px 18px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px);
  transition: all 0.22s ease; pointer-events: none;
  z-index: 9999; max-width: 300px;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok  { border-color: var(--green); }
.toast.err { border-color: var(--red); }
