/* AshenItems Catalog - dashboard-hosted editor styles.
   Shares the visual language of cinematics.css (same palette + form/panel/
   button system) so the Items Editor reads as part of the same suite. */

:root {
  /* Staff-ledger variant: re-source the editor palette onto the shared
     dashboard theme tokens (theme.css) - parchment surfaces, launcher ink,
     gold accent. Interior drafting-table inlays keep their dark hexes. */
  --bg: var(--ashen-canvas);
  --bg-2: var(--ashen-canvas-deep);
  --panel: var(--ashen-panel);
  --panel-2: var(--ashen-panel-strong);
  --border: var(--ashen-hairline);
  --border-2: var(--ashen-hairline-strong);
  --text: var(--ashen-ink);
  --muted: var(--ashen-ink-muted);
  --accent: var(--ashen-accent);
  --accent-2: var(--ashen-accent-text);
  --accent-dim: var(--ashen-accent-dim);
  --green: var(--ashen-emerald);
  --red: var(--ashen-red);
  --radius: 12px;
  --font: var(--ashen-body);
}

html,
body,
main,
#app,
.layout,
#editor {
  background: var(--bg);
}

#app { min-height: calc(100vh - 64px); }

/* Keep this state helper scoped. A global `.hidden` rule would override
   Tailwind's responsive `hidden md:flex` nav utility and hide the tabs. */
#app.hidden,
#app .hidden { display: none !important; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }

/* ------------------------------------------------------------ editor header */

.cinema-header {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: rgba(20, 16, 31, 0.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  position: sticky;
  top: 64px; /* below the dashboard nav */
  z-index: 10;
}

.brand { font-size: 15px; font-weight: 700; letter-spacing: 0.3px; display: flex; align-items: center; gap: 8px; }
.brand-mark { font-size: 17px; }
.brand .sub { color: var(--accent-2); font-weight: 600; font-size: 13px; }

.header-right { display: flex; align-items: center; gap: 8px; }
.server-tag {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  background: var(--bg-2);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------------------------------------------ layout */

.layout {
  display: flex;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 64px - 54px);
  min-height: 480px;
}

/* ---------------------------------------------------------------- sidebar */

#sidebar {
  width: 100%;
  flex: 1;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.catalog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px;
  border-bottom: 1px solid var(--border);
}
.catalog-eyebrow { color: var(--accent-2); font-size: 11px; font-weight: 800; letter-spacing: 1.4px; text-transform: uppercase; }
.catalog-toolbar h1 { margin: 4px 0 3px; font-size: 26px; color: var(--text); }
.catalog-toolbar p { margin: 0; color: var(--muted); font-size: 13px; }
.toolbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.catalog-filter { display: flex; gap: 10px; align-items: center; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--panel-soft); }
.search-box { display: flex; align-items: center; gap: 8px; flex: 1; max-width: 520px; background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 9px; padding: 0 11px; color: var(--muted); }
.search-box input { border: 0; outline: 0; background: transparent; color: var(--text); width: 100%; padding: 9px 0; font-size: 13px; }
#item-list { flex: 1; overflow-y: auto; padding: 24px 28px 36px; }
/* -------------------------------------------- catalog category tree
   Two-level T&L-style tree: Equipment (main) ▸ Weapons/Armor/Accessories
   ▸ leaves, mirroring the skills editor's weapon-tree + slot library. */

