/* One stylesheet for three pages. No framework, no build step — the same rules
   as every other castomapi front end.

   Layout is: fixed top bar, a sidebar of filters, a fluid grid of cards. The
   grid is the whole product, so everything else is deliberately quiet. */

:root {
  color-scheme: dark;

  --bg: #0c0d10;
  --bg-raised: #141619;
  --bg-sunken: #08090b;
  --bg-hover: #1b1e23;
  --line: #24272e;
  --line-strong: #363a44;

  --text: #e8eaee;
  --text-dim: #9aa1ad;
  --text-faint: #666d7a;

  --accent: #6ea8fe;
  --accent-soft: rgba(110, 168, 254, 0.14);
  --ok: #56d3a0;
  --warn: #f0b849;
  --bad: #f2777a;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 16px;
  --bar-height: 56px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

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

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

code,
kbd {
  font-family: var(--mono);
  font-size: 0.92em;
}

/* --- top bar ------------------------------------------------------------ */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--gap);
  height: var(--bar-height);
  padding: 0 20px;
  background: rgba(12, 13, 16, 0.86);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand span {
  color: var(--text-faint);
  font-weight: 400;
  font-size: 12px;
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}

.nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
}

.nav a:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

.nav a[aria-current='page'] {
  background: var(--accent-soft);
  color: var(--accent);
}

.topbar .spacer {
  flex: 1;
}

/* --- controls ----------------------------------------------------------- */

input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
}

input[type='text'],
input[type='search'],
input[type='password'],
select,
textarea {
  padding: 8px 10px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search {
  flex: 1;
  max-width: 460px;
}

button {
  padding: 8px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s;
}

button:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--text-faint);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #08111f;
  font-weight: 600;
}

button.primary:hover:not(:disabled) {
  background: #8bbcff;
  border-color: #8bbcff;
}

button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}

button.ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

button.danger:hover:not(:disabled) {
  border-color: var(--bad);
  color: var(--bad);
}

button.small {
  padding: 4px 9px;
  font-size: 12px;
}

label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- page shell --------------------------------------------------------- */

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 28px;
  max-width: 1680px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

.shell.single {
  grid-template-columns: 1fr;
  max-width: 1100px;
}

.sidebar {
  position: sticky;
  top: calc(var(--bar-height) + 24px);
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.side-group h3 {
  margin-bottom: 8px;
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

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

.cat {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-dim);
  text-align: left;
  width: 100%;
}

.cat:hover {
  background: var(--bg-hover);
  border: none;
}

.cat[aria-pressed='true'] {
  background: var(--accent-soft);
  color: var(--accent);
}

.cat .count {
  font-size: 11px;
  color: var(--text-faint);
  font-variant-numeric: tabular-nums;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  padding: 4px 9px;
  border-radius: 100px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--line-strong);
  color: var(--text);
}

.warn-chip {
  border-color: rgba(240, 184, 73, 0.5);
  background: rgba(240, 184, 73, 0.1);
  color: var(--warn);
}

.warn-chip:hover {
  border-color: var(--warn);
  color: var(--warn);
}

.chip[aria-pressed='true'] {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}

/* A tag in the drawer: the chip is a label with its own remove button, not a
   filter, so it does not light up on hover the way the sidebar chips do. */
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  cursor: default;
}

.tag-chip:hover {
  border-color: var(--line);
  color: var(--text-dim);
}

