/* CityRP model catalogue -- a dark, dense, three-pane layout.
   Colours are defined once as tokens so a server can be reskinned by
   overriding :root in a small extra stylesheet. */

:root {
  --bg:            #0e1116;
  --bg-raised:     #151a21;
  --bg-sunken:     #0a0d11;
  --panel:         #171d25;
  --line:          #232b36;
  --line-strong:   #313c4b;
  --text:          #dfe5ec;
  --text-dim:      #8b97a6;
  --text-faint:    #5d6875;
  --accent:        #4ea3ff;
  --accent-dim:    #1d3a58;
  --warn:          #e8a13a;
  --danger:        #e0596b;
  --ok:            #4fbf87;
  --radius:        8px;
  --radius-sm:     5px;
  --shadow:        0 8px 24px rgba(0, 0, 0, .45);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }

/* Several panels are toggled with the `hidden` attribute, and a class that sets
   `display` would otherwise beat the user-agent rule that hides them. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  height: 52px;
  flex: 0 0 auto;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand h1 { font-size: 15px; letter-spacing: .2px; white-space: nowrap; }

.brand-mark {
  width: 18px; height: 18px; flex: 0 0 auto;
  border-radius: 4px;
  background: linear-gradient(140deg, var(--accent), #7a5cff);
}

/* ------------------------------------------------------------- mode tabs */
.mode-tabs {
  display: flex; gap: 2px; flex: 0 0 auto;
  background: var(--bg-sunken);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 2px;
}
.mode-tab {
  border: none; background: none; color: var(--text-dim);
  padding: 4px 11px; border-radius: 4px; font-size: 12px;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.is-on { background: var(--accent-dim); color: #cfe6ff; font-weight: 600; }

.search-wrap { position: relative; flex: 1 1 auto; max-width: 620px; }

.search-wrap input {
  width: 100%;
  height: 34px;
  padding: 0 32px 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
}
.search-wrap input:focus { outline: none; border-color: var(--accent); }

#search-clear {
  position: absolute; right: 4px; top: 4px;
  width: 26px; height: 26px;
}

.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

.pill {
  font: 12px/1 var(--mono);
  color: var(--text-dim);
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  white-space: nowrap;
}

/* --------------------------------------------------------------- buttons */
button { font: inherit; cursor: pointer; }

.ghost-btn, .primary-btn, .wide-btn, .chip, .icon-btn, .link-btn {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  color: var(--text);
  padding: 6px 10px;
  transition: background .12s, border-color .12s, color .12s;
}
.ghost-btn:hover, .chip:hover, .icon-btn:hover, .wide-btn:hover {
  background: #1e2631; border-color: var(--accent);
}
.primary-btn { background: var(--accent); border-color: var(--accent); color: #06121d; font-weight: 600; }
.primary-btn:hover { background: #6cb4ff; }
.icon-btn { padding: 0; line-height: 1; background: transparent; border: none; color: var(--text-dim); font-size: 18px; }
.link-btn { background: none; border: none; color: var(--accent); padding: 2px 4px; font-size: 12px; }
.chip { padding: 4px 9px; font-size: 12px; }
.chip.is-on { background: var(--accent-dim); border-color: var(--accent); color: #cfe6ff; }
.wide-btn { width: 100%; margin-top: 8px; padding: 9px; }
button:disabled { opacity: .45; cursor: not-allowed; }

/* ---------------------------------------------------------------- layout */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 232px 340px 1fr;
  min-height: 0;
}

.sidebar, .results { border-right: 1px solid var(--line); overflow-y: auto; min-height: 0; }
.sidebar { background: var(--panel); padding-bottom: 24px; }
.results { background: var(--bg-raised); display: flex; flex-direction: column; }

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  padding: 12px 14px 8px;
}
.panel-head h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint);
}
.panel-head.sticky {
  position: sticky; top: 0; z-index: 3;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}
.results-tools { display: flex; gap: 6px; align-items: center; }
.results-tools select {
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 5px 6px; font-size: 12px;
}

/* ------------------------------------------------------------ folder tree */
.tree { padding: 0 6px; }

