:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1f2430;
  --ink-soft: #5b6472;
  --line: #e3e8f0;
  --primary: #4c6ef5;
  --primary-dark: #3b5bdb;
  --danger: #e03131;
  --danger-soft: #fff0f0;
  --ok: #2f9e44;
  --radius: 14px;
  --shadow: 0 4px 20px rgba(31, 36, 48, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px 80px;
}

.page__header { margin-bottom: 24px; }
.page__header h1 { margin: 0 0 6px; font-size: 26px; letter-spacing: 0.5px; }
.page__subtitle { margin: 0; color: var(--ink-soft); font-size: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.field { margin-bottom: 20px; }
.field:last-child { margin-bottom: 0; }
.field--row { display: flex; gap: 16px; }
.field__col { flex: 1; min-width: 0; }

.field__label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.field__hint { font-weight: 400; color: var(--ink-soft); font-size: 12px; }

.select, .textarea {
  width: 100%;
  font-family: inherit;
  font-size: 15px;
  color: var(--ink);
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(76, 110, 245, 0.15);
}
.select:disabled, .textarea:disabled { background: #f1f3f7; color: #aab2c0; cursor: not-allowed; }

.textarea { resize: vertical; min-height: 96px; }

.field__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  gap: 12px;
}
.char-count { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }

.field__error {
  display: block;
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 6px;
  min-height: 0;
}
.field__error:empty { margin-top: 0; }
.field--invalid .select,
.field--invalid .textarea { border-color: var(--danger); background: var(--danger-soft); }

/* 场景 tab 切换 */
.tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.tab {
  font-family: inherit;
  padding: 8px 18px;
  font-size: 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfe;
  color: var(--ink-soft);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.tab:hover:not(:disabled):not(.tab--active) { border-color: var(--primary); color: var(--primary); }
.tab--active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.tab:disabled { opacity: 0.45; cursor: not-allowed; }

/* 分段控件：输出长度 */
.segmented {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fbfcfe;
}
.segmented__item { position: relative; }
.segmented__item input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segmented__item span {
  display: block;
  padding: 9px 18px;
  font-size: 14px;
  color: var(--ink-soft);
  user-select: none;
}
.segmented__item input:checked + span {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

/* 按钮 */
.actions { display: flex; gap: 12px; margin-top: 8px; }
.expected-cost {
  align-self: center;
  margin: 0;
  color: var(--ink-soft);
  font-size: 14px;
  white-space: nowrap;
}
.expected-cost--insufficient { color: var(--danger); font-weight: 600; }
.btn {
  font-family: inherit;
  font-size: 15px;
  border-radius: 10px;
  padding: 11px 22px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s, opacity 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:not(:disabled):hover { background: var(--primary-dark); }
.btn--ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: #f6f8fc; }
.btn--sm { padding: 6px 14px; font-size: 13px; }

.btn__spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.45);
  border-top-color: #fff;
  border-radius: 50%;
  display: none;
  animation: spin 0.7s linear infinite;
}
.btn.is-loading .btn__spinner { display: inline-block; }

@keyframes spin { to { transform: rotate(360deg); } }

/* 结果 */
.result__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.result__title { margin: 0; font-size: 18px; }
.result__note {
  margin: 10px 0 0;
  padding: 8px 12px;
  font-size: 13px;
  color: #9a5b00;
  background: #fff7e6;
  border: 1px solid #ffe1a8;
  border-radius: 8px;
}

.result__body {
  white-space: pre-wrap;
  font-size: 15px;
  line-height: 1.85;
  color: var(--ink);
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  max-height: 60vh;
  overflow: auto;
}

@media (max-width: 560px) {
  .field--row { flex-direction: column; gap: 20px; }
}

/* ===== 顶栏 / 会员区 ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.topbar__brand { font-size: 13px; color: var(--ink-soft); letter-spacing: 1px; }
.topbar__member { display: flex; align-items: center; gap: 8px; }
.member-chip {
  font-family: inherit;
  font-size: 13px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--primary);
  background: #eef2ff;
  color: var(--primary-dark);
  cursor: pointer;
  transition: background 0.15s;
}
.member-chip:hover { background: #e0e8ff; }
.member-chip__role { font-size: 11px; opacity: 0.75; margin-left: 4px; }

/* ===== 额度条 ===== */
.quota-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}
.quota-bar__role {
  background: #eef2ff;
  color: var(--primary-dark);
  border-radius: 6px;
  padding: 2px 8px;
  font-weight: 600;
}
.quota-bar__text { color: var(--ink); font-weight: 600; }
.quota-bar__text--empty { color: var(--danger); }
.quota-bar__refresh { color: var(--ink-soft); margin-left: auto; }

/* ===== 弹窗 ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal__mask { position: absolute; inset: 0; background: rgba(20, 24, 33, 0.45); }
.modal__panel {
  position: relative;
  width: min(420px, calc(100vw - 40px));
  max-height: 85vh;
  overflow: auto;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 12px 48px rgba(20, 24, 33, 0.25);
  padding: 20px 24px 24px;
}
.modal__header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal__title { margin: 0; font-size: 17px; }
.modal__close {
  border: none;
  background: none;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 4px;
}
.modal__close:hover { color: var(--ink); }
.modal__body { display: flex; flex-direction: column; gap: 6px; }
.tabs--modal { gap: 6px; }

/* 弹窗内输入框 */
.input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--ink);
}
.input:focus { outline: none; border-color: var(--primary); background: #fff; }
.modal__body .field__label { margin-top: 8px; }

.form-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 0; }
.form-ok { color: var(--ok); font-size: 13px; min-height: 18px; margin: 4px 0 0; }
.btn--block { width: 100%; justify-content: center; margin-top: 10px; }

/* 权益列表 */
.ent-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.ent-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
}
.ent-item--off { opacity: 0.55; }
.ent-item__name { font-weight: 600; }
.ent-item__quota { color: var(--ink-soft); font-size: 13px; }
.ent-item__quota--empty { color: var(--danger); font-weight: 600; }

/* 账号设置折叠区 */
.settings { border-top: 1px solid var(--line); padding: 10px 0; }
.settings__summary {
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  list-style: none;
  padding: 4px 0;
}
.settings__summary::before { content: '▸ '; color: var(--ink-soft); }
.settings[open] .settings__summary::before { content: '▾ '; }
.settings form { padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }

/* 权益不足态的生成按钮 */
.btn--primary:disabled.btn--quota-empty {
  background: #adb5bd;
  cursor: not-allowed;
}
