/* ============================================================
   components.css · 通用组件
   ============================================================ */

/* ---------- 卡片 ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
}
.card-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-2);
  display: flex; align-items: center; gap: 10px;
}
.card-head h4 { font-size: 13.5px; font-weight: 600; }
.card-head .extra { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.card-body { padding: 16px; }
.card-body.tight { padding: 10px 12px; }
.card-foot {
  padding: 10px 16px;
  border-top: 1px solid var(--border-2);
  display: flex; align-items: center; gap: 10px;
}

/* 统计卡 */
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-1);
}
.stat .label {
  font-size: 12px; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.stat .value {
  font-size: 24px; font-weight: 650;
  line-height: 1.3; margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat .sub .delta { font-weight: 600; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 14px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--panel-2); border-color: #d3dae3; }
.btn:active { background: #f0f2f5; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }

.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }

.btn-text {
  border-color: transparent; background: transparent; color: var(--brand);
  padding: 0 8px; height: 28px;
}
.btn-text:hover { background: var(--brand-soft); }
.btn-text.danger { color: var(--danger); }
.btn-text.danger:hover { background: var(--danger-soft); }

.btn-sm { height: 26px; padding: 0 10px; font-size: 12.5px; }

/* ---------- 表单 ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field .flabel { font-size: 12.5px; color: var(--text-2); }
.field .fhint  { font-size: 11.5px; color: var(--muted); }

.input, .select, textarea.input {
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 13px; font-family: inherit;
  outline: none;
  width: 100%;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 68px; line-height: 1.6; }
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.input::placeholder { color: #b3bcc9; }
.select { cursor: pointer; }

.filter-bar {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end;
  padding: 12px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.filter-bar .f { min-width: 150px; flex: 1 1 150px; }
.filter-bar .f.wide { min-width: 220px; flex: 1 1 220px; }
.filter-bar .f.narrow { min-width: 110px; flex: 1 1 110px; }
.filter-bar .spacer { flex: 1; }
.filter-bar .btn { flex: 0 0 auto; align-self: flex-end; }

/* ---------- 表格 ---------- */
.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-scroll { overflow-x: auto; }

table.tbl {
  /* 自适应：列宽由内容决定；容器不够宽时走 .table-scroll 横向滚动，
     绝不把单元格压窄成「文字竖排」 */
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 13px;
}
table.tbl th {
  text-align: left;
  padding: 10px 14px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  color: var(--text-2);
  font-size: 12.5px;
  white-space: nowrap;
}
table.tbl td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-2);
  vertical-align: middle;
  /* 关键：默认不换行，避免中文被挤成竖排；超长内容省略号 */
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.tbl td.wrap { white-space: normal; max-width: none; overflow: visible; text-overflow: clip; }
table.tbl td.tags { white-space: normal; max-width: 190px; }
table.tbl td.ops { white-space: nowrap; max-width: none; overflow: visible; }
table.tbl td.ops .btn-text { margin-right: 2px; }
table.tbl tbody tr:hover { background: #fbfcfe; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .cell-sub { font-size: 11.5px; color: var(--muted); }

/* 表头：主标题排序 + 次要指标小号排序入口 */
table.tbl th .th-sort { cursor: pointer; user-select: none; }
table.tbl th .th-sub {
  margin-top: 2px; font-weight: 400; font-size: 11px; color: var(--muted);
}
table.tbl th .sort-mini {
  cursor: pointer; user-select: none; color: var(--muted); font-size: 11px;
}
table.tbl th .sort-mini:hover { color: var(--text-2); }
table.tbl th .sort-mini.on { color: var(--brand); font-weight: 600; }
table.tbl td.ops-col { white-space: nowrap; }
table.tbl .c-name { display: flex; align-items: center; gap: 6px; }

.table-foot {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border-top: 1px solid var(--border-2);
  font-size: 12.5px; color: var(--muted);
}
.table-foot .spacer { flex: 1; }

/* 分页 */
.pager { display: flex; align-items: center; gap: 4px; }
.pager .pg {
  min-width: 28px; height: 28px; padding: 0 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--radius-sm);
  font-size: 12.5px; cursor: pointer; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
}
.pager .pg:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.pager .pg.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.pager .pg:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- 徽章 / 标签 ---------- */
.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 20px;
  font-size: 11.5px;
  line-height: 19px;
  white-space: nowrap;
}
.badge-gray   { background: #f1f3f6; color: #5b6673; }
.badge-blue   { background: var(--brand-soft); color: var(--brand-dark); }
.badge-green  { background: var(--down-soft); color: #087443; }
.badge-red    { background: var(--danger-soft); color: var(--danger); }
.badge-orange { background: var(--warn-soft); color: var(--warn); }
.badge-purple { background: #f3edff; color: var(--purple); }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 11.5px;
  background: #f1f3f6;
  color: var(--text-2);
  margin: 1px 3px 1px 0;
}
.tag.removable { padding-right: 4px; }
.tag .x { cursor: pointer; color: var(--muted); margin-left: 4px; }
.tag .x:hover { color: var(--danger); }

.dot-status {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  margin-right: 6px; vertical-align: 1px;
}
.dot-status.on    { background: #10b981; }
.dot-status.off   { background: #9aa3af; }
.dot-status.warn  { background: var(--warn); }
.dot-status.danger{ background: var(--danger); }

/* ---------- 进度条 ---------- */
.progress {
  height: 6px; border-radius: 4px;
  background: #eef1f5; overflow: hidden;
}
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.progress.warn   > i { background: var(--warn); }
.progress.danger > i { background: var(--danger); }
.progress.ok     > i { background: #10b981; }

/* ---------- 提示条 ---------- */
.alert {
  display: flex; gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 12.5px;
  line-height: 1.6;
}
.alert .ico { flex: 0 0 auto; }
.alert-info    { background: var(--info-soft); border-color: #bfe3f5; color: #075985; }
.alert-warn    { background: var(--warn-soft); border-color: #f6ddb4; color: #92400e; }
.alert-danger  { background: var(--danger-soft); border-color: #f8c9c9; color: #991b1b; }
.alert-ok      { background: var(--down-soft); border-color: #bfe8d3; color: #065f46; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.42);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fade-in .15s ease-out;
  padding: 20px;
}
.modal {
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow-3);
  width: 520px;
  max-width: 100%;
  max-height: 88vh;
  display: flex; flex-direction: column;
}
.modal.wide { width: 760px; }
.modal-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-2);
  display: flex; align-items: center;
}
.modal-head h4 { font-size: 15px; }
.modal-head .close {
  margin-left: auto; cursor: pointer; color: var(--muted);
  font-size: 18px; line-height: 1; padding: 2px 6px; border-radius: 4px;
}
.modal-head .close:hover { background: var(--panel-2); color: var(--text); }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--border-2);
  display: flex; justify-content: flex-end; gap: 8px;
}
.modal-body .field { margin-bottom: 14px; }
.modal-body .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: #1f2937; color: #fff;
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13px;
  box-shadow: var(--shadow-2);
  animation: fade-in .18s ease-out;
  display: flex; align-items: center; gap: 8px;
  max-width: 80vw;
}
.toast.ok     { background: #0f9d58; }
.toast.err    { background: var(--danger); }
.toast.warn   { background: var(--warn); }

/* ---------- 空状态 / 加载 ---------- */
.empty {
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
}
.empty .ico { font-size: 30px; opacity: .5; }
.empty .txt { margin-top: 8px; font-size: 13px; }

.loading {
  padding: 44px 20px; text-align: center; color: var(--muted); font-size: 13px;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.tabs .tab {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { color: var(--brand-dark); font-weight: 600; border-bottom-color: var(--brand); }

/* ---------- 语义容器（v1.7.1 · 从 JS 内联样式回收） ---------- */
.scroll-box  { max-height: 340px; overflow: auto; }        /* 长列表限高滚动 */
.code-area   { height: 320px; font-size: 12px; }           /* 源码 / 长文本区 */
.empty-drop  {                                             /* 拖拽空态占位 */
  border: 1px dashed #cfd7e2; border-radius: 8px;
  padding: 22px; text-align: center; color: #8a94a6;
}
.pre-wrap    { white-space: pre-wrap; word-break: break-all; }
.block-pad-y { display: block; padding: 4px 0; }
.grow-min    { flex: 1; min-width: 80px; }                 /* 进度条等可伸缩容器 */
.bare        { border: none; background: none; }           /* 去边框底色（分页省略号等） */

/* ---------- 键值对列表 ---------- */
.kv { display: grid; grid-template-columns: 132px 1fr; gap: 8px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- 时间线 ---------- */
.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: ""; position: absolute; left: 5px; top: 4px; bottom: 4px;
  width: 1px; background: var(--border);
}
.timeline .item { position: relative; padding-bottom: 14px; }
.timeline .item::before {
  content: ""; position: absolute; left: -17px; top: 6px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--panel); border: 2px solid var(--brand);
}
.timeline .item .t { font-size: 11.5px; color: var(--muted); }
.timeline .item .c { font-size: 13px; }
