/* ============================================
   sidebar.css — Bereich: sidebar
   ============================================ */
.chat-layout {
  /* NEU */
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

.chat-sidebar {
  width: 420px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin-bottom: 20px;
  margin-left: 10px;
  /* Alles in der Sidebar (Name, Avatar, Tabs, Chat-Items, Statustexte)
     nicht markierbar — sieht beim Selektieren sonst doof aus */
  user-select: none;
  -webkit-user-select: none;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-header__user-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.sidebar-header__user-wrapper:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.04));
}

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-header .chat-avatar {
  width: 32px;
  height: 32px;
  font-size: 13px;
  flex-shrink: 0;
}

.sidebar-header .avatar-status {
  display: none;
}

.chat-item.relative .chat-avatar span:first-of-type {
  border-radius: 50%;
}

.sidebar-header__edit-icon {
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.15s;
}

.sidebar-header__user-wrapper:hover .sidebar-header__edit-icon {
  opacity: 1;
}

.sidebar-header__actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  position: relative;
}

.sidebar-header__action-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.sidebar-header__action-btn:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.06));
}

/* User-Menü-Dropdown in der Sidebar-Header-Zeile (Geräte, Benachrichtigungen,
   Abmelden). Wiederholt das send-menu-Muster, öffnet aber nach unten unterhalb
   der Header-Zeile. .chat-sidebar hat overflow:hidden — das Dropdown bleibt
   innerhalt der Sidebar-Box (rechtsbündig, ~220px in 360px), wird also nicht
   abgeschnitten. */
.sidebar-user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 220px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  z-index: 40;
}

.sidebar-user-menu[hidden] {
  display: none;
}

/* FontAwesome setzt display: inline-block auf .fa/.fas — das würde das
   hidden-Attribut des Web-Push-Icons/Spinners (nur display:none mit
   Spezifität 0) außer Kraft setzen. Deshalb explizit hier forcieren. */
.sidebar-user-menu [data-web-push-target="icon"][hidden],
.sidebar-user-menu .web-push__spinner[hidden] {
  display: none;
}

.user-info {
  font-size: 13px;
  color: var(--text-muted);
}

.chat-list {
  flex: 1;
  overflow-y: scroll;
  padding-bottom: 60px;
  position: relative;
  height: 100%;
}

.chat-item {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.2s;
}

.chat-item:hover {
  background: var(--surface-hover);
}

/* Light theme: der --surface-hover ist hier fast unsichtbar (fast weiß).
   Über transparent gemischt, damit das dezent gelbe Pinned-Hintergrund
   beim Hover erhalten bleibt (nicht durch eine deckende Fläche ersetzt
   wird) und die Intensität analog zum Dark-Mode-Hover ist. */
:root:not([data-theme="dark"]) .chat-item:hover {
  background: color-mix(in srgb, var(--text) 8%, transparent);
}

.chat-item.active {
  background: var(--accent);
}

.sidebar-tabs {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.sidebar-tabs input[type="radio"] {
  display: none;
}

.tab-labels {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tab-label {
  flex: 1;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  min-width: 0;
}

.tab-label:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.tab-label i {
  font-size: 16px;
}

#tab-chats:checked~.tab-labels label[for="tab-chats"],
#tab-contacts:checked~.tab-labels label[for="tab-contacts"],
#tab-discover:checked~.tab-labels label[for="tab-discover"] {
  /* Aktiver Tab */
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--surface);
}

.tab-contents {
  /* Tab Inhalte */
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.tab-content {
  flex: 1;
  overflow: hidden;
  display: none;
}

#tab-chats:checked~.tab-contents .tab-content--chats {
  /* Sichtbare Tabs */
  display: flex;
  flex-direction: column;
}

#tab-contacts:checked~.tab-contents .tab-content--contacts {
  display: flex;
  flex-direction: column;
}

#tab-discover:checked~.tab-contents .tab-content--discover {
  display: block;
}

.new-chat {
  border-radius: 50%;
  border: 1px solid var(--border-input);
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 56px;
  height: 56px;
  font-size: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  cursor: pointer;
  color: var(--inverse-text);
}

