/* Relay27 web client. Dark, violet accent. No external resources. */

:root {
  --bg: #0b0a12;
  --surface: #13111c;
  --surface-2: #1a1726;
  --surface-3: #231f33;
  --border: #272338;
  --text: #ece9f5;
  --muted: #9a94b0;
  --accent: #7c3aed;
  --accent-2: #a855f7;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 10px;
  --glow: 0 0 0 1px rgba(168, 85, 247, .45), 0 0 22px rgba(124, 58, 237, .45);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[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, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
#app { height: 100vh; height: 100dvh; }
h1, h2, h3, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: var(--accent-2); overflow-wrap: anywhere; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 2px; }
.icon { flex: none; display: block; }
.spacer { flex: 1; }
.boot { padding: 2rem; color: var(--muted); text-align: center; }

/* ----------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .55rem 1rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); font-weight: 600;
}
.btn:hover:not(:disabled) { background: var(--surface-3); }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, var(--accent), #6d28d9); color: #fff; }
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }
.btn-danger { border-color: transparent; background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #dc2626; }
.btn-block { width: 100%; }
.btn-link { padding: 0; border: 0; background: none; color: var(--accent-2); font-weight: 600; }
.btn-link:hover { text-decoration: underline; }

.icon-btn {
  display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; padding: 0;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
}
.icon-btn:hover, .icon-btn.on { background: var(--surface-3); color: var(--text); }

.avatar {
  display: inline-grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%;
  color: #fff; font-size: 13px; font-weight: 700; letter-spacing: .02em; user-select: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-xs { width: 20px; height: 20px; font-size: 9px; }

.badge {
  min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent);
  color: #fff; font-size: 11px; font-weight: 700; line-height: 20px; text-align: center;
}

/* -------------------------------------------------------------- forms */

.form { display: grid; gap: .9rem; }
.stack { display: grid; gap: 1.25rem; }
.field { display: grid; gap: .35rem; }
.field > span { color: var(--muted); font-size: 13px; font-weight: 600; }
.field small, .form-intro { color: var(--muted); }
.field small { font-size: 12px; }
input[type="text"], input[type="password"], textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); outline: none;
}
textarea { resize: vertical; }
input:focus-visible, textarea:focus-visible { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(168, 85, 247, .25); }
.form-error { padding: .5rem .75rem; border-radius: 8px; background: rgba(239, 68, 68, .12); color: #fca5a5; font-size: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; }
.copy-row { display: flex; align-items: center; gap: .4rem; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.modal {
  width: min(460px, calc(100vw - 2rem)); max-height: calc(100dvh - 2rem); padding: 0; overflow: auto;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .6);
}
.modal::backdrop { background: rgba(5, 4, 10, .7); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1rem .25rem 1.25rem; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: .75rem 1.25rem 1.25rem; }

#toasts { position: fixed; z-index: 100; left: 50%; bottom: 1.25rem; display: grid; gap: .5rem; width: min(420px, calc(100vw - 2rem)); transform: translateX(-50%); pointer-events: none; }
.toast { padding: .65rem .9rem; border: 1px solid var(--border); border-left: 3px solid var(--accent-2); border-radius: var(--radius); background: var(--surface-3); box-shadow: 0 10px 30px rgba(0, 0, 0, .5); }
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }

/* --------------------------------------------------------------- auth */

.auth {
  display: grid; place-items: center; height: 100%; padding: 1rem; overflow: auto;
  background:
    radial-gradient(60rem 30rem at 15% -10%, rgba(124, 58, 237, .28), transparent 60%),
    radial-gradient(50rem 28rem at 100% 110%, rgba(168, 85, 247, .18), transparent 60%),
    var(--bg);
}
.auth-card {
  display: grid; gap: 1rem; width: min(400px, 100%); padding: 2rem; border: 1px solid var(--border);
  border-radius: 18px; background: rgba(19, 17, 28, .92); box-shadow: 0 30px 90px rgba(0, 0, 0, .55); text-align: center;
}
.auth-card .form { text-align: left; }
.auth-logo { margin: 0 auto; border-radius: 16px; box-shadow: var(--glow); }
.auth-card h1 { font-size: 26px; letter-spacing: .04em; }
.auth-sub, .auth-switch { color: var(--muted); }

/* -------------------------------------------------------------- shell */

.shell { display: flex; height: 100%; }
.drawer { display: flex; flex: none; }
.drawer-backdrop { display: none; }

