/* ============================================================
   Collector - stylesheet
   Dark-first (a photo of a card reads better against a dark page),
   with a light theme via prefers-color-scheme and a manual toggle
   that stamps data-theme on <html>.
   ============================================================ */

:root {
  --bg-deep:   #0e1015;
  --bg:        #14171f;
  --bg-raise:  #1a1e28;
  --bg-hover:  #212632;
  --line:      #2a303d;
  --line-soft: #202634;
  --text:      #e8eaf0;
  --text-dim:  #98a0b3;
  --text-mute: #6c7488;
  --accent:      #c8963e;
  --accent-soft: #3a2e17;
  --accent-text: #f0c675;
  --good:  #4ea87a;
  --warn:  #d9a13b;
  --bad:   #d4685f;
  --info:  #5b8fd0;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 6px 24px rgba(0,0,0,.34);
  --sidebar-w: 246px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="light"],
html:not([data-theme="dark"]) {
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  html:not([data-theme="dark"]) {
    --bg-deep:   #eceef2;
    --bg:        #f7f8fa;
    --bg-raise:  #ffffff;
    --bg-hover:  #eef0f5;
    --line:      #d7dbe4;
    --line-soft: #e4e7ee;
    --text:      #1b1f2a;
    --text-dim:  #5a6376;
    --text-mute: #858da0;
    --accent:      #a2751f;
    --accent-soft: #f6ecd6;
    --accent-text: #7c5813;
    --shadow: 0 6px 20px rgba(20,25,40,.10);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg-deep:   #eceef2;
  --bg:        #f7f8fa;
  --bg-raise:  #ffffff;
  --bg-hover:  #eef0f5;
  --line:      #d7dbe4;
  --line-soft: #e4e7ee;
  --text:      #1b1f2a;
  --text-dim:  #5a6376;
  --text-mute: #858da0;
  --accent:      #a2751f;
  --accent-soft: #f6ecd6;
  --accent-text: #7c5813;
  --shadow: 0 6px 20px rgba(20,25,40,.10);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg-deep);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; font-weight: 620; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.08rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .7em; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); }

.muted { color: var(--text-dim); }
.mute  { color: var(--text-mute); }
.err   { color: var(--bad); font-size: .88rem; }
.warn  { color: var(--warn); }
.hint  { color: var(--text-mute); font-size: .84rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------- controls */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=password], input[type=search],
input[type=number], input[type=date], input[type=url], select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 76px; resize: vertical; }
label { display: block; font-size: .84rem; color: var(--text-dim); margin-bottom: .1rem; }
label > input, label > select, label > textarea { margin-top: .25rem; color: var(--text); }
.row-check { display: flex; align-items: center; gap: .5rem; color: var(--text-dim); }
.row-check input { width: auto; margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .48rem .8rem;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--text-mute); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1408; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.sm { padding: .3rem .55rem; font-size: .84rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2rem; height: 2rem;
  background: transparent; border: 1px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--text-dim);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.stack { display: grid; gap: .7rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7rem; }
@media (max-width: 620px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------- auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.auth-card {
  width: 100%; max-width: 384px;
  background: var(--bg-raise);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.3rem; }
.brand h1 { margin: 0; font-size: 1.2rem; }
.brand p { margin: 0; font-size: .82rem; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-mark.sm { width: 24px; height: 24px; }
.qr { display: grid; place-items: center; padding: .8rem; background: #fff; border-radius: var(--radius-sm); }
.qr svg { display: block; width: 100%; max-width: 232px; height: auto; }
.secret {
  display: block; margin-top: .5rem; padding: .5rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: .84rem; word-break: break-all; letter-spacing: .04em;
}
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; padding-left: 1.2rem; margin: .2rem 0 .6rem; }
.codes li { font-family: var(--mono); font-size: .9rem; }
details summary { cursor: pointer; color: var(--text-dim); font-size: .84rem; }

/* ---------------------------------------------------------- app shell */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  display: flex; flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--line);
  height: 100vh; position: sticky; top: 0;
  overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; gap: .55rem; padding: .85rem .9rem; border-bottom: 1px solid var(--line-soft); }
.brand-name { font-weight: 650; letter-spacing: .01em; }
.sidebar-close { display: none; margin-left: auto; }

.nav { padding: .6rem .5rem; display: grid; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: .55rem;
  padding: .44rem .6rem; border-radius: var(--radius-sm);
  color: var(--text-dim); font-size: .9rem;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 560; }
.ico { width: 1.1em; text-align: center; opacity: .85; }

