/* ════════════════════════════════════════════════
   components.css — 通用组件 (按钮/表单/表格/卡片/标签/弹窗/Toast)
   ════════════════════════════════════════════════ */

/* ─── 页面头部 ─── */
.page-head {
  margin-bottom: 20px;
  display: flex; align-items: end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.page-head h2 { font-size: 22px; font-weight: 650; letter-spacing: -.4px; }
.page-head .desc { color: var(--fg2); font-size: 13px; margin-top: 2px; }

/* ─── 卡片 / Panel ─── */
.card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-xs);
}
.panel { margin-bottom: 14px; }
.panel-h {
  padding: 12px 16px;
  font-size: 13px; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.panel-h .h-r { display: flex; gap: 8px; align-items: center; }
.panel-b { padding: 16px; }
.panel-b.np { padding: 0; }

/* ─── 统计卡片 grid ─── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 15px 17px;
  position: relative; overflow: hidden;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), transform .18s var(--ease);
}
.stat:hover { border-color: var(--line2); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 2px; background: transparent;
  transition: background .18s;
}
.stat.red::before { background: var(--red); }
.stat.ok::before { background: var(--green); }
.stat.warn::before { background: var(--orange); }
.stat.info::before { background: var(--blue); }
.stat.red .val  { color: var(--red); }
.stat.ok  .val  { color: var(--green); }
.stat.muted .val { color: var(--fg3); }
.stat .lab {
  font-size: 11.5px; color: var(--fg3);
  font-weight: 500; letter-spacing: .3px;
}
.stat .val {
  font-size: 26px; font-weight: 700;
  letter-spacing: -.6px; margin-top: 5px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.stat .stat-ico {
  position: absolute; top: 13px; right: 13px;
  width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
}
.stat .stat-ico svg { width: 19px; height: 19px; }
.stat.red  .stat-ico { background: var(--red-soft);    color: var(--red); }
.stat.ok   .stat-ico { background: var(--green-soft);  color: var(--green); }
.stat.warn .stat-ico { background: var(--orange-soft); color: var(--orange); }
.stat.info .stat-ico { background: var(--blue-soft);   color: var(--blue); }
.stat.muted .stat-ico { background: var(--bg3);        color: var(--fg3); }

/* ─── 图表 ─── */
.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
@media (max-width: 900px) { .charts { grid-template-columns: 1fr; } }
.chart-h { height: 240px; }

/* ─── 表单 ─── */
.fr {
  display: flex; gap: 12px; flex-wrap: wrap;
  margin-bottom: 12px; align-items: flex-end;
}
.fg { flex: 1; min-width: 160px; }
.fg label {
  display: block;
  font-size: 12px; color: var(--fg2);
  font-weight: 600; letter-spacing: .2px;
  margin-bottom: 6px;
}

input[type=text], input[type=password], input[type=number], input[type=email], textarea, select {
  width: 100%; padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg); font-size: 13.5px;
  font-family: inherit;
  transition-property: border-color, box-shadow, background-color;
  transition-duration: 150ms;
  transition-timing-function: ease-out;
  box-shadow: inset 0 1px 2px rgba(20, 20, 30, .04);
}
input::placeholder, textarea::placeholder { color: var(--fg3); }
input:hover, textarea:hover, select:hover { border-color: var(--line2); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), inset 0 1px 2px rgba(20, 20, 30, .03);
  background: var(--bg2);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
select {
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238d8f99' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }
input[type=range] { accent-color: var(--accent); cursor: pointer; }

/* ─── 按钮 ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg); font-size: 13px; font-weight: 500;
  line-height: 1.2;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition-property: transform, background-color, border-color, color, box-shadow;
  transition-duration: 120ms;
  transition-timing-function: ease-out;
  min-height: 34px;
}
.btn:hover { border-color: var(--line2); background: var(--bg3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn:focus-visible { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
.btn.pri {
  background: var(--accent); color: #fff; border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(47, 111, 87, .18);
}
.btn.pri:hover { background: var(--accent2); border-color: var(--accent2); box-shadow: 0 2px 5px rgba(47, 111, 87, .25); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn.danger:hover { background: var(--red); color: #fff; border-color: var(--red); }
.btn.warn { color: var(--orange); border-color: var(--orange-soft); background: var(--orange-soft); }
.btn.warn:hover { background: var(--orange); color: #fff; border-color: var(--orange); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--fg2); padding: 6px 10px; }
.btn.ghost:hover { background: var(--bg3); color: var(--fg); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; min-height: 30px; }
.btn.xs { padding: 5px 9px; font-size: 12px; border-radius: var(--r-xs); min-height: 26px; }
.btn-row { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; }

/* ─── 开关 ─── */
.tog {
  display: inline-flex; align-items: center; gap: 8px;
  cursor: pointer; font-size: 13px; user-select: none;
  align-self: center;
}
.tog input { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }
.tog .sw {
  width: 38px; height: 22px;
  background: var(--bg4);
  border-radius: 11px;
  position: relative;
  transition: background .15s;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.tog .sw::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
  transition: transform .15s;
}
.tog input:checked + .sw {
  background: var(--accent);
  border-color: var(--accent);
}
.tog input:checked + .sw::after { transform: translateX(16px); }
.tog .lab-on, .tog .lab-off {
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
  min-width: 22px; text-align: center;
}
.tog .lab-on  { color: var(--accent); }
.tog .lab-off { color: var(--fg3); }
.tog input:checked ~ .lab-on  { display: inline; }
.tog input:checked ~ .lab-off { display: none; }
.tog:not(:has(input:checked)) .lab-on  { display: none; }
.tog:not(:has(input:checked)) .lab-off { display: inline; }

/* ─── 标签 ─── */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 9px; border-radius: 99px;
  font-size: 11px; font-weight: 600; letter-spacing: .2px;
  background: var(--bg3); color: var(--fg2);
}
.tag.ok    { background: var(--green-soft);  color: var(--green); }
.tag.no    { background: var(--red-soft);    color: var(--red); }
.tag.warn  { background: var(--orange-soft); color: var(--orange); }
.tag.info  { background: var(--blue-soft);   color: var(--blue); }
.tag.muted { background: var(--bg3);         color: var(--fg3); }

