:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d8bfd;
  --accent-hover: #5c9dff;
  --success: #3dd68c;
  --offline: #6b7a90;
  --danger: #f07178;
  --mine: #2563eb;
  --theirs: #2a3548;
  --radius: 12px;
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
  --header-h: 52px;
  --sidebar-w: 360px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

.small {
  font-size: 0.75rem;
}

/* ─── Auth ─── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(61, 139, 253, 0.25), transparent),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 28px;
}

.auth-brand {
  text-align: center;
  margin-bottom: 24px;
}

.auth-brand .logo {
  font-size: 44px;
  margin-bottom: 8px;
}

.auth-brand h1 {
  font-size: 1.35rem;
  font-weight: 700;
}

.auth-brand p {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 4px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  background: var(--bg);
  padding: 4px;
  border-radius: 10px;
}

.auth-tabs .tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.auth-tabs .tab.active {
  background: var(--surface2);
  color: var(--text);
}

.auth-tabs .tab:hover:not(.active) {
  color: var(--text);
}

.auth-form label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  margin: 12px 0 6px;
}

.auth-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 12px;
  text-align: center;
}

/* ─── Buttons ─── */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 10px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.btn:hover {
  opacity: 0.9;
}

.btn.block {
  width: 100%;
  margin-top: 20px;
  padding: 14px;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
}

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

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn.sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
}

.btn.icon:hover {
  background: var(--border);
}

.btn.back {
  flex-shrink: 0;
}

.btn.send {
  flex-shrink: 0;
  padding: 12px 16px;
  border-radius: 10px;
}

.muted {
  color: var(--muted);
}

/* ─── App Shell — Desktop Split Layout ─── */
.app-shell {
  position: relative;
  height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand .logo {
  font-size: 1.4rem;
}

.sidebar-brand h1 {
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
}

.sidebar-actions {
  display: flex;
  gap: 6px;
}

/* Sidebar tab navigation */
.sidebar-tabs {
  flex-shrink: 0;
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  background: var(--surface);
}

.sidebar-tabs .nav-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 10px 4px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
  white-space: nowrap;
}

.sidebar-tabs .nav-item.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.sidebar-tabs .nav-item:hover:not(.active) {
  color: var(--text);
}

/* Sidebar body — holds the active view-tab */
.sidebar-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view-tab {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}

.view-tab.active {
  display: flex;
}

/* ─── WS / presence dots ─── */
.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--offline);
}

.ws-dot.online {
  background: var(--success);
  box-shadow: 0 0 0 2px rgba(61, 214, 140, 0.35);
}

.ws-dot.offline {
  background: var(--offline);
}

.presence-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  background: var(--offline);
}

.presence-dot.online {
  background: var(--success);
  box-shadow: 0 0 6px rgba(61, 214, 140, 0.5);
}

.presence-dot.offline {
  background: var(--offline);
}

.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
}

.search-box {
  padding: 10px 12px;
  flex-shrink: 0;
}

