:root {
  --bg: #0b0e14;
  --surface: #131823;
  --surface-2: #1b2232;
  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --danger: #ef4444;
  --success: #10b981;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: radial-gradient(circle at 15% 0%, rgba(99, 102, 241, 0.14), transparent 38%),
    radial-gradient(circle at 85% 5%, rgba(236, 72, 153, 0.09), transparent 34%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(11, 14, 20, 0.82);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}

.brand-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.2px;
}

.brand-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.search-wrap {
  flex: 1;
  min-width: 220px;
  max-width: 460px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 14px 9px 36px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.search-wrap input:focus {
  border-color: var(--primary);
  background: var(--surface-2);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.badge {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.storage-badge.oss {
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.1);
}

/* Buttons */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s ease;
  color: var(--text);
  background: var(--surface-2);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover), #8b5cf6);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-hover);
}

.btn-outline:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.28);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12px;
}

.btn-xs {
  padding: 4px 9px;
  font-size: 12px;
  border-radius: 7px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

/* Main */
.container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 20px;
}

.style-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.style-chip {
  padding: 7px 14px;
  border-radius: 999px;
  font-size: 13px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.16s ease;
}

.style-chip:hover {
  border-color: var(--border-hover);
  color: var(--text);
}

.style-chip.active {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(129, 140, 248, 0.6);
  color: #fff;
}

.style-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.chip-count {
  font-size: 11px;
  opacity: 0.7;
}

/* Gallery Grid */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 18px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--border-hover);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.35);
}

.card-media {
  position: relative;
  aspect-ratio: 4 / 3;
  background: #0f141e;
  overflow: hidden;
}

.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.35s ease;
}

.card:hover .card-media img {
  transform: scale(1.04);
}

.card-no-img {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 13px;
}

.card-badges {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
}

.card-id {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(11, 14, 20, 0.75);
  backdrop-filter: blur(8px);
  color: #e2e8f0;
}

.card-img-count {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(11, 14, 20, 0.75);
  color: #e2e8f0;
}

.card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.35;
}

.style-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.16);
  border: 1px solid rgba(99, 102, 241, 0.35);
  color: #c7d2fe;
  white-space: nowrap;
}

.card-prompt {
  margin: 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: auto;
}

.tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-muted);
}

.card-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 72px 20px;
  background: var(--surface);
  border: 1px dashed var(--border-hover);
  border-radius: var(--radius);
}

.empty-icon {
  font-size: 42px;
  margin-bottom: 10px;
}

.empty-state h3 {
  margin: 0 0 8px;
}

.empty-state p {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 14px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(5, 7, 11, 0.78);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow-y: auto;
}

.modal {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-hover);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.modal-sm { max-width: 420px; }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 1060px; }

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 18px 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span {
  font-size: 12.5px;
  color: var(--text-muted);
}

.field input,
.field textarea,
.field select {
  background: var(--bg);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}

.field input[type="color"] {
  padding: 3px;
  height: 38px;
  cursor: pointer;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--primary);
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.flex-1 { flex: 1; min-width: 180px; }
.flex-2 { flex: 2; min-width: 240px; }

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

kbd {
  background: var(--surface-2);
  border: 1px solid var(--border-hover);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 11px;
}

/* Upload Zone */
.upload-zone {
  border: 1.5px dashed rgba(99, 102, 241, 0.5);
  border-radius: 12px;
  padding: 18px;
  background: rgba(99, 102, 241, 0.06);
  cursor: pointer;
  transition: background 0.16s, border-color 0.16s;
}

.upload-zone:hover,
.upload-zone.dragover {
  background: rgba(99, 102, 241, 0.14);
  border-color: var(--primary-hover);
}

.upload-zone-content {
  display: flex;
  align-items: center;
  gap: 14px;
}

.upload-icon {
  font-size: 28px;
}

.upload-status {
  margin-top: 10px;
  font-size: 12.5px;
  color: #a5b4fc;
}

.uploaded-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
}

.uploaded-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-hover);
  background: var(--bg);
}

.uploaded-item img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}

.uploaded-item-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 6px;
  gap: 4px;
}

.uploaded-item select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 11px;
  padding: 2px 4px;
}

.uploaded-del {
  background: transparent;
  border: none;
  color: #fca5a5;
  cursor: pointer;
  font-size: 13px;
}

/* Detail Modal */
.detail-head-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.prompt-id-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: #a5b4fc;
}

.detail-layout {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 20px;
  padding: 18px 20px;
  overflow-y: auto;
}

.detail-media {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-main-img-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  min-height: 320px;
  display: grid;
  place-items: center;
}

.detail-main-img-wrap img {
  width: 100%;
  max-height: 62vh;
  object-fit: contain;
  display: block;
}

.role-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  background: rgba(11, 14, 20, 0.8);
  border: 1px solid var(--border-hover);
}

.detail-thumbs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.detail-thumb {
  width: 66px;
  height: 66px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.15s, border-color 0.15s;
}

.detail-thumb.active,
.detail-thumb:hover {
  opacity: 1;
  border-color: var(--primary);
}

.detail-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-info {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.info-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.info-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
  color: var(--text-muted);
}

.code-box {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.55;
  max-height: 220px;
  overflow-y: auto;
}

.code-box-sm {
  max-height: 100px;
}

.info-meta-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-item {
  font-size: 13px;
  display: flex;
  gap: 8px;
}

.meta-k {
  color: var(--text-muted);
  white-space: nowrap;
}

.meta-link {
  color: #818cf8;
  text-decoration: none;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.agent-box {
  padding: 12px;
  border-radius: 10px;
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.agent-cmd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: #e0e7ff;
  word-break: break-word;
}

.detail-admin-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* Styles & Skill Modal */
.styles-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  padding: 18px 20px;
  overflow-y: auto;
}

.styles-left,
.styles-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-muted);
}

.style-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.style-row {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.style-row-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.style-row-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 600;
}

.style-row-slug {
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: ui-monospace, monospace;
}

.style-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.style-form {
  padding: 14px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.style-form h4 {
  margin: 0;
  font-size: 14px;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

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

.skill-preview {
  margin: 0;
  flex: 1;
  min-height: 380px;
  max-height: 62vh;
  overflow: auto;
  padding: 14px;
  border-radius: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: #cbd5e1;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-hover);
  color: var(--text);
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.6);
  color: #fecaca;
}

.toast.success {
  border-color: rgba(16, 185, 129, 0.55);
  color: #a7f3d0;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 860px) {
  .detail-layout,
  .styles-layout {
    grid-template-columns: 1fr;
  }
}
