/* ============================================================
   创信检测 · 组件库 ui.css
   依赖 tokens.css。所有页面统一引这两个文件。
   ============================================================ */

/* ---------------- 基础 ---------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: var(--fs-body)/var(--lh-body) var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, h4 { margin: 0; line-height: var(--lh-tight); font-weight: 700; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-num); }
.hide { display: none !important; }

/* ---------------- 应用外壳 ---------------- */
.app { display: flex; min-height: 100vh; }

/* 左侧栏 */
.side {
  width: var(--w-side); flex: 0 0 var(--w-side);
  background: var(--surface); border-right: 1px solid var(--line);
  padding: var(--sp-5) var(--sp-3);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand img { width: 30px; height: auto; display: block; }
.brand b { font-size: 15.5px; color: var(--brand-deep); letter-spacing: .2px; }
.brand small { display: block; color: var(--dim); font-size: 10.5px; font-weight: 400; letter-spacing: .8px; }

.nav-sec {
  font-size: 10.5px; color: var(--dim); letter-spacing: .5px;
  padding: var(--sp-3) 9px var(--sp-1);
}
.nav-i {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: var(--r-md);
  font-size: 14px; color: var(--ink-2); cursor: pointer;
  border: 1px solid transparent; background: none;
  width: 100%; text-align: left; transition: .14s;
}
.nav-i:hover { background: var(--surface-2); color: var(--ink); }
.nav-i.on {
  background: var(--brand-tint); color: var(--brand-deep);
  border-color: #cfe2f8; font-weight: 650;
}
.nav-i .dot { width: 7px; height: 7px; border-radius: 2px; flex: none; }
.nav-i .cnt {
  margin-left: auto; font-size: 11px; color: var(--muted);
  background: #f1f4f9; border-radius: var(--r-pill); padding: 0 7px; font-weight: 400;
}
.nav-i .cnt.hot { background: var(--danger-bg); color: var(--danger); }
.nav-i.sub { padding-left: 16px; font-size: 13.5px; }
.nav-i.lv2 { padding-left: 28px; font-size: 13px; color: #5b6577; }
.nav-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: var(--sp-2); }

/* 主区 */
.main { flex: 1; min-width: 0; padding: var(--sp-5) var(--sp-6) var(--sp-10); }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; gap: var(--sp-3);
  height: var(--h-top); padding: 0 var(--sp-6);
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: var(--z-nav);
}
.topbar h1 { font-size: var(--fs-h1); color: var(--brand-deep); letter-spacing: .2px; }
.topbar .sub { font-size: var(--fs-sm); color: var(--muted); }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: var(--sp-2); }

/* 页头（无顶栏时用） */
.page-hd { display: flex; align-items: flex-end; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-2); }
.page-hd h1 { font-size: var(--fs-h1); color: var(--brand-deep); }
.page-hd .sub { color: var(--muted); font-size: var(--fs-sm); }
.page-hd .right { margin-left: auto; display: flex; gap: var(--sp-2); align-items: center; }

/* ---------------- 卡片 ---------------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-4);
  box-shadow: var(--sh-1);
}
.card.flush { padding: 0; overflow: hidden; }
.card-hd {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line-2);
  font-size: var(--fs-h3); font-weight: 650; color: #123c6b;
}
.card-hd .right { margin-left: auto; font-weight: 400; font-size: var(--fs-sm); color: var(--muted); }
.card-bd { padding: var(--sp-4); }

/* 区块标题 */
.sec {
  margin: var(--sp-6) 0 var(--sp-3); font-size: var(--fs-h3); font-weight: 700;
  color: #0d3b6b; display: flex; align-items: center; gap: var(--sp-2);
}
.sec::before { content: ""; width: 3px; height: 14px; border-radius: 2px; background: var(--brand); }
.sec .right { margin-left: auto; font-weight: 400; font-size: var(--fs-sm); color: var(--muted); }

