/* ============================================================
   SIMULADOR DE INVERSIONES — Rodrigo Estrella
   Vanilla CSS · sobrio y profesional · claro por defecto
   ============================================================ */

:root {
  color-scheme: light;
  --bg:        #f5f6f8;
  --surface:   #ffffff;
  --surface-2: #f1f3f7;
  --border:    #e3e7ee;
  --accent:    #1e40af;
  --accent-soft: #eef2fc;
  --green:     #15803d;
  --green-soft:#f0f7f1;
  --red:       #b91c1c;
  --red-soft:  #fbf1f1;
  --text-hi:   #16202e;
  --text-mid:  #51607a;
  --text-lo:   #5d6c86;
  --font-body: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'Space Mono', monospace;
  --radius:    10px;
  --shadow:    0 1px 2px rgba(22,32,46,0.05), 0 4px 14px rgba(22,32,46,0.05);
  --tr: 0.25s ease;
}
html.dark {
  color-scheme: dark;
  --bg:        #12161d;
  --surface:   #1a202a;
  --surface-2: #222a36;
  --border:    #2c3543;
  --accent:    #8ab0f5;
  --accent-soft: #1f2836;
  --green:     #4ade80;
  --green-soft:#1a2a22;
  --red:       #f08c8c;
  --red-soft:  #2c1f21;
  --text-hi:   #e8ecf2;
  --text-mid:  #a3aebf;
  --text-lo:   #7d8a9d;
  --shadow:    0 1px 2px rgba(0,0,0,0.2), 0 4px 14px rgba(0,0,0,0.18);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-hi);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

/* ─── Topbar ─────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.8rem 1.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.55rem; }
.brand-mark { color: var(--accent); font-size: 0.7rem; }
.brand-name {
  font-weight: 600;
  font-size: 1.02rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.brand-name em { font-style: normal; color: var(--accent); }

.tabs { display: flex; gap: 0.3rem; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.tab {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-mid);
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 0.45rem 1rem;
  cursor: pointer;
  transition: all var(--tr);
}
.tab:hover { color: var(--text-hi); }
.tab.active {
  color: var(--accent);
  background: var(--surface);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.topbar-tools { display: flex; align-items: center; gap: 0.5rem; }
.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-mid);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  transition: all var(--tr);
}
.tool-btn:hover { color: var(--accent); border-color: var(--accent); }
.theme-toggle .icon-moon { display: none; }
html.dark .theme-toggle .icon-moon { display: inline; }
html.dark .theme-toggle .icon-sun { display: none; }

/* ─── Franja de mercado ──────────────────────────────────── */
.market-strip {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  overflow-x: auto;
}
.market-inner {
  display: flex;
  align-items: center;
  gap: 1.6rem;
  max-width: 1380px;
  margin: 0 auto;
  padding: 0.5rem 1.75rem;
  white-space: nowrap;
}
.mk { display: inline-flex; align-items: baseline; gap: 0.45rem; }
.mk-label { color: var(--text-lo); letter-spacing: 0.06em; text-transform: uppercase; font-size: 0.6rem; }
.mk b { color: var(--text-hi); font-weight: 700; }
.mk-src { margin-left: auto; color: var(--text-lo); font-size: 0.6rem; }

/* ─── Layout ─────────────────────────────────────────────── */
.panel { display: none; }
.panel.active { display: block; }
.layout {
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 1.1rem;
  max-width: 1380px;
  margin: 0 auto;
  padding: 1.25rem 1.75rem 3rem;
}
.sidebar { display: flex; flex-direction: column; gap: 1.1rem; }
.content { display: flex; flex-direction: column; gap: 1.1rem; min-width: 0; }

/* ─── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.3rem;
  box-shadow: var(--shadow);
}
.card-title {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-lo);
  margin: 0 0 0.85rem;
}
.hint { font-size: 0.77rem; color: var(--text-lo); line-height: 1.55; margin: 0.7rem 0 0; }

/* ─── Controles ──────────────────────────────────────────── */
.rate-control { display: flex; flex-direction: column; gap: 0.7rem; }
input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }
.rate-value {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
  font-weight: 600;
  font-size: 1.55rem;
  color: var(--text-hi);
}
.rate-value.big { font-size: 1.7rem; }
.rate-value input {
  width: 110px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1.55rem;
  color: var(--text-hi);
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--border);
  padding: 0 0 2px;
  transition: border-color var(--tr);
}
.rate-value.big input { font-size: 1.7rem; width: 150px; }
.rate-value input:focus { border-color: var(--accent); }
.rate-value span { color: var(--text-lo); font-size: 1rem; }

