/* ============================================================
   ProjectTelemetry — Messages (#/messages)  window.PTMessages
   Two-pane messenger. All colors are tokens, so light/dark
   (blueprint) themes both work with no per-theme rules here.
   ============================================================ */

.msg-wrap {
  display: flex;
  height: calc(100vh - 108px);
  min-height: 480px;
  background: var(--white);
  border: 1px solid var(--bd);
  border-radius: 12px;
  overflow: hidden;
}

/* ── Left: conversation list ─────────────────────────────── */
.msg-list {
  width: 336px;
  flex-shrink: 0;
  border-right: 1px solid var(--bd);
  display: flex;
  flex-direction: column;
  background: var(--nav-bg);
  min-width: 0;
}
.msg-list-hd {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
}
.msg-list-hd h2 { font-size: 19px; font-weight: 800; letter-spacing: -.01em; color: var(--ink); margin: 0; }
.msg-new-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--bd);
  background: var(--white); color: var(--accent); cursor: pointer; font-size: 17px;
  display: flex; align-items: center; justify-content: center; transition: background .15s, border-color .15s;
}
.msg-new-btn:hover { background: var(--bg2); border-color: var(--accent); }

.msg-search {
  display: flex; align-items: center; gap: 8px;
  margin: 4px 12px 8px; padding: 8px 12px;
  background: var(--bg2); border: 1px solid var(--bd); border-radius: 9px;
  color: var(--ink-soft);
}
.msg-search i { font-size: 16px; flex-shrink: 0; }
.msg-search input {
  border: none; background: none; outline: none; width: 100%;
  font-size: 14px; color: var(--ink); font-family: inherit;
}
.msg-list-scroll { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }

