/* NapCat 控制台 · 管理员后台样式
   复用 base.css 的设计变量与原子组件（.card / .btn / .badge / .table / .tabs /
   .field / .switch / .stat-grid / .modal / .toast / .logs / .empty / .spinner），
   这里只补充后台特有的骨架、登录页、工具栏、审计日志与容器编排组件。
   骨架类统一挂在 .admin-body 作用域下，避免与 console.css 的同名类互相污染。 */

/* ==================== 1. 页面骨架 ==================== */

body.admin-body {
  --side-w: 264px;
  overflow-x: hidden;
}

/* 桌面折叠为图标栏 */
body.admin-body.nav-collapsed {
  --side-w: 84px;
}

/* 首屏引导遮罩 */
.boot {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 14px;
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 500px at 12% -10%, rgba(56, 189, 248, 0.16), transparent 60%),
    radial-gradient(800px 480px at 92% 0%, rgba(99, 102, 241, 0.18), transparent 62%);
}

.boot-text {
  color: var(--muted);
  font-size: 14px;
  letter-spacing: 0.04em;
}

/* 侧边栏 + 主内容 双列骨架 */
body.admin-body .app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: 100vh;
  transition: grid-template-columns 0.26s cubic-bezier(0.22, 1, 0.36, 1);
}

body.admin-body .sidebar {
  position: sticky;
  top: 0;
  z-index: 45;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 16px calc(18px + env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(11, 16, 32, 0.92), rgba(8, 11, 18, 0.96));
  backdrop-filter: blur(14px);
  overflow-x: hidden;
  overflow-y: auto;
  transition: padding 0.26s ease, transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

/* 品牌区 */
body.admin-body .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 8px 14px;
  color: var(--text);
  text-decoration: none;
  flex: 1 1 auto;
  min-width: 0;
}

body.admin-body .brand:hover {
  color: var(--text);
}

body.admin-body .brand-logo {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: var(--grad);
  color: #ffffff;
  box-shadow: var(--shadow);
}

body.admin-body .brand-logo svg {
  width: 21px;
  height: 21px;
}

body.admin-body .brand-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

body.admin-body .brand-text {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}

body.admin-body .brand-sub {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

/* 主导航 */
body.admin-body .nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

body.admin-body .nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  height: 42px;
  padding: 0 12px;
  border-radius: 10px;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 550;
  letter-spacing: 0.01em;
  text-decoration: none;
  transition: background 0.16s ease, color 0.16s ease;
}

body.admin-body .nav-item svg {
  width: 18px;
  height: 18px;
  flex: none;
  opacity: 0.85;
  transition: color 0.16s ease, opacity 0.16s ease;
}

body.admin-body .nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

body.admin-body .nav-item:hover svg {
  opacity: 1;
}

body.admin-body .nav-item.is-active {
  background: var(--grad-soft);
  color: var(--text);
}

body.admin-body .nav-item.is-active svg {
  color: var(--brand);
  opacity: 1;
}

body.admin-body .nav-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 10px;
  bottom: 10px;
  width: 2px;
  border-radius: 2px;
  background: var(--brand);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.85);
}

/* 侧栏底部：操作员信息 + 快捷链接 */
body.admin-body .side-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

body.admin-body .user-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

body.admin-body .avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--grad);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
}

body.admin-body .avatar svg {
  width: 17px;
  height: 17px;
}

body.admin-body .user-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

body.admin-body .user-box .badge {
  height: 19px;
  padding: 0 7px;
  font-size: 10.5px;
}

body.admin-body .side-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

body.admin-body .side-links a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12.5px;
  text-decoration: none;
  transition: background 0.16s ease, color 0.16s ease;
}

body.admin-body .side-links a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-2);
}

body.admin-body .side-links a svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
}

/* 主内容区 */
body.admin-body .main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 0 clamp(18px, 3vw, 36px) 40px;
}

body.admin-body .topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px 0 18px;
  background: linear-gradient(
    180deg,
    rgba(8, 11, 18, 0.94),
    rgba(8, 11, 18, 0.6) 70%,
    transparent
  );
  backdrop-filter: blur(8px);
}

body.admin-body .topbar h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text);
}

body.admin-body .page-sub {
  margin: 5px 0 0;
  font-size: 12.5px;
  color: var(--muted);
}

body.admin-body .topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
}

/* 顶部提示条（例如演示模式 / 只读提醒） */
body.admin-body .banner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid rgba(251, 191, 36, 0.32);
  border-radius: 12px;
  background: rgba(251, 191, 36, 0.09);
  color: #fde68a;
  font-size: 13px;
}

body.admin-body .banner svg {
  width: 17px;
  height: 17px;
  flex: none;
}

