/* ============================================================
   模块分发后台 · 深色控制台
   结构：tokens → 基础 → 布局 → 组件 → 页面元素 → 响应式
   ============================================================ */

:root {
  --bg: #0e1013;
  --surface: #15181c;
  --surface-2: #1b2025;
  --surface-3: #23282f;
  --border: #262c34;
  --border-strong: #3a414c;
  --text: #e4e7eb;
  --text-2: #9aa2ac;
  --text-3: #7b838d;
  --accent: #d29922;
  --accent-strong: #e3b341;
  --accent-dim: rgba(210, 153, 34, .13);
  --ok: #3fb950;
  --ok-dim: rgba(63, 185, 80, .12);
  --danger: #f85149;
  --danger-dim: rgba(248, 81, 73, .12);
  --radius: 6px;
  --radius-lg: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --shadow-pop: 0 8px 24px rgba(0, 0, 0, .45);
}

/* ---------- 基础 ---------- */

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 var(--font);
}

a { color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
  border-radius: 2px;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- 布局 ---------- */

.shell { display: flex; min-height: 100vh; }

.side {
  width: 216px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 9px;
  padding: 18px;
  font-size: 14px; font-weight: 600; letter-spacing: .02em;
  border-bottom: 1px solid var(--border);
}
.brand-mark { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); flex-shrink: 0; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 12px 10px; flex: 1; }
.nav a {
  display: block; padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--text-2); font-size: 13px; text-decoration: none;
}
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); box-shadow: inset 2px 0 0 var(--accent); }

.side-foot { padding: 12px 18px; border-top: 1px solid var(--border); }
.side-foot a { color: var(--text-3); font-size: 13px; text-decoration: none; }
.side-foot a:hover { color: var(--text); }

.main { flex: 1; min-width: 0; padding: 28px 36px 56px; }
.main > * { max-width: 1060px; }

/* ---------- 页头 / 提示 ---------- */

.page-head { margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 19px; font-weight: 600; }
.page-sub { margin: 4px 0 0; font-size: 13px; color: var(--text-2); }

.flash {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; font-size: 13px; margin-bottom: 18px;
}
.flash-ok   { color: var(--ok);          border-color: rgba(63, 185, 80, .4);  background: var(--ok-dim); }
.flash-warn { color: var(--accent-strong); border-color: rgba(210, 153, 34, .4); background: var(--accent-dim); }
.flash-err  { color: var(--danger);     border-color: rgba(248, 81, 73, .4);  background: var(--danger-dim); }

/* ---------- 状态条（平铺一行，不做卡片阵列） ---------- */

.statline {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 20px;
  overflow: hidden;
}
.stat { flex: 1; padding: 14px 18px; min-width: 0; }
.stat + .stat { border-left: 1px solid var(--border); }
.stat-k { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.stat-v { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; word-break: break-all; }
.stat-v.is-accent { color: var(--accent-strong); }
.stat-v.is-muted { color: var(--text-3); font-weight: 400; }

/* ---------- 面板 ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.panel + .panel { margin-top: 20px; }
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 14px; font-weight: 600; }
.panel-meta { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.panel-body { padding: 16px 18px; }

/* ---------- 按钮 / 文本操作 ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  height: 32px; padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text); font: 500 13px/1 var(--font);
  cursor: pointer; text-decoration: none;
  transition: background-color .12s, border-color .12s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #171004; font-weight: 600; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-solid-danger { background: var(--danger); border-color: var(--danger); color: #1d0503; font-weight: 600; }
.btn-solid-danger:hover { background: #ff6b63; border-color: #ff6b63; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }

.tlink {
  background: none; border: 0; padding: 2px 1px;
  color: var(--text-2); font: 400 13px/1.4 var(--font);
  cursor: pointer; text-decoration: none;
  border-radius: 2px;
}
.tlink:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.tlink-danger { color: var(--danger); }
.tlink-danger:hover { color: #ff7a73; }

.tsep {
  display: inline-block; width: 1px; height: 12px;
  background: var(--border-strong); margin: 0 8px; vertical-align: -1px;
}

/* ---------- 表格 ---------- */

.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--text-2);
  padding: 10px 18px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr:hover td { background: rgba(255, 255, 255, .018); }
.tbl .num { text-align: right; }
.tbl .ops { text-align: right; white-space: nowrap; }
.tbl .ops form { display: inline-block; margin: 0; }

tr.empty td { color: var(--text-3); text-align: center; padding: 34px 18px; }
tr.empty td a { color: var(--text-2); text-decoration: underline; text-underline-offset: 3px; }

.t-name { font-weight: 600; }
.t-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.t-time { font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.cell-hash { white-space: nowrap; }
.cell-hash .hash { font-size: 12px; color: var(--text-2); margin-right: 8px; background: none; border: 0; padding: 0; }
.cell-ua {
  max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; color: var(--text-2);
}

/* 状态点 */
.status { display: inline-flex; align-items: center; font-size: 13px; }
.dot { width: 7px; height: 7px; border-radius: 50%; margin-right: 7px; background: var(--text-3); flex-shrink: 0; }
.status-cur { color: var(--accent-strong); } .status-cur .dot { background: var(--accent); }
.status-ok  { color: var(--ok); }            .status-ok .dot  { background: var(--ok); }
.status-off { color: var(--text-3); }
.status-err { color: var(--danger); }        .status-err .dot { background: var(--danger); }

/* ---------- 上传 ---------- */

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 30px 16px;
  cursor: pointer; text-align: center;
  transition: border-color .12s, background-color .12s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-dim); }
