:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e2e1dc;
  --border-strong: #cfcec7;
  --text: #1f1e1b;
  --text-dim: #6b6a64;
  --text-faint: #97968f;
  --accent: #0070d2;
  --accent-soft: #e6f0fb;
  --danger: #a32d2d;
  --danger-soft: #fcebeb;
  --warn: #854f0b;
  --warn-soft: #faeeda;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

.wrap { max-width: 1360px; margin: 0 auto; padding: 24px 20px 80px; }

header.top {
  display: flex; align-items: baseline; gap: 12px;
  flex-wrap: wrap; margin-bottom: 6px;
}
header.top h1 { font-size: 19px; font-weight: 600; margin: 0; }
header.top .sub { color: var(--text-dim); font-size: 13px; }

.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px; margin: 16px 0;
}
.toolbar .grow { flex: 1; }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); border-radius: 8px; padding: 7px 14px;
  font-size: 13px; cursor: pointer; font-family: inherit;
}
.btn:hover { background: #fafaf8; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.btn.primary:hover { background: #0a6cb7; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: #e8c9c9; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn-icon {
  border: none; background: transparent; color: var(--text-faint);
  cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 6px; border-radius: 5px;
}
.btn-icon:hover { background: var(--danger-soft); color: var(--danger); }

input[type="text"], select, textarea {
  font: inherit; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 7px; padding: 6px 9px; width: 100%;
}
input[type="text"]:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft);
}

/* 系列卡片 */
.campaign {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.camp-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.camp-no { font-weight: 600; font-size: 14px; }

.grid {
  display: grid; gap: 10px 14px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  margin-bottom: 14px;
}
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field-label { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.field-hint { font-size: 11px; color: var(--text-faint); }

/* 广告组 */
.adgroup {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; margin-bottom: 12px; background: #fcfcfb;
}
.ag-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 10px;
}
.ag-title { font-size: 13px; font-weight: 600; color: var(--accent); }

.sub-block { margin-top: 14px; }
.sub-head {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  font-size: 13px; font-weight: 600; margin-bottom: 8px;
}
.muted { color: var(--text-faint); font-weight: 400; font-size: 12px; }

/* 关键词表 */
.kw-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kw-table th {
  text-align: left; font-size: 11px; color: var(--text-dim);
  font-weight: 500; padding: 5px 6px; border-bottom: 1px solid var(--border);
}
.kw-table td { padding: 3px 6px 3px 0; }

.paste-box {
  margin-top: 8px; min-height: 46px; font-size: 12px;
  font-family: var(--mono); resize: vertical;
}

/* RSA */
.rsa-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}
.rsa-col-title {
  font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px;
}
.rsa-row {
  display: flex; align-items: center; gap: 7px; margin-bottom: 5px;
}
.rsa-idx {
  width: 20px; flex: none; text-align: right;
  font-size: 11px; color: var(--text-faint); font-family: var(--mono);
}
.rsa-row textarea { resize: vertical; font-size: 12px; }

.counter {
  flex: none; width: 46px; text-align: right;
  font-size: 11px; color: var(--text-faint); font-family: var(--mono);
}
.counter.warn { color: var(--warn); }
.counter.over { color: var(--danger); font-weight: 600; }

