/* ============================================
   一曲阳光AI交互 - 主样式表
   ============================================ */

:root {
  --bg-primary: #1a1a2e;
  --bg-secondary: #16213e;
  --bg-tertiary: #0f0f23;
  --bg-input: #1e1e3a;
  --bg-hover: #2a2a4a;

/* 确保 hidden 属性生效（防止 CSS display 覆盖） */
[hidden] { display: none !important; }
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --accent: #667eea;
  --accent-hover: #5a6fd6;
  --accent-gradient: linear-gradient(135deg, #667eea, #764ba2);
  --border: #2a2a45;
  --success: #4ade80;
  --warning: #fbbf24;
  --danger: #f87171;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --sidebar-width: 280px;
  --transition: 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

#app { display: flex; height: 100vh; }

/* ============ 侧边栏 ============ */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: all var(--transition);
  z-index: 10;
}
.sidebar.collapsed {
  width: 0; min-width: 0; overflow: hidden; border: none;
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.logo svg { flex-shrink: 0; }

.btn-icon {
  background: none; border: none; color: var(--text-secondary); cursor: pointer;
  font-size: 18px; padding: 4px 8px; border-radius: 6px;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-new-chat {
  margin: 12px; padding: 10px 16px; background: var(--accent-gradient);
  color: #fff; border: none; border-radius: var(--radius);
  cursor: pointer; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 8px; transition: all var(--transition);
}
.btn-new-chat:hover { opacity: 0.9; transform: translateY(-1px); }

.session-list {
  flex: 1; overflow-y: auto; padding: 8px;
}
.session-item {
  padding: 12px; border-radius: var(--radius-sm); cursor: pointer;
  margin-bottom: 4px; transition: all var(--transition);
  display: flex; align-items: center; justify-content: space-between;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active { background: var(--accent); background: rgba(102,126,234,0.15); }
.session-item .session-title {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; color: var(--text-primary);
}
.session-item .session-date {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}
.session-item .session-delete {
  opacity: 0; background: none; border: none; color: var(--danger);
  cursor: pointer; padding: 4px; border-radius: 4px; font-size: 14px;
}
.session-item:hover .session-delete { opacity: 1; }
.loading-text { text-align: center; color: var(--text-muted); padding: 20px; font-size: 13px; }

.sidebar-footer {
  padding: 12px; border-top: 1px solid var(--border);
}
.btn-admin {
  display: block; text-align: center; padding: 10px;
  background: var(--bg-hover); color: var(--text-secondary);
  text-decoration: none; border-radius: var(--radius-sm); font-size: 13px;
  transition: all var(--transition);
}
.btn-admin:hover { background: var(--accent); color: #fff; }

/* ============ 主区域 ============ */
.main {
  flex: 1; display: flex; position: relative; overflow: hidden;
}
.chat-container {
  flex: 1; display: flex; flex-direction: column; max-width: 900px; margin: 0 auto;
  width: 100%;
}

/* ============ 消息区 ============ */
.chat-messages {
  flex: 1; overflow-y: auto; padding: 24px 16px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.welcome-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 70vh; text-align: center;
}
.welcome-logo { margin-bottom: 20px; }
.welcome-screen h1 { font-size: 28px; margin-bottom: 8px; background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.welcome-sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 32px; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; max-width: 500px; }
.quick-btn {
  padding: 10px 18px; background: var(--bg-secondary); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 20px; cursor: pointer;
  font-size: 13px; transition: all var(--transition);
}
.quick-btn:hover { background: var(--bg-hover); border-color: var(--accent); }

/* 消息气泡 */
.message {
  display: flex; margin-bottom: 20px; animation: fadeIn 0.3s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message-avatar {
  width: 36px; height: 36px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 16px; font-weight: bold; margin: 0 10px;
}
.message.user .message-avatar { order: 2; background: var(--accent-gradient); color: #fff; }
.message.assistant .message-avatar { order: 1; background: var(--bg-secondary); border: 1px solid var(--border); color: var(--accent); }

.message-content {
  max-width: 75%; padding: 12px 16px; border-radius: var(--radius);
  font-size: 14px; line-height: 1.7; word-wrap: break-word;
}
.message.user .message-content { background: var(--accent-gradient); color: #fff; border-radius: var(--radius) 4px var(--radius) var(--radius); }
.message.assistant .message-content { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 4px var(--radius) var(--radius) var(--radius); }

.message-content p { margin-bottom: 8px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content pre {
  background: var(--bg-tertiary); border-radius: var(--radius-sm);
  padding: 12px; overflow-x: auto; font-size: 13px; margin: 8px 0;
}
.message-content code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
}
.message-content :not(pre) > code {
  background: var(--bg-tertiary); padding: 2px 6px; border-radius: 4px;
}

/* 流式打字光标 */
.streaming-cursor::after {
  content: '▊'; animation: blink 1s step-end infinite; color: var(--accent);
}
@keyframes blink { 50% { opacity: 0; } }

/* ============ 输入区 ============ */
.chat-input-area {
  padding: 12px 16px 8px; border-top: 1px solid var(--border);
  background: var(--bg-primary);
}
.input-wrapper {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px;
  transition: border-color var(--transition);
}
.input-wrapper:focus-within { border-color: var(--accent); }

.input-tools { display: flex; align-items: center; }
.tool-btn {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; padding: 6px; border-radius: 6px; display: flex;
  transition: all var(--transition);
}
.tool-btn:hover { background: var(--bg-hover); color: var(--accent); }

#chatInput {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 14px; font-family: inherit;
  resize: none; max-height: 200px; line-height: 1.5; padding: 4px 0;
}
#chatInput::placeholder { color: var(--text-muted); }

.btn-send {
  background: var(--accent); color: #fff; border: none;
  border-radius: 50%; width: 36px; height: 36px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all var(--transition);
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-send.sending {
  background: var(--danger);
}

.input-hint {
  text-align: center; font-size: 11px; color: var(--text-muted);
  margin-top: 6px;
}

/* ============ 文件预览区 ============ */
.file-preview-area {
  display: flex; gap: 8px; padding: 8px 16px 0; flex-wrap: wrap;
}
.file-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: 20px; font-size: 12px;
}
.file-chip .remove-chip {
  cursor: pointer; color: var(--text-muted); font-size: 14px;
}
.file-chip .remove-chip:hover { color: var(--danger); }

/* ============ 机器人状态 ============ */
.robot-status {
  position: fixed; right: 16px; bottom: 120px;
  display: flex; flex-direction: column; align-items: center;
  gap: 8px; z-index: 5;
}
.robot-icon { position: relative; }
.robot-face svg { color: var(--text-muted); transition: color 0.5s ease; }
.robot-face.working svg { color: var(--success); animation: robotPulse 1.5s ease-in-out infinite; }
.robot-face.idle svg { color: var(--warning); }
.robot-face.sleep svg { color: var(--text-muted); opacity: 0.3; }

@keyframes robotPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  position: absolute; bottom: 0; right: 0;
  border: 2px solid var(--bg-primary);
}
.status-dot.working { background: var(--success); animation: dotPulse 1s ease-in-out infinite; }
.status-dot.idle { background: var(--warning); }
.status-dot.sleep { background: var(--text-muted); }

@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(74,222,128,0); }
}

.status-text { font-size: 11px; color: var(--text-muted); }

/* ============ 弹窗 ============ */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; backdrop-filter: blur(4px);
}
.modal-content {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); max-width: 700px; width: 90%;
  max-height: 80vh; display: flex; flex-direction: column;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; }
.btn-close {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; font-size: 20px; padding: 4px 8px;
}
.modal-body { flex: 1; overflow-y: auto; padding: 16px; }

/* ============ 上传进度 ============ */
.upload-progress {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 24px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; min-width: 250px;
}
.progress-bar {
  height: 4px; background: var(--border); border-radius: 2px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--accent-gradient); border-radius: 2px;
  transition: width 0.3s ease; width: 0%;
}

/* ============ 拖拽上传 ============ */
.drop-zone-active #chatInput::placeholder { color: var(--accent); }
.drop-overlay {
  position: fixed; inset: 0; background: rgba(102,126,234,0.1);
  border: 3px dashed var(--accent); z-index: 200;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.drop-overlay .drop-text {
  font-size: 24px; color: var(--accent); font-weight: 600;
}

/* ============ 响应式 ============ */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; }
  .sidebar.collapsed { left: -280px; width: 280px; min-width: 280px; }
  .main { padding: 0; }
  .chat-container { max-width: 100%; }
  .message-content { max-width: 85%; }
  .robot-status { right: 8px; bottom: 100px; }
  .robot-face svg { width: 40px; height: 40px; }
}

