/* Material 3（含 Expressive 形状指引）
 *
 * 形状层级刻意分级，遵循两条规则：
 *   - 重要动作不能给小圆角（Smaller shapes can result in essential actions looking less important）
 *   - 用形状打破节奏来突出某个元素（Break from the surrounding shape style）
 *
 *   36   hero            最大容器，锚定页面
 *   28   卡片 / 面板      常规容器
 *   24   统计块 / 主按钮   主按钮故意用大圆角矩形，与药丸形次级按钮形成对比
 *   20   代码块 / toast
 *   16   输入框
 *   999  次级按钮 / chip  低权重
 *
 * 颜色 token 由 ui/theme.ts 运行时按种子色生成。
 */

@font-face {
  font-family: "Roboto";
  src: url("./fonts/roboto-var.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  /* 首屏兜底（JS 执行前） */
  --md-sys-color-primary: #4f5bd5;
  --md-sys-color-on-primary: #ffffff;
  --md-sys-color-primary-container: #dfe0ff;
  --md-sys-color-on-primary-container: #000e5d;
  --md-sys-color-secondary-container: #e2e0f9;
  --md-sys-color-on-secondary-container: #191a2c;
  --md-sys-color-tertiary-container: #ffd8ee;
  --md-sys-color-on-tertiary-container: #370726;
  --md-sys-color-surface: #fbf8ff;
  --md-sys-color-surface-container-lowest: #ffffff;
  --md-sys-color-surface-container-low: #f5f2fa;
  --md-sys-color-surface-container: #efedf4;
  --md-sys-color-surface-container-high: #e9e7ef;
  --md-sys-color-surface-container-highest: #e4e1e9;
  --md-sys-color-on-surface: #1b1b21;
  --md-sys-color-on-surface-variant: #46464f;
  --md-sys-color-outline: #777680;
  --md-sys-color-outline-variant: #c6c5d0;
  --md-sys-color-error: #ba1a1a;
  --md-sys-color-error-container: #ffdad6;
  --md-sys-color-on-error-container: #410002;

  --md-ref-typeface-brand: "Roboto", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --md-ref-typeface-plain: "Roboto", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;

  --page-max: 1040px;

  /* 形状层级 */
  --shape-hero: 36px;
  --shape-card: 28px;
  --shape-accent: 24px;
  --shape-inner: 20px;
  --shape-field: 16px;
  --shape-pill: 999px;

  --hairline: 1px solid color-mix(in srgb, var(--md-sys-color-outline-variant) 58%, transparent);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--md-sys-color-surface-container-low);
}

html,
body {
  margin: 0;
  padding: 0;
  color: var(--md-sys-color-on-surface);
  font-family: var(--md-ref-typeface-plain);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--md-sys-color-surface-container-low);
}

/* ---------------------------------------------------------------- 顶栏 */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: var(--hairline);
}

.app-bar__inner {
  max-width: var(--page-max);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-bar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--md-sys-color-primary);
  color: var(--md-sys-color-on-primary);
  font-weight: 700;
  font-size: 15px;
}

.tabs-bar {
  position: sticky;
  top: 60px;
  z-index: 9;
  background: color-mix(in srgb, var(--md-sys-color-surface-container-low) 92%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: var(--hairline);
}

.tabs {
  display: block;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 20px;
  --md-primary-tab-container-color: transparent;
}

/* ---------------------------------------------------------------- 布局 */

.page {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 40px 20px calc(72px + env(safe-area-inset-bottom));
}

@media (min-width: 900px) {
  .page {
    padding-inline: 24px;
  }
}

.view {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

#pending {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.muted {
  color: var(--md-sys-color-on-surface-variant);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

.foot {
  margin-top: 44px;
  text-align: center;
  color: var(--md-sys-color-outline);
}

.page-head h1 {
  margin: 0 0 10px;
  font-weight: 400;
  letter-spacing: -0.025em;
}

.page-head p {
  margin: 0;
}

/* ---------------------------------------------------------------- Hero（最大容器） */

.hero {
  position: relative;
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
  border-radius: var(--shape-hero);
  border: var(--hairline);
  padding: 34px 30px 28px;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  right: -70px;
  top: -90px;
  width: 240px;
  height: 240px;
  border-radius: 50%;
  background: color-mix(in srgb, var(--md-sys-color-on-primary-container) 8%, transparent);
  pointer-events: none;
}

.hero__eyebrow {
  margin: 0 0 14px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.72;
  font-size: 11.5px;
}

.hero__title {
  margin: 0;
  font-weight: 400;
  letter-spacing: -0.03em;
  max-width: 20ch;
}

.hero__sub {
  margin: 14px 0 0;
  max-width: 42ch;
  opacity: 0.82;
}

.hero__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 15px;
  border-radius: var(--shape-pill);
  background: color-mix(in srgb, var(--md-sys-color-on-primary-container) 10%, transparent);
  color: var(--md-sys-color-on-primary-container);
  font-size: 12.5px;
  font-weight: 500;
}

.chip--strong {
  background: var(--md-sys-color-on-primary-container);
  color: var(--md-sys-color-primary-container);
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- 状态 */

.state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 14px;
  padding: 44px 24px;
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--shape-card);
  border: var(--hairline);
}