.sidebar-section { padding: .5rem .5rem 0; }
.sidebar-section-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: .35rem .6rem; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-mute);
}
.space-list { display: grid; gap: 1px; padding-bottom: .4rem; }
.space-item {
  display: flex; align-items: center; gap: .5rem;
  padding: .38rem .6rem; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text-dim); font-size: .88rem;
  border: none; background: none; text-align: left; width: 100%;
}
.space-item:hover { background: var(--bg-hover); color: var(--text); }
.space-item.active { background: var(--accent-soft); color: var(--accent-text); }
.space-item .label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-item .count { font-size: .76rem; color: var(--text-mute); font-variant-numeric: tabular-nums; }
.space-item .pin { opacity: .55; font-size: .7rem; }

.sidebar-foot { margin-top: auto; padding: .7rem; border-top: 1px solid var(--line-soft); display: grid; gap: .5rem; }
.who { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.avatar {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 650; font-size: .82rem;
}
.who-text { min-width: 0; display: grid; }
.who-text strong, .who-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .82rem; }

.main { min-width: 0; display: flex; flex-direction: column; background: var(--bg-deep); }
.topbar {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .9rem; border-bottom: 1px solid var(--line);
  background: var(--bg); position: sticky; top: 0; z-index: 20;
}
.menu-btn { display: none; }
.search-wrap { flex: 1; max-width: 520px; }
.topbar-actions { margin-left: auto; display: flex; gap: .4rem; align-items: center; }

.view { padding: 1rem; min-width: 0; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 40; width: 82vw; max-width: var(--sidebar-w);
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .sidebar-close, .menu-btn { display: inline-flex; }
}

/* ---------------------------------------------------------- panels, tiles */
.panel {
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .7rem; }
.panel-head h2, .panel-head h3 { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.tile {
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .75rem .85rem;
}
.tile .k { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-mute); }
.tile .v { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.tile .s { font-size: .8rem; color: var(--text-dim); }
.tile.accent .v { color: var(--accent-text); }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
@media (max-width: 1000px) { .dash-grid { grid-template-columns: 1fr; } }

/* bar list used for brand/decade/storage breakdowns */
.barlist { display: grid; gap: .4rem; }
.barrow { display: grid; grid-template-columns: 1fr auto; gap: .3rem .6rem; align-items: center; }
.barrow .bl { font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barrow .bv { font-size: .82rem; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.bartrack { grid-column: 1 / -1; height: 5px; background: var(--bg-hover); border-radius: 3px; overflow: hidden; }
.barfill { height: 100%; background: var(--accent); border-radius: 3px; }

.meter { height: 7px; background: var(--bg-hover); border-radius: 4px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--good); }

/* ---------------------------------------------------------- table */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-raise); }
table.cards { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.cards th, table.cards td { padding: .45rem .6rem; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; }
table.cards thead th {
  position: sticky; top: 0; background: var(--bg-raise); z-index: 2;
  font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-mute);
  cursor: pointer; user-select: none;
}
table.cards thead th:hover { color: var(--text); }
table.cards tbody tr:hover { background: var(--bg-hover); }
table.cards tbody tr.sel { background: var(--accent-soft); }
table.cards td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.cards td.wide { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.th-sort::after { content: ""; }
.th-sort.asc::after  { content: " ▲"; font-size: .7em; }
.th-sort.desc::after { content: " ▼"; font-size: .7em; }
.cell-check { width: 1px; }

.thumb {
  width: 30px; height: 42px; object-fit: cover; border-radius: 3px;
  background: var(--bg-hover); display: block;
}
.thumb-ph { display: grid; place-items: center; color: var(--text-mute); font-size: .7rem; }

/* ---------------------------------------------------------- grid + gallery */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: .7rem; }
.card-tile {
  background: var(--bg-raise); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; cursor: pointer; display: flex; flex-direction: column;
}
.card-tile:hover { border-color: var(--accent); }
.card-tile .pic { aspect-ratio: 5 / 7; background: var(--bg-hover); display: grid; place-items: center; overflow: hidden; }
.card-tile .pic img { width: 100%; height: 100%; object-fit: cover; }
.card-tile .pic .none { color: var(--text-mute); font-size: .78rem; }
.card-tile .meta { padding: .5rem .6rem; display: grid; gap: .1rem; }
.card-tile .t { font-size: .86rem; font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-tile .st { font-size: .78rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-tile .val { font-size: .84rem; color: var(--accent-text); font-variant-numeric: tabular-nums; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: .5rem; }
.gallery .g { aspect-ratio: 5/7; border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-raise); border: 1px solid var(--line); cursor: pointer; }
.gallery .g img { width: 100%; height: 100%; object-fit: cover; }
.gallery .g:hover { border-color: var(--accent); }

/* ---------------------------------------------------------- filter bar */
.toolbar {
  display: flex; flex-wrap: wrap; gap: .45rem; align-items: center;
  margin-bottom: .7rem;
}
.toolbar .spacer { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { padding: .35rem .6rem; background: var(--bg-raise); border: none; cursor: pointer; color: var(--text-dim); font-size: .84rem; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent-text); }

.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .2rem .45rem .2rem .55rem; font-size: .8rem;
  background: var(--accent-soft); color: var(--accent-text);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 99px;
}
.chip button { background: none; border: none; cursor: pointer; color: inherit; opacity: .7; padding: 0 .1rem; }
.chip button:hover { opacity: 1; }

