:root {
  --bg: #0b141a;
  --panel: #111b21;
  --panel-2: #202c33;
  --rail: #0a1219;
  --border: #22323c;
  --text: #e9edef;
  --muted: #8696a0;
  --accent: #00a884;
  --accent-2: #005c4b;
  --in: #202c33;
  --out: #005c4b;
  --danger: #f15c6d;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}
.hidden { display: none !important; }

#app { display: grid; grid-template-columns: 64px 360px 1fr; height: 100vh; }

/* Rail */
.rail {
  background: var(--rail); display: flex; flex-direction: column; align-items: center;
  padding: 12px 0; gap: 6px; border-right: 1px solid var(--border);
}
.rail-logo {
  width: 40px; height: 40px; border-radius: 12px; background: var(--accent);
  color: #06231d; font-weight: 800; display: grid; place-items: center; font-size: 20px; margin-bottom: 10px;
}
.rail-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent;
  color: var(--muted); font-size: 20px; cursor: pointer; transition: .15s;
}
.rail-btn:hover { background: var(--panel-2); }
.rail-btn.active { background: var(--panel-2); color: var(--accent); }
.rail-spacer { flex: 1; }
.rail-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.rail-dot.on { background: var(--accent); }

/* List */
.list { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.list-head { display: flex; gap: 8px; padding: 12px; align-items: center; }
.channel-select {
  flex: 1; background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; font-size: 14px;
}
.icon-btn { width: 38px; height: 38px; border: 0; border-radius: 10px; background: var(--panel-2); color: var(--text); font-size: 18px; cursor: pointer; }
.icon-btn:hover { background: var(--accent-2); }
.search { padding: 0 12px 10px; }
.search input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 9px 12px; font-size: 14px;
}
.chat-list { flex: 1; overflow-y: auto; }
.chat-item { display: flex; gap: 12px; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.03); }
.chat-item:hover { background: var(--panel-2); }
.chat-item.active { background: var(--panel-2); }
.avatar {
  width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, #2a3942, #374b55);
  display: grid; place-items: center; font-weight: 700; color: var(--text); flex-shrink: 0; font-size: 16px;
}
.chat-body { flex: 1; min-width: 0; }
.chat-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 11px; color: var(--muted); flex-shrink: 0; margin-left: 8px; }
.chat-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #06231d; border-radius: 12px; font-size: 11px; font-weight: 700; padding: 1px 7px; margin-left: 6px; }

.panel-view { flex: 1; overflow-y: auto; padding: 16px; }
.panel-view h3 { margin: 4px 0 14px; }
.ch-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.ch-card .num { font-size: 16px; font-weight: 700; }
.ch-card .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kv { font-size: 13px; color: var(--muted); line-height: 1.8; }
.kv b { color: var(--text); }

/* Conversation */
.conv { background: #0b141a; display: flex; flex-direction: column; position: relative; }
.conv::before {
  content: ""; position: absolute; inset: 0; opacity: .04; pointer-events: none;
  background-image: radial-gradient(circle, #fff 1px, transparent 1px); background-size: 22px 22px;
}
.conv-empty { margin: auto; text-align: center; color: var(--muted); }
.empty-logo { font-size: 64px; }
.conv-empty h2 { color: var(--text); margin: 8px 0 4px; }
.conv-inner { display: flex; flex-direction: column; height: 100%; z-index: 1; }
.conv-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.conv-name { font-weight: 600; }
.conv-sub { font-size: 12px; color: var(--muted); }
.messages { flex: 1; overflow-y: auto; padding: 20px 8%; display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: 65%; padding: 7px 10px 5px; border-radius: 10px; font-size: 14px; line-height: 1.4; position: relative; word-wrap: break-word; }
.msg.in { align-self: flex-start; background: var(--in); border-top-left-radius: 2px; }
.msg.out { align-self: flex-end; background: var(--out); border-top-right-radius: 2px; }
.msg .meta { font-size: 10px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .tick { margin-left: 3px; }
.msg .tick.read { color: #53bdeb; }
.msg img, .msg video { max-width: 100%; border-radius: 8px; display: block; }
.msg.failed { outline: 1px solid var(--danger); }
.composer { display: flex; gap: 10px; padding: 12px 16px; background: var(--panel); border-top: 1px solid var(--border); }
.composer input { flex: 1; background: var(--panel-2); border: 0; color: var(--text); border-radius: 20px; padding: 11px 16px; font-size: 14px; }
.send-btn { width: 44px; height: 44px; border: 0; border-radius: 50%; background: var(--accent); color: #06231d; font-size: 18px; cursor: pointer; }
.send-btn:hover { background: #06cf9c; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: 360px; }
.modal-card h3 { margin: 0 0 14px; }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 5px; }
.modal-card input { width: 100%; background: var(--panel-2); border: 1px solid var(--border); color: var(--text); border-radius: 10px; padding: 10px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.btn { border: 0; border-radius: 10px; padding: 9px 16px; font-size: 14px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #06231d; font-weight: 600; }
.btn.ghost { background: var(--panel-2); color: var(--text); }

.chat-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .panel-view::-webkit-scrollbar { width: 7px; }
.chat-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .panel-view::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
