/* ════════════════════════════════════════════════════════════
   HUMAN Finanzas — Design System
   Dark mode, modern agency aesthetic
   ════════════════════════════════════════════════════════════ */

/* ── TOKENS ─────────────────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --bg-2:      #161a24;
  --bg-3:      #1e2333;
  --bg-4:      #252b3b;
  --border:    rgba(255,255,255,0.07);
  --border-2:  rgba(255,255,255,0.12);

  --text:      #f0f2f7;
  --text-2:    #a0a8bf;
  --text-3:    #636d8a;

  --accent:    #6c63ff;
  --accent-2:  #8b85ff;
  --accent-bg: rgba(108,99,255,0.12);

  --green:     #22c55e;
  --green-bg:  rgba(34,197,94,0.12);
  --yellow:    #f59e0b;
  --yellow-bg: rgba(245,158,11,0.12);
  --red:       #ef4444;
  --red-bg:    rgba(239,68,68,0.12);

  --sidebar-w: 220px;
  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
}

/* ── RESET ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  font-size: 14px;
  line-height: 1.5;
}

/* ── SIDEBAR ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon { font-size: 24px; }

.logo-text {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

.logo-text small {
  font-size: 11px;
  font-weight: 400;
  color: var(--accent-2);
  display: block;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.2s;
}

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

.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent-2);
}

.nav-icon { font-size: 16px; }

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

/* ── PAGES ───────────────────────────────────────────────────── */
.page { display: none; }
.page.active { display: block; }

/* ── PAGE HEADER ─────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 16px;
}

.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.page-header .sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

/* ── KPI GRID ────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.kpi-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  transition: border-color 0.2s;
}

.kpi-card:hover { border-color: var(--border-2); }

.kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-3);
}

.result-card.positive { border-color: var(--green); }
.result-card.negative { border-color: var(--red); }
.result-card.positive .kpi-value { color: var(--green); }
.result-card.negative .kpi-value { color: var(--red); }

/* ── DASH GRID ───────────────────────────────────────────────── */
.dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

/* ── CARDS ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

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

.card-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ── TABLES ──────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  background: var(--bg-3);
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 14px;
  text-align: left;
}

.data-table td {
  padding: 11px 14px;
  border-top: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--bg-3); }

.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .center { text-align: center; }

.tfoot-total td {
  background: var(--bg-3);
  border-top: 2px solid var(--border-2) !important;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 12px 14px;
}

.empty-td {
  color: var(--text-3);
  text-align: center;
  padding: 24px !important;
  font-style: italic;
}

/* Inline editable cells */
.editable-cell {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  text-align: right;
  width: 100%;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.15s;
}

.editable-cell:focus {
  outline: none;
  background: var(--accent-bg);
}

/* ── BADGES / ALERTS ─────────────────────────────────────────── */
.badge {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 100px;
  background: var(--bg-4);
  color: var(--text-3);
  border: 1px solid var(--border);
}

.alert-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  letter-spacing: 0.03em;
}

.alert-badge.verde   { background: var(--green-bg); color: var(--green); }
.alert-badge.amarillo{ background: var(--yellow-bg); color: var(--yellow); }
.alert-badge.rojo    { background: var(--red-bg); color: var(--red); }

/* ── ALERTAS LIST ────────────────────────────────────────────── */
.alertas-list { display: flex; flex-direction: column; gap: 8px; }

.alerta-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.alerta-item.rojo { background: var(--red-bg); border: 1px solid rgba(239,68,68,0.2); }
.alerta-item.amarillo { background: var(--yellow-bg); border: 1px solid rgba(245,158,11,0.2); }

.alerta-client { font-weight: 600; }
.alerta-detail { color: var(--text-2); font-size: 12px; text-align: right; }

/* ── SCENARIOS CHIPS ─────────────────────────────────────────── */
.scenarios-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
}

.scenario-chip {
  padding: 6px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-2);
  background: var(--bg-3);
  color: var(--text-2);
  transition: all 0.2s;
}

.scenario-chip:hover { background: var(--bg-4); color: var(--text); }
.scenario-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.scenario-chip.baseline::after { content: ' ★'; font-size: 10px; opacity: 0.7; }

/* ── PROYECCIONES LAYOUT ─────────────────────────────────────── */
.proy-layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.proy-sidebar { margin-bottom: 0; }

.months-list { display: flex; flex-direction: column; gap: 4px; }

.month-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.month-item:hover { background: var(--bg-3); color: var(--text); }
.month-item.active { background: var(--accent-bg); color: var(--accent-2); }
.month-item .month-badge { font-size: 11px; color: var(--text-3); }

.proy-editor { display: flex; align-items: center; justify-content: center; }

/* ── SCENARIO EDITOR ─────────────────────────────────────────── */
.scenario-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.scenario-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.scenario-tab {
  padding: 7px 16px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-2);
  background: var(--bg-3);
  color: var(--text-2);
  transition: all 0.2s;
}

.scenario-tab:hover { background: var(--bg-4); color: var(--text); }
.scenario-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.scenario-tab.baseline::after { content: ' ★'; font-size: 11px; }

