/* COGNIVIA v4.0 — Gimnasio Cognitivo con IA — dark-first, ATD brand identity
 * Paleta oficial ATD: Azul marino #0f054c, Cian #00ddfd, Fucsia #ec1f52, Blanco #FFFFFF
 * Migrado de COGNIVIA v3.1.1 con mejoras premium para v4.0
 */
:root {
  --bg: #0a0330;
  --bg-surface: #0f054c;
  --bg-card: #160a5e;
  --bg-card-hover: #1c0e6e;
  --bg-input: #1a0c55;
  --fg: #e8e6f0;
  --fg-muted: #9b96b8;
  --fg-dim: #6b6590;
  --cyan: #00ddfd;
  --cyan-dim: rgba(0,221,253,0.15);
  --cyan-glow: rgba(0,221,253,0.25);
  --red: #ec1f52;
  --red-dim: rgba(236,31,82,0.15);
  --green: #2dd4a8;
  --green-dim: rgba(45,212,168,0.15);
  --yellow: #f5c542;
  --yellow-dim: rgba(245,197,66,0.15);
  --purple: #a78bfa;
  --purple-dim: rgba(167,139,250,0.15);
  --border: rgba(255,255,255,0.08);
  --border-active: rgba(0,221,253,0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  color-scheme: dark;
}
/* COGNIVIA es siempre dark mode — tema azul marino profesional ATD
 * No hay modo claro: la identidad visual es oscura por diseño */

* { box-sizing: border-box; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  line-height: 1.6;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  padding-block: 0;
  min-height: 100vh;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 100;
  background: var(--bg-surface);
}

h1, h2, h3, h4 { font-family: var(--font-display); text-wrap: balance; line-height: 1.2; }
button { font-family: var(--font-body); cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: var(--font-body); }

.app { max-width: 1100px; margin: 0 auto; padding-block: 16px 60px; }

/* ── Navigation ── */
.nav {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 50;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
/* Fallback text logo — hidden when img loads */
.nav-logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700; font-size: 14px;
  color: #fff;
}
/* ATD logo image in nav */
.nav-logo-img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
}
/* Version badge in nav */
.nav-version-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--cyan);
  background: var(--cyan-dim);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  letter-spacing: 0.04em;
  font-family: var(--font-display);
}
/* Logout link subtle styling */
.nav-link-logout {
  color: var(--fg-dim);
}
.nav-link-logout:hover {
  color: var(--red);
  background: var(--red-dim);
}
.nav-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.nav-title span { color: var(--cyan); }
.nav-links {
  display: flex; gap: 4px;
}
.nav-link {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  transition: all 0.2s;
  letter-spacing: 0.01em;
}
.nav-link:hover { color: var(--fg); background: var(--cyan-dim); }
.nav-link.active { color: var(--cyan); background: var(--cyan-dim); }

/* ── Stats Bar ── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-value.cyan { color: var(--cyan); }
.stat-value.red { color: var(--red); }
.stat-value.green { color: var(--green); }
.stat-value.yellow { color: var(--yellow); }
.stat-label {
  font-size: 11px;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 4px;
}

/* ── Section Headers ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}
.section-title {
  font-size: 20px;
  font-weight: 700;
}
.section-subtitle {
  font-size: 13px;
  color: var(--fg-muted);
}

/* ── Module Cards ── */
.modules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 36px;
}
.module-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: all 0.25s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.module-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.module-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}
.module-card[data-color="cyan"]::before { background: var(--cyan); }
.module-card[data-color="red"]::before { background: var(--red); }
.module-card[data-color="green"]::before { background: var(--green); }
.module-card[data-color="yellow"]::before { background: var(--yellow); }
.module-card[data-color="purple"]::before { background: var(--purple); }
.module-card[data-color="cyan2"]::before { background: linear-gradient(90deg, var(--cyan), var(--green)); }

.module-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  margin-bottom: 14px;
  transition: transform 0.3s ease;
}
.module-icon.cyan { background: var(--cyan-dim); }
.module-icon.red { background: var(--red-dim); }
.module-icon.green { background: var(--green-dim); }
.module-icon.yellow { background: var(--yellow-dim); }
.module-icon.purple { background: var(--purple-dim); }

