/* ============================================================
   icons+ design system — v0.3.1
   Aligned with modern-web-guidance:
   - color-scheme + light-dark() theming (manual override via
     <meta name="color-scheme"> mapped back through :root:has())
   - native <dialog> modals with @starting-style entry/exit
   - compositor-friendly motion (opacity/translate/scale) with
     prefers-reduced-motion handling
   - rem type scale, text-wrap: balance, no fixed heights
   ============================================================ */

/* ---------- Theme tokens ---------- */
:root {
  color-scheme: light dark;

  --bg-l: #f4f5f7;          --bg-d: #0e1014;
  --surface-l: #ffffff;     --surface-d: #171a20;
  --surface-2-l: #eef0f4;   --surface-2-d: #20242c;
  --text-l: #1a1d23;        --text-d: #e8eaee;
  --muted-l: #5d6470;       --muted-d: #a2abb8;
  --border-l: #e2e5ea;      --border-d: #2b303a;
  --primary-l: #4f46e5;     --primary-d: #7c74ff;
  --primary-hover-l: #4338ca; --primary-hover-d: #8f88ff;
  --primary-2-l: #7c3aed;   --primary-2-d: #a78bfa;
  --ok-l: #15803d;          --ok-d: #4ade80;
  --err-l: #dc2626;         --err-d: #f87171;
  --shadow-l: 0 1px 2px rgb(16 24 40 / 0.05), 0 2px 8px rgb(16 24 40 / 0.06);
  --shadow-d: 0 1px 2px rgb(0 0 0 / 0.5), 0 2px 8px rgb(0 0 0 / 0.35);
  --shadow-pop-l: 0 4px 12px rgb(16 24 40 / 0.08), 0 20px 48px rgb(16 24 40 / 0.18);
  --shadow-pop-d: 0 4px 12px rgb(0 0 0 / 0.45), 0 20px 48px rgb(0 0 0 / 0.6);
  --topbar-h: 60px;
  --radius: 12px;

  /* resolved tokens — fallback path (no light-dark() support) */
  --bg: var(--bg-l);       --surface: var(--surface-l);
  --surface-2: var(--surface-2-l); --text: var(--text-l);
  --muted: var(--muted-l); --border: var(--border-l);
  --primary: var(--primary-l); --primary-hover: var(--primary-hover-l);
  --primary-2: var(--primary-2-l);
  --ok: var(--ok-l);       --err: var(--err-l);
  --shadow: var(--shadow-l); --shadow-pop: var(--shadow-pop-l);
}
/* flat fallback branch (kept out of :root for parser robustness) */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-d);       --surface: var(--surface-d);
    --surface-2: var(--surface-2-d); --text: var(--text-d);
    --muted: var(--muted-d); --border: var(--border-d);
    --primary: var(--primary-d); --primary-hover: var(--primary-hover-d);
    --primary-2: var(--primary-2-d);
    --ok: var(--ok-d);       --err: var(--err-d);
    --shadow: var(--shadow-d); --shadow-pop: var(--shadow-pop-d);
  }
}

/* Modern path: tokens follow color-scheme, which the manual
   <meta name="color-scheme"> override drives through :root:has(). */
