/* ==========================================================================
   授权管理后台 · 样式
   无外部依赖（不引 CDN），跟随系统深浅色。
   ========================================================================== */

:root {
  --bg:        #f5f6f8;
  --panel:     #ffffff;
  --panel-2:   #fafbfc;
  --text:      #1a1d23;
  --text-2:    #5b6472;
  --muted:     #8b95a5;
  --border:    #e4e7ec;
  --border-2:  #eef0f3;

  --primary:   #4f46e5;
  --primary-h: #4338ca;
  --danger:    #dc2626;
  --danger-h:  #b91c1c;
  --ok:        #059669;
  --warn:      #d97706;

  --sidebar-bg:     #0f172a;
  --sidebar-text:   #94a3b8;
  --sidebar-active: #1e293b;
  --sidebar-accent: #818cf8;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0b0f17;
    --panel:    #121924;
    --panel-2:  #161e2b;
    --text:     #e6e9ef;
    --text-2:   #a8b3c4;
    --muted:    #7d8899;
    --border:   #232c3b;
    --border-2: #1b2432;

    --primary:   #6366f1;
    --primary-h: #818cf8;
    --danger:    #ef4444;
    --danger-h:  #f87171;
    --ok:        #34d399;
    --warn:      #fbbf24;

    --sidebar-bg:     #080c14;
    --sidebar-text:   #8494ab;
    --sidebar-active: #141d2b;
    --sidebar-accent: #818cf8;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

code, .mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", monospace;
}

/* ---------------------------------------------------------------- 布局 */
.layout {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 18px 12px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 4px 8px 18px;
}

.brand-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--sidebar-accent);
  box-shadow: 0 0 0 4px rgba(129, 140, 248, .15);
  flex: none;
}

.brand-name { color: #e8edf7; font-weight: 600; font-size: 14px; }
.brand-sub  { font-size: 11px; color: #5c6b82; margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--sidebar-active); color: #dbe4f3; }
.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: inset 2px 0 0 var(--sidebar-accent);
}
.nav-ico { width: 16px; text-align: center; opacity: .85; font-size: 13px; }

/* 侧边栏角标（如回收站件数）。深色底上取高对比红，置于条目右端。 */
.nav-badge {
  margin-left: auto;
  min-width: 18px;
  padding: 0 6px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.sidebar-foot {
  margin-top: auto;
  padding: 12px 10px 4px;
  font-size: 11px;
  color: #4d5b70;
  border-top: 1px solid rgba(255,255,255,.06);
}

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.page-title { font-size: 17px; font-weight: 600; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.who { font-size: 12.5px; color: var(--muted); }

.content { padding: 22px 26px 60px; display: flex; flex-direction: column; gap: 16px; }

/* ---------------------------------------------------------------- 面板 */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-head h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-head:not(:first-child) { margin-top: 20px; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1000px) { .two-col { grid-template-columns: 1fr; } }

.narrow { max-width: 720px; }

/* ---------------------------------------------------------------- 统计卡 */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (max-width: 1000px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -.02em; }
.stat-ok    .stat-value { color: var(--ok); }
.stat-warn  .stat-value { color: var(--warn); }
.stat-live  .stat-value { color: var(--primary); }
.stat-danger .stat-value { color: var(--danger); }

/* ---------------------------------------------------------------- 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-2);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--panel-2); }
.row-disabled td { opacity: .5; }
.row-admin td { background: rgba(99, 102, 241, .05); }

.ellipsis { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tiny { font-size: 11px; }

/* ---------------------------------------------------------------- 标签 */
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  line-height: 1.6;
  border: 1px solid transparent;
  white-space: nowrap;
}
.st-inactive { background: rgba(139,149,165,.14); color: var(--text-2); }
.st-active   { background: rgba(5,150,105,.13);  color: var(--ok); }
.st-disabled { background: rgba(220,38,38,.12);  color: var(--danger); }
.st-unknown  { background: rgba(217,119,6,.13);  color: var(--warn); }

.dot-online, .dot-offline {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
}
.dot-online  { background: var(--ok); box-shadow: 0 0 0 3px rgba(5,150,105,.16); }
.dot-offline { background: var(--border); }

/* ---------------------------------------------------------------- 按钮 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); border-color: var(--primary-h); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-h); border-color: var(--danger-h); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--border); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------- 表单 */
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.field-hint  { font-size: 11.5px; color: var(--muted); }

/* 生成卡密页：天数快捷选项（月卡/季卡/年卡） */
.quick-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 1px; }
.quick-row .btn { background: var(--panel-2); color: var(--text-2); }
.quick-row .btn:hover { border-color: var(--primary); color: var(--primary); }

.input {
  width: 100%;
  padding: 8px 11px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, .16);
}
.input[readonly] { background: var(--panel-2); color: var(--muted); }
textarea.input { resize: vertical; min-height: 68px; }
select.input { cursor: pointer; }
.input-num { width: 110px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .field:nth-of-type(3),
.form-grid .field:nth-of-type(4) { grid-column: span 1; }
@media (max-width: 720px) { .form-grid { grid-template-columns: 1fr; } }
.form-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }

