:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --ink: #1d1c1a;
  --muted: #6f6b64;
  --line: #e4e1da;
  --accent: #8a1c2b;
  --chip: #f0eee9;
  --yellow-gold: #d6b25e;
  --pink-gold: #e3a593;
  --white-gold: #cfd3d6;
  --platinum: #b9bec4;
  --other-metal: #8f8a82;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); }
.muted { color: var(--muted); }

/* header */
.top {
  position: sticky; top: 0; z-index: 3;
  display: flex; align-items: center; gap: 16px;
  height: 48px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brandmark { flex: 1; font-weight: 700; letter-spacing: .02em; }
.user { color: var(--muted); white-space: nowrap; }

/* filters */
.filters {
  position: sticky; top: 48px; z-index: 2;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 20px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.filters select, .search-row input {
  height: 32px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink); font: inherit;
}
.search-row { padding: 16px 20px 0; }
.search-row input { width: min(420px, 100%); height: 36px; padding: 0 12px; }
.filters select { max-width: 200px; }
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.view-toggle button { border: 0; background: var(--surface); padding: 0 12px; height: 32px; font: inherit; cursor: pointer; }
.view-toggle button.active { background: var(--ink); color: #fff; }
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; }

/* results */
.results { padding: 16px 20px 40px; display: grid; gap: 14px; }
.results.models { grid-template-columns: minmax(0, 1fr); }
.results.refs { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.empty { color: var(--muted); padding: 40px; text-align: center; }

.model {
  min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px;
}
.model-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; margin-bottom: 10px; }
.code {
  font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--ink); color: #fff; padding: 4px 7px; border-radius: 5px;
}
.model-name { font-weight: 600; font-size: 15px; }
.model-meta { color: var(--muted); }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--chip); color: var(--muted); }
.badge.hj { background: #f4e6e8; color: var(--accent); }
/* Wrap rather than scroll: every variant of a model in view at once. */
.variants { display: flex; flex-wrap: wrap; gap: 10px; }

.ref {
  flex: 0 0 150px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  transition: border-color .15s, box-shadow .15s;
}
.results.refs .ref { flex: initial; }
.ref:hover, .ref:focus-visible { border-color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.08); outline: none; }
.ref .pic { aspect-ratio: 1; background: #fff; display: grid; place-items: center; }
.ref img { width: 100%; height: 100%; object-fit: contain; }
.ref .nopic { color: var(--muted); font-size: 12px; }

/* Discarded: still shown, never a match target. */
.ref.discarded .pic { position: relative; }
.ref.discarded img { opacity: .35; filter: grayscale(1); }
.ref.discarded .pic::before, .ref.discarded .pic::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  width: 120%; height: 4px; background: var(--accent); border-radius: 2px;
}
.ref.discarded .pic::before { transform: translate(-50%, -50%) rotate(45deg); }
.ref.discarded .pic::after { transform: translate(-50%, -50%) rotate(-45deg); }
.ref.discarded .pic { overflow: hidden; }
.ref.discarded .refcode { text-decoration: line-through; color: var(--muted); }
.discard-note { color: var(--accent); font-size: 11px; font-weight: 600; }
.ref .info { padding: 6px 8px 8px; border-top: 1px solid var(--line); }
.ref .refcode { font: 600 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.ref .name { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ref .line2 { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; align-items: center; }

.size { font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--chip); }
.metal { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.metal::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--other-metal); border: 1px solid rgba(0,0,0,.15); }
.metal.yellow-gold::before { background: var(--yellow-gold); }
.metal.pink-gold::before { background: var(--pink-gold); }
.metal.white-gold::before { background: var(--white-gold); }
.metal.platinum::before { background: var(--platinum); }
.stones { font-size: 11px; color: var(--muted); }

/* detail */
dialog#detail {
  width: min(960px, 94vw); max-height: 90vh; padding: 0;
  border: 0; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(20, 18, 16, .45); }
.close { position: absolute; right: 10px; top: 6px; border: 0; background: none; font-size: 26px; cursor: pointer; color: var(--muted); }
.detail-body { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
.detail-image { background: #fff; display: grid; place-items: center; min-height: 360px; border-right: 1px solid var(--line); }
.detail-image img { width: 100%; max-height: 80vh; object-fit: contain; }
.detail-info { padding: 22px; overflow: auto; max-height: 90vh; }
.detail-info h2 { margin: 0 0 12px; font-size: 18px; }
.detail-info h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0 0 12px; }
dt { color: var(--muted); }
dd { margin: 0; }
.siblings { display: flex; flex-wrap: wrap; gap: 8px; }
.siblings .ref { flex: 0 0 96px; }
.siblings .ref .info { padding: 4px 6px; }
.siblings .ref.current { border-color: var(--accent); }

/* login */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  width: 320px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 28px; display: grid; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { display: grid; gap: 4px; color: var(--muted); }
.login-card input { height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.login-card button { height: 38px; border: 0; border-radius: 6px; background: var(--ink); color: #fff; font: inherit; cursor: pointer; }
.error { color: var(--accent); margin: 0; }

@media (max-width: 720px) {
  .filters { position: static; }
  .detail-body { grid-template-columns: 1fr; }
  .detail-image { border-right: 0; border-bottom: 1px solid var(--line); min-height: 240px; }
}
