/* ===== Global Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Common Components ===== */
.card {
  background: #1a1a2e;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
}

.input-field {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px 16px;
  color: #ffffff;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-field::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.input-field:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn-primary {
  background: #3b82f6;
  color: #ffffff;
  font-weight: 600;
  font-size: 15px;
  padding: 12px 24px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  min-height: 44px;
  min-width: 44px;
  text-decoration: none;
  text-align: center;
}

.btn-primary:hover {
  background: #2563eb;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  background: #1e3a5f;
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
  font-weight: 500;
  font-size: 15px;
  padding: 12px 24px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: background 0.2s ease;
  min-height: 44px;
  min-width: 44px;
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.12);
}

.btn-danger {
  background: #dc2626;
  color: #ffffff;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
  min-height: 44px;
  min-width: 44px;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-success {
  background: #16a34a;
  color: #ffffff;
  font-weight: 600;
  font-size: 14px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  transition: background 0.2s ease;
  min-height: 44px;
  min-width: 44px;
}

.btn-success:hover {
  background: #15803d;
}

.btn-small {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  min-height: 32px;
  min-width: 32px;
  transition: background 0.15s ease;
}

/* ===== Status Bar ===== */
#status-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 48px;
  background: rgba(15, 15, 15, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
}

.status-left {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
}

.status-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 20px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-connected {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.status-connected .status-dot {
  background: #22c55e;
  animation: pulse-green 2s ease-in-out infinite;
}

.status-reconnecting {
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
}

.status-reconnecting .status-dot {
  background: #eab308;
  animation: pulse-yellow 1s ease-in-out infinite;
}

.status-error {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.status-error .status-dot {
  background: #ef4444;
}

@keyframes pulse-green {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

@keyframes pulse-yellow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ===== Main Content Layout ===== */
#main-content {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  bottom: 64px;
  display: flex;
  gap: 0;
}

#slide-container {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

#video-grid {
  width: 240px;
  flex-shrink: 0;
  background: rgba(15, 15, 15, 0.95);
  border-left: 1px solid rgba(255, 255, 255, 0.06);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
}

#video-grid:empty {
  display: none;
}

.video-tile {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background: #1a1a2e;
  border-radius: 8px;
  overflow: hidden;
}

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

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

.video-tile .video-role-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.8);
  color: #fff;
}

/* ===== Bottom Bar ===== */
#bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(15, 15, 15, 0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  z-index: 100;
}

#chat-bar {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

#chat-input {
  flex: 1;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 24px;
  padding: 10px 16px;
  color: #ffffff;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
  min-width: 0;
}

#chat-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

#chat-input:focus {
  border-color: rgba(59, 130, 246, 0.5);
}

#chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #3b82f6;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

#chat-send:hover {
  background: #2563eb;
}

#mic-toggle,
#cam-toggle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

#mic-toggle:hover,
#cam-toggle:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

#mic-toggle.active,
#cam-toggle.active {
  background: rgba(34, 197, 94, 0.2);
  border-color: #22c55e;
  color: #22c55e;
}

#mic-toggle.muted {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #ef4444;
}

/* ===== Spinner ===== */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

/* ===== Disconnect Overlay ===== */
#disconnect-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

/* ===== Utility ===== */
.hidden {
  display: none !important;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Role-Based Visibility ===== */
[data-role="attendee"] #control-panel,
[data-role="attendee"] #control-toggle,
[data-role="attendee"] .presenter-only,
[data-role="attendee"] .host-only {
  display: none !important;
}

[data-role="host"] .presenter-only {
  display: none !important;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #main-content {
    flex-direction: column-reverse;
  }

  #video-grid {
    width: 100%;
    height: 100px;
    flex-direction: row;
    border-left: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    overflow-x: auto;
    overflow-y: hidden;
  }

  #video-grid .video-tile {
    width: 120px;
    height: 100%;
    flex-shrink: 0;
    aspect-ratio: auto;
  }

  #control-panel {
    width: 100% !important;
    right: 0 !important;
    left: 0 !important;
    bottom: 64px !important;
    top: auto !important;
    max-height: 60vh;
    border-radius: 16px 16px 0 0 !important;
    border-left: none !important;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
  }
}

@media (max-width: 480px) {
  #status-bar {
    padding: 0 8px;
  }

  #room-code {
    display: none !important;
  }

  #bottom-bar {
    padding: 0 8px;
  }
}
