:root {
  --blue-950: #0d2f4b;
  --blue-800: #174a73;
  --blue-700: #205d8b;
  --blue-100: #eaf3f8;
  --blue-050: #f4f8fa;
  --orange-600: #d85f00;
  --orange-500: #f58220;
  --orange-100: #fff1e4;
  --ink: #20252b;
  --muted: #566875;
  --line: #d8e2e8;
  --white: #fff;
  --success: #167a5b;
  --danger: #a72a20;
  --shadow: 0 18px 48px rgba(13, 47, 75, 0.14);
  --radius: 14px;
  --focus: 0 0 0 3px rgba(245, 130, 32, 0.3);
  font-family: Aptos, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--blue-050);
  color-scheme: light;
  accent-color: var(--orange-600);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 300px;
  background: var(--blue-950);
  scrollbar-color: var(--blue-700) var(--blue-100);
  scrollbar-width: thin;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--blue-050);
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

::selection {
  color: var(--white);
  background: var(--blue-700);
}

:focus-visible {
  outline: 2px solid var(--orange-600);
  outline-offset: 3px;
  box-shadow: var(--focus);
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 12px;
  z-index: 100;
  padding: 10px 14px;
  color: var(--blue-950);
  background: var(--white);
  border-radius: 10px;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.institution-bar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px clamp(16px, 3vw, 38px);
  color: var(--blue-950);
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand img {
  display: block;
  width: 132px;
  height: auto;
}

.brand-divider {
  width: 1px;
  height: 36px;
  background: var(--line);
}

.product-name {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.product-name b {
  color: var(--blue-950);
  font-size: 14px;
}

.service-state {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.state-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #b7c3ca;
  box-shadow: 0 0 0 4px rgba(183, 195, 202, 0.2);
}

.service-state.is-ready .state-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(22, 122, 91, 0.14);
}

.service-state.is-error .state-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(167, 42, 32, 0.14);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(270px, 330px) minmax(0, 1fr);
  gap: 0;
}

.course-rail {
  position: relative;
  isolation: isolate;
  overflow-x: hidden;
  overflow-y: auto;
  padding: clamp(26px, 4vw, 48px) clamp(22px, 3vw, 36px) 30px;
  color: var(--white);
  background: var(--blue-800);
}

.rail-intro {
  display: flex;
  align-items: center;
  gap: 14px;
}

.rail-symbol {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  padding: 9px;
  color: var(--blue-950);
  background: var(--orange-500);
  border-radius: 13px;
  stroke: currentColor;
  stroke-width: 1.8;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rail-intro p {
  margin: 0 0 2px;
  color: #dbeaf2;
  font-size: 12px;
  font-weight: 700;
}

.rail-intro h1 {
  margin: 0;
  font-size: clamp(25px, 3vw, 34px);
  line-height: 1;
  letter-spacing: -0.025em;
}

.course-description {
  max-width: 30ch;
  margin: 24px 0 31px;
  color: #eff7fb;
  font-size: 15px;
  line-height: 1.55;
}

.prompt-guide {
  padding-top: 24px;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.prompt-guide h2 {
  margin: 0 0 12px;
  color: #dbeaf2;
  font-size: 12px;
  font-weight: 750;
}

.prompt-suggestion {
  width: 100%;
  display: grid;
  grid-template-columns: 28px 1fr;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px 2px;
  color: var(--white);
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.prompt-suggestion svg {
  width: 24px;
  height: 24px;
  padding: 3px;
  color: #ffb15e;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.prompt-suggestion span {
  font-size: 14px;
  font-weight: 680;
  line-height: 1.3;
}

.prompt-suggestion:hover {
  color: #fff4ea;
  background: rgba(255, 255, 255, 0.06);
}

.scope-note {
  margin-top: 26px;
  color: #dbeaf2;
  font-size: 12px;
  line-height: 1.5;
}

.scope-note summary {
  color: var(--white);
  font-weight: 720;
  text-decoration: underline;
  text-decoration-color: rgba(255, 255, 255, 0.45);
  text-underline-offset: 4px;
  cursor: pointer;
}

.scope-note p {
  margin: 10px 0 0;
}

.tutor-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  background: var(--white);
}

.conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 21px clamp(20px, 4vw, 56px) 17px;
  border-bottom: 1px solid var(--line);
}

.conversation-header h2 {
  margin: 0 0 4px;
  color: var(--blue-950);
  font-size: 18px;
  letter-spacing: -0.012em;
}

.conversation-header p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  color: var(--blue-800);
  background: var(--blue-100);
  border: 0;
  border-radius: 12px;
}

.icon-button:hover {
  color: var(--blue-950);
  background: #dcebf3;
}

