:root {
  color-scheme: light;
  --canvas: #fbfbfd;
  --paper: rgba(255, 255, 255, 0.82);
  --paper-solid: #ffffff;
  --ink: #1d1d1f;
  --ink-secondary: #424245;
  --muted: #86868b;
  --line: rgba(0, 0, 0, 0.06);
  --line-strong: rgba(0, 0, 0, 0.12);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-tint: rgba(0, 113, 227, 0.06);
  --accent-gradient: linear-gradient(135deg, #0071e3 0%, #00c6ff 100%);
  --hero-gradient: linear-gradient(135deg, rgba(0, 113, 227, 0.07) 0%, rgba(94, 92, 230, 0.04) 50%, rgba(0, 198, 255, 0.05) 100%);
  --good: #34c759;
  --good-tint: rgba(52, 199, 89, 0.10);
  --good-ink: #248a3d;
  --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.02), 0 4px 12px rgba(0, 0, 0, 0.03);
  --shadow-card: 0 4px 24px -2px rgba(0, 0, 0, 0.03), 0 1px 2px rgba(0, 0, 0, 0.02);
  --shadow-card-hover: 0 12px 32px -4px rgba(0, 0, 0, 0.07), 0 2px 6px rgba(0, 0, 0, 0.03);
  --shadow-dialog: 0 32px 72px -16px rgba(0, 0, 0, 0.22), 0 12px 28px -6px rgba(0, 0, 0, 0.08);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --radius-pill: 9999px;
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "HarmonyOS Sans", "vivo Sans", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background-color: var(--canvas);
  background-image: 
    radial-gradient(circle at 10% 8%, rgba(0, 113, 227, 0.038) 0%, transparent 45%),
    radial-gradient(circle at 90% 12%, rgba(88, 86, 214, 0.028) 0%, transparent 45%),
    radial-gradient(circle at 50% 90%, rgba(0, 198, 255, 0.025) 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--ink);
  min-height: 100vh;
}

.shell {
  max-width: 1120px;
  margin: auto;
  padding: 0 32px 64px;
}

/* 顶栏 Header - Apple 磨砂通透感 & 悬浮药丸导航 */
.top {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 60px;
  margin: 0 -32px;
  padding: 0 32px;
  backdrop-filter: blur(28px) saturate(190%);
  -webkit-backdrop-filter: blur(28px) saturate(190%);
  background: rgba(251, 251, 253, 0.80);
  border-bottom: 0.5px solid var(--line);
}

a { color: var(--accent); text-decoration: none; transition: all .18s ease; }
a:hover { opacity: .85; }

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -.02em;
}

.brand-mark {
  height: 32px;
  width: 32px;
  display: grid;
  place-items: center;
  background: var(--accent-gradient);
  color: white;
  border-radius: 10px;
  box-shadow: 0 2px 10px rgba(0, 113, 227, 0.28);
  transition: transform .2s ease;
}

.brand:hover .brand-mark {
  transform: scale(1.04);
}

/* 顶级 Floating Segmented Pill 导航 */
nav {
  display: flex;
  gap: 4px;
  align-items: center;
  background: rgba(0, 0, 0, 0.035);
  padding: 4px;
  border-radius: var(--radius-pill);
  border: 0.5px solid rgba(0, 0, 0, 0.04);
}

nav a {
  display: flex;
  align-items: center;
  padding: 5px 14px;
  color: var(--muted);
  font-weight: 500;
  font-size: 13.5px;
  border-radius: var(--radius-pill);
  border: none;
  white-space: nowrap;
  transition: all .2s cubic-bezier(0.16, 1, 0.3, 1);
}

nav a:hover {
  color: var(--ink);
  background: rgba(255, 255, 255, 0.55);
}

nav a[aria-current] {
  color: var(--ink);
  background: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 0.5px 1px rgba(0, 0, 0, 0.04);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

main { padding-top: 32px; }
.heading { margin-bottom: 24px; }
h1, h2, p, dd { margin: 0; }

h1 {
  font-size: 32px;
  line-height: 1.22;
  font-weight: 700;
  letter-spacing: -.035em;
  color: var(--ink);
}

h2 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.02em;
  color: var(--ink);
}

