:root {
  --bg: #f7f6f3; --panel: #ffffff; --line: #e7e3db;
  --text: #2b2722; --dim: #8c857a; --accent: #c2671b; --link: #b25c12;
  --shadow: 0 1px 3px rgba(40,32,20,.06), 0 1px 2px rgba(40,32,20,.04);
  --shadow-hover: 0 6px 20px rgba(40,32,20,.12);
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--accent); }

header {
  display: flex; align-items: center; gap: 20px; padding: 12px 20px;
  background: rgba(255,255,255,.85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10;
}
.brand { font-size: 18px; font-weight: 700; color: var(--text); white-space: nowrap; }
.search { display: flex; gap: 8px; flex: 1; max-width: 560px; }
.search input[type=search] {
  flex: 1; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--text); outline: none;
}
.search input[type=search]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194,103,27,.12); }
.search button {
  padding: 8px 16px; border: 0; border-radius: 8px; background: var(--accent);
  color: #fff; font-weight: 600; cursor: pointer;
}
.search button:hover { background: var(--link); }

.sync-btn {
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  color: var(--text); font-weight: 600; cursor: pointer; white-space: nowrap;
}
.sync-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.sync-btn:disabled { opacity: .6; cursor: progress; }
.export { position: relative; }
.export > summary { list-style: none; display: inline-block; }
.export > summary::-webkit-details-marker { display: none; }
.export-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow-hover); padding: 6px; min-width: 150px;
}
.export-head { font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px 4px; }
.export-menu a { display: block; padding: 7px 10px; border-radius: 6px; color: var(--text); font-size: 13px; }
.export-menu a:hover { background: #fbeede; color: var(--accent); }

.sync-status { font-size: 12px; color: var(--dim); white-space: nowrap; }
.sync-status.busy { color: var(--accent); }
.sync-status.done { color: #2e8b57; }
.sync-status.error { color: #c0392b; }
.readonly-badge {
  font-size: 12px; font-weight: 600; color: var(--dim); white-space: nowrap;
  padding: 4px 10px; border: 1px solid var(--line); border-radius: 20px; background: #fff;
}
.bg-price { font-size: 12px; color: var(--dim); white-space: nowrap; }
.bg-price.busy { color: var(--accent); }
.bg-price.done { color: #2e8b57; }
.bg-price.error { color: #c0392b; }

.layout { display: grid; grid-template-columns: 240px 1fr; gap: 20px; padding: 20px; max-width: 1500px; margin: 0 auto; }
.sidebar { font-size: 13px; }
.sidebar h3 { margin: 18px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar li { display: flex; justify-content: space-between; padding: 2px 0; }
.sidebar li span { color: var(--dim); font-size: 11px; }
.sidebar ul.wrap { display: flex; flex-wrap: wrap; gap: 4px; }
.sidebar ul.wrap li { display: inline; }
.chip {
  display: inline-block; margin: 0 4px 6px 0; padding: 3px 9px; border-radius: 20px;
  background: #fbeede; color: var(--link); font-size: 12px; border: 1px solid #f1ddc3;
}
.chip:hover { background: #f7e2c8; }
.chip.clear { background: #fdeaea; color: #c0392b; border-color: #f6d4d4; }

.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.count { color: var(--dim); }
.sortbox { font-size: 12px; color: var(--dim); }
.sortbox a { margin-left: 8px; color: var(--dim); }
.sortbox a.on { color: var(--accent); font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 18px; }
.card { display: flex; flex-direction: column; background: var(--panel); border-radius: 10px; overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); transition: .15s; }
.card:hover { border-color: #ecd9bd; transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.cover { aspect-ratio: 1; background: #f0ede7; position: relative; }
.qty-badge {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 700;
  padding: 2px 8px; border-radius: 20px; box-shadow: 0 1px 4px rgba(40,32,20,.35);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nocover { width: 100%; height: 100%; display: grid; place-items: center; color: var(--dim); font-size: 12px; }
.meta { padding: 8px 10px 10px; }
.meta .t { font-weight: 600; font-size: 13px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.meta .a { color: var(--link); font-size: 12px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta .y { color: var(--dim); font-size: 11px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pager { display: flex; justify-content: center; align-items: center; gap: 18px; margin: 28px 0; color: var(--dim); }
.empty { color: var(--dim); padding: 40px; text-align: center; }

/* detail */
.detail { max-width: 1000px; margin: 0 auto; padding: 24px 20px; }
.back { display: inline-block; margin-bottom: 16px; color: var(--dim); }
.detail-grid { display: grid; grid-template-columns: 360px 1fr; gap: 32px; }
.detail-cover img { width: 100%; border-radius: 12px; box-shadow: var(--shadow-hover); }
.nocover.big { aspect-ratio: 1; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); }
.detail-info h1 { margin: 0 0 4px; font-size: 26px; }
.detail-info h2 { margin: 0 0 18px; font-size: 18px; font-weight: 500; color: var(--link); }
.detail-info table { width: 100%; border-collapse: collapse; }
.detail-info th { text-align: left; width: 80px; padding: 7px 12px 7px 0; color: var(--dim); font-weight: 500; vertical-align: top; }
.detail-info td { padding: 7px 0; border-bottom: 1px solid var(--line); }
.tag { display: inline-block; margin: 0 6px 4px 0; padding: 2px 10px; border-radius: 6px; background: #f3efe8; font-size: 12px; border: 1px solid var(--line); }
.tag:hover { background: #fbeede; }
.catno { color: var(--dim); font-size: 12px; }

.price-block {
  margin: 0 0 20px; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: 12px; background: #fffdf9;
}
.price-main { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.price-range { font-size: 22px; font-weight: 700; color: var(--accent); }
.price-avg { font-size: 14px; color: var(--dim); }
.price-none { color: var(--dim); font-size: 14px; }
.price-sub { margin-top: 6px; font-size: 13px; color: var(--text); }
.price-detail { margin-top: 8px; }
.price-detail summary { cursor: pointer; font-size: 13px; color: var(--link); }
.price-table { margin-top: 6px; border-collapse: collapse; font-size: 13px; }
.price-table td { padding: 3px 16px 3px 0; border: 0; }
.price-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.price-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.price-time { font-size: 12px; color: var(--dim); }
.price-refresh {
  padding: 5px 12px; border: 1px solid var(--line); border-radius: 7px; background: #fff;
  color: var(--text); font-size: 13px; cursor: pointer;
}
.price-refresh:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.price-refresh:disabled { opacity: .6; cursor: progress; }
.price-status { font-size: 12px; color: var(--dim); }
.price-status.ok { color: #2e8b57; }
.price-status.err { color: #c0392b; }

.qty { display: inline-flex; align-items: center; gap: 8px; }
.qty-btn {
  width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: var(--text); font-size: 16px; line-height: 1; cursor: pointer;
}
.qty-btn:hover { border-color: var(--accent); color: var(--accent); }
.qty-input {
  width: 56px; height: 28px; text-align: center; border: 1px solid var(--line);
  border-radius: 7px; background: #fff; color: var(--text); font-size: 14px;
}
.qty-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(194,103,27,.12); }
.qty-saved { font-size: 12px; color: var(--dim); }
.qty-saved.ok { color: #2e8b57; }
.qty-saved.err { color: #c0392b; }
.links { margin-top: 20px; }

/* filter toggle button — hidden on desktop, shown on mobile */
.filter-toggle { display: none; }

@media (max-width: 720px) {
  body { font-size: 15px; }

  /* header wraps: brand + actions on row 1, search full-width on row 2 */
  header { gap: 10px; padding: 10px 14px; flex-wrap: wrap; }
  .brand { font-size: 16px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .search input[type=search], .search button { padding: 10px 14px; }
  .export-menu { min-width: 160px; }

  .layout { grid-template-columns: 1fr; gap: 14px; padding: 14px; }

  /* sidebar collapses into a toggleable panel (albums stay up top) */
  .filter-toggle {
    display: block; width: 100%; padding: 11px 14px; text-align: left;
    border: 1px solid var(--line); border-radius: 10px; background: #fff;
    color: var(--text); font-size: 15px; font-weight: 600; cursor: pointer;
  }
  .sidebar { display: none; }
  .sidebar.open { display: block; padding: 4px 2px 8px; }
  .sidebar li { padding: 6px 0; }          /* roomier tap targets in filter lists */

  /* album grid: adaptive, always ≥2 per row */
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }

  .toolbar { gap: 8px; }
  .sortbox { width: 100%; }                 /* sort options drop to their own line */
  .sortbox a { margin: 0 14px 0 0; display: inline-block; padding: 2px 0; }

  /* bigger touch targets */
  .qty-btn { width: 42px; height: 42px; font-size: 20px; }
  .qty-input { width: 68px; height: 42px; font-size: 16px; }
  .price-refresh { padding: 10px 16px; font-size: 14px; }

  /* detail page */
  .detail { padding: 16px 14px; }
  .detail-grid { grid-template-columns: 1fr; gap: 18px; }
  .detail-cover img { max-width: 380px; margin: 0 auto; display: block; }
  .detail-info h1 { font-size: 22px; }
  .detail-info h2 { font-size: 16px; }
  .price-range { font-size: 20px; }
  .detail-info th { width: 68px; }
}

@media (min-width: 721px) and (max-width: 980px) {
  .layout { grid-template-columns: 200px 1fr; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
