/* Chat (chat.ts): Kopfzeile, Nachrichten als Sprechblasen, Eingabe unten */
#chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line-soft);
}
.chat-header h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-header h2 .icon {
  width: 16px;
  height: 16px;
}

.chat-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
}
.chat-sound {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
}
.chat-tools button.danger,
.chat-tools button.link.danger {
  color: var(--bad);
}

/* ---- Nachrichten ---- */
.chat-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  padding: 16px;
  overflow-y: auto;
}
.chat-list:empty::before {
  content: 'Noch keine Nachrichten. Sag Hallo! 👋';
  margin: auto;
  color: var(--faint);
}

.chat-msg {
  position: relative; /* für die Leiste beim Darüberfahren */
  flex: none; /* nicht zusammenquetschen, die Liste scrollt stattdessen */
  max-width: 86%;
  padding: 8px 12px 7px;
  background: var(--panel-2);
  border-radius: 16px 16px 16px 6px;
}
.chat-msg.mine {
  align-self: flex-end;
  background: linear-gradient(135deg, #6d5ff5, #4f63e8);
  border-radius: 16px 16px 6px 16px;
}
.chat-msg.theirs {
  align-self: flex-start;
}

.chat-meta {
  display: flex;
  gap: 8px;
  margin-bottom: 2px;
  font-size: 11.5px;
  color: var(--muted);
}
.chat-msg.mine .chat-meta {
  justify-content: flex-end;
  color: rgb(255 255 255 / 0.72);
}
.chat-name {
  font-weight: 700;
}

.chat-text {
  white-space: pre-wrap; /* Zeilenumbrüche der Nachricht bleiben */
  overflow-wrap: anywhere;
}

.chat-state {
  margin-top: 2px;
  font-size: 11px;
  text-align: right;
}
.chat-state:empty {
  display: none;
}
.chat-state[data-state='delivered'] {
  color: rgb(255 255 255 / 0.75);
}
.chat-state[data-state='waiting'] {
  color: #fde68a;
}

/* ---- Eingabe ---- */
.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line-soft);
}
.chat-input {
  flex: 1;
  min-width: 0;
  max-height: 140px;
  padding: 10px 12px;
  line-height: 1.4;
  resize: none;
}
.chat-send {
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
}

.chat-attach {
  flex: none;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
}
.chat-attach .icon,
.chat-send .icon {
  width: 18px;
  height: 18px;
}

/* Hinweis über der Eingabe (z. B. „Dateien gehen nur, wenn …“) */
.chat-notice {
  margin: 0 16px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: #fde68a;
  background: rgb(251 191 36 / 0.1);
  border-radius: var(--radius-s);
}

/* Datei ins Chatfenster ziehen */
#chat.dragging {
  outline: 2px dashed var(--accent);
  outline-offset: -8px;
  background: var(--accent-soft);
}

/* ---- Dateien im Verlauf ---- */
.chat-file {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  min-width: 220px;
}
.chat-thumb {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  object-fit: contain;
}
.chat-msg.theirs .chat-thumb[title] {
  cursor: zoom-in;
}
.chat-file-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.chat-file-icon {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  background: rgb(255 255 255 / 0.1);
  border-radius: 10px;
}
.chat-file-icon .icon {
  width: 18px;
  height: 18px;
}
.chat-file-text {
  min-width: 0;
}
.chat-file-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-file-size {
  font-size: 12px;
  opacity: 0.75;
}
.chat-progress {
  width: 100%;
  height: 6px;
  accent-color: var(--accent-2);
}
.chat-file-actions {
  display: flex;
  gap: 14px;
  font-size: 12.5px;
}
.chat-msg.theirs .chat-file-actions .link {
  color: var(--accent-2);
}
.chat-state[data-state='failed'] {
  color: var(--bad);
}
.chat-msg.mine .chat-state[data-state='failed'] {
  color: #fecaca;
}

