/* ============================================================
   犯罪学智能助手 —— 全局样式
   风格：简洁 / 专业 / 学术 / 手机优先，避免花哨动画
   ============================================================ */

:root {
  --primary: #1f4e79;        /* 学术深蓝 */
  --primary-dark: #16395a;
  --primary-light: #e8eff7;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a2330;
  --text-muted: #6b7785;
  --border: #e3e8ef;
  --user-bubble: #1f4e79;
  --user-text: #ffffff;
  --danger: #b3261e;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* 视图切换 */
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.hidden { display: none !important; }

/* ============ 口令门禁 ============ */
#gate-view {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 6px 24px rgba(20, 40, 70, 0.06);
  text-align: center;
}

.gate-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
}

.gate-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.gate-label {
  display: block;
  text-align: left;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
}

.text-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s;
  background: #fff;
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(31, 78, 121, 0.12);
}

.error-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin: 8px 0 4px;
  text-align: left;
}

/* ============ 聊天主视图 ============ */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 10px;
  flex-shrink: 0;
}

.header-main {
  text-align: center;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--primary);
}

.header-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
}

/* 快捷入口 */
.quick-bar {
  display: flex;
  gap: 8px;
  padding: 12px 12px 4px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}

.quick-btn {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 8px 14px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--primary);
  cursor: pointer;
}

.quick-btn:active {
  background: var(--primary-light);
}

/* 消息区 */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 20px;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.msg-row {
  display: flex;
  margin-bottom: 14px;
}

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

.msg-bubble {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 15px;
  line-height: 1.65;
}

.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.msg-row.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.msg-row.error .msg-bubble {
  background: #fdf2f2;
  border-color: #f0c4c4;
  color: var(--danger);
  font-size: 14px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
  opacity: 0.85;
}

/* “正在思考”加载指示 */
.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 2px;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  background: var(--primary);
  border-radius: 50%;
  animation: blink 1.2s infinite ease-in-out;
}

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

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

/* 输入栏（固定底部，通过 flex 布局避免顶乱页面） */
.input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.input-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.chat-textarea {
  width: 100%;
  display: block;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  line-height: 1.5;
  max-height: 120px;
  outline: none;
  background: #fff;
}

.char-count {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  line-height: 1;
  min-height: 0;
}

.char-count.near-limit {
  color: var(--danger);
}

.chat-textarea:focus {
  border-color: var(--primary);
}

/* 按钮 */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-primary:active { background: var(--primary-dark); }
.btn-primary:disabled { background: #a9bccd; cursor: not-allowed; }

.btn-block { width: 100%; margin-top: 12px; }

.btn-secondary {
  background: #eef1f5;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}

.btn-ghost:active { background: var(--primary-light); }

/* ============ 附件 ============ */
.btn-attach {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-attach:active { background: var(--primary-light); }

.attachment-list {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 12px 0;
}

.attach-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 10px;
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
}

.attach-card.attach-error {
  background: #fdf2f2;
  border-color: #f0c4c4;
}

.attach-name {
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attach-meta {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.attach-remove {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}

.attach-remove:active { color: var(--danger); }

/* ============ 隐私提示（小字） ============ */
.privacy-footer {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
  padding: 12px 16px;
}

#gate-view .privacy-footer {
  margin-top: 24px;
  padding: 0 8px;
}

/* ============ Markdown 内容样式（AI 回答） ============ */
.msg-content h1, .msg-content h2, .msg-content h3,
.msg-content h4, .msg-content h5, .msg-content h6 {
  margin: 0.6em 0 0.4em;
  font-weight: 600;
  line-height: 1.4;
}

.msg-content h1 { font-size: 1.3em; }
.msg-content h2 { font-size: 1.2em; }
.msg-content h3 { font-size: 1.1em; }
.msg-content h4, .msg-content h5, .msg-content h6 { font-size: 1em; }

.msg-content p { margin: 0.4em 0; }

.msg-content ul, .msg-content ol {
  margin: 0.4em 0;
  padding-left: 1.4em;
}

.msg-content li { margin: 0.15em 0; }

.msg-content blockquote {
  border-left: 3px solid var(--primary);
  background: var(--primary-light);
  padding: 6px 12px;
  margin: 0.5em 0;
  color: #3a4a5c;
  border-radius: 0 6px 6px 0;
}

.msg-content code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
  background: #eef1f5;
  padding: 1px 5px;
  border-radius: 4px;
}

.msg-content pre {
  background: #1a2330;
  color: #e6edf3;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
}

.msg-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.msg-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 0.6em 0;
  font-size: 0.92em;
}

.msg-content th, .msg-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.msg-content th { background: var(--primary-light); }

.msg-content a { color: var(--primary); text-decoration: underline; }

.msg-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.8em 0;
}

.msg-content img { max-width: 100%; height: auto; border-radius: 6px; }

/* 桌面端适当收窄，避免过宽 */
@media (min-width: 768px) {
  #chat-view, #gate-view {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
  }
  .msg-bubble { max-width: 70%; }
}