.rate-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.7rem; }
.rate-chips button {
  font-family: var(--font-mono);
  font-size: 0.63rem;
  color: var(--text-mid);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  transition: all var(--tr);
}
.rate-chips button:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

.scenario-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}
.scenario-row label { font-size: 0.85rem; color: var(--text-mid); }
.scenario-input { display: inline-flex; align-items: center; gap: 0.25rem; color: var(--text-mid); }
.scenario-input input {
  width: 70px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-hi);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.35rem 0.5rem;
}
.scenario-compare { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.45rem; }
.scenario-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.5rem 0.75rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.scenario-chip .s-name { color: var(--text-mid); }
.scenario-chip .s-van { font-weight: 700; }
.scenario-chip.pos .s-van { color: var(--green); }
.scenario-chip.neg .s-van { color: var(--red); }
.scenario-chip.base { border-color: var(--accent); }

.data-actions { display: flex; flex-direction: column; gap: 0.45rem; }
.btn-soft {
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 500;
  text-align: left;
  color: var(--text-hi);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  transition: all var(--tr);
}
.btn-soft:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-soft.danger:hover { border-color: var(--red); color: var(--red); background: var(--red-soft); }
.btn-primary {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1.25rem;
  cursor: pointer;
  transition: all var(--tr);
}
html.dark .btn-primary { color: #12161d; }
.btn-primary:hover { opacity: 0.92; }

/* ─── KPIs ───────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  transition: border-color var(--tr);
}
.kpi-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-lo);
}
.kpi-value {
  display: block;
  font-weight: 600;
  font-size: clamp(1.25rem, 2.2vw, 1.7rem);
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin: 0.4rem 0 0.2rem;
  color: var(--text-hi);
  overflow-wrap: anywhere;
}
.kpi-sub { font-size: 0.7rem; color: var(--text-lo); }
.kpi.pos .kpi-value { color: var(--green); }
.kpi.neg .kpi-value { color: var(--red); }
.info-dot {
  width: 16px; height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  font-family: var(--font-mono);
  color: var(--text-lo);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--tr);
}
.info-dot:hover { color: var(--accent); border-color: var(--accent); }

/* ─── Veredicto ──────────────────────────────────────────── */
.verdict {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.05rem 1.3rem;
  box-shadow: var(--shadow);
  transition: all var(--tr);
}
.verdict.pos { border-left-color: var(--green); background: var(--green-soft); }
.verdict.neg { border-left-color: var(--red); background: var(--red-soft); }
.verdict-badge {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
}
.verdict.pos .verdict-badge { color: var(--green); border-color: var(--green); }
.verdict.neg .verdict-badge { color: var(--red); border-color: var(--red); }
.verdict-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.2rem;
  color: var(--text-hi);
}
.verdict.pos .verdict-title { color: var(--green); }
.verdict.neg .verdict-title { color: var(--red); }
.verdict p { margin: 0; font-size: 0.9rem; line-height: 1.6; color: var(--text-mid); }
.verdict p strong { color: var(--text-hi); }

/* ─── Aviso de signos ────────────────────────────────────── */
.sign-hint {
  font-family: var(--font-mono);
  font-size: 0.67rem;
  color: var(--text-lo);
  margin: 0 0 0.6rem;
}
.sign-hint .pos-txt { color: var(--green); }
.sign-hint .neg-txt { color: var(--red); }
.sign-hint code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.05rem 0.35rem;
  color: var(--red);
}

/* ─── Tabla ──────────────────────────────────────────────── */
.table-card { padding-bottom: 0.9rem; }
.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.table-head .card-title { margin: 0; }
.table-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.table-actions .btn-soft { padding: 0.35rem 0.65rem; font-size: 0.74rem; }
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.84rem; }
th {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-lo);
  text-align: left;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th.num { text-align: right; }
