/* 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;
  grid-auto-rows: 1fr;
  gap: 4px;
  padding: 4px;
  min-height: 0;
  overflow: hidden;
  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; height: 100%;
  display: flex; align-items: center; justify-content: center; }
.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;
  width: 100%;
  aspect-ratio: 16/9;
  max-height: 100%;
}

.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);
  flex-direction: column;
  gap: 8px;
}
.tile--no-video .tile-label { display: none; }
.tile--screen {
  background: linear-gradient(135deg, #2d2d30, #232326);
}

.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;
  display: flex;
  align-items: center;
}

.tile-muted {
  position: absolute;
  bottom: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  background: rgba(0, 0, 0, 0.7) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f85149' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='1' y1='1' x2='23' y2='23'/%3E%3Cpath d='M9 9v3a3 3 0 0 0 5.12 2.12M15 9.34V4a3 3 0 0 0-5.94-.6'/%3E%3Cpath d='M17 16.95A7 7 0 0 1 5 12v-2m14 0v2c0 .76-.12 1.5-.35 2.18'/%3E%3Cline x1='12' y1='19' x2='12' y2='23'/%3E%3Cline x1='8' y1='23' x2='16' y2='23'/%3E%3C/svg%3E") no-repeat center / 14px;
  border-radius: 4px;
  z-index: 4;
}

.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-identity {
  text-align: center;
  z-index: 1;
}
.tile-identity-name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}
.tile-identity-email {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.45);
  margin-top: 2px;
}

.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);
  display: none;
  flex-direction: column;
  min-height: 0;
}

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

/* ── Right mode (default): side-by-side with grid ────── */
.chat-panel--right {
  border-left: 1px solid var(--border);
}
.chat-panel--right.chat-panel--open {
  width: 320px;
  flex-shrink: 0;
}

/* When right chat is open, grid and chat sit side by side in a row */
.room-body {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: row;
  overflow: hidden;
}
.room-body .grid {
  flex: 1;
  min-width: 0;
  min-height: 0;
}

/* ── Bottom mode: horizontal split with drag handle ──── */
.chat-panel--bottom {
  border-top: none;
}
.chat-panel--bottom.chat-panel--open {
  flex-shrink: 0;
}

/* When bottom chat is open, switch room-body to column, compress grid to thumbnails */
.room-body--bottom {
  flex-direction: column;
}
.room-body--bottom .grid {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 4px;
  overflow-x: auto;
  overflow-y: hidden;
  min-height: 80px;
}
.room-body--bottom .grid .grid-cell {
  flex: 0 0 160px;
  height: 100%;
}
.room-body--bottom .grid .tile {
  height: 100%;
}

/* ── Drag handle for bottom chat resize ─────────────── */
.chat-resize-handle {
  height: 5px;
  cursor: ns-resize;
  background: var(--border);
  flex-shrink: 0;
  position: relative;
}
.chat-resize-handle:hover,
.chat-resize-handle--active {
  background: var(--accent);
}
.chat-resize-handle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: var(--text-dim);
  opacity: 0.4;
}

.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-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-pos-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1;
}
.chat-pos-toggle:hover { color: var(--text); border-color: var(--text-dim); }

.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); }
}

/* ── Admin: kick button ────────────────────────────────── */

.tile-kick {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(248, 81, 73, 0.8);
  border: none;
  color: #fff;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 4;
}

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

.tile-kick:hover {
  background: var(--danger);
}

/* ── Admin: end conference button ─────────────────────── */

.ctrl-btn--end {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.ctrl-btn--end:hover {
  opacity: 0.85;
}

/* ── Admin: stats overlay ─────────────────────────────── */

.tile-stats {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.75);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-family: monospace;
  color: #8b949e;
  pointer-events: none;
  z-index: 3;
  white-space: nowrap;
}

/* ── Admin: invite modal ──────────────────────────────── */

.invite-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.invite-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 400px;
  max-width: 90vw;
}

.invite-dialog .lobby-field {
  margin-bottom: 12px;
}

.invite-dialog input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

.invite-dialog input:focus {
  border-color: var(--accent);
}

.invite-dialog input:disabled {
  opacity: 0.6;
}

.invite-link-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.invite-link-input {
  flex: 1;
  min-width: 0;
  font-size: 12px !important;
}

.invite-link-secondary {
  opacity: 0.7;
}

.invite-label-secondary {
  opacity: 0.6;
  font-size: 12px;
}

.invite-copy-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.invite-copy-btn:hover {
  background: var(--accent);
  color: #fff;
}

/* ── 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;
  }

  /* Chat overlay on mobile — prevents keyboard from squishing layout */
  .room-body {
    position: relative;
  }
  .chat-panel--right.chat-panel--open,
  .chat-panel--bottom.chat-panel--open {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    border-left: none;
  }
}

/* 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; }
}
