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

html, body {
  height: 100%;
}

body {
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: #fff;
  color: #222;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
}

.hidden {
  display: none !important;
}

/* ---------- 顶栏 ---------- */

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

#title {
  font-size: 17px;
  font-weight: 600;
}

#model {
  font-size: 14px;
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
}

/* ---------- 消息流 ---------- */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  display: flex;
}

.bubble .content {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble.user {
  justify-content: flex-end;
}

.bubble.user .content {
  background: #2f7cf6;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.assistant .content {
  background: #f3f4f6;
  color: #222;
  border-bottom-left-radius: 4px;
}

.bubble.error .content {
  background: #fdecea;
  color: #c0392b;
  border: 1px solid #f5c6c0;
  border-bottom-left-radius: 4px;
}

.thumb {
  max-width: 200px;
  max-height: 200px;
  border-radius: 10px;
  display: block;
  margin-bottom: 6px;
}

/* ---------- 记录卡片 / 确认卡片 ---------- */

.record-card {
  font-weight: 500;
}

.confirm-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 260px;
}

.confirm-tip {
  font-size: 13px;
  color: #666;
}

.confirm-card label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.confirm-card label span {
  width: 40px;
  color: #666;
  flex-shrink: 0;
}

.confirm-card input,
.confirm-card select {
  flex: 1;
  font-size: 14px;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  min-width: 0;
}

.amount-input {
  background: #fff8e1 !important;
  border-color: #f0c36d !important;
  font-weight: 600;
}

.confirm-btn {
  margin-top: 4px;
  padding: 9px;
  font-size: 15px;
  color: #fff;
  background: #2f7cf6;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}

.confirm-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.confirm-error {
  font-size: 13px;
  color: #c0392b;
}

/* ---------- 输入区 ---------- */

#inputbar {
  border-top: 1px solid #eee;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

#inputrow {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

#input {
  flex: 1;
  resize: none;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  padding: 9px 12px;
  border: 1px solid #ddd;
  border-radius: 18px;
  outline: none;
  max-height: 120px;
}

#input:focus {
  border-color: #2f7cf6;
}

#imgbtn,
#sendbtn {
  flex-shrink: 0;
  font-size: 14px;
  padding: 9px 14px;
  border-radius: 18px;
  border: 1px solid #ddd;
  background: #fff;
  cursor: pointer;
}

#sendbtn {
  background: #2f7cf6;
  border-color: #2f7cf6;
  color: #fff;
}

#sendbtn:disabled {
  opacity: 0.5;
  cursor: default;
}

#preview {
  position: relative;
  display: inline-block;
  margin-bottom: 8px;
}

#preview-img {
  max-width: 96px;
  max-height: 96px;
  border-radius: 10px;
  border: 1px solid #eee;
  display: block;
}

#preview-remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- Token 输入层 ---------- */

#token-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

#token-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(320px, 86vw);
  text-align: center;
}

#token-input {
  font-size: 15px;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 10px;
  outline: none;
}

#token-input:focus {
  border-color: #2f7cf6;
}

#token-submit {
  font-size: 15px;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: #2f7cf6;
  color: #fff;
  cursor: pointer;
}

#token-error {
  font-size: 13px;
  color: #c0392b;
}

/* ---------- 移动端 ---------- */

@media (max-width: 480px) {
  .bubble .content {
    max-width: 88%;
  }

  .confirm-card {
    min-width: 0;
    width: 100%;
  }
}
