/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; font-family: 'JetBrains Mono', monospace; font-size: 13px; color: var(--text); background: var(--bg); }

/* ── Layout ── */
#app { display: flex; flex-direction: column; height: 100vh; }

#header {
  height: var(--header-h); min-height: var(--header-h);
  display: flex; align-items: center; gap: 16px; padding: 0 16px;
  background: var(--bg1); border-bottom: 1px solid var(--border);
  position: relative; z-index: 10;
}

#header h1 { font-family: 'Syne', sans-serif; font-size: 15px; font-weight: 700; color: var(--accent); letter-spacing: 0.04em; white-space: nowrap; }
#header h1 span { color: var(--text-dim); font-weight: 400; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-left: auto; }

.btn {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 5px; cursor: pointer; user-select: none;
  font-family: 'JetBrains Mono', monospace; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border2); background: var(--bg2); color: var(--text);
  transition: all .15s;
}
.btn:hover { background: var(--bg3); border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #5baeff; }

#search-wrap { position: relative; display: flex; align-items: center; gap: 0; }
#search {
  width: 340px; padding: 5px 10px 5px 30px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 5px 0 0 5px; border-right: none;
  color: var(--text); font-family: 'JetBrains Mono', monospace; font-size: 12px;
  outline: none; transition: border-color .15s;
}
#search:focus { border-color: var(--accent); }
#search::placeholder { color: var(--text-mute); }
#search.regex-active { border-color: var(--amber); }
#search-icon { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); color: var(--text-mute); pointer-events: none; }
#search-clear {
  height: 28px; width: 26px; flex-shrink: 0;
  background: var(--bg2);
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); border-left: none; border-right: 1px solid var(--border);
  color: var(--text-mute); cursor: pointer; font-size: 11px;
  display: none; align-items: center; justify-content: center;
  transition: color .15s, background .15s;
}
#search-clear:hover { color: var(--text); background: var(--bg3); }
#search-clear.visible { display: flex; }
#btn-regex {
  height: 28px; padding: 0 8px; flex-shrink: 0;
  background: var(--bg2); border: 1px solid var(--border); border-left: 1px solid var(--border2);
  border-radius: 0 5px 5px 0; cursor: pointer;
  font-family: 'JetBrains Mono', monospace; font-size: 11px; font-weight: 500;
  color: var(--text-mute); user-select: none; transition: all .15s;
  display: flex; align-items: center;
}
#btn-regex:hover { color: var(--text); background: var(--bg3); }
#btn-regex.active { color: var(--amber); border-color: var(--amber); background: rgba(232,166,48,0.08); }

/* ── Main area ── */
#main { display: flex; flex: 1; min-height: 0; }

/* ── Tree panel ── */
#tree-panel {
  width: var(--sidebar); min-width: 180px; max-width: 600px;
  display: flex; flex-direction: column;
  background: var(--bg1); border-right: 1px solid var(--border);
  overflow: hidden; position: relative;
}

#tree-header {
  padding: 8px 12px 6px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
#tree-header .label { color: var(--text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; }
#tree-header .count { margin-left: auto; color: var(--text-mute); font-size: 11px; }

#tree-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 0; }

/* Resizer */
#resizer {
  width: 4px; cursor: col-resize; background: var(--border);
  flex-shrink: 0; transition: background .15s;
  position: relative; z-index: 5;
}
#resizer:hover, #resizer.dragging { background: var(--accent); }

/* ── Detail panel ── */
#detail-panel {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden;
}

