/* ========================================
   安全生产知识智能体 — 样式
   ======================================== */

:root {
  --primary: #1565C0;
  --primary-light: #42A5F5;
  --primary-dark: #0D47A1;
  --accent: #FFC107;
  --accent-dark: #FF8F00;
  --bg: #0A1628;
  --bg-light: #0F2035;
  --surface: #1A2D47;
  --surface-light: #243B56;
  --text: #E8EDF3;
  --text-secondary: #8DA4BE;
  --ai-bubble: #1A2D47;
  --user-bubble: #1565C0;
  --danger: #E53935;
  --success: #43A047;
  --radius: 16px;
  --radius-sm: 10px;
}

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

html, body {
  height: 100%;
  font-family: "Microsoft YaHei", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* 粒子背景 */
#particles {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 0;
  pointer-events: none;
}

/* ---- 布局 ---- */
.app-container {
  display: flex;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* ---- 左侧面板 ---- */
.avatar-panel {
  width: 320px;
  min-width: 320px;
  background: linear-gradient(180deg, var(--bg-light) 0%, var(--bg) 100%);
  border-right: 1px solid rgba(255,255,255,0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 20px;
  overflow-y: auto;
}

.avatar-wrapper {
  position: relative;
  width: 220px;
  height: 220px;
  margin-bottom: 16px;
}

.avatar-glow {
  position: absolute;
  top: 50%; left: 50%;
  width: 180px; height: 180px;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle, rgba(33,150,243,0.25) 0%, transparent 70%);
  border-radius: 50%;
  animation: glow-pulse 3s ease-in-out infinite;
}

@keyframes glow-pulse {
  0%, 100% { transform: translate(-50%, -50%) scale(1); opacity: 0.6; }
  50% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; }
}

#avatar-container {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 1;
}

#avatar-container object {
  width: 100%;
  height: 100%;
}

.avatar-status {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 22, 40, 0.85);
  backdrop-filter: blur(8px);
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 2;
  border: 1px solid rgba(67, 160, 71, 0.3);
}

.status-dot {
  width: 7px; height: 7px;
  background: var(--success);
  border-radius: 50%;
  display: inline-block;
  animation: dot-blink 2s ease-in-out infinite;
}

@keyframes dot-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.avatar-info {
  text-align: center;
  margin-bottom: 20px;
}

.avatar-info h2 {
  font-size: 22px;
  color: var(--text);
  margin-bottom: 4px;
}

.avatar-info p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.info-tags {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}

.tag {
  background: rgba(21, 101, 192, 0.2);
  color: var(--primary-light);
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid rgba(33, 150, 243, 0.2);
}

/* 快捷问题 */
.quick-questions {
  width: 100%;
  margin-top: 8px;
}

.quick-questions h3 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding-left: 4px;
}

.quick-btn {
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.quick-btn:hover {
  background: var(--surface-light);
  border-color: var(--primary-light);
  transform: translateX(4px);
}

/* ---- 右侧聊天面板 ---- */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  background: rgba(15, 32, 53, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-icon {
  font-size: 28px;
}

.chat-header h1 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}

.header-sub {
  font-size: 12px;
  color: var(--text-secondary);
}

.online-badge {
  color: var(--success);
  font-size: 13px;
}

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

.chat-messages::-webkit-scrollbar {
  width: 5px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
}

/* 消息气泡 */
.message {
  display: flex;
  gap: 12px;
  max-width: 78%;
  animation: msg-in 0.3s ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.user-message {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.ai-message .message-avatar {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
}

.user-message .message-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
}

.message-content {
  background: var(--ai-bubble);
  border-radius: var(--radius) var(--radius) var(--radius) 4px;
  padding: 14px 18px;
  border: 1px solid rgba(255,255,255,0.06);
}

.user-message .message-content {
  background: var(--user-bubble);
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  border-color: transparent;
}

.message-name {
  font-size: 12px;
  color: var(--primary-light);
  margin-bottom: 6px;
  font-weight: 500;
}

.user-message .message-name {
  color: rgba(255,255,255,0.7);
}

.message-text {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  word-break: break-word;
}

.message-text strong {
  color: var(--accent);
}

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* 打字指示器 */
.typing-indicator {
  display: flex;
  gap: 12px;
  align-self: flex-start;
  max-width: 78%;
}

.typing-dots {
  background: var(--ai-bubble);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius) var(--radius) var(--radius) 4px;
  padding: 14px 20px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dots span {
  width: 8px; height: 8px;
  background: var(--text-secondary);
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

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

/* ---- 输入区域 ---- */
.chat-input-area {
  padding: 16px 28px 20px;
  background: rgba(15, 32, 53, 0.8);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(255,255,255,0.06);
}

/* ---- 语音面板 ---- */
.voice-panel {
  width: 100%;
  margin-bottom: 12px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.06);
}

.voice-panel h3 {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 10px;
  padding-left: 4px;
}

.voice-toggle {
  margin-bottom: 8px;
}

.switch-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
}

.switch-label input[type="checkbox"] {
  display: none;
}

.switch-slider {
  width: 36px;
  height: 20px;
  background: var(--surface-light);
  border-radius: 10px;
  position: relative;
  transition: background 0.3s;
  flex-shrink: 0;
}

.switch-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: all 0.3s;
}