.tree-row {
  display: flex; align-items: center; gap: 4px;
  width: 100%;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  border: none; background: none; text-align: left;
  font-size: 13px;
}
.tree-row:hover { background: #1d242e; color: var(--text); }
.tree-row.is-active { background: var(--accent-dim); color: #cfe6ff; }
.tree-row .twisty {
  width: 14px; flex: 0 0 14px; text-align: center;
  color: var(--text-faint); font-size: 10px;
}
.tree-row .label { flex: 1 1 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-row .count { font: 11px var(--mono); color: var(--text-faint); }
.tree-children { margin-left: 10px; border-left: 1px solid var(--line); }

.tag-cloud { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 12px; }
.tag-cloud .chip { font-size: 11px; }

/* ------------------------------------------------------------------ grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  padding: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
  display: flex; flex-direction: column;
}
.card:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.card.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.card-thumb {
  aspect-ratio: 1 / 1;
  background: var(--bg-sunken) center/cover no-repeat;
  display: grid; place-items: center;
  color: var(--text-faint);
  font-size: 11px;
  position: relative;
}
.card-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }

.card-body { padding: 7px 8px 9px; min-width: 0; }
.card-name {
  font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-folder {
  font: 10px/1.4 var(--mono);
  color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-tags { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 4px; }
.card-tags span {
  font-size: 10px; padding: 1px 5px; border-radius: 99px;
  background: var(--accent-dim); color: #b7d8ff;
}

.grid-status { padding: 0 12px 12px; color: var(--text-faint); font-size: 12px; }

/* ----------------------------------------------------------------- stage */
.stage { display: grid; grid-template-rows: 1fr auto; min-height: 0; min-width: 0; }

.canvas-host { position: relative; min-height: 0; background: var(--bg-sunken); }
.canvas-host canvas { display: block; width: 100%; height: 100%; }

.viewer-overlay {
  position: absolute; inset: 0;
  display: grid; place-content: center; justify-items: center; gap: 12px;
  color: var(--text-dim);
  background: rgba(10, 13, 17, .72);
  text-align: center; padding: 24px;
  pointer-events: none;
}
.viewer-overlay.error { color: var(--danger); pointer-events: auto; }
.viewer-overlay p { margin: 0; max-width: 44ch; }

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* With no 3D, the stage does not need to hog half the screen. */
.no-webgl { min-height: 180px; }
.no-webgl + .inspector { max-height: none; }

.viewer-hud {
  position: absolute; left: 12px; top: 10px;
  font: 11px var(--mono); color: var(--text-faint);
  pointer-events: none;
}

/* ------------------------------------------------------------ light rig */
.light-panel {
  position: absolute;
  top: 10px; right: 10px;
  width: 300px;
  max-height: calc(100% - 70px);
  overflow-y: auto;
  z-index: 4;
  background: rgba(21, 26, 33, .96);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px 12px;
  backdrop-filter: blur(6px);
}
.light-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.light-panel-head h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint);
}
.light-panel .muted { margin: 8px 0 0; }

.light-row-inline {
  display: flex; align-items: center; gap: 6px; margin-bottom: 7px;
}
.light-row-inline label { font-size: 11px; color: var(--text-dim); min-width: 62px; }
.light-row-inline select { flex: 1 1 auto; }
.light-row-inline output { font: 10px var(--mono); color: var(--text-faint); min-width: 30px; }

.light-panel select,
.light-panel input[type="color"] {
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 4px 5px; font-size: 11px;
}
.light-panel input[type="color"] { padding: 1px; width: 26px; height: 24px; cursor: pointer; }
.light-panel input[type="range"] { flex: 1 1 auto; accent-color: var(--accent); min-width: 0; }

.light-check {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-dim); margin-bottom: 9px;
}

.light-list { display: flex; flex-direction: column; gap: 7px; margin-bottom: 9px; }

.light-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px;
  background: var(--bg-sunken);
}
.light-item.is-off { opacity: .45; }
.light-item-head { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; }
.light-item-head select { flex: 1 1 auto; }
.light-axis {
  display: grid; grid-template-columns: 12px 1fr 32px;
  align-items: center; gap: 5px;
  font: 10px var(--mono); color: var(--text-faint);
}
.light-empty { font-size: 11px; color: var(--text-faint); }

@media (max-width: 900px) {
  .light-panel { position: static; width: auto; max-height: none; margin: 8px; }
}

.viewer-controls {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; gap: 5px; flex-wrap: wrap;
}

/* ------------------------------------------------------------- inspector */
.inspector {
  border-top: 1px solid var(--line);
  background: var(--panel);
  max-height: 46vh;
  overflow-y: auto;
  padding: 12px 16px 20px;
}
.inspector-empty { color: var(--text-faint); font-size: 13px; }

.inspector h3 {
  font-size: 15px;
  overflow-wrap: anywhere;
}
.inspector .path {
  font: 11px var(--mono); color: var(--text-dim);
  overflow-wrap: anywhere; margin: 2px 0 10px;
}

.insp-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 22px;
}
.insp-block h4 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-faint); margin: 0 0 6px;
}

