/* ============================================================
   后台管理面板 · 共享样式
   主应用「设置 → 🛠 后台管理」与独立控制台 /admin 共用同一份布局。
   所有类名以 ap- 前缀，面板不依赖宿主页面的任何样式，也不会污染宿主。
   ============================================================ */

.ap,
.ap-modal {
  --ap-primary: #ff7eb3;
  --ap-primary-dark: #e85d97;
  --ap-primary-soft: #ffeef5;
  --ap-text: #23232b;
  --ap-muted: #8b8b98;
  --ap-border: #ececf2;
  --ap-card: #ffffff;
  --ap-danger: #d9484c;
  --ap-ok: #1a7f4b;
  --ap-warn: #8a5a00;
  --ap-shadow: 0 1px 3px rgba(20, 20, 40, .06), 0 6px 18px rgba(20, 20, 40, .04);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  color: var(--ap-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.ap *,
.ap-modal * { box-sizing: border-box; }
.ap [hidden],
.ap-modal[hidden],
.ap-pane[hidden] { display: none !important; }

/* ---------- 顶部标题与操作 ---------- */
.ap-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin: 0 2px 10px; }
.ap-title { font-size: 17px; font-weight: 700; }
.ap-sub { color: var(--ap-muted); font-size: 12.5px; margin-top: 2px; }
.ap-head-actions { display: flex; gap: 6px; flex: 0 0 auto; padding-top: 2px; }

.ap-btn {
  border: 1px solid var(--ap-border); background: var(--ap-card); color: var(--ap-text);
  border-radius: 10px; padding: 7px 12px; font-size: 13px; cursor: pointer;
  font-family: inherit; transition: background .15s, border-color .15s;
}
.ap-btn:hover { border-color: #e3d9e2; }
.ap-btn.primary { background: var(--ap-primary); border-color: var(--ap-primary); color: #fff; font-weight: 600; }
.ap-btn.primary:hover { background: var(--ap-primary-dark); border-color: var(--ap-primary-dark); }
.ap-btn.danger { color: var(--ap-danger); border-color: #f3c9cb; }
.ap-btn.block { display: block; width: 100%; padding: 11px; margin-top: 4px; }
.ap-btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- 概览数字 ---------- */
.ap-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(86px, 1fr)); gap: 8px; margin: 0 0 10px; }
.ap-stat { background: var(--ap-card); border-radius: 12px; padding: 9px 6px; text-align: center; box-shadow: var(--ap-shadow); }
.ap-stat b { display: block; font-size: 19px; line-height: 1.25; }
.ap-stat span { font-size: 12px; color: var(--ap-muted); }

/* ---------- 页签 ---------- */
.ap-tabs { display: flex; gap: 6px; margin: 0 0 10px; }
.ap-tab {
  flex: 1; padding: 9px 4px; border-radius: 10px; border: 1px solid var(--ap-border);
  background: var(--ap-card); color: var(--ap-text); font-size: 14px; cursor: pointer; font-family: inherit;
}
.ap-tab.active { background: var(--ap-primary); border-color: transparent; color: #fff; font-weight: 600; }

/* ---------- 说明文字 ---------- */
.ap-note { color: var(--ap-muted); font-size: 12.5px; line-height: 1.6; margin: 0 4px 8px; }
.ap-note b { color: var(--ap-text); }

/* ---------- 卡片与表单 ---------- */
.ap-card {
  background: var(--ap-card); border-radius: 16px; box-shadow: var(--ap-shadow);
  padding: 14px 14px 16px; margin-bottom: 12px;
}
.ap-card-title { font-size: 15px; font-weight: 700; }
.ap-card-sub { color: var(--ap-muted); font-size: 12.5px; line-height: 1.6; margin: 5px 0 2px; }

.ap-switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--ap-border);
}
.ap-switch-row:first-of-type { border-top: none; padding-top: 2px; }
.ap-switch-text { min-width: 0; }
.ap-switch-label { font-weight: 600; font-size: 14.5px; }
.ap-switch-desc { color: var(--ap-muted); font-size: 12.5px; line-height: 1.55; margin-top: 2px; }
.ap-switch { position: relative; display: inline-block; width: 46px; height: 26px; flex: 0 0 auto; }
.ap-switch input { opacity: 0; width: 0; height: 0; }
.ap-slider { position: absolute; inset: 0; cursor: pointer; background: #d7d7e0; border-radius: 999px; transition: background .2s; }
.ap-slider::before {
  content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px;
  background: #fff; border-radius: 50%; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.ap-switch input:checked + .ap-slider { background: var(--ap-primary); }
.ap-switch input:checked + .ap-slider::before { transform: translateX(20px); }

.ap-field { display: flex; flex-direction: column; gap: 5px; margin-top: 10px; }
.ap-field > span { font-size: 12.5px; color: var(--ap-muted); }
.ap-field input,
.ap-field select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--ap-border); border-radius: 10px;
  font-size: 14px; font-family: inherit; color: var(--ap-text); background: #fff; outline: none;
}
.ap-field input:focus,
.ap-field select:focus { border-color: var(--ap-primary); }
.ap-field-hint { font-size: 12px; color: var(--ap-muted); font-style: normal; line-height: 1.5; }
.ap-check-row { display: flex; align-items: flex-start; gap: 8px; font-size: 12.5px; color: var(--ap-muted); margin-top: 10px; line-height: 1.5; }
.ap-check-row input { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.ap-status { font-size: 12.5px; line-height: 1.55; margin: 10px 0 0; color: var(--ap-muted); }
.ap-status.ok { color: var(--ap-ok); }
.ap-status.err { color: var(--ap-danger); }
.ap-actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; align-items: center; }

.ap-risk { font-size: 12.5px; line-height: 1.65; border-radius: 9px; padding: 9px 11px; margin: 12px 0 0; }
.ap-risk.warn { color: var(--ap-warn); background: #fff4dc; border: 1px solid #ffd98a; }
.ap-risk.info { color: #3a6ea5; background: #eef5fc; border: 1px solid #cfe1f5; }

/* ---------- 列表（账号 / 日志） ---------- */
.ap-rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.ap-row {
  background: var(--ap-card); border-radius: 14px; box-shadow: var(--ap-shadow);
  padding: 12px 13px; display: flex; flex-wrap: wrap; gap: 4px 10px;
}
.ap-row-main { flex: 1 1 auto; min-width: 0; }
.ap-row-top { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.ap-name { font-weight: 600; font-size: 14.5px; }
.ap-name small { color: var(--ap-muted); font-weight: 400; font-size: 12.5px; }
.ap-meta { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: 12px; color: var(--ap-muted); margin-top: 5px; }
.ap-meta b { color: var(--ap-text); font-weight: 600; }
.ap-row-actions { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-top: 8px; }
.ap-row-actions button {
  font-size: 12px; padding: 5px 10px; border-radius: 9px; border: 1px solid var(--ap-border);
  background: #fff; color: var(--ap-text); cursor: pointer; font-family: inherit;
}
.ap-row-actions button:hover { border-color: #e3d9e2; }
.ap-row-actions button.danger { color: var(--ap-danger); border-color: #f3c9cb; }
.ap-self { color: var(--ap-muted); font-size: 12px; padding-top: 4px; text-align: right; flex: 1 1 100%; }
.ap-empty { text-align: center; color: var(--ap-muted); padding: 22px 0; font-size: 13.5px; }

.ap-badge {
  display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px;
  background: #eef0f4; color: #6f6f7c;
}
.ap-badge.admin { background: var(--ap-primary-soft); color: var(--ap-primary-dark); }
.ap-badge.online { background: #e6f7ee; color: var(--ap-ok); }
.ap-badge.offline { background: #f0f0f2; color: #90909c; }
.ap-badge.disabled { background: #eee; color: #b0b0b8; text-decoration: line-through; }
.ap-badge.pending { background: #fff3d6; color: #b7791f; }
.ap-badge.types { background: #eef2ff; color: #4a5bd1; }

/* ---------- 日志筛选 ---------- */
.ap-filter { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.ap-filter button {
  padding: 5px 13px; border-radius: 999px; border: 1px solid var(--ap-border);
  background: var(--ap-card); color: var(--ap-text); font-size: 13px; cursor: pointer; font-family: inherit;
}
.ap-filter button.active { background: var(--ap-primary); border-color: transparent; color: #fff; }
.ap-log-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.ap-log-foot .ap-note { margin: 0 0 0 2px; flex: 1 1 160px; }

/* ---------- 用户编辑弹窗：手机端贴底、桌面端居中 ---------- */
.ap-modal {
  position: fixed; inset: 0; background: rgba(30, 30, 40, .45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 80;
}
.ap-modal-card {
  width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
  background: var(--ap-card); border-radius: 20px 20px 0 0;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom, 0px));
}
.ap-modal-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.ap-modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.ap-modal-actions .ap-btn { flex: 1; padding: 11px; }

/* 面板自带兜底 toast（宿主没提供 toast 时用） */
.ap-toast {
  position: fixed; left: 50%; bottom: 36px; transform: translateX(-50%); z-index: 90;
  max-width: min(86vw, 360px); padding: 12px 16px; border-radius: 14px;
  background: rgba(38, 38, 48, .95); color: #fff; font-size: 14px; line-height: 1.55;
  text-align: center; box-shadow: 0 10px 28px rgba(20, 20, 40, .3);
}

/* ---------- 宽屏（独立控制台常见）：操作按钮挪到卡片右侧 ---------- */
@media (min-width: 560px) {
  .ap-modal { align-items: center; }
  .ap-modal-card { border-radius: 20px; margin-bottom: 20px; }
}
@media (min-width: 760px) {
  .ap-row { padding: 14px 16px; align-items: flex-start; }
  .ap-row-actions { flex: 0 0 auto; margin-top: 0; }
  .ap-head { margin-bottom: 14px; }
}
