/* css/motion-view.css — Motion & Gait Analyzer: full-screen camera scanner
   redesign. The camera view is the base layer everything else floats on. */

#motionRoot {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: #0a0a0a;
  overflow: hidden;
}

.motion-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #0a0a0a;
  filter: var(--motion-cam-filter, none);
}

.motion-video[hidden],
.motion-camera-idle .motion-video { opacity: 0; }

.motion-camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  text-align: center;
  padding: 2rem;
}
.motion-camera-placeholder i { font-size: 3rem; opacity: 0.6; }
.motion-camera-placeholder p { max-width: 320px; font-size: 0.9rem; }

/* Scan-line overlay, shown only while actively capturing/recording */
.motion-scan-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: none;
  overflow: hidden;
}
.motion-scan-overlay.active { display: block; }
.motion-scan-line {
  position: absolute;
  left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, var(--accent, #14b8a6), transparent);
  box-shadow: 0 0 12px 2px var(--accent, #14b8a6);
  animation: motionScanMove 2.4s ease-in-out infinite;
}
@keyframes motionScanMove {
  0%, 100% { top: 8%; }
  50% { top: 92%; }
}

/* Top HUD: analysis-type context + live angle/status readout */
.motion-hud {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 4.5rem);
  left: 1rem;
  right: 1rem;
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}
.motion-prompt-chip {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 1.2rem;
  font-size: 0.88rem;
  text-align: center;
  max-width: 420px;
  border: 1px solid rgba(255, 255, 255, 0.15);
}
.motion-angle-chip {
  background: rgba(20, 184, 166, 0.85);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 700;
  display: none;
  align-items: center;
  gap: 0.4rem;
}
.motion-angle-chip.visible { display: inline-flex; }

/* "Perfect frame" cue — the joint angle has settled within the same tight
   spread the auto-capture waits for, so this is the moment to hold still. */
.motion-angle-chip.motion-angle-stable {
  background: rgba(34, 197, 94, 0.92);
  animation: motionAngleStablePulse 0.8s ease-in-out infinite;
}
@keyframes motionAngleStablePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* Navbar dropdown (injected into #navbarViewSlot) */
/* Floating controls: preferences | record/capture | camera settings */
.motion-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--bottom-nav-h, 60px) + 1.4rem);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.2rem;
  pointer-events: none;
}
.motion-controls > * { pointer-events: auto; }

