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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #1a1a2e;
  color: #e0e0e0;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hidden { display: none !important; }

/* --- Auth Screen --- */
.auth-box {
  background: #16213e;
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.auth-box h1 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 1.8rem;
  color: #4fc3f7;
  letter-spacing: 1px;
}

.tabs {
  display: flex;
  margin-bottom: 24px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #0f3460;
}

.tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.tab.active {
  background: #0f3460;
  color: #4fc3f7;
  font-weight: 600;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form input {
  padding: 12px 14px;
  background: #0f3460;
  border: 1px solid #1a4a8a;
  border-radius: 8px;
  color: #e0e0e0;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  border-color: #4fc3f7;
}

.auth-form button[type="submit"] {
  padding: 12px;
  background: #4fc3f7;
  border: none;
  border-radius: 8px;
  color: #0d0d1a;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s;
}

.auth-form button[type="submit"]:hover {
  background: #29b6f6;
}

.error-msg {
  color: #ef5350;
  font-size: 0.85rem;
  min-height: 1rem;
  text-align: center;
}

.success-msg {
  color: #66bb6a;
  font-size: 0.85rem;
  text-align: center;
}

/* --- Chat Screen --- */
#chat-screen {
  width: 100%;
  height: 100vh;
  display: flex;
}

.sidebar {
  width: 280px;
  min-width: 280px;
  background: #16213e;
  display: flex;
  flex-direction: column;
  border-right: 1px solid #0f3460;
  overflow: hidden;
}

.sidebar-header {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #0f3460;
  gap: 8px;
}

