/* ========== 主题 ========== */
:root {
  --bg: #060913;
  --surface: rgba(16, 21, 40, 0.66);
  --surface-strong: rgba(18, 24, 46, 0.92);
  --surface-2: rgba(255, 255, 255, 0.035);
  --surface-3: rgba(255, 255, 255, 0.06);
  --border: rgba(160, 170, 255, 0.12);
  --border-strong: rgba(160, 170, 255, 0.22);
  --text: #e9ecfb;
  --muted: #8d95b5;
  --violet: #8b5cf6;
  --indigo: #6366f1;
  --cyan: #22d3ee;
  --pink: #f472b6;
  --accent: linear-gradient(135deg, #a78bfa 0%, #6366f1 45%, #22d3ee 100%);
  --primary: #8b7cf8;
  --primary-soft: rgba(139, 92, 246, 0.14);
  --danger: #fb7185;
  --danger-soft: rgba(244, 63, 94, 0.12);
  --success: #34d399;
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.1);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 20px 50px -20px rgba(0, 0, 0, 0.7);
  --ring: 0 0 0 3px rgba(139, 92, 246, 0.35);
  --mono: ui-monospace, "Cascadia Code", "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: dark;
}

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

html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
::selection { background: rgba(139, 92, 246, 0.45); color: #fff; }

h1, h2, h3 { margin: 0; line-height: 1.3; letter-spacing: 0.01em; }
h2 { font-size: 17px; margin-bottom: 6px; }
h3 { font-size: 14px; margin: 20px 0 8px; color: #c7cdf0; }
code, pre { font-family: var(--mono); font-size: 13px; }
code { background: var(--surface-3); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; color: #d6dbff; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; margin: 12px 4px; }
.nowrap { white-space: nowrap; }

/* ========== 动态背景 ========== */
.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background:
    radial-gradient(1100px 700px at 15% -10%, #1a1240 0%, transparent 60%),
    radial-gradient(900px 600px at 110% 110%, #062433 0%, transparent 60%),
    var(--bg);
  transition: opacity 0.6s var(--ease);
}
.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
  will-change: transform;
}
.b1 { width: 46vmax; height: 46vmax; top: -18vmax; left: -12vmax; background: radial-gradient(circle, #7c3aed, transparent 65%); animation: drift-a 24s ease-in-out infinite alternate; }
.b2 { width: 42vmax; height: 42vmax; bottom: -20vmax; right: -12vmax; background: radial-gradient(circle, #0891b2, transparent 65%); animation: drift-b 28s ease-in-out infinite alternate; }
.b3 { width: 30vmax; height: 30vmax; top: 35%; left: 55%; background: radial-gradient(circle, #db2777, transparent 65%); opacity: 0.28; animation: drift-c 32s ease-in-out infinite alternate; }
.b4 { width: 26vmax; height: 26vmax; top: 55%; left: 5%; background: radial-gradient(circle, #4f46e5, transparent 65%); opacity: 0.35; animation: drift-d 36s ease-in-out infinite alternate; }
.grid {
  position: absolute;
  inset: -1px;
  background-image:
    linear-gradient(rgba(170, 180, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(170, 180, 255, 0.045) 1px, transparent 1px);
  background-size: 52px 52px;
  -webkit-mask-image: radial-gradient(ellipse 75% 60% at 50% 35%, #000 25%, transparent 80%);
  mask-image: radial-gradient(ellipse 75% 60% at 50% 35%, #000 25%, transparent 80%);
  animation: grid-pan 40s linear infinite;
}
body[data-view="app"] .blob { opacity: 0.28; }
body[data-view="app"] .b3 { opacity: 0.14; }
body[data-view="app"] .grid { opacity: 0.6; }

@keyframes drift-a { to { transform: translate(18vw, 14vh) scale(1.15); } }
@keyframes drift-b { to { transform: translate(-20vw, -12vh) scale(1.1); } }
@keyframes drift-c { 0% { transform: translate(0, 0) scale(1); } 50% { transform: translate(-25vw, -20vh) scale(1.25); } 100% { transform: translate(-10vw, 10vh) scale(0.9); } }
@keyframes drift-d { to { transform: translate(30vw, -25vh) scale(1.2); } }
@keyframes grid-pan { to { background-position: 52px 52px, 52px 52px; } }

/* ========== 卡片 ========== */
.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
}

/* ========== 按钮 ========== */
.btn {
  position: relative;
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, border-color 0.2s, color 0.2s, transform 0.15s var(--ease), box-shadow 0.25s;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-3); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.98); }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tab:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary {
  border: 0;
  color: #fff;
  background: linear-gradient(120deg, #7c3aed, #6366f1 35%, #0ea5e9 70%, #7c3aed);
  background-size: 250% 100%;
  box-shadow: 0 8px 24px -10px rgba(124, 58, 237, 0.8);
  overflow: hidden;
}
.btn.primary:hover { background-position: 100% 0; box-shadow: 0 12px 30px -10px rgba(99, 102, 241, 0.9); transition: background-position 0.8s var(--ease), box-shadow 0.25s, transform 0.15s; }
.btn.primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.28) 50%, transparent 70%);
  transform: translateX(-120%);
}
.btn.primary:hover::after { transform: translateX(120%); transition: transform 0.9s var(--ease); }
.btn.danger { border: 0; color: #fff; background: linear-gradient(135deg, #f43f5e, #e11d48); box-shadow: 0 8px 22px -10px rgba(244, 63, 94, 0.8); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-3); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 8px; }
.btn.link-danger:hover { color: var(--danger); border-color: rgba(251, 113, 133, 0.5); background: var(--danger-soft); }
.btn.block { width: 100%; padding: 11px; font-size: 15px; }
.btn:disabled { opacity: 0.6; cursor: default; transform: none; }

/* ========== 输入 ========== */
input, select {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(8, 11, 24, 0.55);
  color: var(--text);
  font: inherit;
  transition: border-color 0.2s, box-shadow 0.25s, background 0.2s;
}
input::placeholder { color: #5d6587; }
input:hover, select:hover { border-color: var(--border-strong); }
input:focus, select:focus { outline: none; border-color: rgba(139, 92, 246, 0.7); background: rgba(10, 14, 30, 0.8); box-shadow: var(--ring); }
input:-webkit-autofill { -webkit-text-fill-color: var(--text); -webkit-box-shadow: 0 0 0 40px #12162c inset; caret-color: var(--text); }
select option { background: #12162c; color: var(--text); }
label { display: block; font-weight: 500; margin-top: 16px; color: #cbd1ef; font-size: 13px; }
label > input, label > select, label > .input-group { margin-top: 7px; font-weight: 400; font-size: 14px; }
.input-group { display: flex; gap: 6px; }
.input-group input { flex: 1; min-width: 0; font-family: var(--mono); }
.hint { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
.error {
  color: #fecdd3;
  background: var(--danger-soft);
  border: 1px solid rgba(251, 113, 133, 0.3);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  margin: 16px 0 0;
  font-size: 13px;
  animation: fade-in 0.3s var(--ease);
}

/* ========== 登录页 ========== */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 38px 34px 26px;
  text-align: left;
  background: rgba(14, 18, 36, 0.62);
  animation: rise 0.7s var(--ease) both;
}
/* 旋转的渐变描边 */
@property --angle { syntax: "<angle>"; initial-value: 0deg; inherits: false; }
.login-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: conic-gradient(from var(--angle), rgba(167, 139, 250, 0.9), rgba(34, 211, 238, 0.15) 25%, rgba(244, 114, 182, 0.7) 50%, rgba(99, 102, 241, 0.15) 75%, rgba(167, 139, 250, 0.9));
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: spin-border 8s linear infinite;
  pointer-events: none;
}
.login-card.shake { animation: shake 0.45s var(--ease); }
.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  filter: drop-shadow(0 10px 28px rgba(124, 58, 237, 0.6));
  animation: float 5s ease-in-out infinite;
}
.login-logo img { width: 56px; height: 56px; }
.login-title {
  text-align: center;
  font-size: 26px;
  font-weight: 750;
  background: linear-gradient(120deg, #fff 20%, #c4b5fd 50%, #67e8f9 80%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer-text 6s linear infinite;
}
.login-sub { text-align: center; margin: 6px 0 8px; font-size: 13px; }
.login-card .btn.block { margin-top: 24px; }
.login-foot { margin: 20px 0 0; text-align: center; font-size: 11.5px; color: #5d6587; letter-spacing: 0.04em; }

.brand { display: flex; align-items: center; gap: 10px; }
.brand.small { font-weight: 700; font-size: 16px; gap: 9px; }
.brand.small img { filter: drop-shadow(0 4px 12px rgba(124, 58, 237, 0.55)); }

/* ========== 顶栏 ========== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 0 28px;
  height: 62px;
  background: rgba(8, 11, 24, 0.6);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  backdrop-filter: blur(16px) saturate(150%);
  animation: fade-down 0.5s var(--ease) both;
}
.tabs { display: flex; gap: 4px; height: 100%; }
.tab {
  position: relative;
  appearance: none;
  border: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-weight: 500;
  padding: 0 14px;
  cursor: pointer;
  transition: color 0.2s;
}
.tab:hover { color: var(--text); }
.tab::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transition: transform 0.35s var(--ease);
}
.tab.active { color: #fff; }
.tab.active::after { transform: scaleX(1); box-shadow: 0 0 12px rgba(139, 92, 246, 0.8); }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; min-width: 0; }
.account span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

.panel { max-width: 1120px; margin: 0 auto; padding: 28px; animation: rise 0.5s var(--ease) both; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; }
.toolbar input { max-width: 380px; margin-right: auto; padding-left: 38px; background-image: url("/search.svg"); background-repeat: no-repeat; background-position: 13px 50%; background-size: 16px; }

/* ========== 表格 ========== */
.table-card { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; background: rgba(255, 255, 255, 0.02); }
.table tbody tr { transition: background 0.2s; animation: fade-in 0.35s var(--ease) both; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: rgba(139, 92, 246, 0.07); }
.table td.name { font-family: var(--mono); font-weight: 600; word-break: break-all; color: #f1f3ff; }
.table td.note { color: var(--muted); max-width: 280px; }
.table td.time { color: var(--muted); white-space: nowrap; font-size: 13px; }
.actions-col { width: 1%; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.value-row { background: linear-gradient(90deg, rgba(139, 92, 246, 0.12), rgba(34, 211, 238, 0.06)) !important; animation: slide-down 0.3s var(--ease) both !important; }
.value-box { display: flex; align-items: center; gap: 10px; }
.value-box code { flex: 1; background: rgba(6, 9, 20, 0.7); border-color: rgba(139, 92, 246, 0.35); padding: 8px 12px; word-break: break-all; user-select: all; color: #e0e7ff; }
.empty { text-align: center; color: var(--muted); padding: 44px 16px; margin: 0; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; background: var(--surface-3); border: 1px solid var(--border); color: #c7cdf0; }
.badge.rw { background: var(--warn-soft); border-color: rgba(251, 191, 36, 0.45); color: #fde68a; }
.badge.expired { color: var(--danger); border-color: rgba(251, 113, 133, 0.5); background: var(--danger-soft); }
.scopes code { margin-right: 4px; display: inline-block; margin-bottom: 2px; }

/* ========== 令牌表单 ========== */
.form-card { padding: 22px 24px; margin-bottom: 18px; }
.form-card > .muted { margin: 0; font-size: 13px; }
.grid-form { display: grid; grid-template-columns: 1fr 170px; gap: 0 16px; }
.grid-form .span-2 { grid-column: 1 / -1; }
.form-actions { display: flex; align-items: flex-end; justify-content: flex-end; margin-top: 16px; }
.notice {
  margin-top: 18px;
  padding: 15px 17px;
  border: 1px solid rgba(251, 191, 36, 0.4);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.1), rgba(244, 114, 182, 0.06));
  border-radius: var(--radius-sm);
  color: #fde68a;
  animation: pop 0.4s var(--ease) both;
}
.token-line { display: flex; gap: 8px; align-items: center; margin: 10px 0; }
.token-line code { flex: 1; padding: 9px 12px; word-break: break-all; background: rgba(6, 9, 20, 0.75); user-select: all; color: #fff; }

/* ========== 说明页 ========== */
.prose { padding: 24px 28px; }
.prose p { margin: 6px 0; color: #c7cdf0; }
.prose pre {
  background: rgba(6, 9, 20, 0.7);
  border: 1px solid var(--border);
  border-left: 2px solid var(--violet);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
  color: #dbe2ff;
}

/* ========== 弹窗 ========== */
.dialog {
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 26px 26px 22px;
  width: min(520px, calc(100vw - 32px));
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(139, 92, 246, 0.08);
}
.dialog[open] { animation: pop 0.35s var(--ease) both; }
.dialog.narrow { width: min(410px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(3, 5, 12, 0.6); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); }
.dialog[open]::backdrop { animation: fade-in 0.3s ease both; }
.dialog h2 { margin-bottom: 4px; font-size: 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }
#confirm-text { margin: 12px 0 0; word-break: break-all; color: #c7cdf0; }

/* ========== 提示 ========== */
.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: rgba(18, 24, 46, 0.92);
  color: #fff;
  padding: 11px 20px 11px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  z-index: 50;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 9px;
  animation: toast-in 0.4s var(--ease) both;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 10px var(--success); }
.toast.error { border-color: rgba(251, 113, 133, 0.5); }
.toast.error::before { background: var(--danger); box-shadow: 0 0 10px var(--danger); }

/* ========== 动画 ========== */
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-down { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: scale(0.94) translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 16px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes shimmer-text { to { background-position: 200% center; } }
@keyframes spin-border { to { --angle: 360deg; } }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-9px); }
  40% { transform: translateX(8px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* ========== 窄屏 ========== */
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px 0; gap: 8px 12px; }
  .tabs { order: 3; width: 100%; height: 44px; overflow-x: auto; }
  .tab { padding: 0 10px; }
  #me-email { display: none; }
  .panel { padding: 14px; }
  .toolbar { flex-wrap: wrap; }
  .toolbar input { max-width: none; margin-right: 0; }
  .grid-form { grid-template-columns: 1fr; }
  .input-group { flex-wrap: wrap; }
  .input-group input { flex-basis: 100%; }
  .login-card { padding: 32px 22px 22px; }
  .blob { filter: blur(70px); }

  /* 表格改为卡片：每条记录一块，操作按钮横排 */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 14px 16px; border-bottom: 1px solid var(--border); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table th, .table td { border: 0; padding: 2px 0; }
  .table td.note { max-width: none; }
  .table td.note:empty { display: none; }
  .table td.time { font-size: 12px; }
  .table td[data-label]::before { content: attr(data-label); color: var(--muted); margin-right: 4px; }
  .table td.name, .table td.title { font-size: 15px; }
  .row-actions { justify-content: flex-start; flex-wrap: wrap; margin-top: 10px; }
  .row-actions .btn.small { padding: 6px 14px; }
}
