/* --- CSS Variable Tokens --- */
:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  
  /* Palette - Dark Mode Only */
  --bg-app: #0e0e11;
  --bg-card: #16161a;
  --bg-control: rgba(30, 30, 38, 0.75);
  
  --border-color: rgba(255, 255, 255, 0.08);
  --border-active: #0a84ff; /* Active Blue */
  --border-danger: #ea4335;
  
  --ink-primary: #f5f5f7;
  --ink-secondary: #a1a1a6;
  --ink-muted: #86868b;
  
  --color-success: #34a853;
  --color-warning: #fbbc05;
  --color-danger: #ea4335;
  
  --rounded-sm: 8px;
  --rounded-md: 12px;
  --rounded-lg: 16px;
  --rounded-full: 9999px;
  
  --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --max-width-setup: 460px;
}

/* --- Base Styles --- */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--ink-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Common Screen Utility */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.hidden {
  display: none !important;
}

/* --- 1. SETUP / WELCOME SCREEN --- */
.setup-screen {
  justify-content: center;
  align-items: center;
  padding: 24px;
  overflow-y: auto;
}

.setup-card {
  width: 100%;
  max-width: var(--max-width-setup);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--rounded-lg);
  padding: 32px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.setup-header {
  text-align: center;
}

.logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.logo-icon {
  width: 32px;
  height: 32px;
  color: var(--border-active);
}

.logo h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.subtitle {
  font-size: 14px;
  color: var(--ink-secondary);
}

/* Setup Video Preview */
.preview-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background-color: #000;
  border-radius: var(--rounded-md);
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.preview-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror camera local */
}

.preview-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(14, 14, 17, 0.9);
  color: var(--ink-secondary);
  font-size: 14px;
  transition: var(--transition-smooth);
  pointer-events: none;
}

.preview-video:not([srcObject]) + .preview-overlay {
  opacity: 1;
}

.preview-controls {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  z-index: 10;
}

/* Inputs & Form */
.setup-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
}

.input-group input,
.input-group select {
  font-family: var(--font-sans);
  background-color: #1e1e24;
  border: 1px solid var(--border-color);
  color: var(--ink-primary);
  padding: 12px 16px;
  font-size: 14px;
  border-radius: var(--rounded-sm);
  outline: none;
  transition: var(--transition-smooth);
}

.input-group input:focus,
.input-group select:focus {
  border-color: var(--border-active);
  box-shadow: 0 0 0 2px rgba(10, 132, 255, 0.25);
}

.room-input-container {
  display: flex;
  gap: 8px;
}

.room-input-container input {
  flex: 1;
}

/* Buttons */
button {
  font-family: var(--font-sans);
  cursor: pointer;
  border: none;
  outline: none;
  transition: var(--transition-smooth);
}

.btn-primary {
  background-color: var(--border-active);
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  padding: 14px;
  border-radius: var(--rounded-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary:hover {
  background-color: #0066cc;
}

.btn-secondary {
  background-color: #2c2c35;
  color: var(--ink-primary);
  font-size: 13px;
  padding: 0 16px;
  border-radius: var(--rounded-sm);
}

.btn-secondary:hover {
  background-color: #3a3a45;
}

.btn-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--rounded-full);
  background-color: rgba(30, 30, 38, 0.85);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-icon:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

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

.btn-icon svg {
  width: 20px;
  height: 20px;
}


/* --- 2. MEETING ROOM SCREEN --- */
.room-screen {
  position: relative;
  background-color: #0b0b0d;
}

/* Header */
.room-header {
  height: 60px;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  background-color: #0e0e11;
  z-index: 10;
}

.room-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.room-status-indicator {
  width: 8px;
  height: 8px;
  background-color: var(--color-success);
  border-radius: var(--rounded-full);
  display: inline-block;
  box-shadow: 0 0 8px var(--color-success);
}

#room-title {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.btn-link {
  background: transparent;
  color: var(--border-active);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--rounded-sm);
}

.btn-link:hover {
  background-color: rgba(10, 132, 255, 0.1);
}

