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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: #f5f6f8;
  overflow: hidden;
}

.chat-app {
  max-width: 640px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #fff;
}

/* ========== Header ========== */
.chat-header {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}
.back-btn {
  color: #888;
  text-decoration: none;
  font-size: 16px;
  padding: 4px 8px;
  margin-right: 8px;
}
.back-btn:hover { color: #555; }
.header-title { flex: 1; }
.header-name { font-size: 17px; font-weight: 600; color: #1a1a2e; }
.header-status { font-size: 12px; color: #888; margin-top: 1px; }

/* ========== Chat body ========== */
.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  -webkit-overflow-scrolling: touch;
  background: #f9fafb;
}

/* Messages */
.msg-row {
  display: flex;
  align-items: flex-start;
  margin-bottom: 14px;
  animation: fadeIn 0.25s ease;
}
.msg-row.user { justify-content: flex-end; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: #eee;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #888;
  flex-shrink: 0;
}
.user-avatar { background: #dbeafe; margin-left: 8px; color: #2563eb; }

.msg-bubble {
  max-width: 78%;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
}
.system-bubble {
  background: #fff;
  margin-left: 8px;
  color: #333;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.user-bubble {
  background: #eff6ff;
  margin-right: 8px;
  color: #333;
}

/* Question list */
.question-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.q-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: #f9fafb;
  border: 1px solid #eee;
  border-radius: 6px;
  font-size: 14px;
  color: #2563eb;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1.5;
}
.q-btn:hover { background: #eff6ff; }

/* Attachment */
.attachment-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 10px 12px;
  background: #f9fafb;
  border-radius: 6px;
  border: 1px solid #eee;
}
.attachment-name {
  flex: 1;
  font-size: 13px; color: #333; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.attachment-type { font-size: 11px; color: #bbb; flex-shrink: 0; }
.attachment-download {
  padding: 5px 12px;
  background: #2563eb;
  color: #fff;
  text-decoration: none;
  border-radius: 4px;
  font-size: 12px;
  white-space: nowrap;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
}
.attachment-download:hover { background: #1d4ed8; }

/* Footer */
.chat-footer {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid #eee;
  padding: 10px 14px 14px;
}
.footer-label { font-size: 13px; color: #aaa; margin-bottom: 8px; }

.keyword-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.kw-btn {
  padding: 8px 16px;
  background: #f5f6f8;
  border: 1px solid #e5e5e5;
  border-radius: 6px;
  font-size: 14px;
  color: #555;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.kw-btn:hover {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

/* Mobile */
@media (max-width: 640px) {
  .chat-app { max-width: 100%; }
  .msg-bubble { max-width: 84%; }
  .chat-footer {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
    max-height: 36vh;
    overflow-y: auto;
  }
  .kw-btn { font-size: 13px; padding: 7px 14px; }
}