.chip-x {
  padding: 0 0 0 2px;
  border: 0;
  background: none;
  color: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.chip-x:hover {
  color: var(--bad);
}

.tag-add {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tag-add input {
  width: 150px;
  padding: 4px 9px;
  font-size: 12px;
}

/* --- grid --------------------------------------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar .count {
  color: var(--text-faint);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: var(--gap);
}

.grid.icons {
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}

.grid.rows {
  grid-template-columns: 1fr;
  gap: 8px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s;
}

.card:hover {
  border-color: var(--line-strong);
  transform: translateY(-2px);
}

.card .thumb {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 4 / 3;
  background: var(--bg-sunken);
  overflow: hidden;
}

.grid.icons .card .thumb {
  aspect-ratio: 1;
  padding: 18px;
}

.card .thumb img,
.card .thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.grid.icons .card .thumb img {
  object-fit: contain;
  /* Icon SVGs are almost all solid black; on a dark grid they need inverting to
     be visible at all. */
  filter: invert(1) brightness(1.4);
}

.card .thumb .glyph {
  font-size: 30px;
  color: var(--text-faint);
}

.card .meta {
  padding: 9px 11px;
  border-top: 1px solid var(--line);
}

.card .meta .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.card .meta .sub {
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 11px;
  display: flex;
  gap: 6px;
  align-items: center;
}

.card .badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 7px;
  border-radius: 100px;
  background: rgba(8, 9, 11, 0.82);
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card .pick {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.12s;
}

.card:hover .pick,
.card.selected .pick {
  opacity: 1;
}

.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.font-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  font-size: 30px;
  line-height: 1.1;
  color: var(--text);
  text-align: center;
  overflow: hidden;
}

/* A result the import policy will refuse: still browsable, visibly not takeable. */
.card.blocked {
  opacity: 0.45;
}

.card.blocked:hover {
  opacity: 0.7;
  border-color: var(--bad);
  transform: none;
}

/* --- states ------------------------------------------------------------- */

.empty {
  padding: 64px 20px;
  text-align: center;
  color: var(--text-faint);
}

.empty h2 {
  margin-bottom: 8px;
  color: var(--text-dim);
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-raised), var(--bg-hover), var(--bg-raised));
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite linear;
  border-radius: var(--radius);
  aspect-ratio: 4 / 3;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.notice {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text-dim);
  margin-bottom: 16px;
  font-size: 13px;
}

.notice.warn {
  border-color: rgba(240, 184, 73, 0.4);
  background: rgba(240, 184, 73, 0.08);
  color: var(--warn);
}

.notice.bad {
  border-color: rgba(242, 119, 122, 0.4);
  background: rgba(242, 119, 122, 0.08);
  color: var(--bad);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
  color: var(--text-faint);
  font-size: 13px;
}

/* --- drawer (asset detail) ---------------------------------------------- */

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 5, 7, 0.66);
  backdrop-filter: blur(2px);
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 41;
  width: min(460px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--bg-raised);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  animation: slide-in 0.16s ease-out;
}

@keyframes slide-in {
  from {
    transform: translateX(18px);
    opacity: 0;
  }
}

.drawer header {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}

