/* 简约主题：默认 白+蓝；data-theme="dark" 时 黑+白 */
:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --radius: 8px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

html[data-theme="dark"] {
  --bg: #111111;
  --surface: #1a1a1a;
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --border: #2a2a2a;
  --accent: #e5e5e5;
  --accent-hover: #ffffff;
  --accent-soft: #262626;
  --danger: #ef4444;
  --danger-hover: #f87171;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.brand p {
  margin: 2px 0 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hint {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Buttons */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.875rem;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.3;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

html[data-theme="dark"] .btn-primary {
  color: #111;
}

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

html[data-theme="dark"] .btn-primary:hover {
  color: #111;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  color: #fff;
}

.btn-ghost {
  background: transparent;
}

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

/* Login */
.login-wrap {
  max-width: 420px;
  margin: 12vh auto;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-wrap h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  font-weight: 600;
}

.login-wrap p {
  color: var(--text-muted);
  margin: 0 0 20px;
  font-size: 0.9rem;
}

.login-wrap img {
  margin: 0 auto;
}

/* Layout */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 20px;
  align-items: start;
}

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

/* Sidebar */
.sidebar {
  position: sticky;
  top: 64px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
}

.sidebar h3 {
  margin: 6px 10px 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.nav-cat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-cat button {
  text-align: left;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
}

.nav-cat button:hover {
  background: var(--accent-soft);
}

.nav-cat button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

html[data-theme="dark"] .nav-cat button.active {
  color: var(--text);
}

/* Main */
.main-panel {
  min-width: 0;
}

.toolbar {
  margin-bottom: 14px;
}

.search-box {
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
  outline: none;
}

.search-box input:focus {
  border-color: var(--accent);
}

.panel-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-title .badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  min-height: 170px;
}

.item-card:hover {
  border-color: var(--accent);
}

.item-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.item-card .thumb {
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  background: var(--bg);
}

.item-card .thumb img {
  max-height: 84px;
  object-fit: contain;
}

.item-card .thumb .placeholder {
  width: 56px;
  height: 56px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.7rem;
  background: var(--surface);
}

.item-card .meta {
  padding: 10px;
  border-top: 1px solid var(--border);
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-card .meta .name {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-card .meta .sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.item-card .meta .actions {
  margin-top: auto;
  padding-top: 6px;
  display: flex;
  gap: 6px;
}

.item-card .meta .actions .btn {
  flex: 1;
  padding: 5px 6px;
  font-size: 0.75rem;
}

.tag-t,
.tag-ct {
  color: var(--text-muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

html[data-theme="dark"] .modal-backdrop {
  background: rgba(0, 0, 0, 0.65);
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  width: min(900px, 100%);
  max-height: min(90vh, 880px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.modal-body {
  padding: 14px 16px;
  overflow: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-preview {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
}

.modal-preview img {
  width: 110px;
  height: 72px;
  object-fit: contain;
}

.modal-preview .info .title {
  font-weight: 600;
  margin-bottom: 2px;
}

.modal-preview .info .desc {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

@media (max-width: 600px) {
  .settings-row {
    grid-template-columns: 1fr;
  }
}

.field label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.field input,
.field select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
}

.skin-option {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 8px;
  cursor: pointer;
  text-align: center;
}

.skin-option:hover {
  border-color: var(--accent);
}

.skin-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.skin-option img {
  height: 56px;
  margin: 0 auto 6px;
  object-fit: contain;
}

.skin-option .label {
  font-size: 0.7rem;
  line-height: 1.3;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Toast */
.toast-wrap {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 180px;
  max-width: 320px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.875rem;
}

.toast.ok {
  border-color: var(--accent);
}

.toast.err {
  border-color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.footer {
  max-width: 1200px;
  margin: 8px auto 24px;
  padding: 0 20px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.footer a {
  color: var(--text-muted);
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.35);
  z-index: 150;
  display: none;
  align-items: center;
  justify-content: center;
}

html[data-theme="dark"] .loading-overlay {
  background: rgba(0, 0, 0, 0.35);
}

.loading-overlay.show {
  display: flex;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.agent-side-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.agent-side-tabs button {
  flex: 1;
}

.agent-side-tabs button.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* 组合码 */
.code-hint {
  margin: 0 0 10px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.code-box {
  width: 100%;
  min-height: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.4;
  resize: vertical;
  box-sizing: border-box;
}

.code-box:focus {
  outline: none;
  border-color: var(--accent);
}

img.img-fail {
  opacity: 0.2;
}

.panel-cache {
  min-height: 40px;
}

/* display:grid/flex 会盖掉浏览器默认的 [hidden]{display:none}，必须显式写 */
.panel-cache[hidden],
.cards-grid[hidden],
.item-card[hidden],
.skin-option[hidden],
.empty-state-filter[hidden] {
  display: none !important;
}

.skins-picker-cache {
  display: contents;
}

/* skins-picker 内直接子项；cache 用 display:contents 让子元素参与 grid */
.skins-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}
