@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --pink: #e879c8;
  --cyan: #22d4f5;
  --pink-dim: rgba(232, 121, 200, 0.15);
  --cyan-dim: rgba(34, 212, 245, 0.15);
  --glass: rgba(255, 255, 255, 0.04);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-hover: rgba(255, 255, 255, 0.07);
  --text: #f0f0f5;
  --text-muted: rgba(240, 240, 245, 0.45);
  --bg-base: #0a0a12;
  --surface: rgba(255, 255, 255, 0.035);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Outfit', sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  overflow: hidden;
}

body {
  background: var(--bg-base);
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 15% 20%, rgba(232, 121, 200, 0.12) 0%, transparent 70%),
    radial-gradient(ellipse 50% 60% at 85% 80%, rgba(34, 212, 245, 0.10) 0%, transparent 70%),
    radial-gradient(ellipse 40% 40% at 50% 50%, rgba(130, 80, 180, 0.06) 0%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.view {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1;
}

.view.active {
  display: flex;
}

#view-auth {
  align-items: center;
  justify-content: center;
}

.auth-card {
  background: rgba(255, 255, 255, 0.04);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 40px;
  width: 420px;
  max-width: calc(100vw - 32px);
  position: relative;
  box-shadow: 0 32px 80px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.04) inset;
}

.auth-card::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 25px;
  background: linear-gradient(135deg, rgba(232, 121, 200, 0.3), transparent 40%, rgba(34, 212, 245, 0.2));
  z-index: -1;
  pointer-events: none;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo .logo-mark {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  background: linear-gradient(135deg, var(--pink), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-logo .logo-sub {
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 4px;
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 28px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-muted);
  background: none;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.2s;
}

.auth-tab.active {
  background: var(--glass);
  color: var(--text);
  box-shadow: 0 1px 6px rgba(0,0,0,0.3);
}

.auth-panel {
  display: none;
}

.auth-panel.active {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.field input {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus {
  border-color: rgba(232, 121, 200, 0.5);
}

.btn-primary {
  background: linear-gradient(135deg, var(--pink), #9b40e0);
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  margin-top: 4px;
  transition: opacity 0.2s, transform 0.1s;
}

.btn-primary:hover {
  opacity: 0.9;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.error-msg {
  font-size: 13px;
  color: #ff6b8a;
  text-align: center;
  min-height: 18px;
  opacity: 0;
  transition: opacity 0.2s;
}

.error-msg.visible {
  opacity: 1;
}

#view-app {
  flex-direction: row;
}

.sidebar {
  width: 300px;
  min-width: 300px;
  height: 100%;
  background: rgba(255,255,255,0.025);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  z-index: 2;
}

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

.sidebar-logo {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--pink), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  transition: color 0.2s, background 0.2s;
  font-size: 14px;
}

.logout-btn:hover {
  color: var(--text);
  background: var(--glass-hover);
}

.search-area {
  padding: 14px 16px;
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  gap: 8px;
  position: relative;
}

.search-input {
  flex: 1;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 9px 12px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: rgba(34, 212, 245, 0.4);
}

.search-icon-btn {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.search-icon-btn:hover {
  color: var(--cyan);
  border-color: rgba(34, 212, 245, 0.3);
}

.search-results {
  position: absolute;
  top: calc(100% - 4px);
  left: 16px;
  right: 16px;
  background: rgba(20, 20, 32, 0.95);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  z-index: 10;
  overflow: hidden;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
  color: var(--text-muted);
}

.search-result-item:hover {
  background: var(--glass-hover);
  color: var(--text);
}

.search-empty {
  padding: 14px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.conversations-list::-webkit-scrollbar {
  width: 4px;
}

.conversations-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background 0.15s;
  border-radius: 0;
}

.conv-item:hover {
  background: var(--glass-hover);
}

.conv-item.active {
  background: var(--pink-dim);
}

.conv-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink-dim), var(--cyan-dim));
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.conv-info {
  min-width: 0;
}

.conv-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
}

.chat-placeholder .placeholder-icon {
  font-size: 48px;
  background: linear-gradient(135deg, var(--pink), var(--cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  opacity: 0.4;
}

.chat-placeholder p {
  font-size: 14px;
}

.chat-area {
  display: none;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.02);
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header .chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink-dim), var(--cyan-dim));
  border: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-header .chat-meta {
  flex: 1;
  min-width: 0;
}

.chat-header .chat-name {
  font-size: 15px;
  font-weight: 600;
}

.chat-header .chat-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

.presence-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s;
}

