:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1c1f23;
  --muted: #7a828c;
  --accent: #4a6cf7;
  --accent-soft: #eef1fe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
}
:root[data-theme="dark"] {
  --bg: #14161a;
  --panel: #1c1f24;
  --border: #2c3037;
  --text: #e6e8ec;
  --muted: #8b939e;
  --accent: #6f8cff;
  --accent-soft: #232941;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { font-size: 15px; font-weight: 600; }
.brand .sep { margin: 0 6px; color: var(--muted); }
.muted { color: var(--muted); font-weight: 400; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.pill {
  font-size: 12px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border);
  padding: 3px 10px; border-radius: 999px; cursor: default;
}
#balancePill { cursor: pointer; }

/* ---------- 布局 ---------- */
.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 12px;
  padding: 12px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border); flex: none;
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .3px; }
.panel-body { padding: 14px; overflow-y: auto; flex: 1; min-height: 0; }
.primary.sm { flex: none; padding: 6px 16px; font-size: 12.5px; }

/* ---------- 表单 ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
label .req { color: #e5484d; }
.hint { color: var(--muted); font-weight: 400; opacity: .8; }
input, textarea, select {
  width: 100%; margin-top: 5px;
  padding: 8px 10px;
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
  outline: none; resize: vertical;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); background: var(--panel); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row > label { margin-bottom: 12px; }

.more { margin: 4px 0 14px; }
.more summary { font-size: 12px; color: var(--muted); cursor: pointer; padding: 6px 0; }
.switch { display: flex; align-items: center; gap: 6px; align-self: end; padding-bottom: 8px; }
.switch input { width: auto; margin: 0; }
input[type="range"] { padding: 0; background: none; border: none; }

.actions { display: flex; gap: 8px; }
button { font: inherit; cursor: pointer; }
.primary {
  flex: 1; padding: 10px; font-size: 14px; font-weight: 600;
  color: #fff; background: var(--accent);
  border: none; border-radius: 8px; transition: .12s;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: .5; cursor: not-allowed; }
.ghost {
  padding: 8px 14px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 8px; transition: .12s;
}
.ghost:hover { color: var(--text); border-color: var(--accent); }
.ghost.sm { padding: 4px 9px; font-size: 12px; }

/* ---------- 历史 ---------- */
.history-list { overflow-y: auto; flex: 1; padding: 6px; }
.hitem {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; position: relative;
}
.hitem:hover { background: var(--bg); }
.hitem.on { background: var(--accent-soft); border-color: var(--accent); }
.hitem b { display: block; font-size: 12.5px; font-weight: 500; line-height: 1.4;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hitem small { color: var(--muted); font-size: 11px; }
.hitem .del {
  position: absolute; right: 6px; top: 6px; display: none;
  border: none; background: none; color: var(--muted); font-size: 13px; padding: 2px 4px;
}
.hitem:hover .del { display: block; }
.hitem .del:hover { color: #e5484d; }

/* ---------- 输出 ---------- */
.out-actions { display: flex; align-items: center; gap: 8px; }
.article { font-size: 15px; line-height: 1.85; word-break: break-word; }
.article h1 { font-size: 21px; margin: 22px 0 12px; }
.article h2 { font-size: 17px; margin: 22px 0 10px; padding-left: 9px; border-left: 3px solid var(--accent); }
.article h3 { font-size: 15px; margin: 18px 0 8px; }
.article p { margin: 10px 0; }
.article ul, .article ol { margin: 10px 0; padding-left: 22px; }
.article li { margin: 5px 0; }
.article hr { border: none; border-top: 1px solid var(--border); margin: 20px 0; }
.article blockquote {
  margin: 12px 0; padding: 8px 14px; color: var(--muted);
  border-left: 3px solid var(--border); background: var(--bg); border-radius: 0 6px 6px 0;
}
.article code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.article pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; }
.article pre code { background: none; padding: 0; }
.article table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13px; display: block; overflow-x: auto; }
.article th, .article td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.article th { background: var(--bg); font-weight: 600; }
.chip {
  padding: 5px 12px; font-size: 12px; color: var(--muted);
  background: var(--bg); border: 1px solid var(--border); border-radius: 999px; transition: .12s;
}
.chip:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* ---------- 弹框 ---------- */
.modal {
  width: min(680px, 92vw); padding: 0; border: none; border-radius: 12px;
  background: var(--panel); color: var(--text);
  box-shadow: 0 24px 64px rgba(16, 24, 40, .28);
}
.modal::backdrop { background: rgba(16, 20, 28, .45); backdrop-filter: blur(2px); }
.modal-box { display: flex; flex-direction: column; max-height: 86vh; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--border); flex: none;
}
.modal-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.modal-head .x { border: none; background: none; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }
.modal-head .x:hover { color: var(--text); }
.modal-body { padding: 18px 20px 4px; overflow-y: auto; flex: 1; }
.modal-body .sec {
  margin: 4px 0 10px; font-size: 11.5px; font-weight: 600; color: var(--muted);
  letter-spacing: .08em; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}