/* Breadcrumb */
#breadcrumb {
  height: 34px; display: flex; align-items: center; gap: 0;
  padding: 0 14px; border-bottom: 1px solid var(--border);
  background: var(--bg1); overflow: hidden; flex-shrink: 0;
}
.bc-sep { color: var(--text-mute); margin: 0 4px; font-size: 10px; }
.bc-item { color: var(--text-dim); font-size: 12px; cursor: pointer; padding: 2px 4px; border-radius: 3px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.bc-item:hover { color: var(--accent); }
.bc-item.current { color: var(--text); cursor: default; }
.bc-item.current:hover { color: var(--text); }

/* Content list */
#content-list { flex: 1; overflow-y: auto; overflow-x: hidden; }

/* Column header */
#col-header {
  display: grid; grid-template-columns: 1fr 100px 140px 90px;
  padding: 0 12px; height: 28px; align-items: center;
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2;
  background: var(--bg1); flex-shrink: 0; user-select: none;
}
.col-h { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.07em; cursor: pointer; display: flex; align-items: center; gap: 4px; }
.col-h:hover { color: var(--text); }
.col-h.sorted { color: var(--accent); }
.sort-arrow { font-size: 9px; }

/* List rows */
.list-row {
  display: grid; grid-template-columns: 1fr 100px 140px 90px;
  padding: 0 12px; height: var(--row-h); align-items: center;
  border-bottom: 1px solid rgba(37,45,58,0.4); cursor: pointer;
  transition: background .08s;
}
.list-row:hover { background: var(--hover); }
.list-row.selected { background: var(--selected); }
.list-row .name-cell { display: flex; align-items: center; gap: 8px; overflow: hidden; }
.list-row .name-cell span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-row .type-cell { color: var(--text-dim); font-size: 11px; }
.list-row .date-cell { color: var(--text-dim); font-size: 11px; }
.list-row .count-cell { color: var(--text-mute); font-size: 11px; text-align: right; }

/* Item icons — monochrome SVG via CSS */
.icon { width: 16px; height: 16px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }

/* ── Side detail pane ── */
#detail-side {
  width: 260px; min-width: 200px; max-width: 400px;
  background: var(--bg1); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0;
}
#detail-side.hidden { display: none; }

#detail-side-header { padding: 12px 14px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
#detail-side-header .ds-icon { width: 32px; height: 32px; margin-bottom: 8px; }
#detail-side-header .ds-name { font-family: 'Syne', sans-serif; font-size: 14px; font-weight: 600; color: var(--text); word-break: break-all; line-height: 1.3; }
#detail-side-header .ds-type { margin-top: 4px; font-size: 11px; color: var(--text-dim); }

#detail-side-body { flex: 1; overflow-y: auto; padding: 10px 14px; display: flex; flex-direction: column; gap: 10px; }

.detail-group { display: flex; flex-direction: column; gap: 4px; }
.detail-group .dg-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-mute); }
.detail-group .dg-value { font-size: 12px; color: var(--text); word-break: break-all; }
.detail-group .dg-value.uuid { font-size: 10px; color: var(--text-dim); }
.detail-group .dg-value.count { color: var(--accent); font-size: 15px; font-weight: 500; }
.perm-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.perm-tag { padding: 2px 6px; border-radius: 3px; font-size: 10px; background: var(--bg2); border: 1px solid var(--border2); color: var(--text-dim); }
.perm-tag.on { color: var(--green); border-color: var(--green); background: rgba(61,186,127,0.08); }

/* ── Status bar ── */
#status {
  height: var(--status-h); min-height: var(--status-h);
  display: flex; align-items: center; gap: 16px; padding: 0 14px;
  background: var(--bg1); border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text-mute);
}
#status .s-accent { color: var(--accent); }
#status .s-right { margin-left: auto; display: flex; gap: 12px; }

/* ── Tree nodes ── */
.tree-node { display: flex; flex-direction: column; }
.tree-node-row {
  display: flex; align-items: center; height: 24px; padding-right: 8px;
  cursor: pointer; user-select: none; border-radius: 4px; margin: 0 4px;
  transition: background .08s;
}
.tree-node-row:hover { background: var(--hover); }
.tree-node-row.selected { background: var(--selected); }
.tree-expand { width: 18px; height: 24px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--text-mute); font-size: 9px; }
.tree-expand:hover { color: var(--text-dim); }
.tree-node-row .icon { margin-right: 5px; flex-shrink: 0; }
.tree-node-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.tree-node-count { font-size: 10px; color: var(--text-mute); margin-left: 4px; }
.tree-children { padding-left: 0; }

