/* ===================================================
   P2P E2EE 加密通讯 - 样式表
   =================================================== */

/* --- CSS 变量 --- */
:root {
  --bg-primary: #0f0f14;
  --bg-secondary: #1a1a24;
  --bg-tertiary: #23233a;
  --bg-card: #1e1e30;
  --text-primary: #e8e8f0;
  --text-secondary: #9898b0;
  --text-muted: #6868808c;
  --accent: #6c5ce7;
  --accent-hover: #7d6ff0;
  --accent-light: rgba(108, 92, 231, 0.15);
  --success: #00cec9;
  --success-light: rgba(0, 206, 201, 0.15);
  --warning: #fdcb6e;
  --danger: #ff6b6b;
  --danger-hover: #ee5a5a;
  --border: #2a2a40;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* --- 主布局 --- */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* --- 侧边栏 --- */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  padding: 24px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* 状态面板 */
.status-panel {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.status-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  font-size: 0.85rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 10px;
  flex-shrink: 0;
  transition: background var(--transition);
}

.status-dot.connected,
.status-dot.encrypted {
  background: var(--success);
  box-shadow: 0 0 8px rgba(0, 206, 201, 0.5);
}

.status-dot.connecting {
  background: var(--warning);
  animation: pulse 1.5s infinite;
}

.status-dot.disconnected {
  background: #555;
}

.status-dot.error {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-label {
  color: var(--text-secondary);
  width: 50px;
}

.status-text {
  color: var(--text-primary);
  font-weight: 500;
  margin-left: auto;
  font-size: 0.8rem;
}

/* 安全验证码 */
.security-code-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.security-code-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 8px;
}

.security-icon {
  font-size: 1rem;
}

.security-code {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: 'SF Mono', 'Cascadia Code', 'Consolas', monospace;
  font-size: 0.8rem;
  color: var(--success);
  text-align: center;
  letter-spacing: 1px;
  word-break: break-all;
}

.security-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

/* 用户信息 */
.user-info {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.user-label {
  color: var(--text-secondary);
}

.user-id {
  color: var(--accent);
  font-family: monospace;
  font-size: 0.8rem;
  margin-left: 4px;
}

/* 技术说明 */
.tech-info {
  padding: 16px 20px;
  margin-top: auto;
}

.tech-info h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.tech-info ul {
  list-style: none;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.tech-info li {
  padding: 3px 0;
}

.tech-info li::before {
  content: '✓ ';
  color: var(--success);
}

.tech-info strong {
  color: var(--text-secondary);
}

/* --- 主内容区 --- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* --- 连接面板 --- */
.connect-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.connect-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px;
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.connect-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

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

.connect-card > p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.connect-form {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.connect-form input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition);
}

.connect-form input:focus {
  border-color: var(--accent);
}

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

.connect-info {
  text-align: left;
}

.connect-info p {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 4px 0;
}

.connect-info code {
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--accent);
}

/* --- 聊天面板 --- */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-room-name {
  font-size: 1rem;
  font-weight: 600;
}

.chat-encryption-badge {
  background: var(--success-light);
  color: var(--success);
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 600;
}

/* 消息区域 */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* 系统消息 */
.system-message {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 8px 0;
  user-select: none;
}

/* 消息气泡 */
.message {
  display: flex;
  max-width: 70%;
}

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

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

.message-bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  position: relative;
  word-wrap: break-word;
  word-break: break-word;
}

.message-sent .message-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

.message-content {
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.message-time {
  font-size: 0.65rem;
  opacity: 0.6;
  margin-top: 4px;
  text-align: right;
}

.message-lock {
  font-size: 0.6rem;
}

/* 文件消息 */
.file-message {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.file-icon {
  font-size: 2rem;
}

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

.file-name {
  font-size: 0.85rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-download {
  color: inherit;
  text-decoration: underline;
}

.file-download:hover {
  opacity: 0.8;
}

.file-size {
  font-size: 0.7rem;
  opacity: 0.6;
}

.file-message .message-time {
  width: 100%;
}

/* 输入区域 */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 16px 24px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
}

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

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

.chat-input-area textarea::placeholder {
  color: var(--text-muted);
}

.chat-input-area textarea:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* --- 按钮 --- */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

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

.btn-danger:hover:not(:disabled) {
  background: var(--danger);
  color: #fff;
}

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

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 10px;
  font-size: 1.1rem;
  line-height: 1;
  border-radius: var(--radius-sm);
}

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

.btn-send {
  padding: 10px 24px;
}

/* --- 工具类 --- */
.hidden {
  display: none !important;
}

/* --- 滚动条 --- */
::-webkit-scrollbar {
  width: 6px;
}

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

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

::-webkit-scrollbar-thumb:hover {
  background: #444;
}

/* --- 响应式 --- */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    min-width: 60px;
    overflow: hidden;
  }

  .sidebar-header,
  .security-code-section,
  .user-info,
  .tech-info {
    display: none;
  }

  .status-panel {
    padding: 10px;
  }

  .status-item {
    justify-content: center;
  }

  .status-label,
  .status-text {
    display: none;
  }

  .status-dot {
    margin: 0;
    width: 10px;
    height: 10px;
  }

  .connect-card {
    padding: 24px;
  }

  .connect-form {
    flex-direction: column;
  }

  .chat-messages {
    padding: 16px;
  }

  .message {
    max-width: 85%;
  }
}
