/* ===========================================================
   AiPen —— AI 智能写作平台 样式表
   =========================================================== */
:root {
  --bg: #f4f6fb;
  --card: #ffffff;
  --ink: #1a2233;
  --ink-2: #5b6779;
  --ink-3: #8b95a6;
  --line: #e6eaf2;
  --brand: #4f46e5;
  --brand-2: #6366f1;
  --brand-soft: #eef0ff;
  --ok: #0f9d58;
  --ok-soft: #e8f7ef;
  --warn: #d98200;
  --warn-soft: #fdf3e2;
  --err: #dc2626;
  --err-soft: #fdecec;
  --sidebar: #151a2d;
  --sidebar-2: #1e2540;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; line-height: 1.65; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .6em; line-height: 1.35; font-weight: 700; }
h1 { font-size: 24px; } h2 { font-size: 19px; } h3 { font-size: 16px; }
p { margin: 0 0 1em; }
code { background: #f1f3f9; padding: 1px 6px; border-radius: 6px; font-size: .92em;
       font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
pre { background: #0f1626; color: #e6edf7; padding: 14px 16px; border-radius: 10px; overflow: auto; font-size: 13px; }
pre code { background: none; color: inherit; padding: 0; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex: 0 0 232px; background: var(--sidebar); color: #c9d1e4;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { padding: 20px 20px 16px; display: flex; align-items: center; gap: 10px;
  font-weight: 800; font-size: 17px; color: #fff; letter-spacing: .3px; }
.sidebar .brand .logo { width: 30px; height: 30px; border-radius: 9px; flex: 0 0 30px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6); display: grid; place-items: center;
  font-size: 15px; color: #fff; }
.sidebar nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
.sidebar nav .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: #5d6a86; padding: 14px 12px 6px; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  color: #c9d1e4; border-radius: 9px; margin-bottom: 2px; font-size: 13.5px; }
.sidebar nav a:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: linear-gradient(90deg, var(--brand), var(--brand-2)); color: #fff; font-weight: 600; }
.sidebar .foot { padding: 12px; border-top: 1px solid #262e49; font-size: 12px; color: #6c7899; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: 0 22px;
  position: sticky; top: 0; z-index: 20; }
.topbar .title { font-weight: 700; font-size: 16px; }
.topbar .right { display: flex; align-items: center; gap: 14px; font-size: 13px; color: var(--ink-2); }
.content { padding: 22px; max-width: 1280px; width: 100%; margin: 0 auto; }
.balance-pill { background: var(--brand-soft); color: var(--brand); font-weight: 700;
  padding: 5px 12px; border-radius: 999px; font-size: 13px; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg,var(--brand),#8b5cf6);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px; }
.card.tight { padding: 16px; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2, .card-head h3 { margin: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.grid { display: grid; gap: 16px; }
.grid.c2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.c3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid.c4 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- 统计卡 ---------- */
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .k { font-size: 12.5px; color: var(--ink-3); margin-bottom: 6px; }
.stat .v { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.stat .s { font-size: 12px; color: var(--ink-3); margin-top: 4px; }

/* ---------- 表单 ---------- */
label.f { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=url],
select, textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #d8dee9; border-radius: 10px;
  font-size: 14px; font-family: inherit; color: var(--ink); background: #fff; transition: .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
textarea { resize: vertical; line-height: 1.7; }
.form-row { margin-bottom: 14px; }
.form-row.half { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row .hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.checkbox { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.checkbox input { width: auto; }

/* ---------- 按钮 ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; border: 1px solid transparent; font-size: 13.5px;
  font-weight: 600; cursor: pointer; background: var(--brand); color: #fff; transition: .15s; white-space: nowrap; }
.btn:hover { background: #4338ca; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--ink); border-color: #d8dee9; }
.btn.ghost:hover { background: #f7f8fc; border-color: #c3cbd9; }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.soft:hover { background: #e3e6ff; }
.btn.ok { background: var(--ok); } .btn.ok:hover { background: #0c8748; }
.btn.warn { background: var(--warn); } .btn.warn:hover { background: #b96f00; }
.btn.danger { background: var(--err); } .btn.danger:hover { background: #b91c1c; }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }

/* ---------- 提示 ---------- */
.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13.5px; border: 1px solid transparent; }
.alert-ok { background: var(--ok-soft); color: #0a6c3d; border-color: #c7ebd7; }
.alert-warn { background: var(--warn-soft); color: #8a5300; border-color: #f3ddb6; }
.alert-err { background: var(--err-soft); color: #a11b1b; border-color: #f6cfcf; }
.alert-info { background: #eef4ff; color: #1e40af; border-color: #d3e0fb; }

/* ---------- 徽章 ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f6; color: var(--ink-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

/* ---------- 表格 ---------- */
table.tb { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tb th { text-align: left; padding: 10px 12px; color: var(--ink-3); font-weight: 600;
  border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12.5px; }
table.tb td { padding: 11px 12px; border-bottom: 1px solid #f1f3f9; vertical-align: middle; }
table.tb tbody tr:hover { background: #fafbff; }
table.tb .num { font-variant-numeric: tabular-nums; }
.empty { padding: 36px 16px; text-align: center; color: var(--ink-3); }
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a, .pager span { padding: 6px 11px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; font-size: 13px; color: var(--ink-2); }
.pager span.cur { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ---------- 登录页 ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 10% -10%, #e7e9ff 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 0%, #e3f6ff 0%, transparent 50%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 18px; padding: 32px;
  box-shadow: 0 20px 50px rgba(16,24,40,.12); border: 1px solid var(--line); }
.auth-card .logo-lg { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), #8b5cf6); color: #fff; font-size: 22px; margin-bottom: 16px; }
.auth-card h1 { font-size: 21px; margin-bottom: 6px; }
.auth-card .sub { color: var(--ink-3); font-size: 13px; margin-bottom: 22px; }

/* ---------- 写作工作台 ---------- */
.stepper { display: flex; gap: 6px; flex-wrap: wrap; }
.step-chip { display: flex; align-items: center; gap: 7px; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.step-chip:hover { border-color: #c8cfe0; }
.step-chip.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.step-chip.done { background: var(--ok-soft); border-color: #bfe6d1; color: #0a6c3d; }
.step-chip .n { width: 18px; height: 18px; border-radius: 50%; background: #eef0f6; color: var(--ink-2);
  display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.step-chip.active .n { background: rgba(255,255,255,.25); color: #fff; }
.step-chip.done .n { background: var(--ok); color: #fff; }

.outbox { background: #fcfdff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px;
  min-height: 120px; max-height: 620px; overflow-y: auto; }
.outbox.streaming { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.08); }
.outbox .cursor::after { content: '▌'; color: var(--brand); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { 50% { opacity: 0; } }
.reasoning { background: #f6f7fb; border-left: 3px solid #c8cfe0; padding: 10px 14px; border-radius: 8px;
  color: var(--ink-3); font-size: 12.5px; white-space: pre-wrap; margin-bottom: 14px; max-height: 200px; overflow: auto; }
.md-body { font-size: 14.5px; line-height: 1.85; color: #21293b; }
.md-body h1 { font-size: 22px; margin: 1.2em 0 .5em; }
.md-body h2 { font-size: 18px; margin: 1.3em 0 .5em; padding-left: 10px; border-left: 4px solid var(--brand); }
.md-body h3 { font-size: 15.5px; margin: 1.1em 0 .4em; }
.md-body ul { padding-left: 22px; } .md-body li { margin-bottom: .35em; }
.md-body p { margin-bottom: .9em; }
.md-body strong { color: #101828; }
.md-body blockquote { border-left: 3px solid #d8dee9; margin: 1em 0; padding: 4px 14px; color: var(--ink-2); background: #fafbfe; }

.section-item { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 12px; background: #fff; overflow: hidden; }
.section-item .hd { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: #fafbfe; border-bottom: 1px solid var(--line); }
.section-item .hd .idx { width: 22px; height: 22px; border-radius: 6px; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: 0 0 22px; }
.section-item .hd .h { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-item .bd { padding: 14px 16px; }

.editor { width: 100%; min-height: 260px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.75; }

/* ---------- 步骤导航条 ---------- */
.wizard-nav { display: flex; gap: 8px; margin-bottom: 18px; overflow-x: auto; padding-bottom: 4px; }
.wizard-nav .st { flex: 1 0 auto; min-width: 130px; padding: 12px 14px; border-radius: 12px; background: #fff;
  border: 1px solid var(--line); cursor: pointer; transition: .15s; }
.wizard-nav .st:hover { border-color: #c8cfe0; transform: translateY(-1px); }
.wizard-nav .st.active { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.wizard-nav .st.done { background: #f8fdfa; border-color: #c7ebd7; }
.wizard-nav .st .t { font-weight: 700; font-size: 13.5px; margin-bottom: 2px; }
.wizard-nav .st .d { font-size: 11.5px; color: var(--ink-3); }

/* ---------- Toast ---------- */
#toast-box { position: fixed; right: 20px; bottom: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1a2233; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 13.5px;
  box-shadow: 0 10px 30px rgba(16,24,40,.25); animation: slidein .25s ease; max-width: 380px; }
.toast.ok { background: #0f9d58; } .toast.err { background: #dc2626; } .toast.warn { background: #d98200; }
@keyframes slidein { from { opacity: 0; transform: translateY(10px); } }
.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.ghost .spin, .btn.soft .spin { border-color: rgba(79,70,229,.3); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 登录/注册 tab ---------- */
.tabs { display: flex; background: #f1f3f9; border-radius: 10px; padding: 4px; margin-bottom: 20px; }
.tabs a { flex: 1; text-align: center; padding: 8px; border-radius: 8px; color: var(--ink-2); font-size: 13.5px; font-weight: 600; }
.tabs a.on { background: #fff; color: var(--brand); box-shadow: 0 1px 3px rgba(16,24,40,.08); text-decoration: none; }

/* ---------- 富文本输出区 ---------- */
pre.out { white-space: pre-wrap; word-break: break-word; background: #fcfdff; color: var(--ink);
  border: 1px solid var(--line); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row;
    align-items: center; overflow-x: auto; }
  .sidebar .brand { padding: 12px; }
  .sidebar nav { display: flex; padding: 6px; }
  .sidebar nav a { white-space: nowrap; margin: 0 2px; }
  .sidebar nav .grp, .sidebar .foot { display: none; }
  .content { padding: 14px; }
  .form-row.half { grid-template-columns: 1fr; }
}