.motion-fab {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.motion-fab:hover { background: rgba(255, 255, 255, 0.28); transform: translateY(-2px); }
.motion-fab:active { transform: translateY(0) scale(0.96); }

.motion-record-btn {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: #fff;
  border: 4px solid rgba(255, 255, 255, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.motion-record-btn .motion-record-inner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #dc2626;
  transition: all 0.2s ease;
}
.motion-record-btn.recording .motion-record-inner {
  border-radius: 0.5rem;
  width: 28px;
  height: 28px;
  animation: motionRecPulse 1.4s infinite;
}
@keyframes motionRecPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
  50% { box-shadow: 0 0 0 14px rgba(220, 38, 38, 0); }
}
.motion-record-btn:active { transform: scale(0.94); }

/* Camera settings button doubles as Pause once a session is active */
.motion-fab.is-pause { background: rgba(245, 158, 11, 0.35); border-color: rgba(245, 158, 11, 0.6); }

/* Preferences / camera-settings modals — reuse the app's glass preview-card language */
.motion-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.motion-modal.open { display: flex; }
.motion-modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.motion-modal-card {
  position: relative;
  background: var(--surface);
  border-radius: 1.5rem;
  max-width: 440px;
  width: 100%;
  max-height: 86vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
}
.motion-modal-card h3 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.motion-modal-close {
  position: absolute;
  top: 1rem; right: 1rem;
  background: none; border: none;
  font-size: 1.4rem;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
}
.motion-modal .form-group { margin-bottom: 1rem; }
.motion-modal .form-group[hidden] { display: none !important; }
.motion-modal label { display: block; font-size: 0.8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 0.35rem; text-transform: uppercase; letter-spacing: 0.02em; }
.motion-modal input[type="text"],
.motion-modal select,
.motion-modal textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-light);
  border-radius: 0.7rem;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
}
.motion-modal .btn-primary {
  width: 100%;
  margin-top: 0.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 2rem;
  padding: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.motion-slider-row { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.motion-slider-row label { margin: 0; flex-shrink: 0; width: 90px; }
.motion-slider-row input[type="range"] { flex: 1; }
.motion-slider-row span { width: 40px; text-align: right; font-size: 0.8rem; color: var(--text-secondary); }

/* Analyzing overlay — replaces the camera entirely */
.motion-analyzing {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  background: var(--bg-page);
  text-align: center;
  padding: 2rem;
}
.motion-analyzing.active { display: flex; }
.motion-analyzing-spinner {
  width: 64px;
  height: 64px;
  border: 4px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.motion-analyzing-text { font-size: 1rem; font-weight: 600; color: var(--text-primary); min-height: 1.4em; }
.motion-analyzing-sub { font-size: 0.85rem; color: var(--text-secondary); }

/* Results overlay — full-screen */
.motion-results {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  flex-direction: column;
  background: var(--bg-page);
}
.motion-results.active { display: flex; }
.motion-results-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border-light);
  background: var(--card-bg);
  backdrop-filter: var(--backdrop-blur);
}
.motion-results-header h3 { margin: 0; font-size: 1rem; color: var(--text-primary); }
/* Groups a back button with the title so it can sit beside it without
   upsetting the header's existing 2-group space-between layout — shared by
   Motion's own results view and the "formatview" template (js/view-templates.js), which
   reuses .motion-results* wholesale. */
.motion-results-title-group { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.motion-results-title-group h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.motion-results-actions { display: flex; gap: 0.5rem; }
.motion-icon-btn {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-light);
  background: var(--surface);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.15s ease;
}
.motion-icon-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.motion-results-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  max-width: 760px;
  margin: 0 auto;
  width: 100%;
}
.motion-results-body h2, .motion-results-body h3 { color: var(--text-primary); }
.motion-results-body ul { padding-left: 1.2rem; }
/* Edit-in-place state (js/views/motion-view.js setEditingResults) — the
   dashed outline is the only visual cue needed since contenteditable
   already shows a text cursor; no separate "editing" chrome/toolbar. */
.motion-results-body.motion-results-editing {
  outline: 2px dashed var(--accent);
  outline-offset: 4px;
  border-radius: 0.5rem;
  cursor: text;
}

/* the "formatview" template (js/view-templates.js)'s result body is an iframe, not a div —
   .motion-results-body already gives it the right flex/scroll/max-width
   box; this just makes it look like a plain content area instead of a
   bordered widget, and gives the editing state a border since outline
   doesn't render on iframes as cleanly. */
.formatview-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
  border-radius: 0.75rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}
.formatview-frame.motion-results-editing {
  outline: none;
  border: 2px dashed var(--accent);
}
.motion-results-footer {
  flex-shrink: 0;
  display: flex;
  gap: 0.75rem;
  padding: 1rem 1.2rem calc(1rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border-light);
  background: var(--card-bg);
}
.motion-results-footer button {
  flex: 1;
  padding: 0.75rem;
  border-radius: 2rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.88rem;
}
.motion-results-footer .btn-primary { background: var(--accent); color: #fff; border: none; }
.motion-results-footer .btn-secondary { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border-light); }

/* Dark mode */
[data-theme="dark"] .motion-prompt-chip { background: rgba(0,0,0,0.65); }
[data-theme="dark"] .motion-fab { background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.2); }

/* Mobile */
@media (max-width: 480px) {
  .motion-controls { gap: 1.6rem; }
  .motion-fab { width: 46px; height: 46px; font-size: 1.05rem; }
  .motion-record-btn { width: 68px; height: 68px; }
}

/* ============================================================================
   MOTION UPGRADE — session buttons, tracking quality, review bar, report
   ============================================================================ */

