/* KDKJ / FM&TK 授权后台 —— 全新界面。浅色为主，支持深色。 */
:root {
  --bg: #f5f6f8;
  --bg-grad-1: rgba(11, 138, 114, 0.06);
  --bg-grad-2: rgba(37, 99, 235, 0.05);
  --card: #ffffff;
  --card-2: #f8fafc;
  --line: #e6e9ee;
  --line-strong: #d4d9e0;
  --text: #1c2430;
  --text-2: #5b6472;
  --muted: #8a93a2;
  --accent: #0b8a72;
  --accent-weak: rgba(11, 138, 114, 0.1);
  --blue: #2563eb;
  --danger: #d64545;
  --danger-weak: rgba(214, 69, 69, 0.1);
  --warning: #c37a24;
  --warning-weak: rgba(195, 122, 36, 0.12);
  --shadow-sm: 0 1px 2px rgba(20, 28, 40, 0.05);
  --shadow: 0 6px 24px rgba(20, 28, 40, 0.07);
  --radius: 14px;
  --radius-sm: 10px;
}
:root[data-theme="dark"] {
  --bg: #0f141b;
  --bg-grad-1: rgba(11, 138, 114, 0.1);
  --bg-grad-2: rgba(37, 99, 235, 0.08);
  --card: #171e27;
  --card-2: #1e2732;
  --line: #29323e;
  --line-strong: #37414f;
  --text: #e7ecf2;
  --text-2: #a7b0bd;
  --muted: #78828f;
  --accent: #2bb89a;
  --accent-weak: rgba(43, 184, 154, 0.14);
  --blue: #5b8def;
  --danger: #e2635f;
  --danger-weak: rgba(226, 99, 95, 0.15);
  --warning: #d8993f;
  --warning-weak: rgba(216, 153, 63, 0.16);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 400px at 15% -10%, var(--bg-grad-1), transparent 60%),
    radial-gradient(1000px 400px at 100% 0%, var(--bg-grad-2), transparent 55%),
    var(--bg);
  font-size: 14px;
  line-height: 1.55;
}

/* ── 通用控件 ───────────────────────────────────────────── */
input, select, button, textarea { font-family: inherit; font-size: 14px; }
input, select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}
input::placeholder { color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, transform 0.05s, opacity 0.15s;
  background: var(--card);
  color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { filter: brightness(1.06); }
.btn--ghost { background: transparent; border-color: var(--line-strong); color: var(--text-2); }
.btn--ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn--danger { background: var(--danger-weak); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn--block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: transparent; cursor: pointer; font-size: 16px; line-height: 1;
}
.icon-btn:hover { border-color: var(--accent); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-2); }

/* ── 登录 ───────────────────────────────────────────────── */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 34px 30px;
  display: grid;
  gap: 14px;
  text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h1 { margin: 0; font-size: 21px; }
.login-sub { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.login-card .field { text-align: left; }
.login-card .btn { margin-top: 4px; height: 44px; }

/* ── 顶栏 ───────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--card) 82%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.topbar-logo { font-size: 18px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.who { color: var(--muted); font-size: 13px; padding-right: 4px; }

.wrap {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 28px) clamp(16px, 4vw, 40px) 60px;
  display: grid;
  gap: 16px;
}

/* ── 产品筛选 ───────────────────────────────────────────── */
.product-tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.product-tab {
  display: inline-flex; align-items: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--card); color: var(--text-2);
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: all 0.15s;
}
.product-tab:hover { color: var(--text); border-color: var(--accent); }
.product-tab--on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.product-tab .cnt {
  min-width: 20px; padding: 1px 6px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.08); font-size: 11px; text-align: center; font-weight: 600;
}
:root[data-theme="dark"] .product-tab .cnt { background: rgba(255, 255, 255, 0.1); }
.product-tab--on .cnt { background: rgba(255, 255, 255, 0.24); }

/* ── 统计卡 ─────────────────────────────────────────────── */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
  padding: 16px 18px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  display: grid; gap: 3px;
  border-left: 3px solid var(--line-strong);
}
.stat--ok { border-left-color: var(--accent); }
.stat--warn { border-left-color: var(--warning); }
.stat--muted { border-left-color: var(--muted); }
.stat-label { color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.stat strong { font-size: 26px; line-height: 1.1; font-weight: 700; }
.stat-sub { color: var(--muted); font-size: 11.5px; }

/* ── 面板 ───────────────────────────────────────────────── */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.panel-head h2 { margin: 0; font-size: 15.5px; display: flex; align-items: center; gap: 8px; }
.count-badge {
  font-size: 12px; font-weight: 600; color: var(--text-2);
  background: var(--card-2); border: 1px solid var(--line);
  padding: 1px 8px; border-radius: 999px;
}
.controls { display: flex; gap: 8px; flex-wrap: wrap; }
.search { width: min(300px, 60vw); }
.sort { width: auto; padding-right: 30px; }

/* ── 发码表单 ───────────────────────────────────────────── */
.create-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.7fr 0.8fr 0.9fr 0.9fr 2fr auto;
  gap: 12px; align-items: end;
}
.create-grid .btn { height: 40px; }
.create-hint { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.result {
  margin-top: 14px; padding: 14px;
  background: var(--accent-weak); border: 1px solid transparent;
  border-radius: var(--radius-sm);
}
.result-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--accent);
}
.result pre {
  margin: 0; font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13.5px; line-height: 1.8; white-space: pre-wrap; word-break: break-all;
  color: var(--text);
}

