:root{
  --bg:#0e1116; --panel:#121722; --line:#1f2633; --muted:#9aa6b2; --text:#e7edf3;
  --primary:#2ea8ff; --ok:#35d399; --danger:#ff6b81; --warn:#f6c453;
  --bubble:#1a2130; --bubble-me:#0a5ad6; --bubble-me-2:#0a49ad;
}
*{ box-sizing:border-box; }
html,body,#app{ height:100%; }
body{ margin:0; background:var(--bg); color:var(--text); font:14px/1.4 system-ui,-apple-system,Segoe UI,Roboto,Helvetica,Arial; }

#app{ display:grid; grid-template-columns: 360px 1fr; height:100%; }
.sidebar{ border-right:1px solid var(--line); display:flex; flex-direction:column; background:var(--panel); }
.sidebar-header{ padding:12px; border-bottom:1px solid var(--line); display:grid; gap:10px; }
.brand{ font-weight:800; letter-spacing:.2px; }
.me{ display:flex; gap:10px; align-items:center; }
.avatar{ width:36px; height:36px; border-radius:50%; background:#243048; display:flex; align-items:center; justify-content:center; font-weight:800; }
.me-name{ font-weight:700; }
.tiny{ color:var(--muted); font-size:12px; }
.search input{ width:100%; padding:10px; border-radius:10px; border:1px solid var(--line); background:#0c111a; color:#e7edf3; }
.chat-list{ flex:1; overflow:auto; }
.chat-item{ display:grid; grid-template-columns: 44px 1fr auto; gap:10px; padding:10px 12px; border-bottom:1px solid var(--line); cursor:pointer; }
.chat-item:hover{ background:#0f1520; }
.chat-item .title{ font-weight:700; }
.chat-item .last{ color:var(--muted); overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.sidebar-footer{ padding:10px; border-top:1px solid var(--line); }
.sidebar-footer .row{ display:grid; grid-template-columns: 1fr auto; gap:8px; }
.sidebar-footer input{ padding:10px; border-radius:10px; border:1px solid var(--line); background:#0c111a; color:#e7edf3; }

.chat{ display:flex; flex-direction:column; }
.chat-header{ padding:10px 12px; border-bottom:1px solid var(--line); display:flex; align-items:center; justify-content:space-between; background:var(--panel); flex-wrap:wrap; gap:8px;}
.peer{ display:flex; gap:10px; align-items:center; }
.peer-name{ font-weight:800; }
.actions{ display:flex; gap:8px; align-items:center; flex-wrap: wrap; }
.actions input, .actions select{ padding:8px 10px; border-radius:10px; border:1px solid var(--line); background:#0c111a; color:#e7edf3; }
.btn{ padding:10px 14px; border:1px solid var(--line); border-radius:10px; background:#0f1724; color:#e7edf3; cursor:pointer; }
.btn.primary{ background:#0a2a45; border-color:#17314a; }
.btn.ok{ background:#0b2a22; border-color:#1c4436; }
.btn.small{ padding:6px 10px; }

.messages{
  flex:1; overflow:auto; padding:16px 20px; display:flex; flex-direction:column; gap:14px;
  background:linear-gradient(180deg,#0e1116,#0d1015);
}

/* Message row: avatar above bubble + left/right alignment */
.msg-block{
  max-width:72%;
  display:flex; flex-direction:column; gap:6px;
}
.msg-line{ display:flex; gap:10px; align-items:flex-start; }
.msg-line.left{ justify-content:flex-start; }
.msg-line.right{ justify-content:flex-end; }
.msg-sender{
  display:flex; align-items:center; justify-content:center;
  width:32px; height:32px; border-radius:50%; background:#2a3550; font-size:12px; font-weight:800;
}
.msg{
  border-radius:14px; background:var(--bubble); line-height:1.35; position:relative; padding:10px 12px;
}
.msg.me{ background:linear-gradient(180deg,var(--bubble-me),var(--bubble-me-2)); }
.msg .header{
  display:flex; align-items:center; gap:8px; margin-bottom:6px; font-weight:700; font-size:12px; color:#cfe0ff;
}
.msg .text{ white-space:pre-wrap; word-wrap: break-word; color:#eaf2ff; }
.msg .media img{ max-width:280px; border-radius:10px; display:block; }
.msg .location a{ color:#cfe0ff; text-decoration:none; }
.reply{ border-left:3px solid #5b86e5; padding-left:8px; margin-bottom:6px; color:#d9e1f2; opacity:.9; }
.reply .tiny{ color:#bcc7d6; }
.row-actions{ display:flex; gap:8px; margin-top:6px; opacity:.85; font-size:12px; }
.row-actions .link{ cursor:pointer; color:#b9c7ff; }
.meta{ display:flex; gap:8px; align-items:center; margin-top:6px; }
.badge{ display:inline-block; padding:2px 6px; border-radius:999px; background:#1f2a44; color:#cfe0ff; font-size:11px; }

/* Seen list pop */
.seen{
  margin-left:auto; font-size:11px; color:#9fb4ff; cursor:default; position:relative;
}
.seen:hover::after{
  content: attr(data-seen);
  position:absolute; right:0; top:120%;
  background:#0b111a; border:1px solid #1f2633; padding:8px 10px; border-radius:8px; white-space:pre;
}

/* Composer */
.composer{ padding:10px; border-top:1px solid var(--line); background:#0b111a; }
.composer .row{ display:grid; grid-template-columns: auto 1fr 160px auto; gap:10px; align-items:center; }
.composer input{ padding:10px; border-radius:10px; border:1px solid var(--line); background:#0c111a; color:#e7edf3; }
.icon-btn{ width:40px; height:40px; border-radius:10px; border:1px solid var(--line); background:#0f1724; color:#e7edf3; cursor:pointer; }
.composer-left{ display:flex; gap:8px; align-items:center; }

/* Emoji picker */
.emoji-picker{
  margin-top:8px; border:1px solid var(--line); border-radius:12px; background:#0b111a; padding:8px; display:grid; grid-template-columns: repeat(12, 1fr); gap:4px; max-height:200px; overflow:auto;
}
.emoji-picker button{
  font-size:20px; padding:6px; border:none; background:transparent; cursor:pointer; border-radius:8px;
}
.emoji-picker button:hover{ background:#1a2232; }
.hidden{ display:none !important; }

/* Modal */
.modal{ position:fixed; inset:0; background:rgba(0,0,0,.5); display:flex; align-items:center; justify-content:center; }
.modal.hidden{ display:none; }
.modal-content{
  width:min(520px, 92vw); background:#111726; border:1px solid #1f2633; border-radius:12px; padding:16px;
}
.modal-title{ font-weight:800; margin-bottom:8px; }
.modal-content input{ width:100%; padding:10px; border-radius:10px; border:1px solid var(--line); background:#0c111a; color:#e7edf3; }
.modal-actions{ display:flex; gap:8px; justify-content:flex-end; margin-top:12px; }

@media (max-width: 980px){
  #app{ grid-template-columns: 1fr; }
  .sidebar{ display:none; }
  .composer .row{ grid-template-columns: auto 1fr auto; }
  #ttlInput{ display:none; }
  .msg-block{ max-width:86%; }
}

/* Emoji-friendly font stacks */
:root{
  --emoji-font: "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji","Twemoji Mozilla","EmojiOne Color","Android Emoji",emoji;
}

/* apply emoji fonts in key places */
body, input, button, .text, .emoji-picker button {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, var(--emoji-font);
}

/* Map card (location bubble) */
.map-card {
  width: min(320px, 80vw);
  height: 180px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}

/* Leaflet default fixes inside dark bubble */
.leaflet-container {
  background: #0b111a;
}
.leaflet-control-attribution {
  background: rgba(0,0,0,.35);
  color: #cfe0ff;
  border-radius: 6px;
  padding: 0 4px;
}

img.emoji {
  height: 1em;
  width: 1em;
  vertical-align: -0.15em;
}