/* Preferences button becomes X / Cancel while a session is running */
.motion-fab.is-cancel { background: rgba(220, 38, 38, 0.85); border-color: rgba(255, 255, 255, 0.5); }
.motion-fab.is-cancel:hover { background: rgba(220, 38, 38, 1); }
.motion-fab:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Record button: Record (red dot) → Capture (shutter ring) → Stop (square) */
.motion-record-btn .motion-record-label {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
  white-space: nowrap;
  pointer-events: none;
}
.motion-record-btn[data-mode="capture"] .motion-record-inner { background: var(--accent, #14b8a6); border-radius: 50%; width: 52px; height: 52px; box-shadow: inset 0 0 0 3px #fff; }
.motion-record-btn[data-mode="capture"]:active .motion-record-inner { transform: scale(0.88); }
.motion-record-btn[data-mode="stop"] .motion-record-inner { border-radius: 0.5rem; width: 28px; height: 28px; animation: motionRecPulse 1.4s infinite; }
.motion-record-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* Live tracking-quality chip */
.motion-quality-chip {
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  padding: 0.3rem 0.8rem;
  border-radius: 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.motion-quality-chip[hidden] { display: none; }
.motion-quality-chip::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.motion-quality-chip.q-good::before { background: #22c55e; }
.motion-quality-chip.q-fair::before { background: #f59e0b; }
.motion-quality-chip.q-poor::before { background: #ef4444; }

/* Prefs modal helpers */
.motion-optional { font-weight: 400; text-transform: none; letter-spacing: 0; opacity: 0.7; }
.motion-field-hint { display: block; margin-top: 0.3rem; font-size: 0.72rem; color: var(--text-secondary); }
.motion-protocol-hint { font-size: 0.78rem; line-height: 1.45; color: var(--text-secondary); background: var(--accent-soft); border: 1px solid var(--border-light); border-radius: 0.7rem; padding: 0.6rem 0.8rem; margin-bottom: 1rem; }
.motion-protocol-hint:empty { display: none; }
.motion-modal input[type="number"] { width: 100%; padding: 0.6rem 0.75rem; border: 1px solid var(--border-light); border-radius: 0.6rem; background: var(--surface); color: var(--text-primary); font-family: inherit; font-size: 0.9rem; }
.motion-modal .form-group[hidden], .motion-modal div[hidden] { display: none !important; }

/* Review bar: draft → confirmed */
.motion-review-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding: 0.55rem 1rem;
  background: #fef3c7;
  border-bottom: 1px solid #fbbf24;
  color: #92400e;
  font-size: 0.8rem;
  flex-shrink: 0;
}
.motion-review-bar[hidden] { display: none; }
.motion-review-bar.confirmed { background: #dcfce7; border-bottom-color: #22c55e; color: #166534; }
.motion-review-actions { display: flex; gap: 0.45rem; flex-wrap: wrap; }
.motion-review-btn { border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 0.55rem; padding: 0.3rem 0.7rem; font-size: 0.75rem; font-weight: 700; font-family: inherit; cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem; }
.motion-review-btn.primary { background: #92400e; border-color: #92400e; color: #fff; }
.motion-review-bar.confirmed .motion-review-btn.primary { background: #166534; border-color: #166534; }
.motion-review-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Structured report (js/views/motion-report.js) ---------- */
.motion-results-body .mr-sec { margin-bottom: 1.4rem; }
.mr-tag { font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; border-radius: 0.4rem; padding: 0.15rem 0.45rem; vertical-align: middle; margin-left: 0.3rem; }
.mr-tag-measured { background: #ccfbf1; color: #0f766e; }
.mr-tag-rule { background: #e0e7ff; color: #3730a3; }
.mr-tag-ai { background: #fef3c7; color: #92400e; }
.mr-note, .mr-sub { font-size: 0.72rem; color: var(--text-secondary); }
.mr-note { margin: 0.2rem 0 0.7rem; }
.mr-sub { margin-top: 0.15rem; }
.mr-quality { border: 1px solid var(--border-light); border-left-width: 4px; border-radius: 0.6rem; padding: 0.5rem 0.75rem; font-size: 0.8rem; margin-bottom: 0.9rem; background: var(--surface); }
.mr-quality.mr-q-good { border-left-color: #22c55e; } .mr-quality.mr-q-fair { border-left-color: #f59e0b; } .mr-quality.mr-q-poor { border-left-color: #ef4444; }
.mr-flag { color: #b45309; font-size: 0.74rem; margin-top: 0.25rem; }
.mr-na { color: var(--text-secondary); font-style: italic; }
.mr-table-wrap { overflow-x: auto; margin: 0.4rem 0 0.8rem; }
.mr-table { width: 100%; border-collapse: collapse; font-size: 0.78rem; }
.mr-table th, .mr-table td { border-bottom: 1px solid var(--border-light); padding: 0.45rem 0.5rem; text-align: left; vertical-align: top; }
.mr-table th { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); background: var(--surface); }
.mr-table .mr-inc { width: 28px; text-align: center; }
.mr-table .mr-method { font-size: 0.7rem; color: var(--text-secondary); min-width: 160px; }
.mr-row-na td { opacity: 0.75; }
.mr-conf { display: inline-block; font-size: 0.68rem; font-weight: 700; border-radius: 0.8rem; padding: 0.15rem 0.55rem; white-space: nowrap; }
.mr-conf-hi { background: #dcfce7; color: #166534; } .mr-conf-mo { background: #fef9c3; color: #854d0e; }
.mr-conf-lo { background: #ffedd5; color: #9a3412; } .mr-conf-un { background: #fee2e2; color: #991b1b; }
.mr-move { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-start; margin-bottom: 0.6rem; }
.mr-move-chart { flex: 0 0 auto; max-width: 100%; }
.mr-spark { width: 260px; max-width: 100%; height: 60px; background: var(--surface); border: 1px solid var(--border-light); border-radius: 0.5rem; }
.mr-spark-line { fill: none; stroke: var(--accent, #14b8a6); stroke-width: 2; stroke-linejoin: round; }
.mr-spark-zero { stroke: var(--border-light); stroke-dasharray: 3 3; }
.mr-facts { flex: 1; min-width: 220px; margin: 0; padding-left: 1.1rem; font-size: 0.8rem; }
.mr-comp ul, .mr-limits, .mr-cannot ul { font-size: 0.8rem; margin: 0.3rem 0; }
.mr-flagged { color: #b45309; }
.mr-cannot { border: 1px dashed #f59e0b; background: rgba(245, 158, 11, 0.08); border-radius: 0.6rem; padding: 0.6rem 0.8rem; margin: 0.8rem 0; font-size: 0.8rem; }
.mr-reco { border: 1px solid var(--accent, #14b8a6); border-radius: 0.8rem; padding: 0.8rem 1rem; background: var(--accent-soft); margin-bottom: 0.8rem; }
.mr-reco-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; font-size: 1rem; }
.mr-reco-label { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); }
.mr-ai { border-top: 3px solid #f59e0b; padding-top: 0.6rem; }
[data-theme="dark"] .mr-tag-measured { background: rgba(20,184,166,0.2); color: #5eead4; }
[data-theme="dark"] .mr-tag-rule { background: rgba(99,102,241,0.2); color: #a5b4fc; }
[data-theme="dark"] .mr-tag-ai { background: rgba(245,158,11,0.2); color: #fcd34d; }
[data-theme="dark"] .motion-review-bar { background: rgba(245,158,11,0.15); color: #fcd34d; border-bottom-color: rgba(245,158,11,0.5); }
[data-theme="dark"] .motion-review-bar.confirmed { background: rgba(34,197,94,0.15); color: #86efac; border-bottom-color: rgba(34,197,94,0.5); }
[data-theme="dark"] .motion-review-btn.primary { background: #b45309; border-color: #b45309; }
[data-theme="dark"] .motion-review-bar.confirmed .motion-review-btn.primary { background: #15803d; border-color: #15803d; }
@media print { .motion-review-bar { display: none !important; } .mr-include { display: none; } }