.my-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 6px;
  flex: 1;
  min-width: 0;
  transition: background 0.15s;
}
.my-profile:hover { background: #0f3460; }

.my-profile-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.my-profile-info span:first-child {
  font-weight: 600;
  color: #4fc3f7;
  font-size: 0.95rem;
}

.status-preview {
  font-size: 0.72rem;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#logout-btn {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color 0.2s;
  flex-shrink: 0;
}
#logout-btn:hover { color: #ef5350; }

/* --- Avatar --- */
.avatar-sm {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #0f3460;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #4fc3f7;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-sm img { width: 100%; height: 100%; object-fit: cover; }

.avatar-xs {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #0f3460;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: #4fc3f7;
  flex-shrink: 0;
  overflow: hidden;
}
.avatar-xs img { width: 100%; height: 100%; object-fit: cover; }

.avatar-lg {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: #0f3460;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  font-weight: 700;
  color: #4fc3f7;
  overflow: hidden;
  margin: 0 auto 12px;
}
.avatar-lg img { width: 100%; height: 100%; object-fit: cover; }

/* --- Sidebar Sections --- */
.sidebar-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}

.sidebar-section-header {
  padding: 8px 16px 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #555;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-section-header button {
  background: none;
  border: none;
  color: #4fc3f7;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}
.sidebar-section-header button:hover { color: #81d4fa; }

#user-list, #group-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

#user-list li, #group-list li {
  padding: 8px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 9px;
  transition: background 0.15s;
  border-radius: 8px;
  margin: 1px 6px;
}

#user-list li:hover, #group-list li:hover { background: #0f3460; }
#user-list li.active, #group-list li.active { background: #0f3460; }

.user-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-info .uname { font-size: 0.9rem; font-weight: 500; }
.user-info .ustatus { font-size: 0.72rem; color: #666; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.online  { background: #66bb6a; }
.dot.offline { background: #444; }

.unread-badge {
  margin-left: auto;
  background: #4fc3f7;
  color: #0d0d1a;
  border-radius: 10px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.group-icon {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #1a3a5c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #1a1a2e;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid #0f3460;
  background: #16213e;
  font-weight: 600;
  color: #4fc3f7;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.no-chat {
  color: #555;
  text-align: center;
  margin-top: 40px;
}

.message {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.message.mine {
  align-self: flex-end;
  background: #0f3460;
  border-bottom-right-radius: 4px;
}

.message.theirs {
  align-self: flex-start;
  background: #16213e;
  border-bottom-left-radius: 4px;
}

.message .meta {
  font-size: 0.72rem;
  color: #666;
  margin-top: 4px;
}

.message-form {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid #0f3460;
  background: #16213e;
}

.message-form input {
  flex: 1;
  padding: 12px 16px;
  background: #0f3460;
  border: 1px solid #1a4a8a;
  border-radius: 24px;
  color: #e0e0e0;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}

.message-form input:focus { border-color: #4fc3f7; }

.message-form button[type="submit"] {
  padding: 0 18px;
  background: #4fc3f7;
  border: none;
  border-radius: 24px;
  color: #0d0d1a;
  font-size: 1.2rem;
  cursor: pointer;
  transition: background 0.2s;
}

.message-form button[type="submit"]:hover { background: #29b6f6; }

#mic-btn, #media-btn, #emoji-btn {
  padding: 0 14px;
  background: #1a3a5c;
  border: none;
  border-radius: 24px;
  color: #e0e0e0;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}

#mic-btn:hover, #media-btn:hover, #emoji-btn:hover { background: #0f3460; }

#mic-btn.recording {
  background: #ef5350;
  color: #fff;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
}

.modal-box {
  background: #16213e;
  border-radius: 14px;
  padding: 28px;
  width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2 { font-size: 1.1rem; color: #4fc3f7; }

.modal-close {
  background: none;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 1rem;
  transition: color 0.15s;
}
.modal-close:hover { color: #ef5350; }

.profile-avatar-wrap { text-align: center; margin-bottom: 20px; }

.avatar-upload-btn {
  display: inline-block;
  font-size: 0.82rem;
  color: #4fc3f7;
  cursor: pointer;
  padding: 4px 10px;
  border: 1px solid #0f3460;
  border-radius: 8px;
  transition: background 0.15s;
}
.avatar-upload-btn:hover { background: #0f3460; }

.profile-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.profile-field label { font-size: 0.8rem; color: #888; }

.profile-field input {
  background: #0f3460;
  border: 1px solid #1a4a8a;
  border-radius: 8px;
  color: #e0e0e0;
  padding: 9px 12px;
  font-size: 0.9rem;
  outline: none;
}
.profile-field input:focus { border-color: #4fc3f7; }

.profile-field button, .create-btn {
  padding: 9px 18px;
  background: #4fc3f7;
  border: none;
  border-radius: 8px;
  color: #0d0d1a;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
  align-self: flex-start;
}
.profile-field button:hover, .create-btn:hover { background: #29b6f6; }
.create-btn { width: 100%; align-self: stretch; }

/* Member picker */
.member-picker {
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid #0f3460;
  border-radius: 8px;
  padding: 4px;
}

.member-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s;
}
.member-picker label:hover { background: #0f3460; }
.member-picker input[type="checkbox"] { accent-color: #4fc3f7; }

/* --- Tipp-Indikator --- */
#typing-indicator {
  padding: 4px 24px 0;
  font-size: 0.78rem;
  color: #666;
  height: 18px;
  font-style: italic;
}

/* --- Emoji-Picker --- */
#emoji-picker {
  position: absolute;
  bottom: 70px;
  left: 20px;
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 12px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
  z-index: 50;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  max-width: 300px;
}

#emoji-picker span {
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  text-align: center;
  transition: background 0.15s;
  user-select: none;
}
#emoji-picker span:hover { background: #0f3460; }

/* --- Gelesen-Haken --- */
.msg-status {
  font-size: 0.7rem;
  margin-left: 4px;
}
.msg-status.sent     { color: #555; }
.msg-status.read     { color: #4fc3f7; }

/* --- Bearbeitet-Label --- */
.msg-edited {
  font-size: 0.7rem;
  color: #555;
  font-style: italic;
  margin-left: 4px;
}

/* --- Nachrichten-Aktionen (Hover-Menü) --- */
.message { position: relative; }

.msg-actions {
  display: none;
  position: absolute;
  top: -28px;
  right: 0;
  background: #0f3460;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.message.mine:hover .msg-actions  { display: flex; }

.msg-actions button {
  background: none;
  border: none;
  color: #e0e0e0;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 0.78rem;
  transition: background 0.15s;
}
.msg-actions button:hover { background: #1a4a8a; }
.msg-actions button.del  { color: #ef5350; }

/* Gelöschte Nachricht */
.message.deleted-msg .msg-content {
  color: #555;
  font-style: italic;
}

/* Inline-Edit */
.msg-edit-form {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.msg-edit-form input {
  flex: 1;
  background: #0f3460;
  border: 1px solid #4fc3f7;
  border-radius: 6px;
  color: #e0e0e0;
  padding: 4px 8px;
  font-size: 0.9rem;
  outline: none;
}
.msg-edit-form button {
  background: #4fc3f7;
  border: none;
  border-radius: 6px;
  color: #0d0d1a;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
}

.voice-player {
  display: flex;
  align-items: center;
  gap: 8px;
}

.voice-player audio {
  height: 36px;
  max-width: 220px;
  accent-color: #4fc3f7;
}

.msg-image {
  max-width: 280px;
  max-height: 320px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}

.msg-video {
  max-width: 300px;
  max-height: 240px;
  border-radius: 8px;
  display: block;
}

/* Vollbild-Bildvorschau */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  cursor: zoom-out;
}

#lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 6px;
  object-fit: contain;
}

.upload-progress {
  font-size: 0.8rem;
  color: #4fc3f7;
  padding: 4px 8px;
}

/* --- Call Buttons im Header --- */
.header-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.header-actions button {
  background: #1a3a5c;
  border: none;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.2s;
}
.header-actions button:hover { background: #0f3460; }
#call-btn { color: #66bb6a; }
#video-call-btn { color: #4fc3f7; }
#call-btn.in-call, #video-call-btn.in-call { color: #ef5350; }

/* --- Eingehender Anruf Overlay --- */
#incoming-call {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.call-box {
  background: #16213e;
  border-radius: 16px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.call-avatar {
  font-size: 3rem;
  animation: ring 1s infinite;
}

@keyframes ring {
  0%, 100% { transform: rotate(-15deg); }
  50% { transform: rotate(15deg); }
}

#caller-name-label {
  font-size: 1.2rem;
  font-weight: 600;
  color: #e0e0e0;
}

.call-actions {
  display: flex;
  gap: 16px;
  margin-top: 8px;
}

.call-actions button {
  padding: 12px 24px;
  border: none;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
}

#accept-btn { background: #66bb6a; color: #0d0d1a; }
#accept-btn:hover { background: #4caf50; }
#decline-btn { background: #ef5350; color: #fff; }
#decline-btn:hover { background: #e53935; }

/* --- Aktiver Anruf Leiste --- */
#active-call {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 32px;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 50;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

#call-status-label { color: #66bb6a; font-size: 0.9rem; }
#call-timer { font-family: monospace; font-size: 1rem; color: #e0e0e0; }

#end-call-btn {
  padding: 8px 18px;
  background: #ef5350;
  border: none;
  border-radius: 24px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.9rem;
}
#end-call-btn:hover { background: #e53935; }

/* --- Video-Call Overlay --- */
#video-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

#remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

#local-video {
  position: absolute;
  bottom: 100px;
  right: 20px;
  width: 180px;
  height: 120px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid #4fc3f7;
  background: #111;
}

#video-controls {
  position: absolute;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 16px;
}

#video-controls button {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  transition: background 0.2s;
}

#toggle-mic-btn { background: #1a3a5c; color: #e0e0e0; }
#toggle-mic-btn:hover { background: #0f3460; }
#toggle-mic-btn.muted { background: #555; color: #999; }

#toggle-cam-btn { background: #1a3a5c; color: #e0e0e0; }
#toggle-cam-btn:hover { background: #0f3460; }
#toggle-cam-btn.muted { background: #555; color: #999; }

#screenshare-btn { background: #1a3a5c; color: #e0e0e0; }
#screenshare-btn:hover { background: #0f3460; }
#screenshare-btn.active { background: #4fc3f7; color: #0d0d1a; }

#end-video-btn { background: #ef5350; color: #fff; }
#end-video-btn:hover { background: #e53935; }

#video-status {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: #66bb6a;
  font-size: 0.9rem;
  background: rgba(0,0,0,0.5);
  padding: 4px 14px;
  border-radius: 12px;
}

#video-timer {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  color: #e0e0e0;
  font-family: monospace;
  font-size: 1rem;
  background: rgba(0,0,0,0.5);
  padding: 2px 12px;
  border-radius: 12px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #0f3460; border-radius: 2px; }
