/* ==========================================================
   MAGPY CRATE — same editorial cartography theme as Atlas
   ========================================================== */
:root {
  --atlas-bg: #1c1815;
  --atlas-surface: #211d1a;
  --atlas-elevated: #28231f;
  --atlas-elevated-2: #322d28;
  --atlas-border: #322d27;
  --atlas-border-strong: #56504a;
  --atlas-text: #f0eadd;
  --atlas-text-2: #d4cebf;
  --atlas-muted: #a09a8c;
  --atlas-dim: #6e685e;
  --atlas-active: #ece6d8;
  --atlas-emerald: #8aab8e;
  --atlas-amber: #c4a575;
  --atlas-paper: #ffffff;
  --font-display: "Geist", -apple-system, "Helvetica Neue", sans-serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--atlas-bg);
  color: var(--atlas-text);
  line-height: 1.45;
  font-size: 14px;
  overflow-x: clip;
}
* { scrollbar-color: var(--atlas-border-strong) var(--atlas-surface); scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--atlas-surface); }
::-webkit-scrollbar-thumb { background: var(--atlas-border-strong); border-radius: 5px; border: 2px solid var(--atlas-surface); }
::-webkit-scrollbar-thumb:hover { background: var(--atlas-active); }

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--atlas-surface);
  border-right: 1px solid var(--atlas-border-strong);
  padding: 20px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.main { display: flex; flex-direction: column; min-width: 0; position: relative; overflow-x: clip; }
.topbar { position: sticky; top: 0; z-index: 6; background: var(--atlas-surface); }

/* ==== Brand block (matches Atlas) ==== */
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  padding-bottom: 14px;
  position: relative;
  border-bottom: 2px solid var(--atlas-text);
}
.brand::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  width: 72px;
  height: 2px;
  background: var(--atlas-text-2);
}
.brand-mark { width: 64px; height: 64px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-text { display: flex; flex-direction: column; line-height: 1; min-width: 0; flex: 1; }
.brand-text .family-label {
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 500;
  color: var(--atlas-muted);
  letter-spacing: 0.24em;
  text-transform: lowercase;
  margin-bottom: 2px;
  margin-left: 1px;
}
.brand-text .wordmark {
  font-family: "Righteous", "Geist", sans-serif;
  font-size: 50px;
  font-weight: 400;
  color: var(--atlas-text);
  letter-spacing: 0.012em;
  line-height: 0.88;
}
.brand-text .tagline {
  font-family: var(--font-mono);
  font-size: 8.5px;
  color: var(--atlas-dim);
  letter-spacing: 0.185em;
  text-transform: uppercase;
  margin-top: 7px;
  font-weight: 500;
  white-space: nowrap;
}

/* ==== Toolbar ==== */
.toolbar-main {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 22px;
  background: var(--atlas-surface);
  border-bottom: 1px solid var(--atlas-border-strong);
}
.toolbar-search { flex: 1; min-width: 0; }
.toolbar-search .search-wrap { position: relative; display: flex; align-items: center; width: 100%; }
.toolbar-search .search-icon {
  position: absolute;
  left: 14px;
  color: var(--atlas-dim);
  font-size: 16px;
  pointer-events: none;
  z-index: 1;
}
.toolbar-search input[type=text] {
  flex: 1; min-width: 0; width: auto;
  padding: 10px 38px;
  font-size: 14px; line-height: 1.15;
  font-family: var(--font-sans);
  background: var(--atlas-bg);
  border: 1px solid var(--atlas-border);
  color: var(--atlas-text);
  border-radius: 6px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.toolbar-search input[type=text]:focus {
  outline: none;
  border-color: var(--atlas-active);
  box-shadow: 0 0 0 3px rgba(236, 230, 216, 0.08);
}
.toolbar-search input[type=text]::placeholder { color: var(--atlas-dim); }
.search-clear {
  position: absolute; right: 8px;
  background: transparent; border: none;
  color: var(--atlas-muted);
  cursor: pointer; font-size: 22px; padding: 0 8px; line-height: 1;
}
.search-clear:hover { color: var(--atlas-text); }
.toolbar-actions {
  display: flex; gap: 10px; align-items: center; flex-wrap: nowrap; flex-shrink: 0;
}
.toolbar-actions select {
  background: var(--atlas-elevated);
  border: 1px solid var(--atlas-border);
  color: var(--atlas-text);
  padding: 10px 30px 10px 12px;
  border-radius: 6px;
  font-size: 14px; line-height: 1.15;
  cursor: pointer;
  font-family: var(--font-sans);
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'><path d='M2 4.5 L6 8.5 L10 4.5' stroke='%23ece6d8' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 10px 10px;
}
.toolbar-actions select:hover { border-color: var(--atlas-border-strong); }
.toolbar-actions .stats {
  font-size: 12px;
  color: var(--atlas-muted);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  flex-shrink: 0;
}
.toolbar-actions .stats strong {
  color: var(--atlas-text);
  font-weight: 600;
}

/* ==== Active filters bar ==== */
.active-filters {
  padding: 10px 22px;
  background: var(--atlas-surface);
  border-bottom: 1px solid var(--atlas-border-strong);
  box-shadow: inset 3px 0 0 var(--atlas-text);
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.active-filters .label {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--atlas-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin-right: 6px;
}
.active-filters .pill {
  display: inline-flex; align-items: center;
  font-size: 11.5px;
  padding: 3px 4px 3px 9px;
  background: var(--atlas-elevated);
  border: 1px solid var(--atlas-border);
  border-radius: 12px;
  color: var(--atlas-text-2);
}
.active-filters .pill button {
  background: transparent;
  border: none;
  color: var(--atlas-muted);
  cursor: pointer;
  font-size: 14px;
  margin-left: 5px;
  padding: 0 4px;
  line-height: 1;
}
.active-filters .pill button:hover { color: var(--atlas-text); }

/* ==== Sidebar filters ==== */
.filter-group { margin-bottom: 22px; }
.filter-section h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 10px;
  font-weight: 600;
  color: var(--atlas-muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 7px;
}
.filter-section h3 .ph { font-size: 12px; }
.filter-section h3 .filter-counter {
  margin-left: 5px;
  font-size: 10px;
  font-weight: 400;
  color: var(--atlas-muted);
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}
.toggles { display: flex; flex-direction: column; gap: 6px; }
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--atlas-text-2);
  cursor: pointer;
}
.toggle input[type=checkbox] {
  accent-color: var(--atlas-bg);
  width: 14px; height: 14px;
  cursor: pointer;
}
.toggle:hover { color: var(--atlas-text); }
.options { display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  padding: 4px 9px;
  background: var(--atlas-elevated);
  border: 1px solid var(--atlas-border);
  color: var(--atlas-text-2);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.12s;
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.005em;
}
.chip:hover { background: var(--atlas-elevated-2); color: var(--atlas-text); border-color: var(--atlas-border-strong); }
.chip.on {
  background: var(--atlas-active);
  color: var(--atlas-bg);
  border-color: var(--atlas-active);
  font-weight: 600;
}
.chip .count {
  font-size: 10px;
  color: var(--atlas-dim);
  margin-left: 5px;
  font-variant-numeric: tabular-nums;
}
.chip.on .count { color: var(--atlas-bg); opacity: 0.65; }

/* ==== Grid ==== */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  padding: 18px 22px;
  align-content: start;
}
.empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--atlas-muted);
  font-size: 13px;
}
.empty .ph { font-size: 24px; display: block; margin-bottom: 10px; }