/* ── TWO COLS ────────────────────────────────────────────────── */
.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.two-cols .card { margin-bottom: 0; }

/* ── CLIENTS LAYOUT ──────────────────────────────────────────── */
.clients-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

.clients-list-card { margin-bottom: 0; }

.clients-master-list { display: flex; flex-direction: column; gap: 4px; }

.client-master-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.client-master-item:hover { background: var(--bg-3); }
.client-master-item.active { background: var(--accent-bg); }

.client-master-name { font-size: 13px; font-weight: 500; color: var(--text); }
.client-master-cat { font-size: 11px; color: var(--text-3); }

.client-detail-panel { }

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { background: var(--accent-2); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-sm { padding: 5px 12px; font-size: 12px; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text-2);
}

.btn-outline:hover { background: var(--bg-4); color: var(--text); }

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.25);
}

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

.btn-icon {
  background: transparent;
  border: none;
  padding: 4px 8px;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 4px;
  font-size: 14px;
  transition: all 0.15s;
}

.btn-icon:hover { color: var(--text); background: var(--bg-4); }
.btn-icon.danger:hover { color: var(--red); }

/* ── INPUTS ──────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
}

.input:focus { border-color: var(--accent); }
.input option { background: var(--bg-3); }

.select-pill {
  padding: 7px 30px 7px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: 100px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23636d8a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.select-pill:focus { border-color: var(--accent); }

/* ── STICKY FOOTER ───────────────────────────────────────────── */
.sticky-footer {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-w);
  right: 0;
  background: var(--bg-2);
  border-top: 1px solid var(--border-2);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 24px;
  z-index: 50;
  backdrop-filter: blur(8px);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.4);
}

.footer-kpi { display: flex; flex-direction: column; gap: 2px; }
.footer-label { font-size: 10px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.06em; }
.footer-val { font-size: 16px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.footer-val.positive { color: var(--green); }
.footer-val.negative { color: var(--red); }
.footer-sep { color: var(--border-2); font-size: 20px; }

/* ── MODALS ──────────────────────────────────────────────────── */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 200;
}

.modal-backdrop.open { display: block; }

.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.95);
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius);
  padding: 0;
  width: 480px;
  max-width: 90vw;
  z-index: 300;
  box-shadow: var(--shadow);
  transition: transform 0.2s, opacity 0.2s;
  opacity: 0;
}

.modal.open {
  display: block;
  transform: translate(-50%, -50%) scale(1);
  opacity: 1;
}

.modal-wide { width: 860px; max-width: 95vw; }

.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: 15px; font-weight: 600; }

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

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 20px 22px;
  max-height: 70vh;
  overflow-y: auto;
}

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

/* ── FORMS ───────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
}

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

/* ── EMPTY STATES ────────────────────────────────────────────── */
.empty-state {
  color: var(--text-3);
  font-size: 13px;
  text-align: center;
  padding: 20px;
}

.empty-state-full {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-3);
}

.empty-icon { font-size: 36px; opacity: 0.5; }
.empty-state-full p { font-size: 14px; }

/* ── COMPARATIVA ─────────────────────────────────────────────── */
.compare-grid {
  display: grid;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.compare-header-row,
.compare-data-row {
  display: grid;
  border-bottom: 1px solid var(--border);
}

.compare-cell {
  padding: 10px 14px;
  font-size: 13px;
  border-right: 1px solid var(--border);
}

.compare-cell:last-child { border-right: none; }
.compare-cell.label { color: var(--text-2); font-weight: 500; }
.compare-cell.header { background: var(--bg-3); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); }
.compare-cell.best { color: var(--green); font-weight: 600; }
.compare-cell.worst { color: var(--red); }
.compare-cell.delta-pos { color: var(--green); font-size: 12px; }
.compare-cell.delta-neg { color: var(--red); font-size: 12px; }

.compare-summary {
  padding: 14px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  font-size: 13px;
  font-weight: 600;
}

.compare-summary.positive { background: var(--green-bg); color: var(--green); }
.compare-summary.negative { background: var(--red-bg); color: var(--red); }

/* ── TOAST ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 100px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  z-index: 500;
  transform: translateY(20px);
  opacity: 0;
  transition: all 0.3s;
  box-shadow: var(--shadow);
  pointer-events: none;
}

.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }

/* ── CLIENT DETAIL ───────────────────────────────────────────── */
.client-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.client-detail-charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.cliente-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  background: var(--green-bg);
  color: var(--green);
}

/* ── SCROLLBAR ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-2); }

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .proy-layout { grid-template-columns: 1fr; }
  .clients-layout { grid-template-columns: 1fr; }
  .two-cols { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .main-content { padding: 16px 16px 120px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .sticky-footer { left: 0; padding: 12px 16px; gap: 12px; }
}

/* ── ANIMATIONS ──────────────────────────────────────────────── */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.page.active { animation: fadeIn 0.25s ease; }
.card { animation: fadeIn 0.3s ease; }
