body { background: #f4f6fb; }
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: linear-gradient(180deg, #1e1b4b, #312e81);
  color: #fff;
  padding: 24px 16px;
  display: flex; flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex: 0 0 220px;
  box-sizing: border-box;
}
.sidebar-brand {
  font-weight: 700; font-size: 17px;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 22px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand .brand-logo {
  width: 32px; height: 32px; border-radius: 9px;
}
.sidebar-brand .brand-logo svg { width: 18px; height: 18px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  margin-top: 6px;
  border-radius: 10px;
  color: rgba(255,255,255,.72);
  cursor: pointer;
  font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.14); color: #fff; }
.nav-item svg { width: 18px; height: 18px; }
.main-area { flex: 1; padding: 28px 40px; overflow-y: auto; }
.main-area > section { max-width: 1280px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
.page-header h1 { margin: 0; font-size: 22px; color: #1e293b; font-weight: 700; }
.stat-grid { display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px;margin-bottom:24px; }
.stat-card {
  background: #fff; border-radius: 14px; padding: 20px 22px;
  box-shadow: 0 6px 20px -10px rgba(15,23,42,.15);
  border: 1px solid #eef0f5;
  display: flex; align-items: center; gap: 16px;
}
.stat-card .stat-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg,#eef2ff,#fce7f3);
  display: inline-flex; align-items: center; justify-content: center;
  color: #6366f1;
}
.stat-card .stat-icon svg { width: 22px; height: 22px; }
.stat-card .label { font-size: 13px; color: #6b7280; }
.stat-card .value {
  font-size: 26px; font-weight: 700; margin-top: 2px;
  background: linear-gradient(135deg,#6366f1,#ec4899);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.dashboard-rank-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:16px; margin-bottom:24px; }
.rank-card { background:#fff; border:1px solid #eef0f5; border-radius:16px; padding:18px; box-shadow:0 6px 20px -12px rgba(15,23,42,.16); min-width:0; }
.rank-head { display:flex; align-items:flex-start; justify-content:space-between; gap:10px; margin-bottom:12px; }
.rank-title { margin:0; color:#1e293b; font-size:15px; font-weight:750; }
.rank-sub { color:#94a3b8; font-size:12px; margin-top:3px; }
.rank-list { display:flex; flex-direction:column; gap:9px; }
.rank-empty { color:#94a3b8; font-size:13px; text-align:center; padding:22px 8px; border:1px dashed #e2e8f0; border-radius:12px; background:#f8fafc; }
.rank-item { display:grid; grid-template-columns:28px minmax(0,1fr) auto; gap:10px; align-items:center; padding:10px; border:1px solid #eef2f7; border-radius:12px; background:#fbfdff; }
.rank-item.clickable { cursor:pointer; transition:background .15s,border-color .15s,transform .15s; }
.rank-item.clickable:hover { background:#f8fafc; border-color:#c7d2fe; transform:translateY(-1px); }
.rank-no { width:28px; height:28px; border-radius:9px; display:inline-flex; align-items:center; justify-content:center; background:#eef2ff; color:#4f46e5; font-weight:800; font-size:12px; }
.rank-user { min-width:0; }
.rank-name { color:#1e293b; font-weight:720; font-size:13px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.rank-meta { color:#94a3b8; font-size:11.5px; margin-top:2px; }
.rank-value { text-align:right; color:#0f172a; font-size:13px; font-weight:800; white-space:nowrap; }
.rank-value.danger { color:#dc2626; }
.rank-view { display:inline-flex; margin-top:4px; color:#4f46e5; font-size:11.5px; font-weight:700; }
.panel { background:#fff; border-radius:14px; padding:22px 24px; border:1px solid #eef0f5; box-shadow:0 4px 14px -8px rgba(15,23,42,.1); }
.panel h2 { margin: 0 0 16px; font-size: 16px; color: #1e293b; font-weight: 600; }
.form-row { display:grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-row.full { grid-template-columns: 1fr; }
.btn-secondary {
  background: #1e293b; color: #fff; border: 0; border-radius: 10px;
  padding: 10px 18px; cursor: pointer; font-weight: 500;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-secondary:hover { background: #0f172a; }
.btn-secondary svg { width: 16px; height: 16px; }
.btn-action {
  background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe;
  border-radius: 8px; padding: 6px 12px; cursor: pointer;
  font-size: 13px; margin-right: 6px;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn-action:hover { background: #e0e7ff; }
.btn-action svg { width: 14px; height: 14px; }
.theme-choice-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.theme-choice {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  text-align: left;
  cursor: pointer;
  transition: border-color .16s, box-shadow .16s, transform .16s;
}
.theme-choice:hover { transform: translateY(-1px); border-color: #c7d2fe; box-shadow: 0 10px 24px -18px rgba(15,23,42,.28); }
.theme-choice.active { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,.14); }
.theme-choice-title { display:flex;align-items:center;justify-content:space-between;gap:8px;font-size:14px;font-weight:800;color:#111827;margin-bottom:8px; }
.theme-choice-desc { color:#64748b;font-size:12px;line-height:1.5;margin-bottom:12px; }
.theme-swatches { display:flex;gap:6px; }
.theme-swatches span { width:24px;height:24px;border-radius:999px;border:1px solid rgba(15,23,42,.12);box-shadow:inset 0 1px 0 rgba(255,255,255,.35); }
.theme-check { width:18px;height:18px;border-radius:999px;border:1px solid #cbd5e1;display:inline-flex;align-items:center;justify-content:center;color:#fff;background:#fff;flex-shrink:0; }
.theme-choice.active .theme-check { background:#6366f1;border-color:#6366f1; }
.api-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
  max-width: 1120px;
  align-items: start;
}
.api-config-card {
  max-width: none !important;
  margin-bottom: 0 !important;
  border-radius: 18px;
  border-color: #e6eaf3;
  box-shadow: 0 16px 42px -34px rgba(15,23,42,.45);
}
.api-config-card h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.api-config-card .api-note {
  color:#64748b;
  font-size:13px;
  line-height:1.6;
  margin:-2px 0 16px;
}
.api-actions {
  display:flex;
  gap:10px;
  margin-top:8px;
  flex-wrap:wrap;
}
html[data-app-theme="daydream"] body,
html[data-app-theme="daydream"] .main-area { background: #0f1014; }
html[data-app-theme="daydream"] .sidebar { background: #18191e; }
html[data-app-theme="daydream"] .page-header h1,
html[data-app-theme="daydream"] .panel h2 { color: #f4f4f5; }
html[data-app-theme="daydream"] .panel,
html[data-app-theme="daydream"] .stat-card,
html[data-app-theme="daydream"] .rank-card,
html[data-app-theme="daydream"] .img-card { background: #18191e; border-color: rgba(255,255,255,.08); box-shadow: 0 18px 42px -32px rgba(0,0,0,.9); }
html[data-app-theme="daydream"] .rank-title,
html[data-app-theme="daydream"] .rank-name,
html[data-app-theme="daydream"] .rank-value { color:#f4f4f5; }
html[data-app-theme="daydream"] .rank-sub,
html[data-app-theme="daydream"] .rank-meta { color:rgba(244,244,245,.56); }
html[data-app-theme="daydream"] .rank-item { background:#202126; border-color:rgba(255,255,255,.08); }
html[data-app-theme="daydream"] .rank-item.clickable:hover { background:#25262c; border-color:rgba(255,255,255,.18); }
html[data-app-theme="daydream"] .rank-empty { background:#202126; border-color:rgba(255,255,255,.10); color:rgba(244,244,245,.56); }
html[data-app-theme="daydream"] .btn-secondary { background: #f4f4f5; color: #111216; }
html[data-app-theme="daydream"] .btn-secondary:hover { background: #ffffff; }
html[data-app-theme="daydream"] .btn-action { background: #202126; color: #f4f4f5; border-color: rgba(255,255,255,.08); }
html[data-app-theme="daydream"] .btn-action:hover { background: #25262c; }
html[data-app-theme="daydream"] .theme-choice { background: #202126; border-color: rgba(255,255,255,.08); }
html[data-app-theme="daydream"] .theme-choice-title { color: #f4f4f5; }
html[data-app-theme="daydream"] .theme-choice-desc { color: rgba(244,244,245,.58); }
html[data-app-theme="daydream"] .theme-choice.active { border-color: #f4f4f5; box-shadow: 0 0 0 3px rgba(255,255,255,.12); }
html[data-app-theme="daydream"] .theme-choice.active .theme-check { background: #f4f4f5; border-color: #f4f4f5; color: #111216; }
html[data-app-theme="vale"] body,
html[data-app-theme="vale"] .main-area { background: #f8fafc; }
html[data-app-theme="vale"] .sidebar { background: #ffffff; color: #111827; border-right: 1px solid #e5e7eb; }
html[data-app-theme="vale"] .nav-item { color: #64748b; }
html[data-app-theme="vale"] .nav-item:hover,
html[data-app-theme="vale"] .nav-item.active { background: #f1f5f9; color: #111827; }
html[data-app-theme="vale"] .sidebar-brand { border-bottom-color: #e5e7eb; }
html[data-app-theme="vale"] .btn-secondary { background: #111827; color: #fff; }
html[data-app-theme="vale"] .btn-action { background: #fff; color: #111827; border-color: #e5e7eb; }
html[data-app-theme="vale"] .btn-action:hover { background: #f8fafc; }
.sidebar-foot a, .sidebar-foot button {
  flex: 1; text-align: center; text-decoration: none;
  font-size: 12px; padding: 7px;
}
/* 图片管理 */
.img-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.img-card {
  background: #fff;
  border-radius: 12px;
  border: 1px solid #eef0f5;
  overflow: hidden;
  box-shadow: 0 4px 14px -8px rgba(15,23,42,.1);
  transition: transform .15s, box-shadow .15s;
  position: relative;
}
.img-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px -8px rgba(15,23,42,.18);
}
.img-card .img-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  cursor: pointer;
  display: block;
  background: #f1f5f9;
}
.img-card .img-meta {
  padding: 10px 12px;
}
.img-card .img-meta .img-prompt {
  font-size: 12px;
  color: #475569;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}
.img-card .img-meta .img-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: #94a3b8;
}
.img-card .img-user-tag {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  backdrop-filter: blur(4px);
}
.img-card .img-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity .15s;
}
.img-card:hover .img-actions { opacity: 1; }
.img-card .img-actions button {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: rgba(0,0,0,.6);
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.img-card .img-actions button:hover { background: rgba(220,38,38,.8); }
.img-preview-dialog {
  width: min(1180px, 94vw);
  max-height: 92vh;
  background: #fff;
  border-radius: 18px;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(320px, 1.18fr) minmax(320px, .82fr);
  box-shadow: 0 28px 70px -28px rgba(15,23,42,.55);
  border: 1px solid rgba(226,232,240,.9);
}
.img-preview-main {
  background: #0f172a;
  min-height: 420px;
  max-height: 92vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}
.img-preview-main img {
  max-width: 100%;
  max-height: calc(92vh - 36px);
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 20px 44px -28px rgba(0,0,0,.8);
}
.img-preview-side {
  min-width: 0;
  padding: 20px;
  overflow-y: auto;
  max-height: 92vh;
  background: #f8fafc;
}
.img-preview-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.img-preview-top h2 {
  margin: 0;
  color: #0f172a;
  font-size: 18px;
  font-weight: 850;
}
.img-preview-close {
  width: 34px;
  height: 34px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: #fff;
  color: #0f172a;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.img-preview-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.img-preview-pill {
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  font-weight: 700;
}
.img-preview-section {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #fff;
}
.img-preview-section h3 {
  margin: 0 0 10px;
  color: #1e293b;
  font-size: 13px;
  font-weight: 850;
}
.img-preview-prompt {
  white-space: pre-wrap;
  word-break: break-word;
  color: #334155;
  font-size: 13px;
  line-height: 1.75;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}
.img-preview-refs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}
.img-preview-ref {
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f1f5f9;
  cursor: pointer;
  padding: 6px;
  text-decoration: none;
  display: block;
}
.img-preview-ref img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  border-radius: 8px;
}
.img-preview-empty {
  color: #94a3b8;
  font-size: 13px;
  padding: 8px 0;
}
.img-chain-step {
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #f8fafc;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.img-chain-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: #0f172a;
  font-size: 12.5px;
  font-weight: 850;
}
.img-chain-status {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 11px;
  font-weight: 800;
}
.img-chain-pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #475569;
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.55;
  max-height: 220px;
  overflow: auto;
}
@media (max-width: 860px) {
  .img-preview-dialog { grid-template-columns: 1fr; }
  .img-preview-main { min-height: 260px; max-height: 48vh; }
  .img-preview-main img { max-height: calc(48vh - 36px); }
  .img-preview-side { max-height: 44vh; }
}
.page-btn {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 13px;
  color: #475569;
  transition: all .15s;
}
.page-btn:hover { background: #f8fafc; border-color: #c7d2fe; }
.page-btn.active { background: #6366f1; color: #fff; border-color: #6366f1; }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.log-filter-bar {
  display: grid;
  grid-template-columns: 180px 140px minmax(220px, 1fr) 110px auto auto;
  gap: 10px;
  align-items: center;
}
.log-status {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}
.log-status.success {
  color: #047857;
  background: #ecfdf5;
  border-color: #a7f3d0;
}
.log-status.failure {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fecaca;
}
.log-message {
  color: #1e293b;
  font-size: 13px;
  line-height: 1.5;
  max-width: 430px;
  word-break: break-word;
}
.log-detail {
  margin-top: 4px;
  color: #64748b;
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  font-size: 11px;
  line-height: 1.45;
  max-width: 520px;
  max-height: 58px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.log-action-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 8px;
  border-radius: 8px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
@media (max-width: 768px) {
  .admin-shell {
    display: block;
    min-width: 0;
  }
  .sidebar {
    width: auto;
    height: auto;
    flex: none;
    min-height: auto;
    padding: 14px 12px 12px;
    display: grid;
    grid-template-columns: repeat(4, minmax(72px, 1fr));
    gap: 8px;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .sidebar-brand {
    grid-column: 1 / -1;
    padding: 0 4px 10px;
    font-size: 15px;
  }
  .nav-item {
    margin-top: 0;
    padding: 9px 6px;
    justify-content: center;
    gap: 5px;
    font-size: 12px;
    text-align: center;
    white-space: nowrap;
  }
  .nav-item svg {
    width: 15px;
    height: 15px;
  }
  .sidebar > div[style*="margin-top:auto"] {
    grid-column: 1 / -1;
    margin-top: 2px !important;
    padding: 2px 4px 0 !important;
  }
  .main-area {
    padding: 18px 12px 28px;
    overflow-x: hidden;
  }
  .main-area > section {
    max-width: 100%;
  }
  .page-header {
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 14px;
  }
  .page-header h1 {
    font-size: 20px;
    line-height: 1.25;
  }
  .panel {
    padding: 14px;
    border-radius: 12px;
  }
  .form-row,
  .stat-grid {
    grid-template-columns: 1fr;
  }
  .dashboard-rank-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .img-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .img-card:hover {
    transform: none;
  }
  .img-card .img-actions {
    opacity: 1;
  }
  #page-images .panel > div {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  #imgSearch,
  #imgUserFilter {
    width: 100% !important;
    min-width: 0 !important;
    grid-column: 1 / -1;
  }
  #imgPagination {
    flex-wrap: wrap;
  }
  table {
    min-width: 680px;
  }
  #page-users .panel,
  #page-storyboards .panel,
  #page-logs .panel {
    overflow: visible !important;
    background: transparent;
    border: 0;
    box-shadow: none;
  }
  #page-users table,
  #page-storyboards table,
  #page-logs table,
  #page-users thead,
  #page-storyboards thead,
  #page-logs thead,
  #page-users tbody,
  #page-storyboards tbody,
  #page-logs tbody,
  #page-users tr,
  #page-storyboards tr,
  #page-logs tr,
  #page-users td,
  #page-storyboards td,
  #page-logs td {
    display: block;
    min-width: 0;
    width: 100%;
  }
  #page-users thead,
  #page-storyboards thead,
  #page-logs thead {
    display: none;
  }
  #page-users tr,
  #page-storyboards tr,
  #page-logs tr {
    background: #fff;
    border: 1px solid #eef0f5;
    border-radius: 14px;
    margin-bottom: 12px;
    padding: 12px;
    box-shadow: 0 4px 14px -8px rgba(15,23,42,.14);
  }
  #page-users td,
  #page-storyboards td,
  #page-logs td {
    border: 0;
    padding: 8px 0;
    font-size: 13px;
  }
  #page-users td::before,
  #page-storyboards td::before,
  #page-logs td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    color: #94a3b8;
    font-size: 11px;
    font-weight: 600;
  }
  #page-users td:last-child,
  #page-storyboards td:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid #eef2f7;
  }
  #page-users td:last-child::before,
  #page-storyboards td:last-child::before {
    width: 100%;
  }
  #page-users .btn-action,
  #page-storyboards .btn-action,
  #page-users .btn-danger,
  #page-storyboards .btn-danger {
    margin-right: 0;
    flex: 1 1 auto;
    justify-content: center;
  }
  #page-storyboards .page-header {
    display: block;
  }
  #page-storyboards .page-header > div {
    display: grid !important;
    grid-template-columns: 1fr auto;
    margin-top: 12px;
  }
  #sbSearch {
    width: 100% !important;
    min-width: 0;
  }
  #adminSbTbody td[data-label="标题"] > div,
  #adminSbTbody td[data-label="标题"] > div + div {
    max-width: none !important;
    white-space: normal !important;
  }
  #adminSbTbody td[data-label="封面"] > div {
    width: 72px !important;
    height: 54px !important;
  }
  .log-filter-bar {
    grid-template-columns: 1fr;
  }
  .theme-choice-grid {
    grid-template-columns: 1fr;
  }
  .log-message,
  .log-detail {
    max-width: none;
  }
}
@media (max-width: 420px) {
  .sidebar {
    grid-template-columns: repeat(3, minmax(72px, 1fr));
  }
  .img-gallery {
    grid-template-columns: 1fr;
  }
}