:root {
  --bg: #0f1216;
  --bg-elev: #161a21;
  --bg-input: #1c2029;
  --border: #242933;
  --text: #e6e8ee;
  --text-dim: #9aa3b2;
  --muted: #6c7483;
  --accent: #6aa2ff;
  --accent-ink: #0f1216;
  --error: #ff6b6b;
  --join: #7bd389;
  --leave: #ffb067;
  --dm-bg: #22202d;
  --dm-border: #5a4ea0;
  --mine-bg: #1d2a3d;
  --mine-border: #2f4b73;
  --system-fg: #8ea0b5;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 8px 24px rgba(0,0,0,.25);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); }

#app { height: 100%; }

.screen { height: 100%; }
[hidden] { display: none !important; }

/* ---------- join screen ---------- */

#join {
  display: grid;
  place-items: center;
  padding: 16px;
}
.join-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.join-card h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: .2px; }
.join-card .sub { margin: 0 0 20px; color: var(--text-dim); font-size: 14px; line-height: 1.45; }
#join-form { display: flex; gap: 8px; }
#join-form input { flex: 1; }
.error { color: var(--error); margin: 10px 0 0; font-size: 13px; }

/* ---------- inputs & buttons ---------- */

input[type=text] {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input[type=text]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(106,162,255,.2);
}

button {
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: filter .12s ease;
}
button:hover { filter: brightness(1.06); }
button:active { filter: brightness(.95); }
#quit {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 10px;
  font-weight: 500;
}
#quit:hover { color: var(--text); border-color: var(--text-dim); }

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

#chat { display: grid; grid-template-columns: 240px 1fr; height: 100%; }
@media (max-width: 640px) { #chat { grid-template-columns: 1fr; } #sidebar { display: none; } }

#sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}
#sidebar header { padding: 16px 16px 10px; border-bottom: 1px solid var(--border); }
#sidebar .brand { font-weight: 700; letter-spacing: .3px; font-size: 14px; }
#sidebar .status {
  margin-top: 6px;
  display: flex; align-items: center; gap: 8px;
  color: var(--text-dim); font-size: 12px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok   { background: var(--join); box-shadow: 0 0 0 3px rgba(123,211,137,.15); }
.dot.warn { background: var(--leave); box-shadow: 0 0 0 3px rgba(255,176,103,.15); animation: pulse 1.2s ease-in-out infinite; }
.dot.bad  { background: var(--error); box-shadow: 0 0 0 3px rgba(255,107,107,.15); }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

.roster-title {
  padding: 14px 16px 6px;
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted);
}
#roster { list-style: none; margin: 0; padding: 0 8px; flex: 1; overflow-y: auto; }
#roster li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px; font-size: 14px; color: var(--text-dim);
  cursor: pointer;
}
#roster li:hover { background: var(--bg-input); color: var(--text); }
#roster li.me { color: var(--text); }
#roster li .av {
  width: 22px; height: 22px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700; color: var(--bg);
  background: var(--accent);
}
#sidebar footer {
  padding: 12px 14px; border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 13px; color: var(--text-dim);
}
#sidebar footer .me strong { color: var(--text); }

main { display: grid; grid-template-rows: auto 1fr auto auto; min-width: 0; }
#chat-header {
  padding: 8px 12px 0 12px; border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex; align-items: flex-end; gap: 8px;
  min-height: 42px;
}
#chat-header .muted { color: var(--text-dim); font-size: 12px; }

/* --- tab strip ------------------------------------------------- */
#tabs {
  display: flex; align-items: flex-end; gap: 4px;
  flex: 1; overflow-x: auto; scrollbar-width: thin;
}
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; margin-bottom: -1px;
  background: transparent; border: 1px solid transparent;
  border-top-left-radius: 8px; border-top-right-radius: 8px;
  color: var(--text-dim); font-size: 13px; cursor: pointer;
  white-space: nowrap; user-select: none;
  position: relative;
}
.tab:hover { color: var(--text); background: var(--bg-input); }
.tab.active {
  color: var(--text); background: var(--bg);
  border-color: var(--border); border-bottom-color: var(--bg);
}
.tab .tab-kind { font-size: 10px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.tab.active .tab-kind { color: var(--accent); }
.tab .tab-close {
  display: inline-grid; place-items: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 11px;
  border: 0; cursor: pointer; line-height: 1;
}
.tab .tab-close:hover { background: var(--border); color: var(--text); }
.tab.unread::after {
  content: ''; position: absolute; top: 6px; right: 4px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
}

/* per-tab action buttons on the right (call buttons) */
#chat-actions { display: flex; gap: 6px; align-items: center; padding-bottom: 8px; }
#chat-actions button {
  background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
  padding: 6px 10px; font-size: 14px; line-height: 1;
  border-radius: 6px;
}
#chat-actions button:hover { background: var(--border); }