.presence-dot.online {
  background: #4cde80;
  box-shadow: 0 0 6px #4cde80;
}

.e2e-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: var(--cyan);
  background: rgba(34, 212, 245, 0.08);
  border: 1px solid rgba(34, 212, 245, 0.2);
  border-radius: 20px;
  padding: 4px 10px;
  letter-spacing: 0.3px;
}

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

.messages::-webkit-scrollbar {
  width: 4px;
}

.messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.08);
  border-radius: 2px;
}

.message {
  display: flex;
  max-width: 68%;
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.mine {
  align-self: flex-end;
}

.message.theirs {
  align-self: flex-start;
}

.bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

.message.mine .bubble {
  background: linear-gradient(135deg, rgba(232, 121, 200, 0.2), rgba(154, 64, 224, 0.2));
  border: 1px solid rgba(232, 121, 200, 0.25);
  border-bottom-right-radius: 4px;
}

.message.theirs .bubble {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-bottom-left-radius: 4px;
}

.msg-time {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--mono);
}

.disappear-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  color: var(--pink);
  margin-left: 6px;
}

.decrypt-fail {
  color: var(--text-muted);
  font-size: 13px;
}

.typing-indicator {
  padding: 6px 24px;
  font-size: 12px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.2s;
  min-height: 24px;
}

.typing-indicator.visible {
  opacity: 1;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.typing-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingDot 1.2s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.input-area {
  padding: 16px 24px;
  border-top: 1px solid var(--glass-border);
  background: rgba(255,255,255,0.02);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.input-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  padding-bottom: 2px;
}

.icon-btn {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 14px;
}

.icon-btn:hover {
  color: var(--pink);
  border-color: rgba(232, 121, 200, 0.3);
  background: var(--pink-dim);
}

.disappear-select {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 8px;
  padding: 0 10px;
  height: 36px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  outline: none;
}

.disappear-select:focus {
  border-color: rgba(232, 121, 200, 0.4);
}

.message-input {
  flex: 1;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 10px 14px;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.5;
  transition: border-color 0.2s;
}

.message-input::placeholder {
  color: var(--text-muted);
}

.message-input:focus {
  border-color: rgba(232, 121, 200, 0.4);
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--pink), #9b40e0);
  border: none;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  transition: opacity 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.send-btn:hover {
  opacity: 0.9;
}

.send-btn:active {
  transform: scale(0.93);
}

/* ── Conversation item menu button ── */
.conv-item {
  position: relative;
}

.conv-menu-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  margin-left: auto;
  flex-shrink: 0;
}

.conv-item:hover .conv-menu-btn {
  opacity: 1;
}

.conv-menu-btn:hover {
  background: var(--glass-hover);
  color: var(--text);
}

/* ── Blocked conversation state ── */
.conv-item.blocked {
  opacity: 0.55;
}

.conv-item.blocked .conv-avatar {
  filter: grayscale(1);
}

.blocked-tag {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: #ff6b8a;
  background: rgba(255, 107, 138, 0.12);
  border: 1px solid rgba(255, 107, 138, 0.25);
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ── Context menu ── */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  background: rgba(18, 18, 28, 0.97);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 4px;
  min-width: 180px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.04) inset;
  animation: ctxIn 0.12s ease;
}

@keyframes ctxIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  border-radius: 7px;
  font-family: var(--font);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}

.ctx-item i {
  width: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}

.ctx-item:hover {
  background: var(--glass-hover);
}

.ctx-item.danger {
  color: #ff6b8a;
}

.ctx-item.danger i {
  color: #ff6b8a;
}

.ctx-item.danger:hover {
  background: rgba(255, 107, 138, 0.1);
}

/* ── Toast notifications ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: rgba(18, 18, 28, 0.97);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 13.5px;
  color: var(--text);
  z-index: 2000;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-info {
  border-color: rgba(34, 212, 245, 0.3);
}

/* ── Message hover hint ── */
.message .bubble {
  cursor: default;
}

.message:hover .bubble {
  filter: brightness(1.06);
}