.dropzone:focus-within { outline: 2px solid var(--accent-strong); outline-offset: 2px; }
.dropzone input[type="file"] {
  position: absolute; width: 1px; height: 1px;
  opacity: 0; overflow: hidden;
}
.dz-main { font-size: 14px; }
.dz-sub { font-size: 12px; color: var(--text-3); }

.dz-file {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px; padding: 9px 12px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px;
}
.dz-filesize { color: var(--text-3); font-size: 12px; }
.dz-file .tlink { margin-left: auto; }

.form-row { display: flex; gap: 14px; margin-top: 16px; flex-wrap: wrap; }
.form-row .field { flex: 0 0 220px; margin: 0; }
.form-row .field.grow { flex: 1 1 260px; }

.upload-actions { display: flex; align-items: center; gap: 16px; margin-top: 16px; }
.progress {
  flex: 1; max-width: 380px; height: 4px;
  background: var(--surface-3); border-radius: 2px; overflow: hidden;
}
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .15s linear; }

/* ---------- 表单 ---------- */

.field { margin: 0 0 14px; min-width: 0; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }

.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  color: var(--text);
  padding: 7px 11px;
  font: 400 13px/1.5 var(--font);
  transition: border-color .12s;
}
.input:focus { outline: none; border-color: var(--accent-strong); }
.input::placeholder { color: var(--text-3); }
textarea.input { resize: vertical; min-height: 72px; }

.check-field { display: flex; align-items: flex-start; gap: 8px; margin: 14px 0 16px; }
.check-field input[type="checkbox"] { margin-top: 3px; width: 15px; height: 15px; accent-color: var(--accent); }
.check-field label { font-size: 13px; color: var(--text-2); margin: 0; cursor: pointer; }

.filterbar {
  display: flex; align-items: flex-end; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.filterbar .field { margin: 0; flex: 0 0 160px; }
.filterbar .field.grow { flex: 1 1 200px; }
.filterbar .btn { margin-bottom: 1px; }
.filterbar .clear-link { padding-bottom: 9px; }

/* ---------- 密钥 / 环境 ---------- */

.hint { margin: 0 0 12px; font-size: 13px; color: var(--text-2); }
.keyline { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.keyline form { display: inline-block; margin: 0; }
.key {
  font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px 10px; word-break: break-all;
}

.env { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 12px 28px; }
.env > div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  border-bottom: 1px dashed var(--border); padding-bottom: 10px;
}
.env dt { color: var(--text-2); font-size: 13px; white-space: nowrap; }
.env dd { margin: 0; font-size: 13px; word-break: break-all; text-align: right; }

/* ---------- 分页 ---------- */

.pager { display: flex; align-items: center; gap: 16px; padding: 12px 18px; }
.pager-info { font-size: 12.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* ---------- 确认弹窗 ---------- */

dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 0;
  min-width: 320px; max-width: calc(100vw - 40px);
  box-shadow: var(--shadow-pop);
}
dialog::backdrop { background: rgba(4, 6, 8, .6); }
.dlg-body { padding: 18px 20px 4px; }
.dlg-body p { margin: 0; font-size: 13.5px; line-height: 1.7; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px 18px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; top: 18px; right: 18px; z-index: 100;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-left: 2px solid var(--accent);
  color: var(--text);
  font-size: 13px;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  max-width: min(420px, calc(100vw - 36px));
  animation: toast-in .15s ease-out;
}
.toast-ok { border-left-color: var(--ok); }
.toast-err { border-left-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(-6px); opacity: 0; } }

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

.login-body {
  display: flex; min-height: 100vh;
  align-items: center; justify-content: center;
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 380px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 28px 26px;
}
.brand-lg { border-bottom: 0; padding: 0 0 20px; font-size: 15px; justify-content: center; }
.login-lead { margin: 0 0 16px; font-size: 13px; color: var(--text-2); }
.login-card .flash { margin-bottom: 14px; }

/* ---------- 响应式 ---------- */

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side {
    position: static; width: auto; height: auto;
    flex-direction: row; align-items: center;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { border-bottom: 0; padding: 12px 16px; }
  .nav { flex-direction: row; padding: 6px 4px; flex: 1; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .side-foot { border-top: 0; padding: 0 14px 0 0; }
  .main { padding: 18px 14px 40px; }

  .statline { flex-wrap: wrap; }
  .stat { flex: 1 1 46%; }
  .stat:nth-child(3) { border-left: 0; border-top: 1px solid var(--border); }
  .stat:nth-child(4) { border-top: 1px solid var(--border); }

  .form-row { flex-direction: column; }
  .form-row .field { flex: 1 1 auto; }
  .filterbar .field { flex: 1 1 130px; }
  .cell-ua { max-width: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}