/* =========================================================
   <agent-run-widget> 样式
   结构：胶囊头部（状态环 · 图标 · 标题 · 计时）+ 可展开的卡片内容
   尺寸：宽 372 · 圆角 20 · 头部高 38 · 步骤行高 27 · 按钮高 34
   ========================================================= */

/* ---- 设计令牌 · 暗色（默认） ---- */
:root,
agent-run-widget[theme="dark"] {
  --arw-surface: #171717;
  --arw-pill: #1c1c1c;
  --arw-border: #262626;
  --arw-shadow: 0 16px 40px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  --arw-text: #c2c2c2;
  --arw-strong: #ececec;
  --arw-btn: #f7f7f7;
  --arw-muted: #8f8f8f;
  --arw-icon: #8f8f8f;
  --arw-icon-active: #e2e2e2;
  --arw-shimmer-base: #808080;
  --arw-shimmer-hi: #f2f2f2;
  --arw-accent: #659cf9;
  --arw-accent-ink: #0d2552;
  --arw-seg: #292929;
  --arw-seg-active: #333c4c;
  --arw-track: #2c2c2c;
  --arw-arc: #d6d6d6;
  --arw-success: #5fb594;
  --arw-btn-border: #2a2a2a;
  --arw-spark: #e07552;
  --arw-hover: rgba(255, 255, 255, 0.06);
}

/* ---- 设计令牌 · 亮色 ---- */
:root[data-theme="light"],
agent-run-widget[theme="light"] {
  --arw-surface: #ffffff;
  --arw-pill: #ffffff;
  --arw-border: #e6e6e3;
  --arw-shadow: 0 1px 2px rgba(20, 20, 20, 0.05), 0 14px 36px rgba(20, 20, 20, 0.08);
  --arw-text: #3b3b3b;
  --arw-strong: #141414;
  --arw-btn: #1a1a1a;
  --arw-muted: #737373;
  --arw-icon: #858585;
  --arw-icon-active: #1f1f1f;
  --arw-shimmer-base: #757575;
  --arw-shimmer-hi: #0f0f0f;
  --arw-accent: #2f6fe4;
  --arw-accent-ink: #ffffff;
  --arw-seg: #ececea;
  --arw-seg-active: #d9e4fa;
  --arw-track: #e8e8e6;
  --arw-arc: #3a3a3a;
  --arw-success: #1f9a6a;
  --arw-btn-border: #e3e3e0;
  --arw-spark: #d9663f;
  --arw-hover: rgba(20, 20, 20, 0.04);
}

/* ---- 宿主 ---- */

agent-run-widget {
  display: block;
  width: 372px;
  max-width: 100%;
  color: var(--arw-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 20px;
  letter-spacing: -0.016em;
  text-align: left;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

agent-run-widget *,
agent-run-widget *::before,
agent-run-widget *::after {
  box-sizing: border-box;
}

agent-run-widget svg {
  display: block;
  flex: none;
}

.arw {
  --arw-shell-bg: var(--arw-pill);
  position: relative;
}

.arw[data-expanded="true"] {
  --arw-shell-bg: var(--arw-surface);
}

/* ---- 外壳：胶囊 / 卡片 ---- */

.arw__shell {
  width: max-content;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--arw-border);
  border-radius: 20px;
  background: var(--arw-shell-bg);
  box-shadow: var(--arw-shadow);
  transition: background-color 0.3s ease;
}

.arw[data-expanded="true"] .arw__shell {
  width: 100%;
}

/* ---- 头部 ---- */

.arw__header {
  display: flex;
  align-items: center;
  width: 100%;
  height: 38px;
  margin: 0;
  padding: 0 13px 0 8px;
  border: 0;
  border-radius: 19px;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-align: left;
  cursor: pointer;
}

.arw__header:focus-visible {
  outline: 2px solid var(--arw-accent);
  outline-offset: -2px;
}

.arw__status {
  position: relative;
  display: block;
  flex: none;
  width: 22px;
  height: 22px;
}

.arw__ring {
  overflow: visible;
  fill: none;
  stroke-linecap: round;
}

.arw__ring-track {
  stroke: var(--arw-track);
  stroke-width: 1.5;
  transition: stroke 0.3s ease;
}

.arw__ring-arc {
  opacity: 0;
  stroke: var(--arw-arc);
  stroke-width: 1.5;
  transform: rotate(-80deg);
  transform-origin: 11px 11px;
  transition: opacity 0.2s ease;
}

.arw__ring-spark {
  stroke: var(--arw-spark);
  stroke-width: 1.35;
  transition: opacity 0.2s ease;
}

.arw__ring-check {
  opacity: 0;
  stroke: var(--arw-success);
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
}

.arw[data-status="running"] .arw__ring-arc,
.arw[data-status="paused"] .arw__ring-arc {
  opacity: 1;
}

.arw[data-status="running"] .arw__ring-arc {
  animation: arw-spin 1.2s linear infinite;
}

.arw[data-status="done"] .arw__ring-track {
  stroke: var(--arw-success);
}

.arw[data-status="done"] .arw__ring-spark {
  opacity: 0;
}

.arw[data-status="done"] .arw__ring-check {
  opacity: 1;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.45s 0.1s ease-out, opacity 0.1s;
}

/* 等待审批：状态环左上角的蓝点 */
.arw__badge {
  position: absolute;
  top: -1px;
  left: 14px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--arw-accent);
  box-shadow: 0 0 0 2px var(--arw-shell-bg);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.2s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.arw[data-status="approval"] .arw__badge {
  opacity: 1;
  transform: none;
}

.arw__header-icon {
  display: flex;
  flex: none;
  width: 16px;
  height: 16px;
  margin: 0 6px 0 8px;
  color: var(--arw-icon-active);
}

.arw__header-icon[hidden] {
  display: none;
}

.arw__title {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--arw-strong);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arw--no-icon .arw__title {
  margin-left: 9px;
}

.arw__timer {
  flex: none;
  margin-left: auto;
  padding-left: 17px;
  color: var(--arw-muted);
  font-variant-numeric: tabular-nums;
}

.arw__timer[hidden] {
  display: none;
}

/* ---- 进行中文字的高光扫过（2.2s 一圈） ---- */

.arw-shimmer {
  color: transparent;
  background-image: linear-gradient(
    90deg,
    var(--arw-shimmer-base) 0%,
    var(--arw-shimmer-base) 40%,
    var(--arw-shimmer-hi) 50%,
    var(--arw-shimmer-base) 60%,
    var(--arw-shimmer-base) 100%
  );
  background-position: 100% 0;
  background-size: 300% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  animation: arw-shimmer 2.2s linear infinite;
}

/* ---- 卡片内容 ---- */

.arw__body {
  padding: 6px 12px 12px;
}

.arw__body[hidden] {
  display: none;
}

.arw__meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 0 1px;
  color: var(--arw-muted);
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
}