.item-tree {
  margin-bottom: 22px;
  padding: 12px;
  border: 1px solid var(--border-2);
  border-radius: 12px;
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
}
.tree-group { margin-bottom: 2px; }
.tree-group:last-child { margin-bottom: 0; }
.tree-main-head, .tree-type-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
  transition: background .12s;
}
.tree-main-head:hover, .tree-type-head:hover { background: var(--panel-soft); }
.tree-main-head { font-size: 13.5px; font-weight: 800; color: var(--accent-2); text-transform: uppercase; letter-spacing: .8px; }
.tree-type-head { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-top: 2px; }
.tree-main-icon, .tree-type-icon { font-size: 15px; flex: none; }
.tree-chevron { width: 12px; flex: none; font-size: 10px; color: var(--muted); transition: transform .15s; }
.tree-count { margin-left: auto; color: var(--muted); font-size: 11px; font-weight: 500; }
.tree-children { margin: 2px 0 4px 16px; display: flex; flex-direction: column; gap: 3px; }
.tree-leaf {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  transition: border-color .12s, background .12s, transform .1s;
}
.tree-leaf:hover { background: var(--accent-dim); border-color: var(--border-2); transform: translateX(2px); }
.tree-leaf.selected { border-color: var(--accent); background: var(--accent-dim); box-shadow: 0 0 0 1px rgba(241, 65, 94, .25) inset; }
.tree-leaf .tree-leaf-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-leaf .tree-count { margin-left: auto; }
.tree-leaf.legacy { color: var(--muted); font-style: italic; }

/* Selected-leaf item list header (label + count + create button). */
.catalog-leaf { margin: 0 0 14px; }
.catalog-leaf-head { display: flex; align-items: center; gap: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--border-2); }
.catalog-leaf-title { font-size: 16px; font-weight: 700; color: var(--text); }
.catalog-leaf-count { color: var(--muted); font-size: 12px; }
.catalog-leaf-spacer { flex: 1; }
.category-empty { min-height: 260px; }

.layout.mode-editor #sidebar { display: none; }
.layout.mode-editor #editor { flex: 1; width: 100%; padding: 4px 0 24px; }
.layout.mode-catalog #editor { display: none; }

.catalog-type { margin-bottom: 30px; }
.catalog-type-head { display: flex; align-items: baseline; gap: 10px; border-bottom: 1px solid var(--border-2); padding-bottom: 10px; margin-bottom: 16px; }
.catalog-type-head h2 { margin: 0; font-size: 18px; color: var(--text); }
.catalog-type-count { color: var(--muted); font-size: 12px; }
.catalog-category { margin-bottom: 22px; }
.catalog-category-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.catalog-category-head h3 { margin: 0; color: var(--accent-2); font-size: 12px; text-transform: uppercase; letter-spacing: .8px; }
.catalog-category-head span { color: var(--muted); font-size: 11px; }
.catalog-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.catalog-card-category { margin-top: 4px; color: var(--accent-2); font-size: 11px; text-transform: capitalize; }
.catalog-card { min-height: 92px; display: flex; flex-direction: row; align-items: center; gap: 12px; margin: 0; padding: 14px; }
.catalog-card-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; background: var(--panel-soft); border: 1px solid var(--border); font-size: 21px; flex: none; }
.catalog-card-body { min-width: 0; flex: 1; }
.catalog-card .seq-name { padding-right: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.catalog-badges { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 6px; }
.catalog-empty { min-height: 360px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--muted); }
.catalog-empty .empty-logo { margin-bottom: 8px; }
.catalog-empty h2 { color: var(--text); margin: 0 0 6px; }
.catalog-empty p { margin: 0; font-size: 13px; }

.seq-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s, transform 0.12s;
  background: var(--panel-2);
}
.seq-item:hover { border-color: var(--border-2); background: var(--panel-soft); }
.seq-item.active { border-color: var(--accent); background: var(--accent-dim); box-shadow: 0 0 0 1px var(--accent) inset; }

.seq-name { font-weight: 600; font-size: 13.5px; word-break: break-all; padding-right: 22px; }
.seq-meta { font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.seq-del {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.12s;
}
.seq-item:hover .seq-del { opacity: 1; }

.seq-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 24px 10px; }

/* ------------------------------------------------------------------ editor */

#editor {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 4px 4px 24px 0;
  background: var(--bg);
  border-radius: var(--radius);
}

