* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #101322;
  color: #f4f4f5;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 24px;
}

h1 {
  margin-top: 0;
}

.card {
  background: #1b2138;
  border: 1px solid #2d365b;
  border-radius: 12px;
  padding: 16px;
  display: grid;
  gap: 12px;
  max-width: 420px;
}

label {
  display: grid;
  gap: 8px;
  font-size: 14px;
}

input,
button,
select {
  border: 1px solid #36406c;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

input,
select {
  background: #0f1428;
  color: #f4f4f5;
}

button {
  background: #3b82f6;
  color: #fff;
  cursor: pointer;
}

button:hover {
  opacity: 0.95;
}

button.danger {
  background: #ef4444;
}

.hidden {
  display: none;
}

.status-row,
.controls {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.status-row {
  flex-wrap: wrap;
}

.enable-call-audio-btn {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #ca8a04;
  background: #422006;
  color: #fef3c7;
  cursor: pointer;
}

.enable-call-audio-btn:hover {
  background: #713f12;
}

.recording-panel {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.recording-panel.recording-live-active {
  border-color: #dc2626;
  box-shadow: 0 0 0 1px rgba(220, 38, 38, 0.35);
}

.recording-panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.recording-panel-head h4 {
  margin: 0;
  font-size: 14px;
}

.recording-live-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.2);
  border: 1px solid rgba(248, 113, 113, 0.45);
  font-size: 12px;
  font-weight: 600;
  color: #fecaca;
}

.recording-live-row.hidden {
  display: none;
}

.recording-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ef4444;
  animation: recording-pulse 1.2s ease-in-out infinite;
}

@keyframes recording-pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.55;
    transform: scale(0.92);
  }
}

.recording-live-elapsed {
  font-variant-numeric: tabular-nums;
  color: #fca5a5;
  font-weight: 500;
}

.recording-tab-badge {
  margin-left: 2px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: #b91c1c;
  color: #fff;
}

.recording-tab-badge.hidden {
  display: none;
}

.recording-hint {
  margin: 0 0 10px;
  font-size: 12px;
  color: #94a3b8;
  line-height: 1.45;
}

.recording-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.recording-status {
  margin: 0 0 8px;
  font-size: 13px;
  color: #e2e8f0;
}

.recordings-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: #cbd5e1;
  max-height: 160px;
  overflow-y: auto;
}

.recordings-list li {
  margin-bottom: 6px;
}

.recordings-list a {
  color: #93c5fd;
}

.recordings-list .recording-error {
  color: #fca5a5;
  font-size: 11px;
}

.recordings-list .recording-row-actions {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: 6px;
  vertical-align: baseline;
}

.recordings-list .recording-inline-btn {
  font: inherit;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid #475569;
  background: #1e293b;
  color: #e2e8f0;
  cursor: pointer;
}

.recordings-list .recording-inline-btn:hover:not(:disabled) {
  border-color: #64748b;
  background: #334155;
}

.recordings-list .recording-inline-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.recording-play-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.recording-play-modal.hidden {
  display: none;
}

.recording-play-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
}

.recording-play-dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: min(960px, 100%);
  background: #0f172a;
  border-radius: 12px;
  border: 1px solid #334155;
  padding: 12px 14px 14px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.recording-play-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.recording-play-head-right {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.recording-play-open-tab {
  font-size: 12px;
  font-weight: 500;
  color: #93c5fd;
  text-decoration: none;
  white-space: nowrap;
}

.recording-play-open-tab:hover {
  text-decoration: underline;
  color: #bfdbfe;
}

.recording-play-title {
  font-size: 14px;
  font-weight: 600;
  color: #f1f5f9;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.recording-play-close {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: #1e293b;
  color: #e2e8f0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.recording-play-close:hover {
  background: #334155;
}

.recording-play-video {
  display: block;
  width: 100%;
  max-height: min(70vh, 640px);
  background: #000;
  border-radius: 8px;
}

.recording-play-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: #fca5a5;
}

.view-switcher {
  display: inline-flex;
  gap: 8px;
  margin-bottom: 12px;
}

.view-btn {
  background: #273254;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.view-btn.active {
  background: #1d4ed8;
}

.pane.hidden {
  display: none;
}

#videos-grid[hidden] {
  display: none !important;
}

.chat-pane[hidden] {
  display: none !important;
}

.chat-tab-video-hint {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.45;
  color: #cbd5e1;
  padding: 10px 12px;
  background: #1b2138;
  border: 1px solid #2d365b;
  border-radius: 10px;
}

.chat-tab-video-hint.hidden {
  display: none !important;
}

#videos-grid.videos {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.screen-share-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.screen-share-stage.hidden {
  display: none !important;
}

.screen-share-stage-row {
  width: 100%;
}

.stage-video-wrap {
  width: 100%;
  max-height: min(70vh, 720px);
}