.arw__step {
  font-variant-numeric: tabular-nums;
}

/* 分段进度条：高 3 · 段间距 4 */
.arw__progress {
  display: grid;
  grid-template-columns: repeat(var(--arw-seg-count, 6), minmax(0, 1fr));
  gap: 4px;
  height: 3px;
  margin: 8px 0 12px;
}

.arw__seg {
  position: relative;
  display: block;
  overflow: hidden;
  border-radius: 2px;
  background: var(--arw-seg);
  transition: background-color 0.3s ease;
}

.arw__seg.is-current {
  background: var(--arw-seg-active);
}

.arw__seg-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: calc(var(--arw-fill, 0) * 100%);
  border-radius: 2px;
  background: var(--arw-accent);
  transition: width 0.35s ease;
}

/* 步骤列表：最多 5 行，多出来的向上滚动 */
.arw__viewport {
  height: calc(var(--arw-rows, 0) * 27px);
  overflow: hidden;
}

.arw__steps {
  margin: 0;
  padding: 0;
  list-style: none;
  transform: translateY(calc(var(--arw-offset, 0) * -27px));
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.arw__row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 27px;
}

.arw__row-icon {
  display: flex;
  flex: none;
  width: 16px;
  height: 16px;
  color: var(--arw-icon);
  transition: color 0.2s ease;
}

.arw__row-label {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--arw-text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.arw__row-time {
  flex: none;
  min-width: 28px;
  margin-left: auto;
  color: var(--arw-muted);
  font-size: 12px;
  line-height: 16px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.arw__row[data-state="active"] .arw__row-icon {
  color: var(--arw-icon-active);
}

.arw__row[data-state="active"] .arw__row-label:not(.arw-shimmer) {
  color: var(--arw-strong);
}

.arw__row[data-state="waiting"] .arw__row-icon {
  color: var(--arw-accent);
}

.arw__row[data-state="waiting"] .arw__row-label {
  color: var(--arw-strong);
}

.arw__row[data-state="skipped"] .arw__row-label {
  color: var(--arw-muted);
}

/* ---- 底部操作 ---- */

.arw__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 34px;
  margin-top: 13px;
}

.arw__actions {
  display: flex;
  gap: 6px;
}

.arw__btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  margin: 0;
  padding: 0 14px 0 12px;
  border: 1px solid var(--arw-btn-border);
  border-radius: 999px;
  background: transparent;
  color: var(--arw-btn);
  font: inherit;
  font-size: 14px;
  font-weight: 450;
  line-height: 20px;
  letter-spacing: inherit;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.arw__btn:hover {
  background: var(--arw-hover);
}

.arw__btn--primary {
  border-color: transparent;
  background: var(--arw-accent);
  color: var(--arw-accent-ink);
}

.arw__btn--primary:hover {
  background: color-mix(in srgb, var(--arw-accent) 88%, var(--arw-strong));
}

.arw__open {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--arw-text);
  font-size: 14px;
  line-height: 20px;
  text-decoration: none;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.arw__open:hover {
  background: var(--arw-hover);
  color: var(--arw-strong);
}

.arw__btn:focus-visible,
.arw__open:focus-visible {
  outline: 2px solid var(--arw-accent);
  outline-offset: 2px;
}

/* 读屏播报区域 */
.arw__live {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* 程序化更新（首帧、减少动态效果）时关闭过渡 */
.arw--instant,
.arw--instant * {
  transition: none !important;
}

/* ---- 动画 ---- */

@keyframes arw-spin {
  from {
    transform: rotate(-80deg);
  }
  to {
    transform: rotate(280deg);
  }
}

@keyframes arw-shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

/* 减少动态效果：保留设计稿中的静帧 */
@media (prefers-reduced-motion: reduce) {
  .arw,
  .arw * {
    transition: none !important;
    animation: none !important;
  }

  .arw-shimmer {
    background-image: linear-gradient(
      90deg,
      var(--arw-shimmer-hi) 0%,
      var(--arw-shimmer-hi) 22%,
      var(--arw-shimmer-base) 48%,
      var(--arw-shimmer-base) 100%
    );
    background-size: 100% 100%;
  }
}