.switch-label input:checked + .switch-slider {
  background: var(--primary);
}

.switch-label input:checked + .switch-slider::after {
  left: 18px;
  background: white;
}

.voice-select {
  margin-top: 8px;
}

.voice-select label {
  font-size: 12px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

.voice-select select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--text);
  font-size: 12px;
  outline: none;
}

.voice-speed {
  margin-top: 8px;
}

.voice-speed label {
  font-size: 12px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

.voice-speed input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

/* ---- 麦克风按钮 ---- */
.mic-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: var(--surface-light);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  position: relative;
  margin-right: 8px;
}

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

.mic-btn.recording {
  background: var(--danger);
  color: white;
  animation: mic-pulse 1s ease-in-out infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(229, 57, 53, 0); }
}

.mic-pulse {
  display: none;
}

.stop-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--danger);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  margin-right: 6px;
}

.stop-btn:hover {
  background: #C62828;
  transform: scale(1.05);
}

/* ---- 语音状态条 ---- */
.voice-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  padding: 8px 14px;
  background: rgba(229, 57, 53, 0.1);
  border: 1px solid rgba(229, 57, 53, 0.3);
  border-radius: var(--radius-sm);
  animation: fade-in 0.2s;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.voice-wave {
  display: flex;
  gap: 3px;
  align-items: center;
  height: 20px;
}

.voice-wave span {
  width: 3px;
  height: 10px;
  background: var(--danger);
  border-radius: 2px;
  animation: wave 0.8s ease-in-out infinite;
}

.voice-wave span:nth-child(2) { animation-delay: 0.1s; }
.voice-wave span:nth-child(3) { animation-delay: 0.2s; }
.voice-wave span:nth-child(4) { animation-delay: 0.3s; }
.voice-wave span:nth-child(5) { animation-delay: 0.4s; }

@keyframes wave {
  0%, 100% { height: 6px; }
  50% { height: 18px; }
}

.voice-status-text {
  font-size: 13px;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-cancel {
  background: none;
  border: 1px solid rgba(229, 57, 53, 0.4);
  color: var(--danger);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.voice-cancel:hover {
  background: var(--danger);
  color: white;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 4px 4px 4px 16px;
  transition: border-color 0.2s;
}

.input-wrapper:focus-within {
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.15);
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  padding: 10px 0;
  resize: none;
  max-height: 120px;
  font-family: inherit;
}

#user-input::placeholder {
  color: var(--text-secondary);
}

#send-btn {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

#send-btn:hover {
  background: var(--primary-light);
  transform: scale(1.05);
}

#send-btn:active {
  transform: scale(0.95);
}

#send-btn:disabled {
  background: var(--surface-light);
  cursor: not-allowed;
  transform: none;
}

.input-footer {
  text-align: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.6;
}

/* ---- 响应式 ---- */
@media (max-width: 900px) {
  .avatar-panel {
    width: 60px;
    min-width: 60px;
    padding: 12px 6px;
  }
  .avatar-wrapper { width: 42px; height: 42px; }
  .avatar-glow { width: 60px; height: 60px; }
  .avatar-info, .voice-panel, .quick-questions, .avatar-status .status-text { display: none; }
  .avatar-status {
    bottom: -4px;
    padding: 3px 6px;
  }
  .status-dot { width: 5px; height: 5px; }
  .chat-messages { padding: 16px; }
  .message { max-width: 92%; }
}