td { padding: 0.12rem 0.2rem; border-bottom: 1px solid var(--border); }
td input, td select {
  width: 100%;
  min-width: 90px;
  font-family: var(--font-body);
  font-size: 0.84rem;
  color: var(--text-hi);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.42rem 0.5rem;
  transition: all 0.12s ease;
}
td select { cursor: pointer; }
td select option { background: var(--surface); color: var(--text-hi); }
td input[type=number] { text-align: right; font-family: var(--font-mono); font-size: 0.78rem; }
td input:hover, td select:hover { background: var(--surface-2); }
td input:focus, td select:focus { background: var(--surface-2); border-color: var(--accent); outline: none; }
td input.negative { color: var(--red); }
td.cell-concept input { min-width: 150px; font-weight: 500; }
td.subtotal {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--text-mid);
  padding-right: 0.6rem;
  white-space: nowrap;
}
.row-del {
  width: 26px; height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-lo);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.12s ease;
}
.row-del:hover { color: var(--red); background: var(--red-soft); }
tfoot td {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-hi);
  text-align: right;
  padding: 0.55rem 0.6rem;
  border-bottom: none;
  border-top: 2px solid var(--border);
  white-space: nowrap;
}
tfoot td:first-child { text-align: left; letter-spacing: 0.1em; text-transform: uppercase; font-size: 0.62rem; color: var(--text-lo); }
tfoot td.pos { color: var(--green); }
tfoot td.neg { color: var(--red); }

/* ─── Charts ─────────────────────────────────────────────── */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.chart-card.wide { grid-column: 1 / -1; }
.chart { width: 100%; min-height: 260px; }
.chart.tall { min-height: 330px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font-mono); font-size: 10px; fill: var(--text-lo); }
.chart .axis-line { stroke: var(--border); stroke-width: 1; }
.chart .grid-line { stroke: var(--border); stroke-width: 0.6; stroke-dasharray: 3 4; }
.chart-legend {
  display: flex;
  gap: 1.1rem;
  flex-wrap: wrap;
  margin-top: 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  color: var(--text-mid);
}
.chart-legend i {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 3px;
  margin-right: 5px;
  vertical-align: -1px;
}

/* ─── Modales ────────────────────────────────────────────── */
dialog {
  background: var(--surface);
  color: var(--text-hi);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem 1.5rem;
  max-width: 540px;
  width: calc(100vw - 2.5rem);
  box-shadow: 0 24px 60px rgba(22,32,46,0.25);
}
dialog::backdrop { background: rgba(22,32,46,0.45); }
dialog textarea {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-hi);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  resize: vertical;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1rem; }
.info-body { font-size: 0.92rem; line-height: 1.7; color: var(--text-mid); margin: 0; }
.info-body strong { color: var(--text-hi); }

/* ─── Tour guiado ────────────────────────────────────────── */
#tour { position: fixed; inset: 0; z-index: 500; }
#tour-hole {
  position: absolute;
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(22, 28, 38, 0.62);
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  transition: all 0.35s ease;
  pointer-events: none;
}
html.dark #tour-hole { box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.72); }
#tour-card {
  position: absolute;
  width: min(360px, calc(100vw - 2rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.05rem 1.2rem;
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
  transition: all 0.35s ease;
}
#tour-step-count {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  letter-spacing: 0.18em;
  color: var(--accent);
}
#tour-card h3 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0.3rem 0 0.4rem;
  color: var(--text-hi);
}
#tour-card p { margin: 0; font-size: 0.85rem; line-height: 1.6; color: var(--text-mid); }
#tour-card p b { color: var(--text-hi); }
.tour-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.95rem;
}
.tour-nav { display: flex; gap: 0.5rem; }
#tour-prev { padding: 0.5rem 0.75rem; }
@media (prefers-reduced-motion: reduce) {
  #tour-hole, #tour-card { transition: none; }
}

/* ─── Toast ──────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text-hi);
  color: var(--bg);
  border-radius: 100px;
  padding: 0.6rem 1.3rem;
  font-size: 0.8rem;
  font-weight: 500;
  z-index: 300;
  opacity: 0;
  transition: all 0.3s ease;
  pointer-events: none;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ─── Footer ─────────────────────────────────────────────── */
.foot {
  border-top: 1px solid var(--border);
  padding: 1.4rem 1.75rem 1.8rem;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-lo);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 1020px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .sidebar .card { flex: 1 1 260px; }
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 0.7rem 1rem; }
  .layout { padding: 1rem 1rem 2.5rem; }
  .tool-btn span { display: none; }
  .brand-name { font-size: 0.92rem; }
}
