:root {
  --bg: #f4f7fc;
  --card: #ffffff;
  --primary: #1677ff;
  --primary-dark: #0b5fd6;
  --primary-soft: #eaf2ff;
  --text: #1d2330;
  --text-2: #4b5565;
  --muted: #8a93a4;
  --border: #e5ebf4;
  --shadow: 0 10px 30px rgba(23, 52, 102, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Hiragino Sans GB', 'Microsoft YaHei', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
}

.wrap {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px;
}

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

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

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

.brand-logo {
  display: block;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 6px 14px rgba(10, 10, 10, 0.18);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-text strong {
  font-size: 16px;
  letter-spacing: 0.2px;
}

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

.admin-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  background: #fff;
  font-size: 13px;
  transition: all 0.18s ease;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.admin-link svg {
  width: 15px;
  height: 15px;
}

.admin-link:hover {
  color: var(--primary);
  border-color: #b9d4ff;
  background: var(--primary-soft);
}

/* 首屏 */
.hero {
  position: relative;
  overflow: hidden;
  padding: 46px 0 54px;
  background:
    radial-gradient(680px 260px at 12% -10%, rgba(22, 119, 255, 0.16), transparent 62%),
    radial-gradient(520px 240px at 92% 0%, rgba(89, 167, 255, 0.18), transparent 60%),
    linear-gradient(180deg, #f7faff 0%, #f4f7fc 100%);
  border-bottom: 1px solid var(--border);
}

.hero h1 {
  margin: 0 0 8px;
  font-size: 30px;
  line-height: 1.3;
  letter-spacing: 0.4px;
}

.hero p {
  margin: 0 0 24px;
  color: var(--text-2);
  font-size: 14px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 620px;
  padding: 7px 7px 7px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}

.search-icon {
  flex: none;
  width: 19px;
  height: 19px;
  color: var(--muted);
}

.search-box input {
  flex: 1;
  min-width: 0;
  padding: 8px 0;
  border: 0;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  background: transparent;
}

.search-box input::-webkit-search-cancel-button {
  cursor: pointer;
}

.search-box button {
  flex: none;
  padding: 9px 22px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--primary);
  font-size: 14px;
  transition: background 0.18s ease;
}

.search-box button:hover {
  background: var(--primary-dark);
}

/* 主体布局 */
.layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
  padding-top: 24px;
  padding-bottom: 48px;
}

.sidebar {
  position: sticky;
  top: 84px;
  padding: 16px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 6px 18px rgba(23, 52, 102, 0.05);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
}

.link-btn {
  padding: 0;
  border: 0;
  color: var(--muted);
  background: none;
  font-size: 12px;
}

.link-btn:hover {
  color: var(--primary);
}

.cat-tree {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
  padding: 8px 0 2px;
}

.cat-loading {
  padding: 14px 10px;
  color: var(--muted);
  font-size: 13px;
}

.cat-item {
  margin: 1px 0;
}

.cat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: 9px;
  color: var(--text-2);
  transition: background 0.15s ease, color 0.15s ease;
}

.cat-row:hover {
  background: #f4f7fd;
  color: var(--text);
}

.cat-row.active {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 600;
}

.cat-caret {
  display: grid;
  place-items: center;
  flex: none;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 5px;
  color: var(--muted);
  background: transparent;
  transition: transform 0.16s ease;
}

.cat-caret svg {
  width: 13px;
  height: 13px;
}

.cat-caret.open {
  transform: rotate(90deg);
}

.cat-caret.placeholder {
  visibility: hidden;
}

.cat-name {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  color: inherit;
  font-size: 13.5px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0;
}

.cat-count {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.cat-children {
  margin: 0;
  padding: 0;
  list-style: none;
}

.cat-children[hidden] {
  display: none;
}

/* 列表区 */
.content {
  min-width: 0;
}

.result-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.current-path {
  font-size: 16px;
  font-weight: 600;
}

/* 分类说明（来自后台分类的「说明」字段） */
.category-desc {
  margin-top: 6px;
  padding: 7px 11px;
  border-left: 3px solid #b9d4ff;
  border-radius: 0 8px 8px 0;
  background: rgba(22, 119, 255, 0.05);
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.category-desc[hidden] {
  display: none;
}

.result-count {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12.5px;
}

.download-hint {
  color: var(--muted);
  font-size: 12.5px;
}

.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 16px;
}

.app-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 4px 14px rgba(23, 52, 102, 0.04);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.app-card:hover {
  transform: translateY(-2px);
  border-color: #cfe0fa;
  box-shadow: 0 14px 30px rgba(23, 52, 102, 0.1);
}

.app-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* 有历史版本时给右上角链接让出空间 */
.app-card.has-history .app-head {
  padding-right: 92px;
}

.history-link {
  position: absolute;
  top: 14px;
  right: 14px;
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-2);
  background: #fff;
  font-size: 11.5px;
  line-height: 18px;
  white-space: nowrap;
  transition: color 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.history-link:hover {
  color: var(--primary);
  border-color: #b9d4ff;
  background: var(--primary-soft);
}

.app-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  color: #fff;
  font-size: 19px;
  font-weight: 700;
  background: linear-gradient(135deg, hsl(var(--h, 214) 90% 62%), hsl(var(--h, 214) 82% 46%));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

/* 分类配置了 Logo 时用图片展示 */
.app-icon-logo {
  padding: 4px;
  overflow: hidden;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--border);
}

