:root {
  --bg: #05070d;
  --panel: rgba(17, 24, 39, 0.62);
  --panel-2: rgba(15, 23, 42, 0.86);
  --line: rgba(148, 163, 184, 0.14);
  --line-2: rgba(148, 163, 184, 0.24);
  --txt: #e6edf7;
  --mut: #94a3b8;
  --dim: #64748b;
  --acc: #34d399;
  --acc-2: #38bdf8;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background:
    radial-gradient(900px 500px at 12% -8%, rgba(52, 211, 153, 0.10), transparent 60%),
    radial-gradient(760px 460px at 92% 6%, rgba(56, 189, 248, 0.09), transparent 62%),
    radial-gradient(700px 500px at 60% 108%, rgba(14, 165, 233, 0.07), transparent 60%),
    var(--bg);
  color: var(--txt);
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", ui-sans-serif, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.hidden { display: none !important; }

/* ------------------------------------------------------------- 登录 */

.login {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
}

.login-bg {
  position: absolute;
  inset: -30%;
  background: conic-gradient(from 0deg, transparent 0 70%, rgba(52, 211, 153, 0.10) 84%, transparent 100%);
  animation: spin 16s linear infinite;
  pointer-events: none;
}

.login-card {
  position: relative;
  width: min(92vw, 400px);
  padding: 30px 26px 24px;
  border-radius: 20px;
  border: 1px solid rgba(52, 211, 153, 0.22);
  background: linear-gradient(168deg, rgba(15, 23, 42, 0.96), rgba(2, 6, 23, 0.99));
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: rise 0.4s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

.login-mark {
  width: 54px;
  height: 54px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  border: 1px solid rgba(52, 211, 153, 0.32);
  background: radial-gradient(circle at 50% 30%, rgba(52, 211, 153, 0.18), transparent 70%);
  box-shadow: 0 0 30px rgba(52, 211, 153, 0.18);
}

.login-mark svg { width: 26px; height: 26px; }

.login-mark path {
  fill: none;
  stroke: #34d399;
  stroke-width: 3.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 70;
  animation: draw 1s 0.15s ease forwards;
}

.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 19px;
  letter-spacing: 0.06em;
}

.login-sub {
  margin: 6px 0 22px;
  text-align: center;
  color: var(--mut);
  font-size: 12px;
}

.login-hint {
  margin: 16px 0 0;
  font-size: 11px;
  line-height: 1.65;
  color: var(--dim);
  text-align: center;
}

.login-hint code {
  color: var(--mut);
  background: rgba(148, 163, 184, 0.1);
  padding: 1px 5px;
  border-radius: 4px;
}

/* ------------------------------------------------------------- 框架 */

.app {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(9, 14, 24, 0.9), rgba(5, 7, 13, 0.72));
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-weight: 800;
  color: #04120c;
  background: linear-gradient(135deg, #34d399, #38bdf8);
  box-shadow: 0 6px 20px rgba(52, 211, 153, 0.3);
}

.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 14px; letter-spacing: 0.16em; }
.brand-text i { font-style: normal; font-size: 10px; color: var(--dim); letter-spacing: 0.1em; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--mut);
  font-size: 13px;
  transition: background 0.16s, color 0.16s;
}

.nav a:hover { background: rgba(148, 163, 184, 0.08); color: var(--txt); }

.nav a[data-active="1"] {
  color: #d1fae5;
  background: linear-gradient(90deg, rgba(52, 211, 153, 0.16), rgba(56, 189, 248, 0.06));
  box-shadow: inset 0 0 0 1px rgba(52, 211, 153, 0.22);
}

.nav svg, .tabbar svg, .icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  font-size: 11px;
  color: var(--dim);
  border-top: 1px solid var(--line);
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--acc);
  box-shadow: 0 0 10px var(--acc);
}

.dot[data-ok="0"] { background: var(--danger); box-shadow: 0 0 10px var(--danger); }

.main { min-width: 0; padding: 22px 26px 46px; }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h2 { margin: 0; font-size: 18px; letter-spacing: 0.04em; }
.topbar p { margin: 4px 0 0; font-size: 12px; color: var(--dim); }

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

.icon-btn {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.06);
  color: var(--mut);
  cursor: pointer;
  transition: color 0.16s, border-color 0.16s, background 0.16s;
}

.icon-btn:hover { color: var(--txt); border-color: var(--line-2); background: rgba(148, 163, 184, 0.12); }
.icon-btn svg { width: 16px; height: 16px; }

/* ------------------------------------------------------------- 组件 */

.card {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: 0 10px 34px rgba(0, 0, 0, 0.22);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: rgba(148, 163, 184, 0.08);
  color: var(--txt);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.14s, background 0.16s, border-color 0.16s, filter 0.16s;
}

