/* 对话式智能体界面 */
:root {
  --primary: #1a365d;
  --primary-light: #2c5282;
  --accent: #667eea;
  --accent2: #764ba2;
  --bg: #f0f2f5;
  --sidebar-bg: #1a365d;
  --card: #ffffff;
  --text: #1a202c;
  --text-muted: #718096;
  --border: #e2e8f0;
  --user-bg: linear-gradient(135deg, #667eea, #764ba2);
  --bot-bg: #ffffff;
  --radius: 14px;
  --font-base: 20px;
}

html { font-size: var(--font-base); }

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  font-size: 1rem;
  line-height: 1.6;
}

.chat-app {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 300px;
  min-width: 300px;
  background: var(--sidebar-bg);
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.3s;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.35rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo { font-size: 2rem; }
.sidebar-header h2 { font-size: 1.25rem; font-weight: 600; white-space: nowrap; }

.status-card {
  margin: 1rem;
  padding: 1.1rem 1.15rem;
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius);
}
.status-label { font-size: 0.875rem; opacity: 0.75; margin-bottom: 0.4rem; white-space: nowrap; }
.status-phase { font-size: 1.15rem; font-weight: 600; color: #ffd700; white-space: nowrap; }
.status-value { font-size: 1rem; line-height: 1.5; word-break: break-word; }

.progress-wrap { margin-top: 0.85rem; }
.progress-bar {
  height: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.45rem;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #ffd700);
  width: 0%;
  transition: width 0.4s;
}
.progress-text { font-size: 0.875rem; opacity: 0.75; }

.sidebar-actions {
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  flex: 1;
}

.btn-action {
  padding: 0.85rem 1rem;
  border: none;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.btn-action:hover:not(:disabled) { opacity: 0.9; }
.btn-action:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-action.btn-ghost {
  background: rgba(255,255,255,0.1);
  color: white;
}

.sidebar-footer {
  padding: 1.1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: nowrap;
}
.ai-badge {
  font-size: 0.875rem;
  padding: 0.4rem 0.85rem;
  border-radius: 12px;
  background: rgba(255,255,255,0.15);
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1.2;
}
.ai-badge.active { background: linear-gradient(135deg, #667eea, #764ba2); }
.btn-link {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 0.95rem;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 0.25rem 0;
}
.btn-link:hover { color: white; }

/* ── 用户菜单 ──────────────────────────────── */
.user-menu {
  position: relative;
  flex: 1;
  min-width: 0;
}
.user-menu-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  padding: 0.35rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9rem;
  width: 100%;
  transition: background 0.2s;
}
.user-menu-btn:hover { background: rgba(255,255,255,0.2); }
.user-avatar { font-size: 1.1rem; flex-shrink: 0; }
.user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-align: left;
}
.user-arrow { font-size: 0.7rem; flex-shrink: 0; opacity: 0.6; }

.user-dropdown {
  display: none;
  position: absolute;
  bottom: 100%;
  left: 0;
  right: 0;
  margin-bottom: 0.4rem;
  background: white;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  overflow: hidden;
  z-index: 50;
  min-width: 160px;
}
.user-dropdown.show { display: block; }
.user-dropdown hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 0.25rem 0;
}
.dropdown-item {
  display: block;
  padding: 0.65rem 1rem;
  color: #1a202c;
  text-decoration: none;
  font-size: 0.95rem;
  transition: background 0.15s;
  white-space: nowrap;
}
.dropdown-item:hover { background: #f0f2f5; }

/* Main chat */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  padding: 1.25rem 2rem;
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
}
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}
.chat-header h1 { font-size: 1.65rem; color: var(--primary); font-weight: 700; }
.chat-header p { font-size: 1.05rem; color: var(--text-muted); margin-top: 0.25rem; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Message bubbles */
.msg {
  display: flex;
  gap: 0.85rem;
  max-width: 92%;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}
.msg.user .msg-avatar { background: var(--user-bg); }
.msg.assistant .msg-avatar { background: var(--primary); color: white; }

.msg-bubble {
  padding: 1rem 1.25rem;
  border-radius: 18px;
  line-height: 1.75;
  font-size: 1.125rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .msg-bubble {
  background: var(--user-bg);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.assistant .msg-bubble {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}

.msg.typing .msg-bubble {
  display: flex;
  gap: 4px;
  padding: 1rem 1.25rem;
}
.typing-dot {
  width: 8px; height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Template cards in chat */
.tpl-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.tpl-card {
  padding: 1rem 1.15rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
  background: #f7fafc;
}
.tpl-card:hover {
  border-color: var(--accent);
  background: #eef2ff;
}
.tpl-card h4 { font-size: 1.05rem; color: var(--primary); margin-bottom: 0.35rem; font-weight: 600; }
.tpl-card .meta { font-size: 0.925rem; color: var(--text-muted); }
.tpl-card .reason { font-size: 0.975rem; color: var(--accent); margin-top: 0.4rem; font-style: italic; }

.tpl-card.tpl-custom {
  border-color: #667eea;
  background: linear-gradient(135deg, #f0f4ff, #faf5ff);
}
.tpl-card.tpl-custom:hover {
  background: linear-gradient(135deg, #e0e7ff, #f3e8ff);
}
.tpl-card.tpl-custom h4 { color: #667eea; }

/* Quick suggestions */
.quick-suggestions {
  display: flex;
  gap: 0.65rem;
  padding: 0 2rem 0.75rem;
  overflow-x: auto;
  flex-shrink: 0;
}
.suggestion {
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: white;
  font-size: 0.975rem;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all 0.2s;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); background: #eef2ff; }

/* Input area */
.chat-input-area {
  padding: 1rem 2rem 1.25rem;
  background: white;
  border-top: 1px solid var(--border);
  position: relative;
  z-index: 10;
  flex-shrink: 0;
}
.chat-input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 0.75rem 1rem;
  min-height: 56px;
  transition: border-color 0.2s;
}
.chat-input-wrap:focus-within { border-color: var(--accent); }

#chatInput {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 1.125rem;
  font-family: inherit;
  line-height: 1.6;
  max-height: 160px;
  min-height: 28px;
  outline: none;
  padding: 0.25rem 0;
}

.input-btns { display: flex; gap: 0.35rem; align-items: center; }
.btn-icon {
  width: 44px; height: 44px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.35rem;
  transition: background 0.2s;
  flex-shrink: 0;
}
.btn-icon:hover { background: rgba(0,0,0,0.06); }
.btn-icon.listening { background: #fed7d7; animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,62,62,0.3); }
  50% { box-shadow: 0 0 0 6px rgba(229,62,62,0); }
}

.btn-send {
  width: 44px; height: 44px;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s;
  flex-shrink: 0;
  pointer-events: auto;
}
.btn-send svg { width: 22px; height: 22px; }
.btn-send:hover { opacity: 0.9; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.65rem;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: white;
  border-radius: var(--radius);
  width: 90%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal-lg { max-width: 720px; }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.2rem; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 1.75rem; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 1.35rem; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 0.85rem 1.35rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
}
.modal-label { display: block; font-weight: 600; margin-bottom: 0.5rem; font-size: 1rem; }
.modal-input {
  width: 100%;
  padding: 0.75rem 0.95rem;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-family: monospace;
  font-size: 1rem;
}
.hint { font-size: 0.975rem; color: var(--text-muted); margin-bottom: 0.85rem; line-height: 1.6; }
.key-status { font-size: 0.925rem; color: var(--text-muted); margin-top: 0.5rem; }

/* Profile form */
.form-row { display: flex; gap: 0.75rem; margin-bottom: 1rem; }
.form-group-inline { flex: 1; min-width: 0; }
.form-group-inline label { display: block; font-weight: 600; margin-bottom: 0.35rem; font-size: 0.95rem; }
.form-group-inline select.modal-input { cursor: pointer; }

/* Admin user list */
.admin-user-list { display: flex; flex-direction: column; gap: 0.5rem; }
.admin-user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f7fafc;
}
.admin-user-info { flex: 1; min-width: 0; }
.admin-user-info strong { color: var(--primary); }
.admin-user-info span { font-size: 0.85rem; color: var(--text-muted); display: block; }
.admin-user-actions { display: flex; gap: 0.35rem; flex-shrink: 0; }
.admin-user-actions button {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  background: white;
}
.admin-user-actions .btn-danger { color: #e53e3e; border-color: #e53e3e; }
.admin-user-actions .btn-danger:hover { background: #fff5f5; }

.preview-content {
  white-space: pre-wrap;
  font-family: "SimSun", serif;
  font-size: 1rem;
  line-height: 1.85;
}

.btn {
  padding: 0.65rem 1.35rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: white; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--primary); }

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--primary);
  color: white;
  padding: 0.85rem 1.5rem;
  border-radius: 10px;
  font-size: 1rem;
  opacity: 0;
  transition: all 0.3s;
  z-index: 2000;
  max-width: 90vw;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ── Markdown 渲染样式 ──────────────────────── */
.msg-bubble p {
  margin: 0.2em 0 0.5em;
}
.msg-bubble p:last-child {
  margin-bottom: 0;
}
.msg-bubble strong {
  color: #1a365d;
  font-weight: 700;
}
.msg-bubble code {
  background: #edf2f7;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.92em;
  color: #c7254e;
}
.msg-bubble a {
  color: #2c5282;
  text-decoration: underline;
}

/* ── 流式输出光标 ──────────────────────────── */
.msg-bubble.streaming {
  border-left: 2px solid var(--accent);
}
.cursor-blink {
  display: inline;
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
  font-weight: bold;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 大屏进一步放大 */
@media (min-width: 1600px) {
  :root { --font-base: 21px; }
}

/* Responsive */
@media (max-width: 768px) {
  html { font-size: 18px; }
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .msg { max-width: 95%; }
  .chat-messages,
  .quick-suggestions,
  .chat-input-area {
    padding-left: 1rem;
    padding-right: 1rem;
  }
}
