:root {
  --bg: #141821;
  --panel: #1b2130;
  --panel2: #232b3d;
  --text: #e7eaf0;
  --muted: #8b93a8;
  --accent: #5b8cff;
  --accent2: #3d6ee0;
  --mine: #2c4a8f;
  --err: #ff6b6b;
  --ok: #3ecf8e;
  --radius: 14px;
}

* { box-sizing: border-box; }

/* Author display rules would otherwise override the UA [hidden] rule. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- sign in ---------- */

#login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#login form {
  width: 100%;
  max-width: 320px;
  background: var(--panel);
  border-radius: 16px;
  padding: 28px 26px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}

#login h1 {
  margin: 0 0 2px;
  font-size: 26px;
  color: var(--accent);
}

#login .sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 13px;
}

#login label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 4px;
}

#login input {
  width: 100%;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
}

#login input:focus {
  outline: none;
  border-color: var(--accent);
}

#login button {
  width: 100%;
  margin-top: 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 0;
  font-size: 15px;
  font-weight: 600;
}

#login button:active { background: var(--accent2); }

.error { color: var(--err); font-size: 13px; margin: 10px 0 0; }

/* ---------- chat frame ---------- */

#chat {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

#chat header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex: none;
}

#chat header .title { font-weight: 700; font-size: 17px; }

#chat header .spacer { flex: 1; }

#chat header .me { color: var(--muted); font-size: 13px; }

#chat header button {
  background: transparent;
  border: 1px solid rgba(255,255,255,.15);
  color: var(--muted);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
}

#chat header button:hover { color: var(--text); border-color: rgba(255,255,255,.3); }

#chat header button.bell {
  width: 32px; height: 30px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#chat header button.bell.on { color: var(--accent); border-color: var(--accent); }

#chat header button.bell.on::after {
  content: "";
  position: absolute;
  top: 2px; right: 2px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

.conn { font-size: 12px; color: var(--muted); }
.conn::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: 1px;
  background: #e05656;
}
.conn.on::before { background: var(--ok); }

/* ---------- messages ---------- */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sep {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  margin: 14px 0 8px;
  background: var(--panel);
  padding: 3px 12px;
  border-radius: 999px;
}

.msg {
  max-width: min(78%, 560px);
  align-self: flex-start;
}

.msg.mine { align-self: flex-end; }

.msg .who {
  font-size: 12px;
  color: var(--muted);
  margin: 8px 2px 3px;
}

.msg .bubble {
  background: var(--panel2);
  border-radius: var(--radius);
  padding: 8px 12px;
  overflow-wrap: break-word;
}

.msg.mine .bubble { background: var(--mine); }

.msg.group .bubble { border-radius: 8px; }
.msg.group.mine .bubble { border-radius: 8px; }

.msg .text { white-space: pre-wrap; }

.msg .text a {
  color: #9db9ff;
  text-decoration: underline;
}
.msg.mine .text a { color: #cdddff; }

.msg img.media {
  display: block;
  max-width: min(320px, 100%);
  max-height: 300px;
  border-radius: 10px;
  margin-top: 6px;
}

.msg .meta {
  display: block;
  font-size: 10.5px;
  color: var(--muted);
  text-align: right;
  margin-top: 2px;
}
.msg.mine .meta { color: #9fb4e8; }

.msg .bubble.imgonly { padding: 6px; background: transparent; }
.msg .bubble.imgonly .meta { color: var(--muted); }

/* ---------- jump pill ---------- */

#jump {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 13px;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
}

/* ---------- composer ---------- */

#composer {
  flex: none;
  background: var(--panel);
  border-top: 1px solid rgba(255,255,255,.06);
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}

#composer .row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.iconbtn {
  flex: none;
  width: 42px; height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--panel2);
  color: var(--muted);
  border: none;
  border-radius: 50%;
  transition: background .15s, color .15s;
}

.iconbtn:hover, .iconbtn:active { color: var(--text); }

.iconbtn.send { background: var(--accent); color: #fff; }
.iconbtn.send:disabled { opacity: .45; cursor: default; }

#text {
  flex: 1;
  background: var(--panel2);
  border: none;
  color: var(--text);
  font: inherit;
  resize: none;
  max-height: 30vh;
  border-radius: 21px;
  padding: 10px 15px;
  outline: none;
}

#preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  margin: 0 2px 8px;
  background: var(--panel2);
  border-radius: 10px;
}

#previewImg {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 8px;
  flex: none;
}

#preview .pinfo {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#clearImg {
  flex: none;
  width: 30px; height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.12);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translateX(-50%);
  background: #2c3448;
  color: var(--text);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13.5px;
  max-width: 86vw;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
  z-index: 10;
}

/* ---------- small screens ---------- */

@media (max-width: 600px) {
  .msg { max-width: 86%; }
  #chat header .me { display: none; }
}

/* scrollbars */
#messages::-webkit-scrollbar { width: 8px; }
#messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); border-radius: 4px; }
