* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #0f1116;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #8b93a3;
  --accent: #4f8cff;
  --warn: #f0a24b;
  --danger: #ff5c6c;
  --user: #24304a;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow-x: hidden;
  max-width: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC", sans-serif;
}

#app {
  height: 100dvh;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
}
button:active {
  transform: translateY(1px);
}
button:disabled {
  opacity: 0.5;
}

input,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}
input:focus,
textarea:focus {
  border-color: var(--accent);
}

.login {
  max-width: 360px;
  margin: 18vh auto 0;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login h1 {
  margin: 0 0 4px;
  font-size: 24px;
}
.login p {
  margin: 0;
  color: var(--muted);
}
.msg {
  color: var(--danger);
  min-height: 20px;
  font-size: 13px;
}

.app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#ftrWrap {
  display: contents;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
header .left {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
header .right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
header .title {
  font-weight: 600;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
header .icon {
  padding: 6px 8px;
  min-width: 34px;
}
/* 会话内返回键上的"外面待处理/未读"角标 */
header #backBtn {
  position: relative;
}
header #backBadge {
  position: absolute;
  top: -4px;
  right: -6px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  font-size: 10px;
  line-height: 16px;
  color: #fff;
  display: none;
  align-items: center;
  justify-content: center;
}
header #backBadge.alert {
  background: #fa5151;
}
header #backBadge.done {
  background: #1aad19;
}
header .warn {
  color: #111;
  background: var(--warn);
  border-color: transparent;
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  display: inline-block;
}
.dot.on {
  background: #35d07f;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}
.card:active {
  background: var(--panel-2);
}
.card .avatar {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 19px;
}
.card .ct {
  flex: 1 1 auto;
  min-width: 0;
}
.card .t {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .m {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
}
.card .m .proj {
  color: var(--accent);
}
.card .m .busy-dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #35d07f;
}
.card .cr {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
}
.card .cr .idx {
  color: var(--muted);
  font-size: 11px;
}
.card .unread {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #fa5151;
  color: #fff;
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* 任务停下/出错的未读标记(点进会话即清除) */
.card .unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #1aad19;
}
.card .unread-dot.error {
  background: #fa9d3b;
}
.badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.badge.busy {
  color: #111;
  background: #35d07f;
  border-color: transparent;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 14px;
  word-break: break-word;
  border: 1px solid var(--line);
  background: var(--panel);
}
.bubble .txt {
  white-space: normal;
}
.bubble .txt .p {
  white-space: pre-wrap;
}
.bubble .txt ul,
.bubble .txt ol {
  margin: 4px 0;
  padding-left: 20px;
}
.bubble .txt li {
  white-space: pre-wrap;
}
.bubble .txt .md-h {
  font-weight: 600;
  margin: 6px 0 2px;
}
.bubble .txt code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 0.92em;
}
.bubble .txt pre.code {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-x: auto;
  margin: 6px 0;
}
.bubble .txt pre.code code {
  background: none;
  padding: 0;
}
.bubble .txt blockquote {
  border-left: 3px solid var(--line);
  margin: 6px 0;
  padding-left: 8px;
  color: var(--muted);
}
.bubble .txt a {
  color: var(--accent);
}
.bubble .txt hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 8px 0;
}
.bubble .txt .md-table-wrap {
  overflow-x: auto;
  margin: 6px 0;
}
.bubble .txt .md-table {
  border-collapse: collapse;
  font-size: 12px;
}
.bubble .txt .md-table th,
.bubble .txt .md-table td {
  border: 1px solid var(--line);
  padding: 3px 7px;
  white-space: nowrap;
}
.bubble .txt .md-table th {
  background: var(--panel-2);
  font-weight: 600;
}
.bubble.user {
  align-self: flex-end;
  background: var(--user);
  border-color: transparent;
}
.bubble.assistant {
  align-self: flex-start;
}
.bubble .role {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.bubble .txt + .txt {
  margin-top: 8px;
}
.bubble .txt .p + .p,
.bubble .txt .p + ul,
.bubble .txt .p + ol,
.bubble .txt ul + .p,
.bubble .txt ol + .p,
.bubble .txt .p + pre.code,
.bubble .txt pre.code + .p,
.bubble .txt .p + .md-h {
  margin-top: 8px;
}
.bubble .tools {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 4px 0;
}
.bubble .tools:first-child {
  margin-top: 0;
}
.bubble .tools:last-child {
  margin-bottom: 0;
}
.tool-chip {
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  white-space: nowrap;
}
button.more {
  display: block;
  margin: 0 auto 10px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
}
.empty {
  color: var(--muted);
  text-align: center;
  margin-top: 20vh;
}
.thinking {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  padding: 8px 12px 4px;
}
.thinking[hidden] {
  display: none;
}
.thinking .tdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: tdot 1.2s infinite ease-in-out both;
}
.thinking .tdot:nth-child(2) {
  animation-delay: 0.15s;
}
.thinking .tdot:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes tdot {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-2px);
  }
}
.ctx-badge {
  font-size: 11px;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 24px;
}
.overlay[hidden] {
  display: none;
}
.sheet {
  width: 100%;
  max-width: 420px;
  min-width: 0;
  box-sizing: border-box;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.sheet-title {
  font-weight: 600;
  margin-bottom: 10px;
}
.sheet .row {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 10px;
  font-size: 13px;
  padding: 5px 0;
  color: var(--muted);
}
.sheet .row span:first-child {
  white-space: nowrap;
}
.sheet .row span.v {
  color: var(--text);
  text-align: right;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.sheet .hint {
  color: var(--muted);
  font-size: 12px;
  padding: 2px 0 0;
}
.sheet .sect {
  color: var(--muted);
  font-size: 12px;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}
.ctxbar {
  height: 6px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  overflow: hidden;
  margin: 8px 0;
}
.ctxfill {
  height: 100%;
  background: var(--accent);
}
.sheet-close {
  margin-top: 12px;
  text-align: center;
  padding: 8px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  cursor: pointer;
}

footer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
footer textarea {
  resize: none;
  height: 44px;
  max-height: 120px;
}
footer button {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  padding: 0 18px;
}

.pending-badge {
  color: #111;
  background: var(--warn);
  border-color: transparent;
  font-weight: 600;
}

.pending-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.pending {
  border-radius: 14px;
  padding: 12px;
  border: 1px solid var(--warn);
  background: linear-gradient(180deg, rgba(240, 162, 75, 0.12), rgba(240, 162, 75, 0.04));
}
.pending.question {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(79, 140, 255, 0.12), rgba(79, 140, 255, 0.04));
}

.p-title {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.p-icon {
  font-size: 16px;
}
.p-title code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 13px;
}

.p-body {
  font-size: 14px;
  margin-bottom: 10px;
  word-break: break-word;
}
.p-body code {
  background: rgba(0, 0, 0, 0.25);
  padding: 1px 6px;
  border-radius: 6px;
  font-size: 12px;
}

.p-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.p-actions button {
  flex: 1;
  min-width: 84px;
}
.p-actions button.ok {
  background: #1f5f3f;
  border-color: transparent;
}
.p-actions button.no {
  background: #5f2530;
  border-color: transparent;
}

.q-item + .q-item {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.q-head {
  font-size: 12px;
  color: var(--muted);
  text-transform: none;
}
.q-multi {
  color: var(--accent);
  margin-left: 6px;
}
.q-text {
  font-weight: 600;
  margin: 4px 0 8px;
}
.opts {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.opt {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
}
.opt input {
  width: auto;
  margin-top: 3px;
}
.opt-body {
  display: flex;
  flex-direction: column;
}
.opt-label {
  font-size: 14px;
}
.opt-desc {
  font-size: 12px;
  color: var(--muted);
}
.custom-input {
  margin-top: 8px;
}
/* 选项选中态 + 提交按钮高亮 */
.opt.sel {
  border-color: var(--accent);
  background: rgba(88, 140, 255, 0.16);
}
.opt.sel .opt-label {
  font-weight: 600;
}
.pending.question .p-actions button.ok {
  opacity: 0.55;
}
.pending.question .p-actions button.ok.ready {
  opacity: 1;
  background: #1fbf6b;
  color: #04170c;
  font-weight: 600;
}
.q-hint {
  display: none;
  color: #ffb4a2;
  font-size: 12px;
  margin-top: 8px;
}
.q-hint.show {
  display: block;
}


.bubble.pending{opacity:.5}
.send-err{color:#ff6b6b;font-size:12px;text-align:center;padding:6px 12px 0}

/* 会话列表: 正在跑任务时的转圈 */
.card .m .spin {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 2px solid rgba(53, 208, 127, 0.25);
  border-top-color: #35d07f;
  margin-right: 4px;
  vertical-align: -1px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
/* 会话内: 一键到底 */
.to-bottom {
  position: fixed;
  right: 14px;
  bottom: 124px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(40, 44, 54, 0.94);
  color: #e8eaed;
  border: 1px solid var(--line);
  font-size: 20px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 30;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
.to-bottom:active {
  transform: scale(0.94);
}
footer button.stop {
  background: var(--warn);
  color: #111;
}
/* 会话列表下拉刷新: 跟手位移 + 上方转圈 */
#main.pull-anim {
  transition: transform 0.22s ease-out;
}
.pull-spin {
  position: fixed;
  top: 52px;
  left: 50%;
  margin-left: -13px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid rgba(120, 130, 150, 0.35);
  border-top-color: var(--accent);
  z-index: 45;
}
.pull-spin[hidden] {
  display: none;
}
.pull-spin.spinning {
  animation: spin 0.8s linear infinite;
}
.pull-text {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  color: #9aa3b2;
  font-size: 12px;
  z-index: 45;
}
.pull-text[hidden] {
  display: none;
}