/* ============ Markdown 渲染 ============ */
.message-content h1, .message-content h2, .message-content h3 {
  margin: 12px 0 6px; font-weight: 600;
}
.message-content h1 { font-size: 1.4em; }
.message-content h2 { font-size: 1.2em; }
.message-content h3 { font-size: 1.1em; }
.message-content ul, .message-content ol { padding-left: 20px; margin: 8px 0; }
.message-content li { margin-bottom: 4px; }
.message-content blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text-secondary); margin: 8px 0;
}
.message-content table {
  border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px;
}
.message-content th, .message-content td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left;
}
.message-content th { background: var(--bg-tertiary); }
.message-content a { color: var(--accent); }
.message-content hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* 代码块复制按钮 */
.code-block-wrapper { position: relative; }
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--bg-hover); color: var(--text-secondary);
  border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer;
  font-size: 11px; transition: all var(--transition);
}
.copy-btn:hover { background: var(--accent); color: #fff; }

/* 消息操作按钮 */
.message-actions {
  display: flex; gap: 4px; margin-top: 6px; opacity: 0; transition: opacity var(--transition);
}
.message:hover .message-actions { opacity: 1; }
.msg-action-btn {
  background: none; border: 1px solid var(--border); color: var(--text-muted);
  padding: 2px 8px; border-radius: 4px; cursor: pointer; font-size: 11px;
}
.msg-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
