/* =========================================================================
   dingtalk-ai-cs 运营后台 · 样式（原生 CSS，无框架依赖）
   布局：顶栏 + 左栏导航 + 内容区（六页共享，见 PROTOTYPE.md §0）
   ========================================================================= */
:root {
  --c-blue: #1677ff;
  --c-blue-bg: #e8f1ff;
  --c-green: #12a150;
  --c-green-bg: #e6f7ee;
  --c-orange: #d97706;
  --c-orange-bg: #fff4e5;
  --c-red: #d92d20;
  --c-red-bg: #fdeceb;
  --c-gray: #6b7280;
  --c-gray-bg: #f1f2f4;
  --c-border: #e5e7eb;
  --c-text: #1f2329;
  --c-sub: #6b7280;
  --c-bg: #f5f6f8;
  --radius: 6px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--c-text);
  background: var(--c-bg);
}
a { color: var(--c-blue); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
code, .mono { font-family: Menlo, Consolas, monospace; }

/* ---------------- 顶栏 ---------------- */
#topbar {
  height: 52px; display: flex; align-items: center; gap: 14px;
  padding: 0 16px; background: #fff; border-bottom: 1px solid var(--c-border);
  position: sticky; top: 0; z-index: 30;
}
#topbar .brand { font-weight: 600; font-size: 15px; }
.env-badge {
  font-size: 12px; padding: 2px 8px; border-radius: 10px;
  background: var(--c-orange-bg); color: var(--c-orange); border: 1px solid #f7d9ab;
}
#topbar .spacer { flex: 1; }
#topbar .who { color: var(--c-sub); }
.demo-badge {
  font-size: 12px; padding: 2px 8px; border-radius: 10px;
  background: var(--c-red-bg); color: var(--c-red); border: 1px solid #f5c2bd;
}
#demo-banner {
  display: none; padding: 8px 16px; background: #fff8e6; color: #7a4b00;
  border-bottom: 1px solid #f3e0b3; font-size: 13px;
}
#demo-banner b { color: #a35b00; }

/* ---------------- 主体骨架 ---------------- */
#shell { display: flex; min-height: calc(100vh - 53px); }
#sidebar {
  width: 184px; flex: 0 0 184px; background: #fff; border-right: 1px solid var(--c-border);
  padding: 12px 0;
}
#sidebar .nav-item {
  display: block; padding: 10px 18px; color: var(--c-text); cursor: pointer;
  border-left: 3px solid transparent;
}
#sidebar .nav-item:hover { background: #f7f8fa; text-decoration: none; }
#sidebar .nav-item.active { background: var(--c-blue-bg); color: var(--c-blue); border-left-color: var(--c-blue); font-weight: 600; }
#content { flex: 1; padding: 16px 20px 40px; min-width: 0; }
.page-title { font-size: 18px; font-weight: 600; margin: 0 0 4px; }
.page-desc { color: var(--c-sub); font-size: 13px; margin: 0 0 14px; }