/* ── 表格 ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.table { width: 100%; border-collapse: collapse; min-width: 820px; }
.table th, .table td {
  padding: 12px 12px; text-align: left; vertical-align: top;
  border-top: 1px solid var(--line);
}
.table thead th {
  border-top: none; border-bottom: 1px solid var(--line-strong);
  color: var(--muted); font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em;
  position: sticky; top: 0;
}
.table tbody tr:hover { background: var(--card-2); }
.col-actions { text-align: right; }

.code-cell { display: grid; gap: 3px; }
.code-main { display: flex; align-items: center; gap: 6px; }
.code-text { font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600; font-size: 13.5px; letter-spacing: 0.02em; }
.copy-mini {
  border: none; background: transparent; cursor: pointer; padding: 2px 4px;
  border-radius: 6px; font-size: 13px; color: var(--muted); line-height: 1;
}
.copy-mini:hover { background: var(--accent-weak); color: var(--accent); }
.code-time { color: var(--muted); font-size: 11.5px; }

.pbadge {
  display: inline-block; padding: 3px 9px; border-radius: 7px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--card-2); color: var(--text-2); border: 1px solid var(--line);
}
.pbadge--fmtk { background: var(--accent-weak); color: var(--accent); border-color: transparent; }
.pbadge--kdkj { background: var(--warning-weak); color: var(--warning); border-color: transparent; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--active { background: var(--accent-weak); color: var(--accent); }
.pill--revoked { background: var(--danger-weak); color: var(--danger); }
.pill--expired { background: var(--warning-weak); color: var(--warning); }
.tag-soon {
  display: inline-block; margin-top: 4px;
  font-size: 11px; font-weight: 600; color: var(--warning);
  background: var(--warning-weak); padding: 1px 7px; border-radius: 6px;
}

.expire-cell { display: grid; gap: 2px; }
.expire-main { font-size: 13px; }
.expire-sub { color: var(--muted); font-size: 11.5px; }

.bind-cell { display: grid; gap: 2px; min-width: 170px; }
.bind-code { font-weight: 600; font-size: 13px; }
.bind-sub { color: var(--muted); font-size: 11.5px; }
.bind-none { color: var(--muted); font-size: 12.5px; }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.row-actions .btn { height: 30px; padding: 0 10px; font-size: 12.5px; }

/* 行内编辑 */
.edit-row td { background: var(--card-2); }
.edit-grid { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.edit-grid .field { min-width: 130px; }
.edit-grid .field.grow { flex: 1; min-width: 200px; }
.edit-grid input { height: 36px; }

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

/* ── loading skeleton ───────────────────────────────────── */
.skeleton-row td { padding: 16px 12px; }
.sk {
  height: 12px; border-radius: 6px;
  background: linear-gradient(90deg, var(--line) 25%, var(--card-2) 37%, var(--line) 63%);
  background-size: 400% 100%; animation: sk 1.2s ease infinite;
}
@keyframes sk { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ── toast ──────────────────────────────────────────────── */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: #1f2630; color: #fff; box-shadow: var(--shadow);
  font-size: 13.5px; animation: toast-in 0.2s ease;
}
.toast--err { background: var(--danger); }
.toast--ok { background: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── 响应式 ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .create-grid { grid-template-columns: 1fr 1fr; }
  .create-grid .field--grow, .create-grid .btn { grid-column: 1 / -1; }
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .create-grid { grid-template-columns: 1fr 1fr; }
  .topbar .who { display: none; }
  .search { width: 100%; }
  .controls { width: 100%; }
}

/* ── AI 标题配置 ─────────────────────────────────────────── */
.aicfg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.aicfg-grid .field--grow { grid-column: 1 / -1; }
.key-row { display: flex; gap: 8px; }
.key-row input { flex: 1; }
textarea.mono {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text); font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 13px; line-height: 1.6; resize: vertical;
}
textarea.mono:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.aicfg-words { margin-top: 14px; }
.aicfg-words > summary { cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 600; padding: 6px 0; }
.aicfg-words .prefix-in { width: 90px; height: 26px; padding: 0 8px; font-size: 12px; display: inline-block; }
.aicfg-actions { display: flex; align-items: center; gap: 14px; margin-top: 16px; }
.aicfg-status { font-size: 13px; color: var(--text-2); }

/* ── AI 配置：品类编辑块 ─────────────────────────────────── */
.aicfg-h3 { margin: 20px 0 4px; font-size: 14px; }
.aicfg-cat { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; margin-top: 12px; background: var(--card-2); }
.aicfg-cat-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.aicfg-cat-head > b { font-size: 14px; }
.aicfg-prefix-label { font-size: 12.5px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.aicfg-cat-count { margin-left: auto; font-size: 12px; color: var(--muted); }
.aicfg-cat-head .len-in { width: 62px; height: 26px; padding: 0 6px; font-size: 12px; display: inline-block; }