.icon-button svg {
  width: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.transcript {
  overflow: auto;
  scroll-behavior: smooth;
  padding: clamp(24px, 4vw, 48px) clamp(20px, 5vw, 72px);
}

.message {
  width: min(100%, 790px);
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 13px;
  margin: 0 auto 28px;
}

.user-message {
  grid-template-columns: minmax(0, 1fr) 38px;
}

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  color: var(--white);
  background: var(--blue-800);
  border-radius: 12px;
  font-size: 12px;
  font-weight: 800;
}

.user-message .avatar {
  grid-column: 2;
  color: var(--blue-950);
  background: var(--orange-500);
}

.user-message .message-body {
  grid-column: 1;
  grid-row: 1;
  justify-self: end;
  max-width: 680px;
  padding: 13px 16px;
  color: var(--white);
  background: var(--blue-800);
  border-radius: 14px 5px 14px 14px;
}

.message-author {
  margin: 0 0 8px;
  color: var(--blue-800);
  font-size: 12px;
  font-weight: 800;
}

.user-message .message-author {
  color: #dbeaf2;
}

.answer-content {
  max-width: 72ch;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.66;
}

.user-message .answer-content {
  color: var(--white);
}

.answer-content > :first-child {
  margin-top: 0;
}

.answer-content > :last-child {
  margin-bottom: 0;
}

.answer-content p,
.answer-content ul,
.answer-content ol,
.answer-content blockquote,
.answer-content .table-wrap {
  margin: 0 0 13px;
}

.answer-content h3,
.answer-content h4 {
  margin: 22px 0 8px;
  color: var(--blue-950);
  line-height: 1.25;
}

.answer-content h3 {
  font-size: 17px;
}

.answer-content h4 {
  font-size: 15px;
}

.answer-content ul,
.answer-content ol {
  padding-left: 22px;
}

.answer-content li + li {
  margin-top: 5px;
}

.answer-content blockquote {
  padding: 11px 14px;
  color: var(--blue-950);
  background: var(--blue-100);
  border-radius: 11px;
}

.table-wrap {
  overflow-x: auto;
}

.answer-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.answer-content th,
.answer-content td {
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  border: 1px solid var(--line);
}

.answer-content th {
  color: var(--white);
  background: var(--blue-800);
}

.grounding-note {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.grounding-note svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--orange-600);
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.sources {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.sources h3 {
  margin: 0 0 8px;
  color: var(--blue-950);
  font-size: 12px;
}

.sources ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.loading-row {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  color: var(--blue-800);
}

.loading-row span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: consult 1.2s cubic-bezier(.22, 1, .36, 1) infinite;
}

.loading-row span:nth-child(2) { animation-delay: 120ms; }
.loading-row span:nth-child(3) { animation-delay: 240ms; }

.error-message .message-body {
  padding: 14px 16px;
  color: #70231d;
  background: #fff0ee;
  border-radius: 12px;
}

.retry-button {
  margin-top: 9px;
  padding: 8px 11px;
  color: var(--white);
  background: var(--danger);
  border: 0;
  border-radius: 9px;
  font-weight: 700;
}

.composer {
  padding: 17px clamp(20px, 5vw, 72px) 18px;
  background: var(--blue-050);
  border-top: 1px solid var(--line);
}

.composer > label {
  display: block;
  width: min(100%, 790px);
  margin: 0 auto 7px;
  color: var(--blue-950);
  font-size: 12px;
  font-weight: 800;
}