.user-count {
  font-size: 13px;
  color: var(--ink-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Main Video Grid */
.video-grid-container {
  flex: 1;
  width: 100%;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.video-grid {
  width: 100%;
  height: 100%;
  display: grid;
  gap: 16px;
  transition: var(--transition-smooth);
}

/* Grid Layouts Based on peer count */
.layout-1-peer {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  max-width: 1000px;
  max-height: 560px;
}

.layout-2-peers {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr;
}

@media (max-width: 768px) {
  .layout-2-peers {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }
}

.layout-3-peers {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

.layout-3-peers > :last-child {
  grid-column: span 2;
  max-width: 50%;
  justify-self: center;
  width: 100%;
}

@media (max-width: 768px) {
  .layout-3-peers {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr 1fr;
  }
  .layout-3-peers > :last-child {
    grid-column: auto;
    max-width: 100%;
  }
}

.layout-4-peers {
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

/* Video Wrapper */
.video-wrapper {
  background-color: var(--bg-card);
  border-radius: var(--rounded-lg);
  border: 2px solid transparent;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  transition: var(--transition-smooth);
  width: 100%;
  height: 100%;
}

.video-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 1;
}

/* Mirror local video only */
.local-wrapper video {
  transform: scaleX(-1);
}

/* Active Speaker glow */
.video-wrapper.active-speaker {
  border-color: var(--color-success);
  box-shadow: 0 0 16px rgba(52, 168, 83, 0.4);
}

/* Name tag and mute overlays */
.video-meta {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 2;
  pointer-events: none;
}

.display-name {
  background-color: rgba(22, 22, 26, 0.8);
  backdrop-filter: blur(8px);
  padding: 6px 12px;
  border-radius: var(--rounded-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border-color);
  max-width: 70%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-icons {
  display: flex;
  gap: 8px;
}

.mic-status {
  width: 28px;
  height: 28px;
  border-radius: var(--rounded-full);
  background-color: rgba(22, 22, 26, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-color);
}

.mic-status .mic-off-icon {
  color: var(--color-danger);
}

.mic-status .mic-on-icon {
  color: var(--ink-secondary);
}

/* Avatar Fallback for disabled video */
.avatar-fallback {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #232329;
  color: var(--ink-primary);
  font-size: 48px;
  font-weight: 700;
  z-index: 0;
}

/* --- Control Footer --- */
.room-controls {
  height: 84px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  background-color: var(--bg-control);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  z-index: 10;
}

.controls-group {
  display: flex;
  gap: 16px;
}

.controls-group:first-child {
  /* Center buttons */
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.btn-control {
  height: 48px;
  padding: 0 16px;
  min-width: 76px;
  border-radius: var(--rounded-md);
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--ink-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 500;
}

.btn-control:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.btn-control svg {
  width: 18px;
  height: 18px;
}

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

.btn-control.active-off:hover {
  background-color: #d93025;
}

.btn-share.active-on {
  background-color: var(--border-active);
  color: #fff;
}

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

.btn-danger:hover {
  background-color: #d93025;
}

/* Responsive Footer */
@media (max-width: 600px) {
  .room-controls {
    padding: 0 16px;
  }
  .controls-group:first-child {
    position: static;
    transform: none;
    flex: 1;
    justify-content: center;
  }
  .btn-control {
    min-width: 64px;
    padding: 0 8px;
  }
  .control-label {
    display: none; /* Hide label texts on mobile screen */
  }
}

/* --- Spotlight / Presentation Mode --- */
.video-grid.spotlight-mode {
  display: grid;
  grid-template-columns: 4fr 1.2fr;
  grid-template-rows: repeat(3, 1fr);
  gap: 16px;
  height: 100%;
}

.video-grid.spotlight-mode .spotlight-active {
  grid-column: 1;
  grid-row: 1 / span 3;
  height: 100%;
  border-color: var(--border-active);
  box-shadow: 0 4px 24px rgba(10, 132, 255, 0.25);
}

.video-grid.spotlight-mode > :not(.spotlight-active) {
  grid-column: 2;
  grid-row: auto;
  height: 100%;
  max-height: 140px;
  aspect-ratio: 16 / 9;
  align-self: center;
  justify-self: center;
}

@media (max-width: 992px) {
  .video-grid.spotlight-mode {
    grid-template-columns: 3fr 1fr;
  }
}

@media (max-width: 768px) {
  .video-grid.spotlight-mode {
    grid-template-columns: repeat(4, 1fr);
    grid-template-rows: 1fr auto;
    gap: 12px;
  }

  .video-grid.spotlight-mode .spotlight-active {
    grid-column: 1 / span 4;
    grid-row: 1;
    aspect-ratio: 16 / 9;
  }

  .video-grid.spotlight-mode > :not(.spotlight-active) {
    grid-column: auto;
    grid-row: 2;
    height: 60px;
    max-height: none;
    aspect-ratio: 16 / 9;
    align-self: center;
  }
}


/* --- 3. TOAST NOTIFICATIONS --- */
.toast-container {
  position: fixed;
  top: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background-color: rgba(22, 22, 26, 0.95);
  border: 1px solid var(--border-color);
  color: var(--ink-primary);
  padding: 12px 20px;
  border-radius: var(--rounded-md);
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
  animation: slideIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  transition: var(--transition-smooth);
}

.toast.toast-fadeout {
  opacity: 0;
  transform: translateY(-8px);
}

@keyframes slideIn {
  from { transform: translateX(30px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-success { border-left: 3px solid var(--color-success); }
.toast-error { border-left: 3px solid var(--color-danger); }
.toast-info { border-left: 3px solid var(--border-active); }
