/* ──────────────────────────────────────────────────────
   Digital UI — Video-centric layout
   ────────────────────────────────────────────────────── */

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Top Bar ── */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--card);
  flex-shrink: 0;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.top-bar-left .eyebrow {
  font-size: 14px;
  letter-spacing: 0.08em;
}

.top-bar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.top-bar-actions .btn {
  padding: 7px 14px;
  font-size: 12px;
}

/* ── Connection Status ── */
.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.is-connected {
  background: var(--success);
  box-shadow: 0 0 8px rgba(0, 255, 157, 0.6);
  animation: pulse-dot 2s ease-in-out infinite;
}

.status-dot.is-connecting {
  background: #ffbb00;
  box-shadow: 0 0 8px rgba(255, 187, 0, 0.5);
  animation: pulse-dot 1s ease-in-out infinite;
}

.status-dot.is-error {
  background: var(--danger);
  box-shadow: 0 0 8px rgba(255, 0, 60, 0.5);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.connection-status strong {
  font-size: 12px;
  color: #fff;
  white-space: nowrap;
}

.connection-status .conn-detail {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

/* ── Main Stage ── */
.main-stage {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  min-height: 0;
}

/* ── Video Container ── */
.video-container {
  display: flex;
  flex-direction: column;
  background: #000;
  position: relative;
  min-height: 0;
}

.video-shell {
  flex: 1;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.video-shell::before,
.video-shell::after {
  content: '';
  position: absolute;
  width: 30px;
  height: 30px;
  pointer-events: none;
  z-index: 10;
}

.video-shell::before {
  top: 8px; left: 8px;
  border-top: 2px solid var(--brand);
  border-left: 2px solid var(--brand);
}

.video-shell::after {
  bottom: 8px; right: 8px;
  border-bottom: 2px solid var(--brand);
  border-right: 2px solid var(--brand);
}

.video-shell video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.video-shell.has-video-frame video {
  opacity: 1;
}

.video-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 5;
}

.video-overlay p {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 1px;
}

.video-shell.has-video-frame + .video-overlay,
.video-shell.has-video-frame .video-overlay {
  display: none;
}

/* ── Transcript Bar ── */
.transcript-bar {
  flex-shrink: 0;
  min-height: 48px;
  max-height: 80px;
  overflow-y: auto;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: rgba(4, 8, 20, 0.95);
}

.transcript-content {
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  line-height: 1.6;
  color: var(--brand);
  white-space: pre-wrap;
}

.transcript-content .partial {
  color: var(--muted);
  font-style: italic;
}

.transcript-content .final {
  color: var(--text);
}

/* ── Side Panel ── */
.side-panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--card);
  overflow-y: auto;
  min-height: 0;
}

.panel-section {
  border-bottom: 1px solid var(--line);
}

.panel-section summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  user-select: none;
  transition: background 0.15s;
}

.panel-section summary:hover {
  background: rgba(0, 243, 255, 0.05);
}

.panel-section summary::-webkit-details-marker {
  display: none;
}

.panel-section summary .eyebrow {
  font-size: 10px;
  margin-right: 4px;
}

.panel-section[open] summary {
  border-bottom: 1px solid var(--line);
  background: rgba(0, 243, 255, 0.03);
}

.panel-body {
  padding: 12px 16px;
}

/* ── Character List (compact) ── */
.character-list-compact {
  display: grid;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.character-chip {
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--card-strong);
  cursor: pointer;
  transition: border-color 0.2s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.character-chip:hover {
  border-color: var(--line-strong);
}

.character-chip.active {
  border-color: var(--brand);
  background: rgba(0, 243, 255, 0.08);
}

.character-chip .char-name {
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.character-chip .char-id {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  color: var(--muted);
}

.character-chip.active::after {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--brand);
  border-radius: 50%;
  box-shadow: var(--glow);
  flex-shrink: 0;
}

/* ── Chat History ── */
.chat-history {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  padding-right: 4px;
}

.chat-bubble {
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 90%;
  word-break: break-word;
}

.chat-bubble.user {
  align-self: flex-end;
  background: rgba(0, 243, 255, 0.12);
  border: 1px solid var(--line);
  color: var(--text);
}

.chat-bubble.assistant {
  align-self: flex-start;
  background: rgba(181, 60, 255, 0.08);
  border: 1px solid rgba(181, 60, 255, 0.2);
  color: var(--text);
}

/* ── Chat Input ── */
.chat-input-row {
  display: flex;
  gap: 8px;
}

.chat-input-row input {
  flex: 1;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.3);
  color: var(--text);
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
}