/* 视图容器 */
body.admin-body .view {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: admin-fade-up 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

/* ==================== 2. 登录页 ==================== */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login-card {
  width: min(420px, 100%);
  padding: 34px 30px 26px;
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.02));
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
  animation: admin-fade-up 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  text-align: center;
}

.login-logo {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  border-radius: 16px;
  background: var(--grad);
  color: #ffffff;
  box-shadow: 0 12px 30px rgba(56, 189, 248, 0.28);
}

.login-logo svg {
  width: 28px;
  height: 28px;
}

.login-title {
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
}

.login-sub {
  font-size: 12.5px;
  color: var(--muted);
}

.login-card .form-grid {
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.login-error {
  margin: 2px 0 10px;
  padding: 9px 11px;
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 9px;
  background: rgba(248, 113, 113, 0.12);
  color: #fecaca;
  font-size: 12.5px;
}

.login-card .btn-block {
  margin-top: 16px;
  height: 42px;
}

.login-foot {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  font-size: 12.5px;
}

.login-foot a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.16s ease;
}

.login-foot a:hover {
  color: var(--brand);
}

/* ==================== 3. 工具栏与表格补充 ==================== */

body.admin-body .toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 0 12px;
}

body.admin-body .search-box {
  position: relative;
  flex: 1 1 auto;
  min-width: 220px;
  max-width: 380px;
}

body.admin-body .search-box svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 15px;
  height: 15px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

body.admin-body .search-box .input {
  padding-left: 33px;
}

