/* edge-techu styles — Light/Dark theme aligned with edge-uix contracts */
/* UX-005 PnL colors, edge.ui.prefs theme sync */

:root {
  --radius: 6px;
  --transition: 200ms ease;

  /* Platform PnL colors (UX-005) */
  --pnl-positive: #22c55e;
  --pnl-negative: #ef4444;
  --pnl-neutral: #9ca3af;

  /* Platform tokens (edge-uix) */
  --edge-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --edge-font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* --- Dark theme (default) --- */
body, body.theme-dark {
  --gain: #2ecc71;
  --loss: #e74c3c;
  --neutral: #94a3b8;
  --highlight: #f59e0b;
  --primary: #3b82f6;
  --edge-bg: #0f172a;
  --edge-surface: #1e293b;
  --edge-surface-hover: #273548;
  --edge-text: #e2e8f0;
  --edge-muted: #64748b;
  --edge-border: #334155;
  --edge-accent: #3b82f6;
  --grid-line: rgba(255,255,255,0.06);
  --chart-text: #8B9AB5;
}

/* --- Light theme --- */
body.theme-light {
  --gain: #059669;
  --loss: #e11d48;
  --neutral: #64748b;
  --highlight: #d97706;
  --primary: #2563eb;
  --edge-bg: #f8fafc;
  --edge-surface: #ffffff;
  --edge-surface-hover: #f1f5f9;
  --edge-text: #0f172a;
  --edge-muted: #64748b;
  --edge-border: #e2e8f0;
  --edge-accent: #2563eb;
  --grid-line: rgba(15,23,42,0.05);
  --chart-text: #0f172a;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--edge-font-family);
  background: var(--edge-bg);
  color: var(--edge-text);
  overflow: hidden;
  height: 100vh;
  transition: background 300ms ease, color 300ms ease;
}

#techu-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* --- Header --- */

#techu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--edge-surface);
  border-bottom: 1px solid var(--edge-border);
  height: 40px;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.header-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--edge-text);
}