.stat-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.stat {
  font: 11px var(--mono);
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 99px;
  color: var(--text-dim);
}
.stat b { color: var(--text); font-weight: 600; }
.stat.warn { border-color: var(--warn); color: var(--warn); }

.field { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.field label { font-size: 12px; color: var(--text-dim); min-width: 84px; }
.field select, .field input[type="range"] { flex: 1 1 auto; }
.field select {
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 5px 6px; font-size: 12px; max-width: 100%;
}

.code-block {
  position: relative;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: 11.5px/1.55 var(--mono);
  white-space: pre;
  overflow-x: auto;
  color: #b9c6d4;
}
.copy-row { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

.pack-btn {
  display: inline-block;
  text-decoration: none;
  margin-bottom: 6px;
}
.pack-note { font-size: 11px; color: var(--text-faint); font-family: var(--mono); }
.pack-missing { color: var(--warn); margin-top: 2px; cursor: help; }

/* ------------------------------------------------------- material browser */
.mat-card-thumb {
  aspect-ratio: 1 / 1;
  background: var(--bg-sunken) center/cover no-repeat;
  display: grid; place-items: center;
  image-rendering: pixelated;
}
.mat-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.tex-list { display: flex; flex-direction: column; gap: 6px; }
.tex-row {
  display: flex; gap: 8px; align-items: center;
  background: var(--bg-sunken); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 5px 7px;
}
.tex-row img {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 4px;
  object-fit: cover; background: #000; image-rendering: pixelated;
}
.tex-meta { min-width: 0; font-size: 11px; }
.tex-meta .r { color: var(--accent); font: 10px var(--mono); }
.tex-meta .p { font: 10px var(--mono); color: var(--text-faint); overflow-wrap: anywhere; }
.tex-meta .d { color: var(--text-dim); font: 10px var(--mono); }

.vmt-source {
  background: var(--bg-sunken); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 8px 10px;
  font: 11px/1.5 var(--mono); color: #b9c6d4;
  white-space: pre; overflow: auto; max-height: 220px;
}
.param-table { width: 100%; border-collapse: collapse; font: 11px var(--mono); }
.param-table td { padding: 2px 6px 2px 0; vertical-align: top; }
.param-table td:first-child { color: var(--accent); white-space: nowrap; }
.param-table td:last-child { color: var(--text-dim); overflow-wrap: anywhere; }

.mat-list { display: flex; flex-direction: column; gap: 6px; }
.mat {
  display: flex; gap: 8px; align-items: center;
  background: var(--bg-sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 7px;
}
.mat img {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 4px; object-fit: cover; background: #000;
  image-rendering: pixelated;
}
.mat-meta { min-width: 0; font-size: 11px; }
.mat-meta .n { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mat-meta .p { font: 10px var(--mono); color: var(--text-faint); overflow-wrap: anywhere; }
.mat.missing { border-color: var(--danger); }

.notes textarea {
  width: 100%; min-height: 64px; resize: vertical;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 7px 8px; font: inherit;
}
.notes input {
  width: 100%;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 6px 8px; font: inherit; margin-top: 6px;
}
.notes .muted { font-size: 11px; color: var(--text-faint); }

.warn-list { color: var(--warn); font-size: 12px; margin: 8px 0 0; padding-left: 18px; }

/* ----------------------------------------------------------------- login */
.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: auto;
}
.login-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px 24px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.login-brand h1 { font-size: 16px; }
.login-label {
  display: block; margin: 14px 0 5px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--text-faint);
}
.login-card input[type="password"] {
  width: 100%;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 9px 10px; font: inherit;
}
.login-card input[type="password"]:focus { outline: none; border-color: var(--accent); }
.login-error { color: var(--danger); font-size: 12px; margin: 9px 0 0; }
.login-submit { width: 100%; margin-top: 14px; padding: 9px; }

/* ---------------------------------------------------------------- dialog */
.dialog {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 18px 20px;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog input {
  width: 100%; margin: 10px 0 14px;
  background: var(--bg-sunken); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  padding: 8px; font: inherit;
}
.dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }
.muted { color: var(--text-dim); font-size: 12px; }

/* ----------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 9px 16px;
  box-shadow: var(--shadow);
  z-index: 50;
  font-size: 13px;
}
.toast.err { border-color: var(--danger); color: #ffc9d0; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 200px 280px 1fr; }
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; overflow-y: auto; }
  .sidebar { max-height: 180px; }
  .results { max-height: 300px; }
  .stage { min-height: 70vh; }
  .inspector { max-height: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
