:root {
  --launcher-hud-inset-left: 68px;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

app-root {
  display: block;
  width: 100%;
  height: 100%;
}

staige-reality-player {
  position: fixed;
  inset: 0;
  display: block;
}

.login {
  position: fixed;
  inset: 0;
  z-index: 10020;
  width: 100%;
  height: 100%;
  overflow: auto;
}

.login aisw-user {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100%;
}

#connectDock {
  position: fixed;
  right: 16px;
  top: 16px;
  z-index: 9998;
  width: min(460px, calc(100vw - 32px));
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 10px 28px rgba(2, 6, 23, 0.45);
  display: none;
  backdrop-filter: blur(4px);
}

#connectDock.visible {
  display: block;
}

.connect-dock__title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #cbd5e1;
}

.connect-flow {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.connect-link {
  flex: 1;
  height: 2px;
  background: rgba(148, 163, 184, 0.45);
  border-radius: 999px;
}

.connect-node {
  min-width: 78px;
  border-radius: 10px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  padding: 8px 8px 7px;
  text-align: center;
  background: rgba(30, 41, 59, 0.6);
}

.connect-node__icon {
  display: block;
  font-size: 16px;
  line-height: 1;
}

.connect-node__label {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  font-weight: 600;
}

.connect-node.pending {
  opacity: 0.7;
}

.connect-node.active {
  border-color: #60a5fa;
  background: rgba(30, 64, 175, 0.35);
  color: #dbeafe;
}

.connect-node.done {
  border-color: #34d399;
  background: rgba(6, 95, 70, 0.35);
  color: #d1fae5;
}

.connect-node.error {
  border-color: #f87171;
  background: rgba(127, 29, 29, 0.35);
  color: #fee2e2;
}

.connect-dock__detail {
  margin-top: 10px;
  font-size: 12px;
  color: #cbd5e1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#launcher {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 9999;
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: #0f172a;
  color-scheme: light;
}

#launcher .launcher-panel {
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
  overflow: auto;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 8px 30px rgba(15, 23, 42, 0.12);
}

#launcher.collapsed {
  width: auto;
  max-height: none;
  pointer-events: none;
}

#launcher.collapsed .launcher-panel {
  display: none;
}

#launcher.collapsed .launcher-fab {
  display: flex;
  pointer-events: auto;
}

#launcher:not(.collapsed) .launcher-fab {
  display: none;
}

#launcher .launcher-fab {
  display: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
}

#launcher .launcher-fab__logo {
  display: block;
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  pointer-events: none;
}

#launcher .launcher-fab:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

#launcher .launcher-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#launcher .launcher-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

#launcher .launcher-title {
  font-weight: 600;
  font-size: 15px;
}

#launcher .section-title {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 600;
  color: #0f172a;
}

#launcher .muted {
  color: #64748b;
  font-size: 11px;
}

#launcher .launcher-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

#launcher .launcher-field__label {
  font-size: 12px;
  color: #334155;
  flex: 1;
}

#launcher .launcher-field input[type='number'] {
  margin-top: 0;
  width: 88px;
  flex-shrink: 0;
}

#launcher .launcher-hint {
  margin: 4px 0 0;
}

#launcher #status {
  margin-top: 8px;
  font-size: 12px;
  color: #334155;
  white-space: pre-wrap;
  padding: 8px 10px;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

#launcher input,
#launcher select {
  margin-top: 6px;
  width: 100%;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  box-sizing: border-box;
  color: #0f172a;
  background: #fff;
}

#launcher .btn-row {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

#launcher .btn-primary {
  flex: 1;
  border: 0;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 600;
}

#launcher .btn-secondary {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}

#launcher .btn-ghost {
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 11px;
}

#launcher #cameraList {
  margin-top: 8px;
  max-height: 200px;
  overflow: auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #0f172a;
}

#launcher #cameraList label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  color: #0f172a;
}

#launcher #cameraList label:hover {
  background: #f8fafc;
}

#launcher #cameraList .cam-text-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

#launcher #cameraList .cam-title {
  font-size: 12px;
  font-weight: 600;
  color: #0f172a !important;
}

#launcher #cameraList .cam-address {
  font-size: 11px;
  color: #64748b !important;
}

#launcher #cameraList .cam-empty {
  padding: 10px;
  font-size: 12px;
  color: #64748b;
}

#launcher #cameraList input[type='checkbox'] {
  margin-top: 2px;
  width: auto;
  flex-shrink: 0;
}

/* Pipeline */
#pipeline {
  margin-top: 12px;
  display: none;
}

#pipeline.visible {
  display: block;
}

.pipeline-camera {
  margin-top: 10px;
  padding: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
}

.pipeline-camera-title {
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.pipeline-step {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 0;
  font-size: 11px;
  border-bottom: 1px solid #f1f5f9;
}

.pipeline-step:last-child {
  border-bottom: none;
}

.step-icon {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  margin-top: 1px;
}

.step-icon.pending {
  background: #e2e8f0;
  color: #64748b;
}

.step-icon.active {
  background: #dbeafe;
  color: #1d4ed8;
  animation: pulse 1.2s ease-in-out infinite;
}

.step-icon.done {
  background: #dcfce7;
  color: #166534;
}

.step-icon.error {
  background: #fee2e2;
  color: #991b1b;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.step-body {
  flex: 1;
  min-width: 0;
}

.step-label {
  font-weight: 600;
  color: #0f172a;
}

.step-detail {
  color: #64748b;
  margin-top: 2px;
  word-break: break-all;
}

/* Encoder panel */
#encoderPanel {
  margin-top: 12px;
  display: none;
}

