/* ==========================================================================
   管理端公共样式
   ========================================================================== */
html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  box-sizing: border-box;
}
*, *:before, *:after {
  box-sizing: border-box;
}

/* 全局去除管理端可见上下/左右滚动条 */
::-webkit-scrollbar {
  width: 0px !important;
  height: 0px !important;
  display: none !important;
}
html, body, .admin, .main, .content, .sidebar, .nav, .table-wrap, .drawer-body {
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

.admin { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; max-width: 100vw; width: 100%; box-sizing: border-box; }

.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--sp-6);
  padding: var(--sp-5); background: var(--bg-surface); border-right: 1px solid var(--border-subtle); box-sizing: border-box; }
.brand-mark { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-md); font-weight: var(--fw-semibold); letter-spacing: -0.01em; }
.brand-logo { width: 30px; height: 30px; border-radius: var(--radius-sm); background: var(--accent); display: grid; place-items: center; color: var(--text-inverse); }
.brand-sub { font-size: var(--fs-xs); color: var(--text-tertiary); margin-left: 38px; margin-top: -6px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group-label { font-size: var(--fs-xs); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: .06em; color: var(--text-tertiary); padding: var(--sp-3) var(--sp-3) var(--sp-1); }
.nav-item { display: flex; align-items: center; gap: var(--sp-3); height: 38px; padding: 0 var(--sp-3); border-radius: var(--radius-md);
  font-size: var(--fs-base); color: var(--text-secondary); transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-text); font-weight: var(--fw-medium); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: var(--sp-2); }
