/* KarCast Vehicle Browser Client Theme */
:root {
  --bg-color: #000;
  --card-bg: #0B1B24;
  --card-border: #1D3743;
  --mint-accent: #75E5C2;
  --primary-color: #75E5C2;
  --mint-dim: rgba(117, 229, 194, 0.12);
  --mint-border: rgba(117, 229, 194, 0.3);
  --text-primary: #F3F7F9;
  --text-secondary: #95B7C8;
  --amber-warning: #F59E0B;
  --red-error: #EF4444;
  --panel-bg: #08141D;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background-color: var(--bg-color);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow: hidden;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Video Canvas & Container */
#stream-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  z-index: 1;
}

#content-viewport, #dock-viewport {
  position: absolute;
  left: 0;
  width: 100%;
  overflow: hidden;
}

#content-viewport {
  top: var(--content-top, 0px);
  height: var(--content-height, calc(100% - 10vw));
}

#dock-viewport {
  bottom: 0;
  height: var(--dock-height, 10vw);
}

#remoteVideo, #relayCanvas, #dockVideo, #relayDockCanvas {
  display: block;
  width: var(--frame-width, 100%);
  margin-inline: auto;
  object-fit: fill;
  touch-action: none;
  background: #000;
}

#remoteVideo, #relayCanvas {
  height: var(--content-frame-height, calc(121.621622vh - 12.162162vw));
}

#remoteVideo, #dockVideo {
  width: var(--video-frame-width, 100%);
}

#remoteVideo {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

#dockVideo {
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  height: var(--dock-frame-height, 56.25vw);
}

#relayDockCanvas {
  height: 100%;
}


/* Connection Pill (Overlay when connected) */
#connection-pill {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(11, 27, 36, 0.85);
  backdrop-filter: blur(12px);
  border: 1px solid var(--card-border);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  pointer-events: auto;
  transition: opacity 0.3s ease;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber-warning);
}

.status-dot.connected {
  background: var(--mint-accent);
  box-shadow: 0 0 8px var(--mint-accent);
}

.status-dot.connecting {
  background: var(--mint-accent);
  animation: pulse 1.5s infinite;
}

.status-dot.error {
  background: var(--red-error);
}

@keyframes pulse {
  0% { opacity: 0.4; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}

/* Pairing & Setup UI Overlay */
#pairing-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(6, 15, 20, 0.96);
  backdrop-filter: blur(20px);
  padding: 24px;
  overflow-y: auto;
}

.card {
  width: 100%;
  max-width: 580px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 28px;
  padding: 36px 36px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  text-align: left;
}

/* Brand Header */
.brand {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.brand-icon {
  width: 52px;
  height: 52px;
  background: var(--mint-dim);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--mint-accent);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--mint-accent);
}

.brand-title {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  line-height: 1.2;
}

.subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Vertical Timeline Section */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 6px;
}

.timeline-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.timeline-left {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  flex-shrink: 0;
}

.timeline-line {
  position: absolute;
  top: 32px;
  bottom: -20px;
  left: 17px;
  width: 2px;
  background: var(--card-border);
  z-index: 1;
}

.timeline-circle {
  position: relative;
  z-index: 2;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.3s ease;
}

.timeline-circle.pending {
  border: 1.5px solid var(--card-border);
  color: var(--text-secondary);
  background: var(--card-bg);
}

.timeline-circle.completed {
  background: var(--mint-accent);
  color: #06231C;
  border: none;
}

.timeline-circle.active {
  background: var(--mint-dim);
  border: 1.5px solid var(--mint-accent);
  color: var(--mint-accent);
}

/* Loading Spinner Ring */
.spinner-ring {
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(117, 229, 194, 0.25);
  border-top-color: var(--mint-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.spinner-ring-small {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(117, 229, 194, 0.25);
  border-top-color: var(--mint-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.timeline-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.timeline-content.row-between {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.step-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
}

.step-title.muted {
  color: var(--text-secondary);
  font-weight: 600;
}

.step-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Right-aligned Status Badges */
.status-done {
  font-size: 14px;
  font-weight: 600;
  color: var(--mint-accent);
}

.status-badge-progress {
  font-size: 12px;
  font-weight: 700;
  color: var(--mint-accent);
  background: var(--mint-dim);
  border: 1px solid var(--mint-border);
  padding: 5px 12px;
  border-radius: 20px;
}

.status-muted {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Divider & Inset Status Panel */
.divider {
  width: 100%;
  height: 1px;
  background: var(--card-border);
  margin: 4px 0;
}

.status-panel {
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-panel-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-panel-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.status-panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.status-panel-sub {
  font-size: 13px;
  color: var(--text-secondary);
}

.connection-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
}

#connection-progress-value {
  color: var(--mint-accent);
  font-size: 14px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.connection-progress-track {
  width: 100%;
  height: 8px;
  margin-top: 5px;
  overflow: hidden;
  border: 1px solid var(--card-border);
  border-radius: 4px;
  background: #050d12;
}

.connection-progress-fill {
  width: 0;
  height: 100%;
  border-radius: 3px;
  background: var(--mint-accent);
  transition: width 0.35s ease;
}

/* Failure / Retry Message */
.message-box {
  font-size: 13px;
  color: var(--amber-warning);
}

.message-box.error {
  color: var(--red-error);
}

/* Diagnostics Panel (?metrics=1) */
#metrics-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 40vh;
  background: rgba(6, 15, 20, 0.95);
  border-top: 1px solid var(--card-border);
  color: #edf7f6;
  padding: 12px 16px;
  font-family: monospace;
  font-size: 11px;
  white-space: pre-wrap;
  overflow-y: auto;
  z-index: 200;
}

[hidden] {
  display: none !important;
}

/* Responsiveness & Narrow Viewports */
@media (max-width: 480px) {
  .card {
    padding: 24px 20px;
    border-radius: 20px;
  }

  .brand-title {
    font-size: 22px;
  }

  .timeline-content.row-between {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .status-badge-progress {
    align-self: flex-start;
  }
}