.module-name {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
/* Module name colors matching DEMO */
.module-card[data-color="cyan"] .module-name { color: var(--cyan); }
.module-card[data-color="red"] .module-name { color: var(--red); }
.module-card[data-color="green"] .module-name { color: var(--green); }
.module-card[data-color="yellow"] .module-name { color: var(--yellow); }
.module-card[data-color="purple"] .module-name { color: var(--purple); }
.module-card[data-color="cyan2"] .module-name { color: var(--cyan); }

.module-desc {
  font-size: 13px;
  color: var(--fg-muted);
  margin-bottom: 14px;
  line-height: 1.5;
}
.module-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--fg-dim);
}
.module-meta-item {
  display: flex;
  align-items: center;
  gap: 4px;
}
/* Start link like DEMO */
.module-start-link {
  color: var(--cyan);
  font-weight: 600;
  font-size: 13px;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
  transition: opacity 0.2s;
}
.module-start-link:hover { opacity: 0.8; }
.module-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 12px;
  overflow: hidden;
}
.module-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s;
}

/* ── Streak & Daily ── */
.daily-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
}
.streak-display {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.streak-fire { font-size: 28px; }
.streak-count {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  color: var(--yellow);
  font-variant-numeric: tabular-nums;
}
.streak-label { font-size: 13px; color: var(--fg-muted); }
.streak-days {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.streak-day {
  width: 36px; height: 36px;
  border-radius: var(--radius-xs);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.streak-day.done { background: var(--green-dim); color: var(--green); }
.streak-day.today { background: var(--cyan-dim); color: var(--cyan); border: 1px solid var(--cyan); }
.streak-day.future { background: var(--bg-input); color: var(--fg-dim); }

/* ── Training View ── */
.view { display: none; }
.view.active { display: block; }

.training-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.back-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  transition: all 0.2s;
}
.back-btn:hover { background: var(--bg-card-hover); border-color: var(--border-active); }

.training-module-info {
  flex: 1; min-width: 0;
}
.training-module-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
}
.training-module-level {
  font-size: 12px;
  color: var(--fg-muted);
}

.difficulty-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.difficulty-badge.basico { background: var(--green-dim); color: var(--green); }
.difficulty-badge.intermedio { background: var(--yellow-dim); color: var(--yellow); }
.difficulty-badge.avanzado { background: var(--red-dim); color: var(--red); }

/* Chat Interface */
.chat-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 20px;
}
.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.chat-trainer-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
}
.chat-trainer-status {
  font-size: 11px;
  color: var(--green);
  display: flex; align-items: center; gap: 4px;
}
.chat-trainer-status::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
}

.chat-messages {
  padding: 20px;
  max-height: 500px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.chat-msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.chat-msg.trainer {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-xs);
}
.chat-msg.user {
  background: var(--cyan-dim);
  border: 1px solid rgba(0,221,253,0.2);
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-xs);
}
.chat-msg .sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--cyan);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.chat-msg.user .sender { color: var(--fg-muted); }
.chat-msg em { color: var(--cyan); font-style: normal; font-weight: 500; }

.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 18px;
}
.chat-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--fg-dim);
  animation: typing 1.2s infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

.chat-input-area {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.chat-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 0;
  resize: none;
  overflow-y: auto;
  min-height: 44px;
  max-height: 160px;
  font-family: var(--font-body);
}
.chat-input:focus { border-color: var(--border-active); }
.chat-input::placeholder { color: var(--fg-dim); }
.chat-send {
  padding: 12px 20px;
  background: var(--cyan);
  color: #0f054c;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
  white-space: nowrap;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-send:hover { filter: brightness(1.1); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Options buttons */
.chat-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-self: flex-start;
  animation: msgIn 0.3s ease;
}
.chat-option-btn {
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--fg);
  transition: all 0.2s;
}
.chat-option-btn:hover {
  border-color: var(--cyan);
  background: var(--cyan-dim);
  color: var(--cyan);
}

/* Exercise Context Card — prominent like DEMO */
.exercise-context {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--cyan);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.exercise-context-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--cyan);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  font-family: var(--font-display);
}
.exercise-context-text {
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.6;
}

/* Training Stats sidebar */
.training-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 20px;
}
@media (max-width: 768px) {
  .training-layout { grid-template-columns: 1fr; }
}
.training-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.sidebar-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.sidebar-card-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
}

/* Score ring */
.score-ring {
  width: 100px; height: 100px;
  margin: 0 auto 10px;
  position: relative;
}
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring circle {
  fill: none;
  stroke-width: 8;
  stroke-linecap: round;
}
.score-ring .track { stroke: var(--border); }
.score-ring .fill { stroke: var(--cyan); transition: stroke-dashoffset 1s ease; }
.score-ring .score-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}
.score-ring .score-label {
  font-size: 10px;
  color: var(--fg-muted);
  font-weight: 500;
}

