/* ============ Aibubu 风格 · 白色极简主题 ============ */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface2: #f5f5f7;
  --surface3: #eeeff0;
  --line: #e8e8ed;
  --border: #e8e8ed;
  --text: #1a1a1f;
  --muted: #8a8a93;
  --accent: #6c5ce7;
  --accent-soft: #f0edff;
  --danger: #e5484d;
  --ok: #2f9e5f;
  --gold: #d98324;
  --shadow: 0 2px 14px rgba(20, 20, 40, .05);
  --radius: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.5; min-height: 100vh;
  padding-top: calc(56px + env(safe-area-inset-top));
  padding-bottom: calc(160px + env(safe-area-inset-bottom));
}

/* ---- 顶部栏 ---- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 14px 0;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 38px; height: 38px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--text);
  border-radius: 10px; cursor: pointer; font-size: 17px;
}
.icon-btn:active { background: var(--surface2); }
.brand { display: flex; align-items: center; gap: 7px; min-width: 0; }
.brand-logo {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  object-fit: cover; display: block;
}
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: -.5px; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.balance-chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 13px; border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; max-width: 130px; overflow: hidden; text-overflow: ellipsis;
}
.balance-chip:active { background: var(--surface2); }
.user-btn { border: 1px solid var(--line); border-radius: 50%; }

/* ---- 主舞台 ---- */
.stage { max-width: 720px; margin: 0 auto; padding: 20px 16px; min-height: 55vh; }
.stage-inner {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 12vh 10px 40px; transition: opacity .3s;
}
.stage-inner.compact { padding: 20px 10px; }
.hero-icon {
  width: 62px; height: 62px; border-radius: 18px; margin-bottom: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface2); color: var(--text);
}
.hero-title { font-size: 25px; font-weight: 700; margin: 0 0 8px; letter-spacing: -.5px; }
.hero-sub { font-size: 13px; color: var(--muted); margin: 0; }
.content-area { margin-top: 8px; }