.btn:hover { background: rgba(148, 163, 184, 0.16); transform: translateY(-1px); }
.btn:active { transform: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn.primary {
  border-color: rgba(52, 211, 153, 0.4);
  background: linear-gradient(120deg, #34d399, #10b981 55%, #38bdf8);
  color: #04160f;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(52, 211, 153, 0.24);
}

.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { border-color: rgba(248, 113, 113, 0.42); color: #fca5a5; background: rgba(248, 113, 113, 0.08); }
.btn.block { width: 100%; padding: 11px; }
.btn.sm { padding: 5px 10px; font-size: 12px; border-radius: 7px; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; margin-bottom: 6px; font-size: 11px; color: var(--mut); letter-spacing: 0.05em; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line-2);
  background: rgba(2, 6, 23, 0.7);
  color: var(--txt);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.18s, box-shadow 0.18s;
}

input:focus, select:focus, textarea:focus {
  border-color: rgba(52, 211, 153, 0.62);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12);
}

select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--mut) 50%), linear-gradient(135deg, var(--mut) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }

/* 统计卡 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }

.stat { padding: 15px 16px; }
.stat-label { font-size: 11px; color: var(--dim); letter-spacing: 0.08em; }
.stat-value { margin-top: 6px; font-size: 26px; font-weight: 700; letter-spacing: 0.02em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 12px; font-weight: 400; color: var(--dim); margin-left: 4px; }
.stat[data-tone="acc"] .stat-value { color: var(--acc); }
.stat[data-tone="warn"] .stat-value { color: var(--warn); }
.stat[data-tone="danger"] .stat-value { color: var(--danger); }
.stat[data-tone="blue"] .stat-value { color: var(--acc-2); }

/* 图表 */
.chart-wrap { padding: 16px 18px 10px; }
.chart-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.chart-head h3 { margin: 0; font-size: 13px; }
.chart-head span { font-size: 11px; color: var(--dim); }

.chart { display: flex; align-items: flex-end; gap: 5px; height: 118px; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; gap: 5px; min-width: 0; }
.bar i {
  display: block;
  min-height: 2px;
  border-radius: 4px 4px 2px 2px;
  background: linear-gradient(180deg, rgba(52, 211, 153, 0.95), rgba(56, 189, 248, 0.55));
  transition: height 0.4s cubic-bezier(0.2, 0.9, 0.3, 1);
  box-shadow: 0 0 14px rgba(52, 211, 153, 0.16);
}
.bar em { font-style: normal; font-size: 9px; color: var(--dim); text-align: center; white-space: nowrap; overflow: hidden; }

/* 事件 */
.events { padding: 6px 0; }
.event { display: flex; gap: 10px; align-items: flex-start; padding: 9px 18px; border-bottom: 1px solid rgba(148, 163, 184, 0.07); }
.event:last-child { border-bottom: 0; }
.event-badge { flex: none; width: 6px; height: 6px; margin-top: 7px; border-radius: 50%; background: var(--acc); }
.event-badge[data-kind="revoke"] { background: var(--danger); }
.event-badge[data-kind="extend"] { background: var(--warn); }
.event-badge[data-kind="generate"] { background: var(--acc-2); }
.event-main { min-width: 0; }
.event-title { font-size: 12.5px; }
.event-meta { font-size: 11px; color: var(--dim); margin-top: 2px; }

/* 工具栏 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .search { position: relative; flex: 1 1 240px; min-width: 160px; }
.toolbar .search input { padding-left: 32px; }
.toolbar .search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; fill: none; stroke: var(--dim); stroke-width: 2; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.06);
  color: var(--mut);
  font-size: 11.5px;
  cursor: pointer;
  transition: all 0.16s;
}
.chip:hover { color: var(--txt); border-color: var(--line-2); }
.chip[data-active="1"] { color: #d1fae5; border-color: rgba(52, 211, 153, 0.5); background: rgba(52, 211, 153, 0.14); }

/* 列表 */
.card-table { overflow: hidden; }

.chead, .crow {
  display: grid;
  grid-template-columns: minmax(230px, 2.2fr) 108px 92px 148px 44px;
  gap: 12px;
  align-items: center;
  padding: 11px 16px;
}

.chead {
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--dim);
  border-bottom: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.04);
  text-transform: uppercase;
}

.crow { border-bottom: 1px solid rgba(148, 163, 184, 0.07); transition: background 0.14s; }
.crow:last-child { border-bottom: 0; }
.crow:hover { background: rgba(148, 163, 184, 0.05); }

