:root {
  --bg: #0a0e14; --panel: #111722; --panel2: #0d131c; --line: #1e2836;
  --text: #e6edf3; --muted: #7d8aa0; --accent: #4cc2ff; --accent2: #2a7fff;
  --me: #143b5c; --them: #19222f; --ok: #3fb950; --warn: #d29922;
  --radius: 12px; --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
#app { display: grid; grid-template-columns: 340px 1fr; height: 100vh; }

#sidebar { background: var(--panel2); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: 2px; padding: 18px 16px; border-bottom: 1px solid var(--line); }
.logo { color: var(--accent); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--warn); margin-left: auto; box-shadow: 0 0 8px currentColor; }
.dot.on { background: var(--ok); }
.dot.off { background: #d9534f; }

.me { padding: 14px 16px; border-bottom: 1px solid var(--line); }
.me-label, .foot { color: var(--muted); font-size: 11px; line-height: 1.5; }
.myid { display: block; font-family: var(--mono); font-size: 11px; color: var(--accent); word-break: break-all; background: var(--panel); padding: 8px 10px; border-radius: 8px; margin: 6px 0 8px; border: 1px solid var(--line); }
.me-actions { display: flex; gap: 8px; }

.add { display: flex; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
input { background: var(--panel); border: 1px solid var(--line); color: var(--text); padding: 10px 12px; border-radius: 8px; font-size: 13px; outline: none; width: 100%; }
input:focus { border-color: var(--accent2); }

.btn { background: var(--accent2); color: #fff; border: 0; padding: 10px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; font-size: 13px; white-space: nowrap; }
.btn:hover { background: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 11px; }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }

#convo-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.convo { padding: 11px 12px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.convo:hover { background: var(--panel); }
.convo.active { background: var(--panel); outline: 1px solid var(--line); }
.convo .name { font-weight: 600; font-size: 13px; }
.convo .prev { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot { padding: 12px 16px; border-top: 1px solid var(--line); }

#chat { display: flex; flex-direction: column; min-width: 0; }
.empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.empty .big { font-size: 48px; color: var(--accent); opacity: .5; }
.empty-inner { max-width: 360px; }
.muted { color: var(--muted); font-size: 12px; }

#chat-active { display: flex; flex-direction: column; height: 100%; }
#chat-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
#peer-name { font-family: var(--mono); font-size: 13px; color: var(--text); word-break: break-all; }
#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 68%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.4; word-wrap: break-word; }
.bubble.them { background: var(--them); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.me { background: var(--me); align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .t { display: block; font-size: 10px; color: var(--muted); margin-top: 3px; }
.sys { align-self: center; color: var(--muted); font-size: 11px; padding: 4px 10px; }

#send-form { display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); }
.btn.send { padding: 10px 20px; }
.btn.attach { padding: 10px 12px; background: transparent; border: 1px solid var(--line); cursor: pointer; display: grid; place-items: center; }
.btn.attach:hover { border-color: var(--accent); }

@media (max-width: 720px) {
  #app { grid-template-columns: 1fr; }
  #chat { display: none; }
  body.chatting #chat { display: flex; position: fixed; inset: 0; background: var(--bg); }
  body.chatting #sidebar { display: none; }
}