/* ---- 结果 ---- */
.result-card { margin-top: 16px; }
.result-info { margin-bottom: 10px; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.result-item { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--surface2); }
.result-item img, .result-item video { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; background: #f0f0f0; }
.result-item .actions { padding: 8px; text-align: center; }
.result-item a { color: var(--accent); font-size: 12px; text-decoration: none; font-weight: 600; }

/* ---- 对话 ---- */
.chat-log { display: flex; flex-direction: column; gap: 10px; padding: 6px 0; max-height: 60vh; overflow-y: auto; }
.chat-msg { padding: 11px 14px; border-radius: 14px; font-size: 14px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; max-width: 86%; }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.assistant { align-self: flex-start; background: var(--surface2); color: var(--text); border-bottom-left-radius: 4px; }

/* ---- GPT 式生成进度气泡 ---- */
.chat-msg.gen-msg { max-width: 100%; width: 100%; white-space: normal; padding: 16px; }
.gen-loading { display: flex; align-items: center; gap: 16px; }
.gen-ring { position: relative; width: 42px; height: 42px; flex: none; }
.gen-ring svg { transform: rotate(-90deg); display: block; }
.gen-ring-track { fill: none; stroke: var(--line); stroke-width: 4; }
.gen-ring-fill {
  fill: none; stroke: var(--accent); stroke-width: 4; stroke-linecap: round;
  stroke-dasharray: 113.1; stroke-dashoffset: calc(113.1 * (1 - var(--p) / 100));
  transition: stroke-dashoffset .6s ease;
}
.gen-ring-num {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: -.3px;
}
.gen-ring-num span { font-size: 8px; margin-left: .5px; opacity: .8; }
.gen-loading-meta { min-width: 0; }
.gen-stage { font-size: 14px; font-weight: 600; color: var(--text);
  background: linear-gradient(90deg, var(--text) 30%, var(--muted) 50%, var(--text) 70%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; animation: genShimmer 1.8s linear infinite; }
@keyframes genShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.gen-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.gen-result { margin-top: 2px; }
.gen-result:empty { display: none; }
.gen-result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.gen-result-item { border-radius: 12px; overflow: hidden; background: var(--surface); border: 1px solid var(--line);
  animation: genReveal .5s ease both; }
@keyframes genReveal { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.gen-result-item img, .gen-result-item video { width: 100%; display: block; aspect-ratio: 1; object-fit: cover; background: #f0f0f0; }
.gen-actions { padding: 7px; text-align: center; }
.gen-actions a { color: var(--accent); font-size: 12px; text-decoration: none; font-weight: 600; }
.gen-done { font-size: 11px; color: var(--muted); margin-top: 8px; }
.gen-error { font-size: 13px; color: #d64545; background: #fff2f2; border-radius: 10px; padding: 10px 12px; }

/* ---- 底部输入器 ---- */
.composer-wrap {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, #fff 70%, rgba(255,255,255,0));
}
.composer {
  max-width: 720px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 22px; box-shadow: var(--shadow); padding: 10px 12px 10px;
}
.composer-input {
  width: 100%; border: none; outline: none; resize: none; background: transparent;
  font-size: 15px; color: var(--text); line-height: 1.5; padding: 4px 4px 6px;
  max-height: 120px; font-family: inherit;
}
.composer-input::placeholder { color: #b0b0b8; }
.composer-tools { display: flex; align-items: center; gap: 7px; }
.tool-btn {
  width: 36px; height: 36px; flex: none; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.tool-btn:active, .tool-btn.active { background: var(--accent-soft); color: var(--accent); }
.plus-btn svg { transition: transform .18s ease; }
.plus-btn.active svg { transform: rotate(45deg); }  /* + 变 ×，直观表示可收起 */
.tool-pill {
  height: 36px; display: inline-flex; align-items: center; gap: 5px; flex: none;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 0 11px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.type-pill { max-width: 27%; }
.model-pill { flex: 1 1 auto; min-width: 0; max-width: 34%; }
.tool-pill:active { background: var(--surface2); }
.model-pill span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-pill svg { flex: none; }
.submit-pill {
  margin-left: auto; height: 36px; flex: none; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
  border: none; border-radius: 999px; padding: 0 13px;
  background: #3a3a3f; color: #fff; font-size: 13px; font-weight: 700; cursor: pointer;
  max-width: 42%; min-width: 0;
}
.submit-pill #costInfo {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.submit-pill:active { transform: scale(.97); }
.submit-pill .bolt { font-size: 14px; flex: none; }
.submit-pill:disabled { opacity: .55; }

/* 参数面板 / 进度 */
.param-panel {
  border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px;
  max-height: 46vh; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.param-panel::-webkit-scrollbar { width: 5px; }
.param-panel::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.selected-model { font-size: 13px; color: var(--accent); font-weight: 600; margin: 4px 0 8px; }
.param-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.param-field label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.cost-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.progress-wrap { margin-top: 10px; }
.progress-bar { height: 6px; background: var(--surface2); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
#progressText { margin-top: 6px; font-size: 11px; }

/* ---- 抽屉 ---- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; opacity: 0; pointer-events: none; transition: opacity .25s; }
.overlay.show { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 45;
  width: min(82vw, 330px); background: var(--surface);
  transform: translateX(-102%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column; box-shadow: 8px 0 30px rgba(0,0,0,.1);
  padding-top: env(safe-area-inset-top);
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--line); }
.drawer-brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.drawer-nav { padding: 10px; display: flex; flex-direction: column; gap: 3px; }
.drawer-nav button {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: none; background: transparent; color: var(--text); text-align: left;
  padding: 13px 12px; border-radius: 11px; font-size: 15px; cursor: pointer; font-family: inherit;
}
.drawer-nav button:active, .drawer-nav button:hover { background: var(--surface2); }
.drawer-nav button span { font-size: 18px; width: 24px; text-align: center; }
.drawer-status { padding: 12px 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.drawer-foot { margin-top: auto; padding: 16px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); }

/* ---- 底部弹层 ---- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: var(--surface); border-radius: 20px 20px 0 0;
  transform: translateY(102%); transition: transform .28s cubic-bezier(.2,.8,.2,1);
  max-height: 82vh; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -6px 30px rgba(0,0,0,.08);
}
.sheet.open { transform: translateY(0); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; border-bottom: 1px solid var(--line); }
.sheet-head h3 { margin: 0; font-size: 16px; }
.sheet-body { padding: 14px 18px 22px; overflow-y: auto; }

/* 类型选择 */
.type-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.type-card {
  border: 1px solid var(--line); background: var(--surface); border-radius: 14px;
  padding: 18px 8px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  cursor: pointer; font-size: 14px; font-weight: 600;
}
.type-card .ico { font-size: 26px; }
.type-card.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* 模型列表（弹层内） */
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.filter-btn { border: 1px solid var(--line); background: var(--surface); color: var(--muted); padding: 6px 13px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.model-list { display: flex; flex-direction: column; gap: 8px; }
.model-item {
  display: flex; align-items: center; gap: 10px; padding: 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer;
}
.model-item.active { border-color: var(--accent); background: var(--accent-soft); }
.model-item .radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid #c9c9d0; flex: none; }
.model-item.active .radio { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px #fff; }
.model-item .meta { min-width: 0; flex: 1; }
.model-item .mid { font-size: 13px; font-weight: 600; word-break: break-all; }
.model-item .desc { font-size: 11px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-item .price-tag { font-size: 11px; color: var(--gold); background: #fff6e9; border-radius: 7px; padding: 3px 7px; white-space: nowrap; flex: none; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.cap-tag { font-size: 10px; padding: 2px 8px; border-radius: 999px; white-space: nowrap; flex: none; }
.cap-image { background: var(--accent-soft); color: var(--accent); }
.cap-text  { background: #e9f7ef; color: var(--ok); }
.cap-video { background: #fff2e6; color: var(--gold); }
.cap-embedding, .cap-audio, .cap-unknown { background: var(--surface2); color: var(--muted); }

/* ---- 通用表单/按钮 ---- */
.panel { padding: 4px 0; }
.panel h2 { font-size: 17px; margin: 4px 0 12px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
input, textarea, select {
  width: 100%; background: var(--surface2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 14px;
  font-family: inherit; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: 10px 15px; border-radius: 10px; font-size: 14px; cursor: pointer; font-family: inherit; }
.btn:active { transform: scale(.98); }
.btn.small { padding: 7px 12px; font-size: 12px; }
.btn.primary { background: var(--accent); border: none; color: #fff; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.hint, .muted { color: var(--muted); font-size: 12px; line-height: 1.6; }
.info { font-size: 12px; color: var(--ok); background: #e9f7ef; border: 1px solid #cceadb; padding: 8px 10px; border-radius: 8px; margin-top: 10px; }
.quote-info { color: var(--gold); font-size: 13px; font-weight: 600; }
.req { color: var(--danger); }
select { margin-bottom: 0; }
.tab-row { display: flex; gap: 5px; background: var(--surface2); padding: 4px; border-radius: 10px; margin-bottom: 6px; }
.tab-btn { flex: 1; border: none; background: transparent; color: var(--muted); padding: 9px; border-radius: 8px; font-size: 14px; cursor: pointer; font-family: inherit; }
.tab-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; }
.code-row .btn { flex: none; white-space: nowrap; }
.change-pwd { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface2); }
.badge { font-size: 11px; color: var(--muted); background: var(--surface2); padding: 5px 10px; border-radius: 20px; border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { color: var(--ok); border-color: #cceadb; }
.user-chip { font-size: 12px; color: var(--accent); background: var(--accent-soft); padding: 5px 10px; border-radius: 20px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- 历史记录 ---- */
.history-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; }
.history-item { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); cursor: pointer; }
.history-item:active { transform: scale(.98); }
.history-item .thumb { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: #f0f0f0; }
.history-item .thumb-placeholder { width: 100%; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; background: #f0f0f0; color: var(--muted); font-size: 30px; }
.history-item .h-meta { padding: 8px; }
.history-item .h-model { font-size: 12px; font-weight: 600; word-break: break-all; }
.history-item .h-time { font-size: 10px; color: var(--muted); margin-top: 3px; }
.history-item .h-cost { font-size: 10px; color: var(--gold); margin-top: 3px; }
.history-item .h-ttl { font-size: 10px; color: var(--ok); margin-top: 5px; padding-top: 5px; border-top: 1px dashed var(--line); }
.h-ttl.urgent, .modal-ttl.urgent { color: var(--danger) !important; }
.modal-ttl { font-size: 12px; color: var(--ok); margin-top: 6px; font-weight: 600; }
.history-empty { grid-column: 1 / -1; text-align: center; padding: 30px 10px; }

/* ---- 参考图上传 ---- */
.upload-box { margin-top: 2px; }
.upload-drop { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 60px; border: 1px dashed #cfcfd6; border-radius: 10px; background: var(--surface2); cursor: pointer; padding: 10px; text-align: center; }
.upload-drop input[type=file] { display: none; }
.upload-hint { color: var(--accent); font-size: 13px; line-height: 1.5; }
.upload-tip { font-size: 11px; color: var(--muted); margin: 6px 0 0; }
.upload-preview { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.upload-thumb { position: relative; width: 66px; height: 66px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.upload-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border: none; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 20px; cursor: pointer; padding: 0; }
.thumb-file { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; background: var(--surface2, #f2f2f5); color: var(--muted, #888); font-size: 22px; }
.thumb-file span { font-size: 10px; }
.file-thumb { background: var(--surface2, #f2f2f5); }

/* ---- 弹窗 / toast ---- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--surface); border-radius: 18px; width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; padding: 18px; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { border: none; background: var(--surface2); color: var(--text); width: 30px; height: 30px; border-radius: 8px; font-size: 15px; cursor: pointer; }
.modal-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.modal-prompt { background: var(--surface2); border-radius: 10px; padding: 12px; font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-break: break-word; margin-bottom: 12px; }
.modal-prompt .plabel { color: var(--accent); font-weight: 600; display: block; margin-bottom: 4px; }
/* ---- 下载文件名弹窗 ---- */
.name-box { max-width: 400px; }
.name-box input { margin: 4px 0 14px; }
.name-actions { display: flex; gap: 10px; }
.name-btn { flex: 1; border: 1px solid var(--line); background: var(--surface2); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit; }
.name-btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.name-btn:active { opacity: .82; }
.toast { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); background: #1a1a1f; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13px; z-index: 80; box-shadow: 0 8px 30px rgba(0,0,0,.2); max-width: 88%; text-align: center; }
.hidden { display: none !important; }