.state__icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
}

.state h2 {
  margin: 0;
}

.state p {
  margin: 0;
  max-width: 34ch;
}

/* ---------------------------------------------------------------- 面板 */

.panel {
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--shape-card);
  border: var(--hairline);
  padding: 32px;
}

.panel__head h2 {
  margin: 0 0 10px;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.panel__head p {
  margin: 0;
  line-height: 1.65;
  max-width: 58ch;
}

.panel__head a {
  color: var(--md-sys-color-primary);
  text-underline-offset: 3px;
}

/* ---------------------------------------------------------------- 步骤 */

.steps {
  list-style: none;
  margin: 28px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.step {
  display: flex;
  gap: 16px;
}

.step__avatar {
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
}

.step__body {
  flex: 1;
  min-width: 0;
}

.step__body h3 {
  margin: 6px 0 6px;
  font-weight: 500;
}

.step__body > p {
  margin: 0 0 12px;
  color: var(--md-sys-color-on-surface-variant);
}

.tone-primary {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.tone-secondary {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.tone-tertiary {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.tone-error {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

md-outlined-text-field {
  width: 100%;
  --md-outlined-text-field-container-shape: var(--shape-field);
}

/* ---------------------------------------------------------------- 代码块 */

.code {
  background: var(--md-sys-color-surface-container-high);
  border-radius: var(--shape-inner);
  overflow: hidden;
}

.code__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 8px 8px 16px;
}

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

.code pre {
  margin: 0;
  padding: 4px 18px 18px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ---------------------------------------------------------------- 按钮 */

.panel__actions {
  margin-top: 30px;
}

md-filled-button,
md-outlined-button,
md-filled-tonal-button {
  --md-filled-button-container-shape: var(--shape-pill);
  --md-outlined-button-container-shape: var(--shape-pill);
  --md-filled-tonal-button-container-shape: var(--shape-pill);
  min-height: 48px;
}

/* 主操作：刻意脱离药丸节奏，用大圆角矩形 + 更高体量强调 */
.panel__actions md-filled-button {
  width: 100%;
  min-height: 58px;
  --md-filled-button-container-shape: var(--shape-accent);
  font-size: 15px;
  letter-spacing: 0.01em;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 18px;
}

/* ---------------------------------------------------------------- 卡片 */

.card {
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: var(--shape-card);
  border: var(--hairline);
  padding: 30px;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 14px;
}

.filter-row md-outlined-text-field {
  flex: 1 1 280px;
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.filter-row .filter-actions {
  margin-top: 0;
}

.filter-actions md-filled-button,
.filter-actions md-outlined-button {
  min-height: 44px;
}

/* ---------------------------------------------------------------- 统计 */

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat {
  position: relative;
  border-radius: var(--shape-accent);
  padding: 20px 18px 18px;
  background: var(--md-sys-color-surface-container-high);
}

.stat.tone-primary {
  background: var(--md-sys-color-primary-container);
  color: var(--md-sys-color-on-primary-container);
}

.stat.tone-secondary {
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
}

.stat.tone-tertiary {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.stat b {
  display: block;
  font-size: 36px;
  font-weight: 500;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.stat span {
  font-size: 12px;
  opacity: 0.78;
}

.stat svg {
  position: absolute;
  top: 18px;
  right: 16px;
  opacity: 0.45;
}

.chain {
  margin: 16px 0 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: var(--shape-pill);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface-variant);
  font-size: 12.5px;
}

.badge.ok {
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

.badge.bad {
  background: var(--md-sys-color-error-container);
  color: var(--md-sys-color-on-error-container);
}

/* ---------------------------------------------------------------- 表格 */

.table-wrap {
  overflow-x: auto;
  margin: 0 -8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

th,
td {
  text-align: left;
  padding: 15px 8px;
  border-bottom: var(--hairline);
  vertical-align: top;
}

th {
  color: var(--md-sys-color-on-surface-variant);
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: color-mix(in srgb, var(--md-sys-color-on-surface) 3%, transparent);
}

.table-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: var(--shape-pill);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.cell {
  min-width: 0;
}

.cell.mono {
  white-space: nowrap;
}

.cell-sub {
  display: block;
  margin-top: 3px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: 11.5px;
  max-width: 100%;
  overflow: hidden;
  word-break: break-word;
}

td.mono {
  white-space: nowrap;
}

td.wrap,
td.muted {
  word-break: break-word;
}

td:has(.cell:empty) {
  display: none;
}

/* 窄屏：表格降级为 label + 内容堆叠 */
@media (max-width: 899px) {
  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tr {
    padding: 15px 0;
    border-bottom: var(--hairline);
  }

  tbody tr:last-child {
    border-bottom: 0;
  }

  tbody tr:hover td {
    background: transparent;
  }

  td {
    border: 0;
    padding: 4px 0;
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
  }

  td::before {
    content: attr(data-label);
    color: var(--md-sys-color-on-surface-variant);
    font-size: 11.5px;
    padding-top: 2px;
  }

  td:empty {
    display: none;
  }

  .stat {
    padding: 15px 14px;
  }

  .stat b {
    font-size: 26px;
  }

  .stat svg {
    display: none;
  }
}

/* ---------------------------------------------------------------- 对话框 */

md-dialog {
  --md-dialog-container-shape: var(--shape-card);
}

.dialog-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
}

.dialog-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
}

/* ---------------------------------------------------------------- Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(560px, calc(100vw - 32px));
  padding: 14px 20px;
  border-radius: var(--shape-inner);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  font-size: 13.5px;
  z-index: 20;
}

/* ---------------------------------------------------------------- 预览提示 */

.preview-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 14px 20px;
  border-radius: var(--shape-inner);
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  font-size: 13px;
}

/* ---------------------------------------------------------------- 动效 */

@media (prefers-reduced-motion: no-preference) {
  @keyframes rise {
    from {
      opacity: 0;
      transform: translateY(16px);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  @keyframes pop {
    from {
      opacity: 0;
      transform: scale(0.86);
    }
    to {
      opacity: 1;
      transform: none;
    }
  }

  /* 内容块依次升起，形成节奏 */
  .view > * {
    animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.25, 1) both;
  }

  .view > *:nth-child(2) {
    animation-delay: 0.05s;
  }

  .view > *:nth-child(3) {
    animation-delay: 0.1s;
  }

  .view > *:nth-child(4) {
    animation-delay: 0.15s;
  }

  .view > *:nth-child(5) {
    animation-delay: 0.2s;
  }

  .view > *:nth-child(6) {
    animation-delay: 0.25s;
  }

  .stat b {
    animation: pop 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
  }

  .card {
    transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.25, 1);
  }

  .card:hover {
    transform: translateY(-2px);
  }

  /* 按下时形状轻微变化，呼应 M3 的 shape morph */
  md-filled-button {
    transition:
      transform 0.12s ease,
      border-radius 0.18s ease;
  }

  md-filled-button:active {
    transform: scale(0.975);
  }

  .panel__actions md-filled-button:active {
    --md-filled-button-container-shape: 18px;
  }

  .stat,
  .chip,
  .status-chip {
    transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.25, 1);
  }

  .stat:hover {
    transform: translateY(-2px) scale(1.01);
  }
}
