:root {
  --bg: #0a0a0f;
  --surface: #14141c;
  --card: #1a1a26;
  --border: #2a2a3a;
  --hover: #252535;
  --text: #e8e8ed;
  --text-secondary: #8888a0;
  --text-muted: #7d7d91;
  --brand: #6366f1;
  --brand-hover: #7477f3;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* hidden 属性优先于组件的 display 声明，避免弹窗层永久覆盖页面 */
.login-wrap[hidden],
.modal[hidden],
.toast[hidden],
#app-view[hidden],
.empty[hidden] { display: none; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(900px 500px at 12% -10%, rgba(99, 102, 241, 0.16), transparent 60%),
    radial-gradient(700px 420px at 92% 0%, rgba(56, 189, 248, 0.1), transparent 62%);
  pointer-events: none;
  z-index: 0;
}

h1, h2 { margin: 0; font-weight: 600; }

/* ── 登录 ── */

.login-wrap {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(32, 32, 46, 0.9), rgba(18, 18, 26, 0.97));
  border: 1px solid rgba(99, 102, 241, 0.22);
  border-radius: 20px;
  padding: 34px 32px 28px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.6),
    0 0 70px rgba(99, 102, 241, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}

.brand h1 { font-size: 18px; letter-spacing: 0.2px; }
.brand p { margin: 3px 0 0; font-size: 12px; color: var(--text-muted); }

.brand-dot {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), #38bdf8);
  box-shadow: 0 8px 22px rgba(99, 102, 241, 0.45);
  position: relative;
}

.brand-dot::after {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: #0a0a0f;
}

.brand--sm { margin-bottom: 0; gap: 10px; }
.brand--sm h1 { font-size: 15px; }
.brand--sm .brand-dot { width: 28px; height: 28px; border-radius: 9px; }
.brand--sm .brand-dot::after { inset: 9px; }

/* ── 表单控件 ── */

.field { display: block; margin-bottom: 16px; }
.field > span {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 7px;
}

.input {
  width: 100%;
  padding: 11px 13px;
  background: rgba(10, 10, 15, 0.75);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.input::placeholder { color: var(--text-muted); }

.input:hover { border-color: rgba(99, 102, 241, 0.35); }

.input:focus {
  border-color: var(--brand);
  background: rgba(10, 10, 15, 0.95);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
}

select.input { cursor: pointer; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover { background: var(--hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 500;
}

.btn--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }

.btn--ghost { background: transparent; }

.btn--block {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  letter-spacing: 0.16em;
  text-indent: 0.16em;
  border-radius: 11px;
}

.btn--sm { padding: 4px 9px; font-size: 12px; border-radius: 8px; }

.btn--danger { color: var(--danger); }
.btn--danger:hover { background: rgba(248, 113, 113, 0.1); border-color: rgba(248, 113, 113, 0.4); }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.icon-btn:hover { color: var(--text); }

.login-hint {
  margin: 12px 0 0;
  min-height: 18px;
  font-size: 12px;
  color: var(--danger);
  text-align: center;
}

/* ── 顶栏 ── */

#app-view {
  position: relative;
  z-index: 1;
  padding: 18px 22px 40px;
  max-width: 1500px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.who { font-size: 12px; color: var(--text-muted); margin: 0 4px; }

/* ── 统计卡 ── */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}

.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.stat--ok .stat-value { color: var(--ok); }
.stat--warn .stat-value { color: var(--warn); }
.stat--brand .stat-value { color: var(--brand-hover); }

/* ── 面板与表格 ── */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.toolbar-left {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
  min-width: 260px;
}

.toolbar-left .input { width: auto; min-width: 130px; }
.toolbar-left #filter-q { flex: 1; min-width: 180px; }

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  padding: 10px 14px;
  background: rgba(10, 10, 15, 0.5);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 10px 14px;
  border-bottom: 1px solid rgba(42, 42, 58, 0.55);
  vertical-align: middle;
}

.table tbody tr:hover { background: rgba(37, 37, 53, 0.55); }
.table tbody tr:last-child td { border-bottom: none; }

.key-cell { display: flex; align-items: center; gap: 6px; }

.key-text {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  letter-spacing: 0.4px;
  color: #c7c9e8;
}

.copy-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 11px;
  padding: 1px 5px;
}

.copy-btn:hover { color: var(--brand-hover); border-color: var(--border); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge--unused { color: var(--text-secondary); background: rgba(136, 136, 160, 0.12); border-color: rgba(136, 136, 160, 0.25); }
.badge--active { color: var(--ok); background: rgba(52, 211, 153, 0.12); border-color: rgba(52, 211, 153, 0.3); }
.badge--expired { color: var(--warn); background: rgba(251, 191, 36, 0.12); border-color: rgba(251, 191, 36, 0.3); }
.badge--revoked { color: var(--danger); background: rgba(248, 113, 113, 0.12); border-color: rgba(248, 113, 113, 0.3); }

.muted { color: var(--text-muted); font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 12px; }

.ops { display: flex; gap: 6px; flex-wrap: wrap; }

.note-cell { color: var(--text-secondary); max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty { padding: 40px; text-align: center; color: var(--text-muted); }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
}

.pager-actions { display: flex; gap: 8px; }

/* ── 弹窗 ── */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 5, 10, 0.72);
  backdrop-filter: blur(4px);
}

.modal-card {
  width: min(520px, 100%);
  max-height: 88vh;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.6);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h2 { font-size: 16px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.hint { font-size: 12px; color: var(--text-muted); margin: 0 0 12px; }
.hint b { color: var(--text-secondary); font-weight: 500; }

.keys-box {
  width: 100%;
  height: 190px;
  resize: vertical;
  padding: 10px;
  background: rgba(10, 10, 15, 0.8);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: #c7c9e8;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.7;
  outline: none;
}

/* ── Toast ── */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 90;
  padding: 9px 16px;
  border-radius: 10px;
  background: rgba(26, 26, 38, 0.98);
  border: 1px solid var(--border);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  font-size: 13px;
}

.toast--ok { border-color: rgba(52, 211, 153, 0.5); color: var(--ok); }
.toast--err { border-color: rgba(248, 113, 113, 0.5); color: var(--danger); }

@media (max-width: 720px) {
  #app-view { padding: 14px 12px 32px; }
  .topbar { flex-direction: column; align-items: flex-start; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  .who { display: none; }
}

/* ── 标签页 ── */
.tabs {
  display: flex;
  gap: 6px;
  padding: 0 18px;
  margin: 6px 0 0;
  border-bottom: 1px solid var(--border);
}
.tab {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 14px;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
  position: relative;
}
.tab:hover { color: var(--text); background: var(--hover); }
.tab.is-active { color: var(--text); }
.tab.is-active::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--brand);
}

/* 注意：.pane 声明了 display 就必须补 [hidden]，否则隐藏失效 */
.pane { display: block; }
.pane[hidden] { display: none; }

/* ── 版本更新 ── */
.panel--tip { padding: 14px 16px; }
.tip-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.tip-title { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.tip-side { display: flex; align-items: center; gap: 8px; min-width: 0; }
.url-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  padding: 6px 10px;
  border-radius: 8px;
  max-width: 460px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.progress {
  height: 6px;
  margin-top: 12px;
  border-radius: 999px;
  background: var(--hover);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--brand);
  border-radius: 999px;
  transition: width 0.15s ease;
}
.file-list { display: flex; flex-direction: column; gap: 2px; }
.file-list .file {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.file-list .file--nosig { color: var(--warn); }
