*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] { display: none !important; }

:root {
  --bg:         #1a1a1e;
  --surface:    #25252b;
  --surface2:   #2e2e36;
  --border:     #3a3a46;
  --text:       #e0e0e8;
  --text-dim:   #888898;
  --accent:     #5d9cf5;
  --accent-dim: #3a6bbf;
  --selected:   rgba(93, 156, 245, 0.18);
  --selected-border: rgba(93, 156, 245, 0.5);
  --warning:    #e3b289;
  --font:  "Segoe UI", system-ui, sans-serif;
  --mono:  "Consolas", "Fira Code", monospace;
  --tree-w:  240px;
  --table-w: 1fr;
  --preview-w: 1fr;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font);
  font-size: 13px;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── TOP BAR ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.brand h1 {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.brand p {
  margin-top: 2px;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.load-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.url-group { display: flex; gap: 4px; }

.status-strip {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 480px;
}

/* ── ARCHIVE INFO BAR ─────────────────────────────────────────────────────── */
.archive-info-bar {
  padding: 4px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

/* ── FILTER BAR ───────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-icon { color: var(--text-dim); }

#search-input {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font);
  width: 200px;
}

#search-input:focus { outline: none; border-color: var(--accent-dim); }

/* ── MAIN TWO-COLUMN LAYOUT ───────────────────────────────────────────────── */
.main-layout {
  display: grid;
  grid-template-columns: var(--tree-w) 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.tree-panel {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
  min-width: 0;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

.preview-panel::after {
  content: "THE MONSTER TRUCK MADNESS GUILD";
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(120, 120, 130, 0.45);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  white-space: nowrap;
  pointer-events: none;
  z-index: 3;
}

/* ── FILE TREE ────────────────────────────────────────────────────────────── */
.file-tree-scroll { padding: 4px 0; }

.file-tree-root, .tree-children {
  list-style: none;
  margin: 0;
  padding: 0;
}

.tree-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
  user-select: none;
}

.tree-row:hover { background: var(--surface2); }

.tree-row.selected {
  background: var(--selected);
  outline: 1px solid var(--selected-border);
  outline-offset: -1px;
}

.tree-arrow { font-size: 9px; color: var(--text-dim); width: 12px; flex-shrink: 0; }
.tree-icon  { font-size: 13px; flex-shrink: 0; }
.tree-label { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.tree-badge {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--surface2);
  border-radius: 8px;
  padding: 1px 5px;
  flex-shrink: 0;
}

.tree-folder-row { color: var(--text); }
.tree-file-row   { color: var(--text-dim); }
.tree-file-row:hover, .tree-file-row.selected { color: var(--text); }

.file-icon { font-size: 13px; flex-shrink: 0; }

/* ── PREVIEW PANE ─────────────────────────────────────────────────────────── */
.preview-meta {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.meta-list {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 10px;
  row-gap: 2px;
  font-size: 12px;
  font-family: var(--mono);
}

.meta-list dt { color: var(--text-dim); white-space: nowrap; }
.meta-list dd { margin: 0; word-break: break-all; }

.meta-actions { margin-top: 6px; }

.preview-content {
  flex: 1;
  overflow: auto;
  padding: 10px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.preview-content.bin-active {
  padding: 0;
  overflow: hidden;
  align-items: stretch;
}

.preview-placeholder { color: var(--text-dim); font-size: 13px; }
.preview-error { color: var(--warning); font-size: 13px; }

/* ── RAW IMAGE PREVIEW ────────────────────────────────────────────────────── */
.raw-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 8px;
  flex-shrink: 0;
}
.raw-ctrl-label {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.raw-palette-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  font-family: var(--font);
  max-width: 200px;
}
.raw-wrap   { display: flex; flex-direction: column; gap: 6px; }
.raw-canvas { image-rendering: pixelated; max-width: 100%; }
.preview-info { font-size: 11px; color: var(--text-dim); font-family: var(--mono); }

/* ── ACT PALETTE PREVIEW ──────────────────────────────────────────────────── */
.act-wrap    { display: flex; flex-direction: column; gap: 6px; position: relative; }
.act-swatch  { cursor: crosshair; }
.act-tooltip {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(0,0,0,0.75);
  color: var(--text);
  font-size: 11px;
  font-family: var(--mono);
  padding: 3px 7px;
  border-radius: 4px;
  pointer-events: none;
}

/* ── TEXT PREVIEW ─────────────────────────────────────────────────────────── */
.text-preview {
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  line-height: 1.6;
}

/* ── HEX DUMP ─────────────────────────────────────────────────────────────── */
.hex-dump {
  font-family: var(--mono);
  font-size: 11px;
  white-space: pre;
  color: var(--text);
  line-height: 1.6;
}

/* ── BIN 3D PREVIEW ───────────────────────────────────────────────────────── */
.bin-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-dim);
}

.toggle-label:hover { color: var(--text); }

.bin-viewport {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.bin-viewport canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.bin-warnings {
  padding: 6px 10px;
  background: rgba(92, 56, 40, 0.28);
  border-top: 1px solid rgba(227, 178, 137, 0.34);
  color: var(--warning);
  font-size: 11px;
  flex-shrink: 0;
}

/* ── TEXTURE VIEWER (BIN preview) ────────────────────────────────────────── */
.tex-viewer {
  display: flex;
  gap: 6px;
  padding: 6px 8px 26px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  height: 112px;
  align-items: flex-start;
}

.tex-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
  cursor: default;
}

.tex-thumb {
  width: 64px;
  height: 64px;
  image-rendering: pixelated;
  border: 1px solid var(--border);
  background: #111;
}

.tex-thumb.missing {
  border-color: rgba(227, 178, 137, 0.4);
  opacity: 0.5;
}

.tex-item-clickable { cursor: pointer; }
.tex-item-clickable:hover .tex-thumb { outline: 2px solid var(--accent); outline-offset: 1px; }
.tex-item-clickable:hover .tex-label { color: var(--accent); }

.tex-label {
  font-size: 9px;
  font-family: var(--mono);
  color: var(--text-dim);
  max-width: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

/* Stats overlay — top-left corner, mirrors JTraxx3 ModelViewerDialog fields */
.bin-stats {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(15, 15, 20, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  padding: 6px 10px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  pointer-events: none;
  z-index: 2;
  max-width: 280px;
}

.bin-stat-row {
  display: flex;
  gap: 8px;
}

.bin-stat-key {
  color: var(--text-dim);
  min-width: 64px;
  flex-shrink: 0;
}

.bin-stat-val {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── WAV AUDIO PREVIEW ────────────────────────────────────────────────────── */
.wav-player {
  width: 100%;
  max-width: 480px;
  margin-top: 8px;
}


/* ── IMAGE PREVIEW ────────────────────────────────────────────────────────── */
.image-preview {
  max-width: 100%;
  image-rendering: pixelated;
  border: 1px solid var(--border);
}

/* ── MODAL ────────────────────────────────────────────────────────────────── */
.main-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  min-width: 340px;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
}

.main-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }

.modal-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--accent);
}

.modal-body { margin-bottom: 14px; }

.modal-field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  margin-bottom: 4px;
  margin-top: 10px;
}

.modal-field-label:first-child { margin-top: 0; }

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

.modal-input {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 12px;
}

.dim-input { width: 70px; }

.modal-select {
  width: 100%;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--font);
}