/* Panel 面板系统 - Apple / vivo 超椭圆超薄视网膜玻璃拟态 */
.panel, .metrics {
  background: var(--paper);
  border: 0.5px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  transition: box-shadow .24s ease, border-color .24s ease;
}

.connection, .redeem-panel, .docs {
  padding: 24px 28px;
  margin-bottom: 20px;
}

.connection { max-width: 600px; }
.redeem-panel { max-width: 620px; }
.redeem-panel form { margin: 16px 0; }

.input-row, .tools, .panel-heading {
  display: flex;
  align-items: center;
  gap: 12px;
}

.tools, .panel-heading {
  justify-content: space-between;
  flex-wrap: wrap;
}

.tools { margin-bottom: 16px; }
label { display: block; margin-bottom: 8px; color: var(--ink); font-weight: 600; font-size: 13.5px; }

/* 控件 Inputs & Selects */
select {
  font: inherit;
  border: 0.5px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  max-width: 100%;
  transition: all .18s ease;
}

input {
  border: 0.5px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font: inherit;
  background: rgba(255, 255, 255, 0.92);
  width: 100%;
  min-width: 0;
  transition: all .2s cubic-bezier(0.16, 1, 0.3, 1);
}

input:focus, select:focus {
  outline: none;
  background: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0, 113, 227, 0.15);
}

