:root {
  --rail: #0b1118;
  --side: #111923;
  --main: #151f2b;
  --elev: #1c2836;
  --hover: #1a2533;
  --border: #243244;
  --text: #e6edf3;
  --muted: #8b9bb0;
  --accent: #2dd4bf;
  --accent-ink: #04201c;
  --danger: #fb7185;
  --warn: #f59e0b;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--main);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
::selection { background: rgba(45, 212, 191, 0.3); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }

/* ---------- buttons and fields ---------- */
.btn {
  background: var(--elev); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-weight: 600;
}
.btn:hover { background: var(--hover); border-color: #34475f; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.field { display: block; margin: 0 0 14px; }
.field > span { display: block; font-size: 12px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; background: var(--rail); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(45, 212, 191, 0.18); }
.error { color: var(--danger); min-height: 1.3em; font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }

/* ---------- sign in ---------- */
#app { height: 100%; }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(900px 500px at 70% -10%, rgba(45, 212, 191, 0.12), transparent), var(--rail); }
.auth-card { width: 100%; max-width: 400px; background: var(--side); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4); }
.auth-card h1 { margin: 0 0 4px; font-size: 26px; display: flex; align-items: center; gap: 10px; }
.auth-card h1 img { width: 34px; height: 34px; }
.auth-card .sub { margin: 0 0 20px; color: var(--muted); }
.tabs { display: flex; gap: 6px; margin-bottom: 18px; background: var(--rail); padding: 4px; border-radius: 10px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--elev); color: var(--text); }
.invite-note { background: rgba(45, 212, 191, 0.1); border: 1px solid rgba(45, 212, 191, 0.3); border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; font-size: 14px; }

/* ---------- main layout ---------- */
.shell { display: grid; grid-template-columns: 72px 240px minmax(0, 1fr) auto; height: 100dvh; }
.rail { background: var(--rail); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 0; overflow-y: auto; }
.rail .sep { width: 32px; height: 2px; background: var(--border); border-radius: 2px; }
.pill {
  position: relative; width: 48px; height: 48px; border-radius: 24px; border: 0; background: var(--elev);
  display: grid; place-items: center; font-weight: 700; font-size: 17px; transition: border-radius 0.15s, background 0.15s;
  flex: none; overflow: hidden;
}
.pill:hover, .pill.on { border-radius: 15px; background: var(--accent); color: var(--accent-ink); }
.pill.add { color: var(--accent); font-size: 26px; font-weight: 400; }
.pill.add:hover { color: var(--accent-ink); }
.pill.home img { width: 28px; height: 28px; }
.pill .dot { position: absolute; right: 2px; top: 2px; min-width: 16px; height: 16px; background: var(--danger); border-radius: 8px; font-size: 11px; line-height: 16px; padding: 0 4px; color: #fff; }

.side { background: var(--side); display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.side-head { height: 52px; padding: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); font-weight: 700; flex: none; }
.side-head .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-body { flex: 1; overflow-y: auto; padding: 10px 8px; min-height: 0; }
.side-label { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.side-label button { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; }
.side-label button:hover { color: var(--text); }
.row {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none;
  border-radius: 8px; color: var(--muted); font-weight: 500;
}
.row:hover { background: var(--hover); color: var(--text); }
.row.on { background: var(--elev); color: var(--text); }
.row.unread { color: var(--text); font-weight: 700; }
.row .hash { opacity: 0.6; font-weight: 700; width: 14px; text-align: center; }
.row .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--danger); color: #fff; border-radius: 9px; font-size: 11px; font-weight: 700; padding: 0 6px; line-height: 18px; }
.userbar { flex: none; display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--rail); border-top: 1px solid var(--border); }
.userbar .who { flex: 1; min-width: 0; line-height: 1.2; }
.userbar .who b, .userbar .who small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userbar .who small { color: var(--muted); font-size: 12px; }