/* ---------------- 指标卡 ---------------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3); }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--sp-4);
  box-shadow: var(--sh-1);
}
.kpi .label { color: var(--muted); font-size: var(--fs-sm); margin-bottom: 6px; }
.kpi .value {
  font-size: var(--fs-display); font-weight: 750; letter-spacing: -.6px;
  line-height: 1.15; color: var(--brand-deep); font-variant-numeric: tabular-nums;
}
.kpi .value small { font-size: var(--fs-h3); font-weight: 400; color: var(--muted); margin-left: 4px; }
.kpi .extra { color: var(--dim); font-size: var(--fs-xs); margin-top: 6px; }
.kpi.up .value { color: var(--danger); }      /* 涨：红 */
.kpi.down .value { color: var(--leaf-deep); } /* 跌：绿 */

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: var(--fs-h3)/1 var(--font);
  padding: 10px 16px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; transition: .14s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn:focus-visible { outline: none; box-shadow: var(--sh-focus); }

.btn.pri { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 650; }
.btn.pri:hover { background: var(--brand-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-tint); }
.btn.danger { color: var(--danger); border-color: var(--danger-line); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }

.btn.sm { padding: 6px 11px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.lg { padding: 12px 22px; font-size: var(--fs-body); }
.btn.block { width: 100%; }
.btn.icon { padding: 8px; min-width: 34px; }

/* 加载态：文字保留，前面转圈 */
.btn.loading { pointer-events: none; opacity: .75; }
.btn.loading::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 按钮组 */
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-md) 0 0 var(--r-md); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r-md) var(--r-md) 0; }

/* ---------------- 表单 ---------------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: var(--fs-xs); color: var(--dim); }
.field .hint { font-size: var(--fs-xs); color: var(--dim); line-height: 1.6; }
.field .err { font-size: var(--fs-xs); color: var(--danger); }

.input, .select, .textarea {
  font: var(--fs-body)/1.4 var(--font);
  padding: 10px 12px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  width: 100%; outline: none; transition: .14s;
}
.input::placeholder, .textarea::placeholder { color: var(--dim); }
.input:hover, .select:hover, .textarea:hover { border-color: #cfdce9; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--brand); box-shadow: var(--sh-focus);
}
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
.input.invalid, .select.invalid { border-color: var(--danger); }
.textarea { resize: vertical; min-height: 84px; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
  linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 34px; }

/* 搜索框（带图标） */
.search { position: relative; }
.search .input { padding-left: 34px; }
.search::before {
  content: "⌕"; position: absolute; left: 11px; top: 50%; transform: translateY(-52%);
  color: var(--dim); font-size: 16px; pointer-events: none;
}

