/* =========================================================
   components.css — 通用 UI 组件
   卡片 / 表格 / 按钮 / 徽章 / 工具栏 / 表单 / 弹窗 / 分页 / 图表 / 热词
   ========================================================= */

/* ── 统计卡片 ───────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--g);
}
.stat-card.warn { border-left-color: var(--warn); }
.stat-card.blue { border-left-color: #4a6cf7; }
.stat-label { font-size: 13px; color: var(--sub); margin-bottom: 10px; }
.stat-val   { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ── 通用卡片 ───────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; }

/* ── 表格 ───────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
table     { width: 100%; border-collapse: collapse; }
th, td    { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th        { background: #fafafa; font-weight: 600; color: var(--sub); font-size: 12px; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td      { background: #fafcff; }

/* ── 徽章 ───────────────────────────────── */
.badge       { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-on    { background: #e8f8ef; color: var(--g); }
.badge-off   { background: #f5f5f5; color: var(--muted); }
.badge-exact { background: #e8f0ff; color: #4a6cf7; }
.badge-fuzzy { background: #fff7e0; color: #d4810a; }
.badge-regex { background: #fce8f3; color: #c0387a; }

/* ── 按钮 ───────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 8px 16px;
  border-radius: 7px; border: none;
  cursor: pointer;
  font-size: 13px; font-weight: 500;
  transition: .15s;
  white-space: nowrap;
}
.btn:disabled           { opacity: .5; cursor: not-allowed; }
.btn-primary            { background: var(--g); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--gd); }
.btn-ghost              { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled)   { background: var(--bg); }
.btn-danger             { background: #fff0f0; color: var(--danger); border: 1px solid #ffd5d5; }
.btn-danger:hover:not(:disabled)  { background: #ffe0e0; }
.btn-sm                 { padding: 5px 10px; font-size: 12px; }
.btn-link               { background: none; border: none; color: var(--g); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.btn-link.danger        { color: var(--danger); }
.btn-link:hover         { text-decoration: underline; }
/* 截断省略 */
.clip    { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clip-lg { max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 工具栏 ─────────────────────────────── */
.toolbar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-wrap {
  flex: 1; min-width: 180px; max-width: 320px;
  position: relative;
}
.search-wrap input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px; outline: none;
  background: var(--card);
  transition: .15s;
}
.search-wrap input:focus  { border-color: var(--g); }
.search-wrap::before {
  content: "🔍";
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 13px; pointer-events: none;
}
.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--card);
  font-size: 13px; outline: none; cursor: pointer;
}
.filter-select:focus { border-color: var(--g); }

/* ── 表单 ───────────────────────────────── */
.form-row { margin-bottom: 16px; }
.form-row label {
  display: block;
  font-size: 13px; font-weight: 500;
  color: var(--sub); margin-bottom: 6px;
}
.form-row label .req { color: var(--danger); }
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px; outline: none;
  transition: .15s;
  font-family: inherit;
  background: #fff;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  border-color: var(--g);
  box-shadow: 0 0 0 3px rgba(7,193,96,.1);
}
.form-row textarea { resize: vertical; min-height: 100px; line-height: 1.6; }
.form-hint   { font-size: 12px; color: var(--muted); margin-top: 5px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ── 模态框 ─────────────────────────────── */
.modal-mask {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.48);
  z-index: 500;
  align-items: center; justify-content: center;
}
.modal-mask.show { display: flex; }
.modal {
  background: var(--card);
  border-radius: 14px;
  width: 560px; max-width: 94vw; max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.22);
  animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: scale(1); } }
.modal-head {
  padding: 20px 24px 0;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; background: var(--card); z-index: 1;
}
.modal-head h3  { font-size: 16px; font-weight: 600; }
.modal-close    { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; padding: 4px; }
.modal-close:hover { color: var(--text); }
.modal-body     { padding: 20px 24px; }
.modal-foot     { padding: 0 24px 20px; display: flex; gap: 10px; justify-content: flex-end; position: sticky; bottom: 0; background: var(--card); }

/* ── 分页 ───────────────────────────────── */
.pagination {
  display: flex; align-items: center; gap: 6px;
  padding: 14px 0 2px;
  justify-content: flex-end;
}
.pg-info { font-size: 13px; color: var(--sub); margin-right: auto; }
.pg-btn  {
  padding: 6px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  cursor: pointer; font-size: 13px; transition: .12s;
}
.pg-btn:hover:not(:disabled) { background: var(--bg); }
.pg-btn.cur     { background: var(--g); color: #fff; border-color: var(--g); }
.pg-btn:disabled{ opacity: .35; cursor: not-allowed; }

/* ── 图表（柱状图）────────────────────────── */
.bar-chart  { display: flex; align-items: flex-end; gap: 4px; height: 140px; }
.bar-col    { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar        { width: 100%; background: var(--g); border-radius: 4px 4px 0 0; opacity: .75; transition: .3s; cursor: default; min-height: 3px; }
.bar:hover  { opacity: 1; }
.bar-label  { font-size: 11px; color: var(--muted); white-space: nowrap; }
.bar-val    { font-size: 11px; color: var(--sub); }

/* ── 热词排行 ───────────────────────────── */
.kw-item          { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.kw-item:last-child{ border-bottom: none; }
.kw-rank          { width: 22px; height: 22px; border-radius: 50%; background: var(--bg); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: var(--muted); flex-shrink: 0; }
.kw-rank.top      { background: var(--g); color: #fff; }
.kw-name          { flex: 1; font-weight: 500; }
.kw-bar-wrap      { width: 80px; height: 5px; background: var(--border); border-radius: 3px; }
.kw-bar-fill      { height: 100%; background: var(--g); border-radius: 3px; }
.kw-count         { font-size: 13px; color: var(--sub); width: 32px; text-align: right; }

/* ── 内容发布 ───────────────────────────── */
.draft-item       { padding: 12px 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.draft-item:last-child { border-bottom: none; }
.draft-info       { flex: 1; min-width: 0; }
.draft-title      { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.draft-mid        { font-size: 12px; color: var(--muted); margin-top: 3px; font-family: monospace; }

/* ── 响应式补丁 ─────────────────────────── */
@media (max-width: 900px) {
  .stat-grid   { grid-template-columns: repeat(2, 1fr); }
  .form-grid-2 { grid-template-columns: 1fr; }
}

/* ── 系统配置页 ─────────────────────────── */
.cfg-card          { margin-bottom: 20px; }
.cfg-group-head    { font-size: 15px; font-weight: 600; color: var(--text); padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.cfg-table         { width: 100%; border-collapse: collapse; }
.cfg-table tr      { border-bottom: 1px solid var(--border); }
.cfg-table tr:last-child { border-bottom: none; }
.cfg-label         { width: 240px; padding: 14px 0; vertical-align: top; }
.cfg-key           { font-size: 13px; color: var(--text); font-weight: 500; }
.cfg-keyname       { font-size: 11px; color: var(--muted); margin-top: 3px; }
.cfg-val           { padding: 12px 0 12px 16px; }
.cfg-input         { width: 100%; max-width: 400px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--bg); color: var(--text); }
.cfg-input:focus   { outline: none; border-color: var(--g); }
.cfg-textarea      { width: 100%; max-width: 400px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; background: var(--bg); color: var(--text); resize: vertical; }
.cfg-textarea:focus{ outline: none; border-color: var(--g); }
.cfg-footer        { padding-top: 14px; border-top: 1px solid var(--border); margin-top: 4px; }

/* Toggle 开关 */
.switch            { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input      { opacity: 0; width: 0; height: 0; }
.slider            { position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 24px; transition: .3s; }
.slider:before     { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: .3s; }
input:checked + .slider            { background: var(--g); }
input:checked + .slider:before     { transform: translateX(20px); }
