:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #fafbfe;
  --border: #e6e9f0;
  --text: #1d2433;
  --muted: #6b7488;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 8px 24px rgba(16,24,40,.05);
  --shadow-lg: 0 20px 48px rgba(16,24,40,.10);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.icon-defs { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; display: inline-block; vertical-align: -3px; flex: none; }
.page-bg {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(720px 360px at 12% -8%, rgba(99,102,241,.10), transparent 65%),
    radial-gradient(620px 320px at 92% 4%, rgba(14,165,233,.08), transparent 60%);
}
.app { max-width: 940px; margin: 0 auto; padding: 0 24px 48px; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 22px 0 20px; margin-bottom: 30px;
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 42px; height: 42px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff; border-radius: 12px; box-shadow: 0 6px 16px rgba(79,70,229,.28);
}
.brand-mark .icon { width: 24px; height: 24px; }
.brand-title { font-weight: 700; font-size: 18px; letter-spacing: -.3px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.topnav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nav-link {
  padding: 7px 13px; border-radius: 8px; color: var(--muted);
  text-decoration: none; font-size: 13px; font-weight: 600; transition: .15s;
}
.nav-link:hover { background: var(--surface); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary); }
.user-chip {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 99px; padding: 6px 13px; font-size: 12px; color: var(--muted);
  box-shadow: var(--shadow);
}

/* Hero */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, #312e81 0%, #4f46e5 55%, #0ea5e9 140%);
  color: #fff; border-radius: 20px; padding: 44px 40px 38px;
  margin-bottom: 22px; box-shadow: var(--shadow-lg);
}
.hero::after {
  content: ""; position: absolute; right: -60px; top: -80px;
  width: 280px; height: 280px; border-radius: 50%;
  background: rgba(255,255,255,.08);
}
.hero-icon {
  display: grid; place-items: center; width: 44px; height: 44px;
  background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.22);
  border-radius: 12px; margin-bottom: 18px;
}
.hero-icon .icon { width: 24px; height: 24px; }
.hero h1 { margin: 0 0 10px; font-size: 30px; letter-spacing: -.6px; position: relative; }
.hero p { margin: 0; color: rgba(255,255,255,.82); font-size: 15px; max-width: 560px; position: relative; }
.hero-features { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 24px; position: relative; }
.hero-features span {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; color: rgba(255,255,255,.9);
  background: rgba(255,255,255,.10); padding: 6px 12px; border-radius: 99px;
}
.hero-features .icon { width: 15px; height: 15px; }

/* 卡片 */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px 28px; margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.login-card { max-width: 640px; }
.center-card { text-align: center; padding: 54px 40px; }
.card-head { margin-bottom: 20px; }
.card-head.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -.4px; }
h2 { margin: 0 0 6px; font-size: 18px; letter-spacing: -.2px; }
h3 { margin: 0 0 6px; font-size: 15px; }
p { margin: 0; color: var(--muted); font-size: 14px; }
strong { color: var(--text); }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin-bottom: 6px; }
.welcome { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.status-cluster { display: flex; gap: 8px; flex-wrap: wrap; }
.status-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 99px; padding: 7px 13px; font-size: 12px; font-weight: 600;
  box-shadow: var(--shadow);
}
.status-pill .icon { width: 15px; height: 15px; color: var(--primary); }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }

/* 按钮 */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); border-radius: 9px; padding: 9px 15px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: .15s ease; font-family: inherit;
}
.btn:hover { border-color: #c7cddb; transform: translateY(-1px); }
.btn:active { transform: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79,70,229,.22); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-lg { padding: 13px 22px; font-size: 15px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* 表单 */
.field { margin-bottom: 16px; }
label { display: block; font-size: 12px; font-weight: 700; margin-bottom: 7px; color: var(--text); }
select, input[type="text"], input[type="password"], input[type="number"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface-2); color: var(--text);
  font-size: 13px; font-family: inherit; transition: .15s;
}
select:focus, input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); background: var(--surface); }

/* 格式切换 */
.format-tabs {
  display: inline-flex; gap: 4px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 4px; margin-bottom: 18px;
}
.format-tab {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  padding: 8px 16px; border-radius: 7px; font-size: 13px; font-weight: 700;
  font-family: inherit; transition: .15s;
}
.format-tab span { font-weight: 500; font-size: 11px; opacity: .7; margin-left: 3px; }
.format-tab:hover { color: var(--text); }
.format-tab.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }

/* 输出区 */
.output-wrap { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.output-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 9px 14px; background: var(--surface); border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--muted); font-weight: 600;
}
.output {
  width: 100%; min-height: 240px; max-height: 480px; overflow: auto;
  margin: 0; padding: 16px; background: transparent;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px; line-height: 1.65; white-space: pre-wrap; word-break: break-all; color: #374151;
}
.output:empty::before { content: attr(placeholder); color: var(--muted); }