.new-chat:hover {
  background: var(--primary);
  color: var(--inverse-text);
}

[data-theme="dark"] .new-chat {
  color: var(--on-accent);
}

.tab-content--chats {
  position: relative;
  padding: 0;
}

.tab-content--contacts {
  padding: 0;
  overflow: hidden;
}

/* ─── Contacts Sub-Tabs ─── */
.contacts-subtabs {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.contacts-subtabs input[type="radio"] {
  display: none;
}

.contacts-subtabs__labels {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.contacts-subtabs__label {
  flex: 1;
  padding: 8px 4px;
  text-align: center;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.contacts-subtabs__label:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.contacts-subtabs__label i {
  font-size: 11px;
}

#subtab-contacts:checked~.contacts-subtabs__labels label[for="subtab-contacts"],
#subtab-search:checked~.contacts-subtabs__labels label[for="subtab-search"],
#subtab-blocked:checked~.contacts-subtabs__labels label[for="subtab-blocked"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.contacts-subtabs__contents {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.contacts-subtab {
  display: none;
  padding: 12px 16px;
}

#subtab-contacts:checked~.contacts-subtabs__contents .contacts-subtab--contacts,
#subtab-search:checked~.contacts-subtabs__contents .contacts-subtab--search,
#subtab-blocked:checked~.contacts-subtabs__contents .contacts-subtab--blocked {
  display: block;
}

/* ─── Contact list refinements ─── */
.contacts-list__title {
  margin: 0 0 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 600;
}

.contacts-list__empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 16px 0;
}

.tab-content--discover {
  padding: 16px;
}

.discover-result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.2s;
}

.discover-result:hover {
  background: var(--surface-hover);
}

.discover-result:last-child {
  border-bottom: none;
}

.discover-result__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
  overflow: hidden;
}

.discover-result__avatar .chat-avatar__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.discover-result__info {
  flex: 1;
  min-width: 0;
}

.discover-result__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.discover-result__meta {
  font-size: 12px;
  color: var(--text-muted);
}

.discover-result__join {
  border: none;
  border-radius: 9999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--primary);
  color: var(--inverse-text);
  flex-shrink: 0;
}

.discover-result__join:hover {
  background: var(--primary-dark);
}

.discover-result__join:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: default;
}

.discover-results__empty {
  padding: 16px;
  font-size: 14px;
  text-align: center;
  color: var(--text-muted);
}

.contact-search {
  margin-bottom: 16px;
}