.msg-row {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 9px 10px; border: none; background: none; cursor: pointer;
  border-radius: 10px; text-align: left; font-family: inherit; color: var(--ink);
  transition: background .12s;
}
.msg-row:hover { background: var(--bg2); }
.msg-row.active { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.msg-row-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.msg-row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.msg-row-name { font-size: 14.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row-time { font-size: 11.5px; color: var(--ink-faint); flex-shrink: 0; }
.msg-row-prev { font-size: 13px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-row-unread .msg-row-name { font-weight: 800; }
.msg-row-unread .msg-row-prev { color: var(--ink); font-weight: 500; }
.msg-mute-i { font-size: 12px; opacity: .7; }
.msg-unread {
  flex-shrink: 0; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 800; display: flex; align-items: center; justify-content: center;
}

/* ── Avatars ─────────────────────────────────────────────── */
.msg-av {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 82%, #000 0%), color-mix(in srgb, var(--accent) 55%, #7c3aed 40%));
  color: #fff; font-size: 14px; font-weight: 700; letter-spacing: .02em;
}
.msg-av-sm { width: 30px; height: 30px; font-size: 11.5px; }
.msg-av-lg { width: 42px; height: 42px; font-size: 15px; }
.msg-av-grp { background: linear-gradient(135deg, #0ea5e9, #6366f1); }
.msg-av-file { background: linear-gradient(135deg, #64748b, #334155); }
.msg-av-spacer { width: 30px; flex-shrink: 0; }

/* ── Right: thread ───────────────────────────────────────── */
.msg-thread { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--white); position: relative; }

.msg-empty, .msg-thread-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 40px; color: var(--ink-soft);
}
.msg-empty i { font-size: 46px; color: var(--ink-faint); margin-bottom: 14px; }
.msg-empty h3 { font-size: 20px; font-weight: 800; color: var(--ink); margin: 0 0 6px; }
.msg-empty p { font-size: 14px; max-width: 340px; line-height: 1.5; margin: 0 0 18px; }
.msg-thread-empty { font-size: 14px; }

.msg-th-hd {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px; border-bottom: 1px solid var(--bd); flex-shrink: 0;
  background: var(--white); position: relative;
}
.msg-back { display: none; border: none; background: none; color: var(--ink); font-size: 20px; cursor: pointer; padding: 4px; }
.msg-th-hd-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msg-th-title { font-size: 15.5px; font-weight: 700; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-th-sub { font-size: 12.5px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-th-actions { display: flex; gap: 4px; }
.msg-icon-btn {
  width: 36px; height: 36px; border-radius: 8px; border: none; background: none;
  color: var(--ink-soft); cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center; transition: background .12s, color .12s;
}
.msg-icon-btn:hover { background: var(--bg2); color: var(--ink); }
.msg-menu {
  position: absolute; top: 52px; right: 12px; z-index: 30;
  background: var(--white); border: 1px solid var(--bd); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(2,6,23,.18); padding: 5px; min-width: 176px;
}
.msg-menu button {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 9px 11px; border: none; background: none; cursor: pointer;
  font-size: 13.5px; color: var(--ink); border-radius: 7px; font-family: inherit; text-align: left;
}
.msg-menu button:hover { background: var(--bg2); }
.msg-menu button i { font-size: 16px; color: var(--ink-soft); }
.msg-menu-danger, .msg-menu-danger i { color: #dc2626 !important; }

.msg-scroll { flex: 1; overflow-y: auto; padding: 16px 18px 8px; display: flex; flex-direction: column; }

.msg-daydiv { text-align: center; margin: 12px 0 10px; position: relative; }
.msg-daydiv span {
  font-size: 11.5px; font-weight: 700; color: var(--ink-faint);
  background: var(--white); padding: 0 12px; position: relative; z-index: 1; text-transform: uppercase; letter-spacing: .04em;
}
.msg-daydiv::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: var(--bd); }

.msg-sys { text-align: center; font-size: 12px; color: var(--ink-faint); margin: 6px 0; }

.msg-b { display: flex; gap: 8px; margin-top: 10px; align-items: flex-end; }
.msg-b.grouped { margin-top: 2px; }
.msg-b.me { flex-direction: row-reverse; }
.msg-b-col { display: flex; flex-direction: column; max-width: min(560px, 74%); }
.msg-b.me .msg-b-col { align-items: flex-end; }
.msg-b-name { font-size: 12px; font-weight: 700; color: var(--ink-soft); margin: 0 0 3px 4px; }
.msg-bubble {
  padding: 8px 12px; border-radius: 15px; font-size: 14px; line-height: 1.45;
  background: var(--bg2); color: var(--ink); border-bottom-left-radius: 5px; word-break: break-word;
}
.msg-b.me .msg-bubble {
  background: var(--accent); color: #fff; border-bottom-left-radius: 15px; border-bottom-right-radius: 5px;
}
.msg-b.grouped .msg-bubble { border-bottom-left-radius: 15px; }
.msg-b.me.grouped .msg-bubble { border-bottom-right-radius: 15px; }
.msg-b-text { white-space: pre-wrap; }
.msg-b-time { font-size: 10.5px; color: var(--ink-faint); margin: 3px 5px 0; }
.msg-deleted { font-style: italic; opacity: .7; }

.msg-b-atts { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.msg-att {
  display: flex; align-items: center; gap: 9px; padding: 8px 10px;
  background: var(--white); border: 1px solid var(--bd); border-radius: 9px;
  text-decoration: none; color: var(--ink); max-width: 320px; transition: border-color .12s;
}
.msg-b.me .msg-att { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.3); color: #fff; }
.msg-att:hover { border-color: var(--accent); }
.msg-att > i:first-child { font-size: 20px; color: var(--accent); flex-shrink: 0; }
.msg-b.me .msg-att > i:first-child { color: #fff; }
.msg-att-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msg-att-label { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-att-meta { font-size: 11px; opacity: .75; }
.msg-att-go { font-size: 14px; opacity: .6; flex-shrink: 0; }

/* ── Composer ────────────────────────────────────────────── */
.msg-att-tray { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 14px 0; }
.msg-composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px;
  border-top: 1px solid var(--bd); flex-shrink: 0;
}
.msg-composer textarea {
  flex: 1; resize: none; border: 1px solid var(--bd); border-radius: 20px;
  padding: 9px 15px; font-size: 14px; font-family: inherit; line-height: 1.4;
  background: var(--bg2); color: var(--ink); outline: none; max-height: 140px; min-height: 40px;
}
.msg-composer textarea:focus { border-color: var(--accent); background: var(--white); }
.msg-attach-btn { flex-shrink: 0; }
.msg-send {
  width: 40px; height: 40px; border-radius: 50%; border: none; background: var(--accent);
  color: #fff; cursor: pointer; font-size: 18px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: opacity .12s;
}
.msg-send:hover { opacity: .9; }
.msg-send:disabled { opacity: .5; cursor: default; }

.msg-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 10px;
  background: var(--bg2); border: 1px solid var(--bd); border-radius: 999px;
  font-size: 12.5px; color: var(--ink); max-width: 220px;
}
.msg-chip i { font-size: 14px; color: var(--accent); }
.msg-chip button { border: none; background: none; cursor: pointer; color: var(--ink-soft); display: flex; padding: 2px; border-radius: 50%; }
.msg-chip button:hover { background: var(--bd); color: var(--ink); }

/* ── Loading / empties ───────────────────────────────────── */
.msg-loading { display: flex; align-items: center; justify-content: center; padding: 30px; color: var(--ink-faint); }
.msg-loading i { font-size: 24px; animation: spin 1s linear infinite; }
.msg-loading-lg { flex: 1; height: 100%; }
.msg-side-empty { padding: 26px 18px; text-align: center; font-size: 13px; color: var(--ink-soft); line-height: 1.5; }

/* ── Modals (new message / file picker) ──────────────────── */
.msg-modal-back {
  position: fixed; inset: 0; z-index: 1200; background: rgba(2,6,23,.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.msg-modal {
  width: 460px; max-width: 100%; max-height: 82vh; background: var(--white);
  border-radius: 14px; box-shadow: 0 24px 60px rgba(2,6,23,.34);
  display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--bd);
}
.msg-modal-hd { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; }
.msg-modal-hd h3 { font-size: 17px; font-weight: 800; color: var(--ink); margin: 0; }
.msg-modal-x { border: none; background: none; cursor: pointer; color: var(--ink-soft); font-size: 20px; display: flex; padding: 4px; border-radius: 6px; }
.msg-modal-x:hover { background: var(--bg2); color: var(--ink); }
.msg-modal-note { font-size: 12.5px; color: var(--ink-soft); padding: 0 18px 4px; line-height: 1.45; margin: 0; }
.msg-pick-search { margin: 6px 18px 8px; }
.msg-pick-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px 8px; }
.msg-pick-title { padding: 0 18px 8px; }
.msg-pick-title input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--bd); border-radius: 9px;
  font-size: 14px; font-family: inherit; background: var(--bg2); color: var(--ink); outline: none;
}
.msg-pick-title input:focus { border-color: var(--accent); }
.msg-pick-list { flex: 1; overflow-y: auto; padding: 0 10px; min-height: 160px; }
.msg-pick-sec {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-faint); padding: 12px 8px 4px;
}
.msg-pick-row {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 8px 8px;
  border: none; background: none; cursor: pointer; border-radius: 9px; text-align: left;
  font-family: inherit; color: var(--ink);
}
.msg-pick-row:hover { background: var(--bg2); }
.msg-pick-row.on { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.msg-pick-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.msg-pick-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-pick-sub { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-pick-check { font-size: 17px; color: var(--ink-faint); opacity: 0; flex-shrink: 0; }
.msg-pick-row.on .msg-pick-check { opacity: 1; color: var(--accent); }
.msg-modal-ft { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--bd); }

/* ── Mobile / narrow: single pane ────────────────────────── */
@media (max-width: 760px) {
  .msg-wrap { height: calc(100vh - 90px); }
  .msg-list { width: 100%; }
  .msg-thread { display: none; }
  .msg-wrap.msg-show-thread .msg-list { display: none; }
  .msg-wrap.msg-show-thread .msg-thread { display: flex; }
  .msg-back { display: flex; }
  .msg-b-col { max-width: 82%; }
}