/* 提示 */
.notice { padding: 11px 14px; border-radius: 9px; font-size: 13px; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; }
.notice .icon { width: 16px; height: 16px; }
.notice-error { background: var(--danger-bg); color: var(--danger); }
.notice-ok { background: var(--success-bg); color: var(--success); }
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 50;
  background: #1d2433; color: #fff; padding: 12px 18px; border-radius: 10px;
  font-size: 13px; box-shadow: var(--shadow-lg); animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateY(12px); opacity: 0; } }

/* 状态图标与进度 */
.state-icon {
  display: grid; place-items: center; width: 56px; height: 56px;
  border-radius: 16px; margin: 0 auto 18px;
}
.state-icon .icon { width: 28px; height: 28px; }
.state-icon-warn { background: var(--warn-bg); color: var(--warn); }
.threshold-bar { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 99px; overflow: hidden; max-width: 320px; margin: 20px auto; }
.threshold-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; transition: width .5s ease; }
.center-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* 短链 */
.short-row { display: flex; gap: 8px; }
.short-row input { flex: 1; }
.short-list { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.short-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 11px 14px; font-size: 13px;
  transition: .15s;
}
.short-item:hover { border-color: #cfd5e2; background: var(--surface); }
.short-item code { font-family: ui-monospace, monospace; font-weight: 700; color: var(--primary); }
.short-item a { color: var(--primary); text-decoration: none; font-size: 12px; font-weight: 600; }
.short-item a:hover { text-decoration: underline; }
.empty-state { color: var(--muted); font-size: 13px; padding: 22px; text-align: center; border: 1px dashed var(--border); border-radius: 9px; margin-top: 16px; background: var(--surface-2); }
.traffic-rows { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.traffic-row { border: 1px solid var(--border); border-radius: 9px; padding: 12px 14px; background: var(--surface-2); }
.traffic-row-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 13px; }
.traffic-row-head strong { font-weight: 700; }
.traffic-row-head span { color: var(--muted); font-size: 12px; }
.traffic-row .usage-bar { margin-top: 10px; }
.footer-actions { text-align: center; margin-top: 8px; }
.footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0 0; }

/* 后台专用 */
.admin-layout { display: grid; grid-template-columns: 210px 1fr; gap: 22px; align-items: start; }
.sidebar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); position: sticky; top: 20px;
}
.sidebar-title { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; padding: 8px 10px; }
.side-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 9px; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 0; background: transparent; width: 100%; text-align: left; font-family: inherit;
  transition: .15s;
}
.side-link:hover { background: var(--surface-2); color: var(--text); }
.side-link.active { background: var(--primary-soft); color: var(--primary); }
.side-link .icon { width: 17px; height: 17px; }
.admin-main { min-width: 0; }
.section { scroll-margin-top: 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat {
  background: linear-gradient(160deg, var(--surface), var(--surface-2));
  border: 1px solid var(--border); border-radius: 11px; padding: 16px;
}
.stat-label { color: var(--muted); font-size: 12px; font-weight: 600; }
.stat-value { font-size: 23px; font-weight: 700; margin-top: 6px; letter-spacing: -.5px; }
.stat-value.accent { color: var(--primary); }
.usage-bar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 12px; }
.usage-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; transition: width .4s ease; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 700; font-size: 12px; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.url { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); }
.row-actions { display: flex; gap: 5px; flex-wrap: wrap; }
.row-actions .btn { padding: 5px 10px; font-size: 12px; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 11px; font-weight: 700; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.tag.off { background: #f1f3f7; color: var(--muted); }
.tag.ok { background: var(--success-bg); color: var(--success); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.inline-form .field { margin: 0; }
.field-full { grid-column: 1 / -1; }
.edit-panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 18px; margin-bottom: 16px; }
.edit-panel .row-actions { margin-top: 16px; }
.code-block {
  background: #1d2433; color: #e5e7eb; border-radius: 9px; padding: 14px 16px;
  font-family: ui-monospace, monospace; font-size: 12px; line-height: 1.7;
  white-space: pre-wrap; word-break: break-all; user-select: all; margin-top: 10px;
}
.hint { font-size: 12px; color: var(--muted); background: var(--primary-soft); color: var(--primary); padding: 10px 13px; border-radius: 9px; margin-bottom: 16px; }
.hint .icon { width: 15px; height: 15px; }

.hidden { display: none !important; }
@media (max-width: 760px) {
  .admin-layout { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}
@media (max-width: 600px) {
  .app { padding: 0 16px 36px; }
  .card { padding: 20px; }
  .hero { padding: 32px 24px; }
  .hero h1 { font-size: 24px; }
  .card-head.row { flex-direction: column; }
  .format-tabs { width: 100%; }
  .format-tab { flex: 1; padding: 8px 6px; }
  .short-row { flex-direction: column; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 14px; }
}
