:root {
  --bg: #f6f7fb;
  --card: #fff;
  --text: #12141c;
  --muted: #747b8d;
  --line: #e6e9f1;
  --purple: #6d4dff;
  --dark: #11131b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 0%, rgba(109, 77, 255, .14), transparent 26%),
    linear-gradient(180deg, #fff, var(--bg));
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

.history-header {
  max-width: 1220px;
  margin: 0 auto;
  padding: 34px 24px 18px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
}
.back-link {
  display: inline-flex;
  margin-bottom: 18px;
  color: var(--purple);
  font-weight: 900;
  text-decoration: none;
}
h1 { margin: 0; font-size: clamp(30px, 5vw, 54px); letter-spacing: -1px; }
p { color: var(--muted); line-height: 1.7; }
.history-header p { max-width: 680px; margin: 10px 0 0; }
#refreshBtn {
  border: 0;
  border-radius: 999px;
  background: var(--dark);
  color: #fff;
  padding: 13px 22px;
  font-weight: 900;
  cursor: pointer;
}

.history-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 10px 24px 60px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 18px;
}
.stats-grid article {
  background: rgba(255,255,255,.86);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 16px 45px rgba(20, 24, 40, .06);
}
.stats-grid b { display: block; font-size: 34px; }
.stats-grid span { color: var(--muted); font-weight: 700; }

.history-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 10px;
  padding: 10px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
}
.history-tabs button {
  flex: 1;
  border: 0;
  border-radius: 999px;
  padding: 13px 18px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}
.history-tabs button.active { background: var(--dark); color: #fff; }

.history-panel { display: none; }
.history-panel.active { display: block; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin: 20px 0 14px;
}
.panel-head h2 { margin: 0; font-size: 26px; }
.panel-head p { margin: 0; max-width: 660px; }
code {
  color: var(--purple);
  background: #f0edff;
  border-radius: 8px;
  padding: 2px 6px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}
.history-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  overflow: hidden;
  box-shadow: 0 18px 45px rgba(20, 24, 40, .07);
}
.history-card .card-body { padding: 16px; }
.history-card h3 { margin: 0 0 8px; font-size: 17px; }
.history-card small { color: var(--muted); display: block; line-height: 1.6; word-break: break-all; }
.history-card video,
.history-card img,
.svg-preview {
  width: 100%;
  aspect-ratio: 16 / 10;
  display: block;
  object-fit: cover;
  background: #edeff5;
}
.svg-preview {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 900;
}
.status-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 9px;
  margin-bottom: 8px;
  background: #eefbf1;
  color: #087a2d;
  font-weight: 900;
  font-size: 12px;
}
.status-pill.pending { background: #fff7de; color: #946500; }
.status-pill.failed { background: #ffecec; color: #b62424; }
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.actions a,
.actions button {
  border: 0;
  border-radius: 12px;
  padding: 10px 12px;
  background: #f1f3f8;
  color: var(--dark);
  font-weight: 900;
  text-decoration: none;
  cursor: pointer;
}
.actions a.primary { background: var(--dark); color: #fff; }

.workflow-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
}
.workflow-list {
  display: grid;
  gap: 12px;
}
.workflow-item {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  padding: 14px;
  cursor: pointer;
  text-align: left;
}
.workflow-item.active { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(109,77,255,.12); }
.workflow-item b { display: block; margin-bottom: 6px; }
.workflow-item span { color: var(--muted); font-size: 13px; line-height: 1.6; }
.workflow-detail {
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: #fff;
  padding: 22px;
  box-shadow: 0 18px 45px rgba(20, 24, 40, .06);
}
.workflow-detail h3 { margin: 0 0 10px; font-size: 24px; }
.detail-block {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 16px;
}
.detail-block pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7f8fb;
  border-radius: 16px;
  padding: 14px;
  color: #222631;
  line-height: 1.7;
}

.empty {
  grid-column: 1 / -1;
  padding: 40px;
  border: 1px dashed #cfd4df;
  border-radius: 24px;
  color: var(--muted);
  background: rgba(255,255,255,.7);
  text-align: center;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  opacity: 0;
  background: var(--dark);
  color: #fff;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 900;
  transition: .2s;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

@media (max-width: 980px) {
  .history-header, .panel-head { flex-direction: column; align-items: stretch; }
  .stats-grid, .card-grid, .workflow-layout { grid-template-columns: 1fr; }
  .history-tabs { border-radius: 22px; flex-direction: column; }
}
