:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f1f3f6;
  --text: #1f2329;
  --text-secondary: #646a73;
  --text-muted: #8f959e;
  --border: #e5e7eb;
  --xhs-red: #ff2442;
  --xhs-red-soft: #fff0f2;
  --quark-blue: #0066ff;
  --quark-blue-soft: #eef4ff;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 28px rgba(15, 23, 42, 0.09);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, 0.22);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 14px 24px 10px;
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 220px;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--xhs-red), #ff6b81);
  box-shadow: 0 0 0 4px var(--xhs-red-soft);
  flex-shrink: 0;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-secondary);
}

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

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 40px;
  padding: 0 16px 0 40px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: var(--surface-muted);
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: all 0.2s ease;
}

#search-input:focus {
  background: var(--surface);
  border-color: var(--xhs-red);
  box-shadow: 0 0 0 3px var(--xhs-red-soft);
}

.controls-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.segmented {
  display: inline-flex;
  background: var(--surface-muted);
  padding: 3px;
  border-radius: var(--radius-pill);
}

.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.sort-select {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  outline: none;
}

/* Tag bar */
.tag-bar-wrap {
  max-width: 1480px;
  margin: 0 auto;
  padding: 6px 24px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tag-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.tag-bar::-webkit-scrollbar {
  display: none;
}

.tag-chip {
  border: 1px solid transparent;
  background: var(--surface-muted);
  color: var(--text-secondary);
  padding: 5px 13px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tag-chip:hover {
  background: #e8eaef;
  color: var(--text);
}

.tag-chip.active {
  background: var(--xhs-red-soft);
  color: var(--xhs-red);
  border-color: rgba(255, 36, 66, 0.25);
  font-weight: 600;
}

.stats-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Container & Notice */
.container {
  max-width: 1480px;
  margin: 0 auto;
  padding: 20px 24px 60px;
}

.notice-bar {
  margin-bottom: 18px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
}

/* Masonry Waterfall */
.masonry {
  column-count: 5;
  column-gap: 18px;
}

@media (max-width: 1360px) {
  .masonry {
    column-count: 4;
  }
}

@media (max-width: 1040px) {
  .masonry {
    column-count: 3;
  }
}

@media (max-width: 720px) {
  .masonry {
    column-count: 2;
    column-gap: 12px;
  }

  .topbar-inner,
  .tag-bar-wrap,
  .container {
    padding-left: 14px;
    padding-right: 14px;
  }
}

.card {
  break-inside: avoid;
  margin-bottom: 18px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

@media (max-width: 720px) {
  .card {
    margin-bottom: 12px;
    border-radius: 12px;
  }
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.card-cover {
  position: relative;
  background: var(--surface-muted);
  overflow: hidden;
}

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

.card:hover .card-cover img {
  transform: scale(1.02);
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(8px);
}

.badge-quark {
  background: rgba(0, 102, 255, 0.9);
  color: #ffffff;
}

.badge-count {
  margin-left: auto;
  background: rgba(17, 24, 39, 0.65);
  color: #ffffff;
}

/* Doc-only stylized cover */
.doc-cover {
  padding: 26px 18px 20px;
  background: linear-gradient(145deg, #eef4ff 0%, #f8fafc 100%);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-cover-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--quark-blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.doc-cover-files {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.doc-cover-file {
  font-size: 12px;
  color: #1e3a8a;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid #dbeafe;
  padding: 6px 10px;
  border-radius: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-body {
  padding: 12px 14px 14px;
}

.card-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.45;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 10px;
}

.card-tag {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--surface-muted);
  padding: 2px 8px;
  border-radius: 6px;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  gap: 8px;
}

.quick-copy-btn {
  border: none;
  background: var(--quark-blue-soft);
  color: var(--quark-blue);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: background 0.15s ease;
}

.quick-copy-btn:hover {
  background: #dbeafe;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 72px 20px;
  color: var(--text-secondary);
}

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

.btn-primary {
  margin-top: 12px;
  border: none;
  background: var(--xhs-red);
  color: #ffffff;
  padding: 9px 20px;
  border-radius: var(--radius-pill);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Detail Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(4px);
}

.modal-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 1040px;
  max-height: 88vh;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-columns: 1.25fr 1fr;
  overflow: hidden;
}

.modal-card.no-media {
  grid-template-columns: 1fr;
  max-width: 620px;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background: #ffffff;
}

.modal-media {
  background: #f6f7f9;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: 88vh;
}

.carousel-stage {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 16px;
}

.carousel-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  cursor: zoom-in;
}

.carousel-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.32);
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-nav:hover {
  background: rgba(15, 23, 42, 0.55);
}

.carousel-nav.prev {
  left: 14px;
}

.carousel-nav.next {
  right: 14px;
}

.img-counter {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: #ffffff;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
}

.zoom-btn {
  position: absolute;
  bottom: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #ffffff;
  cursor: pointer;
  font-size: 15px;
}

.thumb-strip {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: #ffffff;
  border-top: 1px solid var(--border);
  overflow-x: auto;
}

.thumb-item {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  opacity: 0.55;
  cursor: pointer;
  border: 2px solid transparent;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.thumb-item.active {
  opacity: 1;
  border-color: var(--xhs-red);
}

.modal-body {
  padding: 26px 26px 28px;
  overflow-y: auto;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-meta-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 36px;
}

.modal-date {
  font-size: 12px;
  color: var(--text-muted);
}

.source-link {
  font-size: 12px;
  color: var(--xhs-red);
  text-decoration: none;
  font-weight: 500;
}

.source-link:hover {
  text-decoration: underline;
}

.modal-title {
  margin: 0;
  font-size: 20px;
  line-height: 1.4;
  font-weight: 700;
}

.modal-desc {
  margin: 0;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-tag {
  border: none;
  background: var(--surface-muted);
  color: var(--text-secondary);
  padding: 5px 11px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  cursor: pointer;
}

.modal-tag:hover {
  background: var(--xhs-red-soft);
  color: var(--xhs-red);
}

/* Quark Section */
.quark-section {
  margin-top: 6px;
  padding: 16px;
  border-radius: 14px;
  background: #f5f8ff;
  border: 1px solid #dbeafe;
}

.quark-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #1e3a8a;
  margin-bottom: 12px;
}

.quark-logo {
  background: var(--quark-blue);
  color: #ffffff;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
}

.quark-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quark-item {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quark-item-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  word-break: break-all;
}

.quark-item-url {
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
}

.quark-item-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.quark-code {
  font-size: 12px;
  background: #f1f5f9;
  color: #334155;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.btn-quark-copy {
  border: none;
  background: var(--quark-blue);
  color: #ffffff;
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.btn-quark-copy:hover {
  background: #0052cc;
}

.btn-quark-open {
  font-size: 12px;
  font-weight: 600;
  color: var(--quark-blue);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--quark-blue-soft);
}

.btn-quark-open:hover {
  background: #dbeafe;
}

@media (max-width: 860px) {
  .modal {
    padding: 10px;
  }

  .modal-card {
    grid-template-columns: 1fr;
    max-height: 92vh;
    overflow-y: auto;
  }

  .modal-media {
    min-height: 260px;
    max-height: 52vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .modal-body {
    max-height: none;
    overflow-y: visible;
    padding: 18px 16px 24px;
  }
}

@media (max-width: 720px) {
  .topbar-inner {
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 8px;
  }

  .search-wrap {
    flex: 1 1 100%;
    max-width: none;
  }

  .controls-right {
    width: 100%;
    margin-left: 0;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
  }

  .seg-btn {
    padding: 5px 10px;
    font-size: 12px;
  }

  .quota-pill,
  .user-badge,
  .auth-btn {
    font-size: 12px;
    padding: 5px 10px;
  }

  #search-input,
  .field input,
  .admin-create-form input {
    font-size: 16px;
  }
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lightbox img {
  max-width: 96vw;
  max-height: 92vh;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 18px;
  right: 22px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(17, 24, 39, 0.9);
  color: #ffffff;
  padding: 10px 18px;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: all 0.22s ease;
  z-index: 300;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Auth & Quota Controls */
.quota-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--quark-blue);
  background: var(--quark-blue-soft);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.user-menu {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-muted);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.auth-btn {
  border: none;
  background: var(--text);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
}

.auth-btn:hover {
  opacity: 0.9;
}

.auth-btn.secondary {
  background: var(--surface-muted);
  color: var(--text-secondary);
}

.auth-btn.admin-btn {
  background: var(--xhs-red);
}

/* Dialog Cards (Login & Admin) */
.dialog-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 28px 26px 26px;
}

.dialog-card.dialog-wide {
  max-width: 720px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}

.dialog-title {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 700;
}

.dialog-subtitle {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.field input,
.admin-create-form input {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 14px;
  outline: none;
}

.field input:focus,
.admin-create-form input:focus {
  border-color: var(--quark-blue);
}

.full-width {
  width: 100%;
  margin-top: 4px;
}

.form-error {
  font-size: 13px;
  color: var(--xhs-red);
  background: var(--xhs-red-soft);
  padding: 8px 12px;
  border-radius: 8px;
}

/* Quark Locked Preview */
.quark-locked-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.quark-locked-names {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.quark-locked-name {
  font-size: 13px;
  color: var(--text);
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 8px 10px;
  border-radius: 8px;
}

.btn-claim-quark {
  border: none;
  background: var(--quark-blue);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}

.btn-claim-quark:hover {
  background: #0052cc;
}

.btn-claim-quark:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Admin User Management */
.admin-create-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  margin-bottom: 12px;
}

.admin-create-form .btn-primary {
  margin-top: 0;
  height: 40px;
  padding: 0 16px;
  border-radius: 10px;
}

@media (max-width: 680px) {
  .admin-create-form {
    grid-template-columns: 1fr;
  }
}

.admin-user-list {
  margin-top: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 48vh;
}

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

.admin-user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.admin-user-name {
  font-size: 14px;
  font-weight: 700;
}

.admin-user-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.admin-user-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-btn {
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.mini-btn:hover {
  background: var(--surface-muted);
}

.mini-btn.danger {
  color: var(--xhs-red);
  border-color: rgba(255, 36, 66, 0.25);
}