.modal-hint { font-size: 11px; color: var(--text-dim); margin: 8px 0 4px; }

.dim-suggestions { display: flex; flex-wrap: wrap; gap: 4px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── LOADING OVERLAY ──────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  z-index: 100;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
button {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font);
  white-space: nowrap;
}

button:hover    { background: var(--border); }
button.quiet    { color: var(--text-dim); font-size: 11px; }
button.btn-primary {
  background: var(--accent-dim);
  color: #fff;
  border-color: var(--accent);
}
button.btn-primary:hover { background: var(--accent); }
button.btn-small { font-size: 11px; padding: 2px 7px; }

button:disabled, input:disabled, select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:focus-visible, input:focus-visible, select:focus-visible {
  outline: none;
  border-color: var(--accent-dim);
}

input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }
input[type="number"]   { accent-color: var(--accent); }

input[type="search"] {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font);
  width: 200px;
}

input[type="url"] {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 12px;
  font-family: var(--mono);
  width: 260px;
}

/* ── RESPONSIVE ───────────────────────────────────────────────────────────── */
@media (max-width: 1080px) {
  .status-strip { max-width: 240px; }
  :root { --tree-w: 200px; }
}

@media (max-width: 600px) {
  .main-layout {
    grid-template-columns: 1fr;
  }
  .tree-panel       { display: none; }
  .preview-panel    { min-height: 300px; }
  input[type="url"] { width: 100%; }
}