.composer-row {
  width: min(100%, 790px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin: 0 auto;
  padding: 7px;
  background: var(--white);
  border: 1px solid #b9cbd6;
  border-radius: var(--radius);
  box-shadow: 0 7px 24px rgba(13, 47, 75, 0.08);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.composer-row:focus-within {
  border-color: var(--blue-700);
  box-shadow: 0 0 0 3px rgba(23, 74, 115, 0.13), 0 10px 28px rgba(13, 47, 75, 0.1);
}

.composer textarea {
  width: 100%;
  min-height: 43px;
  max-height: 150px;
  resize: none;
  padding: 10px 11px;
  color: var(--ink);
  caret-color: var(--orange-600);
  background: transparent;
  border: 0;
  outline: 0;
  line-height: 1.45;
}

.composer textarea::placeholder {
  color: #647681;
  opacity: 1;
}

.send-button {
  min-height: 43px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 15px;
  color: #38200c;
  background: var(--orange-500);
  border: 0;
  border-radius: 10px;
  font-weight: 800;
  box-shadow: 0 7px 18px rgba(216, 95, 0, 0.2);
}

.send-button:hover {
  background: #ff962f;
  transform: translateY(-1px);
}

.send-button:disabled {
  color: #5f6f79;
  background: #d7e0e5;
  box-shadow: none;
  transform: none;
}

.send-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.composer-meta {
  width: min(100%, 790px);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 7px auto 0;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.privacy-notice {
  margin: 8px 0 0;
  color: #5f6f82;
  font-size: 0.76rem;
  line-height: 1.4;
}

.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;
}

@keyframes consult {
  0%, 70%, 100% { transform: translateY(0); opacity: 0.35; }
  35% { transform: translateY(-5px); opacity: 1; }
}

@media (min-width: 901px) {
  .workspace {
    height: calc(100vh - 74px);
    height: calc(100dvh - 74px);
    overflow: hidden;
  }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .course-rail {
    overflow: visible;
    padding-block: 24px;
  }

  .course-description {
    max-width: 65ch;
    margin-bottom: 20px;
  }

  .prompt-guide {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding-top: 18px;
  }

  .prompt-guide h2 {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  .prompt-suggestion {
    align-items: start;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
  }

  .scope-note {
    margin-top: 18px;
  }

  .tutor-panel {
    min-height: 0;
    grid-template-rows: auto auto auto;
  }

  .transcript {
    overflow: visible;
  }
}

@media (max-width: 640px) {
  .institution-bar {
    min-height: 64px;
    padding: 8px 14px;
  }

  .brand {
    gap: 10px;
  }

  .brand img {
    width: 98px;
  }

  .brand-divider,
  .product-name,
  .service-state span:last-child {
    display: none;
  }

  .prompt-guide {
    grid-template-columns: repeat(3, 172px);
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    padding-bottom: 9px;
    scroll-snap-type: x proximity;
    scrollbar-color: #ffb15e rgba(255, 255, 255, 0.15);
  }

  .prompt-guide::-webkit-scrollbar {
    height: 6px;
  }

  .prompt-guide::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
  }

  .prompt-guide::-webkit-scrollbar-thumb {
    background: #ffb15e;
    border-radius: 6px;
  }

  .prompt-suggestion {
    grid-template-columns: 26px 1fr;
    min-height: 68px;
    scroll-snap-align: start;
  }

  .conversation-header {
    padding: 16px;
  }

  .conversation-header p {
    max-width: 34ch;
  }

  .transcript {
    padding: 24px 15px;
  }

  .message,
  .user-message {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 9px;
  }

  .avatar,
  .user-message .avatar {
    grid-column: 1;
    width: 32px;
    height: 32px;
    border-radius: 10px;
  }

  .user-message .message-body {
    grid-column: 2;
    justify-self: stretch;
  }

  .composer {
    position: static;
    padding: 13px 12px 14px;
  }

  .composer-row {
    grid-template-columns: minmax(0, 1fr) 43px;
  }

  .send-button {
    width: 43px;
    padding: 0;
  }

  .send-button span,
  .composer-meta span:first-child {
    display: none;
  }

  .composer-meta {
    justify-content: flex-end;
  }
}

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

/* Simulador local de integración LMS */
.auth-gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--blue-050); }
.auth-gate[hidden] { display: none; }
.auth-card { width: min(100%, 460px); padding: clamp(24px,5vw,38px); background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-card h1 { margin: 4px 0 12px; color: var(--blue-950); font-size: clamp(26px,5vw,34px); }
.auth-card > p { line-height: 1.55; color: var(--muted); }
.auth-eyebrow { margin: 0; color: var(--blue-800) !important; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; }
.auth-card form, #code-step { display: grid; gap: 10px; }
.auth-card label { margin-top: 8px; font-size: 13px; font-weight: 800; color: var(--blue-950); }
.auth-card input { min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; font: inherit; }
.auth-card input:focus-visible { outline: 3px solid rgba(245,130,32,.28); border-color: var(--blue-800); }
.auth-action { width: 100%; margin-top: 4px; }
.pilot-code { padding: 13px; color: var(--blue-950) !important; background: var(--orange-100); border: 1px solid var(--orange-500); border-radius: 9px; }
.auth-status { min-height: 24px; margin-bottom: 0; color: var(--danger) !important; }
.logout-button { min-height: 38px; padding: 7px 12px; color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.55); border-radius: 9px; font-weight: 700; cursor: pointer; }
.auth-locked .institution-bar, .auth-locked .workspace { display: none; }

.demo-lms {
  color: #1d2730;
  background: #eef1f3;
}

.demo-lms-header {
  padding: 18px clamp(18px, 4vw, 48px);
  color: #fff;
  background: #27384a;
}

.demo-lms-header h1 {
  margin: 0 0 5px;
  font-size: 22px;
}

.demo-lms-header p {
  margin: 0;
  color: #d7e1e8;
}

.demo-lms-content {
  padding: 24px clamp(14px, 4vw, 48px) 40px;
}

.demo-lms-content > p {
  max-width: 72ch;
  line-height: 1.5;
}

.demo-frame {
  width: 100%;
  height: 760px;
  margin-top: 16px;
  background: #fff;
  border: 1px solid #b8c4cc;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

@media (max-width: 640px) {
  .demo-frame {
    height: 900px;
  }
}
