/* ═══════════════════════════════════════════════
   ChatServer — style.css
   Dark theme, Slack/Discord-inspired layout
═══════════════════════════════════════════════ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-deep:      #0d0f14;
  --bg-sidebar:   #14161e;
  --bg-main:      #1a1d27;
  --bg-input:     #22263a;
  --bg-hover:     #1e2130;
  --bg-active:    #252a3d;
  --bg-message:   #1e2234;
  --bg-card:      #1c1f2e;

  --accent:       #4f8ef7;
  --accent-hover: #6aa3ff;
  --accent-dim:   rgba(79,142,247,.15);

  --text-primary:   #e8eaf0;
  --text-secondary: #8b8fa8;
  --text-muted:     #585c72;
  --text-link:      #4f8ef7;

  --green:  #3ecf6e;
  --red:    #e05260;
  --yellow: #f5c842;

  --border: rgba(255,255,255,.06);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-w: 240px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;

  --shadow: 0 4px 24px rgba(0,0,0,.45);
  --shadow-sm: 0 2px 8px rgba(0,0,0,.3);
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; }
input  { font-family: inherit; }
ul     { list-style: none; }
a      { color: var(--text-link); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }

/* ── Utility ── */
.hidden { display: none !important; }

/* ═══════════════════════
   LOGIN SCREEN
═══════════════════════ */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(79,142,247,.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(79,142,247,.06) 0%, transparent 50%),
    var(--bg-deep);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 48px 44px 40px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 18px;
}

.login-card h1 {
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -.5px;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.login-sub {
  color: var(--text-secondary);
  font-size: .875rem;
  margin-bottom: 28px;
}

/* Vertical login fields */
.login-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-fields input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: .95rem;
  outline: none;
  transition: border-color .15s;
}

.login-fields input:focus { border-color: var(--accent); }

.join-btn-full {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  font-weight: 600;
  transition: background .15s, transform .1s;
  margin-top: 2px;
}

.join-btn-full:hover  { background: var(--accent-hover); }
.join-btn-full:active { transform: scale(.98); }
.join-btn-full:disabled {
  background: var(--bg-active);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

/* Login status message */
.login-status {
  min-height: 1.4em;
  margin-top: 10px;
  font-size: .82rem;
  text-align: center;
}
.login-status.error   { color: var(--red); }
.login-status.success { color: var(--green); }
.login-status.info    { color: var(--text-secondary); }

.login-hint {
  margin-top: 14px;
  color: var(--text-muted);
  font-size: .78rem;
}

/* ═══════════════════════
   CHAT SCREEN — SHELL
═══════════════════════ */
#chat-screen {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ═══════════════════════
   SIDEBAR
═══════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform .2s ease;
  z-index: 100;
}

.sidebar-top {
  padding: 16px 14px 12px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
}

.brand-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -.3px;
  color: var(--text-primary);
}

.sidebar-me {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-hover);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
}

.me-name {
  flex: 1;
  font-size: .85rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Presence dot */
.presence-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.presence-dot.online  { background: var(--green); box-shadow: 0 0 0 2px var(--bg-sidebar); }
.presence-dot.offline { background: var(--text-muted); }

/* Nav section */
.sidebar-nav {
  padding: 10px 0;
  flex: 1;
  overflow-y: auto;
}

.nav-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px 4px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .07em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.nav-section-header .icon-btn {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 1px 4px;
  border-radius: 4px;
  transition: color .15s, background .15s;
}

.nav-section-header .icon-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* Room items */
.room-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 6px;
  margin: 1px 6px;
  font-size: .875rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .12s, color .12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-item:hover              { background: var(--bg-hover); color: var(--text-primary); }
.room-item.active             { background: var(--bg-active); color: var(--text-primary); font-weight: 600; }
.room-item .hash              { color: var(--text-muted); font-size: .9em; flex-shrink: 0; }
.room-item.active .hash       { color: var(--accent); }
.room-item .unread-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 6px;
}

