/* 管理后台样式（基于 style.css 的深色主题扩展） */

/* ---------------- 布局 ---------------- */
.admin-layout {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: 22px;
  max-width: 1520px;
  margin: 0 auto;
  padding: 20px 20px 60px;
  align-items: start;
}

.admin-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: calc(var(--bar-h) + 16px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 10px;
}
.admin-nav .nav-title {
  font-size: 11px;
  letter-spacing: .1em;
  color: var(--dim);
  padding: 6px 10px 8px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-2);
  padding: 9px 11px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  width: 100%;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); border-color: transparent; }
.nav-item.active { background: var(--surface-2); border-color: var(--line-2); color: var(--text); }
.nav-item svg { width: 16px; height: 16px; fill: currentColor; opacity: .85; flex: none; }
.admin-nav .nav-foot {
  margin-top: 8px;
  padding: 10px 10px 2px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--dim);
  line-height: 1.6;
}

.admin-main { min-width: 0; }

.page-head {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h2 { margin: 0; font-size: 20px; font-weight: 680; letter-spacing: -.2px; }
.page-head .sub { color: var(--dim); font-size: 12.5px; margin-top: 2px; }
.page-head .spacer { flex: 1; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* 移动端抽屉开关 */
.admin-menu-btn { display: none; }
.drawer-mask { display: none; }

/* ---------------- 面板 ---------------- */
.panel {
  margin-bottom: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.panel-head h3 { margin: 0; font-size: 14px; font-weight: 620; }
.panel-head .sub { color: var(--dim); font-size: 12px; }
.panel-head .spacer { flex: 1; }
.panel-note { margin: 10px 0 0; color: var(--dim); font-size: 12px; line-height: 1.7; }

/* ---------------- 统计卡 ---------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 13px 15px;
}
.stat-card .label { font-size: 12px; color: var(--dim); }
.stat-card .value {
  font-size: 23px; font-weight: 680; margin-top: 3px;
  font-variant-numeric: tabular-nums;
}

/* ---------------- 表格 ---------------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
  text-align: left;
  padding: 10px 13px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table thead th {
  background: var(--bg-2);
  color: var(--dim);
  font-weight: 500;
  font-size: 12px;
}
.data-table tbody tr:hover { background: rgba(255, 255, 255, .025); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td.title-cell { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.data-table .actions { display: flex; gap: 6px; }
.data-table button { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.data-table .empty-row td { text-align: center; color: var(--dim); padding: 26px 0; }

/* ---------------- 徽章 ---------------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.badge.role-super_admin { background: rgba(245, 69, 92, .14); border-color: rgba(245, 69, 92, .4); color: #ffb3bb; }
.badge.role-admin { background: rgba(240, 180, 41, .13); border-color: rgba(240, 180, 41, .38); color: #f5d79a; }
.badge.role-user { background: rgba(150, 160, 175, .12); color: var(--text-2); }
.badge.ok { background: rgba(55, 211, 153, .12); border-color: rgba(55, 211, 153, .36); color: #a4e8cd; }
.badge.off { background: rgba(245, 69, 92, .12); border-color: rgba(245, 69, 92, .34); color: #ffb3bb; }
.badge.warn { background: rgba(240, 180, 41, .12); border-color: rgba(240, 180, 41, .34); color: #f5d79a; }
.badge.info { background: rgba(120, 150, 220, .13); border-color: rgba(120, 150, 220, .34); color: #b9c9f0; }

/* ---------------- 弹窗 ---------------- */
.dlg-root { position: fixed; inset: 0; z-index: 120; }
.dlg-root[hidden] { display: none; }
.dlg-mask {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .62);
  opacity: 0;
  transition: opacity .18s;
}
.dlg-root.show .dlg-mask { opacity: 1; }
.dlg-box {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -46%);
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 10px;
  padding: 18px 20px 16px;
  box-shadow: 0 20px 56px rgba(0, 0, 0, .55);
  opacity: 0;
  transition: opacity .18s, transform .18s;
}
.dlg-root.show .dlg-box { opacity: 1; transform: translate(-50%, -50%); }
.dlg-title { margin: 0 0 4px; font-size: 15px; font-weight: 620; }
.dlg-desc { margin: 0 0 13px; color: var(--dim); font-size: 12.5px; line-height: 1.65; }
.dlg-body { display: flex; flex-direction: column; gap: 12px; }
.dlg-field { display: flex; flex-direction: column; gap: 6px; }
.dlg-label { font-size: 12px; color: var(--dim); }
.dlg-field input, .dlg-field select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
}
.dlg-field input:focus, .dlg-field select:focus {
  outline: none;
  border-color: var(--brand);
}
.dlg-quick-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -4px; }
.dlg-quick {
  padding: 4px 11px;
  font-size: 12px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
}
.dlg-quick:hover { color: var(--text); border-color: var(--line-2); }
.dlg-error {
  margin: 13px 0 0;
  padding: 9px 11px;
  border-radius: 7px;
  font-size: 12.5px;
  line-height: 1.65;
  background: rgba(245, 69, 92, .12);
  border: 1px solid rgba(245, 69, 92, .34);
  color: #ffb3bb;
}
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-btn {
  padding: 7px 16px;
  border-radius: 7px;
  font-size: 13px;
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  font-family: inherit;
}
.dlg-btn:hover { color: var(--text); background: var(--surface-2); }
.dlg-btn:disabled { opacity: .55; cursor: not-allowed; }
.dlg-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.dlg-primary:hover { color: #fff; filter: brightness(1.08); background: var(--brand); }
.dlg-danger { background: var(--brand); border-color: var(--brand); color: #fff; }
body.dlg-open { overflow: hidden; }

/* 权限说明条 */
.perm-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 10px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-2);
  color: var(--dim);
  font-size: 12.5px;
  line-height: 1.7;
  margin-bottom: 14px;
}
.perm-note b { color: var(--text-2); font-weight: 600; }
.perm-note svg { width: 15px; height: 15px; fill: currentColor; flex: none; margin-top: 2px; opacity: .8; }

