/* ============================================================
   SecureChat Web - 样式表
   深色主题，移动端优先响应式设计
   ============================================================ */

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-hover: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #238636;
  --accent-hover: #2ea043;
  --accent-blue: #58a6ff;
  --danger: #da3633;
  --border: #30363d;
  --shadow: rgba(0, 0, 0, 0.4);
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ── 通用组件 ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
}

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

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-icon {
  padding: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-primary);
  transition: all var(--transition);
}
.btn-icon:hover { background: var(--bg-hover); }

input[type="text"],
input[type="password"],
input[type="search"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color var(--transition);
}

input:focus {
  border-color: var(--accent-blue);
}

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

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Auth View ────────────────────────────────────────────── */

#auth-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
}

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

.auth-logo .emoji {
  font-size: 48px;
  display: block;
  margin-bottom: 8px;
}

.auth-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.auth-logo p {
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-tabs {
  display: flex;
  margin-bottom: 24px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 4px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  text-align: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--transition);
}

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

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-form .btn {
  width: 100%;
  margin-top: 8px;
  padding: 12px;
  font-size: 15px;
}

.auth-form .form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-form label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  text-align: center;
  padding: 8px;
  background: rgba(218, 54, 51, 0.1);
  border-radius: var(--radius);
}

/* ── App View ─────────────────────────────────────────────── */

#app-view {
  flex: 1;
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}

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

.sidebar-header h2 {
  font-size: 16px;
  font-weight: 700;
}

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

/* Search Bar */
.search-bar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.search-bar input {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
}

/* Conversation List */
.conversation-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-list::-webkit-scrollbar {
  width: 4px;
}
.conversation-list::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 2px;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}

.conversation-item:hover {
  background: var(--bg-hover);
}

.conversation-item.online .conv-name::after {
  content: ' ●';
  color: var(--accent);
  font-size: 10px;
}

.conv-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

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

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

.conv-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-meta {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

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

.main-placeholder .icon {
  font-size: 64px;
  opacity: 0.3;
}

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

/* Search Results */
#search-results {
  padding: 8px 0;
  border-top: 1px solid var(--border);
  max-height: 300px;
  overflow-y: auto;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition);
}

.search-result-item:hover {
  background: var(--bg-hover);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.user-info {
  flex: 1;
}

.user-name {
  font-size: 14px;
  font-weight: 600;
}

/* ── Chat View ─────────────────────────────────────────────── */

#chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.chat-header .back-btn {
  background: none;
  border: none;
  color: var(--accent-blue);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.chat-header .back-btn:hover { background: var(--bg-tertiary); }

.chat-header h3 {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.messages-container::-webkit-scrollbar {
  width: 4px;
}
.messages-container::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 2px;
}

.message-bubble {
  display: flex;
  max-width: 75%;
}

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

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

.bubble-content {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  position: relative;
}

.message-bubble.mine .bubble-content {
  background: var(--accent);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-bubble.theirs .bubble-content {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.bubble-text {
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  justify-content: flex-end;
}

.bubble-time {
  font-size: 10px;
  opacity: 0.7;
}

.bubble-status {
  font-size: 10px;
  opacity: 0.7;
}

/* Typing indicator */
#typing-indicator {
  padding: 8px 16px;
  color: var(--text-secondary);
  font-size: 13px;
  font-style: italic;
}

/* Chat Input */
.chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

.chat-input {
  flex: 1;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.chat-input:focus { border-color: var(--accent-blue); }

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Error Toast ───────────────────────────────────────────── */

#error-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--danger);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 90%;
}

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

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    min-width: unset;
  }

  .message-bubble {
    max-width: 88%;
  }
}

/* ── Call UI ───────────────────────────────────────────────── */

.call-btn {
  min-width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  transition: opacity 0.2s, transform 0.1s;
}

.call-btn:active {
  transform: scale(0.95);
}

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

/* 通话中静音/摄像头按钮 */
.call-btn:not([style*="border-radius: 50%"]) {
  border-radius: 24px;
  color: #fff;
}

#call-overlay video {
  object-fit: cover;
}
