:root {
  --bg-base: #0b0d12;
  --bg-sidebar: #12151f;
  --bg-panel: #0f1219;
  --bg-elevated: #1a1e2b;
  --bg-hover: #222738;
  --bg-input: #181c28;
  --border: rgba(255, 255, 255, 0.06);
  --border-focus: rgba(99, 102, 241, 0.5);
  --text: #eef0f6;
  --text-secondary: #8b92a8;
  --text-muted: #5c6378;
  --accent: #6366f1;
  --accent-hover: #5558e3;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  --green: #22c55e;
  --red: #ef4444;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --sidebar-w: 320px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-base);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.screen { height: 100vh; }

::-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,.18); }

.btn {
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--accent-gradient);
  color: #fff;
  padding: 12px 24px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(99, 102, 241, .35);
}
.btn-primary:hover { box-shadow: 0 6px 24px rgba(99, 102, 241, .45); }
.btn-block { width: 100%; }

.btn-chip {
  background: var(--bg-elevated);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.btn-chip:hover { background: var(--bg-hover); border-color: rgba(99,102,241,.3); }

.btn-icon-only {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.btn-icon-only:hover { color: var(--accent); background: rgba(99,102,241,.1); }

.btn-action {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-action:hover { color: var(--accent); background: rgba(99,102,241,.12); }

.btn-composer {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.btn-composer:hover { color: var(--accent); background: rgba(99,102,241,.1); }

.btn-send {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--accent-gradient);
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 12px rgba(99,102,241,.4);
}
.btn-send:hover { box-shadow: 0 4px 16px rgba(99,102,241,.55); }

.btn-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 22px;
  line-height: 1;
}
.btn-close:hover { background: var(--bg-hover); color: var(--text); }

.btn-call {
  width: 60px; height: 60px;
  border-radius: 50%;
  color: #fff;
}
.btn-reject { background: var(--red); box-shadow: 0 4px 20px rgba(239,68,68,.4); }
.btn-accept { background: var(--green); box-shadow: 0 4px 20px rgba(34,197,94,.4); }
.btn-reject:hover, .btn-accept:hover { filter: brightness(1.08); }

#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.login-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(99,102,241,.18) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(139,92,246,.12) 0%, transparent 60%),
    var(--bg-base);
}

.login-card {
  position: relative;
  width: 400px;
  padding: 48px 40px;
  background: rgba(26, 30, 43, .85);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-logo { margin-bottom: 20px; }
.login-card h1 { font-size: 26px; font-weight: 700; margin-bottom: 6px; letter-spacing: -.02em; }
.subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }

.login-form input[type="text"] {
  width: 100%;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color .2s;
}
.login-form input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(99,102,241,.15); }

.demo-users { margin-top: 24px; }
.demo-label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .05em; }
.demo-btns { display: flex; gap: 8px; justify-content: center; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 20px; line-height: 1.6; }

#main-screen { display: flex; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.me-info { display: flex; gap: 12px; align-items: center; min-width: 0; }
.me-text { min-width: 0; }
.me-text .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.role-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 2px;
}
.role-badge.consultant { color: #6366f1; background: rgba(99,102,241,.12); }
.role-badge.client { color: #0d9488; background: rgba(13,148,136,.12); }

.user-item-body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 16px;
  flex-shrink: 0;
  color: #fff;
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.avatar-lg { width: 46px; height: 46px; font-size: 18px; }

.name { font-weight: 600; font-size: 15px; line-height: 1.3; }
.status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
}
.status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status.online { color: var(--green); }
.status.online .dot { background: var(--green); box-shadow: 0 0 6px rgba(34,197,94,.6); }

.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }

.sidebar-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.btn-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-logout:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.conv-item {
  padding: 12px 14px;
  cursor: pointer;
  border-radius: var(--radius);
  display: flex;
  gap: 12px;
  align-items: center;
  transition: background .15s;
  margin-bottom: 2px;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active {
  background: rgba(99, 102, 241, .12);
  border: 1px solid rgba(99, 102, 241, .2);
}
.conv-item .conv-body { flex: 1; min-width: 0; }
.conv-item .preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 3px;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  position: relative;
}

.chat-area::before {
  content: '';
  position: absolute; inset: 0;
  background: radial-gradient(ellipse 50% 40% at 70% 20%, rgba(99,102,241,.04) 0%, transparent 70%);
  pointer-events: none;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}