.pager { display: flex; align-items: center; gap: .5rem; justify-content: center; margin-top: .8rem; color: var(--text-dim); font-size: .86rem; }

.bulkbar {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  padding: .5rem .7rem; margin-bottom: .6rem;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-sm); color: var(--accent-text); font-size: .87rem;
}

/* ---------------------------------------------------------- badges */
.badge {
  display: inline-block; padding: .05rem .35rem; border-radius: 4px;
  font-size: .72rem; font-weight: 600; letter-spacing: .02em;
  background: var(--bg-hover); color: var(--text-dim); border: 1px solid var(--line);
}
.badge.rc    { background: color-mix(in srgb, var(--info) 20%, transparent); color: var(--info); border-color: transparent; }
.badge.auto  { background: color-mix(in srgb, var(--good) 20%, transparent); color: var(--good); border-color: transparent; }
.badge.relic { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); border-color: transparent; }
.badge.grade { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge.set   { background: color-mix(in srgb, var(--info) 16%, transparent); color: var(--info); border-color: transparent; }
.badge.sealed{ background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); border-color: transparent; }

/* ---------------------------------------------------------- card detail */
.detail { display: grid; grid-template-columns: 300px 1fr; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .detail { grid-template-columns: 1fr; } }
.shots { display: grid; gap: .5rem; }
.shot-main { aspect-ratio: 5/7; background: var(--bg-hover); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: grid; place-items: center; }
.shot-main img { width: 100%; height: 100%; object-fit: contain; }
.shot-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px,1fr)); gap: .35rem; }
.shot-strip .s { position: relative; aspect-ratio: 5/7; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); cursor: pointer; }
.shot-strip .s.on { border-color: var(--accent); }
.shot-strip .s img { width: 100%; height: 100%; object-fit: cover; }
.shot-strip .s .x { position: absolute; top: 1px; right: 1px; background: rgba(0,0,0,.6); color: #fff; border: none; border-radius: 3px; cursor: pointer; font-size: .7rem; line-height: 1; padding: .1rem .25rem; }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius);
  padding: .9rem; text-align: center; color: var(--text-mute); font-size: .85rem; cursor: pointer;
}
.dropzone.hot { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: .25rem .8rem; font-size: .88rem; }
.kv dt { color: var(--text-mute); }
.kv dd { margin: 0; }

/* ---------------------------------------------------------- modal, toasts */
.modal-host { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal {
  position: relative; width: 100%; max-width: 620px; max-height: 88vh; overflow: auto;
  background: var(--bg-raise); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: .8rem .9rem; border-bottom: 1px solid var(--line-soft); position: sticky; top: 0; background: var(--bg-raise); }
.modal-head h2 { margin: 0; font-size: 1rem; }
.modal-body { padding: .9rem; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 200; display: grid; gap: .4rem; }
.toast {
  padding: .55rem .8rem; border-radius: var(--radius-sm);
  background: var(--bg-raise); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: .87rem; max-width: 340px;
}
.toast.ok  { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }

.empty { padding: 2.2rem 1rem; text-align: center; color: var(--text-mute); }
.spinner { padding: 1.6rem; text-align: center; color: var(--text-mute); }

.trend { width: 100%; height: 96px; display: block; }
.trend path.line { fill: none; stroke: var(--accent); stroke-width: 2; }
.trend path.area { fill: var(--accent-soft); stroke: none; }

/* Tier-preview banner. Distinct from the read-only bar so an admin can tell at
   a glance whether they are looking at a real restriction or a simulated one. */
.bulkbar.preview {
  background: color-mix(in srgb, var(--info) 18%, transparent);
  border-color: color-mix(in srgb, var(--info) 45%, transparent);
  color: var(--info);
}
.bulkbar.preview .warn { color: var(--warn); }