.stage-share-caption {
  font-size: 13px;
  color: #cbd5e1;
  text-align: center;
  padding: 8px 8px 0;
  line-height: 1.35;
}

/* Participant tiles: You + others on rows below the stage. */
.call-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
  align-items: start;
}

.participant-tile.self-tile {
  background: #1b2138;
  border: 1px solid #2d365b;
  border-radius: 12px;
  padding: 10px;
  position: relative;
  order: 99;
}

.participant-tile.self-tile.self-speaking {
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.8);
}

.tile-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
  margin-bottom: 8px;
}

.chat-card {
  margin-top: 16px;
  background: #1b2138;
  border: 1px solid #2d365b;
  border-radius: 12px;
  padding: 12px;
}

.participants-panel {
  margin-bottom: 10px;
}

.participants-panel h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #cbd5e1;
  font-weight: 600;
}

.participants-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.participant-chip {
  background: #273254;
  border: 1px solid #36406c;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.participant-chip.self {
  background: #1d4ed8;
}

.participant-chip.speaking {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.5);
}

.participant-status {
  opacity: 0.85;
  font-size: 11px;
}

.participant-speaking {
  background: rgba(34, 197, 94, 0.2);
  border: 1px solid rgba(34, 197, 94, 0.5);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

.chat-messages {
  background: #0f1428;
  border: 1px solid #2d365b;
  border-radius: 10px;
  min-height: 140px;
  max-height: 240px;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  gap: 8px;
}

.chat-streams {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 10px;
}

/* Single-stream layout (direct 1:1): full-width transcript + roomier scroll area */
#chat-pane.direct-chat .chat-streams {
  grid-template-columns: 1fr;
}

#chat-pane.direct-chat .chat-stream:first-child {
  max-width: none;
  width: 100%;
}

#chat-pane.direct-chat .chat-messages {
  width: 100%;
  min-height: 220px;
  max-height: min(480px, 58vh);
  box-sizing: border-box;
}

#chat-pane.direct-chat .chat-message {
  max-width: min(92%, 52rem);
}

.chat-stream h4 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #cbd5e1;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.unread-badge {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
  padding: 0 5px;
}

.dm-thread-label {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.chat-message {
  padding: 8px 10px;
  border-radius: 8px;
  max-width: 85%;
  font-size: 13px;
  line-height: 1.4;
}

.chat-message.self {
  justify-self: end;
  background: #1d4ed8;
}

.chat-message.remote {
  justify-self: start;
  background: #273254;
}

.chat-message.system {
  justify-self: center;
  background: transparent;
  color: #9ca3af;
  font-style: italic;
  padding: 2px 6px;
}

.chat-author {
  display: block;
  font-size: 11px;
  opacity: 0.85;
  margin-bottom: 2px;
}

.chat-controls {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chat-meta-controls {
  display: grid;
  grid-template-columns: 180px;
  gap: 8px;
  margin-top: 10px;
}

.chat-meta-controls label {
  gap: 6px;
}

#chat-scope-select {
  background: #0f1428;
  color: #f4f4f5;
}

#chat-input {
  flex: 1;
}

.video-wrap {
  background: #000;
  border-radius: 10px;
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

/* Softer than pure black when there is no camera preview yet (or camera is off). */
#local-video.local-video-empty {
  background: #121726;
  border: 1px dashed rgba(148, 163, 184, 0.35);
}

#local-video.local-video-empty .placeholder {
  max-width: 14rem;
  text-align: center;
  line-height: 1.45;
  padding: 0 12px;
}

.screen-share-tile video {
  object-fit: contain;
}

.remote-participant-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #1b2138;
  border: 1px solid #2d365b;
  border-radius: 12px;
  padding: 10px;
  width: 100%;
  position: relative;
  aspect-ratio: unset;
  min-height: unset;
  align-items: stretch;
  justify-content: flex-start;
  overflow: visible;
}

.remote-participant-stack .remote-camera-slot {
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 160px;
}

.remote-participant-stack.speaking {
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.8);
  border-radius: 12px;
}

/* Flatten remote tiles into the same grid as the self tile (Meet-like strip). */
.remote-videos {
  display: contents;
}

.video-wrap video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.video-wrap.speaking {
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.8);
}

.participant-name {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(15, 20, 40, 0.8);
  color: #f4f4f5;
  font-size: 12px;
  line-height: 1;
}

.participant-video-status {
  position: absolute;
  right: 8px;
  top: 8px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(15, 20, 40, 0.8);
  color: #f4f4f5;
  font-size: 11px;
  line-height: 1;
}

.placeholder {
  color: #9ca3af;
  font-size: 13px;
}

@media (max-width: 760px) {
  .call-gallery {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  }

  .chat-streams {
    grid-template-columns: 1fr;
  }

  .chat-message {
    max-width: 100%;
  }

  .video-wrap {
    min-height: 180px;
  }
}