/* Online users */
.sidebar-online {
  border-top: 1px solid var(--border);
  padding: 8px 0 10px;
  max-height: 180px;
  overflow-y: auto;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 14px;
  font-size: .84rem;
  color: var(--text-secondary);
}

/* ═══════════════════════
   CHAT AREA
═══════════════════════ */
.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-main);
  overflow: hidden;
}

.chat-header {
  padding: 0 18px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-main);
  flex-shrink: 0;
  font-size: .95rem;
}

.hash-icon {
  font-size: 1.15rem;
  color: var(--text-muted);
  line-height: 1;
}

#room-title {
  font-weight: 700;
  color: var(--text-primary);
}

.header-sep { color: var(--text-muted); font-size: .85rem; }

.room-desc {
  font-size: .82rem;
  color: var(--text-secondary);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-btn {
  display: none;
  font-size: 1.2rem;
  color: var(--text-secondary);
  padding: 4px 6px;
  border-radius: 4px;
}
.menu-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 0 8px;
  display: flex;
  flex-direction: column;
}

.messages-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: .9rem;
  font-style: italic;
}

/* Message row */
.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 3px 18px;
  transition: background .1s;
}

.msg-row:hover { background: var(--bg-message); }

.msg-row.grouped { padding-top: 1px; padding-bottom: 1px; }
.msg-row.grouped .msg-avatar { visibility: hidden; }

/* Avatar */
.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .9rem;
  flex-shrink: 0;
  margin-top: 2px;
  color: #fff;
  text-transform: uppercase;
}

.msg-body { flex: 1; min-width: 0; }

.msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 2px;
}

.msg-author {
  font-size: .875rem;
  font-weight: 700;
  color: var(--text-primary);
}

.msg-author.is-me { color: var(--accent); }

.msg-time {
  font-size: .72rem;
  color: var(--text-muted);
}

.msg-text {
  font-size: .9rem;
  color: var(--text-primary);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.55;
}

/* System messages */
.msg-row.system {
  padding: 4px 18px;
  justify-content: center;
}

.msg-row.system .system-text {
  font-size: .75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Day divider */
.day-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  color: var(--text-muted);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .04em;
}

.day-divider::before,
.day-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Connection banner */
.connection-banner {
  text-align: center;
  padding: 6px;
  font-size: .78rem;
  background: rgba(245,200,66,.1);
  color: var(--yellow);
  border-top: 1px solid rgba(245,200,66,.2);
}

/* ── Input Row ── */
.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-main);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-row input {
  flex: 1;
  padding: 11px 16px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}

.input-row input:focus { border-color: var(--accent); }
.input-row input::placeholder { color: var(--text-muted); }

#send-btn {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

#send-btn:hover  { background: var(--accent-hover); }
#send-btn:active { transform: scale(.94); }
#send-btn:disabled { background: var(--bg-hover); cursor: not-allowed; }

/* Icon button (generic) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  border-radius: 4px;
  font-size: .9rem;
  padding: 3px 5px;
  transition: color .12s, background .12s;
}

.icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ═══════════════════════
   MODAL
═══════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 30px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}

.modal-card h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.modal-card p {
  font-size: .82rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-card input {
  width: 100%;
  padding: 10px 13px;
  background: var(--bg-input);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: .9rem;
  outline: none;
  margin-bottom: 20px;
}

.modal-card input:focus { border-color: var(--accent); }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary {
  padding: 9px 22px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 600;
  transition: background .15s;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  padding: 9px 18px;
  background: var(--bg-hover);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-weight: 500;
  transition: background .15s;
}

.btn-secondary:hover { background: var(--bg-active); color: var(--text-primary); }

/* ═══════════════════════
   RESPONSIVE
═══════════════════════ */
@media (max-width: 640px) {
  :root { --sidebar-w: 220px; }

  .menu-btn { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
  }

  .login-card {
    margin: 16px;
    padding: 36px 24px 30px;
  }

  .chat-header { padding: 0 12px; }
  .messages { padding: 10px 0 6px; }
  .msg-row   { padding: 3px 12px; }
  .input-row { padding: 10px 12px; }
}

