:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e4e7ec;
  --text: #1f2329;
  --muted: #8a9099;
  --brand: #b5651d;
  --brand-dark: #8a4d16;
  --ok: #1f9d55;
  --err: #d64545;
  --warn: #c47f17;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

/* ---- 顶栏 ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  padding: 0 24px;
  height: 56px;
}
.brand { font-weight: 700; color: var(--brand-dark); }
.project-switch { margin: 0; }
.project-switch select {
  min-width: 140px; padding: 6px 28px 6px 8px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--text);
}
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.nav a:hover { background: #f0f1f3; }
.nav a.on { background: var(--brand); color: #fff; }
.userbox { color: var(--muted); display: flex; align-items: center; gap: 10px; }
.link-btn { background: none; border: none; color: var(--brand); cursor: pointer; font-size: 14px; }

.container { max-width: 980px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.foot { text-align: center; color: var(--muted); padding: 24px; font-size: 12px; }

/* ---- 卡片 ---- */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card-label { color: var(--muted); font-size: 12px; }
.card-value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.card-value.small { font-size: 15px; }
.card-value.ok { color: var(--ok); }
.card-value.muted { color: var(--muted); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; margin-bottom: 18px; }

/* ---- 表格 ---- */
table { border-collapse: collapse; width: 100%; }
.kv th { text-align: left; color: var(--muted); font-weight: 500; width: 160px; padding: 6px 8px; vertical-align: top; }
.kv td { padding: 6px 8px; }
.data { font-size: 13px; }
.data th, .data td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; }
.data th { color: var(--muted); font-weight: 500; background: #fafbfc; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; color: #555; }

/* ---- 状态标签 ---- */
.status { padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.status.success { background: #e6f5ec; color: var(--ok); }
.status.partial { background: #fdf3e0; color: var(--warn); }
.status.failed { background: #fbe9e9; color: var(--err); }
.status.running { background: #e8f0fe; color: #2b6cb0; }
.tag { padding: 2px 8px; border-radius: 4px; font-size: 12px; }
.tag.on { background: #e6f5ec; color: var(--ok); }
.tag.off { background: #f0f1f3; color: var(--muted); }
.err-text { color: var(--err); }

/* ---- 表单 ---- */
label { display: block; margin-bottom: 12px; color: #444; }
input[type=text], input[type=number], input[type=password], textarea, select {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 14px;
}
textarea { resize: vertical; font-family: inherit; }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 18px; }
.btn-row { margin: 8px 0; }

.btn {
  display: inline-block; padding: 9px 18px; border-radius: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  cursor: pointer; font-size: 14px; text-decoration: none; margin-right: 8px;
}
.btn:hover { background: #f5f6f8; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; }
.btn.block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.hint { color: var(--muted); font-size: 12px; margin-top: 8px; }
.muted { color: var(--muted); }

/* ---- 提示条 ---- */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.alert.info { background: #e8f0fe; color: #2b6cb0; }
.alert.ok { background: #e6f5ec; color: var(--ok); }
.alert.err { background: #fbe9e9; color: var(--err); }

/* ---- 登录页 ---- */
.login-body { background: linear-gradient(135deg, #f0e6d8, #f5f6f8); display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: #fff; padding: 36px; border-radius: 14px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.08); }
.login-card h1 { text-align: center; color: var(--brand-dark); margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 20px; font-size: 13px; }
.link { color: var(--brand); text-decoration: none; }
.link:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .topbar { height: auto; min-height: 56px; flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  .cards { grid-template-columns: repeat(2, 1fr); }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .metrics2 { grid-template-columns: 1fr; }
}

/* ---- 危险按钮 / 行内表单 ---- */
.btn.danger { background: #fff; border-color: var(--err); color: var(--err); }
.btn.danger:hover { background: var(--err); color: #fff; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline-form input { width: 120px; margin: 0; }

/* ---- 仪表盘 ---- */
.metrics2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.metric-box { border: 1px solid var(--line); border-radius: 10px; padding: 16px; background: #fff; }
.metric-box h3 { font-size: 13px; color: var(--muted); margin: 0 0 12px; font-weight: 600; }
.bars { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: grid; grid-template-columns: 96px 1fr 36px; align-items: center; gap: 8px; font-size: 12px; }
.bar-track { background: #eef0f3; border-radius: 5px; height: 14px; overflow: hidden; }
.bar-fill { background: var(--brand); height: 100%; border-radius: 5px; }
.bar-fill.green { background: var(--ok); }
.bar-num { text-align: right; color: var(--muted); }
.trend { display: flex; align-items: flex-end; gap: 6px; height: 96px; padding-top: 6px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; }
.trend-bar { width: 70%; background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; }
.trend-label { font-size: 10px; color: var(--muted); }
.big-num { font-size: 26px; font-weight: 700; }
.rate-ok { color: var(--ok); }
.rate-warn { color: var(--warn); }

/* ---- 折叠面板（产品页 / 首页“上次生成”） ---- */
details.product-fold { padding: 0; }
details.product-fold > .fold-head {
  list-style: none; cursor: pointer; padding: 14px 18px;
  display: flex; align-items: center; gap: 10px; font-size: 16px; font-weight: 600;
  user-select: none;
}
details.product-fold > .fold-head::-webkit-details-marker { display: none; }
details.product-fold > .fold-head::before {
  content: "\25B8"; color: var(--brand); font-size: 13px; transition: transform .15s; flex: none;
}
details.product-fold[open] > .fold-head::before { transform: rotate(90deg); }
details.product-fold[open] > .fold-head { border-bottom: 1px solid var(--line); }
.fold-head:hover { background: #fafafa; }
.fold-title { flex: 1; }
.fold-body { padding: 18px; }

/* ---- 首页紧凑布局：一屏内看完，往下滑一屏到底 ---- */
.dash .cards { gap: 10px; margin-bottom: 12px; }
.dash .card { padding: 11px 14px; }
.dash .card-label { font-size: 11px; }
.dash .card-value { font-size: 18px; margin-top: 2px; }
.dash .panel { padding: 14px 16px; margin-bottom: 12px; }
.dash .panel h2 { margin-bottom: 8px; }
.dash .metric-box { padding: 12px; }
.dash .metric-box h3 { margin-bottom: 8px; }
.dash .metrics2 { gap: 12px; }
.dash .trend { height: 96px; }
.dash .big-num { font-size: 22px; }
.dash .hint { margin-top: 6px; }

/* 首页放宽到宽屏比例（仅首页，其它页不变） */
.dash { width: 94vw; max-width: 1300px; position: relative; left: 50%; transform: translateX(-50%); }
/* 数据概览左右分栏：趋势(宽) | 脚本分布(窄) */
.dash-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 14px; margin-bottom: 14px; }
/* 各产品 | 各编导 | 失败原因 三栏横排 */
.dash-grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }

/* 产品页：保存 / 删除 同行，删除推到最右防误点 */
.action-bar { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.action-bar .del-form { margin: 0 0 0 auto; }

@media (max-width: 900px) {
  .dash { width: 100%; left: auto; transform: none; }
  .dash-grid, .dash-grid3 { grid-template-columns: 1fr; }
}