/* Ranking list */
.ranking-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ranking-item:last-child { border: none; }
.ranking-pos {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ranking-pos.gold { background: var(--yellow-dim); color: var(--yellow); }
.ranking-pos.silver { background: var(--fg-dim); color: var(--fg); }
.ranking-pos.bronze { background: var(--red-dim); color: var(--red); }
.ranking-name { flex: 1; min-width: 0; }
.ranking-score { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--cyan); }

/* ── Profile View ── */
.profile-header {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}
.profile-avatar {
  width: 72px; height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 28px; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.profile-info { min-width: 0; }
.profile-name {
  font-family: var(--font-display);
  font-size: 22px; font-weight: 700;
}
.profile-profession {
  font-size: 13px; color: var(--fg-muted);
}
.profile-badges {
  display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap;
}
.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
}
.badge.cyan { background: var(--cyan-dim); color: var(--cyan); }
.badge.green { background: var(--green-dim); color: var(--green); }
.badge.yellow { background: var(--yellow-dim); color: var(--yellow); }

.skills-radar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.skills-bars { display: flex; flex-direction: column; gap: 14px; }
.skill-bar-item { display: flex; flex-direction: column; gap: 4px; }
.skill-bar-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px;
}
.skill-bar-name { font-weight: 500; }
.skill-bar-score { font-variant-numeric: tabular-nums; color: var(--cyan); font-weight: 600; }
.skill-bar-track {
  height: 6px; background: var(--border); border-radius: 3px; overflow: hidden;
}
.skill-bar-fill {
  height: 100%; border-radius: 3px; transition: width 0.8s ease;
}

/* ── Rankings View ── */
.rankings-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.rank-tab {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-muted);
  transition: all 0.2s;
}
.rank-tab:hover { color: var(--fg); }
.rank-tab.active { background: var(--cyan-dim); color: var(--cyan); }

.rank-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.rank-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.rank-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.rank-table tr:hover td { background: var(--bg-card); }
.rank-table .you { background: var(--cyan-dim); }
.rank-table .you td { font-weight: 600; }

.rank-profession { font-size: 12px; color: var(--fg-muted); }
.rank-change { font-size: 12px; }
.rank-change.up { color: var(--green); }
.rank-change.down { color: var(--red); }

/* ── Buttons ── */
.btn-primary {
  padding: 10px 22px;
  background: var(--cyan);
  color: #0f054c;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }
.btn-secondary {
  padding: 10px 22px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--border-active); }

/* ── Footer ── */
.footer {
  text-align: center;
  padding: 28px 0 16px;
  border-top: 1px solid var(--border);
  margin-top: 36px;
}
.footer-tagline {
  font-style: italic;
  color: var(--fg-muted);
  font-size: 14px;
  margin-bottom: 8px;
  letter-spacing: 0.01em;
}
.footer-brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  color: var(--fg-dim);
}
.footer-brand span { color: var(--cyan); }
.footer-text { font-size: 12px; color: var(--fg-dim); }

