:root {
  --blue: #0068ff;
  --blue-soft: #e5efff;
  --mine: #dbebff;
  --bg: #eef0f1;
  --panel: #ffffff;
  --line: #e1e4e8;
  --text: #081c36;
  --muted: #7589a3;
  --bot: #0b8a5a;
  --warn: #b45309;
  --danger: #c0262d;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; }

.banner {
  background: #fff4d6; color: var(--warn); border-bottom: 1px solid #f3d38a;
  padding: 6px 16px; font-size: 12.5px; font-weight: 600; text-align: center;
}
.app { flex: 1; display: grid; grid-template-columns: 340px 1fr; min-height: 0; }

/* ── sidebar ── */
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.me { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; }
.me small { display: block; color: var(--muted); }
#search { width: 100%; padding: 8px 12px; border: none; border-radius: 8px; background: var(--bg); font: inherit; }
#search:focus { outline: 2px solid var(--blue-soft); }
.groups { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.groups li { display: flex; gap: 10px; align-items: center; padding: 10px 14px; cursor: pointer; }
.groups li:hover { background: #f3f5f6; }
.groups li.active { background: var(--blue-soft); }
.groups .meta { flex: 1; min-width: 0; }
.groups .row1 { display: flex; justify-content: space-between; gap: 8px; }
.groups .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.groups .time { color: var(--muted); font-size: 12px; flex: none; }
.groups .last { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.groups .unread { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; font-weight: 700; }
.ghost { margin: 10px 14px 14px; padding: 8px; border: 1px solid var(--line); background: none; border-radius: 8px; cursor: pointer; font: inherit; }
.ghost.danger { color: var(--danger); }
.ghost:hover { background: #fff5f5; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 14px; background: var(--blue);
}
.avatar.small { width: 30px; height: 30px; font-size: 11px; }
.avatar.bot { background: var(--bot); }

/* ── chat ── */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-head { display: flex; gap: 10px; align-items: center; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.persona { display: flex; flex-direction: column; font-size: 11.5px; color: var(--muted); gap: 2px; }
.persona select { font: inherit; font-size: 14px; color: var(--text); padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; max-width: 220px; }

.messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 4px; }
.empty { margin: auto; color: var(--muted); text-align: center; max-width: 360px; line-height: 1.6; }
.msg { display: flex; gap: 8px; align-items: flex-end; max-width: 72%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .stack { display: flex; flex-direction: column; min-width: 0; }
.msg .who { font-size: 12px; color: var(--muted); margin: 6px 0 2px 2px; }
.msg.from-bot .who { color: var(--bot); font-weight: 600; }
.bubble {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px;
  white-space: pre-wrap; word-wrap: break-word; line-height: 1.45; position: relative;
}
.msg.mine .bubble { background: var(--mine); border-color: #c4dcff; }
.msg.from-bot .bubble { border-color: #bfe6d3; }
.bubble .time { display: block; font-size: 11px; color: var(--muted); margin-top: 4px; }
.mention { color: var(--blue); font-weight: 600; }
.quote { border-left: 3px solid var(--blue); background: rgba(0, 104, 255, .06); padding: 4px 8px; border-radius: 4px; margin-bottom: 6px; font-size: 12.5px; }
.quote b { display: block; font-size: 12px; }
.recalled { color: var(--muted); font-style: italic; }
.photo { width: min(320px, 100%); max-height: 320px; object-fit: contain; border-radius: 8px; display: block; cursor: zoom-in; }
.msg .stack:has(.photo) { width: min(340px, 70vw); }
.file-card { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; min-width: 220px; }
.file-card .ext { width: 40px; height: 46px; border-radius: 6px; background: var(--blue); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; text-transform: uppercase; }
.file-card small { display: block; color: var(--muted); }
.actions { display: none; gap: 4px; align-self: center; }
.msg:hover .actions { display: flex; }
.actions button { border: none; background: #fff; border-radius: 12px; padding: 3px 8px; font-size: 12px; cursor: pointer; color: var(--muted); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.actions button:hover { color: var(--blue); }

/* ── composer ── */
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 12px; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.input-wrap { flex: 1; position: relative; }
#text { width: 100%; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font: inherit; max-height: 160px; }
#text:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.send { background: var(--blue); color: #fff; border: none; border-radius: 10px; padding: 9px 18px; font: inherit; font-weight: 600; cursor: pointer; }
.send:disabled { opacity: .5; cursor: default; }
.icon-btn { border: none; background: none; font-size: 20px; cursor: pointer; padding: 6px 8px; border-radius: 8px; color: var(--muted); line-height: 1; }
.icon-btn:hover { background: var(--bg); }
.quote-bar { display: flex; justify-content: space-between; gap: 8px; border-left: 3px solid var(--blue); background: var(--blue-soft); padding: 6px 10px; border-radius: 6px; margin-bottom: 6px; }
.quote-bar span { display: block; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60vw; }
.pending { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.pending span { background: var(--bg); border-radius: 12px; padding: 3px 10px; font-size: 12.5px; }
.pending button { border: none; background: none; cursor: pointer; color: var(--danger); margin-left: 4px; }
.mention-menu { position: absolute; bottom: 100%; left: 0; margin: 0 0 6px; padding: 4px; list-style: none; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.1); min-width: 220px; z-index: 5; }
.mention-menu li { padding: 6px 10px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.mention-menu li.on, .mention-menu li:hover { background: var(--blue-soft); }
.mention-menu small { color: var(--muted); }

.viewer { position: fixed; inset: 0; background: rgba(0,0,0,.8); display: grid; place-items: center; z-index: 20; cursor: zoom-out; }
.viewer img { max-width: 92vw; max-height: 92vh; }
.dragging .messages { outline: 3px dashed var(--blue); outline-offset: -10px; }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .app.in-chat .sidebar { display: none; }
  .app:not(.in-chat) .chat { display: none; }
  .only-mobile { display: inline-block; }
  .msg { max-width: 88%; }
  .persona select { max-width: 140px; }
}