.contact-requests {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.contact-request {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.contact-request:last-child {
  border-bottom: none;
}

.contact-request__avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.contact-request__info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.contact-request__name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-request__meta {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-request__block {
  color: #d9534f;
}

.contact-request__status {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 4px 8px;
  border-radius: 4px;
  background: #f0f0f0;
}

.contact-request--outgoing {
  flex-wrap: wrap;
  opacity: 0.75;
}

.contact-request__actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-basis: 100%;
  margin-left: 44px;
  /* Avatar (34px) + gap (10px) — unter die Info-Spalte */
}

.blocked-users {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.blocked-users__title {
  margin: 0;
  padding: 10px 12px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-light);
}

.blocked-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.blocked-user:last-child {
  border-bottom: none;
}

.blocked-users__empty {
  margin: 0;
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.contact-request__unblock {
  margin-left: auto;
}

.contacts-list {
  margin-bottom: 8px;
}

.contacts-list__list {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
}

.contact-item:last-child {
  border-bottom: none;
}

.contact-search__dropdown {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}

.contact-search__input-wrapper {
  display: flex;
  align-items: center;
  padding: 12px;
  background: var(--surface-hover);
}

.contact-search__input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  padding: 0 8px;
}

.contact-search__input::placeholder {
  color: var(--text-muted);
}

.contact-search__results {
  max-height: 300px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.2s;
}

.search-result-item:hover {
  background: var(--surface-hover);
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

.search-result-info {
  flex: 1;
  min-width: 0;
}

.search-result-name {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  word-break: break-word;
}

.search-result-name strong {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.search-result-username {
  font-size: 12px;
  color: var(--text-muted);
}

.search-result-status {
  font-size: 12px;
}

.search-result-pending,
.search-result-status__pending,
.search-result-status__rejected {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 12px;
  font-weight: 500;
  cursor: default;
}

.search-result-pending,
.search-result-status__pending {
  background: #fef3e4;
  color: #b86700;
}

.search-result-status__rejected {
  background: #fee2e2;
  color: #9f1c1c;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--inverse-text);
  font-weight: 600;
  font-size: 16px;
  position: relative;
  /* overflow: hidden; — bewusst NICHT global: würde den unten-rechts
     positionierten Online-Status-Punkt (.avatar-status, am Rand der Rundung)
     abschneiden. Stattdessen wird der innere Buchstaben-Avatar (span) gerundet
     (siehe .chat-header/.chat-item span:first-of-type). */
}

.sidebar-header .chat-avatar {
  overflow: hidden;
}

.chat-avatar__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--inverse-text);
}

.avatar-status.online {
  background: var(--success);
}

.avatar-status.offline {
  background: var(--muted);
}

.chat-info {
  flex: 1;
  min-width: 0;
}

.chat-name {
  font-weight: 500;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  gap: 6px;
}

/* text-overflow greift auf Flex-Containern nicht — der Text ist ein
   anonymer Flex-Item. Deshalb trägt der Body-Text selbst das Truncating
   (overflow != visible hebt die automatische min-width:auto auf). */
.chat-preview__body {
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-preview__time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-unread {
  margin-left: auto;
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--inverse-text);
  font-size: 12px;
  font-weight: 600;
  line-height: 20px;
  text-align: center;
}

.chat-unread[hidden] {
  display: none;
}

.chat-item__mute {
  position: absolute;
  top: 4px;
  left: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 12px;
  z-index: 2;
}

/* Pin-Fähnchen an gepinnten Items — statisch unten links (Gegenstück zum
   Mute-Icon oben links). Kein Hover-Button mehr: Pin/Unpin lebt im Header. */
.chat-item__pin-flag {
  position: absolute;
  bottom: 4px;
  left: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  color: var(--primary);
  font-size: 12px;
  z-index: 2;
}

.chat-item__pin-flag[hidden] {
  display: none;
}

.chat-item__mute[hidden] {
  display: none;
}

.user-status-badge {
  font-size: 12px;
  color: var(--success);
  font-weight: 500;
}

.subtitle {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.user-status-badge.offline {
  color: var(--muted);
}

.chat-item__restore {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--border-light);
  color: var(--text-light);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  z-index: 2;
}

.chat-item:hover .chat-item__restore {
  display: flex;
}

.chat-item:has(.chat-item__restore):hover .chat-unread {
  /* In archivierten Items: Unread-Badge im Hover unsichtbar machen (statt
   Platz zu schaffen) — visibility behält seinen Platz im Fluss, kein
   Layout-Shift; der Restore-Button überdeckt den Bereich. Das Mute-Icon
   sitzt seitlich vor dem Avatar und ist nicht betroffen. */
  visibility: hidden;
}

.chat-item__restore:hover {
  background: var(--primary);
  color: var(--inverse-text);
}

/* Pinned Items: dezente Hervorhebung */
.chat-item--pinned {
  background: color-mix(in srgb, var(--primary) 4%, transparent);
}

/* Hover auch bei selected erlauben: der GELBE --accent-Hintergrund wird beim
   Hover nur aufgehellt (helleres Gelb) — nicht durch Grau/Oliv ersetzt.
   Die :root:not(...)-Variante (gleiche Spezifität wie der generelle Light-
   Hover, aber später im Dokument) verhindert, dass der graue Ton im Light
   den Selected-Hover überdeckt. */
.chat-item.active:hover,
:root:not([data-theme="dark"]) .chat-item.active:hover {
  background: color-mix(in srgb, var(--accent) 70%, white 30%);
}

[data-theme="dark"] .chat-item.active .chat-name {
  color: var(--on-accent);
}