.drawer header h2 {
  flex: 1;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer .body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.preview {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  max-height: 320px;
  padding: 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview img,
.preview video {
  max-width: 100%;
  max-height: 296px;
  object-fit: contain;
}

.preview img.icon {
  width: 96px;
  height: 96px;
  filter: invert(1) brightness(1.4);
}

.preview .glyph {
  font-size: 56px;
  color: var(--text-faint);
}

.facts {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 6px 12px;
  font-size: 13px;
}

.facts dt {
  color: var(--text-faint);
}

.facts dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.copyline {
  display: flex;
  gap: 6px;
  align-items: center;
}

.copyline input {
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
}

/* The files stored beside a model — its textures and .bin — in the drawer.
   A texture tile shows the map itself, which is the only way to tell
   baseColor from normal at a glance. */
.filelist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.filelist-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.filelist .files {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.file {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: inherit;
  text-decoration: none;
  overflow: hidden;
}

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

.file.main {
  border-style: dashed;
}

.file img,
.file .glyph {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 64px;
  object-fit: cover;
  border-radius: calc(var(--radius) - 3px);
  /* A transparent baseColor map is invisible on a dark panel. */
  background: repeating-conic-gradient(var(--line) 0% 25%, transparent 0% 50%) 0 0 / 12px 12px;
  font-size: 22px;
  color: var(--text-faint);
}

.file .name {
  font-size: 11px;
  line-height: 1.3;
  /* Two lines rather than one: texture names differ at the end
     (…_baseColor_1001 vs …_normal), and a single clipped line makes every map
     of one material look identical. The full path is in the tooltip. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.filelist .hint {
  margin: 0;
  font-size: 11px;
  color: var(--text-faint);
}

/* Inside a queue row the section is a second grid line under the name, not a
   fourth column beside the buttons. */
.qrow .filelist {
  grid-column: 2 / -1;
  margin-top: 4px;
}

.file .sub {
  font-size: 10px;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- upload ------------------------------------------------------------- */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 52px 20px;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text-dim);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.12s, background 0.12s;
}

.dropzone:hover,
.dropzone.over {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.dropzone .big {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.queue {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
}

.qrow {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 9px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

.qrow.ok {
  border-left-color: var(--ok);
}

.qrow.bad {
  border-left-color: var(--bad);
}

.qrow.busy {
  border-left-color: var(--accent);
}

.qrow .qthumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  object-fit: cover;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 11px;
  overflow: hidden;
}

.qrow .qthumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* An SVG shown straight from the queued file: icon SVGs are almost all solid
   black, so the same inversion the icon grid uses. */
.qrow .qthumb img.icon {
  object-fit: contain;
  padding: 6px;
  filter: invert(1) brightness(1.4);
}

.qrow .qthumb .font-preview {
  padding: 0;
  font-size: 20px;
}

.qrow .qthumb .glyph {
  font-size: 20px;
}

.qrow .qname {
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qrow .qnote {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-faint);
}

.qrow.bad .qnote {
  color: var(--bad);
}

.qrow.ok .qnote {
  color: var(--ok);
}

.qrow.warn {
  border-left-color: var(--warn);
}

.qrow.warn .qnote {
  color: var(--warn);
}

/* --- admin -------------------------------------------------------------- */

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

.panel + .panel {
  margin-top: 18px;
}

.panel h2 {
  font-size: 15px;
  margin-bottom: 4px;
}

.panel .hint {
  color: var(--text-faint);
  font-size: 12px;
  margin-bottom: 14px;
}

.statgrid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.stat {
  padding: 12px 14px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.stat .n {
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.stat .k {
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  text-align: left;
  color: var(--text-faint);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}

td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

tr:last-child td {
  border-bottom: none;
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--text-faint);
}

.dot.on {
  background: var(--ok);
}

.dot.off {
  background: var(--line-strong);
}

/* --- login -------------------------------------------------------------- */

.centered {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.login {
  width: min(360px, 92vw);
  padding: 26px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.login h1 {
  font-size: 17px;
  margin-bottom: 4px;
}

.login p {
  color: var(--text-faint);
  font-size: 13px;
  margin: 0 0 18px;
}

/* --- rating ------------------------------------------------------------- */

.rating-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.star-btn {
  padding: 4px 8px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: 100px;
  line-height: 1;
}

.star-btn:hover:not(:disabled) {
  border-color: var(--warn);
}

.rating {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.stars {
  color: var(--text-faint);
  letter-spacing: 1px;
  font-size: 13px;
}

.stars.has-points {
  color: var(--warn);
}

.points {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-dim);
  min-width: 1ch;
}

.star-minus {
  padding: 2px 7px;
  line-height: 1;
}

.rating-badge {
  left: auto;
  right: 8px;
  color: var(--warn);
  background: rgba(8, 9, 11, 0.85);
}

.rating-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

/* A card can carry both a duration and a rating; keep them off each other. */
.card .badge + .rating-badge {
  top: 8px;
}

/* --- toasts ------------------------------------------------------------- */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 13px;
  animation: rise 0.16s ease-out;
  max-width: 380px;
}

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

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

@keyframes rise {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
}

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

  .sidebar {
    position: static;
  }

  .nav a {
    padding: 6px 9px;
  }
}

/* Controls sitting in a toolbar are inline company, not form fields on their
   own line — the global `select, input { width: 100% }` would otherwise make
   each one wrap. */
.toolbar select,
.toolbar input[type="text"] {
  width: auto;
  min-width: 150px;
}
.toolbar label {
  margin: 0;
  white-space: nowrap;
}

/* Extract page: cards are buttons here, because picking which images to pull
   in is the whole interaction. Everything else reuses the library's card. */
.card.selectable,
button.card {
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 0;
  width: 100%;
}
button.card:hover { border-color: var(--accent); }
button.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
button.card.selected::after {
  content: "✓";
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #000;
  font-size: 13px;
  line-height: 20px;
  text-align: center;
}
button.card { position: relative; }