.app-icon-logo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.app-title {
  min-width: 0;
  flex: 1;
}

.app-title h3 {
  margin: 0 0 4px;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 18px;
}

.tag-version {
  color: var(--primary);
  background: var(--primary-soft);
  font-weight: 600;
}

.tag-category {
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  background: #f2f5fa;
}

.app-desc {
  /* 内容少时也占住三行高度，保证同排卡片各区块对齐 */
  min-height: 78px;
  margin: 12px 0 0;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.65;
  word-break: break-word;
}

/* 默认折叠三行，展开后完整显示 */
.app-desc .md-body {
  height: 78px;
  overflow: hidden;
}

.app-desc.expanded .md-body {
  height: auto;
}

/* Markdown 内容排版 */
.md-body > :first-child {
  margin-top: 0;
}

.md-body > :last-child {
  margin-bottom: 0;
}

.md-body p {
  margin: 0 0 6px;
}

.md-body h4,
.md-body h5,
.md-body h6 {
  margin: 10px 0 6px;
  color: inherit;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.5;
}

.md-body ul,
.md-body ol {
  margin: 0 0 6px;
  padding-left: 18px;
}

.md-body li {
  margin: 2px 0;
}

.md-body strong {
  font-weight: 600;
}

.md-body code {
  padding: 1px 5px;
  border-radius: 5px;
  background: #eef2f8;
  font-family: ui-monospace, SFMono-Regular, Consolas, 'Courier New', monospace;
  font-size: 12px;
}

.md-body pre {
  margin: 0 0 8px;
  padding: 10px 12px;
  overflow: auto;
  border-radius: 9px;
  background: #0f1726;
  color: #d7e3f4;
  font-size: 12px;
  line-height: 1.6;
}

.md-body pre code {
  padding: 0;
  background: none;
  color: inherit;
}

.md-body blockquote {
  margin: 0 0 6px;
  padding: 1px 10px;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

.md-body a {
  color: var(--primary);
  text-decoration: underline;
}

.md-body hr {
  margin: 10px 0;
  border: 0;
  border-top: 1px dashed var(--border);
}

.app-desc-empty {
  color: var(--muted);
  font-size: 13px;
}

.desc-toggle {
  margin-top: 2px;
  padding: 0;
  border: 0;
  color: var(--primary);
  background: none;
  font-size: 12px;
}

/* 内容未溢出时按钮不可见但仍占位，保证各卡片高度一致 */
.desc-toggle[hidden] {
  display: block;
  visibility: hidden;
}

.meta {
  display: flex;
  gap: 18px;
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.meta div {
  min-width: 0;
}

.meta dt {
  color: var(--muted);
  font-size: 11.5px;
}

.meta dd {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.md5-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 7px 9px;
  border-radius: 9px;
  background: #f7f9fd;
}

.md5-label {
  flex: none;
  color: var(--muted);
  font-size: 11.5px;
}

.md5-row code {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-family: ui-monospace, SFMono-Regular, Consolas, Menlo, monospace;
  font-size: 11.5px;
}

.copy-btn {
  flex: none;
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  background: #fff;
  font-size: 11.5px;
}

.copy-btn:hover {
  color: var(--primary);
  border-color: #b9d4ff;
}

.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  flex: 1;
  min-width: 0;
  padding: 10px 14px;
  border: 0;
  border-radius: 11px;
  color: #fff;
  background: linear-gradient(135deg, #3b8dff, #1677ff);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 6px 14px rgba(22, 119, 255, 0.25);
  transition: filter 0.18s ease, opacity 0.18s ease;
}

.download-btn svg {
  width: 16px;
  height: 16px;
}

.download-btn:hover {
  filter: brightness(1.05);
}

.download-btn:disabled {
  cursor: not-allowed;
  opacity: 0.62;
  box-shadow: none;
}

/* 次要按钮：复制下载链接 */
.copy-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: none;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 11px;
  color: var(--text-2);
  background: #fff;
  font-size: 13px;
  white-space: nowrap;
  transition: color 0.18s ease, border-color 0.18s ease;
}

.copy-link-btn svg {
  width: 15px;
  height: 15px;
}

.copy-link-btn:hover {
  color: var(--primary);
  border-color: #b9d4ff;
}

.progress-wrap {
  margin-top: 10px;
}

.progress-track {
  height: 7px;
  border-radius: 999px;
  background: #e9eef7;
  overflow: hidden;
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #4b9bff, #1677ff);
  transition: width 0.15s linear;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  margin-top: 5px;
  color: var(--muted);
  font-size: 11.5px;
}

.progress-wrap[hidden] {
  display: none;
}

/* 历史版本弹窗 */
body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal[hidden] {
  display: none;
}

.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 38, 0.45);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 560px;
  max-height: min(82vh, 640px);
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 0 24px 60px rgba(15, 23, 38, 0.28);
  animation: modal-in 0.18s ease;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.4;
  word-break: break-word;
}

