:root {
  --bg: #09090b;
  --surface: #121216;
  --surface-alt: #18181f;
  --border: #27272a;
  --text: #f4f4f5;
  --muted: #a1a1aa;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

.reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--success));
  z-index: 50;
  transition: width 0.1s ease-out;
}

.topbar {
  background: rgba(18, 18, 22, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand h1 { font-size: 1.2rem; letter-spacing: -0.02em; }
.badge {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.08em;
}

.btn-install {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid var(--accent);
  color: #fff;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.tabs { display: flex; gap: 0.4rem; }
.tab-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.84rem;
  transition: all 0.15s;
}
.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.container { max-width: 880px; margin: 1.25rem auto; padding: 0 1rem 4rem; }
.view { display: none; }
.view.active { display: block; }
.hidden { display: none !important; }

.kpi-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  margin-bottom: 1.1rem;
}
.kpi-card, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}
.kpi-label { display: block; font-size: 0.72rem; color: var(--muted); text-transform: uppercase; }
.kpi-card strong { font-size: 1.15rem; }

/* Banner de Próximo Sprint */
.next-sprint-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(18, 18, 22, 0.95));
  border-color: rgba(59, 130, 246, 0.4);
  margin-bottom: 1.25rem;
}
.next-banner-info h3 { font-size: 1.05rem; margin-bottom: 0.2rem; color: #fff; }
.btn-auto { width: auto !important; white-space: nowrap; padding: 0.65rem 1.15rem; }

/* Búsqueda y Filtros */
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.5rem;
}
.search-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
}
.search-input:focus { outline: none; border-color: var(--accent); }
.filter-chips { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.filter-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.78rem;
  cursor: pointer;
}
.filter-chip.active {
  background: rgba(59, 130, 246, 0.18);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.book-group { margin-bottom: 2rem; }
.book-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.book-header h2 { font-size: 1.05rem; color: #fff; }
.book-header span { font-size: 0.8rem; color: var(--muted); }
.book-progress-badge {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.74rem !important;
}

.sprint-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 0.65rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
}
.sprint-item:hover { border-color: var(--accent); }
.sprint-item:active { transform: scale(0.995); }
.sprint-info h4 { font-size: 0.95rem; margin-bottom: 0.25rem; color: #fff; }
.sprint-info p { font-size: 0.84rem; color: var(--muted); line-height: 1.45; }

.status-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: #1e1e24;
  color: var(--muted);
  white-space: nowrap;
}
.status-pill.cached { background: rgba(59, 130, 246, 0.15); color: #60a5fa; }
.status-pill.completed { background: rgba(16, 185, 129, 0.15); color: var(--success); }

.nav-back-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.toolbar-right { display: flex; gap: 0.45rem; }
.btn-ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}
.btn-ghost:hover { color: #fff; border-color: var(--accent); }

.session-header { margin-bottom: 1.25rem; }
.tag { font-size: 0.72rem; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.session-header h2 { font-size: 1.35rem; margin-top: 0.2rem; }
.subtitle { color: var(--muted); font-size: 0.9rem; margin-top: 0.25rem; }

.card { margin-bottom: 1.25rem; }
.card-top-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}
.phase-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
}
.reading-time { font-size: 0.76rem; color: var(--muted); }
.card h3 { font-size: 1.05rem; margin-bottom: 0.6rem; color: #fff; }

/* Tipografía enriquecida para Markdown, Tablas Financieras y Citas */
.markdown-body { font-size: 0.98rem; color: #e4e4e7; overflow-wrap: break-word; }
body.large-reading-mode .markdown-body { font-size: 1.12rem; line-height: 1.8; }

.markdown-body h3, .markdown-body h4 {
  color: #fff;
  margin: 1.45rem 0 0.6rem;
  font-size: 1.1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.3rem;
}
.markdown-body p { margin-bottom: 0.9rem; }
.markdown-body ul, .markdown-body ol { margin: 0.5rem 0 1rem 1.35rem; }
.markdown-body li { margin-bottom: 0.45rem; }
.markdown-body strong { color: #fff; font-weight: 600; }
.markdown-body blockquote {
  margin: 0.85rem 0;
  padding: 0.75rem 1rem;
  background: var(--surface-alt);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  color: #d4d4d8;
}
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.88rem;
  display: block;
  overflow-x: auto;
}
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.75rem;
  text-align: left;
}
.markdown-body th { background: var(--surface-alt); color: #fff; }
.markdown-body code {
  background: var(--surface-alt);
  padding: 0.15rem 0.35rem;
  border-radius: 4px;
  font-size: 0.88em;
}

.english-box {
  margin-top: 1.35rem;
  padding: 1rem;
  background: rgba(59, 130, 246, 0.08);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
}
.english-box small { font-size: 0.68rem; font-weight: 700; color: var(--accent); }
.english-box p { font-size: 0.92rem; font-style: italic; margin-top: 0.3rem; }

.tutor-history {
  margin: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 420px;
  overflow-y: auto;
}
.tutor-msg { padding: 0.85rem 1rem; border-radius: 8px; font-size: 0.92rem; }
.tutor-msg.user { background: rgba(59, 130, 246, 0.12); border: 1px solid rgba(59, 130, 246, 0.3); }
.tutor-msg.mentor { background: var(--surface-alt); border: 1px solid var(--border); }

.unlock-box { margin: 1.5rem 0; }

textarea, .select-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0.8rem;
  margin: 0.75rem 0;
  font-family: inherit;
  font-size: 0.95rem;
}

.action-buttons-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 0.75rem;
}
.draft-status {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: right;
}

.btn-primary, .btn-secondary {
  border: none;
  padding: 0.8rem 1.2rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  font-size: 0.95rem;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #27272a; color: #fff; }
.btn-secondary:hover { background: #3f3f46; }
.btn-primary:disabled, .btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.eval-header { display: flex; justify-content: space-between; align-items: center; }
.score-pill {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
}
.takeaway { font-weight: 600; color: var(--accent); margin-bottom: 0.75rem; }

@media (max-width: 640px) {
  .topbar { padding: 0.75rem 1rem; }
  .brand-row { width: 100%; }
  .tabs { width: 100%; display: grid; grid-template-columns: repeat(3, 1fr); }
  .tab-btn { text-align: center; padding: 0.5rem 0.3rem; font-size: 0.78rem; }
  .kpi-bar { grid-template-columns: 1fr; gap: 0.6rem; }
  .kpi-card { display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1.1rem; }
  .next-sprint-banner { flex-direction: column; align-items: flex-start; }
  .btn-auto { width: 100% !important; }
  .sprint-item { flex-direction: column; align-items: flex-start; gap: 0.65rem; }
  .sprint-meta { width: 100%; display: flex; justify-content: flex-end; }
  .action-buttons-row { grid-template-columns: 1fr; }
  .card { padding: 1.05rem; }
  .session-header h2 { font-size: 1.15rem; }
}