/* ==== Card ==== */
.card {
  background: var(--atlas-surface);
  border: 1px solid var(--atlas-border);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 280px;
  transition: border-color 0.12s, transform 0.12s;
  content-visibility: auto;
  contain-intrinsic-size: 280px;
}
.card:hover {
  border-color: var(--atlas-border-strong);
  transform: translateY(-1px);
}
.card .thumb {
  aspect-ratio: 1 / 1;
  background: var(--atlas-paper);
  border-bottom: 1px solid var(--atlas-border-strong);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
/* Native lazy-loading <img> — browser fetches only thumbs near viewport.
   Critical when the catalog grows to 100K+ products. */
.card .thumb-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card .thumb-fallback {
  font-size: 38px;
  color: var(--atlas-dim);
  background: var(--atlas-elevated);
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
/* R3PLICA square mark — placed bottom-right of the thumbnail to cover the
   3dmaxter watermark embedded in source images. Swap assets/r3-mark.svg
   with the official square logo when ready, no CSS change needed. */
.card .thumb-mark {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 38px;
  height: 38px;
  display: block;
  pointer-events: none;
  z-index: 2;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.35));
}
.card .has-archive-band {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--atlas-emerald);
  color: var(--atlas-bg);
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  text-align: center;
  padding: 3px 0;
  pointer-events: none;
}
.card .body {
  padding: 10px 11px 12px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.card .name {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 600;
  color: var(--atlas-text);
  letter-spacing: -0.005em;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .brand-name {
  font-size: 11px;
  color: var(--atlas-amber);
  font-weight: 500;
  font-family: var(--font-display);
  letter-spacing: 0.01em;
}
.card .meta {
  font-size: 10.5px;
  color: var(--atlas-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-family: var(--font-mono);
}
.card .meta .dot { color: var(--atlas-dim); }
.card .meta .file-size { color: var(--atlas-text-2); font-weight: 500; }
.card .actions {
  display: flex;
  gap: 5px;
  margin-top: auto;
  padding-top: 8px;
  align-items: center;
}
.card .actions a, .card .actions button {
  font-size: 11px;
  padding: 5px 9px;
  border-radius: 4px;
  background: var(--atlas-elevated);
  color: var(--atlas-text-2);
  border: 1px solid var(--atlas-border);
  cursor: pointer;
  font-family: var(--font-sans);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.12s;
}
.card .actions a:hover, .card .actions button:hover {
  background: var(--atlas-elevated-2);
  border-color: var(--atlas-border-strong);
  color: var(--atlas-text);
}
.card .actions .icon-btn { padding: 5px 7px; font-size: 13px; }
.card .actions a.primary {
  background: var(--atlas-emerald);
  color: var(--atlas-bg);
  border-color: var(--atlas-emerald);
  font-weight: 600;
  flex: 1;
  justify-content: center;
}
.card .actions a.primary:hover {
  background: #98ba9c;
  border-color: #98ba9c;
  color: var(--atlas-bg);
}
.card .actions .no-local {
  font-size: 10px;
  color: var(--atlas-dim);
  font-style: italic;
  flex: 1;
  padding: 5px 0;
}

/* ==== Toast ==== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--atlas-elevated-2);
  color: var(--atlas-text);
  padding: 10px 18px;
  border-radius: 5px;
  border: 1px solid var(--atlas-border-strong);
  font-size: 12.5px;
  opacity: 0;
  transition: opacity 0.18s;
  pointer-events: none;
  z-index: 50;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
.toast.show { opacity: 1; }

/* ==== Back-to-top floating button ==== */
.back-to-top {
  position: fixed;
  bottom: 78px;        /* sits above the launcher bottom-right (which is at 18px + 48px) */
  right: 18px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--atlas-elevated);
  border: 1px solid var(--atlas-border-strong);
  color: var(--atlas-text-2);
  cursor: pointer;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, background 0.12s, color 0.12s, transform 0.12s;
  z-index: 50;
}
.back-to-top.show {
  opacity: 1;
  pointer-events: auto;
}
.back-to-top:hover {
  background: var(--atlas-elevated-2);
  color: var(--atlas-text);
  transform: translateY(-1px);
}
@media (max-width: 768px) {
  .back-to-top { bottom: 70px; right: 14px; }
}

/* ==========================================================
   Mobile drawer infrastructure (matching Atlas pattern)
   ========================================================== */
.mobile-filters-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--atlas-elevated);
  border: 1px solid var(--atlas-border-strong);
  color: var(--atlas-text);
  width: 40px;
  height: 40px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 18px;
}
.mobile-filters-btn:hover { background: var(--atlas-elevated-2); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 40;
  backdrop-filter: blur(2px);
}
.app.sidebar-open .sidebar-backdrop { display: block; }