.mobile-to-studio-btn { display: none; }
.user-chip { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2); border-radius: var(--radius-md); border: 1px solid var(--border-subtle); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-size: var(--fs-sm); font-weight: var(--fw-semibold); }
.user-chip .name { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.user-chip .role { font-size: var(--fs-xs); color: var(--text-tertiary); }

.main { min-width: 0; width: 100%; max-width: 100%; box-sizing: border-box; }
.main-head { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  height: var(--header-h); padding: 0 var(--sp-8); background: color-mix(in srgb, var(--bg-canvas) 88%, transparent); backdrop-filter: blur(12px); border-bottom: 1px solid var(--border-subtle); width: 100%; max-width: 100%; box-sizing: border-box; }
.main-head h1 { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.main-head .crumb { font-size: var(--fs-xs); color: var(--text-tertiary); }
.main-head-actions { display: flex; align-items: center; gap: var(--sp-2); flex-shrink: 0; }

.content { padding: var(--sp-8); display: flex; flex-direction: column; gap: var(--sp-6); width: 100%; max-width: 100%; min-width: 0; box-sizing: border-box; }
.page-intro { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-6); flex-wrap: wrap; }
.page-intro h2 { font-size: var(--fs-lg); font-weight: var(--fw-semibold); margin-bottom: var(--sp-1); }
.page-intro p { color: var(--text-secondary); font-size: var(--fs-sm); max-width: 620px; }

/* 主模型配置卡片 */
.planner-card {
  padding: var(--sp-5);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.planner-head h3 {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: 4px;
}
.planner-head p {
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  max-width: 680px;
  line-height: var(--lh-normal);
}
.planner-controls {
  display: flex;
  gap: var(--sp-4);
  align-items: flex-end;
  flex-wrap: wrap;
}
.planner-field {
  flex: 1;
  min-width: 220px;
}
.planner-btn-row { display: flex; gap: var(--sp-2); padding-bottom: 1px; }

/* 生图模型授权池 */
.pool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.pool-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 11px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  cursor: pointer;
  transition: border-color var(--dur-fast), background-color var(--dur-fast);
}
.pool-item:hover { border-color: var(--border-strong); }
.pool-item.is-checked {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.pool-item input { margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; }
.pool-item-body { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.pool-item-name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pool-item-id {
  font-size: 11px;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pool-empty {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  padding: 10px 0;
}
.planner-hint {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  min-height: 16px;
}
.planner-hint.is-warn { color: var(--warning); }
.planner-hint.is-ok { color: var(--success); }

/* Provider 卡片 */
.provider-list { display: flex; flex-direction: column; gap: var(--sp-3); }.provider-card { display: grid; grid-template-columns: 1fr auto; gap: var(--sp-4); align-items: center; padding: var(--sp-5);
  background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: var(--radius-lg);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
.provider-card:hover { border-color: var(--border-default); box-shadow: var(--shadow-md); }
.provider-main { display: flex; align-items: center; gap: var(--sp-4); min-width: 0; }
.provider-icon { width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; flex-shrink: 0; }
.provider-head { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.provider-name { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.provider-url { font-size: var(--fs-sm); color: var(--text-secondary); font-family: var(--font-mono); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.provider-meta { display: flex; gap: var(--sp-4); margin-top: var(--sp-2); font-size: var(--fs-xs); color: var(--text-tertiary); flex-wrap: wrap; }
.key-mask { font-family: var(--font-mono); letter-spacing: 0.04em; }
.provider-actions { display: flex; align-items: center; gap: var(--sp-1); flex-wrap: wrap; justify-content: flex-end; }

.model-tags { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.model-tag { display: inline-flex; align-items: center; gap: var(--sp-2); height: 28px; padding: 0 var(--sp-3); border-radius: var(--radius-md);
  background: var(--bg-sunken); border: 1px solid var(--border-subtle); font-size: var(--fs-xs); color: var(--text-secondary); }

/* 抽屉 */
.drawer-overlay { position: fixed; inset: 0; z-index: var(--z-overlay); background: rgba(28,29,33,.35); backdrop-filter: blur(2px); opacity: 0; visibility: hidden; transition: opacity var(--dur-base) var(--ease-out), visibility var(--dur-base); }
.drawer-overlay.is-open { opacity: 1; visibility: visible; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: var(--z-modal); width: 480px; max-width: 94vw; background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; transform: translateX(100%); visibility: hidden; pointer-events: none; transition: transform var(--dur-slow) var(--ease-out), visibility var(--dur-slow); }
.drawer.is-open { transform: translateX(0); visibility: visible; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-5) var(--sp-6); border-bottom: 1px solid var(--border-subtle); }
.drawer-head h3 { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.drawer-body { flex: 1; overflow-y: auto; padding: var(--sp-6); display: flex; flex-direction: column; gap: var(--sp-5); }
.drawer-foot { display: flex; justify-content: flex-end; gap: var(--sp-3); padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--border-subtle); }

/* 模型管理列表 */
.model-row-item { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); background: var(--bg-sunken); }
.model-row-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.model-row-name { font-size: var(--fs-sm); font-weight: var(--fw-medium); }
.model-row-id { font-size: var(--fs-xs); color: var(--text-tertiary); font-family: var(--font-mono); }
.model-cap { display: flex; flex-wrap: wrap; gap: 6px; }
.cap-pill { font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); }
.cap-pill.muted { background: var(--bg-surface); color: var(--text-tertiary); border: 1px solid var(--border-subtle); }

.empty-block { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); padding: var(--sp-12); text-align: center; border: 1px dashed var(--border-subtle); border-radius: var(--radius-lg); }
.empty-block .icon-wrap { width: 52px; height: 52px; border-radius: var(--radius-lg); background: var(--bg-surface); border: 1px solid var(--border-subtle); display: grid; place-items: center; color: var(--accent-text); }
.empty-block h3 { font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.empty-block p { color: var(--text-secondary); font-size: var(--fs-sm); }

/* 表格 */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.search { position: relative; width: 260px; max-width: 100%; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); }
.search .input { padding-left: 38px; }
.table-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: block;
}
table {
  width: 100%;
  min-width: 680px; /* 核心防错位约束：小屏下横向滑动，杜绝中文单字竖排折行 */
  border-collapse: collapse;
}
thead th {
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-tertiary);
  padding: var(--sp-3) var(--sp-5);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}
tbody td {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
  font-size: var(--fs-base);
  vertical-align: middle;
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color var(--dur-fast) var(--ease-out); }
tbody tr:hover { background: var(--bg-hover); }
.cell-user { display: flex; align-items: center; gap: var(--sp-3); }
.cell-user .avatar { width: 34px; height: 34px; flex-shrink: 0; }
.cell-user .uid { font-size: var(--fs-xs); color: var(--text-tertiary); font-family: var(--font-mono); }
.row-actions { display: flex; align-items: center; gap: var(--sp-1); justify-content: flex-end; }
.row-actions .btn {
  padding: 4px 8px;
  font-size: 12px;
}

/* ==========================================================================
   响应式断点：按 max-width 从大到小排列，确保窄屏覆盖生效
   ========================================================================== */
@media (max-width: 900px) {
  .admin {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    max-width: 100vw;
    width: 100%;
    overflow-x: hidden;
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    height: auto;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    background: color-mix(in srgb, var(--bg-surface) 96%, transparent);
    backdrop-filter: blur(16px);
  }
  .sidebar > div:first-child {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }
  .mobile-to-studio-btn {
    display: inline-flex !important;
    align-items: center;
    gap: 4px;
    height: 28px;
    padding: 0 10px;
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent-text);
    font-size: 12px;
    font-weight: var(--fw-medium);
    text-decoration: none;
    border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
    white-space: nowrap;
  }
  .brand-sub { display: none; }
  .sidebar .nav {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    margin: 0;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .sidebar .nav::-webkit-scrollbar {
    display: none;
  }
  .nav-item {
    padding: 5px 10px;
    font-size: 12.5px;
    white-space: nowrap;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    background: var(--bg-sunken);
  }
  .nav-item.is-active {
    background: var(--accent-soft);
    color: var(--accent-text);
  }
  .nav-group-label { display: none; }
  .sidebar-foot {
    display: none;
  }

  .main {
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    overflow-x: hidden;
  }
  .main-head {
    height: auto;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    box-sizing: border-box;
    width: 100%;
    max-width: 100vw;
  }
  .main-head h1 {
    font-size: var(--fs-base);
    margin: 0;
  }
  .main-head .crumb {
    display: none; /* 移动端隐藏冗余面包屑，节省横向空间 */
  }
  .main-head-actions {
    gap: 6px;
    flex-shrink: 0;
  }
  .main-head-actions .btn {
    padding: 5px 10px;
    font-size: 12px;
  }
  .content {
    padding: var(--sp-3);
    gap: var(--sp-4);
    width: 100% !important;
    max-width: 100vw !important;
    min-width: 0 !important;
    box-sizing: border-box;
    overflow-x: hidden;
  }
  .page-intro {
    gap: var(--sp-2);
  }
  .page-intro h2 {
    font-size: var(--fs-md);
  }
  .page-intro p {
    font-size: var(--fs-xs);
    line-height: 1.5;
  }
  .provider-url { max-width: 60vw; }

  /* 抽屉在移动端占满屏 */
  .drawer {
    width: 100vw !important;
    max-width: 100vw !important;
  }
  .drawer-body {
    padding: var(--sp-4);
    gap: var(--sp-4);
  }
  .drawer-foot {
    padding: var(--sp-3) var(--sp-4);
    flex-wrap: wrap;
  }
  .drawer-foot .btn {
    flex: 1;
  }
}

@media (max-width: 720px) {
  .row-actions .btn {
    padding: 2px 6px;
    font-size: 11px;
  }
  .planner-controls {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-3);
  }
  .planner-field {
    width: 100% !important;
    min-width: 0 !important;
  }
  .planner-btn-row {
    width: 100%;
    display: flex;
    gap: var(--sp-2);
  }
  .planner-btn-row .btn {
    flex: 1;
    justify-content: center;
    padding: 8px 12px;
  }
  .pool-grid {
    grid-template-columns: 1fr;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-2);
  }
  .search {
    width: 100%;
  }
  .provider-card {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    padding: var(--sp-4);
  }
  .provider-actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
    border-top: 1px dashed var(--border-subtle);
    padding-top: var(--sp-2);
  }
}

