/* ========== 金色村落心智智能体 v2 — Alexa 风格 + 金色主题 ========== */

:root {
  --bg: #ffffff;
  --bg-card: #f5f5f5;
  --bg-hover: #eeeeee;
  --bg-input: #f0f0f0;
  --gold: #c9a84c;
  --gold-dark: #a68a36;
  --gold-light: #e8d59a;
  --gold-bg: rgba(201,168,76,0.08);
  --gold-bg-strong: rgba(201,168,76,0.15);
  --text: #212121;
  --text-secondary: #666666;
  --text-dim: #999999;
  --border: #e8e8e8;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: 0.2s ease;
  --font: -apple-system, "PingFang SC", "Noto Sans SC", "Helvetica Neue", sans-serif;
  --header-h: 52px;
  --input-h: 56px;
  --sidebar-w: 280px;
}

/* ========== Reset ========== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh; height: 100dvh;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; color: inherit; }
img { max-width: 100%; display: block; }

/* ========== 欢迎页 ========== */
.welcome-screen {
  position: fixed; inset: 0; z-index: 200;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 2rem;
}
.welcome-screen.hidden { display: none; }
.welcome-content { max-width: 340px; }
.welcome-logo {
  width: 72px; height: 72px; margin: 0 auto 1.5rem;
  border-radius: 18px; object-fit: contain;
  box-shadow: 0 4px 20px rgba(201,168,76,0.2);
}
.welcome-content h1 {
  font-size: 1.6rem; font-weight: 700; color: var(--gold-dark);
  margin-bottom: 0.6rem; letter-spacing: 0.04em;
}
.welcome-content p {
  color: var(--text-secondary); font-size: 0.9rem;
  margin-bottom: 2rem; line-height: 1.8;
}
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--gold); color: #fff;
  font-weight: 600; font-size: 0.95rem;
  padding: 0.75rem 2rem; border-radius: 24px;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(201,168,76,0.3);
}
.btn-primary:hover { background: var(--gold-dark); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-lg { width: 100%; padding: 0.9rem; font-size: 1rem; }
.btn-secondary {
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary); font-size: 0.85rem;
  padding: 0.6rem 1.5rem; border-radius: 20px;
  background: var(--bg-card); margin-top: 0.75rem;
  transition: all var(--transition);
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--gold-dark); }

/* ========== 通用图标按钮 ========== */
.btn-icon {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; border-radius: 50%;
  transition: all var(--transition); color: var(--text-secondary);
}
.btn-icon:hover { background: var(--bg-card); }
.btn-icon-text {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 0.75rem; font-size: 0.85rem;
  border-radius: var(--radius-sm); transition: all var(--transition);
  color: var(--text-secondary);
}
.btn-icon-text:hover { background: var(--bg-card); }

/* ========== 侧边栏 ========== */
.sidebar-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0,0,0,0.35); opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.sidebar-overlay.active { opacity: 1; pointer-events: auto; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w); z-index: 91;
  background: var(--bg);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform var(--transition);
  display: flex; flex-direction: column;
}
.sidebar.active { transform: translateX(0); }
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.sidebar-header h2 { font-size: 1rem; font-weight: 600; color: var(--gold-dark); }

.btn-new-decode {
  display: flex; align-items: center; gap: 0.5rem;
  width: calc(100% - 2rem); margin: 1rem;
  padding: 0.7rem; justify-content: center;
  background: var(--gold-bg); color: var(--gold-dark);
  border: 1px dashed var(--gold-light); border-radius: 12px;
  font-size: 0.88rem; font-weight: 500;
  transition: all var(--transition);
}
.btn-new-decode:hover { background: var(--gold-bg-strong); }

