/* ============================================================
   语崽 · 网页版客户端（M1）
   浅色主题 / 立体质感（柔和阴影 + 毛玻璃顶栏 + 高反差渐变主按钮）/
   移动端自适应 / 零外部资源
   ============================================================ */

:root {
  /* 品牌主色：靛蓝→紫渐变（高反差主按钮） */
  --brand: #4f46e5;
  --brand-strong: #4338ca;
  --brand-2: #7c3aed;
  --brand-2-strong: #6d28d9;
  --brand-tint: #eef2ff;       /* 用户气泡浅底 */
  --brand-ink: #312e81;        /* 浅底上的文字色 */
  --ink: #1f2937;
  --ink-sub: #6b7280;
  --ink-faint: #9ca3af;
  --line: #e5e7eb;
  --surface: #ffffff;
  --danger: #dc2626;
  --danger-line: #fca5a5;
  --warn: #d97706;
  /* 统一阴影层级：s=控件 / m=卡片 / l=浮层弹窗 */
  --shadow-s: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-m: 0 1px 2px rgba(16, 24, 40, .05), 0 10px 28px -12px rgba(16, 24, 40, .16);
  --shadow-l: 0 24px 64px -16px rgba(15, 23, 42, .28);
  --shadow-brand: 0 1px 2px rgba(79, 70, 229, .32), 0 6px 16px -4px rgba(79, 70, 229, .38);
  --shadow-brand-hover: 0 2px 4px rgba(79, 70, 229, .32), 0 12px 26px -6px rgba(79, 70, 229, .46);
  --ease: 160ms ease;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  /* 页面背景：浅灰微渐变，衬托浮起卡片 */
  background: linear-gradient(180deg, #f6f7fb 0%, #edeff5 100%) fixed;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ---------- 可访问性细节：选中色 / 焦点环 / 滚动条 ---------- */

::selection { background: rgba(79, 70, 229, .18); }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

* { scrollbar-width: thin; scrollbar-color: #c6cad6 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c6cad6; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #a9adbd; }

/* ---------- 通用控件 ---------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 16px;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  background: var(--surface);
  color: #374151;
  box-shadow: var(--shadow-s);
  transition: background var(--ease), border-color var(--ease), color var(--ease),
    box-shadow var(--ease), transform var(--ease), opacity var(--ease);
}
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* 主按钮：高反差靛蓝紫渐变；hover 加深 + 微抬升，active 回落 */
.btn.primary {
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.btn.primary:not(:disabled):hover {
  background: linear-gradient(135deg, var(--brand-strong), var(--brand-2-strong));
  box-shadow: var(--shadow-brand-hover);
  transform: translateY(-1px);
}
.btn.primary:not(:disabled):active {
  transform: translateY(0);
  box-shadow: var(--shadow-brand);
}

/* 次要按钮：中性描边 */
.btn.ghost { border-color: var(--line); background: var(--surface); }
.btn.ghost:not(:disabled):hover { background: #f9fafb; border-color: #d1d5db; }
.btn.block { width: 100%; }

/* 圆形图标按钮（添加图片等） */
.btn.icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--line);
  color: var(--ink-sub);
  background: var(--surface);
  flex: none;
}
.btn.icon-btn:not(:disabled):hover {
  color: var(--brand);
  border-color: #c7d2fe;
  background: var(--brand-tint);
  transform: translateY(-1px);
  box-shadow: var(--shadow-m);
}
.btn.icon-btn:not(:disabled):active { transform: translateY(0); box-shadow: var(--shadow-s); }

input[type="text"], input[type="tel"], textarea, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 9px 12px;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
}
input[type="text"]:focus, input[type="tel"]:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .14);
}

/* ---------- 登录视图 ---------- */

.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid rgba(229, 231, 235, .8);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: var(--shadow-l);
}
.brand {
  margin: 0;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: 2px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand.small { font-size: 20px; }
.tagline { margin: 8px 0 24px; color: var(--ink-sub); font-size: 14px; }
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; color: var(--ink-sub); margin-bottom: 6px; }
.field input { width: 100%; }
.device-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: #374151;
  background: #f9fafb;
  border: 1px dashed #d1d5db;
  border-radius: 8px;
  padding: 7px 10px;
  display: inline-block;
}
.advanced { margin-bottom: 16px; font-size: 13px; color: var(--ink-sub); }
.advanced summary { cursor: pointer; }
.advanced .field { margin-top: 10px; }
.form-error { color: var(--danger); font-size: 13px; margin: 0 0 14px; }