.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-bar .input[type="text"] { flex: 1; min-width: 220px; }
.filter-bar select.input { width: auto; min-width: 130px; flex: none; }
.filter-count { margin-left: auto; font-size: 12px; }

/* ---------------------------------------------------------------- 提示条 */
.alert {
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 14px;
  line-height: 1.6;
}
.alert code { font-size: 12px; padding: 1px 5px; border-radius: 4px; background: rgba(0,0,0,.06); }
.alert-error { background: rgba(220,38,38,.09);  color: var(--danger); border-color: rgba(220,38,38,.22); }
.alert-warn  { background: rgba(217,119,6,.10);  color: var(--warn);   border-color: rgba(217,119,6,.24); }
.alert-ok    { background: rgba(5,150,105,.10);  color: var(--ok);     border-color: rgba(5,150,105,.22); }
.alert-info  { background: rgba(99,102,241,.09); color: var(--primary);border-color: rgba(99,102,241,.22); }
.alert-error code { background: rgba(220,38,38,.12); }

.empty { color: var(--muted); font-size: 13px; padding: 10px 0; margin: 0; }
.link { color: var(--primary); }
.link:hover { text-decoration: underline; }
.muted { color: var(--muted); }

/* ---------------------------------------------------------------- 键值表 */
.kv {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 7px 14px;
  margin: 0;
  font-size: 13px;
}
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; word-break: break-all; }
.prewrap { white-space: pre-wrap; }

/* ---------------------------------------------------------------- 操作区 */
.ops { display: flex; flex-direction: column; gap: 12px; }
.op-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0; }

.detail-head {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.card-code {
  font-size: 13.5px;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  letter-spacing: .04em;
}
.card-code.big { font-size: 16px; padding: 5px 12px; }

/* ---------------------------------------------------------------- 生成结果 */
.result-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.result-actions { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 8px;
  max-height: 460px;
  overflow-y: auto;
}
.card-list li { display: flex; }
.card-list .card-code { width: 100%; text-align: center; user-select: all; }

/* ---------------------------------------------------------------- 时间线 */
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.timeline li {
  display: flex;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border-2);
  align-items: baseline;
}
.timeline li:last-child { border-bottom: none; }
.tl-time { flex: none; width: 92px; font-size: 11.5px; }
.tl-action { flex: none; color: var(--primary); font-size: 11.5px; }
.tl-detail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- 分页 */
.pager {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: center;
  margin-top: 16px;
  font-size: 12.5px;
}

/* ---------------------------------------------------------------- 登录页 */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 0%, rgba(99,102,241,.10), transparent 45%),
    radial-gradient(circle at 85% 100%, rgba(129,140,248,.08), transparent 45%),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 26px;
  box-shadow: 0 4px 24px rgba(16, 24, 40, .08), 0 1px 3px rgba(16, 24, 40, .06);
}

.login-brand {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 22px;
}
.login-brand .brand-dot { background: var(--primary); box-shadow: 0 0 0 4px rgba(99,102,241,.14); }
.login-brand .brand-name { color: var(--text); font-size: 15px; }
.login-brand .brand-sub { color: var(--muted); }

.login-form { display: flex; flex-direction: column; gap: 14px; }

.login-hint {
  margin: 16px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  text-align: center;
}

/* ---------------------------------------------------------------- 卡密管理：排序 / 勾选 / 批量 */
.st-deleted { background: rgba(139,149,165,.14); color: var(--muted); }

.row-deleted td { opacity: .55; }

.col-check { width: 36px; text-align: center; }
.col-check input[type="checkbox"] { cursor: pointer; }

th.sortable { padding: 0; }
th.sortable a {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  color: inherit;
  text-decoration: none;
}
th.sortable a:hover { color: var(--primary); }
.sort-dir { font-size: 10px; color: var(--primary); }

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-2);
  font-size: 12.5px;
}
.bulk-scope { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; color: var(--text-2); }
.bulk-scope input { cursor: pointer; }
.bulk-bar .sep { width: 1px; height: 20px; background: var(--border); }
.bulk-bar .input-num { width: 84px; }
.bulk-count { margin-left: auto; }