.modal-sub {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.modal-close {
  flex: none;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  background: #f4f7fd;
  font-size: 18px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
  background: #eaf0f9;
}

.modal-body {
  padding: 8px 12px 14px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 10px;
  border: 0;
  border-radius: 10px;
  background: none;
  text-align: left;
}

.history-item:hover {
  background: var(--primary-soft);
}

.hv-version {
  flex: none;
  padding: 1px 8px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 600;
}

.history-item:hover .hv-version {
  background: #fff;
}

.hv-meta {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hv-dl {
  flex: none;
  color: var(--primary);
  font-size: 12.5px;
}

.history-empty,
.history-loading {
  padding: 30px 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* 空状态 / 骨架屏 / 分页 */
.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 60px 20px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
}

/* display 已改为 flex/grid，需要显式让 hidden 生效 */
.empty[hidden],
.pager[hidden] {
  display: none;
}

.empty svg {
  width: 44px;
  height: 44px;
  color: #c3cbd9;
}

.empty p {
  margin: 6px 0 10px;
  font-size: 14px;
}

.ghost-btn {
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-2);
  background: #fff;
  font-size: 13px;
}

.ghost-btn:hover {
  color: var(--primary);
  border-color: #b9d4ff;
}

.skeleton-card {
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}

.sk {
  border-radius: 8px;
  background: linear-gradient(90deg, #eef2f8 25%, #f7f9fd 37%, #eef2f8 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease infinite;
}

.sk-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.sk-icon {
  width: 46px;
  height: 46px;
  border-radius: 13px;
}

.sk-title {
  width: 60%;
  height: 15px;
}

.sk-sub {
  width: 40%;
  height: 12px;
  margin-top: 8px;
}

.sk-line {
  width: 100%;
  height: 11px;
  margin-top: 12px;
}

.sk-line.short {
  width: 62%;
}

.sk-btn {
  height: 38px;
  margin-top: 16px;
  border-radius: 11px;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 24px;
}

.pager button {
  padding: 7px 15px;
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text-2);
  background: #fff;
  font-size: 13px;
}

.pager button:hover:not(:disabled) {
  color: var(--primary);
  border-color: #b9d4ff;
}

.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

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

/* 页脚与提示 */
.footer {
  padding: 22px 0 30px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 36px;
  z-index: 90;
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 10px 20px;
  border-radius: 10px;
  color: #fff;
  background: rgba(29, 35, 48, 0.9);
  box-shadow: 0 10px 26px rgba(20, 30, 50, 0.22);
  font-size: 13px;
  animation: toast-in 0.2s ease;
}

.toast[hidden] {
  display: none;
}

.toast.error {
  background: rgba(200, 45, 45, 0.94);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .cat-tree {
    max-height: 260px;
  }

  .hero {
    padding: 34px 0 40px;
  }

  .hero h1 {
    font-size: 24px;
  }

  .download-hint {
    display: none;
  }
}

@media (max-width: 560px) {
  .wrap {
    padding: 0 14px;
  }

  .brand-text small {
    display: none;
  }

  .admin-link {
    padding: 6px 10px;
    font-size: 12px;
  }

  .app-grid {
    grid-template-columns: 1fr;
  }

  .meta {
    gap: 14px;
  }
}