.empty {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.empty-logo { font-size: 52px; margin-bottom: 10px; opacity: 0.7; }
.empty h2 { margin: 0 0 6px; color: var(--text); }

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.title-block h2 { margin: 0 0 6px; font-size: 20px; word-break: break-all; }
.title-block h2 .crumb {
  color: var(--accent-2);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .4px;
  text-transform: none;
  margin-right: 6px;
  vertical-align: middle;
}

.chip {
  display: inline-block;
  font-size: 11.5px;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-2);
  color: var(--muted);
  background: var(--bg-2);
  margin-right: 6px;
  vertical-align: middle;
}
.chip-ok { color: var(--green); border-color: rgba(95, 191, 143, 0.45); }
.chip-error { color: var(--red); border-color: rgba(226, 85, 85, 0.45); }
.chip-dirty { color: var(--accent-2); border-color: rgba(241, 65, 94, 0.5); }

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

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.panel h3 { margin: 0 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--accent-2); display: flex; align-items: center; gap: 8px; }
.panel .hint { color: var(--muted); font-size: 12.5px; margin: -6px 0 12px; line-height: 1.5; }
.count { color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ forms */

.flag-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 14px; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
/* Reserve the same label height in the Basic grid so helper text wrapping
   does not push only some controls lower than their neighbors. */
.field-label { display: block; min-height: 30px; line-height: 15px; }
.field input, .field select, .field textarea {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  width: 100%;
  font-family: var(--font);
}
.field textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.field .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* --------------------------------------------------------------- stat rows */

.kv-list { display: flex; flex-direction: column; gap: 8px; }
.kv-row { display: flex; gap: 8px; align-items: center; }
.kv-row input, .kv-row select {
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
}
.kv-row select { cursor: pointer; }
.kv-row input.kv-key, .kv-row select.kv-key { flex: 1; min-width: 0; }
.kv-row input.kv-val { flex: 1; min-width: 0; }
.kv-row input:focus, .kv-row select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* ------------------------------------------------------------ stats tab */
/* One Stats panel mirroring the in-game character-menu sheet: collapsible
   category cards (Weapons / Defense / Attack / Protection / Body, plus
   Attribute bonuses and the free-form Vanilla attributes list). */
.stats-tab-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.stats-tab-head .hint { flex: 1; min-width: 240px; margin: 0; }
.stat-section {
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: var(--panel-2);
  margin-bottom: 10px;
  overflow: hidden;
}
.stat-section > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.stat-section > summary::-webkit-details-marker { display: none; }
.stat-section > summary::before { content: '▸'; color: var(--muted); font-size: 11px; transition: transform 0.15s; }
.stat-section[open] > summary::before { transform: rotate(90deg); }
.stat-section > summary:hover { background: rgba(255, 255, 255, 0.03); }
.stat-section > summary .stat-section-title { flex: 1; }
.stat-section > summary .count { font-size: 11px; font-weight: 500; }
.stat-section > .hint { margin: 0 14px 12px; }
.stat-section > .field-grid { padding: 0 14px 4px; }
.stat-section > .stat-hints { padding: 0 14px 14px; }
.vanilla-head { display: flex; justify-content: flex-end; margin: 0 14px 8px; }

/* ------------------------------------------------------------------ look */

.look-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

/* Segmented model-source control */
.look-source { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.look-source-btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  flex: 1 1 170px; max-width: 250px;
  padding: 10px 12px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.look-source-btn:hover { border-color: var(--accent); }
.look-source-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  box-shadow: 0 0 0 1px rgba(241, 65, 94, .3) inset;
}
.look-source-icon { font-size: 16px; }
.look-source-label { font-size: 13px; font-weight: 700; }
.look-source-sub { font-size: 11px; color: var(--muted); }

/* Hotbar-icon sub-editor under Vanilla model: sprite vs uploaded PNG */
.hotbar-mode { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.hotbar-mode .look-source-btn { flex: 1 1 160px; }
.hotbar-sub { margin-bottom: 4px; }

/* Dynamic per-source panel */
.look-panel {
  border: 1px dashed var(--border-2);
  border-radius: 10px;
  padding: 12px;
  background: var(--accent-dim);
  margin-bottom: 14px;
}
.look-panel.hidden { display: none; }

/* Locked notice shown while a Hotbar look override is active - the model
   tabs are hidden because the override rewrites the model field, so they'd
   otherwise flip on every hotbar click. */
.look-locked {
  border: 1px dashed var(--border-2);
  border-radius: 10px;
  padding: 12px;
  background: var(--accent-dim);
  margin-bottom: 14px;
  color: var(--accent-2);
  font-size: 12.5px;
  line-height: 1.5;
}
.look-locked strong { color: var(--text); }

/* AshenPack model picker */
.model-picker-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: 8px;
  padding: 0 10px;
  margin-bottom: 10px;
  color: var(--muted);
}
.model-picker-search input { border: 0; outline: 0; background: transparent; color: var(--text); width: 100%; padding: 8px 0; font-size: 13px; }
.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}
.model-card {
  position: relative;
  display: flex; flex-direction: column; gap: 3px;
  padding: 8px 10px;
  border: 1px solid var(--border-2);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-family: var(--font);
  transition: border-color .12s, background .12s;
}
.model-card:hover { border-color: var(--accent); }
.model-card.selected { border-color: var(--accent); background: var(--accent-dim); }
.model-card-name { font-size: 12.5px; font-weight: 700; text-transform: capitalize; }
.model-card-loc { font-size: 10.5px; color: var(--muted); word-break: break-all; }
.model-card-check { position: absolute; top: 6px; right: 8px; color: var(--accent-2); font-weight: 800; }
.model-picker-empty { padding: 18px 10px; text-align: center; color: var(--muted); font-size: 12px; }

