/* =========================================================
   Inversiones IA - Sistema visual compartido
   ========================================================= */

:root {
  --bg: #f5f7fa;
  --bg-alt: #ffffff;
  --bg-raised: #ffffff;
  --text: #16202a;
  --text-muted: #56636f;
  --border: #e1e6ec;
  --primary: #145a32;
  --primary-strong: #0d3d22;
  --primary-soft: #e5f3ea;
  --accent: #1a6dd8;
  --accent-soft: #e5f0fd;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --success: #1c7c3f;
  --warning: #a8630a;
  --warning-soft: #fdf0dc;
  --shadow: 0 1px 3px rgba(20, 30, 40, .08), 0 1px 2px rgba(20, 30, 40, .06);
  --shadow-lg: 0 8px 24px rgba(20, 30, 40, .12);
  --radius: 12px;
  --radius-sm: 8px;
  --maxw: 1180px;
  --font: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

:root[data-theme="dark"] {
  --bg: #0f1720;
  --bg-alt: #16212c;
  --bg-raised: #1b2732;
  --text: #e8edf2;
  --text-muted: #96a5b3;
  --border: #2a3a48;
  --primary: #3fb96c;
  --primary-strong: #63d68c;
  --primary-soft: #123322;
  --accent: #5b9bf5;
  --accent-soft: #142a42;
  --danger: #f0665d;
  --danger-soft: #3a1b1a;
  --success: #46c274;
  --warning: #e0a458;
  --warning-soft: #3a2c14;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720;
    --bg-alt: #16212c;
    --bg-raised: #1b2732;
    --text: #e8edf2;
    --text-muted: #96a5b3;
    --border: #2a3a48;
    --primary: #3fb96c;
    --primary-strong: #63d68c;
    --primary-soft: #123322;
    --accent: #5b9bf5;
    --accent-soft: #142a42;
    --danger: #f0665d;
    --danger-soft: #3a1b1a;
    --success: #46c274;
    --warning: #e0a458;
    --warning-soft: #3a2c14;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}

.nav {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 20px;
  max-width: var(--maxw);
  margin: 0 auto;
  flex-wrap: wrap;
}

.brand {
  font-weight: 800;
  font-size: 1.15rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand .dot { color: var(--primary); }

.nav-links {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-left: auto;
  align-items: center;
}

.nav-links a {
  color: var(--text-muted);
  font-weight: 600;
  font-size: .92rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}
.nav-links a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.nav-links a.active { color: var(--primary); background: var(--primary-soft); }

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.theme-toggle:hover { border-color: var(--primary); }

/* ---------- Layout blocks ---------- */
main { display: block; }

.hero {
  padding: 56px 0 40px;
}

.hero h1 {
  font-size: clamp(1.9rem, 4vw, 2.8rem);
  margin: 0 0 14px;
  letter-spacing: -.02em;
}

.hero p.lead {
  font-size: 1.15rem;
  color: var(--text-muted);
  max-width: 62ch;
}

.section {
  padding: 40px 0;
}

.section-title {
  font-size: 1.5rem;
  margin: 0 0 6px;
}

.section-sub {
  color: var(--text-muted);
  margin: 0 0 28px;
}

/* ---------- Cards / grid ---------- */
.grid {
  display: grid;
  gap: 18px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card h3 { margin: 0; font-size: 1.1rem; }
.card p { margin: 0; color: var(--text-muted); font-size: .95rem; }

.level-card {
  position: relative;
  overflow: hidden;
}

.level-card .level-tag {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 4px 10px;
  border-radius: 999px;
  width: fit-content;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  margin-top: 4px;
}
.progress-bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 999px;
  transition: width .4s ease;
}

.progress-label {
  font-size: .82rem;
  color: var(--text-muted);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: .95rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: transform .05s ease, box-shadow .15s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-strong); text-decoration: none; }

.btn-outline { background: transparent; border-color: var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); text-decoration: none; }

.btn-sm { padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Lesson pages ---------- */
.lesson-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 32px;
  align-items: start;
  padding: 32px 0 80px;
}

.lesson-toc {
  position: sticky;
  top: 84px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-size: .88rem;
}
.lesson-toc h4 { margin: 0 0 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.lesson-toc ol { margin: 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
.lesson-toc li a {
  display: flex;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  color: var(--text-muted);
  font-weight: 600;
}
.lesson-toc li a:hover { background: var(--primary-soft); color: var(--primary); text-decoration: none; }
.lesson-toc li a.done::before { content: "✓ "; color: var(--success); }
.lesson-toc .toc-back { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }

.lesson-content { min-width: 0; }

.lesson-content h1 { font-size: 2rem; margin: 0 0 6px; }
.lesson-content .lesson-meta { color: var(--text-muted); margin: 0 0 32px; font-size: .95rem; }
.lesson-content h2 { font-size: 1.4rem; margin: 40px 0 14px; padding-top: 8px; border-top: 1px solid var(--border); }
.lesson-content h2:first-of-type { border-top: none; margin-top: 0; }
.lesson-content h3 { font-size: 1.12rem; margin: 24px 0 8px; }
.lesson-content p { margin: 0 0 14px; }
.lesson-content ul, .lesson-content ol { margin: 0 0 16px; padding-left: 22px; }
.lesson-content li { margin-bottom: 6px; }
.lesson-content strong { color: var(--text); }

.callout {
  border-radius: var(--radius);
  padding: 16px 18px;
  margin: 20px 0;
  border: 1px solid var(--border);
  background: var(--bg-raised);
}
.callout-title {
  font-weight: 700;
  font-size: .85rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.callout.def { border-left: 4px solid var(--accent); background: var(--accent-soft); }
.callout.def .callout-title { color: var(--accent); }
.callout.tip { border-left: 4px solid var(--primary); background: var(--primary-soft); }
.callout.tip .callout-title { color: var(--primary); }
.callout.warn { border-left: 4px solid var(--warning); background: var(--warning-soft); }
.callout.warn .callout-title { color: var(--warning); }
.callout.example { border-left: 4px solid var(--text-muted); }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0 24px;
  font-size: .92rem;
}
table.data-table th, table.data-table td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
table.data-table th { background: var(--bg-alt); font-weight: 700; }

.term { border-bottom: 1px dotted var(--text-muted); cursor: help; }

/* ---------- Quiz ---------- */
.quiz-box {
  margin-top: 48px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.quiz-box h2 { margin-top: 0 !important; border-top: none !important; }
.quiz-q { margin-bottom: 22px; }
.quiz-q p.q-text { font-weight: 700; margin-bottom: 10px; }
.quiz-options { display: flex; flex-direction: column; gap: 8px; }
.quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  background: var(--bg-alt);
}
.quiz-option:hover { border-color: var(--accent); }
.quiz-option.correct { border-color: var(--success); background: var(--primary-soft); }
.quiz-option.incorrect { border-color: var(--danger); background: var(--danger-soft); }
.quiz-feedback { margin-top: 14px; font-weight: 700; }
.quiz-feedback.ok { color: var(--success); }
.quiz-feedback.ko { color: var(--danger); }
.lesson-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 40px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

/* ---------- Forms ---------- */
input[type="text"], input[type="number"], input[type="password"], input[type="search"], select {
  font-family: inherit;
  font-size: .95rem;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-alt);
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { font-size: .85rem; font-weight: 700; color: var(--text-muted); display: block; margin-bottom: 4px; }
.field { margin-bottom: 16px; }

/* ---------- Practice zone ---------- */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-tile {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.stat-tile .label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.stat-tile .value { font-size: 1.5rem; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.value.pos { color: var(--success); }
.value.neg { color: var(--danger); }

.practice-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 880px) {
  .practice-layout, .lesson-shell { grid-template-columns: 1fr; }
  .lesson-toc { position: static; }
}

.watchlist { max-height: 640px; overflow-y: auto; }
.watchlist-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  gap: 8px;
}
.watchlist-item:hover { background: var(--bg-alt); }
.watchlist-item.active { background: var(--primary-soft); }
.watchlist-item .wl-name { font-weight: 700; font-size: .9rem; }
.watchlist-item .wl-ticker { font-size: .76rem; color: var(--text-muted); }
.watchlist-item .wl-price { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.watchlist-item .wl-change { text-align: right; font-size: .78rem; font-variant-numeric: tabular-nums; }

.chart-box { height: 380px; background: var(--bg-raised); border: 1px solid var(--border); border-radius: var(--radius); }

.badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
}
.badge.buy { background: var(--primary-soft); color: var(--primary); }
.badge.sell { background: var(--danger-soft); color: var(--danger); }

.alert {
  border-radius: var(--radius);
  padding: 14px 16px;
  border: 1px solid var(--border);
  margin-bottom: 18px;
  font-size: .92rem;
}
.alert.warn { background: var(--warning-soft); border-color: var(--warning); }
.alert.info { background: var(--accent-soft); border-color: var(--accent); }

footer.site-footer {
  border-top: 1px solid var(--border);
  padding: 28px 0;
  color: var(--text-muted);
  font-size: .85rem;
  margin-top: 60px;
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