/* ── Responsive ── */
@media (max-width: 768px) {
  .nav {
    padding: 10px 0;
    gap: 8px;
  }
  .nav-links {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-link {
    padding: 8px 12px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .training-layout { grid-template-columns: 1fr; }
  .training-sidebar { order: -1; }
}
@media (max-width: 600px) {
  body { padding-left: 12px; padding-right: 12px; }
  .app { padding-block: 10px 40px; }
  .modules-grid { grid-template-columns: 1fr; gap: 12px; }
  .stats-bar { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px 10px; }
  .stat-value { font-size: 24px; }
  .stat-label { font-size: 10px; }
  .profile-header { flex-direction: column; text-align: center; }
  .profile-badges { justify-content: center; }
  .profile-avatar { width: 60px; height: 60px; font-size: 22px; }
  .profile-name { font-size: 18px; }
  .rank-table { font-size: 13px; }
  .rank-table th, .rank-table td { padding: 8px 10px; }
  .chat-messages { max-height: 50vh; }
  .chat-input-area { padding: 10px 12px; gap: 8px; }
  .chat-send { padding: 10px 14px; font-size: 13px; }
  .module-card { padding: 16px; }
  .module-desc { font-size: 12px; margin-bottom: 10px; }
  .section-title { font-size: 17px; }
  .section-subtitle { font-size: 12px; }
  .daily-section { padding: 14px; }
  .streak-count { font-size: 28px; }
  .streak-day { width: 30px; height: 30px; font-size: 10px; }
  .footer { padding: 20px 0 12px; margin-top: 24px; }
  .footer-tagline { font-size: 12px; }
  .sidebar-card { padding: 12px; }
  /* Touch targets: min 44px height */
  .gate-btn, .chat-send, .nav-link, .module-card .module-start-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
@media (max-width: 380px) {
  .stats-bar { grid-template-columns: 1fr 1fr; gap: 6px; }
  .stat-value { font-size: 20px; }
  .nav-title { font-size: 15px; }
  .nav-version-badge { font-size: 9px; padding: 2px 4px; }
}

/* ── Access Code Gate ── */
.access-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.access-gate.hidden { display: none; }
.gate-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 36px;
  max-width: 440px;
  width: 100%;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.gate-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--red));
}
/* Fallback text logo for gate — hidden when img loads */
.gate-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--cyan), var(--purple));
  border-radius: var(--radius);
  display: none; /* Hidden by default when using img */
  align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-size: 24px; font-weight: 700; color: #fff;
  margin: 0 auto 20px;
}
/* ATD logo image in gate */
.gate-logo-img {
  display: block;
  margin: 0 auto 16px;
  object-fit: contain;
  filter: drop-shadow(0 4px 16px rgba(0,221,253,0.2));
}
.gate-title {
  font-family: var(--font-display);
  font-size: 24px; font-weight: 700;
  margin-bottom: 8px;
}
.gate-title span { color: var(--cyan); }
.gate-text {
  font-size: 14px; color: var(--fg-muted);
  line-height: 1.6; margin-bottom: 28px;
}
.gate-input-group { position: relative; margin-bottom: 16px; }
.gate-input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  text-align: center;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.3s;
}
.gate-input:focus { border-color: var(--cyan); }
.gate-input.error { border-color: var(--red); animation: shake 0.4s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.gate-error {
  font-size: 13px; color: var(--red);
  margin-bottom: 12px; min-height: 20px;
}
.gate-btn {
  width: 100%;
  padding: 14px;
  background: var(--cyan);
  color: #0f054c;
  border-radius: var(--radius-sm);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  transition: all 0.2s;
  margin-bottom: 20px;
}
.gate-btn:hover { filter: brightness(1.1); transform: translateY(-1px); }
.gate-footer {
  font-size: 12px; color: var(--fg-dim);
  line-height: 1.5;
}
.gate-footer a {
  color: var(--cyan);
  text-decoration: none;
}
.gate-footer a:hover { text-decoration: underline; }
/* Gate tagline — como la DEMO */
.gate-tagline {
  font-style: italic;
  color: var(--fg-muted);
  font-size: 13px;
  margin-bottom: 8px;
}
.gate-brand-line {
  margin-top: 10px;
  font-size: 11px;
  color: var(--fg-dim);
  letter-spacing: 0.02em;
}
/* FORJA Phase Pills — como la DEMO hero */
.gate-forja-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 16px 0 20px;
}
.forja-pill {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-display);
  color: var(--pill-color, var(--cyan));
  border: 1px solid var(--pill-color, var(--cyan));
  background: transparent;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
}
.forja-pill:hover {
  background: color-mix(in srgb, var(--pill-color, var(--cyan)) 15%, transparent);
}
@media (max-width: 600px) {
  .gate-card { padding: 32px 20px; }
}

/* ══════ COGNIVIA v4.0 — Nuevos estilos premium ══════ */