/* --- incoming-call modal -------------------------------------- */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(10,12,16,.75); backdrop-filter: blur(4px);
  display: grid; place-items: center;
}
.modal-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px 32px; min-width: 300px; text-align: center;
  box-shadow: var(--shadow);
  animation: ringPulse 1.5s ease-in-out infinite;
}
@keyframes ringPulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(106,162,255,.35); }
  50%     { box-shadow: 0 0 0 16px rgba(106,162,255,0); }
}
.caller-avatar {
  width: 68px; height: 68px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 28px; font-weight: 700;
  margin: 0 auto 12px;
}
.caller-name { font-size: 16px; }
.caller-kind { color: var(--text-dim); font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: .1em; }
.modal-actions { margin-top: 20px; display: flex; gap: 10px; justify-content: center; }
button.danger { background: var(--error); color: white; }
button.primary { background: var(--accent); color: var(--accent-ink); }

/* --- in-call view -------------------------------------------- */
#call-view {
  position: fixed; inset: 0; z-index: 900;
  background: #000; display: flex; flex-direction: column;
}
.call-stage { flex: 1; position: relative; overflow: hidden; display: grid; place-items: center; }
#remote-video { width: 100%; height: 100%; object-fit: contain; background: #111; }
#local-video {
  position: absolute; bottom: 20px; right: 20px;
  width: 200px; max-width: 30vw; aspect-ratio: 16/9;
  border: 2px solid var(--bg-elev); border-radius: 10px;
  background: #222; object-fit: cover;
}
#call-peer-label {
  position: absolute; top: 20px; left: 20px;
  background: rgba(0,0,0,.6); color: #fff; padding: 6px 12px;
  border-radius: 6px; font-size: 14px;
}
.call-controls {
  display: flex; gap: 12px; justify-content: center;
  padding: 16px; background: var(--bg-elev); border-top: 1px solid var(--border);
}
.call-controls button {
  min-width: 56px; height: 48px; border-radius: 24px;
  background: var(--bg-input); color: var(--text); border: 1px solid var(--border);
  font-size: 18px;
}
.call-controls button.off { background: var(--error); color: #fff; }
.call-controls button.danger { background: var(--error); color: #fff; min-width: 90px; }

#messages {
  list-style: none; margin: 0; padding: 14px 20px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 8px;
}
#messages li {
  max-width: 78%;
  padding: 8px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px; line-height: 1.45;
  word-wrap: break-word;
}
#messages li .meta {
  font-size: 11px; color: var(--muted); margin-bottom: 2px;
  display: flex; gap: 6px; align-items: baseline;
}
#messages li .meta .who { color: var(--text); font-weight: 600; }
#messages li.mine { align-self: flex-end; background: var(--mine-bg); border-color: var(--mine-border); }
#messages li.dm { background: var(--dm-bg); border-color: var(--dm-border); }
#messages li.system,
#messages li.join,
#messages li.leave,
#messages li.error {
  align-self: center;
  background: transparent;
  border: 0;
  color: var(--system-fg);
  font-size: 12px;
  padding: 2px 6px;
}
#messages li.join  { color: var(--join); }
#messages li.leave { color: var(--leave); }
#messages li.error { color: var(--error); }

#send-form {
  display: flex; gap: 8px;
  padding: 12px 20px 6px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
#send-form input { flex: 1; }

.hint {
  margin: 0; padding: 4px 20px 12px;
  color: var(--muted); font-size: 11px;
  background: var(--bg-elev);
}
.hint code {
  background: var(--bg-input);
  padding: 1px 6px; border-radius: 4px;
  color: var(--text-dim);
}