.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #06201c; flex: none; position: relative; user-select: none; }
.avatar.sm { width: 28px; height: 28px; font-size: 13px; }
.avatar .presence { position: absolute; right: -2px; bottom: -2px; width: 11px; height: 11px; border-radius: 50%; background: #64748b; border: 2px solid var(--side); }
.avatar .presence.on { background: #34d399; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--main); }
.topbar { height: 52px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); font-weight: 700; }
.topbar .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .navbtn { display: none; }
.banner { background: var(--warn); color: #261a00; text-align: center; padding: 4px; font-size: 13px; font-weight: 600; }

.msgs { flex: 1; overflow-y: auto; padding: 12px 0 8px; min-height: 0; }
.msgs .start { padding: 20px 16px; color: var(--muted); }
.msgs .start h2 { color: var(--text); margin: 0 0 4px; }
.msg { position: relative; display: grid; grid-template-columns: 52px minmax(0, 1fr); padding: 2px 16px 2px 8px; }
.msg:hover { background: rgba(255, 255, 255, 0.025); }
.msg.first { margin-top: 12px; }
.msg .gutter { display: flex; justify-content: center; padding-top: 2px; }
.msg .gutter .time { opacity: 0; font-size: 11px; color: var(--muted); padding-top: 4px; }
.msg:hover .gutter .time { opacity: 1; }
.msg .meta { display: flex; align-items: baseline; gap: 8px; }
.msg .author { font-weight: 700; }
.msg .stamp { font-size: 12px; color: var(--muted); }
.msg .edited { font-size: 11px; color: var(--muted); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg .replyref { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 2px; padding-left: 10px; border-left: 2px solid var(--border); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.msg .replyref b { color: var(--text); }
.msg.flash { animation: flash 1.4s ease; }
@keyframes flash { from { background: rgba(45, 212, 191, 0.25); } to { background: transparent; } }
.msg .actions { position: absolute; right: 14px; top: -14px; display: none; background: var(--elev); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; z-index: 2; }
.msg:hover .actions, .msg:focus-within .actions { display: flex; }
.msg .actions button { background: none; border: 0; padding: 4px 10px; font-size: 13px; color: var(--muted); }
.msg .actions button:hover { background: var(--hover); color: var(--text); }
.msg .actions button.danger:hover { color: var(--danger); }
.msg .editbox { width: 100%; }
.msg .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mention { background: rgba(45, 212, 191, 0.15); color: var(--accent); border-radius: 4px; padding: 0 3px; font-weight: 600; }
.mention.me { background: rgba(245, 158, 11, 0.25); color: #fbbf24; }
code.ic { background: var(--rail); border-radius: 4px; padding: 1px 5px; font-size: 0.92em; }
pre.cb { background: var(--rail); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 4px 0; white-space: pre; font-size: 13.5px; }
.msg.mentioned { background: rgba(245, 158, 11, 0.08); box-shadow: inset 3px 0 0 var(--warn); }
.attach img { max-width: min(420px, 100%); max-height: 320px; border-radius: 8px; display: block; margin-top: 4px; background: var(--rail); }
.filecard { display: inline-flex; flex-direction: column; margin-top: 4px; padding: 8px 12px; background: var(--rail); border: 1px solid var(--border); border-radius: 8px; text-decoration: none; color: var(--text); max-width: 100%; }
.filecard small { color: var(--muted); }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.react { display: inline-flex; align-items: center; gap: 5px; background: var(--elev); border: 1px solid var(--border); border-radius: 8px; padding: 1px 8px; font-size: 14px; }
.react.mine { border-color: var(--accent); background: rgba(45, 212, 191, 0.14); }
.react small { font-weight: 700; color: var(--muted); }

.composer-wrap { flex: none; padding: 0 16px 14px; position: relative; }
.typing { height: 20px; font-size: 13px; color: var(--muted); padding: 0 4px; }
.replybar { display: flex; justify-content: space-between; align-items: center; background: var(--elev); border-radius: 8px 8px 0 0; padding: 6px 12px; font-size: 13px; color: var(--muted); }
.replybar button { background: none; border: 0; color: var(--muted); font-size: 16px; }
.pending { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px 0; background: var(--elev); border-radius: 10px 10px 0 0; }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--rail); border: 1px solid var(--border); border-radius: 8px; padding: 3px 8px; font-size: 13px; }
.chip button { background: none; border: 0; color: var(--muted); padding: 0 2px; }
.composer { display: flex; align-items: flex-end; gap: 6px; background: var(--elev); border-radius: 12px; padding: 6px; }
.replybar + .composer, .pending + .composer { border-top-left-radius: 0; border-top-right-radius: 0; }
.composer textarea { flex: 1; background: none; border: 0; outline: none; resize: none; max-height: 200px; padding: 8px 6px; min-height: 38px; }
.iconbtn { background: none; border: 0; width: 38px; height: 38px; border-radius: 8px; color: var(--muted); font-size: 18px; flex: none; }
.iconbtn:hover { background: var(--hover); color: var(--text); }
.emojis { position: absolute; bottom: 70px; right: 20px; width: 300px; background: var(--elev); border: 1px solid var(--border); border-radius: 12px; padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; z-index: 20; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5); }
.emojis.floating { position: fixed; bottom: auto; right: auto; }
.emojis button { background: none; border: 0; font-size: 20px; border-radius: 6px; padding: 4px 0; }
.emojis button:hover { background: var(--hover); }
.drop { position: absolute; inset: 0; background: rgba(11, 17, 24, 0.85); display: none; place-items: center; font-size: 20px; font-weight: 700; z-index: 30; border: 3px dashed var(--accent); }
.drop.on { display: grid; }

.members { width: 224px; background: var(--side); border-left: 1px solid var(--border); overflow-y: auto; padding: 10px 8px; }
.members h4 { margin: 10px 8px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.member { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; text-align: left; padding: 5px 8px; border-radius: 8px; }
.member:hover { background: var(--hover); }
.member.off { opacity: 0.5; }
.member .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.member .role { font-size: 11px; color: var(--warn); font-weight: 700; }

.welcome { flex: 1; overflow-y: auto; padding: 28px 20px; }
.welcome .grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); max-width: 900px; }
.card { background: var(--side); border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.card h3 { margin: 0 0 4px; }
.card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.line { display: flex; gap: 8px; }

/* ---------- modal and toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: 100%; max-width: 440px; background: var(--side); border: 1px solid var(--border); border-radius: 16px; padding: 22px; max-height: 90dvh; overflow: auto; }
.modal h3 { margin: 0 0 14px; font-size: 18px; }
.modal .buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 3px solid transparent; }
.swatch.on { border-color: var(--text); }
.copyline { display: flex; gap: 8px; margin-bottom: 10px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--elev); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; z-index: 60; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); max-width: 90vw; }
.toast.err { border-color: var(--danger); }

/* ---------- small screens ---------- */
@media (max-width: 900px) { .members { display: none; } .members.show { display: block; position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; width: min(260px, 80vw); } }
@media (max-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail, .side { position: fixed; top: 0; bottom: 0; z-index: 40; transition: transform 0.2s; }
  .rail { left: 0; width: 72px; transform: translateX(-100%); }
  .side { left: 72px; width: min(260px, calc(100vw - 72px)); transform: translateX(calc(-100% - 72px)); }
  body.nav-open .rail, body.nav-open .side { transform: none; }
  body.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.5); z-index: 35; }
  .topbar .navbtn { display: inline-block; }
  .msg .actions { display: flex; top: 0; right: 8px; background: transparent; border: 0; }
  .msg .actions button { padding: 2px 6px; }
  .composer-wrap { padding: 0 8px calc(10px + env(safe-area-inset-bottom)); }
}
