/* ── TraderTV Academy ─────────────────────────────────────────────────────
   Academy-specific UI: interactive cards (rendered from ```academy-card
   fences in any conversation that emits them) plus, further below, the
   domain-scoped chrome (top bar / rail / activity workspace) that only
   activates under body[data-domain="tradertv-academy"].
   All colors come from the style.css design tokens → light + dark for free. */

/* ── Cards ── */

.academy-card {
  margin: 10px 0 4px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 560px;
}

.academy-card + .academy-card {
  margin-top: 12px;
}

.ac-head {
  margin-bottom: 8px;
}

.ac-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-soft-border);
  border-radius: 999px;
  padding: 2px 8px;
  margin-bottom: 6px;
}

.ac-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.ac-subtitle {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.ac-goal {
  font-size: 13.5px;
  color: var(--text-secondary);
  margin: 6px 0;
}

/* Type chips — the activity type badge in lesson rows and the per-activity
   chips in the course map. `ac-done` marks a completed activity. */

.ac-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.ac-step {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}

.ac-step.ac-done {
  color: var(--ok);
  background: var(--ok-soft-bg);
  border-color: var(--ok);
}

/* Lesson activity checklist: one compact row per activity — type badge,
   title, ✓ when completed, and a right-aligned Open button (document/video)
   or quiz meta. Rows wrap at phone width instead of squeezing the title. */

.ac-activities {
  list-style: none;
  margin: 8px 0 2px;
  padding: 0;
}

.ac-activity {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border-soft);
  font-size: 13px;
  color: var(--text-secondary);
}

.ac-activity:first-child {
  border-top: none;
}

.ac-activity .ac-step {
  flex: none;
}

.ac-activity-title {
  flex: 1 1 10ch;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ac-activity.ac-done .ac-activity-title {
  color: var(--text-muted);
}

.ac-check {
  flex: none;
  color: var(--ok);
  font-weight: 700;
}

.ac-activity-meta {
  flex: none;
  margin-left: auto;
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .ac-activity-meta {
    flex: 1 1 100%;
    margin-left: 0;
    white-space: normal;
  }
}

/* Buttons */

.ac-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.ac-btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ac-btn:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--text-dim);
}

.ac-btn.ac-primary {
  color: var(--btn-fg);
  background: var(--btn-bg);
  border-color: var(--btn-bg);
}

.ac-btn.ac-primary:hover:not(:disabled) {
  background: var(--btn-bg-hover);
}

/* The per-row Open button in a lesson checklist: smaller, pushed right. */
.ac-btn.ac-row-btn {
  flex: none;
  margin-left: auto;
  font-size: 12px;
  padding: 4px 11px;
}

.ac-btn:focus-visible,
.ac-choice:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.ac-btn:disabled,
.ac-choice:disabled {
  opacity: 0.55;
  cursor: default;
}

/* Quiz */

.ac-prompt {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text);
  margin: 8px 0 10px;
}

.ac-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ac-choice {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-align: left;
  font: inherit;
  font-size: 13.5px;
  color: var(--text-secondary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.ac-choice:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--accent);
}

.ac-choice.ac-chosen {
  border-color: var(--accent);
  background: var(--accent-soft);
  opacity: 1;
}

.ac-choice-label {
  flex: none;
  font-weight: 700;
  color: var(--accent);
  min-width: 18px;
}

/* Quiz result */

.ac-score {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 2px;
}

.ac-score-pct {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
}

.ac-band {
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 3px 10px;
  border: 1px solid var(--border);
}

.ac-band.ac-good {
  color: var(--ok);
  background: var(--ok-soft-bg);
  border-color: var(--ok);
}

.ac-band.ac-attention {
  color: var(--danger);
  background: var(--danger-soft-bg);
  border-color: var(--danger-soft-border);
}

.ac-score-detail {
  font-size: 12.5px;
  color: var(--text-muted);
  margin: 2px 0 0;
}

/* Journal */

.ac-journal-prompts {
  margin: 8px 0 4px 20px;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.ac-journal-prompts li {
  margin: 4px 0;
}

.ac-hint {
  font-size: 12.5px;
  color: var(--text-dim);
  margin: 8px 0 0;
}

/* Progress + course map: one .ac-course block per course (header row + bar +
   lesson rows); the course map adds a chip row under each lesson. */

.ac-bar {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  overflow: hidden;
}

.ac-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s;
}

.ac-courses {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 8px;
}

.ac-course-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 8px;
  margin-bottom: 4px;
}