.search-box input {
  width: 100%;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ─── Lists ─── */
.list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.list li:hover {
  background: var(--surface2);
}

.list li.active {
  background: var(--surface2);
}

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

.list-title {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-sub {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-label {
  font-size: 0.7rem;
  margin-top: 2px;
}

.status-label.online {
  color: var(--success);
}

.status-label.offline {
  color: var(--muted);
}

.unread-dot {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

/* Notify toolbar */
.notify-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 6px 12px;
  flex-shrink: 0;
}

.notify-list li {
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.notify-list li.unread {
  border-left: 3px solid var(--accent);
}

/* ─── Chat view (right column) ─── */
.view-stack {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  z-index: 5;
}

.view-stack.hidden {
  display: none !important;
}

.view-stack:not(.hidden) {
  display: flex !important;
}

.view-header {
  flex-shrink: 0;
  min-height: var(--header-h);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-main h1,
.header-main h2 {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-main.compact h2 {
  font-size: 1rem;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* ─── Chat messages ─── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.messages .placeholder {
  color: var(--muted);
  text-align: center;
  margin: auto;
  padding: 24px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 65%;
}

.msg-row.mine {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row.theirs {
  align-self: flex-start;
}

.msg-meta {
  font-size: 0.65rem;
  color: var(--muted);
  margin-bottom: 4px;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.45;
  word-break: break-word;
}

.msg-row.mine .msg-bubble {
  background: var(--mine);
  border-bottom-right-radius: 4px;
}

.msg-row.theirs .msg-bubble {
  background: var(--theirs);
  border-bottom-left-radius: 4px;
}

.msg-row.recalled .msg-bubble {
  font-style: italic;
  opacity: 0.65;
}

.msg-actions button {
  font-size: 0.75rem;
  background: none;
  border: none;
  color: var(--accent);
  margin-top: 4px;
  font-family: inherit;
  cursor: pointer;
}

.msg-actions button:hover {
  text-decoration: underline;
}

/* ─── Composer ─── */
.composer {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 120px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.typing-hint {
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0 16px 6px;
  font-style: italic;
}

/* ─── Empty chat placeholder ─── */
.empty-chat {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.app-shell:has(#view-chat:not(.hidden)) .empty-chat {
  display: none;
}

.empty-chat-inner {
  text-align: center;
  color: var(--muted);
}

.empty-chat-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-chat-inner p {
  font-size: 0.95rem;
}

/* ─── Nav badge (inline for sidebar tabs) ─── */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 0.6rem;
  min-width: 16px;
  height: 16px;
  border-radius: 999px;
  padding: 0 4px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ─── Call overlay ─── */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 12, 18, 0.92);
  padding: 24px;
}

.call-card {
  width: min(380px, 100%);
  text-align: center;
  padding: 36px 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.call-label {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.call-card h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.call-status {
  color: var(--muted);
  margin-bottom: 4px;
}

.call-timer {
  font-variant-numeric: tabular-nums;
  color: var(--success);
  min-height: 1.25rem;
  margin-bottom: 24px;
}

.call-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.call-actions .block {
  width: 100%;
}

.btn.call-accept {
  background: var(--success);
  color: #0a1612;
  flex: 1;
}

.btn.call-reject {
  background: var(--danger);
  color: #fff;
  flex: 1;
}

#meeting-overlay .call-timer {
  margin-bottom: 0;
}

.meeting-actions {
  display: flex;
  gap: 12px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.meeting-actions.meeting-actions--member {
  justify-content: center;
}

.meeting-actions.meeting-actions--member .meeting-btn-leave {
  flex: none;
  width: 100%;
  max-width: 280px;
}

.meeting-actions .meeting-btn-leave,
.meeting-actions .meeting-btn-end {
  flex: 1;
  min-height: 48px;
  padding: 12px 16px;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.meeting-actions .meeting-btn-leave {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.meeting-actions .meeting-btn-leave:hover {
  background: rgba(255, 255, 255, 0.1);
}

.meeting-actions .meeting-btn-end {
  background: linear-gradient(180deg, #f5858c 0%, #e85d66 100%);
  color: #fff;
  box-shadow: 0 4px 16px rgba(240, 113, 120, 0.35);
}

.meeting-actions .meeting-btn-end:hover {
  filter: brightness(1.05);
}

.meeting-actions .meeting-btn-leave:active,
.meeting-actions .meeting-btn-end:active {
  transform: scale(0.98);
}

.meeting-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(61, 214, 140, 0.12);
  border-bottom: 1px solid rgba(61, 214, 140, 0.25);
}

.meeting-banner-text {
  font-size: 0.875rem;
  color: var(--success);
}

.msg-system-row {
  display: flex;
  justify-content: center;
  margin: 12px 0 16px;
}

.msg-system {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 0.8125rem;
  color: var(--muted);
  max-width: 90%;
}

.msg-system-icon {
  font-size: 0.9rem;
  line-height: 1;
}

/* ─── Scrollbar ─── */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}