.c-code { display: flex; align-items: center; gap: 6px; min-width: 0; }
.c-code .mono { font-size: 12.5px; letter-spacing: 0.04em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-code .masked { color: var(--mut); }

.tiny-btn {
  flex: none;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  font-size: 12px;
}
.tiny-btn:hover { color: var(--txt); border-color: var(--line-2); background: rgba(148, 163, 184, 0.1); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--line-2);
  color: var(--mut);
  white-space: nowrap;
}
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill[data-s="active"] { color: #34d399; border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.1); }
.pill[data-s="unused"] { color: #94a3b8; }
.pill[data-s="soon"] { color: #fbbf24; border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.1); }
.pill[data-s="expired"] { color: #f87171; border-color: rgba(248, 113, 113, 0.38); background: rgba(248, 113, 113, 0.09); }
.pill[data-s="revoked"] { color: #cbd5e1; border-color: rgba(148, 163, 184, 0.32); background: rgba(148, 163, 184, 0.08); }

.c-dev, .c-exp { font-size: 12px; color: var(--mut); font-variant-numeric: tabular-nums; }
.c-exp em { display: block; font-style: normal; font-size: 10px; color: var(--dim); }

.empty { padding: 56px 20px; text-align: center; color: var(--dim); }
.empty b { display: block; color: var(--mut); font-size: 14px; margin-bottom: 6px; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--dim); }
.pager .pages { display: flex; gap: 6px; }

/* 生成结果 */
.gen-grid { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
.gen-form { padding: 18px; }
.gen-form h3 { margin: 0 0 14px; font-size: 14px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.result { padding: 16px; }
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.result-head h3 { margin: 0; font-size: 14px; }
.code-list { display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow: auto; }
.code-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: rgba(2, 6, 23, 0.5); }
.code-item .mono { flex: 1; font-size: 12.5px; letter-spacing: 0.04em; }

/* 设置 */
.kv { padding: 4px 0 14px; }
.kv-row { display: flex; gap: 12px; padding: 11px 18px; border-bottom: 1px solid rgba(148, 163, 184, 0.07); font-size: 13px; }
.kv-row:last-child { border-bottom: 0; }
.kv-k { width: 96px; flex: none; color: var(--dim); font-size: 12px; }
.kv-v { min-width: 0; word-break: break-all; }
.kv-v .mono { font-size: 12px; color: var(--mut); }

/* 底部 sheet */
.sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet-mask { position: absolute; inset: 0; background: rgba(2, 6, 23, 0.66); backdrop-filter: blur(6px); animation: fade 0.2s ease both; }
.sheet-body {
  position: relative;
  width: min(100%, 480px);
  max-height: 86vh;
  overflow: auto;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border-radius: 18px 18px 0 0;
  border: 1px solid var(--line-2);
  border-bottom: 0;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.98), rgba(5, 7, 13, 0.99));
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.5);
  animation: sheetUp 0.26s cubic-bezier(0.2, 0.9, 0.3, 1) both;
}

.sheet-title { margin: 0 0 4px; font-size: 15px; }
.sheet-sub { margin: 0 0 16px; font-size: 12px; color: var(--dim); }
.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.sheet-actions .btn { justify-content: flex-start; padding: 12px 14px; }
.sheet-close { position: absolute; top: 12px; right: 12px; }

.detail-grid { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.detail-row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; padding: 7px 0; border-bottom: 1px dashed rgba(148, 163, 184, 0.12); }
.detail-row span { color: var(--dim); }
.detail-row b { font-weight: 500; text-align: right; word-break: break-all; }

.device { display: flex; justify-content: space-between; gap: 10px; padding: 9px 10px; border-radius: 8px; background: rgba(148, 163, 184, 0.06); margin-bottom: 6px; font-size: 11.5px; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid rgba(52, 211, 153, 0.32);
  background: rgba(6, 18, 14, 0.95);
  color: #d1fae5;
  font-size: 12.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 90;
  max-width: 86vw;
  text-align: center;
}
.toast[data-show="1"] { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="err"] { border-color: rgba(248, 113, 113, 0.4); color: #fecaca; background: rgba(26, 8, 8, 0.95); }

/* 手机 */
.tabbar { display: none; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes sheetUp { from { transform: translateY(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .main { padding: 16px 14px calc(84px + env(safe-area-inset-bottom)); }
  .topbar { margin-bottom: 14px; }
  .topbar h2 { font-size: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 12px 13px; }
  .stat-value { font-size: 22px; }
  .gen-grid { grid-template-columns: minmax(0, 1fr); }

  .chead { display: none; }
  .crow {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "code act" "state state" "dev exp";
    gap: 7px 10px;
    padding: 12px 14px;
  }
  .c-code { grid-area: code; }
  .c-act { grid-area: act; }
  .c-state { grid-area: state; }
  .c-dev { grid-area: dev; }
  .c-exp { grid-area: exp; }
  .c-exp em { display: inline; margin-left: 6px; }

  .tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(5, 9, 16, 0.94);
    backdrop-filter: blur(16px);
  }
  .tabbar a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 5px 0;
    font-size: 10px;
    color: var(--dim);
    position: relative;
  }
  .tabbar a[data-active="1"] { color: var(--acc); }
  .tabbar svg { width: 20px; height: 20px; }
  .tab-fab .fab {
    width: 34px;
    height: 34px;
    margin-top: -14px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    font-size: 20px;
    font-weight: 300;
    color: #04160f;
    background: linear-gradient(135deg, #34d399, #38bdf8);
    box-shadow: 0 8px 22px rgba(52, 211, 153, 0.36);
  }
  .tab-fab span:last-child { margin-top: 1px; }

  .toast { bottom: calc(78px + env(safe-area-inset-bottom)); }
  .sheet-body { border-radius: 20px 20px 0 0; }
}

@media (min-width: 861px) {
  .sheet { align-items: center; }
  .sheet-body { border-radius: 16px; border-bottom: 1px solid var(--line-2); animation: rise 0.24s cubic-bezier(0.2, 0.9, 0.3, 1) both; }
}
