:root {
  --bg: #f4f6f9; --surface: #ffffff; --surface-2: #f8fafc; --text: #111827; --text-2: #374151; --muted: #6b7280;
  --line: #e5e7eb; --line-2: #eef0f3;
  --accent: #2563eb; --accent-2: #1d4ed8; --accent-soft: #e8efff; --accent-text: #fff;
  --side: #0f172a; --side-text: #cbd5e1; --side-muted: #64748b; --side-active: #1e293b;
  --ok: #15803d; --ok-bg: #e8f6ee; --bad: #b42318; --bad-bg: #fdeceb;
  --warn: #9a6200; --warn-bg: #fff5db; --idle: #4b5563; --idle-bg: #eef0f3;
  --radius: 10px; --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 1px 3px rgb(16 24 40 / .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e14; --surface: #141821; --surface-2: #10131a; --text: #e5e7eb; --text-2: #cbd5e1; --muted: #8b95a5;
    --line: #262b36; --line-2: #1d222c;
    --accent: #5b8cff; --accent-2: #7aa2ff; --accent-soft: #1a2440; --accent-text: #0b0e14;
    --side: #080a0f; --side-text: #b6c0cf; --side-muted: #5b6577; --side-active: #161b26;
    --ok: #4ade80; --ok-bg: #0f2a1a; --bad: #ff8a80; --bad-bg: #351513;
    --warn: #f5c451; --warn-bg: #30260b; --idle: #b6bcc6; --idle-bg: #1f242e;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 13px; letter-spacing: .02em; }
.err { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 12px; min-height: 1em; }

/* ---------- 控件 ---------- */
.btn { font: inherit; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { border-color: #c4c9d2; background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.danger.primary { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.link { border: 0; background: none; height: auto; padding: 0; color: var(--accent); }
.btn.link.danger { color: var(--bad); }
.btn.block { width: 100%; height: 40px; font-size: 14px; }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 16px; cursor: pointer; width: 32px; height: 32px; border-radius: 6px; }
.icon-btn:hover { background: var(--line-2); color: var(--text); }
input, textarea, select { font: inherit; font-size: 13px; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; height: 34px; }
textarea { height: auto; padding: 8px 10px; resize: vertical; }
textarea.mono { font-family: var(--mono); font-size: 12px; }
input[type=file] { padding: 5px; height: auto; }
input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn:focus-visible, .icon-btn:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: block; margin-bottom: 14px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.field > input, .field > textarea, .field > select, .field > .code-row { margin-top: 6px; }
.field .sub { font-weight: 400; color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 8px; }

/* ---------- 标签 ---------- */
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 12px;
  font-weight: 500; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag { display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px; border-radius: 99px; font-size: 12px;
  font-weight: 500; background: var(--idle-bg); color: var(--idle); white-space: nowrap; }
.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.ok, .tag.done, .tag.active, .tag.unused { background: var(--ok-bg); color: var(--ok); }
.tag.expired, .tag.invalid, .tag.missing, .tag.failed, .tag.disabled { background: var(--bad-bg); color: var(--bad); }
.tag.unknown, .tag.queued, .tag.running, .tag.expiring { background: var(--warn-bg); color: var(--warn); }
.tag.used, .tag.cancelled, .tag.draft, .tag.unchecked { background: var(--idle-bg); color: var(--idle); }
.plat { display: inline-block; font-size: 12px; padding: 1px 6px; border-radius: 4px; background: var(--line-2); color: var(--text-2); margin-right: 6px; }

/* ---------- 登录页 ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth-panel { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 32px; box-shadow: 0 10px 30px rgb(16 24 40 / .08); }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 24px; }
.auth-title { font-size: 18px; font-weight: 600; }
.auth-sub { color: var(--muted); font-size: 13px; }
.logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 18px; flex: none; }
.logo.sm { width: 28px; height: 28px; font-size: 14px; border-radius: 7px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; background: var(--line-2); border-radius: 8px; padding: 3px; margin-bottom: 20px; }
.seg-btn { font: inherit; font-size: 13px; border: 0; background: none; color: var(--muted); height: 32px; border-radius: 6px; cursor: pointer; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }
.code-row { display: flex; gap: 8px; }
.code-row input { font-family: var(--mono); letter-spacing: .3em; }

/* ---------- 布局 ---------- */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; font-weight: 600; color: #fff; font-size: 15px; }
#nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav-group { font-size: 11px; letter-spacing: .06em; color: var(--side-muted); padding: 16px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 0 10px; height: 36px; border-radius: 7px; color: var(--side-text);
  font-size: 13.5px; cursor: pointer; text-decoration: none; }
.nav-item:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-ico { width: 18px; text-align: center; opacity: .9; font-size: 14px; }
.side-foot { padding: 12px 18px; font-size: 12px; color: var(--side-muted); border-top: 1px solid #1e293b; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 24px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.crumb { font-size: 15px; font-weight: 600; flex: 1; min-width: 0; }
.top-right { display: flex; align-items: center; gap: 12px; }
.menu-btn { display: none; }
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; background: none; cursor: pointer; color: var(--text); font: inherit; font-size: 13px; padding: 4px; border-radius: 8px; }
.user-btn:hover { background: var(--line-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 12px; }
.pop { position: absolute; right: 0; top: 40px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 8px 24px rgb(16 24 40 / .12); min-width: 160px; padding: 6px; z-index: 10; }
.pop a, .pop button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; font: inherit; font-size: 13px;
  color: var(--text); background: none; border: 0; cursor: pointer; }
.pop a:hover, .pop button:hover { background: var(--line-2); text-decoration: none; }
.view { padding: 24px; max-width: 1360px; width: 100%; }
.alert { margin: 16px 24px 0; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.inline { margin: 0 0 16px; }

/* ---------- 页面元素 ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.panel-head h2 { font-size: 14px; }
.panel-body { padding: 16px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters input[type=search] { min-width: 220px; }
.spacer { flex: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12.5px; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.meter { height: 6px; border-radius: 99px; background: var(--line-2); overflow: hidden; margin-top: 8px; }
.meter > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; background: var(--surface-2); padding: 10px 14px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-2); }
td.ops { white-space: nowrap; text-align: right; }
td.ops .btn.link + .btn.link { margin-left: 12px; }
th.ops { text-align: right; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cell-main { font-weight: 500; color: var(--text); }
.cell-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.pager .btns { display: flex; gap: 6px; align-items: center; }
.levels { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.level-card { padding: 16px; }
.level-card h3 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.level-card ul { list-style: none; padding: 0; margin: 12px 0; font-size: 13px; color: var(--text-2); display: grid; gap: 6px; }
.level-card ul b { font-weight: 500; color: var(--text); }

/* ---------- 弹窗 / 提示 ---------- */
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); padding: 0;
  width: min(560px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgb(16 24 40 / .2); }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(15 23 42 / .45); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 15px; }
.dlg-body { padding: 18px 20px 4px; max-height: calc(100vh - 220px); overflow-y: auto; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
#dlg-err { padding: 0 20px; }
.codebox { font-family: var(--mono); font-size: 13px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; max-height: 300px; overflow: auto; white-space: pre; margin: 0; }
.logs { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border-radius: 8px; padding: 12px; margin: 0;
  max-height: 380px; overflow: auto; white-space: pre-wrap; }
.logs .error { color: var(--bad); } .logs .warn { color: var(--warn); }
.progress { height: 6px; background: var(--line-2); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(8px); background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 50;
  max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* ---------- 窄屏 ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; box-shadow: 0 0 0 100vmax rgb(0 0 0 / .4); }
  .menu-btn { display: inline-block; }
  .topbar { padding: 0 16px; }
  .view { padding: 16px; }
  .alert { margin: 12px 16px 0; }
  .cols, .grid2, .grid3 { grid-template-columns: 1fr; }
  .user-email, #top-expiry { display: none; }
  .filters input, .filters select, .filters input[type=search] { min-width: 0; flex: 1 1 140px; }
  .kv { grid-template-columns: 90px 1fr; }
}
.filters input[type=checkbox] { min-width: 0; width: 16px; flex: none; }
.filters .check { flex: none; }
.table-wrap table { min-width: 760px; }