/* 不可操作的按钮 */
.data-table button[disabled] {
  opacity: .4;
  cursor: not-allowed;
  filter: grayscale(1);
}

/* ---------------- 表单 ---------------- */

.upload-box {
  border: 1px dashed var(--line-2);
  border-radius: var(--radius);
  padding: 16px;
}
.upload-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.upload-row input[type="text"] { flex: 1; min-width: 180px; }
.upload-row input[type="file"] {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 6px 9px;
  font-size: 12.5px;
  color: var(--text-2);
  max-width: 100%;
}
.upload-row input[type="file"]::file-selector-button {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 4px 9px;
  margin-right: 9px;
  cursor: pointer;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  align-items: end;
}
.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 12px; color: var(--dim); }
.form-field input, .form-field select { width: 100%; }

/* 上传进度 */
.upload-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.upload-progress[hidden] { display: none; }
.upload-progress .bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, .08);
  border-radius: 3px;
  overflow: hidden;
}
.upload-progress .bar > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width .2s linear;
}
.upload-progress .pct {
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  flex: none;
  min-width: 92px;
  text-align: right;
}
.upload-progress.done .pct { color: #a4e8cd; }
.upload-progress.failed .pct { color: #ffb3bb; }

/* 任务列表 */
.task-list { margin-top: 12px; font-size: 13px; }
.task-item {
  padding: 9px 0;
  border-top: 1px solid var(--line);
  display: flex; gap: 10px; align-items: center;
}
.task-item .kind {
  font-size: 11px; padding: 2px 7px; border-radius: 5px;
  background: rgba(120, 150, 220, .14); color: #b9c9f0; flex: none;
}
.task-item .msg { flex: 0 0 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-bar { flex: 1; height: 5px; background: rgba(255, 255, 255, .08); border-radius: 3px; overflow: hidden; }
.task-bar > span { display: block; height: 100%; background: var(--brand); width: 0; transition: width .3s; }
.task-item .pct { width: 42px; text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; flex: none; }

/* 状态条 */
.status-line {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 13px;
}
.status-line.ok { border-color: rgba(55, 211, 153, .32); color: #a4e8cd; }
.status-line.bad { border-color: rgba(245, 69, 92, .32); color: #ffb3bb; }

/* Toast */
#toast-box {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
}
#toast-box .toast { left: auto; right: 0; bottom: auto; transform: none; }

/* =========================================================
   响应式
   ========================================================= */
@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; padding: 14px 12px 50px; gap: 0; }

  .admin-menu-btn { display: inline-grid; }
  .admin-nav {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 250px;
    z-index: 70;
    border-radius: 0;
    border: none;
    border-right: 1px solid var(--line);
    padding-top: 14px;
    transform: translateX(-100%);
    transition: transform .22s ease;
    overflow-y: auto;
  }
  .admin-nav.open { transform: none; }
  .drawer-mask {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .55);
    z-index: 65;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s;
  }
  .drawer-mask.show { opacity: 1; pointer-events: auto; }
}

@media (max-width: 760px) {
  /* 顶栏精简：只留菜单、图标、头像、退出 */
  .admin-page .topbar { gap: 8px; padding: 0 12px; }
  .admin-page .topbar .brand { display: none; }
  .admin-page .user-chip .name { display: none; }
  .admin-page #admin-logout { padding: 6px 10px; }

  /* 表格转卡片 */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: 10px;
    padding: 10px 12px;
    background: var(--bg-2);
  }
  .data-table tbody tr:hover { background: var(--bg-2); }
  .data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
    border: none;
    white-space: normal;
    text-align: right;
  }
  .data-table td::before {
    content: attr(data-label);
    color: var(--dim);
    font-size: 12px;
    flex: none;
    text-align: left;
  }
  .data-table td.title-cell { max-width: none; font-weight: 500; }
  .data-table td.cell-actions {
    justify-content: flex-end;
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }
  .data-table td.cell-actions::before { content: ''; }
  .data-table .actions { flex-wrap: wrap; justify-content: flex-end; }
  .data-table .empty-row td { justify-content: center; padding: 22px 0; }

  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 11px 13px; }
  .stat-card .value { font-size: 20px; }
  .page-head h2 { font-size: 17px; }
  .panel { padding: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .upload-row { flex-direction: column; align-items: stretch; }
  .upload-row input[type="text"], .upload-row input[type="file"] { width: 100%; max-width: none; }
  .upload-row button { width: 100%; }
  .task-item { flex-wrap: wrap; }
  .task-item .msg { flex: 1 1 100%; order: 3; }
  #toast-box { left: 12px; right: 12px; bottom: 12px; }
  #toast-box .toast { left: 0; right: 0; }
}