/* ── Hero Section (Dashboard) ── */
.hero-section {
  position: relative;
  text-align: center;
  padding: 48px 24px 40px;
  margin-bottom: 28px;
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(15,5,76,0.9) 0%, rgba(10,3,48,0.95) 50%, rgba(15,5,76,0.9) 100%);
  border: 1px solid var(--border);
  overflow: hidden;
}
.hero-section::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--cyan), var(--green), var(--yellow), var(--red), var(--purple));
  background-size: 200% 100%;
  animation: gradientShift 4s ease infinite;
}
.hero-glow {
  position: absolute;
  top: 50%; left: 50%;
  width: 400px; height: 400px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(0,221,253,0.06) 0%, transparent 70%);
  pointer-events: none;
}
.hero-content {
  position: relative;
  z-index: 1;
}
.hero-title {
  font-family: var(--font-display);
  font-size: clamp(24px, 4vw, 36px);
  font-weight: 700;
  line-height: 1.15;
  margin-bottom: 14px;
  color: var(--fg);
}
.hero-highlight {
  background: linear-gradient(135deg, var(--cyan), var(--green));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle {
  font-size: clamp(13px, 2vw, 15px);
  color: var(--fg-muted);
  line-height: 1.6;
  max-width: 640px;
  margin: 0 auto 20px;
}
.hero-forja-pills {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}
@media (max-width: 600px) {
  .hero-section { padding: 32px 16px 28px; }
  .hero-forja-pills { gap: 6px; }
  .hero-forja-pills .forja-pill { padding: 4px 10px; font-size: 11px; }
}

/* ── Platform Stats (estadísticas globales animadas) ── */
.platform-stats-section {
  margin: 36px 0 8px;
  padding: 0 8px;
}
.platform-stats-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  flex-wrap: wrap;
  background: linear-gradient(135deg, rgba(15,5,76,0.7), rgba(10,3,48,0.9));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
}
.platform-stat {
  flex: 1;
  min-width: 100px;
  text-align: center;
  padding: 8px 16px;
}
.platform-stat-number {
  font-family: var(--font-display);
  font-size: clamp(32px, 5vw, 44px);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.platform-stat-number.cyan { color: var(--cyan); }
.platform-stat-number.green { color: var(--green); }
.platform-stat-number.yellow { color: var(--yellow); }
.platform-stat-number.red { color: var(--red); }
.platform-stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 6px;
}
.platform-stat-divider {
  width: 1px;
  height: 48px;
  background: var(--border);
  flex-shrink: 0;
}
@media (max-width: 600px) {
  .platform-stats-inner { flex-wrap: wrap; gap: 8px; padding: 20px 12px; }
  .platform-stat { min-width: 40%; }
  .platform-stat-divider { display: none; }
}

/* ── History action buttons ── */
.history-action-btn {
  margin-top: 6px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(0, 221, 253, 0.08);
  color: var(--cyan);
  border: 1px solid var(--cyan);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: all 0.2s ease;
  letter-spacing: 0.02em;
}
.history-action-btn:hover {
  background: rgba(0, 221, 253, 0.18);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 221, 253, 0.2);
}
.history-action-btn:active {
  transform: translateY(0);
}

/* ── History detail panel ── */
#history-detail {
  transition: all 0.3s ease;
}
#history-detail:not([hidden]) {
  display: block !important;
  animation: fadeIn 0.3s ease-out;
}

/* ── Premium enhancements ── */

/* Smooth page transitions */
.view {
  animation: fadeIn 0.3s ease-out;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Card glow on hover */
.stat-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

/* Module card enhanced hover */
.module-card {
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}
.module-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.3);
}

/* Chat send button glow */
.chat-send:hover:not(:disabled) {
  box-shadow: 0 0 16px var(--cyan-glow);
}

/* Chat message entrance animation */
.chat-msg {
  animation: msgSlide 0.3s ease-out;
}
@keyframes msgSlide {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Score ring glow animation */
.score-ring .fill {
  filter: drop-shadow(0 0 6px var(--cyan-glow));
}

/* Gate card enhanced gradient border */
.gate-card::before {
  height: 4px;
  background: linear-gradient(90deg, var(--cyan), var(--green), var(--yellow), var(--red), var(--purple));
  background-size: 200% 100%;
  animation: gradientShift 4s ease infinite;
}
@keyframes gradientShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

/* Nav enhanced */
.nav {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Gate subtitle uppercase for DEMO match */
.gate-subtitle {
  text-transform: uppercase;
  letter-spacing: 0.08em !important;
}

/* Input focus ring */
.gate-input:focus {
  box-shadow: 0 0 0 3px var(--cyan-dim);
}
.chat-input:focus {
  box-shadow: 0 0 0 3px var(--cyan-dim);
}

/* Streak days smooth entry */
.streak-day {
  transition: transform 0.2s ease;
}
.streak-day:hover {
  transform: scale(1.1);
}

/* Progress bar step active glow */
.forja-step[style*="var(--cyan)"],
.forja-step[style*="var(--green)"],
.forja-step[style*="var(--yellow)"],
.forja-step[style*="var(--red)"],
.forja-step[style*="var(--purple)"] {
  box-shadow: 0 0 6px currentColor;
}

/* Responsive: gate forja pills */
@media (max-width: 400px) {
  .gate-forja-pills { gap: 6px; }
  .forja-pill { padding: 4px 10px; font-size: 11px; }
}

/* ── Custom scrollbar (DEMO style) ── */
.chat-messages::-webkit-scrollbar,
.chat-input::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track,
.chat-input::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb,
.chat-input::-webkit-scrollbar-thumb {
  background: var(--border-active);
  border-radius: 3px;
}
.chat-messages::-webkit-scrollbar-thumb:hover,
.chat-input::-webkit-scrollbar-thumb:hover {
  background: var(--cyan);
}

/* ── Chat message user bubble — more visible like DEMO ── */
.chat-msg.user {
  background: rgba(0,221,253,0.12);
  border: 1px solid rgba(0,221,253,0.25);
}

/* ── History card improvements ── */
.history-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s ease;
}
.history-card:hover {
  border-color: var(--border-active);
}

/* ── Profile stats cards with gradient borders ── */
.stat-card {
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--cyan), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}
.stat-card:hover::after {
  opacity: 1;
}

