:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --bg-panel: #1b2029;
  --bg-hover: #232936;
  --border: #2a3140;
  --text: #e6e9ef;
  --text-dim: #8b95a7;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.15);
  --dir: #ffc46b;
  --file: #7dd3fc;
  --danger: #f87171;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------------- 布局 ---------------- */
.app { display: grid; grid-template-columns: 250px 1fr; height: 100%; }
.app.with-preview { grid-template-columns: 250px 1fr 380px; }

/* ---------------- 侧边栏 ---------------- */
.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px; }
.logo { font-size: 20px; }
.sidebar-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.sidebar-title strong { font-size: 14px; }
.sidebar-title small {
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-search { padding: 0 12px 10px; }
.sidebar-search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  outline: none;
}
.sidebar-search input:focus { border-color: var(--accent); }

.tree { flex: 1; overflow: auto; padding: 4px 8px 12px; }
.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: var(--accent-soft); color: #cfe0ff; }
.tree-item .caret { width: 12px; color: var(--text-dim); font-size: 10px; transition: transform .15s; }
.tree-item .caret.open { transform: rotate(90deg); }
.tree-item .tname { overflow: hidden; text-overflow: ellipsis; }
.tree-children { margin-left: 12px; border-left: 1px solid var(--border); padding-left: 4px; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 14px; color: var(--text-dim); font-size: 12px; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---------------- 工具栏 ---------------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  color: var(--text-dim);
  line-height: 1;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent); border-color: rgba(76,141,255,.35); }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}
.breadcrumb::-webkit-scrollbar { display: none; }
.crumb { padding: 4px 8px; border-radius: 6px; cursor: pointer; color: var(--text-dim); flex: none; }
.crumb:hover { background: var(--bg-hover); color: var(--text); }
.crumb.current { color: var(--text); font-weight: 600; }
.crumb-sep { color: var(--border); flex: none; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding-left: 10px;
  flex: none;
  width: 260px;
}
.search-box input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; padding: 6px 0; }
.view-toggle { display: flex; gap: 2px; flex: none; }

/* ---------------- 内容区 ---------------- */
.content { flex: 1; overflow: auto; padding: 12px 14px 40px; min-height: 0; }
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 12px;
  padding-bottom: 10px;
  flex-wrap: wrap;
}
.status-right { display: flex; gap: 12px; align-items: center; }
.select-wrap { display: inline-flex; align-items: center; gap: 6px; }
.select-wrap select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 6px;
  outline: none;
}

.message {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 12px;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  white-space: pre-wrap;
}
.message.info { background: var(--accent-soft); border-color: rgba(76, 141, 255, 0.35); color: #cfe0ff; }

/* ---------------- 列表视图 ---------------- */
.listing.list { display: flex; flex-direction: column; gap: 2px; }
.list-header {
  display: grid;
  grid-template-columns: 1fr 110px 170px 34px;
  gap: 10px;
  padding: 6px 10px;
  color: var(--text-dim);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}
.list-header span { cursor: pointer; user-select: none; }
.list-header span:hover { color: var(--text); }
.row {
  display: grid;
  grid-template-columns: 1fr 110px 170px 34px;
  gap: 10px;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
}
.row:hover { background: var(--bg-hover); }
.row.selected { background: var(--accent-soft); }
.row .name { display: flex; align-items: center; gap: 8px; min-width: 0; }
.row .name span.label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .size, .row .mtime { color: var(--text-dim); font-size: 12px; }
.row .mtime { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .actions { opacity: 0; text-align: right; }
.row:hover .actions { opacity: 1; }
.dir-row .label { color: var(--dir); }
.file-row .label { color: var(--file); }
.badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-dim);
  flex: none;
}

/* ---------------- 网格视图 ---------------- */
.listing.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.grid .card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  cursor: pointer;
  transition: transform .12s, border-color .12s;
  overflow: hidden;
}
.grid .card:hover { border-color: var(--accent); transform: translateY(-2px); }
.grid .card.selected { border-color: var(--accent); background: var(--accent-soft); }
.grid .card .ico { font-size: 30px; display: block; margin-bottom: 8px; }
.grid .card .label { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.grid .card .sub { color: var(--text-dim); font-size: 11px; margin-top: 3px; }

/* ---------------- 预览面板 ---------------- */
.preview {
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.preview-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { display: flex; gap: 4px; flex: none; }
.preview-meta {
  padding: 8px 14px;
  color: var(--text-dim);
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
}
.preview-body { flex: 1; overflow: auto; padding: 12px 14px; }
.preview-body pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: #d7dce5;
}
.preview-body img { max-width: 100%; border-radius: 6px; display: block; margin: 0 auto; }
.preview-body .placeholder { color: var(--text-dim); text-align: center; padding: 40px 0; }
.preview-body .note { color: var(--danger); font-size: 12px; margin-bottom: 8px; }

/* ---------------- 响应式 ---------------- */
.only-mobile { display: none; }
@media (max-width: 900px) {
  .app, .app.with-preview { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 250px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform .2s;
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-flex; }
  .search-box { width: 150px; }
  .list-header, .row { grid-template-columns: 1fr 90px 34px; }
  .list-header .mtime-col, .row .mtime { display: none; }
  .preview { position: fixed; inset: 0 0 0 auto; width: 100%; z-index: 30; }
}
