:root {
  --bg: #0d1117;
  --bg2: #0a0e14;
  --panel: #161b22;
  --panel2: #1c2330;
  --border: #2d333b;
  --border2: #3a414d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #2f81f7;
  --accent2: #1f6feb;
  --green: #3fb950;
  --red: #f85149;
  --yellow: #d29922;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", Roboto, sans-serif;
  font-size: 14px; line-height: 1.55;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: "SFMono-Regular", Consolas, "Courier New", monospace; }

/* ---------- 布局 ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #2f81f7, #8250df);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; color: #fff;
}
.brand-logo.lg { width: 46px; height: 46px; font-size: 24px; }
.brand-name { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.nav { flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: var(--muted); font-weight: 500;
}
.nav-item:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--panel2); color: #fff; }
.nav-ico { width: 20px; text-align: center; font-size: 16px; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.user-chip { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.user-chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.logout { color: var(--muted); font-size: 12px; }
.logout:hover { color: var(--red); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; border-bottom: 1px solid var(--border);
  background: var(--bg); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar-right { color: var(--muted); font-size: 13px; }
.content { padding: 24px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- 统计卡 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px;
}
.stat-label { color: var(--muted); font-size: 13px; }
.stat-value { font-size: 28px; font-weight: 700; margin: 4px 0 2px; }
.stat-hint { color: var(--muted); font-size: 12px; }
.stat.blue .stat-value { color: var(--accent); }
.stat.green .stat-value { color: var(--green); }
.stat.yellow .stat-value { color: var(--yellow); }

/* ---------- 面板 ---------- */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.panel-body { padding: 18px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--bg2); }
.table tbody tr:hover { background: #12171f; }
.table .ellip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.table .val { max-width: 200px; }
.table .empty { text-align: center; color: var(--muted); padding: 32px; }
.sm { font-size: 12px; }
.ops { display: flex; gap: 10px; align-items: center; }
/* 🔴 绝不能把 display:flex 直接加在 <td> 上：<td> 会脱离表格单元格布局，
   导致表头与内容错列、相邻列重叠（按钮被盖住点不到）。这里强制还原为单元格。 */
td.ops { display: table-cell; white-space: nowrap; font-size: 0; }
td.ops > * { font-size: 13px; vertical-align: middle; }
td.ops > * + * { margin-left: 12px; }
.op { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; }
.op:hover { text-decoration: underline; }
.op.danger { color: var(--red); }

/* ---------- 批量勾选 / 导出直链 ---------- */
.head-ops { display: flex; align-items: center; gap: 10px; }
.table th.chk, .table td.chk { width: 34px; padding-left: 14px; padding-right: 2px; text-align: center; }
.table th.chk input, .table td.chk input {
  width: 15px; height: 15px; margin: 0; cursor: pointer;
  vertical-align: middle; accent-color: var(--accent);
}
#btn-export-links:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 徽标 ---------- */
.badge { padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-on { background: rgba(63,185,80,.15); color: var(--green); }
.badge-off { background: rgba(139,148,158,.15); color: var(--muted); }
.badge-exp { background: rgba(210,153,34,.16); color: var(--yellow); }
.tag { padding: 2px 8px; border-radius: 6px; background: rgba(47,129,247,.14); color: #79b8ff; font-size: 12px; }

/* ---------- 定时直链 ---------- */
.life-col { min-width: 132px; }
.life-ok { color: var(--green); font-weight: 600; font-size: 13px; }
.life-exp { color: var(--yellow); font-weight: 600; font-size: 13px; }
.life-forever { color: var(--muted); font-size: 13px; }
.dl-col { min-width: 108px; }
.dl-count { font-weight: 700; font-size: 15px; color: var(--accent); }

/* 上传区的存活时长控件：跟在一行里，不要拉满整行宽 */
.upload-life { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.upload-row .input.life-num { width: 90px; }
.upload-row .input.life-unit { width: 96px; }

/* ---------- 日志筛选 ---------- */
.log-filter { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.log-filter .input { width: auto; flex: 1; min-width: 150px; }
.filter-chip {
  display: inline-block; margin: 0 0 14px; padding: 5px 12px; border-radius: 20px;
  background: rgba(47,129,247,.12); color: #79b8ff; font-size: 12px;
}
.filter-chip a { color: var(--accent); margin-left: 6px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px; }
.btn-ghost.danger { color: var(--red); border-color: rgba(248,81,73,.4); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  cursor: pointer; font-size: 14px; font-weight: 600; font-family: inherit;
  transition: all .12s ease; background: var(--panel2); color: var(--text);
}
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--accent2); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border2); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn:disabled, .btn.is-busy { opacity: .55; cursor: not-allowed; pointer-events: none; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { color: var(--muted); font-size: 13px; }
.input, input[type=text], input[type=password], textarea, select {
  background: var(--bg); border: 1px solid var(--border2); border-radius: 8px;
  color: var(--text); padding: 9px 12px; font-size: 14px; font-family: inherit;
  outline: none; width: 100%;
}
.input:focus, input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 90px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.hint { margin-top: 14px; color: var(--muted); font-size: 13px; }

/* ---------- 代码块 ---------- */
.code-block { position: relative; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin: 12px 0; }
.code-block pre { margin: 0; overflow-x: auto; color: #a5d6ff; font-size: 13px; line-height: 1.7; }
.code-block .btn { position: absolute; top: 10px; right: 10px; }

/* ---------- 上传 ---------- */
.upload-box { display: flex; flex-direction: column; gap: 12px; }
.upload-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.upload-row label.btn { position: relative; overflow: hidden; }
.upload-row label.btn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.progress {
  position: relative; height: 24px; background: var(--bg);
  border: 1px solid var(--border2); border-radius: 7px; overflow: hidden;
  display: none; align-items: center;
}
.progress.show { display: flex; }
.progress-bar {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width .2s ease;
}
.progress-text {
  position: relative; z-index: 1; width: 100%; text-align: center;
  font-size: 12px; font-weight: 600; color: #fff; letter-spacing: .3px;
}

/* ---------- 登录 ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: radial-gradient(1200px 600px at 50% -10%, #16243a 0%, var(--bg) 60%); }
.login-wrap { width: 100%; max-width: 380px; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 34px; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand .brand-logo { margin: 0 auto 12px; }
.login-brand h1 { font-size: 18px; margin: 0; }
.login-err { background: rgba(248,81,73,.12); color: var(--red); border: 1px solid rgba(248,81,73,.3); border-radius: 8px; padding: 10px 12px; margin-bottom: 16px; font-size: 13px; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal-card { position: relative; background: var(--panel); border: 1px solid var(--border2); border-radius: 14px; width: 90%; max-width: 560px; padding: 22px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-x { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; top: 20px; right: 24px; z-index: 200;
  padding: 12px 18px; border-radius: 10px; font-weight: 600; font-size: 14px;
  transform: translateX(120%); transition: transform .25s ease; max-width: 340px;
}
.toast.show { transform: translateX(0); }
.toast.ok { background: var(--green); color: #fff; }
.toast.err { background: var(--red); color: #fff; }

/* ---------- 复制反馈 ---------- */
.op.is-copied { color: var(--green); }
.op.is-copied:hover { text-decoration: none; }

.copy-modal {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(1, 4, 9, .68);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.copy-modal.show { display: flex; }
.copy-modal-card {
  width: 100%; max-width: 540px;
  background: var(--panel); border: 1px solid var(--border2);
  border-radius: 12px; padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.copy-modal-title { font-size: 14px; color: var(--muted); margin-bottom: 12px; }
.copy-modal-input {
  width: 100%; padding: 10px 12px;
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border2); border-radius: 8px;
  font-family: "SFMono-Regular", Consolas, "Courier New", monospace; font-size: 13px;
}
.copy-modal-input:focus { outline: none; border-color: var(--accent); }
.copy-modal-ops { margin-top: 14px; text-align: right; }

.muted { color: var(--muted); }

@media (max-width: 768px) {
  .sidebar { width: 64px; }
  .brand-text, .nav-item span:last-child, .sidebar-foot .user-chip, .logout { display: none; }
  .nav-item { justify-content: center; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .log-filter .input { min-width: 100%; }
  .life-col, .dl-col { min-width: 0; }
}

/* ---------- 直链管理弹窗：直链列表 ---------- */
.links-list {
  display: flex; flex-direction: column; gap: 10px;
  max-height: 46vh; overflow-y: auto;
  padding-right: 2px;
}
.link-row {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.link-line {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.link-url {
  flex: 1; min-width: 220px;
  font-size: 12px; color: var(--muted);
  background: var(--panel); border-color: var(--border);
}
/* 按钮之间留出间距（原来 4px 太挤，用户明确提过） */
.link-ops { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
/* 「存活时间」就地下拉：与 .op 文字按钮同一视觉层次，不要占满整行 */
.link-ops .op-select,
.link-ops .op-unit {
  width: auto; padding: 4px 8px; font-size: 13px; border-radius: 6px;
  background: var(--panel); border-color: var(--border);
}
.link-ops .op-num { width: 76px; padding: 4px 8px; font-size: 13px; border-radius: 6px; }
.link-state { margin-top: 6px; color: var(--muted); }

/* ---------- 下载日志弹窗 ---------- */
/* 日志 / 风控弹窗的表格区：固定给一个最小高度，
   免得页数少的时候弹窗高度忽高忽低（翻页时看着像在闪） */
.logs-table-wrap {
  max-height: 68vh; min-height: 320px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
}
.logs-table-wrap .table { margin: 0; }
.logs-table-wrap thead th { position: sticky; top: 0; background: var(--bg2); z-index: 1; }
.btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ---------- 云变量：备注列（排在独立接口地址之前） ---------- */
.remark-col { width: 150px; }
.remark-txt { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 云变量：独立接口地址列 ---------- */
/* 地址列按内容自适应（**不再给 width:100%**）——
   否则它会把表格的富余宽度全吃掉，把右边的「返回值」列推得很远。
   富余宽度统一交给最后一列（操作列）吸收，中间各列都紧贴自己的内容。
   窗口实在窄时才出省略号，鼠标悬停看完整值（title）。 */
.api-col { min-width: 430px; }
.var-table thead th:last-child,
.var-table tbody td.ops { width: 100%; }
.api-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
/* 地址整段可选中：点一下即「全选 + 复制」（user-select:all 负责选中，
   JS 事件委托负责送进剪贴板，见 app.js）。刻意不用 input —— 它只是给你看和复制的，
   要改地址去点这一行的「编辑」。 */
.api-url-text {
  flex: 0 1 auto; min-width: 0; max-width: min(100%, 78ch);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; line-height: 1.5; color: var(--text);
  background: var(--panel2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 10px;
  cursor: copy; user-select: all;
}
.api-url-text:hover { border-color: var(--accent); }
.api-url-text.is-copied { border-color: var(--green); box-shadow: 0 0 0 2px rgba(63, 185, 80, .18); }

/* ---------- 大弹窗（调用日志 / 接口风控）：尽量宽，内容不省略 ---------- */
.modal-card-wide { width: 96vw; max-width: 1240px; }

/* 日志表格里的「提交内容」「客户端」都完整换行显示，不再截成一行小字 */
.req-cell, .ua-cell { white-space: pre-wrap; word-break: break-all; }
.req-cell { max-width: 520px; cursor: copy; user-select: all; border-radius: 4px; }
.ua-cell  { max-width: 280px; color: var(--muted); font-size: 12px; }
.req-cell:hover { background: var(--panel2); }
/* 复制成功后的高亮（接口地址 / 日志提交内容通用） */
.is-copied { background: rgba(63, 185, 80, .12); box-shadow: 0 0 0 2px rgba(63, 185, 80, .35); }

/* ---------- 云变量：接口风控 ---------- */
.risk-cfg, .risk-manual {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin-bottom: 12px;
}
.risk-cfg {
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel2);
}
.risk-inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.risk-inline input[type="number"] { width: 88px; }
.risk-manual input[type="text"] { flex: 1; min-width: 180px; }
.risk-reason { max-width: 260px; white-space: pre-wrap; word-break: break-all; }
/* 「已复制 ✓」始终占位（只切透明度），避免复制瞬间挤动列宽 */
.copy-tip {
  flex: 0 0 auto; font-size: 12px; white-space: nowrap;
  color: var(--green); opacity: 0; transition: opacity .18s;
}
.api-cell.copied .copy-tip { opacity: 1; }