/* 登录方式确认中（/v1/config 在途） */
.login-loading { margin: 0 0 16px; font-size: 14px; color: var(--ink-faint); text-align: center; }

/* config 拉取失败提示：警示色系（对齐 quota-warning-text），右侧重试按钮 */
.config-hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 16px;
  padding: 8px 12px;
  font-size: 13px;
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
}
.config-hint .btn { flex: none; padding: 3px 12px; font-size: 12.5px; }

/* 验证码行：输入框 + 获取验证码按钮（倒计时中按钮禁用，宽度不被挤压） */
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; }
#sendCodeBtn { flex: none; white-space: nowrap; }

/* 发送成功提示行（验证码有效期等） */
.form-hint { margin: -8px 0 14px; font-size: 12.5px; color: var(--ink-sub); }

/* ---------- 聊天视图 ---------- */

.chat-view {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* 顶栏：毛玻璃 + 底部细阴影分隔 */
.chat-header {
  flex: none;
  position: relative;
  z-index: 5;
  background: rgba(255, 255, 255, .72);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  box-shadow: 0 1px 0 rgba(15, 23, 42, .06), 0 8px 20px -14px rgba(15, 23, 42, .18);
}
.chat-header-inner {
  max-width: 820px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.header-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.control { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; }
.control select { padding: 6px 8px; font-size: 13px; }
.control.checkbox { cursor: pointer; user-select: none; }
.header-controls .btn { padding: 6px 12px; font-size: 13px; }

.msg-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
}
.msg-list > * { max-width: 820px; margin-left: auto; margin-right: auto; }

.empty-hint {
  text-align: center;
  color: var(--ink-faint);
  padding: 60px 0 20px;
  font-size: 15px;
  line-height: 1.8;
}

.msg { display: flex; margin-bottom: 14px; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-m);
}
/* 用户气泡：主色浅底 + 轻阴影 */
.msg.user .bubble {
  background: var(--brand-tint);
  color: var(--brand-ink);
  border: 1px solid #e0e7ff;
  border-bottom-right-radius: 4px;
}
/* 助手气泡：白底 + 轻阴影 */
.msg.assistant .bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

/* 用户消息里的图片：多图横排 */
.msg-images { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg-image {
  display: block;
  max-width: 200px;
  max-height: 200px;
  border-radius: 10px;
  border: 1px solid rgba(49, 46, 129, .12);
  object-fit: cover;
  background: #fff;
}

.engine-notice {
  display: inline-block;
  font-size: 12px;
  color: #92400e;
  background: #fef3c7;
  border-radius: 999px;
  padding: 2px 10px;
  margin-bottom: 6px;
}
.bubble .text { white-space: pre-wrap; }
.bubble .text.streaming::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  margin-left: 2px;
  background: var(--brand);
  vertical-align: -0.15em;
  animation: yuzai-blink 1s steps(1) infinite;
}
@keyframes yuzai-blink { 50% { opacity: 0; } }

.meta-line { margin-top: 6px; font-size: 12px; color: var(--ink-faint); }
.meta-line[data-kind="error"] { color: var(--danger); }
.meta-line[data-kind="warn"] { color: var(--warn); }

/* ---------- 输入区（卡片化 + 拖放区） ---------- */

.chat-footer {
  flex: none;
  position: relative; /* 拖放提示 ::after 定位基准 */
  padding: 0 16px calc(14px + env(safe-area-inset-bottom));
}
.input-card {
  max-width: 820px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-m);
  padding: 8px 10px;
  transition: border-color var(--ease), box-shadow var(--ease);
}
/* 聚焦时整卡主色描边 + 微光晕 */
.input-card:focus-within {
  border-color: var(--brand);
  box-shadow: var(--shadow-m), 0 0 0 4px rgba(79, 70, 229, .12);
}
.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#msgInput {
  flex: 1;
  resize: none;
  max-height: 160px;
  line-height: 1.5;
  border: none;
  background: transparent;
  padding: 9px 4px;
}
/* 焦点光晕由 .input-card:focus-within 承担，文本框自身不再描边 */
#msgInput:focus { border: none; box-shadow: none; }

/* 发送按钮：圆形主色 */
#sendBtn {
  flex: none;
  width: 46px;
  height: 46px;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
