:root {
  --bg-dark: #0b0e14;
  --panel-bg: #151a23;
  --card-bg: #1e2532;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --border-color: #2e3748;
  --danger: #ef4444;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'DM Sans', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background-color: transparent !important;
  color: var(--text-main);
  height: 100%;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

.bg-glow {
  position: absolute;
  width: 300px;
  height: 300px;
  border-radius: 50%;
  filter: blur(120px);
  z-index: 0;
  opacity: 0.25;
  pointer-events: none;
}
.bg-glow-1 { top: -50px; left: -50px; background: var(--accent); }
.bg-glow-2 { bottom: -50px; right: -50px; background: #ec4899; }

.layout {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* SIDEBAR */
.sidebar {
  width: 320px;
  background-color: var(--panel-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.logo {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.4rem;
  font-weight: 700;
}

.logo-accent { color: var(--accent); }

.exit-btn {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.user-profile-badge {
  background: var(--card-bg);
  padding: 8px 12px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.contact-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.2s;
}

.contact-item:hover, .contact-item.active {
  background: var(--card-bg);
}

.avatar {
  position: relative;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: #333;
  flex-shrink: 0;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.status-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  background-color: #22c55e;
  border: 2px solid var(--panel-bg);
  border-radius: 50%;
}

.contact-info { flex: 1; overflow: hidden; }
.contact-name { font-weight: 600; font-size: 0.95rem; }
.contact-preview { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.add-room-btn {
  width: 100%;
  background: var(--card-bg);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s;
}

.add-room-btn:hover {
  background: var(--accent);
}

.private-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.secondary-btn {
  background: var(--card-bg);
  border: 1px solid var(--border-color);
}

.unread-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  background: #ff5c5c;
  border-radius: 50%;
  margin-left: 7px;
  vertical-align: middle;
  box-shadow: 0 0 0 2px var(--panel-bg, transparent);
}

.online-users-list {
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
  text-align: left;
}

.online-user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
}

.online-user-item:hover {
  background: var(--card-bg);
}

.online-user-item img {
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.online-user-item .online-user-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.dm-empty-hint {
  font-size: 0.85rem;
  opacity: 0.6;
  text-align: center;
  padding: 20px 0;
}

.msg-delete-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 4px;
  position: absolute;
  top: 4px;
  right: 6px;
}

.msg-delete-btn:hover {
  color: #ff5c5c;
}

.message {
  position: relative;
}

/* CHAT AREA */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  height: 100%;
  position: relative;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.empty-icon { font-size: 3rem; margin-bottom: 12px; color: var(--accent); }
.empty-title { font-size: 1.2rem; font-weight: 600; color: var(--text-main); }
.empty-subtitle { font-size: 0.9rem; margin-top: 4px; }

.chat-active {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.chat-header {
  height: 60px;
  padding: 0 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.chat-header-info { flex: 1; }
.chat-header-status { font-size: 0.75rem; color: #22c55e; }

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 100%;
}

.msg-row.row-sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-row.row-received {
  align-self: flex-start;
  flex-direction: row;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--card-bg);
}

.message {
  max-width: 70vw;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.95rem;
  position: relative;
  word-break: break-word;
}

.msg-sent {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 2px;
}

.msg-received {
  background: var(--card-bg);
  color: var(--text-main);
  border-bottom-left-radius: 2px;
}

.msg-sender {
  font-size: 0.75rem;
  font-weight: 700;
  color: #a5b4fc;
  margin-bottom: 4px;
}

.msg-image {
  max-width: 100%;
  max-height: 250px;
  border-radius: 8px;
  margin-top: 4px;
  cursor: pointer;
  object-fit: cover;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  font-size: 0.65rem;
  opacity: 0.7;
  margin-top: 4px;
}

/* INPUT AREA VISIBILE IN BASSO */
.chat-input-area {
  padding: 10px 12px;
  background: var(--panel-bg);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.msg-input {
  flex: 1;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 20px;
  outline: none;
  resize: none;
  max-height: 80px;
  font-size: 0.95rem;
}

.icon-btn, .send-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.send-btn {
  background: var(--accent);
  color: white;
  width: 40px;
  height: 40px;
}

.send-btn:disabled {
  background: var(--border-color);
  opacity: 0.5;
}

/* OVERLAY CAMERA ABSOLUTO */
.camera-modal-fullscreen {
  display: none !important;
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  background-color: transparent !important;
  z-index: 9999999 !important;
}

.camera-modal-fullscreen.open {
  display: flex !important;
  flex-direction: column !important;
}

.camera-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  position: relative;
}

.camera-header {
  padding: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.8);
  color: #ffffff;
  z-index: 2;
}

.camera-viewport {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: #000000;
  overflow: hidden;
}

.camera-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-controls {
  padding: 24px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: rgba(0, 0, 0, 0.9);
  z-index: 2;
  min-height: 95px;
}

.camera-shutter {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  border: 5px solid #ffffff;
  background: rgba(255, 255, 255, 0.3);
  cursor: pointer;
  outline: none;
}

.camera-switch-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #ffffff;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
}

/* MODALI GENERALI */
.welcome-modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100vw; height: 100dvh;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.welcome-card {
  background: var(--panel-bg);
  border: 1px solid var(--border-color);
  padding: 24px;
  border-radius: 16px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  position: relative;
}

.welcome-input-group {
  display: flex;
  align-items: center;
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  padding: 10px 14px;
  border-radius: 10px;
  margin: 16px 0;
  gap: 10px;
}

.welcome-input-group input {
  background: none;
  border: none;
  color: white;
  outline: none;
  width: 100%;
}

.welcome-btn {
  width: 100%;
  background: var(--accent);
  color: white;
  border: none;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}

.modal-close-btn {
  position: absolute;
  top: 12px; right: 12px;
  background: none; border: none;
  color: var(--text-muted); font-size: 1.2rem;
  cursor: pointer;
}

/* ANTEPRIMA ALLEGATO */
.image-preview-bar {
  display: none;
  padding: 8px 16px;
  background: var(--panel-bg);
  border-top: 1px solid var(--border-color);
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.image-preview-bar.visible { display: flex; }
.image-preview-wrapper { position: relative; width: 40px; height: 40px; }
.image-preview-wrapper img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.preview-remove {
  position: absolute; top: -5px; right: -5px;
  background: var(--danger); color: white;
  border: none; border-radius: 50%; width: 16px; height: 16px;
  font-size: 0.6rem; cursor: pointer;
}

/* MOBILE RESPONSIVE FIX */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .chat-area { display: none; }
  body.chat-open .sidebar { display: none; }
  body.chat-open .chat-area { 
    display: flex; 
    width: 100%; 
    height: 100dvh; 
  }
}
.layout { background: transparent !important; }
.sidebar { background: rgba(10, 14, 39, 0.75) !important; backdrop-filter: blur(12px) !important; }
.chat-area { background: transparent !important; }
.chat-active { background: transparent !important; }
.messages-container { background: transparent !important; }
.empty-state { background: transparent !important; }
.message-bubble { background: rgba(30, 35, 70, 0.6) !important; backdrop-filter: blur(5px) !important; }
.message-bubble.own { background: rgba(99, 102, 241, 0.2) !important; }
.chat-header { background: rgba(10, 14, 39, 0.8) !important; backdrop-filter: blur(10px) !important; }
.chat-input-area { background: rgba(10, 14, 39, 0.85) !important; backdrop-filter: blur(10px) !important; }

/* ===== PULSANTE BAN MODERATORE ===== */
.msg-ban-btn {
  background: rgba(239, 68, 68, 0.8) !important;
  color: white !important;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  font-size: 0.7rem;
  cursor: pointer;
  margin-left: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.msg-ban-btn:hover {
  background: rgba(220, 38, 38, 1) !important;
  transform: scale(1.1);
}

/* ===== SFONDO STELLATO CON DIV ===== */
#stars-bg {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: linear-gradient(135deg, #050814 0%, #0a0e27 30%, #1a1f4b 60%, #0d1235 100%);
  z-index: -100;
  pointer-events: none;
}

#stars-bg::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-image:
    radial-gradient(2px 2px at 20px 30px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2px 2px at 40px 70px, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 90px 40px, rgba(255,255,255,1), transparent),
    radial-gradient(2px 2px at 160px 120px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 230px 80px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2px 2px at 300px 200px, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 350px 150px, rgba(255,255,255,1), transparent),
    radial-gradient(2px 2px at 450px 250px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 500px 100px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2px 2px at 600px 300px, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 700px 180px, rgba(255,255,255,1), transparent),
    radial-gradient(2px 2px at 800px 220px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 850px 350px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2px 2px at 950px 280px, rgba(255,255,255,0.7), transparent),
    radial-gradient(1px 1px at 1000px 400px, rgba(255,255,255,1), transparent),
    radial-gradient(2px 2px at 1100px 150px, rgba(255,255,255,0.8), transparent),
    radial-gradient(1px 1px at 1200px 350px, rgba(255,255,255,0.9), transparent),
    radial-gradient(2px 2px at 1300px 250px, rgba(255,255,255,0.7), transparent);
  background-repeat: repeat;
  background-size: 1400px 900px;
  animation: twinkle 5s ease-in-out infinite alternate;
}

#stars-bg::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background-image:
    radial-gradient(1px 1px at 100px 100px, rgba(100,200,255,0.6), transparent),
    radial-gradient(2px 2px at 300px 250px, rgba(100,200,255,0.5), transparent),
    radial-gradient(1px 1px at 500px 400px, rgba(100,200,255,0.7), transparent),
    radial-gradient(2px 2px at 700px 550px, rgba(100,200,255,0.4), transparent),
    radial-gradient(1px 1px at 900px 200px, rgba(100,200,255,0.6), transparent);
  background-repeat: repeat;
  background-size: 1400px 1100px;
  animation: twinkle 8s ease-in-out infinite alternate-reverse;
}

@keyframes twinkle {
  0% { opacity: 0.5; }
  50% { opacity: 1; }
  100% { opacity: 0.4; }
}