/* ---------------- 卡片 / 区块 ---------------- */
.card { background: #fff; border: 1px solid var(--c-border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card > h3 { margin: 0 0 10px; font-size: 14px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.filters { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------------- 表单控件 ---------------- */
button, .btn {
  font: inherit; padding: 6px 12px; border-radius: var(--radius); cursor: pointer;
  border: 1px solid var(--c-border); background: #fff; color: var(--c-text);
}
button:hover:not(:disabled) { border-color: #c9ced6; background: #fafbfc; }
button.primary { background: var(--c-blue); border-color: var(--c-blue); color: #fff; }
button.primary:hover:not(:disabled) { background: #0e63d6; border-color: #0e63d6; }
button.danger { background: #fff; border-color: #efb4b0; color: var(--c-red); }
button.danger:hover:not(:disabled) { background: var(--c-red-bg); }
button:disabled { opacity: .6; cursor: not-allowed; }
button.link { border: none; background: none; color: var(--c-blue); padding: 2px 4px; }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
input[type=text], input[type=number], input[type=search], input[type=datetime-local], input[type=password], select, textarea {
  font: inherit; padding: 5px 8px; border: 1px solid #d0d5dd; border-radius: var(--radius);
  background: #fff; color: var(--c-text); max-width: 100%;
}
textarea { width: 100%; min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c-blue-bg); border-color: var(--c-blue); }
label.inline { display: inline-flex; align-items: center; gap: 6px; }
.field { margin-bottom: 12px; }
.field > label { display: block; margin-bottom: 4px; color: #374151; }
.field .hint { color: var(--c-sub); font-size: 12px; }
.field .req::after { content: " *"; color: var(--c-red); }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

/* ---------------- 表格 ---------------- */
table.grid { width: 100%; border-collapse: collapse; background: #fff; }
table.grid th, table.grid td {
  text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--c-border); vertical-align: top;
}
table.grid th { background: #fafbfc; font-weight: 600; color: #374151; white-space: nowrap; }
table.grid tr.row-failed td { background: #fffafa; }
table.grid tr.expandable { cursor: pointer; }
table.grid td.ops { white-space: nowrap; }
table.grid td.truncate { max-width: 320px; }
.ellipsis { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.empty { padding: 28px; text-align: center; color: var(--c-sub); }
.sub { color: var(--c-sub); font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------------- 状态标签（颜色严格按 PROTOTYPE §0） ---------------- */
.tag { display: inline-block; font-size: 12px; line-height: 18px; padding: 1px 8px; border-radius: 10px; white-space: nowrap; }
.tag-blue   { background: var(--c-blue-bg);   color: var(--c-blue);   border: 1px solid #bcd7ff; }
.tag-green  { background: var(--c-green-bg);  color: var(--c-green);  border: 1px solid #b7e6cb; }
.tag-orange { background: var(--c-orange-bg); color: var(--c-orange); border: 1px solid #f7d9ab; }
.tag-red    { background: var(--c-red-bg);    color: var(--c-red);    border: 1px solid #f5c2bd; }
.tag-gray   { background: var(--c-gray-bg);   color: var(--c-gray);   border: 1px solid #dcdfe4; }
.spinner {
  display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: -1px;
  border: 2px solid #bcd7ff; border-top-color: var(--c-blue); border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- 分页 ---------------- */
.pager { display: flex; align-items: center; gap: 6px; margin-top: 12px; color: var(--c-sub); flex-wrap: wrap; }
.pager button { min-width: 30px; }
.pager button.cur { border-color: var(--c-blue); color: var(--c-blue); font-weight: 600; }

/* ---------------- 警示条 / 提示 ---------------- */
.warn-bar {
  background: #fffbe6; border: 1px solid #f5e08a; color: #7a5b00;
  padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px;
}
.error-text { color: var(--c-red); font-size: 12px; }
.gap-note { background: var(--c-gray-bg); border: 1px dashed #c4c9d1; color: #4b5563; padding: 8px 10px; border-radius: var(--radius); font-size: 12px; margin-bottom: 10px; }

/* ---------------- Toast ---------------- */
#toast-wrap { position: fixed; top: 62px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  min-width: 220px; max-width: 420px; padding: 10px 12px; border-radius: var(--radius);
  background: #fff; border: 1px solid var(--c-border); box-shadow: 0 6px 18px rgba(16,24,40,.12); font-size: 13px;
}
.toast.ok { border-left: 4px solid var(--c-green); }
.toast.err { border-left: 4px solid var(--c-red); }
.toast.info { border-left: 4px solid var(--c-blue); }

/* ---------------- Modal ---------------- */
#modal-mask {
  position: fixed; inset: 0; background: rgba(16,24,40,.45); z-index: 60;
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; overflow: auto;
}
.modal {
  background: #fff; border-radius: 8px; width: 560px; max-width: 100%;
  box-shadow: 0 12px 32px rgba(16,24,40,.2);
}
.modal.wide { width: 880px; }
.modal-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--c-border); }
.modal-head h4 { margin: 0; font-size: 15px; flex: 1; }
.modal-head .x { border: none; background: none; font-size: 18px; line-height: 1; color: var(--c-sub); cursor: pointer; }
.modal-body { padding: 14px 16px; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* ---------------- P5 看板 ---------------- */
.metric-cards { display: flex; gap: 12px; flex-wrap: wrap; }
.metric-card {
  flex: 1 1 150px; min-width: 150px; background: #fff; border: 1px solid var(--c-border);
  border-radius: var(--radius); padding: 12px; cursor: pointer;
}
.metric-card:hover { border-color: var(--c-blue); box-shadow: 0 2px 8px rgba(22,119,255,.12); }
.metric-card .k { color: var(--c-sub); font-size: 12px; }
.metric-card .v { font-size: 22px; font-weight: 600; margin-top: 4px; }
.metric-card .go { color: var(--c-blue); font-size: 12px; margin-top: 4px; }
.bar-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.bar-row .name { width: 110px; flex: 0 0 110px; }
.bar-track { flex: 1; background: #f1f2f4; border-radius: 4px; height: 16px; overflow: hidden; min-width: 80px; }
.bar-fill { height: 100%; background: var(--c-blue); border-radius: 4px; }
.bar-row .val { width: 120px; flex: 0 0 120px; color: var(--c-sub); font-size: 12px; }
.samples { margin: 6px 0 0; padding-left: 18px; columns: 2; }
.samples li { margin-bottom: 2px; }

/* ---------------- diff ---------------- */
.diff-add { background: var(--c-green-bg); color: #0b7a3c; text-decoration: none; }
.diff-del { background: var(--c-red-bg); color: var(--c-red); text-decoration: line-through; }
table.diff td, table.diff th { vertical-align: top; }
table.diff td.ver { width: 44%; white-space: pre-wrap; word-break: break-word; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--c-border); padding: 0 0 10px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--c-blue); }
.timeline .t { color: var(--c-sub); font-size: 12px; }