/* 校验 */
.validate { border-radius: var(--radius); padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
.validate.ok { background: var(--accent-soft); color: var(--accent); }
.validate.bad { background: var(--danger-soft); color: var(--danger); }
.validate.warnbox { background: var(--warn-soft); color: var(--warn); }
.v-group ul { margin: 4px 0 0; padding-left: 18px; }
.v-group li { font-size: 12px; }

/* 预览 */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 16px;
}
.panel h2 {
  font-size: 14px; font-weight: 600; margin: 0 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.preview-meta { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.unver-legend { color: var(--warn); }
.preview-scroll { overflow: auto; max-height: 340px; }
.preview-table { border-collapse: collapse; font-size: 11px; width: max-content; }
.preview-table th {
  background: #f2f1ed; padding: 5px 7px; text-align: left;
  white-space: nowrap; border: 1px solid var(--border);
  position: sticky; top: 0; font-weight: 500;
}
.preview-table th.unver { background: var(--warn-soft); color: var(--warn); }
.preview-table td {
  padding: 4px 7px; border: 1px solid var(--border);
  white-space: nowrap; max-width: 190px; overflow: hidden; text-overflow: ellipsis;
}

/* 设置 */
.set-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.set-row label { font-size: 13px; color: var(--text-dim); flex: none; }
.set-row input { max-width: 380px; }
.token {
  font-family: var(--mono); font-size: 12px; background: #f2f1ed;
  padding: 4px 9px; border-radius: 6px; color: var(--text-dim);
}
.note {
  font-size: 12px; color: var(--text-dim); background: #f2f1ed;
  border-left: 3px solid var(--border-strong);
  padding: 8px 12px; border-radius: 0 6px 6px 0; margin-top: 10px;
}

/* ===================== 视图切换 ===================== */
.view { display: block; }
.hidden { display: none !important; }
.grow { flex: 1; }

/* ===================== 登录 / 注册 ===================== */
#view-auth {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: linear-gradient(180deg, #f7f7f5 0%, #eeece5 100%);
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 28px 26px 22px;
  box-shadow: 0 8px 28px rgba(0,0,0,.06);
}
.auth-brand {
  font-family: var(--mono); font-size: 12px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 10px;
}
.auth-card h1 { font-size: 19px; margin: 0 0 6px; font-weight: 600; }
.auth-sub { font-size: 13px; color: var(--text-dim); margin: 0 0 18px; line-height: 1.6; }

.auth-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.auth-tab {
  flex: 1; border: 1px solid var(--border-strong); background: transparent;
  border-radius: 8px; padding: 7px 0; font: inherit; font-size: 13px;
  color: var(--text-dim); cursor: pointer;
}
.auth-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.btn.block { width: 100%; padding: 9px 0; margin-top: 4px; }

.auth-msg { display: none; margin-top: 12px; font-size: 12px; color: var(--danger); }
.auth-msg.show { display: block; }
.auth-card .note { margin-top: 16px; }

/* ===================== 页签 ===================== */
header.top .grow { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  border: none; background: transparent; font: inherit; font-size: 13px;
  color: var(--text-dim); padding: 8px 16px; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.badge {
  display: inline-block; min-width: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 11px; line-height: 17px;
  text-align: center; margin-left: 3px;
}

/* ===================== 批次表 ===================== */
.batch-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
.batch-table th {
  text-align: left; font-size: 11px; color: var(--text-dim); font-weight: 500;
  padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.batch-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.batch-table tr:last-child td { border-bottom: none; }
.b-name { font-weight: 500; }
.b-id { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.b-scale { font-size: 12px; color: var(--text-dim); }
.b-time { font-size: 12px; color: var(--text-dim); white-space: nowrap; }
.b-detail { font-size: 11px; color: var(--text-dim); margin-top: 4px; max-width: 320px; line-height: 1.5; }
.b-ops { white-space: nowrap; }
.b-ops .btn { margin: 0 4px 4px 0; }

.st {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 500; white-space: nowrap;
}
.st-pending    { background: #e8eefc; color: #1e4ba8; }
.st-working    { background: var(--warn-soft); color: var(--warn); }
.st-previewed  { background: #d6f1ff; color: #10557e; border: 1px solid #b0ddf2; }
.st-done       { background: var(--accent-soft); color: var(--accent); }
.st-failed     { background: var(--danger-soft); color: var(--danger); }
.st-timeout    { background: #f6e2e2; color: #8c1d1d; border: 1px solid #e0aaaa; }
.st-cancelled  { background: #f0efeb; color: var(--text-faint); }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 5px;
  font-size: 11px; background: #f0efeb; color: var(--text-dim);
}
.tag-apply { background: var(--warn-soft); color: var(--warn); }

.warn-text { color: var(--warn); }
.ok-text   { color: var(--accent); }

/* ===================== 模式选择弹窗 ===================== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(28,27,24,.42);
  display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 99;
}
.modal {
  background: var(--surface); border-radius: 14px; padding: 22px 22px 16px;
  width: 100%; max-width: 480px; box-shadow: 0 18px 50px rgba(0,0,0,.22);
}
.modal h3 { margin: 0 0 6px; font-size: 16px; }
.modal-sum { font-size: 12px; color: var(--text-dim); margin-bottom: 14px; }
.modal-opts { display: flex; flex-direction: column; gap: 9px; }
.modal-opt {
  text-align: left; border: 1px solid var(--border-strong); background: var(--surface);
  border-radius: 10px; padding: 11px 14px; cursor: pointer; font: inherit;
  display: flex; flex-direction: column; gap: 3px;
}
.modal-opt:hover { border-color: var(--accent); background: #f5f9fe; }
.modal-opt strong { font-size: 13px; }
.modal-opt span { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.modal-opt.danger:hover { border-color: var(--danger); background: #fdf6f6; }
.modal-foot { margin-top: 14px; text-align: right; }

code {
  font-family: var(--mono); font-size: 12px; background: #f0efeb;
  padding: 1px 5px; border-radius: 4px;
}
a.btn { text-decoration: none; display: inline-block; }

/* ===================== 主应用顶部 ===================== */
header.top {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 24px 12px; background: var(--surface);
  border-bottom: 1px solid var(--border); margin-bottom: 0;
}
header.top .brand {
  font-family: var(--mono); font-size: 13px; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent); font-weight: 600;
}
header.top .me { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
header.top .me #me-name { color: var(--text); font-weight: 500; }
header.top .me .role {
  font-size: 11px; padding: 2px 7px; border-radius: 4px;
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
}
header.top .me .role.admin { background: #fff1d0; color: #8a5a00; }
header.top #btn-logout { padding: 5px 12px; font-size: 12px; }

main.container { padding: 18px 24px 80px; }

/* ===================== 面板 ===================== */
.pane { display: block; }
.pane.hidden { display: none; }
.pane h3 { font-size: 14px; font-weight: 600; margin: 18px 0 8px; }

.row-actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px;
}
.row-actions .muted { font-size: 12px; color: var(--text-dim); }

.msg { display: none; margin: 8px 0; padding: 8px 12px; border-radius: 6px; font-size: 13px; }
.msg.show { display: block; }
.msg.err { background: var(--danger-soft); color: var(--danger); }
.msg:not(.err) { background: var(--accent-soft); color: var(--accent); }

.empty {
  padding: 28px 16px; text-align: center; color: var(--text-faint);
  font-size: 13px; background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}

/* ===================== 账号表格 ===================== */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.tbl th {
  text-align: left; font-size: 11px; color: var(--text-dim); font-weight: 500;
  padding: 8px 10px; background: #faf9f5; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .ops { white-space: nowrap; }
.tbl .ops .btn { margin: 0 3px 3px 0; }

/* 表格内行内 tag 状态 */
.tag.ok   { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft);    color: var(--warn); }
.tag.err  { background: var(--danger-soft);  color: var(--danger); }

code.tok {
  font-family: var(--mono); font-size: 11px; background: #f2f1ed;
  padding: 2px 6px; border-radius: 4px; color: var(--text);
  cursor: pointer; user-select: all;
}
code.tok:hover { background: var(--accent-soft); color: var(--accent); }

/* ===================== 代码块 / 复制 ===================== */
pre.copycode {
  background: #1f1e1b; color: #e6e5e0; border-radius: 8px;
  padding: 12px 14px; font-family: var(--mono); font-size: 11px; line-height: 1.5;
  max-height: 280px; overflow: auto; white-space: pre; margin: 8px 0;
}

.instr {
  background: #f2f1ed; border-radius: 6px; padding: 10px 14px;
  font-size: 12px; color: var(--text-dim); line-height: 1.7; white-space: pre-line;
  margin: 10px 0 0;
}

/* ===================== 上传脚本对话框（slot-0 + slot-30） ===================== */
.up-script {
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  margin: 10px 0; background: #fbfbfa;
}
.up-script-head { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.up-script pre.copycode { max-height: 240px; margin: 6px 0; }

/* ===================== 批次日志 ===================== */
.logs {
  background: #fcfcfb; border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; max-height: 200px; overflow: auto; font-size: 12px;
}
.log { padding: 3px 0; border-bottom: 1px dashed var(--border); }
.log:last-child { border-bottom: none; }
.log .lt { font-family: var(--mono); font-size: 11px; color: var(--text-faint); margin-right: 8px; }

/* ===================== 弹窗扩展 ===================== */
.modal pre { background: #1f1e1b; color: #e6e5e0; border-radius: 6px; padding: 10px 12px; font-size: 11px; max-height: 220px; overflow: auto; white-space: pre-wrap; }
.modal h4 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text-dim); }

/* 二级按钮 */
.btn.secondary { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn.secondary:hover { background: #faf9f5; color: var(--text); }

/* ===================== 新建批次 · ads 搜索表格 ===================== */
.btabs { display: flex; gap: 6px; margin: 14px 0 10px; border-bottom: 1px solid var(--border); }
.btab { background: transparent; border: none; padding: 8px 14px; font-size: 13px; color: var(--text-dim); cursor: pointer; border-bottom: 2px solid transparent; }
.btab:hover { color: var(--text); }
.btab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.btabpane { margin-top: 10px; }
.form-campaign { background: #fafaf8; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.row2 { display: flex; gap: 12px; }
.row2 > label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.row2 > label input, .row2 > label select { width: 100%; }
.ag-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 12px; background: #fff; }
.ag-head { font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; color: var(--text); }
.ag-del, .kw-del, .g-del { background: transparent; border: 1px solid var(--border); color: var(--text-faint); border-radius: 4px; width: 24px; height: 24px; cursor: pointer; line-height: 1; flex: none; }
.ag-del:hover, .kw-del:hover, .g-del:hover { color: #c0392b; border-color: #c0392b; }
.sub { font-size: 12px; color: var(--text-dim); margin: 10px 0 6px; font-weight: 600; }
.kw-tbl, .grid-tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.kw-tbl th, .grid-tbl th { text-align: left; color: var(--text-dim); font-weight: 600; padding: 4px 6px; border-bottom: 1px solid var(--border); }
.kw-tbl td, .grid-tbl td { padding: 3px 4px; border-bottom: 1px solid #f0efea; }
.kw-tbl input, .grid-tbl input, .kw-tbl select, .grid-tbl select { width: 100%; padding: 5px 6px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; }
.rsa-heads, .rsa-descs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.rsa-field { display: flex; flex-direction: column; gap: 2px; }
.rsa-label { font-size: 11px; color: var(--text-faint); }
.rsa-input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; }
.rsa-count { font-size: 10px; color: var(--text-faint); text-align: right; }
.grid-tbl { display: block; overflow-x: auto; white-space: nowrap; }

/* ===================== 新建批次 · 地区/语言多选 + 创建后状态 ===================== */
.tg-block { display: flex; gap: 14px; margin: 12px 0; }
.tg-col { flex: 1; min-width: 0; background: #fafaf8; border: 1px solid var(--border); border-radius: 8px; padding: 10px; }
.tg-head { font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; display: flex; flex-direction: column; gap: 4px; }
.tg-filter { padding: 5px 8px; font-size: 12px; }
.tg-select { width: 100%; margin-top: 6px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 4px; font-size: 12px; background: var(--surface); }
.tg-sel { font-size: 11px; color: var(--text-faint); margin-top: 6px; line-height: 1.5; word-break: break-all; }
.pm-block { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 6px 0 4px; padding: 8px 10px; background: #f5f9fe; border: 1px solid #d9e6f5; border-radius: 8px; }
.pm-label { font-size: 13px; font-weight: 600; color: var(--text); }
.pm-opt { font-size: 13px; color: var(--text-dim); display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.net-note { display: flex; flex-direction: column; justify-content: center; font-size: 11px; color: var(--text-faint); line-height: 1.5; }

/* ===================== 已发布广告管理面板 ===================== */
.pub-acct-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.pub-acct-label select { max-width: 280px; }
.pub-camp { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; background: var(--surface); }
.pub-camp:last-child { margin-bottom: 0; }
.pub-camp-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pub-camp-head > b { font-size: 14px; }
.pub-meta { font-size: 12px; color: var(--text-dim); }
.pub-actions { margin-left: auto; display: flex; gap: 6px; }
.pub-ag { margin-top: 10px; }
.pub-ag th { background: #faf9f5; }
