:root {
  --bg: #0f1620;
  --bg-2: #141d2a;
  --panel: #1a2433;
  --panel-2: #223046;
  --accent: #00aff0;
  --accent-2: #0078d4;
  --text: #e6edf6;
  --muted: #8aa0bd;
  --danger: #e74c3c;
  --green: #2ecc71;
  --border: #25344a;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 14px;
}
.me { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; color: white; font-size: 18px;
  flex-shrink: 0;
}
.avatar.small { width: 36px; height: 36px; font-size: 15px; }
.me-name { font-weight: 600; }
.me-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.online { background: var(--green); box-shadow: 0 0 6px var(--green); }

.search input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  outline: none;
}
.search input:focus { border-color: var(--accent); }
.pub-toggle {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted); margin-top: 8px;
  cursor: pointer; user-select: none;
}
.pub-toggle input { accent-color: var(--accent); }
.contact-list .empty {
  font-size: 12px; color: var(--muted); padding: 4px 10px; cursor: default;
}
.contact-list .empty:hover { background: transparent; }
.count-pill {
  margin-left: auto; background: var(--accent-2); color: white;
  font-size: 11px; padding: 1px 8px; border-radius: 10px;
}

.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--muted); margin-top: 6px;
}

.contact-list {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 4px;
  overflow-y: auto;
  max-height: 200px;
}
.contact-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 10px; cursor: pointer;
}
.contact-list li:hover { background: var(--panel); }
.contact-list li.active { background: var(--panel-2); }
.contact-list .name { font-size: 14px; }
.contact-list .sub { font-size: 11px; color: var(--muted); }

.join-btn {
  margin-top: auto;
  padding: 12px;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white; border: none; font-weight: 600; cursor: pointer;
  font-size: 14px;
  transition: transform .1s, opacity .2s;
}
.join-btn:hover { transform: translateY(-1px); }
.join-btn:disabled { opacity: .5; cursor: not-allowed; }

/* Main */
.main { display: flex; flex-direction: column; background: var(--bg); }
.topbar {
  height: 64px; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.room-title { display: flex; align-items: center; gap: 12px; }
.room-name { font-weight: 600; }
.room-sub { font-size: 12px; color: var(--muted); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  cursor: pointer;
}
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }

.video-area {
  flex: 1;
  position: relative;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  overflow: auto;
  background: radial-gradient(ellipse at top, #16223a 0%, var(--bg) 60%);
}
.video-tile {
  position: relative;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
  aspect-ratio: 16/9;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  border: 1px solid var(--border);
}
.video-tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile-label {
  position: absolute; bottom: 10px; left: 10px;
  background: rgba(0,0,0,.55); padding: 4px 10px; border-radius: 12px;
  font-size: 12px;
}
.video-tile.self .tile-label { background: rgba(0,175,240,.7); }

.abr-badge {
  position: absolute; top: 10px; right: 10px;
  background: rgba(0,0,0,.6); color: #fff;
  padding: 4px 10px; border-radius: 10px;
  font-size: 11px; font-family: ui-monospace, monospace;
  display: flex; align-items: center; gap: 6px;
  backdrop-filter: blur(6px);
}
.abr-tier {
  font-weight: 700; padding: 1px 6px; border-radius: 6px;
}
.abr-low  { background: #e74c3c; }
.abr-med  { background: #f39c12; }
.abr-high { background: #2ecc71; }
.abr-hd   { background: #00aff0; }

.remotes { display: contents; }

.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--muted);
  pointer-events: none;
}
.placeholder.hidden { display: none; }
.big-call-icon {
  font-size: 64px;
  width: 120px; height: 120px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 12px 40px rgba(0,175,240,.4);
}
.placeholder h2 { color: var(--text); margin: 0 0 8px; }
.placeholder p { max-width: 360px; }

/* Controls */
.controls {
  display: flex; justify-content: center; gap: 14px;
  padding: 18px; background: var(--bg-2);
  border-top: 1px solid var(--border);
}
.ctrl {
  width: 52px; height: 52px; border-radius: 50%;
  border: none; cursor: pointer;
  background: var(--panel-2); color: var(--text);
  font-size: 20px;
  display: flex; align-items: center; justify-content: center;
  transition: transform .1s, background .2s;
}
.ctrl:hover:not(:disabled) { transform: translateY(-2px); }
.ctrl.off { background: #4a2030; color: var(--danger); }
.ctrl.call { background: linear-gradient(135deg, var(--green), #27ae60); width: 62px; height: 62px; font-size: 24px; }
.ctrl.hangup { background: linear-gradient(135deg, #e74c3c, #c0392b); }
.ctrl:disabled { opacity: .45; cursor: not-allowed; }

/* Chat */
.chat {
  background: var(--bg-2);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.chat-head {
  padding: 18px 20px; font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.chat-msgs {
  flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.msg {
  max-width: 80%; padding: 8px 12px; border-radius: 14px;
  background: var(--panel); font-size: 14px; word-wrap: break-word;
}
.msg.mine { align-self: flex-end; background: var(--accent-2); }
.msg .from { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg.mine .from { color: rgba(255,255,255,.7); }

.chat-input {
  display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border);
}
.chat-input input {
  flex: 1; padding: 10px 14px; border-radius: 20px;
  background: var(--panel); border: 1px solid var(--border); color: var(--text); outline: none;
}
.chat-input input:focus { border-color: var(--accent); }
.chat-input button {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--accent); color: white; border: none; cursor: pointer;
  font-size: 16px;
}

@media (max-width: 1024px) {
  .app { grid-template-columns: 240px 1fr; }
  .chat { display: none; }
}
@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