/* ── Drop zone ── */
#drop-zone {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  background: var(--bg); z-index: 100;
}
#drop-zone.hidden { display: none; }
#drop-zone .dz-inner {
  border: 2px dashed var(--border2); border-radius: 16px;
  padding: 48px 64px; display: flex; flex-direction: column; align-items: center; gap: 16px;
  transition: all .2s;
}
#drop-zone.drag-over .dz-inner { border-color: var(--accent); background: var(--accent-glow); }
#drop-zone .dz-title { font-family: 'Syne', sans-serif; font-size: 22px; font-weight: 700; color: var(--text); }
#drop-zone .dz-sub { color: var(--text-dim); font-size: 12px; text-align: center; line-height: 1.6; }
#drop-zone .dz-formats { display: flex; gap: 8px; margin-top: 4px; }
.fmt-tag { padding: 3px 10px; border-radius: 4px; font-size: 11px; border: 1px solid var(--border2); color: var(--text-dim); background: var(--bg2); }

/* ── Progress overlay ── */
#progress {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 20px;
  background: rgba(13,15,18,0.92); z-index: 200;
}
#progress.hidden { display: none; }
#progress .p-label { font-family: 'Syne', sans-serif; font-size: 16px; color: var(--text); }
#progress .p-sub { font-size: 12px; color: var(--text-dim); }
.progress-bar { width: 320px; height: 3px; background: var(--bg3); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width .1s; }

/* ── Scrollbars ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-mute); }

/* ── Empty state ── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 8px; color: var(--text-mute); }
.empty-state .es-icon { font-size: 32px; margin-bottom: 4px; opacity: 0.4; }
.empty-state .es-text { font-size: 12px; }

/* ── Search highlight ── */
.hl { color: var(--amber); background: rgba(232,166,48,0.12); border-radius: 2px; padding: 0 1px; }

/* ── View toggle buttons ── */
.view-toggle { display: flex; border: 1px solid var(--border2); border-radius: 5px; overflow: hidden; }
.view-btn {
  width: 30px; height: 28px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; background: var(--bg2); color: var(--text-mute);
  border: none; transition: all .15s; font-size: 14px;
}
.view-btn:hover { background: var(--bg3); color: var(--text); }
.view-btn.active { background: var(--bg3); color: var(--accent); }

/* ── Icons grid view ── */

.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(var(--icon-sz) + 24px), 1fr));
  gap: 6px; padding: 10px;
}

.icon-cell {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 6px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; transition: background .1s, border-color .1s;
  position: relative; user-select: none;
}
.icon-cell:hover { background: var(--hover); border-color: var(--border); }
.icon-cell.selected { background: var(--selected); border-color: var(--accent); }

/* Folder icon wrap — the SVG IS the visual, no extra box */
.folder-icon-wrap {
  width: var(--icon-sz); height: var(--icon-sz-h);
  flex-shrink: 0; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: center;
}
.folder-icon-wrap svg { display: block; width: 100%; height: 100%; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.4)); }

.thumb-box {
  width: var(--icon-sz); height: var(--icon-sz-h);
  border-radius: 6px; overflow: hidden;
  background: var(--bg2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  position: relative; flex-shrink: 0; margin-bottom: 8px;
}
.thumb-box img {
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .3s;
}
.thumb-box img.loaded { opacity: 1; }
.thumb-box .thumb-icon {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  transition: opacity .2s;
}
.thumb-box.img-loaded .thumb-icon { opacity: 0; pointer-events: none; }

/* Folder: big icon + mini preview peek in lower-right corner */
.folder-mini {
  position: absolute; bottom: 4px; right: 4px;
  width: 42px; height: 32px; border-radius: 3px;
  overflow: hidden; border: 1px solid var(--border2); background: var(--bg3);
}
.folder-mini img {
  width: 100%; height: 100%; object-fit: cover;
  opacity: 0; transition: opacity .3s;
}
.folder-mini img.loaded { opacity: 1; }

.icon-cell .icon-label {
  font-size: 11px; color: var(--text); text-align: center;
  max-width: calc(var(--icon-sz) + 8px); overflow: hidden; text-overflow: ellipsis;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  line-height: 1.35; word-break: break-word;
}
.icon-cell .icon-type { font-size: 10px; color: var(--text-mute); margin-top: 2px; }

@keyframes spin { to { transform: rotate(360deg); } }
.thumb-spin {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--border2); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}