/* ─── 表格 ─── */
.tw {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
}
@media (max-width: 768px) {
  .tw::after {
    content: '';
    position: absolute; top: 0; right: 0; bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--bg2));
    pointer-events: none;
    opacity: .8;
  }
}
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th {
  background: var(--bg);
  text-align: left;
  padding: 10px 14px; font-weight: 600;
  color: var(--fg3);
  font-size: 11px; letter-spacing: .5px;
  border-bottom: 1px solid var(--line2);
  white-space: nowrap;
}
.tbl td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
}
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .12s; }
.tbl tbody tr:hover { background: var(--row-hover); }
.tbl td.wrap { white-space: normal; max-width: 320px; word-break: break-word; }
.tbl .num { font-variant-numeric: tabular-nums; color: var(--fg2); }

/* ─── 状态占位 ─── */
.empty-state { padding: 36px 16px; text-align: center; color: var(--fg3); font-size: 13px; }
.empty-state .ico {
  display: flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; margin: 0 auto 10px;
  border-radius: 12px; background: var(--bg3); color: var(--fg3);
}
.empty-state .ico svg { width: 22px; height: 22px; opacity: .8; }
.err-state   { padding: 24px 16px; text-align: center; color: var(--red); font-size: 13px; }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--line2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
}

/* ─── Toast ─── */
.toasts {
  position: fixed; top: 18px; right: 18px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 11px 14px;
  font-size: 13px;
  min-width: 200px; max-width: 380px;
  box-shadow: 0 8px 24px rgba(20, 20, 30, .1), 0 2px 6px rgba(20, 20, 30, .05);
  animation: toast-in .25s var(--ease);
  pointer-events: auto;
}
.toast.ok   { border-left: 3px solid var(--green); }
.toast.err  { border-left: 3px solid var(--red); }
.toast.warn { border-left: 3px solid var(--orange); }

/* ─── 弹窗 ─── */
.modal-bg {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(20, 20, 30, .4);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  align-items: center; justify-content: center;
  padding: 16px;
}
.modal-bg.show { display: flex; animation: fade .15s; }
.modal {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 24px;
  width: 460px; max-width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .15);
  animation: fade .2s ease;
}
.modal h3 { font-size: 17px; font-weight: 600; margin-bottom: 16px; letter-spacing: -.2px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ─── 进度条 / 数值对 ─── */
.bar { height: 5px; background: var(--bg3); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: var(--accent); border-radius: 3px; transition: width .35s ease; }
.bar > div.red   { background: var(--red); }
.bar > div.warn  { background: var(--orange); }
.bar > div.blue  { background: var(--blue); }
.bar > div.green { background: var(--green); }

.kv { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 12.5px; }
.kv .k { color: var(--fg2); }
.kv .v { font-variant-numeric: tabular-nums; font-weight: 500; }

.dot3 { display: inline-flex; gap: 4px; align-items: center; font-size: 11.5px; color: var(--fg3); margin-left: 6px; }

/* ─── 搜索框 ─── */
.search-box { position: relative; max-width: 260px; flex: 1; }
.search-box input { padding-left: 32px; }
.search-box::before {
  content: '';
  position: absolute; left: 11px; top: 50%;
  transform: translateY(-50%);
  width: 14px; height: 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238d8f99' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.2-3.2'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  pointer-events: none;
}
.search-box:focus-within::before { opacity: .7; }

/* ─── 代码块 ─── */
pre.code {
  margin: 0; padding: 14px 16px;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  font-family: var(--mono);
  font-size: 11.5px; line-height: 1.7;
  color: var(--fg);
  white-space: pre-wrap; word-break: break-word;
  max-height: 50vh; overflow-y: auto;
}