.tab-count {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  background: rgba(148, 163, 184, 0.16);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.tab.is-active .tab-count {
  background: rgba(56, 189, 248, 0.22);
  color: #bae6fd;
}

/* 表格单元格截断 */
.cell-wrap {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.admin-body .table td.cell-wrap {
  max-width: 280px;
}

body.admin-body .mono-sm {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-2);
}

body.admin-body .foot-note {
  padding: 10px 2px 0;
  color: var(--muted);
  font-size: 12px;
}

body.admin-body .table td {
  vertical-align: middle;
}

body.admin-body .table tbody tr:hover {
  background: rgba(56, 189, 248, 0.055);
}

body.admin-body .table .cell-actions .btn {
  flex: 0 0 auto;
}

/* ==================== 4. 环境信息与审计日志 ==================== */

.env-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.env-item {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.env-label {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.env-value {
  margin-top: 5px;
  font-family: var(--mono);
  font-size: 13.5px;
  color: var(--text);
  word-break: break-all;
}

.log-list {
  display: flex;
  flex-direction: column;
  max-height: 420px;
  overflow-y: auto;
}

.log-row {
  display: grid;
  grid-template-columns: 130px 110px minmax(0, 1fr);
  gap: 12px;
  align-items: baseline;
  padding: 9px 4px;
  border-bottom: 1px dashed var(--line);
  font-size: 12.5px;
}

.log-row:last-child {
  border-bottom: 0;
}

.log-time {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.log-actor {
  color: var(--text-2);
  font-weight: 600;
}

.log-text {
  color: var(--text-2);
  word-break: break-word;
}

.log-action {
  color: var(--brand);
  font-family: var(--mono);
  font-size: 11.5px;
}

/* ==================== 5. 容器编排卡片 ==================== */

.ctr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 14px;
}

.ctr-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.ctr-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.ctr-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.ctr-name {
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

.ctr-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
}

.meta-row span:first-child {
  flex: 0 0 auto;
  color: var(--muted);
}

.meta-row span:last-child {
  color: var(--text-2);
  font-family: var(--mono);
  text-align: right;
  word-break: break-all;
}

.ctr-instances {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.ctr-instances:empty {
  margin-bottom: 0;
}

.ctr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* 小号统计数值（版本号、短文本等） */
body.admin-body .stat-value-sm {
  font-size: 22px;
  line-height: 1.35;
  word-break: break-all;
}

/* ==================== 6. 表单补充与工具类 ==================== */

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.form-grid > .field {
  min-width: 0;
}

.form-grid > .field:has(textarea) {
  grid-column: 1 / -1;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  grid-column: 1 / -1;
  padding-top: 4px;
}

/* 表单内联开关行 */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.switch-row .switch {
  flex: 0 0 auto;
}

.switch-row-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  font-size: 13px;
  color: var(--text);
}

.switch-row-text .small {
  color: var(--muted);
}

.text-ok {
  color: var(--ok);
}

.text-danger {
  color: var(--danger);
}

.text-warn {
  color: var(--warn);
}

.text-brand {
  color: var(--brand);
}

/* ==================== 7. 焦点与可访问性 ==================== */

.admin-body a:focus-visible,
.admin-body button:focus-visible,
.admin-body input:focus-visible,
.admin-body select:focus-visible,
.admin-body textarea:focus-visible {
  outline: 2px solid rgba(56, 189, 248, 0.55);
  outline-offset: 2px;
  border-radius: 8px;
}

/* 防止样式加载顺序导致的 [hidden] 失效 */
[hidden] {
  display: none !important;
}

/* ==================== 8. 动效 ==================== */

@keyframes admin-fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

/* ==================== 9. 响应式 ==================== */

@media (max-width: 1180px) {
  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ctr-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  }
}

/* 桌面：侧栏可折叠为图标栏 */
@media (min-width: 1081px) {
  body.admin-body.nav-collapsed .brand {
    justify-content: center;
    padding: 4px 0 12px;
  }

  body.admin-body.nav-collapsed .brand-copy,
  body.admin-body.nav-collapsed .nav-item > span,
  body.admin-body.nav-collapsed .side-links a > span,
  body.admin-body.nav-collapsed .user-box .grow {
    display: none;
  }

  body.admin-body.nav-collapsed .sidebar {
    padding-left: 10px;
    padding-right: 10px;
  }

  body.admin-body.nav-collapsed .nav-item {
    justify-content: center;
    padding: 0;
  }

  body.admin-body.nav-collapsed .nav-item.is-active::before {
    left: 6px;
  }

  body.admin-body.nav-collapsed .user-box {
    justify-content: center;
    padding: 8px 0;
    border-color: transparent;
    background: transparent;
  }

  body.admin-body.nav-collapsed .side-links {
    align-items: center;
  }

  body.admin-body.nav-collapsed .side-links a {
    justify-content: center;
    padding: 8px 0;
  }
}

/* 平板 / 手机：侧栏改为左侧抽屉 */
@media (max-width: 1080px) {
  body.admin-body .app {
    grid-template-columns: minmax(0, 1fr);
  }

  body.admin-body .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 60;
    width: min(304px, 86vw);
    height: 100vh;
    height: 100dvh;
    padding: 18px 14px calc(16px + env(safe-area-inset-bottom));
    border-right: 1px solid var(--line);
    border-bottom: 0;
    transform: translateX(-102%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  }

  body.admin-body.sidebar-open .sidebar {
    transform: none;
  }

  body.admin-body .sidebar-close {
    display: inline-flex;
  }

  body.admin-body.sidebar-open {
    overflow: hidden;
  }

  body.admin-body .brand {
    padding-right: 4px;
  }

  body.admin-body .main {
    padding: 0 16px 40px;
  }

  body.admin-body .topbar {
    align-items: center;
    gap: 12px;
    padding: 14px 0;
  }

  body.admin-body .topbar h1 {
    font-size: 20px;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ctr-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}

@media (max-width: 720px) {
  .form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .ctr-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  body.admin-body .main {
    padding: 0 14px 36px;
  }

  body.admin-body .topbar {
    gap: 10px;
    padding: 12px 0;
  }

  body.admin-body .topbar h1 {
    font-size: 18px;
  }

  body.admin-body .page-sub {
    display: none;
  }

  body.admin-body .topbar-actions {
    gap: 6px;
  }

  body.admin-body .topbar-actions .btn {
    width: 38px;
    height: 38px;
    padding: 0;
    justify-content: center;
  }

  body.admin-body .topbar-actions .btn span {
    display: none;
  }

  body.admin-body .card {
    padding: 14px;
    border-radius: 14px;
  }

  body.admin-body .toolbar {
    align-items: stretch;
  }

  body.admin-body .toolbar > * {
    flex: 1 1 100%;
    max-width: none;
  }

  body.admin-body .search-box {
    min-width: 0;
    max-width: none;
  }

  body.admin-body .tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  body.admin-body .tabs::-webkit-scrollbar {
    display: none;
  }

  body.admin-body .tabs > * {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .table {
    min-width: 640px;
  }

  .login-card {
    padding: 26px 20px 20px;
    border-radius: 16px;
  }

  .login-title {
    font-size: 18px;
  }

  .login-foot {
    flex-direction: column;
    align-items: center;
    gap: 8px;
  }

  .log-row {
    grid-template-columns: minmax(0, 1fr);
    gap: 3px;
    padding: 10px 2px;
  }

  .log-text {
    grid-column: 1 / -1;
  }

  .env-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .switch-row {
    align-items: flex-start;
  }
}

@media (max-width: 430px) {
  .stat-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  .boot,
  .login-card,
  body.admin-body .view,
  .ctr-card,
  body.admin-body .nav-item,
  .log-row {
    animation: none;
    transition: none;
  }

  .ctr-card:hover {
    transform: none;
  }
}