.ac-course-title {
  flex: 1 1 10ch;
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.ac-course-pct {
  font-size: 12px;
  color: var(--text-muted);
}

.ac-status {
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.ac-map-lessons {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
}

.ac-lesson-row {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 6px;
  font-size: 13px;
  color: var(--text-secondary);
  padding: 4px 0;
  border-bottom: 1px solid var(--border-soft);
}

.ac-lesson-row:last-child {
  border-bottom: none;
}

.ac-lesson-row.ac-locked {
  color: var(--text-dim);
}

.ac-lesson-title {
  flex: 1 1 10ch;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ac-lesson-pct {
  font-size: 12px;
  color: var(--text-muted);
}

/* Course-map chips break onto their own line under the lesson row. */
.ac-lesson-row .ac-steps {
  flex: 1 1 100%;
  margin: 2px 0;
}

.ac-lock {
  font-size: 11px;
}

.ac-next {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 10px 0 0;
}

.ac-remaining {
  color: var(--text-muted);
}

/* next-actions chip row: bare buttons, no card chrome */

.academy-card.ac-next-actions {
  background: transparent;
  border: none;
  padding: 0;
}

.academy-card.ac-next-actions .ac-actions {
  margin-top: 6px;
}

/* Streaming placeholder */

.academy-card.ac-loading {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.ac-spinner {
  width: 12px;
  height: 12px;
  flex: none;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ac-spin 0.9s linear infinite;
}

@keyframes ac-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Academy chrome (active only under body[data-domain="tradertv-academy"]) ── */

/* Top bar — reuses the reserved .top-bar class (style.css keeps it display:none
   everywhere else). In-flow first child of .main, so the fixed masquerade
   banner's .app-container offset composes with it untouched. */

body[data-domain="tradertv-academy"] .top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: none;
  padding: 0 20px;
  height: 46px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.top-bar-brand {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.top-bar-mission {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 1;
  border-left: 1px solid var(--border);
  padding-left: 16px;
}

.top-bar-mission-caption {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-dim);
  white-space: nowrap;
}

.top-bar-mission-label {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-bar-p8 {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--btn-fg);
  background: var(--btn-bg);
  border: 1px solid var(--btn-bg);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.top-bar-p8:hover {
  background: var(--btn-bg-hover);
}

.top-bar-p8:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* mode.js toggles `hidden` while ACADEMY_P8_URL is empty. style.css has no
   global .hidden rule on purpose (every use is scoped), so without this the
   button rendered visible-but-dead. */
body[data-domain="tradertv-academy"] .top-bar-p8.hidden {
  display: none;
}

@media (max-width: 720px) {
  .top-bar-mission-caption {
    display: none;
  }
}

/* Utility rail: Progress + Journal only exist in academy scope. Automations is
   hidden here too, but that is not this file's job — initAutomations() gates it
   to agent-automation across all domains. */

.academy-nav-item {
  display: none;
}

body[data-domain="tradertv-academy"] .academy-nav-item {
  display: flex;
}

.academy-nav-icon {
  display: inline-flex;
  align-items: center;
}

/* ── Activity workspace (video player or embedded document) ── */

.academy-workspace {
  position: fixed;
  top: 0;
  right: 0;
  width: 560px;
  max-width: 92vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -6px 0 24px rgba(0, 0, 0, 0.06);
  transform: translateX(100%);
  transition: transform 180ms ease-out, width 180ms ease-out;
  display: flex;
  flex-direction: column;
  z-index: 200;
  min-width: 360px;
}

.academy-workspace.open {
  transform: translateX(0);
}

.academy-workspace.expanded {
  width: 92vw;
}

/* Mirror the other fixed drawers under the masquerade banner offset. */
body.masquerading .academy-workspace {
  top: 36px;
  height: calc(100vh - 36px);
}

/* Docked mode: on wide screens the open workspace pushes the chat column left
   instead of overlaying it — true side-by-side lesson + tutor. The expanded
   (92vw) state stays an overlay. */
@media (min-width: 1200px) {
  body.academy-workspace-open .main {
    padding-right: 560px;
  }
}

.academy-workspace-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
}

.academy-workspace-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.academy-workspace-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.academy-workspace-actions {
  display: flex;
  gap: 4px;
  flex: none;
}

.academy-workspace-btn {
  font: inherit;
  font-size: 14px;
  line-height: 1;
  color: var(--text-muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 7px;
  cursor: pointer;
}

.academy-workspace-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.academy-workspace-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* A flex column so an embedded document can take the remaining height
   (flex: 1) while the video box keeps its 16:9 aspect. */
.academy-workspace-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 14px 16px;
}

.academy-workspace-video {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
}

.academy-workspace-doc {
  position: relative;
  flex: 1 1 auto;
  min-height: 60vh;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.academy-workspace-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

/* Always beside the frame: hosts may refuse framing with no signal we can catch. */
.academy-workspace-link {
  flex: none;
  margin: 8px 0 0;
  font-size: 12.5px;
}

.academy-workspace-link a {
  color: var(--link);
  text-decoration: none;
  border-radius: 3px;
}

.academy-workspace-link a:hover {
  text-decoration: underline;
}

.academy-workspace-link a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.academy-workspace-notice {
  flex: none;
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
  background: var(--warn-soft-bg);
  border: 1px solid var(--warn-soft-border);
  border-radius: 8px;
  padding: 10px 12px;
}

.academy-workspace-h {
  flex: none;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin: 16px 0 6px;
}

.academy-workspace-goal {
  flex: none;
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.academy-workspace-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.academy-workspace-hint {
  font-size: 12.5px;
  color: var(--text-muted);
}
