:root {
  color-scheme: dark;
  --bg: #0b141a;
  --side: #111b21;
  --header: #202c33;
  --panel: #1d2a31;
  --line: #222d34;
  --text: #e9edef;
  --muted: #8696a0;
  --green: #00a884;
  --out: #005c4b;
  --in: #202c33;
  --unread: #25d366;
  --hover: #2a3942;
  --active: #2a3942;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: #0a1014;
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--bg);
  box-shadow: 0 0 0 1px #0008;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--side);
  border-right: 1px solid var(--line);
  min-width: 0;
}

.side-header, .chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
  padding: 0 16px;
  background: var(--header);
}

.me { display: flex; align-items: center; gap: 12px; min-width: 0; }
.chat-header { justify-content: space-between; }
.chat-user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.chat-title { min-width: 0; }
.me-name, #chatName { font-weight: 600; }
.me-status, .chat-sub, .hint, .empty-list, .search-msg small {
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #06210f;
  background: #6b7c85;
  flex: 0 0 auto;
  position: relative;
  overflow: hidden;
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  text-decoration: none;
}

.account-pick {
  display: block;
  margin-top: 6px;
  max-width: 168px;
  border: 0;
  background: #182229;
  color: var(--text);
  border-radius: 6px;
  padding: 4px 6px;
}

.account-pick.hidden { display: none; }
.icon-btn:hover { background: #ffffff12; color: var(--text); }
.icon-btn.on { color: var(--green); }
.icon-btn svg { display: block; }
.header-actions { display: flex; align-items: center; gap: 2px; }

.search-wrap { padding: 8px 12px 10px; background: var(--side); }
.search-wrap input {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 10px 14px;
  outline: none;
}

.chat-list { overflow: auto; flex: 1; }
.chat-item, .search-msg {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #ffffff08;
  cursor: pointer;
}
.chat-item:hover, .search-msg:hover, .chat-item.active { background: var(--hover); }
.chat-item .preview, .search-msg .preview {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-item .meta { text-align: right; position: relative; }
.chat-del {
  display: none;
  margin-top: 6px;
  border: 0;
  background: #ffffff14;
  color: #f15c6d;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 20px;
}
.chat-item:hover .chat-del, .chat-item.active .chat-del { display: inline-grid; place-items: center; }
.chat-item:hover .badge { display: none; }
.time { color: var(--muted); font-size: 12px; }
.badge {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  margin-top: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--unread);
  color: #052e16;
  font-size: 11px;
  font-weight: 700;
}
.empty-list { padding: 28px 16px; text-align: center; }

.thread {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: #0b141a url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h60v60H0z' fill='%230b141a'/%3E%3Cpath d='M10 8l4 3-4 3M40 38l4 3-4 3' stroke='%23182128' stroke-width='1' fill='none'/%3E%3C/svg%3E");
}

.empty-thread, .conversation {
  flex: 1;
  min-height: 0;
  width: 100%;
}
.empty-thread {
  display: grid;
  place-items: center;
  background: #222e35;
}
.empty-card {
  max-width: 420px;
  text-align: center;
  color: var(--muted);
}
.empty-card h1 { color: var(--text); font-weight: 300; margin-bottom: 8px; }
#qrBox img {
  width: 240px;
  background: #fff;
  border-radius: 12px;
  margin-top: 16px;
}

.conversation { display: flex; flex-direction: column; }
.conversation.hidden, .empty-thread.hidden { display: none; }

.messages {
  flex: 1;
  overflow: auto;
  padding: 18px 8%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.day {
  align-self: center;
  margin: 10px 0;
  padding: 6px 12px;
  border-radius: 8px;
  background: #182229;
  color: var(--muted);
  font-size: 12px;
}
.ephemeral-banner {
  margin: 0;
  padding: 8px 16px;
  background: #182229;
  color: #ffd479;
  font-size: 12px;
  text-align: center;
}
.ephemeral-banner.hidden { display: none; }
.ephemeral-note {
  max-width: 420px;
  text-align: center;
  line-height: 1.4;
}
.timer {
  display: inline-flex;
  align-items: center;
  color: #ffd479;
}
.timer svg { display: block; }

.bubble {
  max-width: min(68%, 640px);
  padding: 6px 8px 4px 9px;
  border-radius: 8px;
  box-shadow: 0 1px 0 #0004;
  position: relative;
}
.bubble.in { align-self: flex-start; background: var(--in); }
.bubble.out { align-self: flex-end; background: var(--out); }
.bubble .body { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.bubble.deleted .body { font-style: italic; color: #ffffff99; }
.bubble-del {
  position: absolute;
  top: 4px;
  right: 4px;
  border: 0;
  background: #0006;
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  font-size: 14px;
  line-height: 20px;
}
.bubble:hover .bubble-del { opacity: 1; }

.msg-menu {
  position: fixed;
  z-index: 20;
  min-width: 200px;
  background: #233138;
  border-radius: 10px;
  box-shadow: 0 8px 24px #0008;
  padding: 6px 0;
}
.msg-menu.hidden, .msg-menu button.hidden { display: none; }
.msg-menu button {
  display: block;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  padding: 10px 16px;
  cursor: pointer;
}
.msg-menu button:hover { background: #ffffff12; }
.msg-menu button[data-action="everyone"] { color: #f15c6d; }
.bubble .meta {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  color: #ffffff99;
  font-size: 11px;
  margin-top: 2px;
}
.ticks { letter-spacing: -1px; color: #8696a0; font-size: 13px; }
.ticks.read { color: #53bdeb; }
.preview .ticks { margin-right: 4px; }

.attach-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  background: #182229;
  color: var(--muted);
  font-size: 13px;
}
.attach-bar.hidden { display: none; }
.composer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--header);
}
.composer input[type="text"],
.composer #messageInput {
  flex: 1;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}
.composer button[type="submit"] {
  border: 0;
  border-radius: 8px;
  background: var(--green);
  color: #06210f;
  font-weight: 700;
  padding: 0 18px;
  height: 42px;
  cursor: pointer;
}
.attach-btn { color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  background: #0008;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(420px, 100%);
  background: #233138;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 16px 40px #0008;
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }
.modal-card p { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.4; }
.modal-card input {
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}
.modal-card .hint { min-height: 18px; margin: 10px 0 0; }
.modal-card .hint.ok { color: var(--green); }
.modal-card .hint.err { color: #f15c6d; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions button {
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}
#newChatCancel { background: transparent; color: var(--muted); }
#newChatStart { background: var(--green); color: #06210f; }
#newChatStart:disabled { opacity: 0.6; cursor: default; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .thread:not(.open) { display: none; }
  .sidebar.hide { display: none; }
}