/* 按钮体系 - Apple / vivo 顶级旗舰胶囊 */
button, .button {
  border: 0.5px solid transparent;
  border-radius: var(--radius-pill);
  padding: 8px 18px;
  background: #1d1d1f;
  color: #ffffff;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .2s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

button:hover:not(:disabled), .button:hover:not(:disabled) {
  background: #000000;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

button:active:not(:disabled), .button:active:not(:disabled) {
  transform: scale(0.98);
}

.primary, button.primary, a.button.primary {
  background: #0071e3;
  color: #ffffff;
  border-color: rgba(0, 113, 227, 0.2);
}

.primary:hover:not(:disabled), button.primary:hover:not(:disabled), a.button.primary:hover:not(:disabled) {
  background: #0077ed;
  box-shadow: 0 4px 14px rgba(0, 113, 227, 0.32);
}

button.secondary, .button.secondary {
  background: rgba(255, 255, 255, 0.85);
  color: var(--ink);
  border: 0.5px solid var(--line-strong);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

button.secondary:hover:not(:disabled), .button.secondary:hover:not(:disabled) {
  background: #ffffff;
  border-color: rgba(0, 0, 0, 0.22);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.06);
}

.quiet {
  background: transparent;
  color: var(--accent);
  box-shadow: none;
  font-weight: 500;
  border: none;
  padding: 6px 12px;
}

.quiet:hover {
  background: var(--accent-tint);
  transform: none;
  box-shadow: none;
}

button:disabled { opacity: .45; cursor: not-allowed; transform: none !important; box-shadow: none !important; }

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

/* 时间段 Switch (iOS 原装分段滑块) */
.switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: var(--radius-pill);
  border: 0.5px solid rgba(0, 0, 0, 0.04);
}

.switch button {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: var(--radius-pill);
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 550;
  box-shadow: none;
  transform: none !important;
}

.switch button[aria-pressed="true"] {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0.5px 1px rgba(0, 0, 0, 0.06);
}

/* 核心指标卡群 Metrics - vivo OriginOS 原子组件网格 */
.metrics {
  display: grid;
  grid-template-columns: 1.25fr 1fr .85fr 1fr;
  margin: 0 0 20px;
  overflow: hidden;
}

.metrics div {
  padding: 22px 24px;
  border-right: 0.5px solid var(--line);
  min-width: 0;
  transition: background .2s ease;
}

.metrics div:hover {
  background: rgba(255, 255, 255, 0.45);
}

.metrics .metric-balance {
  background: var(--hero-gradient);
}

.metric-balance dd {
  color: #0071e3;
}
.metric-balance dd .odo-digit,
.metric-balance dd .odo-static {
  color: #0071e3;
}

.metrics div:last-child { border-right: 0; }
.metrics dt, .hint, .metrics small { font-size: 12px; color: var(--muted); letter-spacing: -0.01em; }
.metrics dd {
  font-size: clamp(22px, 3.2vw, 32px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
  letter-spacing: -.035em;
  overflow-wrap: anywhere;
}

/* 图表与趋势 */
.chart-panel {
  padding: 22px 26px;
  margin-bottom: 20px;
}

canvas {
  display: block;
  width: 100%;
  height: 200px;
  margin-top: 14px;
}

.plot { position: relative; }
.chart-tooltip {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 8px 14px;
  border: 0.5px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  pointer-events: none;
  white-space: pre-line;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: 12px;
}

.legend span:before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  margin-right: 6px;
  background: var(--ink);
}

.legend .ink0:before { background: #0071e3; }
.legend .ink1:before { background: #ff9500; }
.legend .ink2:before { background: #5856d6; }
.legend .cache0:before { background: #34c759; }
.legend .cache1:before { background: #30b0c7; }
.legend .cache2:before { background: #af52de; }

.chart-panel h2 small { color: var(--muted); font-size: 13px; font-weight: 500; margin-left: 6px; }
.model-heading { margin-bottom: 14px; }
.model-heading label { margin: 0; display: inline-flex; align-items: center; gap: 8px; }
.model-charts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }

.row-action {
  color: var(--accent);
  background: transparent;
  padding: 4px 10px;
  border: none;
  box-shadow: none;
  font-size: 12.5px;
}

.row-action:hover {
  background: var(--accent-tint);
  border-radius: var(--radius-pill);
  transform: none;
}

.close-btn {
  background: rgba(0, 0, 0, 0.05);
  border: none;
  border-radius: var(--radius-pill);
  width: 28px;
  height: 28px;
  padding: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  box-shadow: none;
  transition: all .15s ease;
}

.close-btn:hover { background: rgba(0, 0, 0, 0.10); color: var(--ink); transform: none; }

/* 弹窗 Dialog - iOS / macOS 原装浮层 */
dialog {
  width: min(520px, calc(100vw - 32px));
  border: 0.5px solid rgba(0, 0, 0, 0.08);
  border-radius: 24px;
  color: var(--ink);
  padding: 26px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(32px) saturate(190%);
  -webkit-backdrop-filter: blur(32px) saturate(190%);
  box-shadow: var(--shadow-dialog);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

dialog dl { display: grid; grid-template-columns: max-content 1fr; gap: 10px 18px; font-size: 13px; }
dialog dt { color: var(--muted); }
dialog dd { overflow-wrap: anywhere; font-weight: 550; font-variant-numeric: tabular-nums; }

.calls .panel-heading { padding: 20px 24px; border-bottom: 0.5px solid var(--line); }
.scroll { overflow-x: auto; }

/* 表格系统 - 现代极简无框列表 */
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  text-align: left;
  font-size: 13.5px;
}

th, td {
  padding: 13px 20px;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: transparent;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 0.5px solid var(--line);
}

td {
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.04);
  transition: background .12s ease;
}

tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(0, 113, 227, 0.03); }

.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.model, code {
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  overflow-wrap: anywhere;
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 600;
  background: rgba(0, 0, 0, 0.05);
  color: var(--ink);
}

.pill.good { background: var(--good-tint); color: var(--good-ink); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

#notice {
  padding: 12px 16px;
  border: 0.5px solid rgba(52, 199, 89, 0.24);
  border-radius: var(--radius-md);
  background: var(--good-tint);
  color: var(--good-ink);
  margin: 0 0 18px;
  font-weight: 500;
}

#notice.error {
  background: rgba(255, 59, 48, 0.10);
  border-color: rgba(255, 59, 48, 0.20);
  color: #c92a2a;
}

.docs dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 10px 18px;
  margin: 14px 0 0;
  font-size: 13px;
}

.docs dt { color: var(--muted); }
.docs dd { margin: 0; }
.docs > code {
  display: block;
  background: #ffffff;
  border: 0.5px solid var(--line);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-top: 14px;
  font-size: 13px;
}

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

@media (max-width: 760px) {
  .model-charts { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics div { border-bottom: 0.5px solid var(--line); }
  .metrics div:nth-child(2) { border-right: 0; }
  .metrics div:nth-child(n+3) { border-bottom: 0; }
}

@media (max-width: 600px) {
  .shell { padding: 0 16px 40px; }
  .top { margin: 0 -16px; padding: 0 16px; min-height: 56px; flex-wrap: wrap; gap: 8px; padding-top: 8px; justify-content: space-between; }
  .top nav { order: 3; width: 100%; margin-top: 4px; justify-content: center; }
  .top nav a { min-height: 36px; padding: 0 12px; }
  main { padding-top: 20px; }
  .metrics { grid-template-columns: 1fr; }
  .metrics div { border-right: 0 !important; }
  canvas { height: 165px; }
}

/* 实时刷新状态药丸 */
.tools-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.04);
  color: var(--muted);
  border: 0.5px solid rgba(0, 0, 0, 0.08);
  font-size: 12.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: all .22s cubic-bezier(0.16, 1, 0.3, 1);
}

.live-pill:hover:not(:disabled) {
  background: #ffffff;
  color: var(--ink);
  border-color: rgba(0, 0, 0, 0.22);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.06);
  transform: translateY(-1px);
}