.history-list { flex: 1; overflow-y: auto; padding: 0.5rem; }
.history-item {
  padding: 0.75rem 1rem; border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition);
  margin-bottom: 2px;
}
.history-item:hover { background: var(--bg-card); }
.history-item.active { background: var(--gold-bg); }
.history-item-title {
  font-size: 0.88rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item-date { font-size: 0.72rem; color: var(--text-dim); margin-top: 0.15rem; }
.history-item-delete {
  float: right; font-size: 0.72rem; color: var(--text-dim);
  opacity: 0; transition: opacity var(--transition); padding: 2px 4px;
}
.history-item:hover .history-item-delete { opacity: 1; }
.sidebar-footer { padding: 0.75rem 1rem; border-top: 1px solid var(--border); }

/* ========== 主容器 ========== */
.main-wrapper {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
}

/* ========== 顶部栏 — Alexa 风格 ========== */
.top-bar {
  height: var(--header-h); flex-shrink: 0;
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0 0.6rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.top-bar-title {
  flex: 1; display: flex; align-items: center; gap: 0.5rem;
  min-width: 0;
}
.top-bar-logo { height: 30px; width: auto; border-radius: 6px; }
.phase-indicator {
  font-size: 0.7rem; color: var(--gold-dark); font-weight: 500;
  background: var(--gold-bg); padding: 2px 10px;
  border-radius: 12px; white-space: nowrap;
}
.btn-report {
  font-size: 0.78rem; font-weight: 500; color: var(--gold-dark);
  background: var(--gold-bg);
  padding: 5px 14px; border-radius: 14px; white-space: nowrap;
  transition: all var(--transition);
}
.btn-report:hover { background: var(--gold-bg-strong); }

/* ========== 对话区域 ========== */
.chat-area {
  flex: 1; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.chat-messages {
  flex: 1; overflow-y: auto; padding: 1rem 0.75rem;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ========== 消息气泡 — Alexa 卡片式 ========== */
.message {
  margin-bottom: 0.75rem;
  display: flex; flex-direction: column;
  max-width: 100%;
  animation: msgIn 0.25s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.message-user { align-items: flex-end; }
.message-assistant { align-items: flex-start; }

.message-bubble {
  max-width: 82%; padding: 0.8rem 1rem;
  border-radius: var(--radius);
  font-size: 0.92rem; line-height: 1.7;
  word-break: break-word;
}
/* 用户气泡：金色底白字 */
.message-user .message-bubble {
  background: var(--gold);
  color: #fff;
  border-bottom-right-radius: var(--radius-xs);
  box-shadow: 0 1px 4px rgba(201,168,76,0.25);
}
/* 助手气泡：浅灰卡片 */
.message-assistant .message-bubble {
  background: var(--bg-card);
  color: var(--text);
  border-bottom-left-radius: var(--radius-xs);
}

.message-bubble p { margin-bottom: 0.4rem; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble strong { color: var(--gold-dark); font-weight: 600; }

/* 气泡内表格 */
.message-bubble table {
  width: 100%; border-collapse: collapse; margin: 0.5rem 0;
  font-size: 0.82rem;
}
.message-bubble th, .message-bubble td {
  padding: 0.45rem 0.5rem; border: 1px solid var(--border);
  text-align: left; vertical-align: top;
}
.message-bubble th {
  background: var(--bg-hover); color: var(--gold-dark);
  font-weight: 600; font-size: 0.78rem;
}
.message-bubble em { color: var(--text-secondary); font-style: normal; }
.message-bubble code {
  background: var(--bg-hover); padding: 1px 5px;
  border-radius: 4px; font-size: 0.85em;
}

/* 打字指示器 — 带状态文字 */
.typing-status {
  display: flex; align-items: center; gap: 10px;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-radius: var(--radius);
  border-bottom-left-radius: var(--radius-xs);
}
.typing-dots {
  display: flex; gap: 4px; flex-shrink: 0;
}
.typing-dots span {
  width: 6px; height: 6px; background: var(--gold);
  border-radius: 50%; animation: typing 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
.typing-text {
  font-size: 0.85rem; color: var(--text-secondary);
  animation: fadeText 1.5s ease infinite;
}
@keyframes fadeText {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* 思考过程折叠块 */
.reasoning-block {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin-bottom: 0.6rem;
  font-size: 0.82rem; color: var(--text-dim);
}
.reasoning-block summary {
  padding: 0.5rem 0.75rem; cursor: pointer;
  color: var(--text-secondary); font-weight: 500;
  list-style: none; display: flex; align-items: center; gap: 0.4rem;
}
.reasoning-block summary::before { content: '💡'; }
.reasoning-block[open] summary { border-bottom: 1px solid var(--border); }
.reasoning-block .reasoning-text {
  padding: 0.75rem; line-height: 1.7; max-height: 250px; overflow-y: auto;
}

/* ========== 输入区域 — Alexa 风格圆角输入框 ========== */
.input-area {
  flex-shrink: 0;
  padding: 0.5rem 0.75rem;
  padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  background: var(--bg);
  display: flex; align-items: flex-end; gap: 0.35rem;
}
.input-text-mode {
  flex: 1; display: flex; align-items: flex-end; gap: 0.35rem;
  background: var(--bg-input);
  border-radius: 24px;
  padding: 0.25rem 0.25rem 0.25rem 0.85rem;
}
.input-text-mode textarea {
  flex: 1; resize: none;
  background: transparent;
  border: none;
  padding: 0.55rem 0;
  font-size: 0.95rem; line-height: 1.5;
  max-height: 100px; min-height: 36px;
  outline: none;
}
.input-text-mode textarea::placeholder { color: var(--text-dim); }

.btn-send {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--gold); color: #fff;
  border-radius: 50%; transition: all var(--transition);
}
.btn-send:disabled { background: var(--bg-hover); color: var(--text-dim); }
.btn-send:not(:disabled):hover { background: var(--gold-dark); }

/* 附件按钮 */
.btn-attach {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); border-radius: 50%;
  transition: all var(--transition);
}
.btn-attach:hover { color: var(--gold-dark); background: var(--gold-bg); }

/* 文件预览标签 */
.file-preview {
  display: flex; align-items: center; gap: 6px;
  background: var(--gold-bg);
  padding: 0.35rem 0.75rem;
  border-radius: 16px;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  color: var(--gold-dark);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.file-preview-icon { font-size: 0.9rem; }
.file-preview-name {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 180px;
}
.file-preview-remove {
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
  background: var(--gold-light); color: #fff;
  border-radius: 50%; font-size: 0.7rem;
  transition: all var(--transition);
}
.file-preview-remove:hover { background: var(--gold-dark); }

/* 语音模式 */
.input-voice-mode { flex: 1; display: flex; }
.voice-btn-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 44px;
  background: var(--bg-input);
  border-radius: 24px;
  cursor: pointer; user-select: none; -webkit-user-select: none;
  transition: all var(--transition); touch-action: manipulation;
}
.voice-btn-area:active, .voice-btn-area.recording {
  background: var(--gold-bg-strong);
  transform: scale(0.98);
}
.voice-btn-inner {
  display: flex; align-items: center; gap: 0.5rem;
  color: var(--text-secondary); pointer-events: none;
}
.voice-btn-area.recording .voice-btn-inner { color: var(--gold-dark); }
.voice-btn-label {
  font-size: 0.88rem; max-width: 60vw;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 模式切换 */
.input-mode-switch { display: flex; align-items: flex-end; padding-bottom: 4px; }
.mode-btn {
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); border-radius: 50%;
  transition: all var(--transition);
}
.mode-btn:hover, .mode-btn:active { color: var(--gold-dark); background: var(--gold-bg); }

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

/* ========== 对话内报告卡片 ========== */
.report-chat-card {
  background: linear-gradient(135deg, rgba(201,168,76,0.06), rgba(201,168,76,0.02));
  border: 1px solid var(--gold-light);
  border-radius: var(--radius);
  padding: 1rem;
  min-width: 220px;
}
.report-chat-card-header {
  display: flex; align-items: flex-start; gap: 0.6rem;
  margin-bottom: 0.75rem;
}
.report-chat-card-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 2px; }
.report-chat-card-info { flex: 1; min-width: 0; }
.report-chat-card-title {
  font-size: 0.92rem; font-weight: 600; color: var(--gold-dark);
  margin-bottom: 0.35rem;
}
.report-chat-card-badge {
  display: inline-block;
  font-size: 0.68rem; color: var(--gold-dark);
  background: var(--gold-bg);
  padding: 2px 8px; border-radius: 10px;
  margin-right: 4px;
}
.report-chat-card-btn {
  width: 100%;
  padding: 0.6rem;
  background: var(--gold);
  color: #fff;
  font-size: 0.88rem; font-weight: 500;
  border-radius: 20px;
  transition: all var(--transition);
  box-shadow: 0 2px 8px rgba(201,168,76,0.25);
}
.report-chat-card-btn:hover { background: var(--gold-dark); }

/* ========== 报告列表 ========== */
.report-list-item {
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 2px;
  position: relative;
}
.report-list-item:hover { background: var(--bg-card); }
.report-list-item.active { background: var(--gold-bg); }
.report-list-delete-btn {
  position: absolute;
  top: 50%;
  right: 0.5rem;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: all var(--transition);
}
.report-list-item:hover .report-list-delete-btn { opacity: 1; }
.report-list-delete-btn:hover { background: #fde8e8; color: #e74c3c; }
.report-list-title {
  font-size: 0.88rem; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.report-list-meta {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.72rem; color: var(--text-dim); margin-top: 0.2rem;
}
.report-list-badge {
  display: inline-block; font-size: 0.68rem;
  background: var(--bg-card); color: var(--text-dim);
  padding: 1px 8px; border-radius: 10px;
}
.report-list-badge.done {
  background: var(--gold-bg); color: var(--gold-dark);
}

/* ========== 设置弹窗 ========== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem; opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
  width: 100%; max-width: 400px;
  background: var(--bg); border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translateY(16px);
  transition: transform var(--transition);
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 1rem; font-weight: 600; }
.modal-body { padding: 1.25rem; }
.form-group { margin-bottom: 1.1rem; }
.form-group label {
  display: block; font-size: 0.82rem; font-weight: 500;
  margin-bottom: 0.35rem; color: var(--text-secondary);
}
.form-group input {
  width: 100%; padding: 0.65rem 0.85rem;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 0.9rem;
  outline: none; transition: border-color var(--transition);
}
.form-group input:focus { border-color: var(--gold); }
.form-group small { display: block; margin-top: 0.25rem; font-size: 0.72rem; color: var(--text-dim); }
.modal-body .btn-primary { width: 100%; margin-top: 0.5rem; }

/* 登录错误提示 */
.auth-error {
  background: #fff0f0; color: #c00;
  font-size: 0.82rem; padding: 0.5rem 0.75rem;
  border-radius: var(--radius-xs);
  margin-bottom: 0.5rem;
}

/* 欢迎页登录状态 */
.welcome-auth { margin-top: 0.5rem; }
.welcome-user-info {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  margin-top: 0.75rem; font-size: 0.85rem;
}
.welcome-user-name { color: var(--gold-dark); font-weight: 500; }
.welcome-user-label {
  font-size: 0.72rem; color: var(--text-dim);
  background: var(--bg-card); padding: 2px 8px; border-radius: 10px;
}

/* ========== 桌面端扩展 ========== */
@media (min-width: 768px) {
  .sidebar { transform: translateX(0); }
  .sidebar-overlay { display: none; }
  .main-wrapper { margin-left: var(--sidebar-w); }
  .message-bubble { max-width: 65%; }
  .chat-messages { padding: 1.5rem 2rem; }
  .input-area { padding: 0.75rem 2rem; }
}
