/* 童锦程式情感分析导师 —— 移动端暗色主题 */
:root {
  --bg: #0f0f0f;
  --bg-soft: #1a1a1a;
  --bg-card: #1e1e1e;
  --border: #2a2a2a;
  --text: #ececec;
  --text-dim: #9a9a9a;
  --gold: #e8c87a;
  --gold-dim: #b89a5e;
  --user-bubble: #2a3b4d;
  --bot-bubble: #262626;
  --danger: #e06c6c;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* 顶栏 */
.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 5;
}
.header-left { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--bg-soft);
}
.title-wrap { display: flex; flex-direction: column; line-height: 1.2; }
.title-wrap h1 { font-size: 16px; font-weight: 700; color: var(--gold); }
.subtitle { font-size: 11px; color: var(--text-dim); margin-top: 2px; }

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  padding: 6px; cursor: pointer; display: flex; align-items: center;
  border-radius: 8px;
}
.icon-btn:active { background: var(--bg-soft); }

/* 消息区 */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 欢迎页 */
.welcome {
  margin: auto;
  text-align: center;
  padding: 20px;
  max-width: 480px;
}
.welcome-icon {
  font-size: 18px;
  color: var(--gold);
  margin-bottom: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.welcome-text {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 22px;
}
.suggest { display: flex; flex-direction: column; gap: 10px; }
.chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color .15s, transform .1s;
}
.chip:active { transform: scale(0.98); border-color: var(--gold-dim); }

/* 消息气泡 */
.msg { display: flex; gap: 8px; max-width: 92%; animation: fade .25s ease; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.bot { align-self: flex-start; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg .bubble {
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 15px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user .bubble { background: var(--user-bubble); border-bottom-right-radius: 4px; color: #fff; }
.msg.bot .bubble { background: var(--bot-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.bot .bubble.streaming::after {
  content: '▌'; color: var(--gold); animation: blink 1s steps(2) infinite; margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }

.msg .avatar-mini {
  width: 26px; height: 26px; border-radius: 7px; flex: 0 0 26px; margin-top: 2px;
  font-size: 13px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.msg.bot .avatar-mini { background: var(--bg-card); color: var(--gold); border: 1px solid var(--border); }
.msg.user .avatar-mini { background: var(--user-bubble); color: #fff; }

.msg.error .bubble { background: #3a1f1f; border-color: var(--danger); color: #ffb3b3; }

/* 输入栏 */
.input-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(var(--safe-bottom) + 10px);
  background: var(--bg);
  border-top: 1px solid var(--border);
}
#input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 18px;
  padding: 11px 16px;
  font-size: 16px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}
#input:focus { outline: none; border-color: var(--gold-dim); }
.send-btn {
  flex: 0 0 auto;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--gold);
  color: #1a1a1a;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.send-btn:disabled { opacity: 0.4; }
.send-btn:active { transform: scale(0.92); }

/* 设置模态框 */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal-body {
  position: relative;
  width: 100%; max-width: 520px;
  background: var(--bg-soft);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(var(--safe-bottom) + 18px);
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h2 { font-size: 17px; color: var(--gold); }

.field { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text-dim); }
.field input, .field select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--gold-dim); }
.hint { font-size: 12px; color: var(--gold-dim); text-decoration: none; }

/* API 获取说明区 */
.provider-guide {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 16px;
}
.guide-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin-bottom: 10px;
}
.guide-title { font-size: 13px; color: var(--gold); font-weight: 600; }
.tag {
  font-size: 10px; padding: 2px 8px; border-radius: 10px;
  font-weight: 600; white-space: nowrap;
}
.tag-ok { background: #1e3a2a; color: #6ee7a8; }
.tag-warn { background: #3a2a1e; color: #e8b87a; }

.guide-steps { list-style: none; margin: 0 0 10px; padding: 0; }
.guide-steps li {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 13px; color: var(--text); margin-bottom: 6px; line-height: 1.4;
}
.step-num {
  flex: 0 0 18px; height: 18px; border-radius: 50%;
  background: var(--gold-dim); color: #1a1a1a;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}

.guide-meta { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--border); }
.guide-meta > div { display: flex; gap: 8px; font-size: 12px; }
.meta-label { flex: 0 0 56px; color: var(--text-dim); }
.meta-val { color: var(--text); flex: 1; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; }

/* 多 Key 管理 */
.key-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.key-list:empty::before {
  content: '还没有 Key，下面填一个加进来';
  display: block; padding: 10px; text-align: center;
  color: var(--text-dim); font-size: 12px;
  border: 1px dashed var(--border); border-radius: 8px;
}
.key-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.key-item.active { border-color: var(--gold-dim); }
.key-item .key-name {
  flex: 0 0 auto; font-size: 12px; color: var(--gold);
  font-weight: 600; max-width: 80px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.key-item .key-val {
  flex: 1; font-family: ui-monospace, monospace; font-size: 11px;
  color: var(--text-dim); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.key-item .key-del {
  flex: 0 0 auto; background: none; border: none; color: var(--text-dim);
  cursor: pointer; padding: 2px; border-radius: 4px;
}
.key-item .key-del:active { color: var(--danger); }

.key-add-row { display: flex; gap: 6px; margin-bottom: 6px; }
.key-add-row input {
  background: var(--bg-card); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 9px 10px; font-size: 13px; font-family: inherit;
}
.key-add-row input:focus { outline: none; border-color: var(--gold-dim); }
#newKeyName { flex: 0 0 90px; }
#newKeyVal { flex: 1; min-width: 0; }
.add-key-btn {
  flex: 0 0 auto; background: var(--gold-dim); color: #1a1a1a; border: none;
  padding: 0 14px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.add-key-btn:active { opacity: 0.8; }
.hint-tip { color: var(--text-dim); margin-top: 4px; }
.field-row { display: flex; gap: 10px; margin-top: 8px; }
.ghost-btn {
  flex: 1; background: transparent; border: 1px solid var(--border); color: var(--text-dim);
  padding: 11px; border-radius: 10px; font-size: 14px; cursor: pointer;
}
.primary-btn {
  flex: 1.4; background: var(--gold); border: none; color: #1a1a1a;
  padding: 11px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.ghost-btn:active, .primary-btn:active { opacity: 0.85; }
.footnote { font-size: 11px; color: var(--text-dim); margin-top: 14px; line-height: 1.5; }

/* 滚动条 */
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* 大屏适配 */
@media (min-width: 600px) {
  .messages { padding-left: 20px; padding-right: 20px; }
  .msg { max-width: 75%; }
}
