/* ChaosCamChat - Dark Purple Theme */
:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #2a2a2a;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.15);
  --text: #e0e0e0;
  --text-muted: #888;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', monospace;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Shared Form Styles ─── */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%; max-width: 420px;
}
.auth-card h1 {
  font-size: 1.5rem; font-weight: 700; margin-bottom: 4px;
}
.auth-card h1 .accent { color: var(--accent); }
.auth-card .subtitle {
  color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px;
}
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block; font-size: 0.85rem; color: var(--text-muted);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input {
  width: 100%; padding: 10px 14px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.95rem; font-family: var(--font);
  transition: border-color 0.2s;
}
.form-group input:focus {
  outline: none; border-color: var(--accent);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border: none; border-radius: var(--radius);
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
  font-family: var(--font);
}
.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-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-block { width: 100%; }

.auth-links {
  text-align: center; margin-top: 20px; font-size: 0.88rem; color: var(--text-muted);
}
.auth-links a { color: var(--accent); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }

.divider {
  display: flex; align-items: center; margin: 24px 0; gap: 12px;
  color: var(--text-muted); font-size: 0.85rem;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.error-msg {
  color: #fff; background: var(--danger); font-size: 0.85rem;
  margin-top: 8px; padding: 8px 12px; border-radius: var(--radius);
  display: none;
}

/* ─── Room Layout ─── */
.room-page { display: flex; flex-direction: column; height: 100vh; }

/* Top Bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: 52px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h2 { font-size: 1.05rem; font-weight: 600; }
.topbar-left .room-id {
  font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono);
}
.topbar-center { display: flex; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.participant-count { font-size: 0.85rem; color: var(--text-muted); }

.toggle-btn {
  padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text-muted); cursor: pointer;
  font-size: 0.82rem; font-weight: 500; transition: all 0.2s;
  display: flex; align-items: center; gap: 6px;
  font-family: var(--font);
}
.toggle-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.toggle-btn .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
  transition: background 0.2s;
}
.toggle-btn.active .dot { background: var(--success); }

/* Main Content */
.room-main {
  display: flex; flex: 1; overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-header {
  padding: 12px 16px; font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.sidebar-list {
  flex: 1; overflow-y: auto; padding: 8px 0;
}
.participant-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  font-size: 0.88rem; transition: background 0.15s;
}
.participant-item:hover { background: var(--surface2); }
.participant-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; color: var(--accent); flex-shrink: 0;
}
.participant-info { flex: 1; min-width: 0; }
.participant-name {
  font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.participant-role {
  font-size: 0.72rem; color: var(--text-muted);
}
.participant-badges { display: flex; gap: 4px; }
.badge {
  width: 8px; height: 8px; border-radius: 50%;
}
.badge-cam-on { background: var(--success); }
.badge-cam-off { background: var(--text-muted); }
.badge-mic-on { background: var(--success); }
.badge-mic-off { background: var(--text-muted); }

.mod-actions { display: none; gap: 4px; margin-left: auto; }
.participant-item:hover .mod-actions { display: flex; }
.mod-btn {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 0.7rem; padding: 2px 6px; border-radius: 4px;
  font-family: var(--font);
}
.mod-btn:hover { background: var(--surface2); color: var(--danger); }

/* Chat Column */
.chat-column {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.chat-empty {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 0.9rem;
}
.chat-msg { display: flex; gap: 10px; font-size: 0.9rem; line-height: 1.45; }
.chat-msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; color: var(--accent); flex-shrink: 0;
}
.chat-msg-body { flex: 1; min-width: 0; }
.chat-msg-header { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.chat-msg-name { font-weight: 600; font-size: 0.85rem; }
.chat-msg-time { font-size: 0.72rem; color: var(--text-muted); }
.chat-msg-text { word-break: break-word; }
.chat-msg-emote { color: var(--accent); font-style: italic; }

.system-msg {
  text-align: center; font-size: 0.8rem; color: var(--text-muted);
  padding: 4px 0;
}
.system-msg.announcement {
  color: var(--accent); font-weight: 500;
}

.load-more-btn {
  text-align: center; padding: 8px 16px; margin: 4px 0 12px 0;
  font-size: 0.82rem; color: var(--accent); cursor: pointer;
  border-radius: var(--radius); background: var(--accent-soft);
  transition: background 0.2s; user-select: none;
}
.load-more-btn:hover { background: rgba(124, 58, 237, 0.25); }

/* Chat Input */
.chat-input-area {
  padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border);
  display: flex; gap: 10px; flex-shrink: 0;
}
.chat-input-area input {
  flex: 1; padding: 10px 14px; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 20px;
  color: var(--text); font-size: 0.9rem; font-family: var(--font);
}
.chat-input-area input:focus { outline: none; border-color: var(--accent); }
.chat-input-area .btn { border-radius: 20px; padding: 8px 18px; }
.emote-toggle {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1.1rem; padding: 0 8px; transition: color 0.2s;
}
.emote-toggle.emoting { color: var(--accent); }

/* Cam Grid */
.cam-panel {
  width: 0; overflow: hidden; background: var(--surface);
  border-left: 1px solid var(--border); display: flex;
  flex-direction: column; transition: width 0.3s;
}
.cam-panel.open { width: 360px; }
.cam-panel-header {
  padding: 12px 16px; font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
}
.cam-grid {
  flex: 1; display: grid; grid-template-columns: 1fr 1fr;
  grid-auto-rows: 160px; gap: 8px; padding: 12px; overflow-y: auto;
  align-content: start;
}
.cam-placeholder {
  grid-column: 1 / -1;
  background: var(--surface2); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 0.8rem;
  border: 1px dashed var(--border); min-height: 120px;
}
.cam-video {
  position: relative; border-radius: var(--radius); overflow: hidden;
  background: #000; display: flex; align-items: center; justify-content: center;
}
.cam-video[data-sid="local"] { border: 2px solid var(--accent); }
.cam-feed {
  width: 100%; height: 100%; object-fit: cover;
}
.cam-label {
  position: absolute; bottom: 6px; left: 6px;
  background: rgba(0,0,0,0.7); color: var(--text);
  padding: 2px 8px; border-radius: 4px; font-size: 0.7rem;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}

/* Room List (for index post-login) */
.room-list-page { padding: 40px 20px; max-width: 800px; margin: 0 auto; }
.room-list-page h2 { margin-bottom: 20px; }
.room-list { display: flex; flex-direction: column; gap: 10px; }
.room-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; transition: border-color 0.2s;
}
.room-card:hover { border-color: var(--accent); }
.room-card-info h3 { font-size: 1rem; margin-bottom: 4px; }
.room-card-info p { font-size: 0.82rem; color: var(--text-muted); }
.room-card-meta { text-align: right; font-size: 0.82rem; color: var(--text-muted); }
.room-card-meta .live { color: var(--success); }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .cam-panel.open { width: 280px; }
}
@media (max-width: 600px) {
  .room-main { flex-direction: column; }
  .sidebar { width: 100%; max-height: 160px; border-right: none; border-bottom: 1px solid var(--border); }
  .cam-panel.open { width: 100%; max-height: 240px; border-left: none; border-top: 1px solid var(--border); }
  .chat-column { order: -1; min-height: 300px; }
}

