:root {
  --bg: #0b0f14;
  --panel: #111823;
  --panel2: #16202c;
  --line: #1e2a38;
  --ink: #e6edf3;
  --mut: #8b98a6;
  --acc: #37c07a;
  --acc2: #1f9d5f;
  --mine: #14532d;
  --theirs: #18222e;
  --danger: #ff6b81;
  --warn: #ffd479;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--mut); }
.tiny { font-size: 11.5px; }
.grow { flex: 1; min-width: 0; }
.err { color: var(--danger); min-height: 18px; margin: 6px 0 0; font-size: 13px; }

/* ---------------------------------------------------------------- join */
.join { min-height: 100%; display: grid; place-items: center; padding: 22px; }
.joinCard {
  width: min(94vw, 400px); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 26px 24px; text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
.joinLogo { width: 76px; height: 76px; }
.joinCard h1 { font-size: 22px; margin: 10px 0 4px; letter-spacing: .2px; }
.joinCard form { text-align: left; margin-top: 18px; }
.lbl { display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--mut); margin: 12px 0 5px; }
.joinCard input {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--line);
  background: #0e1620; outline: none;
}
.joinCard input:focus { border-color: var(--acc2); }
.primary {
  width: 100%; margin-top: 18px; padding: 11px 16px; border: 0; border-radius: 10px;
  background: var(--acc); color: #05210f; font-weight: 700;
}
.primary:hover { background: #46d18a; }
.primary:disabled { opacity: .6; }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: 292px 1fr; height: 100%; }
#sidebar {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--panel); border-right: 1px solid var(--line);
}
.sideHead { display: flex; align-items: center; gap: 10px; padding: 12px 12px 10px; }
.sideLogo { width: 30px; height: 30px; }
.sideTools { display: flex; gap: 6px; padding: 0 12px 10px; }
.sideFoot { padding: 8px 12px 12px; }
#groupList { flex: 1; overflow: auto; padding: 4px 8px 12px; }
.groupBtn {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  background: transparent; border: 1px solid transparent; border-radius: 12px;
  padding: 9px 10px; color: var(--ink);
}
.groupBtn:hover { background: var(--panel2); }
.groupBtn.on { background: #1b2735; border-color: #263547; }
.avatar {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: #1f2d3d; color: #cfe4ff; font-weight: 700; font-size: 13px; flex: 0 0 auto;
}
.groupBtn .gname { display: block; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.groupBtn .gmeta { display: block; font-size: 11.5px; color: var(--mut); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }

#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#chatHead {
  display: flex; gap: 8px; align-items: center; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
#chatHead strong { display: block; font-size: 15.5px; }
.icon {
  background: transparent; border: 1px solid transparent; border-radius: 9px;
  width: 34px; height: 34px; display: grid; place-items: center; color: var(--mut); font-size: 16px;
}
.icon:hover { background: var(--panel2); color: var(--ink); }
.ghost {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 11px; color: var(--ink); font-weight: 600;
}
.ghost:hover { border-color: #33465e; }
.danger { background: #3a1b22; border: 1px solid #5c2a34; color: #ffb4c0;
  border-radius: 10px; padding: 7px 11px; font-weight: 600; }
.onlyNarrow { display: none; }

/* ---------------------------------------------------------------- messages */
.msgs {
  flex: 1; overflow-y: auto; padding: 16px 18px 6px; display: flex; flex-direction: column;
  gap: 8px;
}
.empty { margin: auto; color: var(--mut); text-align: center; }
.msg { max-width: min(76%, 640px); display: flex; flex-direction: column; gap: 2px; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .who { font-size: 11.5px; color: var(--mut); padding: 0 4px; }
.msg .bubble {
  padding: 8px 12px; border-radius: 14px; background: var(--theirs);
  border: 1px solid var(--line); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.mine .bubble { background: var(--mine); border-color: #1d6a3c; }
.msg .stamp { font-size: 10.5px; color: var(--mut); padding: 0 4px; }
.msg.pending .bubble { opacity: .65; }
.msg .fail { color: var(--danger); font-size: 11.5px; }
.daysep { text-align: center; color: var(--mut); font-size: 11.5px; margin: 10px 0 4px; }
.typing { padding: 2px 18px 6px; color: var(--mut); font-size: 12.5px; min-height: 20px; }
.composer {
  display: flex; gap: 8px; padding: 10px 14px 14px; border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer textarea {
  flex: 1; resize: none; max-height: 180px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: #0e1620; outline: none;
}
.composer textarea:focus { border-color: var(--acc2); }
.composer .primary { width: auto; margin: 0; padding: 10px 18px; }

/* ---------------------------------------------------------------- call bar */
.callBar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-radius: 999px;
  background: #0f1a16; border: 1px solid #1d6a3c; box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  z-index: 40;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--mut); display: inline-block; }
.dot.live { background: var(--acc); box-shadow: 0 0 0 0 rgba(55, 192, 122, .6);
  animation: pulse 1.8s infinite; background: var(--acc); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(55, 192, 122, .55); }
  70% { box-shadow: 0 0 0 10px rgba(55, 192, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(55, 192, 122, 0); }
}

/* ---------------------------------------------------------------- modals */
.overlay {
  position: fixed; inset: 0; background: rgba(4, 7, 10, .7); display: grid;
  place-items: center; padding: 18px; z-index: 80;
}
.modal {
  width: min(94vw, 520px); max-height: 86vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 26px 60px rgba(0, 0, 0, .55);
}
.modal header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.modalBody { padding: 16px; overflow: auto; }
.field { margin: 10px 0; }
.field label { display: block; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--mut); margin-bottom: 5px; }
.field input[type=text], .field input[type=number], .field select {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: #0e1620; outline: none;
}
.chk { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.chk input { width: 16px; height: 16px; accent-color: var(--acc); }
.codeOut {
  display: flex; gap: 8px; align-items: center; margin: 10px 0;
  background: #0e1620; border: 1px dashed #2c3d52; border-radius: 10px; padding: 10px 12px;
}
.codeOut code { font: 600 15px/1.2 ui-monospace, Menlo, monospace; letter-spacing: 1px;
  color: var(--warn); overflow-wrap: anywhere; }
.rows { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.row {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px;
  background: #0e1620; border: 1px solid var(--line);
}
.row .grow { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill {
  font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  border: 1px solid #2a3746; color: var(--mut);
}
.pill.ok { color: #9be7a8; border-color: #23543a; background: #13291d; }
.pill.bad { color: #ffb4c0; border-color: #5c2a34; background: #2b151a; }
.hr { height: 1px; background: var(--line); margin: 14px 0; }
.range { width: 100%; accent-color: var(--acc); }

/* ---------------------------------------------------------------- toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column;
  gap: 8px; z-index: 100; }
.toast {
  background: #111a24; border: 1px solid var(--line); border-radius: 10px; padding: 9px 13px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .45); max-width: 340px;
}
.toast.err { border-color: #5c2a34; color: #ffb4c0; }
.toast.ok { border-color: #23543a; color: #b6f0c8; }

/* ---------------------------------------------------------------- narrow */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; inset: 0 auto 0 0; width: 86vw; max-width: 320px; z-index: 60;
    transform: translateX(-102%); transition: transform .18s ease;
  }
  body.nav #sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); }
  .onlyNarrow { display: grid; }
  .msg { max-width: 88%; }
  .callBar { left: 10px; right: 10px; transform: none; justify-content: space-between; }
}