/* ─── Avatar colour palette (generated by username hash) ─── */
.av-0 { background: #e05260; }
.av-1 { background: #4f8ef7; }
.av-2 { background: #3ecf6e; }
.av-3 { background: #f5a623; }
.av-4 { background: #9b59b6; }
.av-5 { background: #1abc9c; }
.av-6 { background: #e67e22; }
.av-7 { background: #2980b9; }

/* ═══════════════════════════════════════════════
   VIDEO CALL OVERLAY
═══════════════════════════════════════════════ */

/* Call button in header */
.call-header-btn {
  margin-left: auto;
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.call-header-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.call-header-btn.in-call {
  background: rgba(62,207,110,.15);
  color: var(--green);
}

.call-indicator {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  background: var(--green);
  border-radius: 50%;
  border: 1.5px solid var(--bg-main);
}

/* Full-screen call overlay */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #0b0d14;
  display: flex;
  flex-direction: column;
}

/* Top bar */
.call-topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,.3);
  backdrop-filter: blur(6px);
  flex-shrink: 0;
}

.call-topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.call-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--red);
  animation: livePulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes livePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.75); }
}

.call-topbar-title {
  font-size: .9rem;
  color: var(--text-secondary);
}
.call-topbar-title strong { color: var(--text-primary); }

.call-count-badge {
  background: var(--bg-active);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
}

.call-topbar-right { display: flex; gap: 6px; }

/* Video grid */
.video-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 8px;
  padding: 12px;
  overflow: hidden;
  align-content: center;
}

/* 1 participant → full width */
.video-grid:has(.video-tile:only-child) {
  grid-template-columns: 1fr;
}

/* Video tile */
.video-tile {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #16181f;
  aspect-ratio: 16/9;
  border: 2px solid transparent;
  transition: border-color .2s;
}

.video-tile.speaking {
  border-color: var(--green);
}

.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Avatar fallback (camera off) */
.video-tile .video-avatar {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-tile .video-avatar .av-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

/* Tile label */
.tile-label {
  position: absolute;
  bottom: 10px;
  left: 10px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: .78rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 5px;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  gap: 5px;
}

.tile-muted-icon {
  opacity: .7;
  font-size: .7rem;
}

/* Controls bar */
.call-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(0,0,0,.4);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ctrl-btn {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  background: rgba(255,255,255,.1);
  transition: background .15s, transform .1s, color .15s;
  border: 1.5px solid rgba(255,255,255,.08);
}

.ctrl-btn:hover  { background: rgba(255,255,255,.18); transform: scale(1.05); }
.ctrl-btn:active { transform: scale(.95); }

.ctrl-btn.toggled-off {
  background: rgba(224,82,96,.2);
  border-color: rgba(224,82,96,.3);
  color: var(--red);
}

.end-call-btn {
  background: var(--red);
  border-color: transparent;
  width: 56px;
  height: 56px;
}
.end-call-btn:hover { background: #c94050; }

/* Pip button (smaller) */
#pip-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-hover);
  color: var(--text-secondary);
}
#pip-btn:hover { color: var(--text-primary); }

/* "Camera off" solid overlay on tile */
.cam-off-overlay {
  position: absolute;
  inset: 0;
  background: #16181f;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Connecting state tile */
.tile-connecting {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-direction: column;
  color: var(--text-muted);
  font-size: .8rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Screen share active indicator */
.ctrl-btn.sharing {
  background: rgba(79,142,247,.2);
  border-color: rgba(79,142,247,.4);
  color: var(--accent);
}

/* Responsive */
@media (max-width: 640px) {
  .video-grid {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 6px;
  }

  .ctrl-btn { width: 44px; height: 44px; }
  .end-call-btn { width: 50px; height: 50px; }
  .call-controls { gap: 8px; padding: 12px 16px; }
}