/* Clickable + droppable texture preview */
.texture-preview {
  width: 88px;
  height: 88px;
  border: 1px solid var(--border-2);
  border-radius: 10px;
  background: repeating-conic-gradient(var(--ashen-canvas-deep) 0 25%, var(--ashen-panel) 0 50%) 0 0 / 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex: none;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.texture-preview:hover, .texture-preview:focus-visible { border-color: var(--accent); outline: none; }
.texture-preview.drag { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.texture-preview img { image-rendering: pixelated; max-width: 100%; max-height: 100%; }
.texture-preview.empty { color: var(--muted); font-size: 11px; text-align: center; line-height: 1.35; }

/* ------------------------------------------------------------- errors etc. */

.errors {
  background: rgba(181, 66, 46, 0.1);
  border: 1px solid rgba(181, 66, 46, 0.45);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
  color: var(--red);
  font-size: 13px;
}
.errors ul { margin: 6px 0 0; padding-left: 20px; }
.errors li { margin-bottom: 2px; }

/* -------------------------------------------------- derived lore preview */

.lore-preview-wrap { margin-top: 14px; }
.lore-preview-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 8px;
}
.lore-preview-title .muted { font-weight: 400; text-transform: none; letter-spacing: 0; }
.mc-tooltip {
  background: var(--panel);
  border: 2px solid var(--border-2);
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 12.5px;
  line-height: 1.75;
  max-width: 460px;
  display: inline-block;
  box-shadow: 0 4px 18px rgba(43, 33, 22, 0.2);
}
.mc-tooltip-line { white-space: nowrap; }
.mc-tooltip-empty { color: var(--muted); font-size: 12px; font-style: italic; }

/* toasts live in theme.css (canonical #toasts/.toast system) */

/* ------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  .tree-children { margin-left: 8px; }

  .layout { flex-direction: column; height: auto; }
  .catalog-toolbar { align-items: flex-start; flex-direction: column; padding: 20px; }
  .catalog-filter, #item-list { padding-left: 20px; padding-right: 20px; }
  #editor { overflow: visible; }
  .editor-head { flex-direction: column; }
  .toolbar { width: 100%; justify-content: flex-start; }
}