.chat-input-row input:focus {
  outline: none;
  border-color: var(--brand);
}

.chat-input-row .btn {
  padding: 8px 14px;
  font-size: 12px;
}

/* ── Messages (compact log) ── */
.messages-compact {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 300px;
  overflow-y: auto;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  line-height: 1.5;
}

.messages-compact .log-entry {
  padding: 4px 8px;
  color: var(--muted);
  border-left: 2px solid transparent;
  word-break: break-all;
}

.messages-compact .log-entry.error {
  color: #ffb3c1;
  border-left-color: var(--danger);
  background: rgba(255, 0, 60, 0.05);
}

/* ── Mic indicator ── */
[hidden] {
  display: none !important;
}

.mic-indicator {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--line);
  border-radius: 4px;
  z-index: 20;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--muted);
}

.mic-indicator .mic-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.15s;
}

.mic-indicator.is-speaking .mic-dot {
  background: var(--success);
  box-shadow: 0 0 8px rgba(0, 255, 157, 0.6);
}

.mic-indicator.is-muted .mic-dot {
  background: var(--danger);
}

.mic-level-bar {
  width: 80px;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}

.mic-level-fill {
  height: 100%;
  width: 0%;
  background: var(--brand);
  border-radius: 3px;
  transition: width 0.05s linear;
}

.mic-indicator.is-speaking .mic-level-fill {
  background: var(--success);
}

.mic-indicator.is-muted .mic-level-fill {
  background: var(--danger);
  opacity: 0.4;
}

/* ── Pipeline status ── */
.pipeline-status {
  position: absolute;
  bottom: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(0, 0, 0, 0.75);
  border: 1px solid var(--line);
  border-radius: 4px;
  z-index: 20;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--muted);
  transition: border-color 0.2s;
}

.pipeline-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background 0.2s;
}

.pipeline-status.stage-listen {
  border-color: var(--brand);
  color: var(--brand);
}

.pipeline-status.stage-listen .pipeline-dot {
  background: var(--brand);
  animation: pulse-dot 1s ease-in-out infinite;
}

.pipeline-status.stage-think {
  border-color: #ffbb00;
  color: #ffbb00;
}

.pipeline-status.stage-think .pipeline-dot {
  background: #ffbb00;
  animation: pulse-dot 0.8s ease-in-out infinite;
}

.pipeline-status.stage-synth {
  border-color: #b53cff;
  color: #b53cff;
}

.pipeline-status.stage-synth .pipeline-dot {
  background: #b53cff;
  animation: pulse-dot 0.8s ease-in-out infinite;
}

.pipeline-status.stage-play {
  border-color: var(--success);
  color: var(--success);
}

.pipeline-status.stage-play .pipeline-dot {
  background: var(--success);
  box-shadow: 0 0 6px rgba(0, 255, 157, 0.5);
}

/* ── Button states ── */
.btn.is-loading {
  pointer-events: none;
  opacity: 0.65;
}

.btn.is-loading::after {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-left: 6px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  vertical-align: middle;
  animation: spin-loading 0.6s linear infinite;
}

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

/* ── Threshold Control ── */
.threshold-control label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 8px;
}

.threshold-control label span {
  font-family: "JetBrains Mono", monospace;
  color: var(--brand);
}

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

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

.threshold-hint {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .main-stage {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .side-panel {
    border-left: none;
    border-top: 1px solid var(--line);
    max-height: 40vh;
  }
}

@media (max-width: 600px) {
  .top-bar {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .top-bar-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