.empty-icon {
  width: 100px; height: 100px;
  border-radius: 50%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.empty-state h2 { font-size: 20px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

.chat-panel { flex: 1; display: flex; flex-direction: column; position: relative; z-index: 1; }

.chat-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(18, 21, 31, .8);
  backdrop-filter: blur(12px);
}
.peer-info { display: flex; gap: 12px; align-items: center; }
.chat-actions { display: flex; gap: 6px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: min(420px, 75%);
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  animation: msgIn .25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.mine {
  align-self: flex-end;
  background: var(--accent-gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 12px rgba(99, 102, 241, .25);
}
.msg.theirs {
  align-self: flex-start;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg .meta {
  font-size: 11px;
  margin-top: 6px;
  opacity: .55;
}
.msg.mine .meta { text-align: right; }
.msg img {
  max-width: 260px;
  border-radius: 10px;
  margin-top: 4px;
  cursor: pointer;
  display: block;
}
.msg.system {
  align-self: center;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 14px;
  border-radius: 20px;
  max-width: 100%;
}

.composer {
  padding: 16px 24px 20px;
  background: rgba(18, 21, 31, .9);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}

.composer-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px 8px 6px 6px;
  transition: border-color .2s, box-shadow .2s;
}
.composer-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.composer-box input[type="text"] {
  flex: 1;
  min-width: 0;
  width: auto;
  padding: 10px 8px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  margin-bottom: 0;
}
.composer-box input::placeholder { color: var(--text-muted); }

.modal {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .55);
  backdrop-filter: blur(4px);
}
.modal-backdrop.dark { background: rgba(0, 0, 0, .75); }

.modal-content {
  position: relative;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-width: 340px;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  animation: modalIn .25s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-header h3 { font-size: 17px; font-weight: 600; }

.user-list { display: flex; flex-direction: column; gap: 4px; }
.user-item {
  padding: 12px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  gap: 12px;
  align-items: center;
  transition: background .15s;
}
.user-item:hover { background: var(--bg-hover); }

.call-modal { text-align: center; padding: 36px 32px; }
.call-avatar {
  width: 88px; height: 88px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 8px 32px rgba(99,102,241,.35);
}
.call-avatar.pulse { animation: pulse 2s ease infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,.4); }
  50% { box-shadow: 0 0 0 16px rgba(99,102,241,0); }
}
.call-modal h3 { font-size: 20px; font-weight: 600; }
.call-sub { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }
.call-buttons { display: flex; gap: 40px; justify-content: center; margin-top: 32px; }
#call-timer { font-size: 28px; font-weight: 600; margin: 12px 0 20px; color: var(--accent); letter-spacing: .05em; }

#remote-audio {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
#remote-video {
  width: 100%; max-height: 280px;
  border-radius: var(--radius);
  background: #000;
  margin: 12px 0;
  display: none;
}
#local-video {
  width: 120px; height: 90px;
  border-radius: 10px;
  position: absolute;
  bottom: 100px; right: 32px;
  background: #000;
  border: 2px solid var(--border);
  display: none;
}
.call-modal.active { position: relative; }

#call-status-hint { min-height: 20px; margin-top: 2px; }
#enable-speaker-btn, #retry-play-btn {
  margin: 8px auto 12px;
  display: none;
}
#enable-speaker-btn:not(.hidden), #retry-play-btn:not(.hidden) { display: block; }

.call-controls {
  display: flex;
  gap: 48px;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
}
.btn-mute {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.btn-mute.muted { background: rgba(239, 68, 68, .15); border-color: #ef4444; color: #ef4444; }
.btn-secondary {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
}

@media (max-width: 768px) {
  .sidebar { width: 100%; max-width: 100%; }
  .messages { padding: 16px; }
  .composer { padding: 12px 16px 16px; }
  #active-call-modal .modal-content,
  #incoming-call-modal .modal-content {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-bottom: max(36px, env(safe-area-inset-bottom));
  }
  .call-buttons { gap: 56px; }
  .call-controls { gap: 64px; margin-bottom: env(safe-area-inset-bottom); }
}

.call-history-list { display: flex; flex-direction: column; gap: 8px; }
.call-record {
  padding: 12px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}
.call-record audio { height: 32px; }