.modal-body .sec:not(:first-child) { margin-top: 18px; }
.modal-body textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; line-height: 1.6; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 20px; border-top: 1px solid var(--border); flex: none;
}

/* ---------- 登录页 ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-box {
  width: 320px; padding: 28px 26px 22px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
}
.login-brand { font-size: 16px; font-weight: 600; margin-bottom: 20px; text-align: center; }
.login-box label { font-size: 12px; }
.login-box .primary { width: 100%; margin-top: 6px; }
.login-err { color: #e5484d; font-size: 12px; min-height: 18px; margin: 10px 0 0; text-align: center; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translate(-50%, 16px);
  background: #1c1f24; color: #fff; padding: 9px 18px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 批量任务页 ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }
.side > .panel:first-child { flex: 1; min-height: 140px; }
.side .domains { flex: none; max-height: 42%; }
.main > div { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* 新建任务表单：顶部一行配置 + 两个撑满高度的编辑区 */
.form-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 12px; padding: 14px; }
.form-top {
  display: grid; gap: 10px; flex: none;
  grid-template-columns: 220px 170px 100px 130px 140px auto;
  align-items: end;
}
.form-top label { margin-bottom: 0; }
.form-top .switch { padding-bottom: 9px; }
.form-top input[type="range"] { height: 33px; margin-top: 5px; }

.editor-grid {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 1fr 1.3fr; gap: 12px;
}
.editor {
  display: flex; flex-direction: column; min-height: 0;
  border: 1px solid var(--border); border-radius: 9px; overflow: hidden;
}
.editor:focus-within { border-color: var(--accent); }
.editor-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 7px 12px; font-size: 12px; color: var(--muted);
  background: var(--bg); border-bottom: 1px solid var(--border); flex: none;
}
.editor-head .counter { margin-top: 0; white-space: nowrap; }
.editor textarea {
  flex: 1; min-height: 0; margin-top: 0; resize: none;
  border: none; border-radius: 0; background: var(--panel);
  font-size: 13px; line-height: 1.7; padding: 12px;
}
.editor textarea:focus { background: var(--panel); }

.row-inline { display: flex; gap: 6px; margin-bottom: 8px; }
.row-inline input { margin-top: 0; }
.row-inline button { flex: none; }

.domain-list { max-height: 150px; overflow-y: auto; }
.ditem {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px; border-radius: 6px; font-size: 12.5px;
}
.ditem:hover { background: var(--bg); }
.ditem .dname { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ditem .ok { color: #2f9e6d; font-size: 10px; }
.ditem-btns { display: flex; gap: 2px; flex: none; }
.ditem button { border: none; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0 3px; }
.ditem .cfg:hover { color: var(--accent); }
.ditem .del:hover { color: #e5484d; }

.tip { color: var(--muted); font-size: 12px; padding: 8px 2px; }

.counter { display: block; margin-top: 4px; font-size: 11.5px; color: var(--muted); }
label code { background: var(--bg); padding: 0 4px; border-radius: 4px; }
input[readonly] { color: var(--muted); cursor: not-allowed; }
.hitem .dim { color: var(--muted); opacity: .75; display: block; }

.badge {
  display: inline-block; padding: 1px 7px; margin-right: 6px;
  font-size: 11px; border: 1px solid; border-radius: 999px;
}

.task-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px;
  font-size: 12px; color: var(--muted); margin-bottom: 12px;
}
.task-meta b { color: var(--text); font-weight: 600; }
.task-meta .next { color: var(--accent); }

.progress { height: 4px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-bottom: 16px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); transition: width .4s; }

.art-list { display: flex; flex-direction: column; gap: 8px; }
.art { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.art.generating { border-color: var(--accent); }
.art.failed { border-color: #e5484d55; }
.art-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; cursor: pointer; }
.art-head:hover { background: var(--bg); }
.art .no {
  flex: none; width: 22px; height: 22px; border-radius: 6px;
  background: var(--bg); color: var(--muted);
  font-size: 11px; display: grid; place-items: center;
}
.art.done .no { background: var(--accent-soft); color: var(--accent); }
.art-title { flex: 1; min-width: 0; }
.art-title b { display: block; font-size: 13.5px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.art-title small { color: var(--muted); font-size: 11.5px; }
.art-title .err { color: #e5484d; display: block; }
.art-title .pub { display: block; color: #2f9e6d; }
.art-title .pub a { color: inherit; }
.art-body { padding: 4px 16px 16px; border-top: 1px solid var(--border); }
.art-actions { margin-top: 12px; }

@media (max-width: 1240px) {
  .form-top { grid-template-columns: 1fr 1fr 1fr; }
  .editor-grid { grid-template-columns: 1fr; grid-auto-rows: minmax(200px, 1fr); }
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }

  .layout { grid-template-columns: 1fr; grid-auto-rows: minmax(0, auto); overflow-y: auto; }
}