/* Utility */
.hidden { display: none !important; }
.fade-in { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Toast (verbessert: länger, Close-Button, Stacking) */
.toast-container {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px; max-width: 380px;
}
.toast {
  padding: 12px 36px 12px 16px; border-radius: var(--radius); color: #fff;
  font-size: 0.88rem; box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  animation: slideIn 0.3s ease; position: relative; word-break: break-word;
}
.toast-close {
  position: absolute; top: 8px; right: 8px; background: none; border: none;
  color: rgba(255,255,255,0.7); cursor: pointer; font-size: 1rem; padding: 0;
  line-height: 1; width: 20px; height: 20px; display: flex; align-items: center;
  justify-content: center; border-radius: 50%;
}
.toast-close:hover { background: rgba(255,255,255,0.2); color: #fff; }
.toast-error { background: var(--danger); }
.toast-info { background: var(--accent); }
.toast-success { background: var(--success); }

/* Error Banner (persistent, oben, dismissable) */
.error-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9998;
  background: var(--danger); color: #fff; padding: 14px 40px 14px 16px;
  font-size: 0.9rem; text-align: center; box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.error-banner-close {
  position: absolute; top: 10px; right: 12px; background: none; border: none;
  color: rgba(255,255,255,0.7); cursor: pointer; font-size: 1.1rem; padding: 0;
}
.error-banner-close:hover { color: #fff; }

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

/* Context Menu */
.context-menu {
  position: fixed; z-index: 10000; min-width: 160px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  padding: 4px 0; display: none; animation: fadeIn 0.15s ease;
}
.context-menu-item {
  padding: 8px 16px; font-size: 0.85rem; color: var(--text-primary);
  cursor: pointer; display: flex; align-items: center; gap: 8px;
  transition: background 0.1s;
}
.context-menu-item:hover { background: var(--bg-surface); color: var(--accent); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item.danger:hover { background: rgba(239,68,68,0.1); }
.context-menu-separator { height: 1px; background: var(--border); margin: 4px 0; }

/* Room Card */
.room-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.room-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.room-card-banner {
  padding: 24px 16px; font-size: 1.1rem; font-weight: 600; color: #fff;
  text-align: center; min-height: 40px; display: flex;
  align-items: center; justify-content: center;
}
.room-card-body {
  padding: 12px 16px; display: flex; justify-content: space-between;
  align-items: center; gap: 12px;
}
.room-card-info h3 { font-size: 0.95rem; margin-bottom: 2px; }
.room-card-info p {
  color: var(--text-muted); font-size: 0.8rem; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px;
}
.room-card-meta { flex-shrink: 0; text-align: right; }
