/* SIFT Conference Guest SPA */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --accent-hover: #79c0ff;
  --danger: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --radius: 8px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ── Lobby ─────────────────────────────────────────────── */

.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
}

.lobby-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
}

.lobby-logo {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-bottom: 4px;
  color: var(--accent);
}

.lobby-subtitle {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 32px;
}

.lobby-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lobby-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
}

.lobby-field label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}

.lobby-field input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.lobby-field input:focus {
  border-color: var(--accent);
}

.lobby-field input:disabled {
  opacity: 0.5;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  opacity: 0.85;
}

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-dim);
}

.error-msg {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid rgba(248, 81, 73, 0.3);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--danger);
  font-size: 13px;
  text-align: left;
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.joining-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 15px;
}

/* ── Conference room ───────────────────────────────────── */

.room {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.room-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.room-name {
  font-size: 15px;
  font-weight: 600;
}

.room-meta {
  font-size: 13px;
  color: var(--text-dim);
}

.rec-badge {
  font-size: 12px;
  color: var(--danger);
  font-weight: 600;
  letter-spacing: 0.5px;
  animation: pulse 1.5s ease-in-out infinite;
}

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

.room-brand {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-dim);
  letter-spacing: 1px;
  font-weight: 600;
  opacity: 0.5;
}

/* ── Video grid ────────────────────────────────────────── */

.grid {
  flex: 1;
  display: grid;
  gap: 4px;
  padding: 4px;
  min-height: 0;
  background: var(--bg);
}

/* Auto-layout: 1 participant = 1x1, 2 = 1x2, 3-4 = 2x2, 5-6 = 2x3, 7-9 = 3x3 */
.grid[data-count="1"] { grid-template-columns: 1fr; }
.grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="3"],
.grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.grid[data-count="5"],
.grid[data-count="6"] { grid-template-columns: 1fr 1fr 1fr; }
.grid[data-count="7"],
.grid[data-count="8"],
.grid[data-count="9"] { grid-template-columns: 1fr 1fr 1fr; }

/* ── Focused layout: main tile + scrollable thumbnail strip ──── */
.grid--focused {
  display: flex;
  gap: 4px;
}
.grid-cell { min-height: 0; min-width: 0; }
.grid-cell--focused {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.grid-cell--focused .tile {
  width: 100%;
  height: 100%;
}
.grid--focused .grid-cell--thumb {
  display: none; /* hidden — rendered in the thumb strip instead */
}

/* Thumb strip: appended by JS as a scrollable sidebar */
.grid-thumb-strip {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  overflow-x: hidden;
}
.grid-thumb-strip .grid-cell--thumb {
  display: block;
  flex-shrink: 0;
  height: 124px;
}

.tile {
  position: relative;
  background: #1c2128;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  min-height: 0;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.tile--local video {
  transform: scaleX(-1);
}

/* Border overlay for hover/focus/local feedback */
.tile::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  z-index: 3;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.tile:hover::after { border-color: var(--accent); }
.tile--local::after { border-color: var(--accent); }

.tile--no-video {
  background: linear-gradient(135deg, #1c2128, #21262d);
}

.tile-label {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.7);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  color: #fff;
  max-width: 80%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tile-avatar {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

.tile-fs {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0, 0, 0, 0.5);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
}

.tile:hover .tile-fs {
  opacity: 1;
}

.tile-fs:hover {
  background: rgba(0, 0, 0, 0.8);
}

/* ── Controls ──────────────────────────────────────────── */

.controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  user-select: none;
}

.ctrl-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--text-dim);
}

.ctrl-btn--off {
  color: var(--danger);
  border-color: rgba(248, 81, 73, 0.3);
}

.ctrl-btn--off:hover {
  background: rgba(248, 81, 73, 0.1);
}

.ctrl-btn--leave {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.ctrl-btn--leave:hover {
  opacity: 0.85;
}

.ctrl-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.ctrl-dot--off {
  background: var(--danger);
}

/* ── Chat panel ───────────────────────────────────────── */

.chat-panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: none;
  flex-direction: column;
  min-height: 0;
}

.chat-panel--open {
  display: flex;
  flex: 1;
}

/* When chat is open, compress the grid into a horizontal thumbnail strip */
.chat-panel--open ~ .controls { /* no change needed, controls stay at bottom */ }
.room:has(.chat-panel--open) .grid {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  height: 120px;
}
.room:has(.chat-panel--open) .grid .grid-cell {
  flex: 0 0 160px;
  height: 100%;
}
.room:has(.chat-panel--open) .grid .tile {
  height: 100%;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.chat-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.chat-close:hover { color: var(--text); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font-size: 13px;
}

.chat-empty {
  color: var(--text-dim);
  text-align: center;
  padding: 24px 0;
  font-size: 13px;
}

.chat-msg {
  margin-bottom: 8px;
}

.chat-name {
  font-weight: 600;
  font-size: 12px;
  margin-right: 6px;
}

.chat-time {
  font-size: 11px;
  color: var(--text-dim);
}

.chat-text {
  margin-top: 2px;
  line-height: 1.4;
  word-break: break-word;
}

.chat-input {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-field {
  flex: 1;
  padding: 6px 10px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

.chat-input-field:focus {
  border-color: var(--accent);
}

.chat-send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-send:hover { background: var(--accent-hover); }

.ctrl-btn--active {
  background: rgba(88, 166, 255, 0.15);
  border-color: var(--accent);
  color: var(--accent);
}

.chat-badge {
  display: none; /* replaced by pulsating outline on the button */
}

/* Pulsating gold outline when unread chat messages exist */
.ctrl-btn--unread {
  animation: chat-pulse 2s ease-in-out infinite;
}

@keyframes chat-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(210, 153, 34, 0); border-color: var(--border); }
  50% { box-shadow: 0 0 0 3px rgba(210, 153, 34, 0.35); border-color: var(--warning); }
}

/* ── End screen ────────────────────────────────────────── */

.end-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  text-align: center;
}

.end-screen h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.end-screen p {
  color: var(--text-dim);
  font-size: 15px;
  margin-bottom: 24px;
}

/* ── Responsive ────────────────────────────────────────── */

@media (max-width: 600px) {
  .lobby-card {
    padding: 28px 20px;
  }

  .grid[data-count="2"] { grid-template-columns: 1fr; }
  .grid[data-count="5"],
  .grid[data-count="6"] { grid-template-columns: 1fr 1fr; }

  /* Focused view: stack main tile on top, thumbs scroll below */
  .grid--focused {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }
  .grid-cell--focused {
    grid-column: 1;
    grid-row: 1;
  }
  .grid--focused .grid-cell--thumb {
    grid-column: 1;
    grid-row: auto;
  }

  .controls {
    flex-wrap: wrap;
  }

  .ctrl-btn {
    padding: 8px 12px;
    font-size: 12px;
  }
}

/* Landscape small screens */
@media (max-height: 500px) and (orientation: landscape) {
  .grid--focused { grid-template-columns: 1fr 140px; }
  .grid-cell--focused { grid-column: 1; grid-row: 1 / -1; }
  .grid--focused .grid-cell--thumb { grid-column: 2; }
}