/* ── Module card icon background pulse ── */
.module-card:hover .module-icon {
  transform: scale(1.05);
  transition: transform 0.3s ease;
}

/* ── Sidebar card subtle glow ── */
.sidebar-card {
  transition: border-color 0.3s ease;
}
.sidebar-card:hover {
  border-color: rgba(0,221,253,0.2);
}

/* ── Hamburger Menu (mobile) ── */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 36px;
  height: 36px;
  padding: 6px;
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}
.nav-hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--fg-muted);
  border-radius: 1px;
  transition: all 0.3s ease;
}
.nav-hamburger:hover { background: var(--bg-card-hover); }
.nav-hamburger.active span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.nav-hamburger.active span:nth-child(2) { opacity: 0; }
.nav-hamburger.active span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

@media (max-width: 600px) {
  .nav-hamburger { display: flex; }
  .nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    gap: 2px;
    padding-top: 8px;
    order: 3;
  }
  .nav-links.open {
    display: flex;
    animation: slideDown 0.2s ease-out;
  }
  @keyframes slideDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .nav-links .nav-link {
    width: 100%;
    text-align: left;
    padding: 12px 14px;
    border-radius: var(--radius-xs);
    font-size: 14px;
  }
  .nav {
    flex-wrap: wrap;
  }
}

/* ═══════ Rankings mejorado ═══════ */
.rankings-summary {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.ranking-user-position {
  display: flex;
  align-items: baseline;
  gap: 8px;
  background: var(--bg-card);
  padding: 12px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.ranking-position-label {
  font-size: 14px;
  color: var(--fg-muted);
}
.ranking-position-number {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  color: var(--cyan);
}
.ranking-position-total {
  font-size: 14px;
  color: var(--fg-dim);
}

/* ═══════ Onboarding Overlay ═══════ */
.onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.onboarding-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 2, 30, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.onboarding-card {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 221, 253, 0.12), 0 0 80px rgba(0, 221, 253, 0.06);
  animation: onboardingIn 0.4s ease-out;
}
@keyframes onboardingIn {
  from { opacity: 0; transform: translateY(20px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.onboarding-step-indicator {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 20px;
}
.onboarding-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-dim);
  transition: background 0.3s, transform 0.3s;
}
.onboarding-dot.active {
  background: var(--cyan);
  transform: scale(1.3);
}
.onboarding-icon {
  font-size: 48px;
  margin-bottom: 16px;
  line-height: 1;
}
.onboarding-title {
  font-family: var(--font-display);
  font-size: clamp(18px, 4.5vw, 22px);
  font-weight: 700;
  color: var(--fg);
  margin-bottom: 12px;
}
.onboarding-text {
  font-size: 14px;
  color: var(--fg-muted);
  line-height: 1.6;
  margin-bottom: 24px;
}
.onboarding-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.onboarding-skip {
  font-size: 13px;
  color: var(--fg-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  transition: color 0.2s;
  min-height: 44px;
}
.onboarding-skip:hover {
  color: var(--fg-muted);
}
.onboarding-next {
  flex: 1;
  max-width: 200px;
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--cyan), #00b4d8);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  min-height: 44px;
}
.onboarding-next:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 221, 253, 0.3);
}

/* ═══════ PDF Export ═══════ */
@media print {
  body { background: #fff !important; color: #000 !important; }
  .nav, .onboarding-overlay, .access-gate { display: none !important; }
  .app { max-width: 100%; padding: 0; }
  .view { display: none !important; }
  #view-profile { display: block !important; }
  #history-detail { display: block !important; background: #fff !important; border: 1px solid #ccc !important; }
  .btn-secondary, .footer { display: none !important; }
}

/* Utility */
[hidden] { display: none !important; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); border: 0;
}