.rail {
  display: flex; flex-direction: column; align-items: center; gap: .6rem; width: 68px; padding: .75rem 0;
  background: var(--bg); border-right: 1px solid var(--border); overflow-y: auto; scrollbar-width: none;
}
.rail-logo { border-radius: 12px; }
.rail-sep { width: 28px; height: 1px; flex: none; background: var(--border); }
.rail-btn {
  display: grid; place-items: center; flex: none; width: 44px; height: 44px; padding: 0; border: 1px solid var(--border);
  border-radius: 14px; background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 700;
  transition: border-radius .15s, background .15s, color .15s;
}
.rail-btn:hover { background: var(--surface-3); color: var(--text); }
.rail-btn.active { border-color: transparent; background: linear-gradient(135deg, var(--accent-2), #5b21b6); color: #fff; box-shadow: var(--glow); }
.rail-add { border-style: dashed; color: var(--accent-2); }

.sidebar { display: flex; flex-direction: column; width: 250px; background: var(--surface); border-right: 1px solid var(--border); }
.side-head { display: flex; align-items: center; gap: .25rem; min-height: 60px; padding: .6rem .5rem .6rem 1rem; border-bottom: 1px solid var(--border); }
.side-title { flex: 1; min-width: 0; }
.side-title h2 { overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.side-sub { display: flex; align-items: center; gap: .35rem; color: var(--muted); font-size: 12px; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.side-actions { display: flex; }
.side-list { flex: 1; padding: .25rem .5rem 1rem; overflow-y: auto; }
.side-section { display: flex; align-items: center; justify-content: space-between; min-height: 32px; margin-top: .9rem; padding-left: .5rem; }
.side-section h3 { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.side-hint { padding: .35rem .5rem; color: var(--muted); font-size: 13px; }

.chan { display: flex; align-items: center; margin-top: 2px; border-radius: 8px; color: var(--muted); }
.chan:hover, .chan:focus-within { background: var(--surface-2); color: var(--text); }
.chan-main { display: flex; align-items: center; flex: 1; gap: .5rem; min-width: 0; padding: .45rem .5rem; border: 0; border-radius: 8px; background: none; color: inherit; text-align: left; }
.chan-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan.unread { color: var(--text); font-weight: 600; }
.chan.active { background: linear-gradient(90deg, var(--accent), #5b21b6); color: #fff; }
.chan.active .badge { background: rgba(255, 255, 255, .22); }
.chan.in-call { background: rgba(34, 197, 94, .12); color: #86efac; }
.chan-del { width: 28px; height: 28px; margin-right: 2px; color: inherit; opacity: 0; }
.chan:hover .chan-del, .chan:focus-within .chan-del { opacity: .8; }
.voice-peers { display: grid; gap: 2px; margin: 2px 0 4px 1.6rem; }
.voice-peers li { display: flex; align-items: center; gap: .4rem; padding: 2px .25rem; color: var(--muted); font-size: 13px; }
.vp-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }

.userbar { display: flex; align-items: center; gap: .5rem; padding: .6rem .5rem .6rem .75rem; border-top: 1px solid var(--border); background: var(--bg); }
.user-meta { display: grid; flex: 1; min-width: 0; line-height: 1.25; }
.user-name, .user-handle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-name { font-weight: 600; }
.user-handle { color: var(--muted); font-size: 12px; }

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

.chat { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: .5rem; min-height: 60px; padding: 0 .75rem 0 1rem; border-bottom: 1px solid var(--border); }
.chat-head h1 { display: flex; align-items: center; gap: .4rem; min-width: 0; font-size: 17px; }
.chat-head h1 span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head h1 .icon { color: var(--muted); }
.conn { padding: 2px 10px; border-radius: 12px; background: rgba(239, 68, 68, .14); color: #fca5a5; font-size: 12px; white-space: nowrap; }
.only-narrow { display: none; }

.chat-body { position: relative; display: flex; flex: 1; min-height: 0; }
.messages { flex: 1; min-width: 0; padding: 1rem 0 .5rem; overflow-y: auto; overflow-anchor: none; }
.hint { padding: .5rem 1rem; color: var(--muted); font-size: 13px; text-align: center; }
.day { display: flex; align-items: center; gap: .75rem; margin: .9rem 1rem .4rem; color: var(--muted); font-size: 12px; font-weight: 600; }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.msg { position: relative; display: flex; gap: .75rem; padding: .2rem 1rem; }
.msg:not(.grouped) { margin-top: .7rem; }
.msg:hover, .msg:focus-within { background: rgba(255, 255, 255, .025); }
.msg-avatar { width: 40px; height: 40px; margin-top: 2px; font-size: 14px; }
.msg-gutter { flex: none; width: 40px; padding-top: 3px; color: transparent; font-size: 11px; text-align: center; }
.msg:hover .msg-gutter { color: var(--muted); }
.msg-main { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: .5rem; }
.msg-author { color: var(--accent-2); font-weight: 700; }
.msg-head time { color: var(--muted); font-size: 12px; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-edited { color: var(--muted); font-size: 12px; }
.msg-actions {
  position: absolute; top: -12px; right: 1rem; display: none; padding: 2px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-2); box-shadow: 0 6px 18px rgba(0, 0, 0, .4);
}
.msg:hover .msg-actions, .msg:focus-within .msg-actions { display: flex; }
.msg-actions .icon-btn { width: 28px; height: 28px; }

.empty { display: grid; justify-items: center; gap: .6rem; max-width: 420px; margin: 12vh auto 0; padding: 1rem; color: var(--muted); text-align: center; }
.empty img { border-radius: 14px; box-shadow: var(--glow); }
.empty h2 { color: var(--text); font-size: 20px; }
.empty-actions { margin-top: .5rem; }

.members { flex: none; width: 220px; padding: .5rem; border-left: 1px solid var(--border); background: var(--surface); overflow-y: auto; }
.members h3 { margin: .75rem .5rem .35rem; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.member { display: flex; align-items: center; gap: .5rem; padding: .3rem .5rem; border-radius: 8px; }
.member.offline { opacity: .5; }
.member-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role { padding: 0 6px; border: 1px solid var(--border); border-radius: 8px; color: var(--muted); font-size: 11px; }

.typing { min-height: 20px; padding: 0 1.25rem; color: var(--muted); font-size: 12px; }
.composer { display: flex; align-items: flex-end; gap: .5rem; margin: 0 1rem 1rem; padding: .35rem .4rem .35rem .9rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-2); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 58, 237, .2); }
.composer-input { flex: 1; min-height: 36px; max-height: 180px; padding: .45rem 0; border: 0; border-radius: 0; background: none; box-shadow: none !important; resize: none; }
.composer-send { width: 36px; height: 36px; color: var(--accent-2); }

/* --------------------------------------------------------------- call */

.call { display: flex; flex: none; flex-direction: column; width: clamp(340px, 34vw, 540px); border-left: 1px solid var(--border); background: var(--surface); }
.shell.call-wide .call { flex: 1; width: auto; }
.shell.call-wide .chat { display: none; }
.shell.call-wide .tile { max-height: calc(100dvh - 150px); }
.call-head { display: flex; align-items: center; gap: .5rem; min-height: 60px; padding: 0 .75rem 0 1rem; border-bottom: 1px solid var(--border); }
.call-head h2 { overflow: hidden; font-size: 16px; text-overflow: ellipsis; white-space: nowrap; }
.live-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--success); box-shadow: 0 0 10px rgba(34, 197, 94, .7); }
.live-dot.pending { background: #f59e0b; box-shadow: none; }
.call-status { color: var(--muted); font-size: 12px; white-space: nowrap; }
.call-count { display: flex; align-items: center; gap: .3rem; color: var(--muted); font-size: 13px; }

.call-grid { --cols: 1; display: grid; flex: 1; grid-template-columns: repeat(var(--cols), minmax(0, 1fr)); align-content: start; gap: 8px; min-height: 0; padding: 10px; overflow-y: auto; }
.tile { position: relative; aspect-ratio: 4 / 3; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.tile video { display: block; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile--mirrored video { transform: scaleX(-1); }
.tile--screen { grid-column: 1 / -1; aspect-ratio: 16 / 9; }
.tile--screen video { object-fit: contain; }
.tile:fullscreen { border: 0; border-radius: 0; }
.tile:fullscreen video { object-fit: contain; }
.tile-avatar { position: absolute; top: 50%; left: 50%; display: grid; place-items: center; width: 34%; aspect-ratio: 1; transform: translate(-50%, -50%); border-radius: 50%; background: var(--surface-3); color: #fff; font-size: clamp(14px, 2.4vw, 26px); font-weight: 700; }
.tile-bar { position: absolute; left: 6px; right: 6px; bottom: 6px; display: flex; align-items: center; gap: 4px; pointer-events: none; }
.tile-name { max-width: 100%; padding: 1px 8px; border-radius: 8px; background: rgba(8, 7, 14, .7); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-muted { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%; background: var(--danger); color: #fff; }

.call-controls { display: flex; justify-content: center; gap: .9rem; padding: .9rem; border-top: 1px solid var(--border); }
.ctl { display: grid; place-items: center; width: 50px; height: 50px; padding: 0; border: 1px solid var(--border); border-radius: 50%; background: var(--surface-3); }
.ctl:hover { border-color: var(--accent-2); }
.ctl.off { background: rgba(239, 68, 68, .15); border-color: rgba(239, 68, 68, .4); color: #fca5a5; }
.ctl.active { background: var(--accent); border-color: transparent; color: #fff; box-shadow: var(--glow); }
.ctl-hangup { background: var(--danger); border-color: transparent; color: #fff; }
.ctl-hangup:hover { background: #dc2626; border-color: transparent; }
.ctl-hangup .icon { transform: rotate(135deg); }

/* ------------------------------------------------------ narrow screens */

@media (max-width: 1180px) {
  .members { position: absolute; z-index: 5; top: 0; right: 0; bottom: 0; box-shadow: -12px 0 30px rgba(0, 0, 0, .45); }
}

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .only-narrow { display: inline-grid; }
  .only-wide { display: none; }
  .drawer { position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; max-width: 92vw; transform: translateX(-102%); transition: transform .18s ease-out; }
  .shell.drawer-open .drawer { transform: none; box-shadow: 20px 0 60px rgba(0, 0, 0, .6); }
  .shell.drawer-open .drawer-backdrop { position: fixed; z-index: 20; inset: 0; display: block; background: rgba(5, 4, 10, .6); }
  .call { order: -1; width: auto; max-height: 48dvh; border-left: 0; border-bottom: 1px solid var(--border); }
  .shell.call-wide .chat { display: flex; }
  .call-head { min-height: 48px; }
  .call-controls { padding: .6rem; }
  .ctl { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
