/* ── Kollegiumschat + Direktnachrichten ───────────────────────────────── */

/* ── Two-panel layout ─────────────────────────────────────────────────── */
/* Chat fills the content area edge-to-edge and never relies on 100vh math
   (which is unreliable on mobile browsers with a collapsing URL bar). */
.content-pad:has(.chat-layout) {
  padding: 0;
  max-width: none;
  height: 100%;
}
.chat-layout {
  display: flex;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

/* ── DM thread list (left panel) ─────────────────────────────────────── */
.dm-list {
  width: 240px;
  flex: none;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
}

.dm-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
  border-bottom: 1px solid var(--border);
  flex: none;
}

.dm-list-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-3);
  padding: 10px 14px 5px;
}

.dm-sep {
  height: 1px;
  background: var(--border);
  margin: 6px 0;
  flex: none;
}

.dm-thread {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  border-radius: 0;
  transition: background .12s;
  position: relative;
}
.dm-thread:hover { background: var(--surface-2); }
.dm-thread.active { background: var(--accent-soft); }
.dm-thread.active .dm-thread-name { color: var(--accent); }

.dm-group-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
.dm-group-icon.sm { width: 24px; height: 24px; border-radius: 50%; }

.dm-thread-body { flex: 1; min-width: 0; }
.dm-thread-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-thread-sub {
  font-size: 11px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.dm-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  height: 18px;
  min-width: 18px;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex: none;
}
.dm-badge-total {
  background: var(--coral, #ef4444);
}

/* ── Message pane (right panel) ───────────────────────────────────────── */
.dm-pane {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.dm-pane-head {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  flex: none;
}

.dm-back-btn {
  display: none; /* shown on mobile */
  background: none;
  border: none;
  color: var(--text-2);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}
.dm-back-btn:hover { background: var(--surface-2); }

/* ── Messages ─────────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-2);
  font-size: 14px;
  padding: 40px 0;
  text-align: center;
}

.chat-date-sep {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0 8px;
  color: var(--text-3);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .04em;
}
.chat-date-sep::before,
.chat-date-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.chat-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 72%;
}
.chat-msg.me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.chat-bubble {
  background: var(--surface-2);
  border-radius: 14px 14px 14px 4px;
  padding: 8px 12px;
  max-width: 100%;
  position: relative;
}
.chat-msg.me .chat-bubble {
  background: var(--accent);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
}

.chat-sender-name {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-3);
  margin-top: 3px;
  padding-left: 4px;
}
.chat-sender-name.me {
  text-align: right;
  padding-left: 0;
  padding-right: 4px;
}

.chat-text {
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-ts {
  font-size: 10.5px;
  color: var(--text-3);
  margin-top: 3px;
  text-align: right;
}
.chat-msg.me .chat-ts { color: rgba(255,255,255,.7); }

/* ── Composer ─────────────────────────────────────────────────────────── */
.chat-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

.chat-input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.chat-input:focus { border-color: var(--accent); }

/* ── File attachments ─────────────────────────────────────────────────── */
.chat-attach-btn {
  flex: none;
  color: var(--text-3);
}
.chat-attach-btn:hover { color: var(--accent); }

.chat-pending-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: var(--accent-soft);
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.chat-pending-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.chat-pending-rm {
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--text-2);
  cursor: pointer;
  padding: 0 4px;
}
.chat-pending-rm:hover { color: var(--coral, #ef4444); }

.chat-attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: rgba(0,0,0,.06);
  border-radius: 8px;
  margin-top: 4px;
  text-decoration: none;
  color: var(--text);
  transition: background .12s;
}
.chat-attachment:hover { background: rgba(0,0,0,.12); }
.chat-attachment.me {
  background: rgba(255,255,255,.18);
  color: #fff;
}
.chat-attachment.me:hover { background: rgba(255,255,255,.28); }

.chat-att-icon { font-size: 20px; flex: none; line-height: 1; }
.chat-att-body { flex: 1; min-width: 0; }
.chat-att-name {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-att-label { font-size: 11px; opacity: .65; margin-top: 1px; }
.chat-att-dl { font-size: 16px; font-weight: 700; flex: none; opacity: .7; }

/* ── Message hover actions (edit / delete own messages) ───────────────── */
.chat-bubble { position: relative; }
.chat-msg-actions {
  position: absolute;
  top: -10px;
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--sh-1);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s;
  z-index: 2;
}
.chat-msg.me .chat-msg-actions { left: -6px; }
.chat-msg:not(.me) .chat-msg-actions { right: -6px; }
.chat-msg:hover .chat-msg-actions { opacity: 1; pointer-events: auto; }
.chat-act-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border: none;
  background: transparent;
  color: var(--text-2);
  border-radius: 6px;
  cursor: pointer;
  transition: background .12s, color .12s;
}
.chat-act-btn:hover { background: var(--surface-2); color: var(--accent); }
.chat-act-btn[title="Löschen"]:hover { color: var(--coral, #ef4444); }

/* ── Inline edit box ──────────────────────────────────────────────────── */
.chat-edit-box { display: flex; flex-direction: column; gap: 6px; min-width: 200px; }
.chat-edit-input {
  width: 100%;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  outline: none;
  line-height: 1.4;
}
.chat-msg.me .chat-edit-input { color: var(--text); }
.chat-edit-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* ── Read receipts (DM ✓ / ✓✓) ────────────────────────────────────────── */
.chat-receipt { margin-left: 5px; font-size: 11px; opacity: .8; }
.chat-msg.me .chat-receipt { color: rgba(255,255,255,.7); }
.chat-receipt.read { color: #7CC0FF; opacity: 1; }
.chat-msg.me .chat-receipt.read { color: #8fd0ff; }

/* ── Typing indicator ─────────────────────────────────────────────────── */
.chat-typing {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 8px 2px; font-size: 12.5px; color: var(--text-3); font-weight: 600;
}
.chat-typing-dots { display: inline-flex; gap: 3px; }
.chat-typing-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-3);
  display: inline-block; animation: chat-typing-bounce 1.2s infinite ease-in-out;
}
.chat-typing-dots i:nth-child(2) { animation-delay: .15s; }
.chat-typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-typing-bounce { 0%,60%,100%{ transform: translateY(0); opacity:.4 } 30%{ transform: translateY(-4px); opacity:1 } }

/* ── Reactions ────────────────────────────────────────────────────────── */
.chat-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.chat-msg.me .chat-reactions { justify-content: flex-end; }
.chat-react-chip {
  display: inline-flex; align-items: center; gap: 3px;
  height: 22px; padding: 0 7px;
  border: 1px solid var(--glass-border-2, var(--border));
  background: var(--glass-bg-soft, var(--surface-2));
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 999px; cursor: pointer; font-size: 12px;
  color: var(--text-2); transition: transform .1s, background .12s;
}
.chat-react-chip:hover { transform: scale(1.08); }
.chat-react-chip.mine { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chat-react-chip .cr-emoji { font-size: 13px; line-height: 1; }
.chat-react-chip .cr-count { font-weight: 700; }

/* ── Emoji picker (hover-popover on a message) ────────────────────────── */
.chat-emoji-picker {
  position: absolute; top: -42px; z-index: 5;
  display: flex; gap: 2px; padding: 5px 7px;
  background: var(--glass-bg-strong, var(--surface));
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border, var(--border));
  border-radius: 999px; box-shadow: var(--glass-sh-pop, var(--sh-3));
}
.chat-msg.me .chat-emoji-picker { right: 0; }
.chat-msg:not(.me) .chat-emoji-picker { left: 0; }
.chat-emoji-opt {
  border: none; background: transparent; cursor: pointer;
  font-size: 19px; line-height: 1; padding: 3px; border-radius: 8px;
  transition: transform .1s, background .12s;
}
.chat-emoji-opt:hover { transform: scale(1.25); background: var(--surface-2); }

/* ── Voice messages ───────────────────────────────────────────────────── */
.chat-mic-btn { flex: none; color: var(--text-2); }
.chat-mic-btn:hover { color: var(--accent); }

.chat-voice {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px; min-width: 220px;
}
.chat-voice-icon { font-size: 17px; flex: none; }
.chat-voice-audio { height: 34px; max-width: 240px; flex: 1; }
.chat-msg.me .chat-voice-audio { filter: invert(0); }

/* Recording bar (replaces composer while recording) */
.chat-recording { gap: 10px; }
.chat-rec-cancel { flex: none; color: var(--coral, #ef4444); }
.chat-rec-dot {
  width: 11px; height: 11px; border-radius: 50%; background: var(--coral, #ef4444);
  flex: none; animation: chat-rec-pulse 1s infinite;
}
@keyframes chat-rec-pulse { 0%,100%{ opacity:1 } 50%{ opacity:.3 } }
.chat-rec-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 14px; color: var(--text); }
.chat-rec-label { font-size: 13px; color: var(--text-3); }
.chat-rec-send { flex: none; }

/* ── @Mentions ────────────────────────────────────────────────────────── */
.chat-mention {
  color: var(--accent);
  font-weight: 700;
  background: var(--accent-soft);
  padding: 0 3px; border-radius: 5px;
}
.chat-msg.me .chat-mention {
  color: #fff; background: rgba(255,255,255,.22);
}
.chat-mention.me { box-shadow: 0 0 0 1.5px var(--accent); }

.chat-mention-menu {
  display: flex; flex-direction: column;
  margin: 0 16px; border: 1px solid var(--glass-border, var(--border));
  background: var(--glass-bg-strong, var(--surface));
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: var(--r-md); box-shadow: var(--glass-sh-pop, var(--sh-3));
  overflow: hidden;
}
.chat-mention-opt {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px; border: none; background: transparent;
  cursor: pointer; text-align: left; width: 100%;
}
.chat-mention-opt:hover { background: var(--accent-soft); }
.chat-mention-name { font-size: 14px; font-weight: 600; color: var(--text); }

/* ── Reply / quote ────────────────────────────────────────────────────── */
/* Quoted block inside a bubble */
.chat-quote {
  display: flex; flex-direction: column; gap: 1px;
  border-left: 3px solid var(--accent);
  padding: 4px 8px; margin-bottom: 5px;
  background: rgba(0,0,0,.05); border-radius: 5px;
  font-size: 12.5px; max-width: 100%;
}
.chat-msg.me .chat-quote { border-left-color: rgba(255,255,255,.7); background: rgba(255,255,255,.14); }
.chat-quote-name { font-weight: 700; color: var(--accent); }
.chat-msg.me .chat-quote-name { color: #fff; }
.chat-quote-text {
  color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px;
}
.chat-msg.me .chat-quote-text { color: rgba(255,255,255,.8); }

/* Reply bar above composer */
.chat-reply-bar {
  display: flex; align-items: center; gap: 9px;
  margin: 0 16px 6px; padding: 7px 12px;
  background: var(--glass-bg-soft, var(--surface-2));
  border-left: 3px solid var(--accent);
  border-radius: 8px; color: var(--accent);
}
.chat-reply-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-reply-to { font-size: 12px; font-weight: 700; color: var(--accent); }
.chat-reply-snippet { font-size: 12.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-reply-cancel {
  border: none; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--text-2); padding: 0 4px; flex: none;
}
.chat-reply-cancel:hover { color: var(--coral, #ef4444); }

/* ── Search in conversation ───────────────────────────────────────────── */
.chat-search-btn { flex: none; color: var(--text-2); }
.chat-search-btn.on { color: var(--accent); }
.chat-search-input {
  height: 32px; padding: 0 12px; margin-right: 4px;
  border: 1.5px solid var(--accent); border-radius: 999px;
  background: var(--glass-bg-soft, var(--surface-2)); color: var(--text);
  font-size: 13.5px; outline: none; width: 200px; max-width: 40vw;
}
.chat-hl { background: #ffe27a; color: #4a3b00; border-radius: 3px; padding: 0 1px; }
:root[data-theme="dark"] .chat-hl { background: #6b5a14; color: #fff; }

/* ── Pinned messages ──────────────────────────────────────────────────── */
.chat-act-btn.on { color: var(--accent); }
.chat-pinned-bar {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 16px; flex: none;
  background: var(--glass-bg-soft, var(--surface-2));
  border-bottom: 1px solid var(--glass-border-2, var(--border));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.chat-pinned-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); }
.chat-pinned-item svg { color: var(--accent); flex: none; }
.chat-pinned-name { font-weight: 700; color: var(--text); flex: none; }
.chat-pinned-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.chat-pinned-rm { border: none; background: none; cursor: pointer; color: var(--text-3); font-size: 16px; line-height: 1; padding: 0 4px; flex: none; }
.chat-pinned-rm:hover { color: var(--coral, #ef4444); }

/* ── Last seen (DM header) ────────────────────────────────────────────── */
.dm-head-meta { display: flex; flex-direction: column; line-height: 1.2; }
.dm-lastseen { font-size: 11.5px; color: var(--text-3); font-weight: 500; margin-top: 1px; }

/* ── Group read count ─────────────────────────────────────────────────── */
/* reuses .chat-receipt.read styling */

/* ── Global search (thread list) ──────────────────────────────────────── */
.dm-search {
  display: flex; align-items: center; gap: 7px;
  margin: 8px 12px; padding: 0 10px; height: 34px;
  background: var(--glass-bg-soft, var(--surface-2));
  border: 1px solid var(--glass-border-2, var(--border));
  border-radius: 999px; color: var(--text-3); flex: none;
}
.dm-search input { flex: 1; border: none; background: none; outline: none; font-size: 13px; color: var(--text); }
.dm-search-x { border: none; background: none; cursor: pointer; color: var(--text-3); font-size: 17px; line-height: 1; padding: 0 2px; }
.dm-search-x:hover { color: var(--coral, #ef4444); }

.dm-results { overflow-y: auto; flex: 1; }
.dm-results-empty { padding: 24px 14px; text-align: center; color: var(--text-3); font-size: 13px; }
.dm-result {
  display: flex; flex-direction: column; gap: 3px; width: 100%;
  padding: 9px 14px; border: none; background: transparent; cursor: pointer; text-align: left;
  border-bottom: 1px solid var(--glass-border-2, var(--border));
}
.dm-result:hover { background: var(--glass-bg-soft, var(--surface-2)); }
.dm-result-head { display: flex; align-items: center; gap: 6px; }
.dm-result-head svg, .dm-result-head .dm-group-icon { color: var(--accent); }
.dm-result-label { font-size: 12.5px; font-weight: 700; color: var(--text); flex: 1; }
.dm-result-time { font-size: 11px; color: var(--text-3); }
.dm-result-text { font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Mobile: single-panel switching ──────────────────────────────────── */
@media (max-width: 700px) {
  .dm-list   { width: 100%; border-right: none; }
  .dm-pane   { width: 100%; }
  .mobile-hidden { display: none; }
  .dm-back-btn { display: flex; }
}

/* ── Klasseliste card in chat ─────────────────────────────────────────── */
.chat-kl-card {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: 14px; max-width: 300px; margin: 4px 0;
  background: color-mix(in srgb, #4f46e5 8%, var(--bg));
  border: 1.5px solid color-mix(in srgb, #4f46e5 28%, var(--border));
  text-decoration: none; cursor: pointer; transition: all .15s;
}
.chat-kl-card:hover {
  border-color: #4f46e5;
  background: color-mix(in srgb, #4f46e5 14%, var(--bg));
  transform: translateY(-1px);
  box-shadow: 0 4px 14px color-mix(in srgb, #4f46e5 20%, transparent);
}
.chat-kl-icon { font-size: 26px; flex-shrink: 0; }
.chat-kl-info { display: flex; flex-direction: column; gap: 3px; flex: 1; min-width: 0; }
.chat-kl-title { font-size: 13px; font-weight: 700; color: var(--text-1); }
.chat-kl-sub   { font-size: 11px; color: var(--text-3); }
.chat-kl-arrow { font-size: 20px; color: #4f46e5; font-weight: 700; flex-shrink: 0; line-height: 1; }