/* ── Icon size slider ── */
.size-slider-wrap {
  display: flex; align-items: center; gap: 6px;
  padding: 0 8px; border: 1px solid var(--border2); border-radius: 5px;
  background: var(--bg2); height: 28px;
}
.size-slider-wrap.hidden { display: none; }
#icon-size-slider {
  -webkit-appearance: none; appearance: none;
  width: 80px; height: 3px; border-radius: 2px;
  background: var(--border2); outline: none; cursor: pointer;
}
#icon-size-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
  border: none;
}
#icon-size-slider::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: none;
}

/* ── Lightbox ── */
#lightbox {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
#lightbox.hidden { display: none; }
#lightbox-bg {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(6px);
  cursor: zoom-out;
}
#lightbox-inner {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  max-width: 90vw; max-height: 90vh;
  animation: lb-in .18s ease;
}
@keyframes lb-in {
  from { opacity: 0; transform: scale(.94); }
  to   { opacity: 1; transform: scale(1); }
}
#lightbox-img {
  max-width: 85vw; max-height: 80vh;
  border-radius: 6px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7);
  object-fit: contain;
  background: var(--bg2);
  display: block;
}
#lightbox-name {
  color: var(--text); font-size: 13px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
#lightbox-close {
  position: absolute; top: -14px; right: -14px;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg2); border: 1px solid var(--border2);
  color: var(--text-dim); font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all .15s;
}
#lightbox-close:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Type filter panel ── */
#filter-bar {
  background: var(--bg1); border-bottom: 1px solid var(--border);
  overflow: hidden; max-height: 0; transition: max-height .22s ease;
  flex-shrink: 0;
}
#filter-bar.open { max-height: 200px; overflow-y: auto; }
#filter-inner { padding: 8px 14px 10px; display: flex; flex-direction: column; gap: 5px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.filter-row-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-mute); width: 52px; flex-shrink: 0;
}
.fchip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px 2px 5px; border-radius: 4px; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg2);
  font-size: 11px; color: var(--text-dim); user-select: none;
  transition: all .12s;
}
.fchip:hover { border-color: var(--border2); color: var(--text); }
.fchip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-glow); }
.fchip-icon { width: 13px; height: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.filter-footer { display: flex; gap: 10px; padding-top: 2px; }
.filter-link { font-size: 11px; color: var(--text-mute); cursor: pointer; }
.filter-link:hover { color: var(--accent); }
#btn-filter { position: relative; }
#btn-filter.has-filter { color: var(--accent); border-color: var(--accent); }
#filter-badge {
  display: none; position: absolute; top: -4px; right: -4px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  border: 1px solid var(--bg1);
}
#btn-filter.has-filter #filter-badge { display: block; }

/* ── Parse filter modal ── */
#parse-modal {
  position: fixed; inset: 0; z-index: 500;
  display: flex; align-items: center; justify-content: center;
}
#parse-modal.hidden { display: none; }
#parse-modal-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); }
#parse-modal-box {
  position: relative; z-index: 1;
  background: var(--bg1); border: 1px solid var(--border2); border-radius: 12px;
  padding: 24px 28px; width: 480px; max-width: 95vw;
  animation: lb-in .18s ease;
  display: flex; flex-direction: column; gap: 16px;
}
#parse-modal-box h2 { font-family: 'Syne', sans-serif; font-size: 16px; font-weight: 700; color: var(--text); }
#parse-modal-box .pm-sub { font-size: 12px; color: var(--text-dim); line-height: 1.5; }
.pm-group { display: flex; flex-direction: column; gap: 6px; }
.pm-group-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-mute); }
.pm-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.pm-footer { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }
.pm-footer .btn { min-width: 80px; justify-content: center; }

@media (max-width: 700px) {
  #detail-side { display: none; }
}
