/* ---------- 基础变量 + IE11 fallback ---------- */
:root {
  --bg: #f4f6fb;
  --fg: #1a2233;
  --muted: #6b7a90;
  --card: #ffffff;
  --border: #e3e8f0;
  --accent: #3b6ef6;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --shadow: 0 4px 16px rgba(20, 30, 60, .08);
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: #f4f6fb;
  color: #1a2233;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  transition: background .25s, color .25s;
  padding-bottom: 48px;
}

body.theme-dark {
  background: #0f141d;
  color: #e6edf7;
  --bg: #0f141d;
  --fg: #e6edf7;
  --muted: #8a9bb4;
  --card: #1a2230;
  --border: #273347;
  --accent: #5b8cff;
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* ---------- 头部 ---------- */
.app-header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f4f6fb;
  background: var(--bg);
  border-bottom: 1px solid #e3e8f0;
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
}

.header-inner {
  display: -webkit-box;
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  gap: 12px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 16px;
}

.brand { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; gap: 8px; -webkit-flex: 0 0 auto; flex: 0 0 auto; }
.brand-logo { font-size: 24px; line-height: 1; }
.brand-text { display: -webkit-flex; display: flex; -webkit-flex-direction: column; flex-direction: column; }
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 11px; color: #6b7a90; color: var(--muted); }

.search-wrap { position: relative; -webkit-flex: 1 1 auto; flex: 1 1 auto; min-width: 0; }
.search-icon { position: absolute; left: 12px; top: 50%; -webkit-transform: translateY(-50%); transform: translateY(-50%); color: #6b7a90; color: var(--muted); font-size: 16px; pointer-events: none; }

.search-input {
  width: 100%; height: 40px; padding: 0 36px;
  border: 1px solid #e3e8f0; border: 1px solid var(--border);
  border-radius: 999px; background: #fff; background: var(--card);
  color: inherit; outline: none; font-size: 14px;
  -webkit-appearance: none; appearance: none;
  transition: border-color .2s, box-shadow .2s;
}

.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 110, 246, .15); }

.search-clear {
  position: absolute; right: 8px; top: 50%;
  -webkit-transform: translateY(-50%); transform: translateY(-50%);
  display: none; width: 26px; height: 26px; border: 0; border-radius: 50%;
  background: transparent; color: #6b7a90; color: var(--muted); font-size: 18px; line-height: 1;
}

.search-wrap.has-value .search-clear { display: block; }

.header-actions { display: -webkit-flex; display: flex; gap: 6px; -webkit-flex: 0 0 auto; flex: 0 0 auto; }

.icon-btn {
  width: 38px; height: 38px;
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  -webkit-justify-content: center; justify-content: center;
  border: 1px solid #e3e8f0; border: 1px solid var(--border);
  border-radius: 10px; background: #fff; background: var(--card);
  color: inherit;
  transition: background .2s, border-color .2s, -webkit-transform .15s, transform .15s;
}

.icon-btn:active { -webkit-transform: scale(.94); transform: scale(.94); }
.icon-btn:hover { border-color: var(--accent); }
.ico { font-size: 16px; line-height: 1; }

.lang-wrap { position: relative; }

.lang-menu {
  position: absolute; right: 0; top: 46px; min-width: 132px; padding: 6px;
  border: 1px solid #e3e8f0; border: 1px solid var(--border);
  border-radius: 12px; background: #fff; background: var(--card);
  box-shadow: 0 8px 28px rgba(20, 30, 60, .14);
  display: none;
}

.lang-wrap.open .lang-menu { display: block; }

.lang-item {
  display: -webkit-flex; display: flex;
  -webkit-align-items: center; align-items: center;
  gap: 8px; width: 100%; padding: 8px 10px;
  border: 0; border-radius: 8px; background: transparent;
  color: inherit; text-align: left; font-size: 13px;
}

.lang-item:hover { background: rgba(59, 110, 246, .08); }
.lang-item.active { color: var(--accent); font-weight: 600; }

.cat-nav {
  display: -webkit-flex; display: flex; gap: 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  max-width: 1280px; margin: 0 auto; padding: 0 16px 10px;
  scrollbar-width: none;
}

.cat-nav::-webkit-scrollbar { display: none; }

.cat-btn {
  -webkit-flex: 0 0 auto; flex: 0 0 auto;
  padding: 6px 14px;
  border: 1px solid #e3e8f0; border: 1px solid var(--border);
  border-radius: 999px; background: transparent;
  color: #6b7a90; color: var(--muted);
  font-size: 13px; white-space: nowrap; transition: all .2s;
}

.cat-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- 主区域 ---------- */
.app-main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 32px; }

.grid { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; margin: -8px; }

@supports (display: grid) {
  .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; margin: 0; }
}

.card {
  position: relative;
  display: -webkit-flex; display: flex;
  -webkit-flex-direction: column; flex-direction: column;
  padding: 16px;
  border: 1px solid #e3e8f0; border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff; background: var(--card);
  box-shadow: 0 1px 2px rgba(20, 30, 60, .04);
  -webkit-flex: 0 0 260px; flex: 0 0 260px;
  margin: 8px; min-width: 0;
  transition: box-shadow .2s, border-color .2s, -webkit-transform .2s, transform .2s;
}