/* 停止态：红系描边 */
#sendBtn.stopping {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger-line);
  box-shadow: var(--shadow-s);
}
#sendBtn.stopping:not(:disabled):hover {
  background: #fef2f2;
  border-color: var(--danger);
  transform: translateY(-1px);
  box-shadow: var(--shadow-m);
}

/* 输入提示行（图片校验拒绝等人话） */
.input-hint {
  margin: 0;
  padding: 2px 6px 8px;
  font-size: 12.5px;
  color: #b45309;
}

/* 待发图片预览条 */
.preview-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 4px 4px 8px;
}
.preview-item { position: relative; flex: none; }
.preview-thumb {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 12px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow-s);
  background: #fff;
}
.preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-sub);
  font-size: 11px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-s);
  transition: color var(--ease), border-color var(--ease);
}
.preview-remove:hover { color: var(--danger); border-color: var(--danger-line); }
.preview-clear {
  align-self: center;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--ink-sub);
  cursor: pointer;
  box-shadow: var(--shadow-s);
  transition: color var(--ease), border-color var(--ease), background var(--ease);
}
.preview-clear:hover { color: var(--danger); border-color: var(--danger-line); background: #fef2f2; }

/* 拖放高亮：虚线框 + 「松开添加图片」遮罩提示 */
.chat-footer.drag-over .input-card {
  border-color: var(--brand);
  outline: 2px dashed rgba(79, 70, 229, .55);
  outline-offset: 3px;
}
.chat-footer.drag-over::after {
  content: '松开添加图片';
  position: absolute;
  inset: 0 16px calc(14px + env(safe-area-inset-bottom));
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  background: rgba(238, 242, 255, .9);
  color: var(--brand);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 1px;
  pointer-events: none; /* 不挡 drop 事件 */
  z-index: 2;
}

/* ---------- 全自动流水线 ---------- */

.pipeline-toggle { font-weight: 600; color: var(--brand); }
.control select:disabled { opacity: .55; cursor: not-allowed; }

/* 卡片序列消息：不用气泡，整栏宽纵向排列 */
.msg.pipeline { display: block; }
.pipeline-cards { width: 100%; display: flex; flex-direction: column; gap: 10px; }

/* 流水线卡片：与气泡/弹窗统一阴影层级 */
.pipeline-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: var(--shadow-m);
}
.pipeline-card[data-status="running"] {
  border-color: #c7d2fe;
  animation: yuzai-breathe 2s ease-in-out infinite; /* 呼吸：进行中卡片 */
}
@keyframes yuzai-breathe { 50% { box-shadow: var(--shadow-m), 0 0 0 4px rgba(79, 70, 229, .1); } }