/* ---- Wie bei Discord: Leiste beim Darüberfahren, Reaktionen, Antworten, Bearbeiten, Löschen, Links ---- */
.chat-actions {
  position: absolute;
  top: -15px;
  left: 8px; /* fremde Nachrichten stehen links: Leiste wächst nach rechts */
  z-index: 1;
  display: none;
  gap: 2px;
  padding: 3px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-s);
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.35);
}
.chat-msg.mine .chat-actions {
  left: auto;
  right: 8px;
}
.chat-msg:hover > .chat-actions,
.chat-msg:focus-within > .chat-actions {
  display: flex;
}
.chat-action {
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 15px;
  color: var(--muted);
  background: none;
  border-radius: 7px;
}
.chat-action:hover {
  color: var(--text);
  background: var(--panel-2);
  filter: none;
}
.chat-action .icon {
  width: 16px;
  height: 16px;
}
.chat-action.danger {
  width: auto;
  padding: 0 10px;
  font-size: 12px;
  color: #fff;
  background: #e5484d; /* auch beim Darüberfahren rot */
}

.chat-edited {
  opacity: 0.8;
}

.chat-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.chat-reactions:empty {
  display: none;
}
.chat-reaction {
  padding: 1px 8px;
  font-size: 12.5px;
  color: inherit;
  background: rgb(255 255 255 / 0.08);
  border: 1px solid transparent;
  border-radius: 999px;
}
.chat-reaction:hover {
  border-color: rgb(255 255 255 / 0.3);
  filter: none;
}
.chat-reaction.mine {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.chat-msg.mine .chat-reaction.mine {
  background: rgb(255 255 255 / 0.22);
  border-color: rgb(255 255 255 / 0.75);
}

/* Zitat in einer Antwort */
.chat-quote {
  justify-content: flex-start;
  gap: 6px;
  max-width: 100%;
  margin: 2px 0 4px;
  padding: 1px 0 1px 8px;
  font-size: 12.5px;
  font-weight: 400;
  color: inherit;
  text-align: left;
  background: none;
  border-left: 2px solid rgb(255 255 255 / 0.35);
  border-radius: 0;
  opacity: 0.8;
}
.chat-quote:hover {
  opacity: 1;
  filter: none;
}
.chat-quote-name {
  flex: none;
  font-weight: 700;
}
.chat-quote-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* Nach Klick auf ein Zitat leuchtet die ursprüngliche Nachricht kurz auf */
.chat-msg.chat-flash {
  animation: chat-flash 1.5s ease-out;
}
@keyframes chat-flash {
  from {
    box-shadow: 0 0 0 3px var(--accent-2);
  }
  to {
    box-shadow: 0 0 0 3px transparent;
  }
}

.chat-msg.deleted .chat-text {
  font-style: italic;
  color: var(--muted);
}
.chat-msg.mine.deleted {
  background: var(--panel-2);
}
.chat-msg.mine.deleted .chat-meta {
  color: var(--muted);
}

.chat-link {
  color: var(--accent-2);
  text-underline-offset: 2px;
}
.chat-msg.mine .chat-link {
  color: #fff;
}

/* „<Name> schreibt …“ liegt im unteren Innenabstand der Liste (16px): nimmt ihr keinen Platz weg, nichts springt */
.chat-typing {
  position: relative; /* über den Nachrichten (die sind selbst positioniert) */
  height: 16px;
  margin-top: -16px;
  padding: 0 16px;
  overflow: hidden;
  font-size: 12px;
  font-style: italic;
  line-height: 16px;
  pointer-events: none; /* Klicks und Scrollen gehen an die Liste darunter */
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}
.chat-typing:not(:empty) {
  background: var(--surface);
}

/* Leiste über der Eingabe beim Antworten bzw. Bearbeiten; hängt optisch an der Eingabe */
.chat-compose {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 8px 0 16px;
  border-top: 1px solid var(--line-soft);
}
.chat-compose:not([hidden]) + .chat-form {
  padding-top: 8px;
  border-top: 0;
}
.chat-compose-info {
  flex: 1;
  min-width: 0;
  padding: 4px 10px;
  border-left: 3px solid var(--accent);
}
.chat-compose-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.chat-compose-text {
  overflow: hidden;
  font-size: 12.5px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-compose-cancel {
  flex: none; /* sonst wie die Knöpfe der Leiste (.chat-action) */
}

/* Schmale Fenster: Chat mit fester Höhe */
@media (max-width: 759px) {
  .chat-list {
    height: 280px;
    flex: none;
  }
}
