:root {
  --bg: #202124;
  --surface: #292a2d;
  --sidebar: #202124;
  --sidebar-border: #3c4043;
  --input-bg: #303134;
  --accent: #8ab4f8;
  --accent-dim: rgba(138, 180, 248, 0.12);
  --accent-green: #81c995;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --msg-user: #394457;
  --msg-system: #303134;
  --danger: #f28b82;
  --danger-dim: rgba(242, 139, 130, 0.15);
  --toolbar-bg: rgba(32, 33, 36, 0.92);
  --toolbar-btn: #3c4043;
  --toolbar-btn-hover: #5f6368;
  --recording: #ea4335;
  --cam-off: #ea4335;
}

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

body {
  font-family: "Space Grotesk", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* ── App layout ── */
#app {
  display: flex;
  height: 100vh;
}

/* ── Video area (left) ── */
.video-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #1a1a1a;
  position: relative;
  min-width: 0;
  padding: 16px 16px 80px;
}

.video-frame {
  position: relative;
  width: 100%;
  max-width: 1200px;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

.video-frame > video#avatar-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.video-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.65));
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}

/* ── User webcam PIP ── */
.pip-container {
  position: absolute;
  bottom: 16px;
  right: 16px;
  width: 180px;
  height: 135px;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: move;
  z-index: 5;
  transition: opacity 0.3s, transform 0.3s;
}

.pip-container.hidden {
  display: none !important;
}

.pip-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1);
}

.pip-label {
  position: absolute;
  bottom: 4px;
  left: 8px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.7);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* ── Floating toolbar (Meet/Zoom style) ── */
.toolbar {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 10;
}

.toolbar-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--toolbar-btn);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  padding: 0;
}

.toolbar-btn:hover {
  background: var(--toolbar-btn-hover);
  transform: none;
  box-shadow: none;
}

.toolbar-btn.active {
  background: var(--recording);
  color: #fff;
}

.toolbar-btn.active:hover {
  background: #d93025;
}

.toolbar-btn.cam-off {
  background: var(--cam-off);
  color: #fff;
}

.toolbar-btn.cam-off:hover {
  background: #d93025;
}

.toolbar-btn-text {
  width: auto;
  border-radius: 24px;
  padding: 0 16px;
  gap: 6px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 13px;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
}

.toolbar-spacer {
  flex: 1;
  min-width: 8px;
}

.toolbar-status {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.2s;
}

.toolbar-status:hover {
  color: var(--accent);
}

/* Mic recording state */
.toolbar-btn.recording {
  background: var(--recording);
  color: #fff;
  animation: pulse-recording 1.5s ease-in-out infinite;
}

.toolbar-btn.recording:hover {
  background: #d93025;
}

@keyframes pulse-recording {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(234, 67, 53, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(234, 67, 53, 0);
  }
}

/* ── Right sidebar ── */
.sidebar {
  width: 360px;
  min-width: 360px;
  background: var(--sidebar);
  border-left: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: width 0.3s ease, min-width 0.3s ease;
}

.sidebar.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
  border-left: none;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.sidebar-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
  padding: 0;
}

.sidebar-close:hover {
  background: var(--input-bg);
  color: var(--text);
  transform: none;
  box-shadow: none;
}

/* ── Gallery (collapsible in sidebar) ── */
.gallery-section {
  flex-shrink: 0;
  border-bottom: 1px solid var(--sidebar-border);
}

.gallery-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  border-radius: 0;
}

.gallery-header:hover {
  background: rgba(255, 255, 255, 0.04);
  transform: none;
  box-shadow: none;
}

.gallery-chevron {
  transition: transform 0.3s ease;
  flex-shrink: 0;
  color: var(--muted);
}

.gallery-selected-name {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
  margin-left: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-body {
  max-height: 250px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.gallery-section.collapsed .gallery-body {
  max-height: 0;
}

.gallery-section.collapsed .gallery-chevron {
  transform: rotate(-90deg);
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
  padding: 0 16px 10px;
}

.example-card {
  border: 2px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  background: var(--input-bg);
  transition: border-color 0.2s ease, transform 0.15s ease;
}

.example-card:hover {
  transform: translateY(-1px);
}

.example-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim);
}

.example-card img {
  width: 100%;
  height: 56px;
  object-fit: cover;
  display: block;
}

.example-card span {
  display: block;
  padding: 3px 4px;
  font-size: 9px;
  text-align: center;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.messages::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--sidebar-border);
  border-radius: 2px;
}

.msg {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
  animation: msg-in 0.2s ease;
  word-break: break-word;
}

.msg-user {
  background: var(--msg-user);
  color: var(--text);
  align-self: flex-end;
  max-width: 85%;
  border-bottom-right-radius: 4px;
}

.msg-system {
  background: var(--msg-system);
  color: var(--muted);
  font-size: 12px;
  align-self: center;
  text-align: center;
}

.msg-action {
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12px;
  align-self: center;
  text-align: center;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Chat input area ── */
.input-area {
  flex-shrink: 0;
  padding: 10px 16px 14px;
  border-top: 1px solid var(--sidebar-border);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--sidebar-border);
  border-radius: 20px;
  padding: 10px 16px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text);
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.2s;
}

.input-row textarea::placeholder {
  color: var(--muted);
}

.input-row textarea:focus {
  border-color: var(--accent);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
  padding: 0;
}

.icon-btn:hover {
  transform: none;
  box-shadow: none;
}

.send-btn {
  background: var(--accent);
  color: var(--bg);
}

.send-btn:hover {
  background: #aecbfa;
}

/* ── Utilities ── */
.hidden {
  display: none !important;
}

/* ── Mobile responsive ── */
@media (max-width: 768px) {
  #app {
    flex-direction: column;
  }

  .video-area {
    flex: none;
    height: 45vh;
    padding: 8px 8px 72px;
  }

  .video-frame {
    max-width: 100%;
    aspect-ratio: auto;
    height: 100%;
  }

  .pip-container {
    width: 120px;
    height: 90px;
    bottom: 8px;
    right: 8px;
  }

  .toolbar {
    bottom: 8px;
    padding: 6px 10px;
  }

  .toolbar-btn {
    width: 40px;
    height: 40px;
  }

  .toolbar-btn-text span {
    display: none;
  }

  .toolbar-btn-text {
    width: 40px;
    padding: 0;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    height: 55vh;
    border-left: none;
    border-top: 1px solid var(--sidebar-border);
  }

  .sidebar.collapsed {
    height: 0;
  }
}