.header-subtitle {
  font-size: 13px;
  color: var(--edge-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-btn {
  background: var(--edge-surface);
  color: var(--edge-muted);
  border: 1px solid var(--edge-border);
  padding: 4px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: background var(--transition);
}

.header-btn:hover {
  background: var(--edge-surface-hover);
  color: var(--edge-text);
}

/* Visible build tag — answers "what build is loaded?" at a glance (UX-012) */
.build-tag {
  align-self: center;
  margin-right: 4px;
  font-size: 11px;
  color: var(--edge-muted);
  font-variant-numeric: tabular-nums;
}

/* Toast for Shift+click storage reset feedback (reload-button.js) */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 16px;
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-radius: var(--radius);
  color: var(--edge-text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 1000;
}

.toast.visible {
  opacity: 1;
}

.theme-toggle-btn {
  min-width: 50px;
  text-align: center;
}

select {
  background: var(--edge-surface);
  color: var(--edge-text);
  border: 1px solid var(--edge-border);
  padding: 4px 8px;
  border-radius: var(--radius);
  font-size: 12px;
}

/* --- Lab Browser --- */

#labBrowser {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.category-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.category-tab {
  padding: 6px 14px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  background: var(--edge-surface);
  color: var(--edge-muted);
  border: 1px solid var(--edge-border);
  transition: all var(--transition);
}

.category-tab:hover {
  background: var(--edge-surface-hover);
  color: var(--edge-text);
}

.category-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.lab-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.lab-card {
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: all var(--transition);
}

.lab-card:hover {
  border-color: var(--primary);
  background: var(--edge-surface-hover);
}

.lab-card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.lab-card-subtitle {
  font-size: 12px;
  color: var(--edge-muted);
  margin-bottom: 8px;
  line-height: 1.4;
}

.lab-card-meta {
  display: flex;
  gap: 8px;
  align-items: center;
}

.lab-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-novice { background: #166534; color: #86efac; }
.badge-intermediate { background: #92400e; color: #fcd34d; }
.badge-skilled { background: #7c2d12; color: #fdba74; }

.lab-card-time {
  font-size: 11px;
  color: var(--edge-muted);
}

.lab-card-completed {
  color: var(--gain);
  font-size: 11px;
}

.lab-card-soon {
  font-size: 10px;
  color: var(--edge-muted);
  border: 1px solid var(--edge-border);
  border-radius: 3px;
  padding: 1px 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Pending = no client module yet. Dimmed and non-interactive — listed so the
   full catalog is visible, but not openable until the lab is built. */
.lab-card-pending {
  opacity: 0.5;
  cursor: default;
}

.lab-card-pending:hover {
  border-color: var(--edge-border);
  background: var(--edge-surface);
}

/* --- Lab Container --- */

#labContainer {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Step Progress */

.step-progress {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--edge-surface);
  border-bottom: 1px solid var(--edge-border);
  align-items: center;
}

.step-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--grid-line);
  transition: background var(--transition);
}

.step-dot.completed {
  background: var(--gain);
}

.step-dot.active {
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
}

.step-label {
  font-size: 11px;
  color: var(--edge-muted);
  margin-left: 8px;
  align-self: center;
}

/* Controls Panel */

.controls-panel {
  padding: 8px 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  background: var(--edge-surface);
  border-bottom: 1px solid var(--edge-border);
  min-height: 44px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.control-label {
  font-size: 11px;
  color: var(--edge-muted);
  white-space: nowrap;
}

.control-value {
  font-size: 12px;
  color: var(--highlight);
  min-width: 32px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 120px;
  height: 4px;
  background: var(--grid-line);
  border-radius: 2px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
}

/* Simulation Area */

.simulation-area {
  /* Size to chart content (was flex:1) so the teaching caption docks directly
     under the chart instead of being stranded at the bottom of a tall void.
     Current labs render <=~480px; overflow-y guards taller content. */
  flex: 0 1 auto;
  padding: 16px;
  display: flex;
  gap: 16px;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
}

.sim-pane {
  flex: 1;
  min-width: 0;
  position: relative;
}

.sim-pane-title {
  font-size: 12px;
  color: var(--edge-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Teaching Panel — three layout modes */

.teaching-panel {
  font-size: 15px;
  color: var(--edge-text);
  line-height: 1.6;
}

/* "Insight:" reads as a small eyebrow above the narration, not an inline prefix.
   Text stays "Insight:" in the DOM so chatx context-grab keeps working. */
.teaching-panel .teaching-label {
  display: block;
  color: var(--highlight);
  font-weight: 700;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin: 0 0 4px;
}

/* Layout: bottom (default) — anchored "coach caption" docked under the chart.
   The accent left-border is the branded device (icon policy: no generic emoji
   until a branded icon inventory exists). */
.teaching-panel.layout-bottom {
  margin: 4px 20px 20px;
  padding: 16px 20px 16px 18px;
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-left: 3px solid var(--highlight);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
}

/* First impression: the first narration of a freshly opened lab renders large
   with lift, then settles to the normal caption on the first step advance. */
.teaching-panel.layout-bottom.is-hero {
  margin: 12px 20px 24px;
  padding: 22px 24px 22px 22px;
  border-left-width: 4px;
  font-size: 17px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}

body.theme-light .teaching-panel.layout-bottom.is-hero {
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
}

/* Layout: side (right companion rail) */
.teaching-panel.layout-side {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 320px;
  padding: 20px;
  background: var(--edge-surface);
  border-left: 3px solid var(--highlight);
  overflow-y: auto;
  font-size: 15px;
  z-index: 10;
}

.teaching-panel.layout-side.is-hero {
  font-size: 16px;
}

/* When side panel is active, shrink simulation area to match the rail width */
#labContainer.teaching-side .simulation-area {
  margin-right: 320px;
}

/* Layout: overlay (floating card) */
.teaching-panel.layout-overlay {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 420px;
  max-height: 260px;
  padding: 18px 20px;
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-left: 3px solid var(--highlight);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  overflow-y: auto;
  z-index: 20;
  font-size: 16px;
}

.teaching-panel.layout-overlay.is-hero {
  width: 480px;
  padding: 24px 26px;
  font-size: 18px;
  border-left-width: 4px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

body.theme-light .teaching-panel.layout-overlay.is-hero {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
}

body.theme-light .teaching-panel.layout-overlay {
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

/* Teaching layout toggle button */
.teaching-layout-toggle {
  font-size: 11px;
  color: var(--edge-muted);
  cursor: pointer;
  float: right;
  margin-left: 8px;
  padding: 2px 6px;
  border: 1px solid var(--edge-border);
  border-radius: 3px;
  background: transparent;
}

.teaching-layout-toggle:hover {
  color: var(--edge-text);
  border-color: var(--edge-muted);
}

/* Canvas iframe */

#canvasFrame {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--edge-bg);
}

/* Annotations */

.annotation {
  position: absolute;
  background: var(--edge-surface);
  border: 1px solid var(--highlight);
  color: var(--edge-text);
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  max-width: 250px;
  z-index: 100;
  pointer-events: none;
  opacity: 1;
  transition: opacity 500ms;
}

.annotation-fade {
  opacity: 0;
}

/* Stats readout */

.stats-readout {
  display: flex;
  gap: 16px;
  padding: 8px 0;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-value {
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat-value.positive { color: var(--gain); }
.stat-value.negative { color: var(--loss); }

.stat-label {
  font-size: 10px;
  color: var(--edge-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Modal */

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-content {
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  text-align: center;
}

.modal-content p {
  margin-bottom: 16px;
  font-size: 14px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

.btn-secondary {
  background: var(--edge-surface);
  color: var(--edge-muted);
  border: 1px solid var(--edge-border);
  padding: 8px 20px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
}

.btn-primary:hover { opacity: 0.9; }
.btn-secondary:hover { background: var(--edge-surface-hover); color: var(--edge-text); }

/* --- Quiz (TU-L003) --- */

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--edge-border);
}

.quiz-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--highlight);
}

.quiz-progress {
  font-size: 12px;
  color: var(--edge-muted);
  font-variant-numeric: tabular-nums;
}

.quiz-question {
  margin-bottom: 20px;
  padding: 16px;
  background: var(--edge-surface);
  border: 1px solid var(--edge-border);
  border-radius: var(--radius);
  transition: border-color var(--transition);
}

.quiz-question.answered {
  border-color: var(--grid-line);
  opacity: 0.85;
}

.quiz-prompt {
  font-size: 14px;
  margin-bottom: 12px;
  line-height: 1.5;
}

.quiz-visual {
  margin-bottom: 12px;
}

.quiz-compare-visual {
  display: flex;
  gap: 16px;
}

.quiz-compare-pane {
  flex: 1;
}

.quiz-compare-label {
  font-size: 12px;
  color: var(--edge-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}

.quiz-answer-area {
  margin-bottom: 8px;
}

.quiz-slider-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.quiz-slider {
  width: 200px;
}

.quiz-slider-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--highlight);
  min-width: 40px;
  font-variant-numeric: tabular-nums;
}

.quiz-submit-btn {
  padding: 6px 16px;
  font-size: 12px;
}

.quiz-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.quiz-option-btn {
  background: var(--edge-surface);
  color: var(--edge-text);
  border: 1px solid var(--edge-border);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all var(--transition);
}

.quiz-option-btn:hover:not(:disabled) {
  background: var(--edge-surface-hover);
  border-color: var(--primary);
}

.quiz-option-btn:disabled {
  cursor: default;
  opacity: 0.7;
}

.quiz-option-btn.correct {
  border-color: var(--gain);
  background: rgba(34, 197, 94, 0.15);
  color: var(--gain);
  opacity: 1;
}

.quiz-option-btn.incorrect {
  border-color: var(--loss);
  background: rgba(239, 68, 68, 0.15);
  color: var(--loss);
  opacity: 1;
}

.quiz-reveal {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
}

.quiz-reveal.quiz-correct {
  background: rgba(34, 197, 94, 0.1);
  border-left: 3px solid var(--gain);
  color: var(--edge-text);
}

.quiz-reveal.quiz-incorrect {
  background: rgba(239, 68, 68, 0.1);
  border-left: 3px solid var(--loss);
  color: var(--edge-text);
}

.quiz-reveal-icon {
  font-weight: 700;
  margin-right: 4px;
}

.quiz-correct .quiz-reveal-icon { color: var(--gain); }
.quiz-incorrect .quiz-reveal-icon { color: var(--loss); }

.quiz-compare-pick {
  margin-top: 8px;
}

/* --- Ask AI Chat Panel (TU-AI001) --- */

.chat-panel {
  position: fixed;
  top: 0;
  right: -360px;
  width: 360px;
  height: 100vh;
  background: var(--edge-surface);
  border-left: 1px solid var(--edge-border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: right 250ms ease;
  box-shadow: -4px 0 20px rgba(0,0,0,0.3);
}

body.theme-light .chat-panel {
  box-shadow: -4px 0 20px rgba(0,0,0,0.08);
}

.chat-panel.open {
  right: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--edge-border);
  gap: 8px;
  flex-shrink: 0;
}

.chat-title {
  font-size: 14px;
  font-weight: 600;
}

.chat-status {
  font-size: 11px;
  color: var(--edge-muted);
  flex: 1;
  text-align: right;
}

.chat-close-btn {
  background: none;
  border: none;
  color: var(--edge-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 6px;
}

.chat-close-btn:hover {
  color: var(--edge-text);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 90%;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.5;
}

.chat-msg-user {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 2px;
}

.chat-msg-ai {
  align-self: flex-start;
  background: var(--edge-bg);
  color: var(--edge-text);
  border: 1px solid var(--edge-border);
  border-bottom-left-radius: 2px;
}

.chat-msg-role {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
  opacity: 0.7;
}

.chat-input-area {
  padding: 10px 12px;
  border-top: 1px solid var(--edge-border);
  flex-shrink: 0;
}

.chat-input {
  width: 100%;
  background: var(--edge-bg);
  color: var(--edge-text);
  border: 1px solid var(--edge-border);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--edge-font-family);
  resize: none;
  outline: none;
}

.chat-input:focus {
  border-color: var(--edge-accent);
}

.chat-input:disabled {
  opacity: 0.5;
}

.chat-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.chat-send-btn {
  padding: 6px 16px;
  font-size: 12px;
}

.chat-escalate-btn {
  background: transparent;
  color: var(--highlight);
  border: 1px solid var(--highlight);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}

.chat-escalate-btn:hover {
  background: rgba(245, 158, 11, 0.1);
}

/* Ask AI button in header */
.ask-ai-btn {
  background: transparent;
  color: var(--highlight);
  border: 1px solid var(--highlight);
  padding: 4px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all var(--transition);
}

.ask-ai-btn:hover {
  background: rgba(245, 158, 11, 0.15);
}

/* SVG charts */

svg text {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Scrollbar */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--edge-bg); }
::-webkit-scrollbar-thumb { background: var(--grid-line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--edge-muted); }