@supports (color: light-dark(#fff, #000)) {
  :root {
    --bg: light-dark(var(--bg-l), var(--bg-d));
    --surface: light-dark(var(--surface-l), var(--surface-d));
    --surface-2: light-dark(var(--surface-2-l), var(--surface-2-d));
    --text: light-dark(var(--text-l), var(--text-d));
    --muted: light-dark(var(--muted-l), var(--muted-d));
    --border: light-dark(var(--border-l), var(--border-d));
    --primary: light-dark(var(--primary-l), var(--primary-d));
    --primary-hover: light-dark(var(--primary-hover-l), var(--primary-hover-d));
    --primary-2: light-dark(var(--primary-2-l), var(--primary-2-d));
    --ok: light-dark(var(--ok-l), var(--ok-d));
    --err: light-dark(var(--err-l), var(--err-d));
    --shadow: light-dark(var(--shadow-l), var(--shadow-d));
    --shadow-pop: light-dark(var(--shadow-pop-l), var(--shadow-pop-d));
  }
}

/* Manual override: <meta name="color-scheme"> is the source of truth.
   CSS must not depend on JS — without it, the site follows the system. */
:root:has(> head > meta[name="color-scheme"][content="dark"]) { color-scheme: dark; }
:root:has(> head > meta[name="color-scheme"][content="light"]) { color-scheme: light; }

/* gradient interpolation space (progressive enhancement) */
:root { --in-oklab: ; }
@supports (linear-gradient(in oklab, red, blue)) {
  :root { --in-oklab: in oklab; }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html {
  accent-color: var(--primary);
  scrollbar-width: thin;
}
@supports (color: light-dark(#fff, #000)) {
  html { scrollbar-color: light-dark(#c3c8cf, #3a4048) transparent; }
}
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; }
.muted { color: var(--muted); font-size: 0.8125rem; }
.hidden { display: none !important; }

/* ---------- 底部悬浮栏（版权 / 致谢 / 备案 / 项目主页 / 版本） ---------- */
.site-footer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px 16px;
  flex-wrap: wrap;
  padding: 9px 18px;
  font-size: 0.75rem;
  color: var(--muted);
  background: color-mix(in oklab, var(--surface) 72%, transparent);
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  border-top: 1px solid var(--border);
}
.site-footer a { color: var(--muted); transition: color 0.15s; }
.site-footer a:hover { color: var(--primary); }
.site-footer #ftIcp, .site-footer #ftGongan { display: inline-flex; align-items: center; gap: 4px; }
.beian-icon {
  width: 14px; height: 14px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
/* 页脚高度由 JS 实测写入 --footer-h：内容多时（多行/窄屏）不会盖住底部卡片 */
body.has-footer { padding-bottom: calc(var(--footer-h, 54px) + 10px); }
@media (prefers-reduced-motion: no-preference) {
  .site-footer { animation: footer-in 0.4s ease-out both; }
  @keyframes footer-in {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
}

/* ---------- 危险操作按钮 ---------- */
.btn-danger {
  background: light-dark(#dc2626, #b91c1c);
  border-color: transparent;
  color: #fff;
}
.btn-danger:hover {
  background: light-dark(#b91c1c, #991b1b);
  border-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

::selection { background: color-mix(in oklab, var(--primary) 30%, transparent); }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 20px;
  min-height: var(--topbar-h);
  background: color-mix(in oklab, var(--surface) 82%, transparent);
  backdrop-filter: blur(12px) saturate(1.3);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; flex-shrink: 0; }
.brand-logo { width: 30px; height: 30px; border-radius: 9px; }
.brand-title { font-size: 1.125rem; letter-spacing: 0.2px; text-wrap: balance; }

.search { flex: 1; max-width: 460px; position: relative; display: flex; align-items: center; }
.search-icon {
  position: absolute; left: 13px; width: 18px; height: 18px;
  fill: none; stroke: var(--muted); stroke-width: 2;
  pointer-events: none;
}
.search input {
  width: 100%;
  padding: 9px 96px 9px 39px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 18%, transparent);
}
/* 搜索框内的「标签」筛选入口 */
.search-filter {
  position: absolute; right: 5px; top: 50%; translate: 0 -50%;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: inherit; font-size: 0.75rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.search-filter svg {
  width: 15px; height: 15px;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
}
.search-filter:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.search-filter.is-active {
  color: var(--primary);
  background: color-mix(in oklab, var(--primary) 12%, transparent);
  border-color: color-mix(in oklab, var(--primary) 35%, transparent);
}
.filter-count {
  min-width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 4px; border-radius: 999px;
  background: var(--primary); color: #fff;
  font-size: 0.625rem; font-variant-numeric: tabular-nums;
}

/* 标签筛选浮层 */
.tag-panel {
  position: absolute; top: calc(100% + 10px); left: 0; right: 0; z-index: 40;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-pop);
  max-height: min(56vh, 400px);
  overflow: auto;
}
.tag-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 9px;
  font-size: 0.75rem; font-weight: 600; color: var(--muted);
}
.tag-panel-hint { margin: 9px 0 0; font-size: 0.6875rem; color: var(--muted); }
.link-btn {
  border: 0; background: none; padding: 2px 4px;
  color: var(--primary); font-family: inherit; font-size: 0.75rem;
  cursor: pointer; border-radius: 6px;
}
.link-btn:hover { text-decoration: underline; }

.tag-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit; font-size: 0.75rem; line-height: 1.35;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.tag-chip:hover { border-color: color-mix(in oklab, var(--primary) 45%, var(--border)); }
.tag-chip.selected {
  color: var(--primary);
  border-color: color-mix(in oklab, var(--primary) 55%, var(--border));
  background: color-mix(in oklab, var(--primary) 14%, var(--surface));
  font-weight: 600;
}
.tag-chip.is-static { cursor: default; color: var(--muted); }
.tag-chip.is-static:hover { border-color: var(--border); }
.tag-chip-count {
  font-size: 0.625rem; font-variant-numeric: tabular-nums;
  color: var(--muted); opacity: 0.8;
}
.tag-chip.selected .tag-chip-count { color: var(--primary); opacity: 1; }

/* 已选标签提示条 */
.active-tags { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.active-tags-label { font-size: 0.6875rem; letter-spacing: 0.08em; color: var(--muted); }

/* 预览弹窗里的标签 */
.preview-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }

/* 标签编辑 / 上传选标签 */
.tag-editor { max-height: 220px; overflow: auto; padding: 2px; margin: 2px 0 10px; }
.tag-custom { display: flex; gap: 8px; margin: 4px 0 6px; }
.tag-custom input {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2); color: var(--text);
  font-family: inherit; font-size: 0.8125rem; outline: none;
}
.tag-custom input:focus { border-color: var(--primary); }
.tag-hint { font-size: 0.71875rem; margin: 2px 0 8px; }
.upload-tags-hint { font-size: 0.6875rem; margin: 4px 0 0; }

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 15px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.875rem;
  font-family: inherit;
  line-height: 1.2;
  min-block-size: 36px;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: color-mix(in oklab, var(--primary) 55%, var(--border)); }
.btn:active { box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.12); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn:disabled:hover { border-color: var(--border); }
.cat-move, .tag-move { min-inline-size: 32px; padding: 6px; font-size: 1rem; }
/* 图标管理表格里的标签列：chips 换行 + 编辑按钮 */
.icon-tags-cell { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; max-width: 220px; }
.icon-tags-cell .tag-chip { font-size: 0.625rem; padding: 2px 8px; }
.icon-tags-cell .icon-tag-edit { padding: 2px 9px; font-size: 0.6875rem; min-block-size: 24px; }
/* 窄屏用的短文案（默认隐藏长文案，移动端互换） */
.t-short { display: none; }

.btn-primary {
  background: linear-gradient(to bottom right var(--in-oklab), var(--primary), var(--primary-2));
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow);
}
.btn-primary:hover {
  background: linear-gradient(to bottom right var(--in-oklab), var(--primary-hover), var(--primary-2));
  border-color: transparent;
}
.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-icon { min-inline-size: 38px; padding: 8px; font-size: 1.125rem; }

/* Theme icon follows the resolved color scheme (pure CSS, no JS state) */
.theme-moon { display: none; }
:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-sun { display: none; }
:root:has(> head > meta[name="color-scheme"][content="dark"]) .theme-moon { display: inline; }
@media (prefers-color-scheme: dark) {
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-sun { display: none; }
  :root:not(:has(> head > meta[name="color-scheme"][content="light"])) .theme-moon { display: inline; }
}

/* ---------- Layout ---------- */
.layout { display: flex; }
.sidebar {
  width: 224px; flex-shrink: 0;
  padding: 16px 12px;
  border-right: 1px solid var(--border);
  position: sticky; top: var(--topbar-h);
  align-self: flex-start;
  max-height: calc(100dvh - var(--topbar-h));
  overflow-y: auto;
}
.cat-heading {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 1.4px;
  text-transform: uppercase; color: var(--muted);
  padding: 2px 12px 10px;
}
.cat-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.cat-item {
  width: 100%;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 9px 12px;
  border: 1px solid transparent; border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  text-align: start;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.12s;
}
.cat-item:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.cat-item:active { transform: scale(0.98); }
.cat-item.active {
  background: color-mix(in oklab, var(--primary) 12%, var(--surface));
  color: var(--primary); border-color: color-mix(in oklab, var(--primary) 35%, var(--border));
  font-weight: 600;
}
.cat-item .count {
  font-size: 0.7rem; font-variant-numeric: tabular-nums;
  min-width: 24px; text-align: center;
  padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  transition: background 0.15s, color 0.15s;
}
.cat-item.active .count { background: var(--primary); color: #fff; }

.content { flex: 1; padding: 20px 24px 48px; min-width: 0; }
.content-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.content-head h1 { font-size: 1.25rem; margin: 0; text-wrap: balance; }

/* ---------- Icon grid ---------- */
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}
.card {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 14px 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-family: inherit;
  color: var(--text);
  text-align: center;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
@media (prefers-reduced-motion: no-preference) {
  .card { transition: border-color 0.15s, box-shadow 0.15s, background 0.15s, translate 0.15s ease; }
  .card:hover, .card:focus-visible { translate: 0 -2px; }
}
.card:hover, .card:focus-visible {
  border-color: color-mix(in oklab, var(--primary) 60%, var(--border));
  box-shadow: var(--shadow-pop);
}
.card img {
  width: 52px; height: 52px;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
}
.card .name {
  font-size: 0.6875rem;
  color: var(--text);
  word-break: break-all;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .alias {
  font-size: 0.625rem;
  color: color-mix(in oklab, var(--muted) 80%, transparent);
  line-height: 1.3;
  text-align: center;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-top: -3px;
}
.preview-alias {
  font-size: 0.8125rem;
  color: var(--muted);
  margin: -6px 0 8px;
}

.empty { text-align: center; color: var(--muted); padding: 72px 0; font-size: 0.9375rem; }

/* ---------- Native dialog modals ---------- */
dialog.modal-card {
  width: min(480px, calc(100vw - 40px));
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 16px;
  padding: 22px;
  box-shadow: var(--shadow-pop);
  font-family: inherit;
}
dialog.modal-card h2 { font-size: 1.125rem; margin: 0 0 6px; text-wrap: balance; }

dialog.modal-card[open] {
  opacity: 1; translate: 0 0; scale: 1;
}
dialog.modal-card {
  opacity: 0; translate: 0 12px; scale: 0.98;
  transition:
    opacity 0.22s ease,
    translate 0.22s ease,
    scale 0.22s ease,
    overlay 0.22s ease,
    display 0.22s ease;
  transition-behavior: allow-discrete;
}
@starting-style {
  dialog.modal-card[open] { opacity: 0; translate: 0 12px; scale: 0.98; }
}

dialog.modal-card::backdrop {
  background: rgb(8 10 14 / 0.48);
  backdrop-filter: blur(3px);
  opacity: 0;
  transition:
    opacity 0.22s ease,
    overlay 0.22s ease,
    display 0.22s ease;
  transition-behavior: allow-discrete;
}
dialog.modal-card[open]::backdrop { opacity: 1; }
@starting-style { dialog.modal-card[open]::backdrop { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  dialog.modal-card,
  dialog.modal-card::backdrop { transition-duration: 0.01s; }
}

/* scroll containment (no overflow hacks on body) */
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { overflow: hidden; overscroll-behavior: contain; }

.modal-close {
  position: absolute; top: 12px; right: 14px;
  /* 预览底板用了负 margin 外扩，必须保证关闭按钮永远压在内容层之上、可点击 */
  z-index: 20;
  border: none; background: transparent;
  font-size: 1.5rem; line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }
dialog.modal-card { position: relative; }

/* 预览底板：中心一层极浅灰 + 细网格，向四周自然淡出到全透明，无边框无硬边 */
dialog#previewModal { border: 0; }
.preview-img-wrap {
  --cell: 26px;
  --grid-line: light-dark(rgb(18 24 38 / 0.085), rgb(255 255 255 / 0.075));
  --wash: light-dark(rgb(15 23 42 / 0.07), rgb(255 255 255 / 0.055));
  position: relative;
  display: grid; place-items: center;
  min-height: 272px;
  padding: 40px 24px;
  margin: -8px -8px 10px;
  border: 0;
  background: none;
  isolation: isolate;
}
.preview-img-wrap::before,
.preview-img-wrap::after {
  content: '';
  position: absolute; inset: 0; z-index: 0;
  pointer-events: none;
}
/* 灰色底：径向遮罩，中心实、边缘 100% 透明 */
.preview-img-wrap::before {
  background-color: var(--wash);
  -webkit-mask-image: radial-gradient(ellipse 72% 72% at 50% 50%, #000 0%, rgb(0 0 0 / 0.4) 58%, transparent 100%);
  mask-image: radial-gradient(ellipse 72% 72% at 50% 50%, #000 0%, rgb(0 0 0 / 0.4) 58%, transparent 100%);
}
/* 网格线：同样径向渐隐，越靠外越淡，缩进一点避免贴到弹窗边缘 */
.preview-img-wrap::after {
  inset: 10px;
  background-image:
    linear-gradient(to right, var(--grid-line) 1px, transparent 1px),
    linear-gradient(to bottom, var(--grid-line) 1px, transparent 1px);
  background-size: var(--cell) var(--cell);
  -webkit-mask-image: radial-gradient(ellipse 66% 66% at 50% 50%, #000 0%, rgb(0 0 0 / 0.45) 45%, transparent 100%);
  mask-image: radial-gradient(ellipse 66% 66% at 50% 50%, #000 0%, rgb(0 0 0 / 0.45) 45%, transparent 100%);
}
.preview-img-wrap img {
  position: relative; z-index: 1;
  max-width: 220px; max-height: 220px;
  object-fit: contain;
  filter: drop-shadow(0 10px 22px rgb(15 23 42 / 0.16));
}
.preview-name { font-weight: 600; margin: 0 0 4px; word-break: break-all; }
.preview-url {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  word-break: break-all;
  margin-bottom: 14px;
  background: var(--surface-2);
  padding: 6px 8px;
  border-radius: 8px;
}
.preview-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.form label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 0.8125rem; color: var(--muted);
}
.form input, .form textarea {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 0.875rem;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.form input::placeholder, .form textarea::placeholder { color: var(--muted); opacity: 0.75; }
.form input:focus, .form textarea:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 18%, transparent);
}
.form-hint { font-size: 0.75rem; color: var(--muted); margin: 0; }
.form-hint code { background: var(--surface-2); padding: 2px 5px; border-radius: 5px; word-break: break-all; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; }
.form-msg { font-size: 0.8125rem; min-height: 1.2em; }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--err); }

/* 下拉与文件选择：原生控件默认样式在深色/浅色下都不统一，这里统一成表单风格 */
.form select {
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 34px 9px 11px;
  font-size: 0.875rem;
  background-color: var(--surface-2);
  color: var(--text);
  outline: none;
  font-family: inherit;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b88a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, box-shadow 0.15s;
}
.form select:focus {
  border-color: var(--primary);
  background-color: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 18%, transparent);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 0.8125rem; color: var(--muted); }
.field-optional {
  font-size: 0.7rem; font-weight: 500; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 1px 6px; margin-inline-start: 4px;
}
dialog.modal-card.modal-upload { width: min(560px, calc(100vw - 28px)); }
.upload-sub { font-size: 0.8125rem; line-height: 1.65; margin: 0 0 2px; }
.upload-drop {
  border: 1.5px dashed var(--border);
  border-radius: 14px;
  padding: 24px 18px;
  text-align: center;
  cursor: pointer;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.upload-drop:hover,
.upload-drop.is-over {
  border-color: var(--primary);
  background: color-mix(in oklab, var(--primary) 6%, var(--surface-2));
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 14%, transparent);
}
.upload-drop:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.upload-drop-icon {
  width: 34px; height: 34px;
  fill: none; stroke: var(--primary); stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.upload-drop-title { font-size: 0.875rem; font-weight: 600; color: var(--text); margin: 8px 0 4px; }
.upload-drop-hint { font-size: 0.75rem; color: var(--muted); margin: 0; }
.upload-file-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.upload-file-list:empty { display: none; }
.upload-file-list li {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: 'name size' 'alias alias';
  align-items: center; gap: 6px 10px;
  padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 0.75rem; color: var(--text);
}
.upload-file-list .fname { grid-area: name; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-file-list .fsize { grid-area: size; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.upload-alias-input {
  grid-area: alias; width: 100%;
  border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 8px; font-size: 0.75rem;
  background: var(--surface); color: var(--text);
  font-family: inherit; outline: none;
}
.upload-alias-input::placeholder { color: var(--muted); opacity: 0.75; }
.upload-alias-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--primary) 16%, transparent);
}
.upload-file-list li.is-bad { border-color: color-mix(in oklab, var(--err) 45%, var(--border)); }
.upload-file-list li.is-bad .fsize { color: var(--err); }
.upload-denied { text-align: center; padding: 22px 8px 6px; }
.upload-denied-icon {
  width: 58px; height: 58px; border-radius: 17px;
  margin: 0 auto 14px;
  display: grid; place-items: center;
  color: var(--primary);
  background: color-mix(in oklab, var(--primary) 12%, var(--surface-2));
}
.upload-denied-icon svg {
  width: 30px; height: 30px;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.upload-denied h2 { font-size: 1.125rem; margin: 0 0 6px; }
.upload-denied p { color: var(--muted); font-size: 0.875rem; line-height: 1.7; margin: 0; }
.upload-denied .form-actions { justify-content: center; margin-top: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  translate: -50% 10px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.875rem;
  z-index: 100;
  box-shadow: var(--shadow-pop);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, translate 0.25s ease, visibility 0.25s;
  pointer-events: none;
}
.toast:not(.hidden) { opacity: 1; visibility: visible; translate: -50% 0; }

/* ---------- Account chip ---------- */
.account-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 5px 10px 5px 6px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.8125rem;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.account-chip:hover {
  border-color: color-mix(in oklab, var(--primary) 55%, var(--border));
  box-shadow: var(--shadow);
}
.account-chip.small { padding: 4px 8px 4px 4px; }
.avatar {
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  background-size: cover;
  background-position: center;
  color: #fff;
  font-weight: 700;
  flex: none;
}
.avatar.has-img { color: transparent; }
.account-chip .avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
  color: #fff;
  font-size: 0.75rem; font-weight: 700;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.account-chip .avatar.has-img { color: transparent; }
.avatar.avatar-lg { width: 56px; height: 56px; font-size: 1.15rem; border-radius: 16px; }
.avatar-editor {
  display: flex; align-items: center; gap: 16px;
  margin: 0 0 24px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface-2);
  max-width: 640px;
}
.avatar-editor-body { min-width: 0; }
.avatar-editor-actions { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.avatar-editor .field-hint { margin: 0; }
.account-chip .account-name { font-weight: 600; }

/* ---------- Role badges ---------- */
.role-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.role-badge.role-super { background: #ede9fe; color: #5b21b6; }
.role-badge.role-uploader { background: #dbeafe; color: #1e40af; }
.role-badge.role-viewer { background: #e5e7eb; color: #374151; }
@media (prefers-color-scheme: dark) {
  .role-badge.role-super { background: #372a66; color: #d6c9ff; }
  .role-badge.role-uploader { background: #173250; color: #a9ccff; }
  .role-badge.role-viewer { background: #2c313a; color: #c2c8d0; }
}
/* light-dark() path wins where supported (incl. manual meta override) */
@supports (color: light-dark(#fff, #000)) {
  .role-badge.role-super { background: light-dark(#ede9fe, #372a66); color: light-dark(#5b21b6, #d6c9ff); }
  .role-badge.role-uploader { background: light-dark(#dbeafe, #173250); color: light-dark(#1e40af, #a9ccff); }
  .role-badge.role-viewer { background: light-dark(#e5e7eb, #2c313a); color: light-dark(#374151, #c2c8d0); }
}

/* ---------- Status badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  white-space: nowrap;
}
.badge.pending { background: #fef3c7; color: #92400e; }
.badge.approved { background: #dcfce7; color: #166534; }
.badge.rejected { background: #fee2e2; color: #991b1b; }
.badge.failed { background: #fde2e2; color: #b91c1c; }
.badge.importing { background: #dbeafe; color: #1e40af; }
@media (prefers-color-scheme: dark) {
  .badge.pending { background: #4a3a12; color: #fcd34d; }
  .badge.approved { background: #143a26; color: #6ee7a0; }
  .badge.rejected, .badge.failed { background: #4a1d1d; color: #fca5a5; }
  .badge.importing { background: #173250; color: #a9ccff; }
}
@supports (color: light-dark(#fff, #000)) {
  .badge.pending { background: light-dark(#fef3c7, #4a3a12); color: light-dark(#92400e, #fcd34d); }
  .badge.approved { background: light-dark(#dcfce7, #143a26); color: light-dark(#166534, #6ee7a0); }
  .badge.rejected { background: light-dark(#fee2e2, #4a1d1d); color: light-dark(#991b1b, #fca5a5); }
  .badge.failed { background: light-dark(#fde2e2, #4a1d1d); color: light-dark(#b91c1c, #fca5a5); }
  .badge.importing { background: light-dark(#dbeafe, #173250); color: light-dark(#1e40af, #a9ccff); }
}
@media (prefers-reduced-motion: no-preference) {
  .badge.importing { animation: pulse 1.2s ease-in-out infinite; }
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

/* ---------- Token box ---------- */
.token-box {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.token-box code { flex: 1; font-size: 0.75rem; word-break: break-all; color: var(--text); }

.role-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.8125rem;
  outline: none;
  font-family: inherit;
}
.role-select:focus { border-color: var(--primary); }

/* ---------- Forced colors fallback ---------- */
@media (forced-colors: active) {
  .card, .btn, .account-chip, .token-box, dialog.modal-card { border: 1px solid CanvasText; }
  .btn-primary { border: 1px solid ButtonBorder; }
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  /* 顶栏收紧：只留 logo + 搜索 + 头像 + 上传 */
  .topbar { gap: 8px; padding: 8px 10px; min-height: 54px; }
  .brand-logo { width: 28px; height: 28px; }
  .search { max-width: none; }
  .search input { padding: 8px 46px 8px 34px; font-size: 0.8125rem; }
  .search-icon { left: 11px; width: 16px; height: 16px; }
  .search-filter > span:not(.filter-count) { display: none; }
  .tag-panel { max-height: 62vh; }
  .preview-img-wrap { min-height: 236px; padding: 30px 16px; }
  .preview-img-wrap img { max-width: 180px; max-height: 180px; }
  .brand-title { display: none; }
  /* 权限相关文字（用户名 / 角色）不占位，只保留头像 */
  .account-chip .account-name,
  .account-chip .role-badge { display: none; }
  .account-chip { padding: 3px; gap: 0; }
  .account-chip .avatar { width: 28px; height: 28px; }
  .t-full { display: none; }
  .t-short { display: inline; }
  .content { padding: 16px 14px 24px; }
  .cat-heading { display: none; }

  /* 移动端：分类改为顶部横向滚动条，可切换分类 */
  .layout { flex-direction: column; }
  .sidebar {
    display: block; align-self: stretch;
    width: 100%; position: static; max-height: none;
    padding: 8px 10px; overflow: visible;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar nav { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .cat-list { flex-direction: row; flex-wrap: nowrap; gap: 6px; }
  .cat-item {
    width: auto; flex: none; white-space: nowrap;
    padding: 6px 12px; border-radius: 999px;
    background: var(--surface-2); font-size: 0.8125rem;
  }
  .cat-item.active { background: var(--primary); color: #fff; }
  .cat-item.active .count { background: rgb(255 255 255 / 0.25); color: #fff; }

  /* 移动端：底部信息栏回到文档最底部（不再固定悬浮、不占用常驻空间） */
  body.has-footer { padding-bottom: 0; }
  .site-footer {
    position: static;
    padding: 18px 14px 22px;
    gap: 6px 12px;
    background: var(--surface);
  }
}

/* 手机竖屏：图标固定一行 4 个，卡片同步收紧 */
@media (max-width: 600px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
  .card { padding: 10px 4px 8px; gap: 6px; border-radius: 12px; }
  .card img { width: 42px; height: 42px; }
  .card .name { font-size: 0.625rem; line-height: 1.3; }
  .card .alias { font-size: 0.5625rem; }
  .content-head { gap: 8px; margin-bottom: 12px; }
  .content-head h1 { font-size: 1.0625rem; }
}