@media (max-width: 480px) {
  .main-head {
    padding: 8px 12px;
  }
  .main-head h1 {
    font-size: 14px;
    white-space: nowrap;
  }
  .main-head-actions {
    gap: 4px;
  }
  .main-head-actions .btn {
    padding: 4px 8px;
    font-size: 11.5px;
    white-space: nowrap;
  }
  .main-head-actions .icon-btn {
    width: 28px;
    height: 28px;
  }
}

/* 移动端专属用户卡片列表（彻底消除左右横向滚动条） */
.user-card-list {
  display: none;
  flex-direction: column;
  gap: var(--sp-3);
  width: 100%;
}
@media (max-width: 768px) {
  .table-wrap {
    display: none !important;
  }
  .user-card-list {
    display: flex !important;
  }
}
.user-card {
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.user-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}
.user-card-identity {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.user-card-name {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}
.user-card-uid {
  font-size: var(--fs-xs);
  color: var(--text-tertiary);
  font-family: var(--font-mono);
}
.user-card-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}
.user-card-info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--bg-sunken);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
}
.user-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  border-top: 1px dashed var(--border-subtle);
  padding-top: var(--sp-2);
  flex-wrap: wrap;
}
.user-card-actions .btn {
  padding: 4px 8px;
  font-size: 11.5px;
}