.pipeline-card-head { display: flex; align-items: center; gap: 8px; }
.pipeline-status {
  flex: none;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  color: var(--ink-faint);
}
.pipeline-card[data-status="running"] .pipeline-status {
  border: 2px solid #c7d2fe;
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: yuzai-spin .8s linear infinite; /* 转动：进行中状态圈 */
}
@keyframes yuzai-spin { to { transform: rotate(360deg); } }
.pipeline-card[data-status="ok"] .pipeline-status { color: #16a34a; }
.pipeline-card[data-status="failed"] .pipeline-status { color: var(--danger); }

/* 活体状态条（G38/8G）：唯一数据源是 StageMachine 视图，点态与 MASCOT_VIEW.dot 对齐 */
.liveness-strip { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 13px; color: var(--ink-faint); }
.liveness-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; box-sizing: border-box; }
.liveness-dot.none { display: none; }
.liveness-dot.hollow { border: 2px solid #cbd5e1; background: transparent; }
.liveness-dot.breath { background: var(--brand); animation: yuzai-dot-breathe 1.6s ease-in-out infinite; }
.liveness-dot.gray { background: #94a3b8; }
.liveness-dot.red { background: var(--danger); }
.liveness-dot.solid { background: var(--brand); }
@keyframes yuzai-dot-breathe { 50% { opacity: .35; } }

.pipeline-card-title { font-weight: 600; font-size: 14px; }
.pipeline-card-points { margin-left: auto; font-size: 12px; color: var(--ink-faint); }
.pipeline-card-content {
  margin-top: 8px;
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px; /* 长蓝图/代码不撑爆时间线，卡片内滚动 */
  overflow-y: auto;
}

@media (prefers-reduced-motion: reduce) {
  .pipeline-card[data-status="running"],
  .pipeline-card[data-status="running"] .pipeline-status { animation: none; }
  * { transition-duration: .01ms !important; }
}

/* ---------- 用量弹窗 ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 10;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: var(--shadow-l);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 17px; }

/* ---- 生成页面预览弹窗 ---- */
.preview-card {
  max-width: 960px;
  height: min(86vh, 860px);
  display: flex;
  flex-direction: column;
  padding: 18px 20px;
}
.preview-actions { display: flex; gap: 8px; align-items: center; }
.preview-notice {
  flex: 1;
  margin-left: 10px;
  font-size: 12px;
  color: var(--ink-sub, #6b7280);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-link-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px; padding: 8px 12px;
  background: var(--bg-soft, #f3f4f6); border-radius: 10px; font-size: 13px;
}
.preview-link { flex: 1; word-break: break-all; color: var(--primary, #4f46e5); }
.preview-frame {
  flex: 1;
  width: 100%;
  border: 1px solid var(--line, #e5e7eb);
  border-radius: 12px;
  background: #fff;
}
.preview-open-btn {
  margin-top: 8px;
  padding: 4px 12px;
  font-size: 13px;
  align-self: flex-start;
}
.pipeline-card-head .preview-open-btn { margin-top: 0; margin-left: auto; }
@media (max-width: 640px) {
  .preview-card { max-width: 100%; height: 92vh; padding: 12px; }
}
.quota-body { font-size: 14px; }
.quota-loading { color: var(--ink-sub); text-align: center; padding: 12px 0; margin: 0; }
.quota-row { margin-bottom: 14px; }
.quota-row-head { display: flex; justify-content: space-between; margin-bottom: 6px; }
.quota-label { color: #374151; }
.quota-nums { color: var(--ink-sub); font-size: 13px; }
.quota-bar {
  height: 8px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}
.quota-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transition: width .3s;
}
.quota-card.warning .quota-bar-fill { background: #f59e0b; }
.quota-extra { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 16px; color: #374151; }
.quota-debt { color: var(--danger); }
.quota-warning-text {
  color: #b45309;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  margin: 14px 0 0;
}

/* ---------- 移动端自适应 ---------- */

@media (max-width: 640px) {
  .bubble { max-width: 88%; font-size: 14.5px; }
  .chat-header-inner { padding: 8px 12px; }
  .header-controls { gap: 8px; }
  .brand.small { font-size: 18px; }
  .msg-list { padding: 14px 10px; }
  .chat-footer { padding: 0 10px calc(10px + env(safe-area-inset-bottom)); }
  .chat-footer.drag-over::after { inset: 0 10px calc(10px + env(safe-area-inset-bottom)); }
  .msg-image { max-width: 140px; max-height: 140px; }
  .pipeline-card { padding: 8px 10px; }
  .pipeline-card-content { font-size: 13.5px; max-height: 260px; }
}

/* ---------- 已发布作品 ---------- */
.works-card { width: min(760px, 100%); max-height: 90vh; overflow-y: auto; }
.works-notice, .work-date { color: var(--ink-sub); font-size: 13px; }
.works-list { display: grid; gap: 12px; margin: 16px 0; }
.work-row { padding: 14px; border: 1px solid var(--line); border-radius: 12px; }
.work-title { font-size: 16px; margin: 0; overflow-wrap: anywhere; }
.work-date { margin: 6px 0 12px; }
.work-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.work-actions a { text-decoration: none; }

.project-context { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.blueprint-box { margin-top: 16px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; }
.blueprint-title { margin: 0 0 10px; font-size: 16px; }
.blueprint-content { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 360px; overflow: auto; font: inherit; }
.blueprint-history { margin: 12px 0; }
.blueprint-history summary { cursor: pointer; margin: 8px 0; }
.blueprint-input { display: block; width: 100%; min-height: 220px; box-sizing: border-box; padding: 12px; margin: 12px 0; font: inherit; resize: vertical; }
.blueprint-structured { margin: 6px 0; }
.blueprint-summary { font-weight: 600; }
.blueprint-section { margin: 8px 0; }
.blueprint-section h4 { margin: 0 0 4px; font-size: 13px; }
.blueprint-row { margin: 2px 0; font-size: 13px; }