.sidebar-close { display: none; }

body.no-scroll { overflow-y: hidden; }

/* ==========================================================
   Tablet (≤1024px): toolbar splits into two stacked rows
   ========================================================== */
@media (max-width: 1024px) {
  .toolbar-main {
    display: block;
    padding: 0;
    background: transparent;
    border: 0;
  }
  .toolbar-search {
    padding: 12px 22px;
    background: var(--atlas-surface);
    border-bottom: 1px solid var(--atlas-border-strong);
    display: flex;
    gap: 10px;
    align-items: center;
  }
  .toolbar-search .search-wrap { flex: 1; min-width: 0; }
  .toolbar-actions {
    padding: 10px 22px;
    background: var(--atlas-surface);
    border-bottom: 1px solid var(--atlas-border-strong);
    gap: 8px;
  }
}

/* ==========================================================
   Mobile (≤768px): sidebar collapses to a drawer
   ========================================================== */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    border-right: none;
    padding-top: 18px;
  }
  .app.sidebar-open .sidebar { transform: translateX(0); }
  .sidebar .brand { padding-right: 46px; }
  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    background: var(--atlas-elevated);
    border: 1px solid var(--atlas-border-strong);
    color: var(--atlas-text);
    border-radius: 6px;
    cursor: pointer;
    font-size: 18px;
    z-index: 2;
    transition: background 0.12s, border-color 0.12s;
  }
  .sidebar-close:hover { background: var(--atlas-elevated-2); border-color: var(--atlas-text-2); }
  .mobile-filters-btn { display: inline-flex; }

  .toolbar-search {
    padding: 10px 14px;
    gap: 8px;
  }
  .toolbar-search input[type=text] { padding: 9px 36px; font-size: 13.5px; line-height: 1.15; }
  .toolbar-actions { padding: 9px 14px; gap: 6px; }
  .toolbar-actions select {
    font-size: 13.5px;
    padding: 9px 28px 9px 10px;
  }

  .grid {
    padding: 14px;
    gap: 10px;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
}