#encoderPanel.visible {
  display: block;
}

.encoder-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.encoder-card {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fafafa;
}

.encoder-card h4 {
  margin: 0 0 6px;
  font-size: 12px;
}

.encoder-kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 4px 8px;
  font-size: 11px;
  margin: 0;
}

.encoder-kv dt {
  color: #64748b;
  margin: 0;
}

.encoder-kv dd {
  margin: 0;
  color: #0f172a;
  word-break: break-all;
}

.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.badge.running { background: #dcfce7; color: #166534; }
.badge.starting { background: #fef9c3; color: #854d0e; }
.badge.pending { background: #e2e8f0; color: #475569; }
.badge.ended { background: #f1f5f9; color: #64748b; }
.badge.error { background: #fee2e2; color: #991b1b; }

.cam-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.cam-status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.badge.cam-online {
  background: #cffafe;
  color: #0e7490;
  text-transform: none;
}

.badge.cam-offline {
  background: #f1f5f9;
  color: #64748b;
  text-transform: none;
}

.badge.cam-unknown {
  background: #fef9c3;
  color: #854d0e;
  text-transform: none;
}

.badge.cam-task {
  background: #ede9fe;
  color: #5b21b6;
  text-transform: none;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge.cam-encoder-running {
  background: #dcfce7;
  color: #166534;
  text-transform: none;
}

.badge.cam-encoder-idle {
  background: #dbeafe;
  color: #1d4ed8;
  text-transform: none;
}

.badge.cam-encoder-other {
  background: #e2e8f0;
  color: #475569;
  text-transform: none;
}

.session-list {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
  font-size: 11px;
}

.session-list li {
  padding: 4px 0;
  border-bottom: 1px solid #e2e8f0;
  color: #475569;
}

.session-list li.current {
  color: #0f172a;
  font-weight: 600;
}

.spark {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 32px;
  margin-top: 6px;
}

.spark .bar {
  width: 4px;
  background: #3b82f6;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}

.spark .bar--rx {
  background: #22c55e;
}

.spark .bar--tx {
  background: #3b82f6;
}

.spark--alert .bar--rx {
  background: #ef4444;
}

.spark-metric {
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 11px;
}

.spark-metric__label {
  color: #64748b;
}

.spark-metric__value {
  color: #0f172a;
  font-weight: 600;
}

.spark-metric--alert .spark-metric__value {
  color: #b91c1c;
}

.spark-warning {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #b91c1c;
}

#launcher .btn-tutorial-prominent {
  margin-top: 8px;
  width: 100%;
  border: 1px solid #7c3aed;
  background: linear-gradient(135deg, #7c3aed, #6366f1);
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
}

#launcher .btn-tutorial-prominent:hover {
  filter: brightness(1.05);
}

.tutorial-highlight {
  position: relative;
  z-index: 10030 !important;
  outline: 2px solid #7c3aed !important;
  border-radius: 8px;
  box-shadow: 0 0 0 6px rgba(124, 58, 237, 0.28);
}

#tutorialOverlay {
  position: fixed;
  inset: 0;
  z-index: 10020;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.2);
  pointer-events: none;
}

#tutorialOverlay.visible {
  display: flex;
}

.tutorial-card {
  width: min(560px, calc(100vw - 40px));
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  box-shadow: 0 14px 40px rgba(2, 6, 23, 0.25);
  padding: 16px;
  color: #0f172a;
  pointer-events: auto;
}

.tutorial-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.tutorial-card__title {
  font-size: 16px;
  font-weight: 700;
}

.tutorial-card__progress {
  font-size: 12px;
  color: #64748b;
}

.tutorial-card__text {
  margin: 10px 0 12px;
  font-size: 14px;
  line-height: 1.45;
  color: #1e293b;
}

.tutorial-card__option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #334155;
}

.tutorial-card__option input[type='checkbox'] {
  width: auto;
  margin: 0;
}

.tutorial-card__actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.tutorial-card__actions button {
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
  font-size: 12px;
}

.tutorial-card__actions .btn-primary {
  border: 0;
  background: #111827;
  color: #fff;
  font-weight: 600;
}

.tutorial-card__actions .btn-secondary,
.tutorial-card__actions .btn-ghost {
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e293b;
}

.tutorial-fab {
  position: fixed;
  right: 68px;
  top: 20px;
  left: auto;
  bottom: auto;
  z-index: 1001;
  min-width: 86px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: rgba(255, 255, 255, 0.95);
  color: #334155;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.2);
}

.tutorial-fab.visible {
  display: inline-flex;
}

@media (max-width: 900px) {
  #launcher {
    left: 8px;
    top: 8px;
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  #launcher .launcher-panel {
    max-height: calc(100dvh - 16px);
    padding: 12px;
  }

  #tutorialOverlay {
    padding: 10px;
  }

  .tutorial-card {
    width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
    padding: 12px;
  }
}
