:root {
  --bg: #1a1b2e;
  --bg-sidebar: #16172b;
  --bg-chat: #1e1f36;
  --bg-input: #252640;
  --bg-msg-own: #4338ca;
  --bg-msg-other: #2a2b45;
  --text: #e2e3f0;
  --text-muted: #8b8da8;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --border: #2d2e4a;
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg-chat);
  border-radius: var(--radius);
  padding: 32px;
  width: 90%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal h2 { margin-bottom: 8px; font-size: 20px; }
.modal p { color: var(--text-muted); margin-bottom: 20px; font-size: 14px; }
.modal input, .modal textarea {
  width: 100%; padding: 12px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 15px;
  margin-bottom: 16px; outline: none; resize: vertical;
}
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.modal textarea { min-height: 60px; font-family: inherit; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; }

/* ── Buttons ── */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 20px; border-radius: 8px; font-size: 15px;
  cursor: pointer; transition: background 0.2s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
  padding: 10px 20px; border-radius: 8px; font-size: 15px; cursor: pointer;
}
.btn-secondary:hover { border-color: var(--accent); }
.btn-icon {
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; padding: 4px 8px; border-radius: 6px;
  transition: all 0.2s;
}
.btn-icon:hover { color: var(--text); background: var(--bg-input); }

/* ── App layout ── */
.app { display: flex; height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 260px; min-width: 260px;
  background: var(--bg-sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-header { padding: 20px; }
.sidebar-header h1 { font-size: 18px; color: var(--accent); }
.room-list-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px 8px; font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 1px;
}
.room-list { list-style: none; flex: 1; overflow-y: auto; padding: 0 8px; }
.room-list li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  font-size: 15px; margin-bottom: 2px; transition: background 0.15s;
  display: flex; align-items: center; gap: 8px;
}
.room-list li:hover { background: var(--bg-input); }
.room-list li.active { background: var(--accent); color: #fff; }
.room-list li .room-hash { color: var(--text-muted); }
.room-list li.active .room-hash { color: rgba(255,255,255,0.7); }
.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; color: var(--text-muted);
}

/* ── Chat area ── */
.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.chat-header h2 { font-size: 18px; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; display: inline-block;
}
.status-dot.connecting { background: #f59e0b; }
.status-dot.connected { background: #22c55e; }
.status-dot.disconnected { background: #ef4444; }

.messages {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 6px;
}

/* ── Message bubbles ── */
.msg-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.msg-meta { font-size: 12px; color: var(--text-muted); padding: 0 14px; }
.msg-meta .msg-name { color: var(--accent-hover); font-weight: 600; }
.msg-bubble {
  padding: 10px 14px; border-radius: var(--radius);
  max-width: 70%; word-wrap: break-word; word-break: break-word;
  font-size: 15px; line-height: 1.5;
  white-space: pre-wrap;
}
.msg-bubble.own {
  background: var(--bg-msg-own); color: #fff;
  align-self: flex-end; border-bottom-right-radius: 4px;
}
.msg-bubble.other {
  background: var(--bg-msg-other); color: var(--text);
  align-self: flex-start; border-bottom-left-radius: 4px;
}
.msg-group.own { align-items: flex-end; }

/* ── Input bar ── */
.message-input-bar {
  padding: 16px 24px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; align-items: center;
}
#upload-btn {
  font-size: 20px; padding: 8px; flex-shrink: 0;
}
.upload-progress {
  font-size: 13px; color: var(--text-muted); padding: 0 4px;
}

/* ── File attachments in messages ── */
.msg-file {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-radius: 8px;
  background: rgba(0,0,0,0.15); margin-top: 6px;
  text-decoration: none; color: inherit;
  transition: background 0.15s;
}
.msg-file:hover { background: rgba(0,0,0,0.25); }
.msg-file-icon { font-size: 24px; flex-shrink: 0; }
.msg-file-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg-file-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-file-size { font-size: 12px; color: var(--text-muted); }
.msg-file img.msg-file-preview {
  max-width: 280px; max-height: 200px; border-radius: 8px; margin-top: 8px;
  cursor: pointer; display: block;
}
#message-input {
  flex: 1; padding: 12px 16px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 15px; outline: none;
}
#message-input:focus { border-color: var(--accent); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .msg-bubble { max-width: 85%; }
}