.live-pill[data-state="active"] {
  background: rgba(52, 199, 89, 0.09);
  border-color: rgba(52, 199, 89, 0.26);
  color: var(--good-ink);
}

.live-pill[data-state="paused"] {
  background: rgba(0, 0, 0, 0.04);
  border-color: rgba(0, 0, 0, 0.08);
  color: var(--muted);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  position: relative;
  flex-shrink: 0;
  transition: background .2s ease, transform .2s ease;
}

.live-pill[data-state="active"] .live-dot {
  background: var(--good);
  box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.55);
  animation: livePulse 2s ease-out infinite;
}

.live-pill[data-syncing="true"] .live-dot {
  transform: scale(1.22);
}

@keyframes livePulse {
  0% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.55); }
  70% { box-shadow: 0 0 0 7px rgba(52, 199, 89, 0); }
  100% { box-shadow: 0 0 0 0 rgba(52, 199, 89, 0); }
}

/* 机械计数器数字滚动动效 (Odometer) */
.odo {
  display: inline-flex;
  align-items: baseline;
  line-height: 1.18;
  font-variant-numeric: tabular-nums;
}

.odo-static {
  display: inline-block;
  line-height: 1.18;
}

.odo-slot {
  display: inline-block;
  height: 1.18em;
  overflow: hidden;
  vertical-align: -0.14em;
  position: relative;
}

.odo-track {
  display: flex;
  flex-direction: column;
  transform: translateY(calc(var(--digit, 0) * -10%));
  transition: transform 0.62s cubic-bezier(0.22, 1, 0.36, 1);
  will-change: transform;
}

.odo-track.instant {
  transition: none !important;
}

.odo-digit {
  display: block;
  height: 1.18em;
  line-height: 1.18em;
  text-align: center;
}

/* 指标变动时的轻柔光晕反馈 */
.metrics > div {
  position: relative;
}

.metrics > div.metric-pulse-up {
  animation: metricPulseUp 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

.metrics > div.metric-pulse-down {
  animation: metricPulseDown 0.9s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes metricPulseUp {
  0% { background-color: rgba(52, 199, 89, 0.14); }
  100% { background-color: transparent; }
}

@keyframes metricPulseDown {
  0% { background-color: rgba(0, 113, 227, 0.13); }
  100% { background-color: transparent; }
}

/* 新增调用记录轻柔浮现 */
tbody tr.row-new td {
  animation: rowSlideIn 0.7s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rowSlideIn {
  0% { background-color: rgba(0, 113, 227, 0.10); }
  100% { background-color: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  .odo-track { transition: none !important; }
  .live-dot, .metrics > div, tbody tr.row-new td { animation: none !important; }
}

.remember-usage {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.remember-usage input { width: auto; margin: 0; }
#redeem-reauth { margin-bottom: 0.75rem; }