@supports (display: grid) {
  .card { margin: 0; -webkit-flex: initial; flex: initial; }
}

.card:hover { border-color: var(--accent); box-shadow: var(--shadow); -webkit-transform: translateY(-2px); transform: translateY(-2px); }

.card-top { display: -webkit-flex; display: flex; -webkit-align-items: center; align-items: center; gap: 10px; margin-bottom: 10px; }

.card-icon {
  width: 36px; height: 36px;
  -webkit-flex: 0 0 36px; flex: 0 0 36px;
  border-radius: 9px; object-fit: contain;
  background: rgba(59, 110, 246, .08);
}

.card-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.card-desc {
  color: #6b7a90; color: var(--muted);
  font-size: 13px; line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 39px;
}

.card-tags { display: -webkit-flex; display: flex; -webkit-flex-wrap: wrap; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.tag {
  padding: 2px 8px; border-radius: 6px;
  background: rgba(59, 110, 246, .08);
  color: #3b6ef6; color: var(--accent);
  font-size: 11px; line-height: 18px;
}

/* 健康状态圆点 */
.health-dot {
  position: absolute; top: 12px; right: 12px;
  width: 9px; height: 9px; border-radius: 50%;
  background: #9aa7b8; box-shadow: 0 0 0 3px rgba(154, 167, 184, .18);
  transition: background .2s, box-shadow .2s;
}

.health-dot.is-good { background: #22c55e; background: var(--green); box-shadow: 0 0 0 3px rgba(34, 197, 94, .18); }
.health-dot.is-ok { background: #f59e0b; background: var(--yellow); box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.health-dot.is-warn { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .18); }
.health-dot.is-timeout { background: #9aa7b8; box-shadow: 0 0 0 3px rgba(154, 167, 184, .18); }
.health-dot.is-error { background: #ef4444; background: var(--red); box-shadow: 0 0 0 3px rgba(239, 68, 68, .18); }

/* 列表版式 */
body.layout-list .grid { display: block; margin: 0; }
body.layout-list .card { -webkit-flex-direction: row; flex-direction: row; -webkit-align-items: center; align-items: center; margin: 0 0 10px; padding: 12px 16px; }
body.layout-list .card-top { margin: 0 12px 0 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }
body.layout-list .card-icon { width: 32px; height: 32px; -webkit-flex-basis: 32px; flex-basis: 32px; }
body.layout-list .card-name { font-size: 14px; }
body.layout-list .card-desc { min-height: 0; -webkit-line-clamp: 1; -webkit-flex: 1 1 auto; flex: 1 1 auto; margin: 0 12px 0 0; }
body.layout-list .card-tags { margin: 0; -webkit-flex: 0 0 auto; flex: 0 0 auto; }

/* 瀑布流版式 */
body.layout-masonry .grid { display: block; margin: 0; -webkit-column-count: 4; column-count: 4; -webkit-column-gap: 16px; column-gap: 16px; }
body.layout-masonry .card { display: inline-block; width: 100%; margin: 0 0 16px; -webkit-column-break-inside: avoid; break-inside: avoid; }

@media (max-width: 1100px) { body.layout-masonry .grid { -webkit-column-count: 3; column-count: 3; } }
@media (max-width: 820px)  { body.layout-masonry .grid { -webkit-column-count: 2; column-count: 2; } }
@media (max-width: 520px)  { body.layout-masonry .grid { -webkit-column-count: 1; column-count: 1; } }

.empty { padding: 64px 16px; text-align: center; color: #6b7a90; color: var(--muted); font-size: 14px; }

.app-footer { max-width: 1280px; margin: 0 auto; padding: 16px; color: #6b7a90; color: var(--muted); font-size: 12px; text-align: center; }
.app-footer .dot { margin: 0 6px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 99;
  -webkit-transform: translate(-50%, 20px); transform: translate(-50%, 20px);
  padding: 8px 16px; border-radius: 999px;
  background: rgba(20, 30, 60, .88); color: #fff; font-size: 13px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, -webkit-transform .25s, transform .25s;
}

.toast.show { opacity: 1; -webkit-transform: translate(-50%, 0); transform: translate(-50%, 0); }

body.loading .grid { opacity: .4; pointer-events: none; }

@media (max-width: 640px) {
  .header-inner { gap: 8px; padding: 8px 12px; }
  .brand-sub { display: none; }
  .brand-name { font-size: 15px; }
  .icon-btn { width: 36px; height: 36px; }
  .cat-nav { padding: 0 12px 8px; }
  .app-main { padding: 14px 12px 24px; }
  body.layout-list .card { -webkit-flex-wrap: wrap; flex-wrap: wrap; }
  body.layout-list .card-desc { -webkit-flex-basis: 100%; flex-basis: 100%; margin: 6px 0 0; }
}