/* 复选 / 单选 */
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-body); }
.check input { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

/* 开关 */
.switch { position: relative; display: inline-block; width: 40px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch i {
  position: absolute; inset: 0; background: #cfd8e3; border-radius: var(--r-pill);
  transition: .18s; cursor: pointer;
}
.switch i::after {
  content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; transition: .18s; box-shadow: var(--sh-1);
}
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { left: 21px; }

/* 筛选工具条 */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end; margin-bottom: var(--sp-3); }
.toolbar .grow { flex: 1; min-width: 180px; }

/* ---------------- 表格 ---------------- */
.tblwrap {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); overflow: auto; box-shadow: var(--sh-1);
}
.tbl { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: var(--fs-table); }
.tbl th {
  text-align: left; padding: var(--sp-2) 12px; background: var(--surface-2);
  color: #475569; font-weight: 650; font-size: var(--fs-sm);
  border-bottom: 1px solid var(--line); white-space: nowrap;
  position: relative; user-select: none;
}
.tbl td {
  padding: var(--rowh) 12px; border-bottom: 1px solid var(--line-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tbl tbody tr:hover td { background: var(--brand-tint-2); }
.tbl tbody tr.sel td { background: var(--brand-tint); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .ct { text-align: center; }
.tbl .link { color: #14508f; cursor: pointer; }
.tbl .link:hover { text-decoration: underline; }

/* 换行模式：行高 ≥15px 时启用 */
.tbl.wrap td {
  white-space: normal; overflow: visible; text-overflow: clip;
  word-break: break-word; line-height: 1.5;
}
.tbl.wrap th { white-space: normal; }

/* 列宽拖动手柄 */
.colh {
  position: absolute; right: -3px; top: 0; bottom: 0; width: 8px;
  cursor: col-resize; z-index: 5;
}
.colh::after {
  content: ""; position: absolute; left: 3px; top: 6px; bottom: 6px;
  width: 1px; background: #d8e0ea;
}
.colh:hover::after { background: var(--brand); width: 2px; left: 2px; }
/* 最后一列的手柄不要超出容器，否则会触发横向滚动条 */
.tbl th:last-child .colh { right: 0; }
/* 最后一列的手柄不要超出容器，否则会触发横向滚动条 */
.tbl th:last-child .colh { right: 0; }

/* 首列固定、操作列固定 */
.tbl.sticky-1 th:first-child, .tbl.sticky-1 td:first-child {
  position: sticky; left: 0; background: var(--surface); z-index: 2;
}
.tbl.sticky-1 th:first-child { background: var(--surface-2); }
.tbl .ops {
  position: sticky; right: 0; background: var(--surface);
  box-shadow: -5px 0 7px -5px rgba(0, 0, 0, .16);
}
.tbl th.ops { background: var(--surface-2); }

/* 空状态（表格内） */
.tbl-empty { padding: var(--sp-10) var(--sp-4); text-align: center; color: var(--dim); font-size: var(--fs-sm); }
.tbl-empty .t { font-size: var(--fs-h3); color: var(--muted); margin-bottom: 6px; }

/* 分页 */
.pager { display: flex; justify-content: center; align-items: center; gap: var(--sp-2); margin-top: var(--sp-3); font-size: var(--fs-sm); color: var(--muted); }
.pager button {
  min-width: 36px; height: 32px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--ink-2);
}
.pager button:hover { border-color: var(--brand); color: var(--brand); }
.pager button.on { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 650; }
.pager button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------- 标签 / 徽标 ---------------- */
.tag {
  display: inline-block; font-size: var(--fs-xs); line-height: 1.6;
  padding: 1px 9px; border-radius: var(--r-pill);
  border: 1px solid var(--line); color: var(--muted); background: var(--surface-2);
  white-space: nowrap;
}
.tag.brand { border-color: #cfe2f8; color: var(--brand); background: var(--brand-tint); }
.tag.ok { border-color: var(--ok-line); color: var(--ok); background: var(--ok-bg); }
.tag.warn { border-color: var(--warn-line); color: var(--warn); background: var(--warn-bg); }
.tag.danger { border-color: var(--danger-line); color: var(--danger); background: var(--danger-bg); }
.tag.leaf { border-color: #d8e9bd; color: #4a7d18; background: var(--leaf-tint); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill);
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 650;
}

/* ---------------- 提示条 ---------------- */
.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: var(--r-md);
  font-size: var(--fs-sm); line-height: 1.75;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
}
.alert .ic { flex: none; font-weight: 700; }
.alert.info { border-color: #cfe2f8; background: var(--brand-tint); color: #15529e; }
.alert.ok { border-color: var(--ok-line); background: var(--ok-bg); color: #0b5c37; }
.alert.warn { border-color: var(--warn-line); background: var(--warn-bg); color: #8a5a12; }
.alert.danger { border-color: var(--danger-line); background: var(--danger-bg); color: #8c1d16; }

/* ---------------- 抽屉 ---------------- */
.drawer { position: fixed; inset: 0; z-index: var(--z-drawer); display: none; }
.drawer.on { display: block; }
.drawer .mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); }
.drawer .pane {
  position: absolute; right: 0; top: 0; bottom: 0; width: min(600px, 94vw);
  background: var(--surface); border-left: 1px solid var(--line);
  padding: var(--sp-5); overflow: auto; box-shadow: var(--sh-3);
}
.drawer h2 { font-size: var(--fs-h2); padding-right: 36px; margin-bottom: var(--sp-2); }
.drawer .close {
  position: absolute; right: var(--sp-4); top: var(--sp-4);
  width: 32px; height: 32px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  cursor: pointer; font-size: 16px;
}

/* ---------------- 弹窗 ---------------- */
.modal { position: fixed; inset: 0; z-index: var(--z-modal); display: none; align-items: center; justify-content: center; }
.modal.on { display: flex; }
.modal .mask { position: absolute; inset: 0; background: rgba(15, 23, 42, .42); }
.modal .box {
  position: relative; background: var(--surface); border-radius: var(--r-xl);
  padding: var(--sp-5); width: min(440px, 92vw); box-shadow: var(--sh-3);
}
.modal h3 { font-size: var(--fs-h2); margin-bottom: var(--sp-2); }
.modal .ft { display: flex; gap: var(--sp-2); justify-content: flex-end; margin-top: var(--sp-5); }

/* ---------------- Toast ---------------- */
.toast-wrap { position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: rgba(34, 38, 43, .94); color: #fff; font-size: var(--fs-sm);
  padding: 10px 18px; border-radius: var(--r-pill); box-shadow: var(--sh-2);
  animation: toast-in .22s ease;
}
.toast.ok { background: rgba(10, 122, 61, .95); }
.toast.err { background: rgba(179, 38, 30, .95); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------------- 空状态 / 加载 ---------------- */
.empty { padding: var(--sp-10) var(--sp-4); text-align: center; }
.empty .ic { font-size: 34px; color: #d5dde8; margin-bottom: var(--sp-2); }
.empty .t { font-size: var(--fs-h3); color: var(--ink-2); margin-bottom: 6px; }
.empty .d { font-size: var(--fs-sm); color: var(--dim); line-height: 1.8; }
.empty .act { margin-top: var(--sp-4); }

.skeleton {
  background: linear-gradient(90deg, #eef2f7 25%, #f7f9fc 37%, #eef2f7 63%);
  background-size: 400% 100%; animation: sk 1.4s ease infinite; border-radius: var(--r-sm);
}
@keyframes sk { from { background-position: 100% 50%; } to { background-position: 0 50%; } }

/* ---------------- 欢迎条 ---------------- */
.welcome {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  background: linear-gradient(96deg, #eaf4fd, #f7fbfe 58%, #fbfdf7);
  border: 1px solid #d6e6f6; border-radius: var(--r-lg);
  padding: var(--sp-4) var(--sp-5); margin: var(--sp-3) 0 var(--sp-5);
}
.welcome .hi { font-size: 16.5px; font-weight: 700; color: var(--brand-deep); }
.welcome .tx { color: #4a6584; font-size: var(--fs-table); }
.welcome .dt { margin-left: auto; color: #7c93ad; font-size: var(--fs-sm); }
.welcome img { height: 38px; margin-left: var(--sp-3); }

/* ---------------- 拖拽上传 ---------------- */
.drop {
  background: var(--surface); border: 1.5px dashed #cfdce9; border-radius: var(--r-lg);
  padding: var(--sp-4); cursor: pointer; transition: .15s; position: relative;
}
.drop:hover { border-color: var(--brand); background: var(--brand-tint-2); }
.drop.over { border-color: var(--brand); background: var(--brand-tint); }
.drop.ok { border-style: solid; border-color: var(--ok-line); background: var(--ok-bg); }
.drop .t { font-size: 14px; font-weight: 650; color: #123c6b; display: flex; align-items: center; gap: 7px; }
.drop .d { font-size: var(--fs-sm); color: var(--muted); margin-top: 6px; line-height: 1.7; }
.drop .f { font-size: var(--fs-sm); color: var(--ok); margin-top: 8px; word-break: break-all; }

/* ---------------- 进度条 ---------------- */
.bar { height: 8px; border-radius: var(--r-pill); background: var(--line-2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: var(--r-pill); background: linear-gradient(90deg, var(--brand), var(--brand-bright)); transition: width .3s; }

/* ---------------- 移动端 ---------------- */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .side {
    width: auto; flex: none; height: auto;
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    flex-direction: row; gap: 2px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
    box-shadow: 0 -2px 12px rgba(15, 23, 42, .06);
    z-index: var(--z-nav); overflow-x: auto;
  }
  .brand, .nav-sec, .nav-foot { display: none; }
  .nav-i { flex: 1; flex-direction: column; gap: 3px; padding: 6px 2px; font-size: 11px; text-align: center; border: 0; }
  .nav-i .cnt { position: absolute; margin: -2px 0 0 14px; }
  .main { padding: var(--sp-4) var(--sp-3) calc(80px + env(safe-area-inset-bottom)); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpi .value { font-size: 26px; }
  .topbar { padding: 0 var(--sp-4); }
  .topbar h1 { font-size: 19px; }
  .welcome { padding: var(--sp-3) var(--sp-4); }
  .welcome .dt { margin-left: 0; }
  .welcome img { display: none; }
  .drawer .pane { width: 100%; }
}