/* 独立工具条（如「清理过期卡密」）：单列一个动作 + 右侧说明文字 */
.tool-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12.5px;
}
.tool-bar form { display: inline-flex; margin: 0; }
.tool-bar .muted { color: var(--muted); }

/* ---------------------------------------------------------------- 滚动条 */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted); }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------- 发布公告 / 更新（broadcast） */

/* 让某个 field 独占整行（版本号 / 下载链接区都要跨列） */
.form-grid .field.full { grid-column: 1 / -1; }

/* 下载线路列表：每行 = 线路名 + 链接 + 删除按钮，纵向堆叠 */
.dl-list { display: flex; flex-direction: column; gap: 8px; }
.dl-row { display: flex; gap: 8px; align-items: center; }
.dl-row .dl-name { flex: none; width: 170px; }
.dl-row .dl-url  { flex: 1; }
.dl-row .dl-del {
  flex: none; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel);
  color: var(--muted); cursor: pointer; font-size: 13px; line-height: 1;
}
.dl-row .dl-del:hover { border-color: var(--danger); color: var(--danger); }

/* 第 1 条 = 主按钮，用主色左边框点明「这条是主下载」 */
.dl-row-primary .dl-name { border-left: 3px solid var(--primary); }

/* 「填了 URL 但没填线路名」—— 该条保存后不会生效，必须显式警示 */
.dl-row-orphan .dl-name,
.dl-row-orphan .dl-url {
  border-color: var(--danger);
  background: rgba(220, 38, 38, .05);
}

.dl-add {
  align-self: flex-start; margin-top: 2px;
  background: transparent; border: 1px dashed var(--border);
  color: var(--text-2);
}
.dl-add:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: transparent; }
.dl-add:disabled { opacity: .45; cursor: not-allowed; }

/* 校验错误清单 */
.err-list { margin: 6px 0 0; padding-left: 20px; }
.err-list li { margin: 3px 0; }
.err-note { margin: 8px 0 0; font-size: 12px; opacity: .8; }

/* 表单下方的元信息行（上次修改人 / 时间） */
.meta-note { font-size: 12px; color: var(--muted); margin-top: 12px; }


/* ---------------------------------------------------------------- 风险事件（Stage 5） */
/* 「谁在打、打到哪一层」的展示构件：首页时间线 / 风险页表格 / 卡密详情共用。 */
.risk-chip {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: 11.5px;
  line-height: 1.6;
  white-space: nowrap;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text-2);
}
/* 高优先级代码（授权模块被换 / 指针被改 / 替身模型 / 清单不符）用红底标出 —— */
/* 这四类几乎不会是误报，管理员扫一眼就该看见。 */
.risk-severe {
  background: rgba(220, 38, 38, .12);
  border-color: rgba(220, 38, 38, .35);
  color: var(--danger);
}
/* 面板左侧红条：有风险事件时把该面板从一屏里「挑出来」。 */
.panel-alert { border-left: 3px solid var(--danger); }

/* ---------------------------------------------------------------- v2 增强（2026-10-05） */
/* 顶栏全局搜索：完整卡密直达详情，片段/备注去列表 */
.topbar-search { display: flex; gap: 6px; align-items: center; margin-left: 16px; flex: 1; max-width: 480px; }
.topbar-search .input { flex: 1; }
@media (max-width: 900px) { .topbar-search { display: none; } }

/* 统计卡变链接：整块可点，外观不变 */
a.stat { text-decoration: none; color: inherit; }
a.stat:hover { border-color: var(--primary); }

/* 趋势柱（纯 CSS，不引图表库） */
.trend-row { display: flex; align-items: flex-end; gap: 10px; margin: 10px 0; }
.trend-label { width: 64px; flex: none; text-align: right; padding-bottom: 16px; }
.trend { display: flex; align-items: flex-end; gap: 3px; height: 56px; flex: 1; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.trend-bar { width: 100%; max-width: 22px; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.trend-bar-ok { background: var(--ok); }
.trend-bar-danger { background: var(--danger); }
.trend-day { margin-top: 2px; }

/* 批次筛选输入框稍窄，别把一行挤爆 */
.input-batch { max-width: 150px; }
.input-card-ref { max-width: 190px; }

/* 窄屏：次要列隐藏 + 表格可横向滚动 */
@media (max-width: 980px) {
  .col-sm-hide { display: none; }
  .table { display: block; overflow-x: auto; white-space: nowrap; }
}
