/* ── Chat layout ─────────────────────────────────────────────── */
#chat-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

/* ── Floating profile button ─────────────────────────────────── */
#my-profile-btn {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 200;
  width: 36px;
  height: 36px;
  background: var(--surface2);
  border: 1.5px solid var(--border-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  font-family: var(--font);
  color: var(--text);
  text-transform: uppercase;
  transition: border-color 0.12s, background 0.12s;
  padding: 0;
  overflow: hidden;
}
#my-profile-btn:hover { border-color: var(--accent); background: var(--surface3); }
#my-profile-btn img   { width: 100%; height: 100%; object-fit: cover; }

/* ── Message feed ────────────────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 3.5rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Message group ───────────────────────────────────────────── */
.msg-group {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.15rem 1.25rem;
  position: relative;
}
.msg-group:hover              { background: rgba(255,255,255,0.025); }
.msg-group + .msg-group       { margin-top: 0; }
.msg-group.follow-up          { padding-top: 0.05rem; padding-bottom: 0.05rem; }
.msg-group.follow-up .msg-avatar { visibility: hidden; }
.msg-group.follow-up .msg-header { display: none; }

.msg-avatar {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
  margin-top: 0.15rem;
  user-select: none;
  text-transform: uppercase;
  overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.1rem;
}

.msg-author                    { font-size: 0.88rem; font-weight: 700; color: var(--text); }
.msg-group.is-me .msg-author   { color: var(--accent); }
.msg-timestamp                 { font-size: 0.68rem; color: var(--muted); }

.msg-bubble {
  display: inline-block;
  max-width: min(560px, 72vw);
  padding: 0.4rem 0.65rem;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-group.is-me .msg-bubble {
  background: rgba(224, 122, 95, 0.12);
  border-left: 2px solid var(--accent);
  padding-left: 0.6rem;
}

.msg-system {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 0.4rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.msg-system::before,
.msg-system::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Message wrapper (double-tap target, full width) ─────────── */
/* Every piece of content (text, image, file, audio, pdf) sits   */
/* inside a msg-wrapper so the entire row width is tappable.     */
.msg-wrapper {
  display: flex;
  flex-direction: column;
  width: 100%;
  border-radius: 0;
  position: relative;
  /* subtle hover hint that it's interactive */
  transition: background 0.1s;
}
.msg-wrapper:hover {
  background: rgba(255,255,255,0.03);
}

/* ── Inline image ────────────────────────────────────────────── */
.img-preview {
  max-width: 300px;
  max-height: 220px;
  display: block;
  cursor: pointer;
  object-fit: cover;
}
.img-preview:hover { opacity: 0.9; }

/* Saved image — persistent, accent bottom border to mark it as server-stored */
.img-preview--saved {
  border-bottom: 2px solid var(--accent);
}

/* ── Video thumbnail (saved files) ──────────────────────────── */
.video-thumb {
  position: relative;
  display: inline-block;
  max-width: 300px;
  line-height: 0;
  cursor: pointer;
}
.video-thumb video {
  max-width: 300px;
  max-height: 220px;
  display: block;
  object-fit: cover;
}
.video-thumb-play {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: rgba(255,255,255,0.9);
  background: rgba(0,0,0,0.28);
  transition: background 0.12s;
  pointer-events: none;
}
.video-thumb:hover .video-thumb-play { background: rgba(0,0,0,0.45); }

/* ── Composer wrap ───────────────────────────────────────────── */
#composer-wrap {
  flex-shrink: 0;
  background: var(--bg);
  padding: 0 1rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#typing-bar {
  min-height: 1.3rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
  padding: 0.15rem 0.1rem;
}

/* ── Online user blobs ───────────────────────────────────────── */
#user-blobs {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 0.1rem 0.45rem;
  flex-wrap: wrap;
}

.user-blob {
  width: 26px;
  height: 26px;
  background: var(--surface2);
  border: 1.5px solid var(--surface3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  cursor: default;
  position: relative;
  transition: background 0.12s, border-color 0.12s;
  user-select: none;
  overflow: hidden;
}
.user-blob.is-me { background: rgba(224, 122, 95, 0.2); border-color: var(--accent); color: var(--accent); }
.user-blob img   { width: 100%; height: 100%; object-fit: cover; }

.user-blob::after {
  content: attr(data-name);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface3);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 600;
  font-style: normal;
  padding: 0.2rem 0.5rem;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s;
  z-index: 10;
  border: 1px solid var(--border-md);
}
.user-blob:hover::after { opacity: 1; }

.user-blob::before {
  content: '';
  position: absolute;
  bottom: -2px;
  right: -2px;
  width: 7px;
  height: 7px;
  background: #4ade80;
  border: 1.5px solid var(--bg);
}

/* ── Composer ────────────────────────────────────────────────── */
#composer {
  display: flex;
  align-items: flex-end;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border-md);
}

#file-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0.5rem 0.5rem 0;
  width: 100%;
  order: -1;
}
#file-previews:empty { display: none; }

.fp-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface2);
  border: 1px solid var(--border-md);
  padding: 0.2rem 0.45rem;
  font-size: 0.72rem;
  max-width: 180px;
}
.fp-name   { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.fp-remove { cursor: pointer; color: var(--muted); font-size: 0.8rem; flex-shrink: 0; line-height: 1; transition: color 0.1s; }
.fp-remove:hover { color: var(--accent); }

#attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.12s, background 0.12s;
}
#attach-btn:hover { color: var(--text); background: var(--surface2); }

#msg-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  line-height: 1.45;
  resize: none;
  padding: 0.7rem 0.5rem;
  max-height: 160px;
  overflow-y: auto;
  align-self: stretch;
}
#msg-input::placeholder { color: var(--muted); }

#send-btn {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, background 0.12s;
}
#send-btn:hover { color: var(--accent); background: var(--surface2); }
