/* Layout */
.app { display: flex; height: 100vh; }

/* ============ Sidebar ============ */
.sidebar {
  width: 300px; min-width: 300px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column;
  overflow: hidden; z-index: 100;
  transition: var(--theme-transition);
}

.sidebar-header {
  padding: var(--space-4);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  transition: var(--theme-transition);
}

.sidebar-header h2 {
  font-size: var(--fs-md); font-weight: 600; margin-bottom: 10px;
  color: var(--text-secondary);
  display: flex; align-items: center; gap: 7px;
}
.sidebar-header h2 .title-icon { color: var(--accent); display: inline-flex; }

.sidebar-header input {
  width: 100%; padding: 7px 10px;
  background: var(--input-bg); border: 1px solid var(--input-border);
  color: var(--text-primary); border-radius: var(--radius-sm);
  font-size: var(--fs-md); transition: var(--theme-transition);
}
.sidebar-header input:focus { border-color: var(--accent); }
.sidebar-header input::placeholder { color: var(--text-muted); }

.folder-tree { flex: 1; overflow-y: auto; padding: var(--space-2) 6px; }

.folder-wrapper { position: relative; }

.folder-item {
  user-select: none; cursor: pointer;
  padding: 6px 8px; border-radius: var(--radius-sm);
  font-size: var(--fs-md); color: var(--text-secondary);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  display: flex; align-items: center; gap: 6px;
  position: relative;
}
.folder-item:hover { background: var(--hover-bg); color: var(--text-primary); }
.folder-item.active { background: var(--accent-soft); color: var(--text-primary); }
.folder-item.active::before {
  content: ''; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px;
  border-radius: var(--radius-full); background: var(--accent);
}

.folder-toggle-btn {
  width: 20px; height: 20px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-muted); border-radius: var(--radius-xs);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.folder-toggle-btn:hover { background: var(--hover-bg); color: var(--text-primary); }
.folder-toggle-btn svg { transition: transform var(--dur) var(--ease); }
.folder-toggle-btn.expanded svg { transform: rotate(90deg); }

.folder-icon { display: inline-flex; flex-shrink: 0; color: var(--text-muted); transition: color var(--dur-fast); }
.folder-item.active .folder-icon { color: var(--accent); }

.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.folder-stats {
  flex-shrink: 0; font-size: var(--fs-xs); color: var(--text-muted);
  background: var(--bg-tertiary); border-radius: var(--radius-full);
  padding: 0 6px; min-width: 18px; text-align: center; line-height: 16px;
}

.folder-children {
  margin-left: 18px; overflow: hidden;
  border-left: 1px solid var(--border-color);
  transition: max-height var(--dur) var(--ease-out);
}
.folder-children.collapsed { display: none; }

.folder-loading { padding: 20px; text-align: center; color: var(--text-muted); font-size: var(--fs-sm); }

.cache-info {
  font-size: var(--fs-xs); color: var(--text-muted);
  padding: 6px 10px;
  background: var(--bg-secondary); border-top: 1px solid var(--border-color);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  transition: var(--theme-transition);
}
.cache-info span { display: inline-flex; align-items: center; gap: 5px; }
.cache-info span[onclick] { cursor: pointer; color: var(--accent); }
.cache-info span[onclick]:hover { text-decoration: underline; }

/* ============ Main / Toolbar ============ */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

.toolbar {
  background: var(--bg-secondary); padding: 8px 16px;
  border-bottom: 1px solid var(--border-color);
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; flex-wrap: wrap; transition: var(--theme-transition);
}

.current-path {
  font-size: var(--fs-sm); color: var(--text-secondary); flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

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

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 5px 10px; background: var(--bg-tertiary);
  border: 1px solid var(--input-border); color: var(--text-secondary);
  border-radius: var(--radius-sm); cursor: pointer; font-size: var(--fs-sm);
  transition: var(--theme-transition), transform var(--dur-fast) var(--ease);
  white-space: nowrap;
}
.btn:hover { background: var(--hover-bg); color: var(--text-primary); }
.btn:active { transform: translateY(1px); }
.btn-icon { width: 30px; height: 30px; padding: 0; }
.btn-icon:hover { color: var(--accent); border-color: var(--border-strong); }

.theme-toggle {
  width: 30px; height: 30px; padding: 0;
  background: transparent; border: 1px solid transparent;
  color: var(--text-secondary); cursor: pointer;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  transition: var(--theme-transition);
}
.theme-toggle:hover { background: var(--hover-bg); color: var(--accent); }

/* Search */
.search-field { position: relative; display: inline-flex; align-items: center; }
.search-field-icon {
  position: absolute; left: 9px; display: inline-flex;
  color: var(--text-muted); pointer-events: none;
}
.search-box {
  padding: 5px 28px 5px 30px; background: var(--input-bg);
  border: 1px solid var(--input-border); color: var(--text-primary);
  border-radius: var(--radius-full); font-size: var(--fs-sm);
  transition: var(--theme-transition); width: 190px;
}
.search-box::placeholder { color: var(--text-muted); }
.search-box:focus { border-color: var(--accent); }
.search-clear {
  position: absolute; right: 6px; width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full); color: var(--text-muted);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.search-clear:hover { background: var(--hover-bg); color: var(--text-primary); }
.search-clear[hidden] { display: none; }

.image-count { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }

#zoomSlider {
  -webkit-appearance: none; appearance: none;
  width: 80px; height: 4px; border-radius: var(--radius-full);
  background: var(--border-strong); cursor: pointer;
}
#zoomSlider:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
#zoomSlider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg-secondary);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-fast) var(--ease);
}
#zoomSlider::-webkit-slider-thumb:hover { transform: scale(1.15); }
#zoomSlider::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; cursor: pointer;
  background: var(--accent); border: 2px solid var(--bg-secondary);
}
#zoomSlider::-moz-range-track { height: 4px; border-radius: var(--radius-full); background: var(--border-strong); }

/* ============ Masonry Grid ============ */
.masonry-scroll { flex: 1; overflow-y: auto; position: relative; }
.masonry-spacer { position: relative; width: 100%; }
.masonry-viewport { position: absolute; top: 0; left: 0; right: 0; padding: 72px; box-sizing: border-box; }

.pic-card {
  position: absolute; cursor: pointer; overflow: hidden;
  border-radius: var(--radius-md); background: var(--card-bg);
  border: 1px solid var(--border-color);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
  will-change: transform, left, top;
  box-shadow: var(--shadow-sm);
}
.pic-card:hover {
  transform: scale(1.02); z-index: 10;
  box-shadow: var(--shadow-md); border-color: var(--border-strong);
}
.pic-card img { width: 100%; height: auto; display: block; opacity: 0; transition: opacity var(--dur-slow) var(--ease); }
.pic-card img.loaded { opacity: 1; }

/* 正方形模式：格子固定为正方形，图片等比缩放裁剪填满 */
.masonry-viewport.view-grid .pic-card img { height: 100%; object-fit: cover; }

/* 瀑布流超高图（高 > 宽×5）：限制卡片高度，图片等比缩小后完整显示 */
.pic-card.tall img { height: 100%; object-fit: contain; }

.pic-skeleton {
  position: absolute; inset: 0;
  background: linear-gradient(100deg, var(--bg-tertiary) 30%, var(--hover-bg) 50%, var(--bg-tertiary) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.pic-overlay {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 22px 10px 9px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), rgba(0, 0, 0, 0));
  opacity: 0; transform: translateY(6px);
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  pointer-events: none;
}
.pic-card:hover .pic-overlay { opacity: 1; transform: translateY(0); }
.pic-name {
  color: #fff; font-size: var(--fs-sm); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.pic-meta { color: rgba(255, 255, 255, 0.72); font-size: var(--fs-xs); margin-top: 2px; }

/* README 卡片 */
.readme-card {
  position: absolute; cursor: default; overflow-y: auto;
  border-radius: var(--radius-md); background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  transition: background var(--dur) var(--ease);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}
.readme-card .readme-card-content {
  width: 100%; box-sizing: border-box; padding: 0;
  background: transparent; max-height: 60vh; overflow-y: auto;
}
.readme-card h1, .readme-card h2, .readme-card h3 { color: var(--text-primary); }
.readme-card p { color: var(--text-secondary); }
.readme-card code { background: var(--bg-primary); }
.readme-card pre { background: var(--bg-primary); }
.readme-card a { color: var(--accent); }
.readme-card a:hover { text-decoration: underline; }
.readme-card img { border-radius: var(--radius-sm); }
.readme-card hr { border-color: var(--border-color); }
.readme-card ul { padding-left: 24px; }
.readme-card li { color: var(--text-secondary); }

/* ============ Lightbox ============ */
.lightbox {
  display: none; position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.96); z-index: 1000;
  justify-content: center; align-items: center; flex-direction: column; overflow: hidden;
}
.lightbox.active { display: flex; animation: fadeIn var(--dur) var(--ease); }

.lightbox-img-container {
  position: relative; width: 100%; height: 100%;
  display: flex; justify-content: center; align-items: center;
  overflow: hidden; cursor: grab;
}
.lightbox-img-container:active { cursor: grabbing; }

.lightbox-img {
  display: block; max-width: 100%; max-height: 100%; width: auto; height: auto;
  object-fit: contain; transition: transform 0.05s linear;
  user-select: none; pointer-events: auto; transform-origin: center center;
}

.lightbox-close {
  position: absolute; top: 16px; right: 20px; z-index: 1001;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full); color: #ccc;
  background: rgba(255, 255, 255, 0.06);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.16); color: #fff; transform: rotate(90deg); }

.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 1001;
  width: 48px; height: 64px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.06); color: #ccc;
  border-radius: var(--radius-lg);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.lightbox-nav:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }
.lightbox-prev { left: 20px; }
.lightbox-next { right: 20px; }

.lightbox-info {
  position: absolute; bottom: 20px; text-align: center;
  color: #aaa; font-size: var(--fs-sm);
  background: rgba(0, 0, 0, 0.6); padding: 8px 16px; border-radius: var(--radius-full);
  z-index: 1001; pointer-events: none;
  max-width: 80vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.lightbox-loading-toast {
  position: absolute; bottom: 20px; right: 20px; z-index: 1002;
  display: flex; align-items: center; gap: 8px;
  background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(8px);
  padding: 8px 14px; border-radius: var(--radius-full);
  font-size: var(--fs-sm); color: var(--accent); font-weight: 500;
  pointer-events: none;
}

.lightbox-original-badge {
  position: absolute; top: 20px; left: 20px; z-index: 1001;
  display: inline-flex; align-items: center; gap: 5px;
  background: rgba(0, 0, 0, 0.6); padding: 6px 12px;
  border-radius: var(--radius-full); font-size: var(--fs-xs); color: var(--accent);
  pointer-events: none;
}

.zoom-hint {
  position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 1001;
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(0, 0, 0, 0.5); padding: 5px 12px;
  border-radius: var(--radius-full); font-size: var(--fs-xs); color: #ccc;
  pointer-events: none; white-space: nowrap; opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
}

/* ============ Toast ============ */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 2000;
  display: flex; align-items: center; gap: 9px;
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 10px 14px;
  font-size: var(--fs-sm); box-shadow: var(--shadow-md);
  transform: translateX(calc(100% + 24px)); opacity: 0;
  transition: transform var(--dur-slow) var(--ease-out), opacity var(--dur-slow) var(--ease-out);
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast-icon { display: inline-flex; }
.toast-success { border-left: 3px solid var(--success); }
.toast-success .toast-icon { color: var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-error .toast-icon { color: var(--danger); }
.toast-info { border-left: 3px solid var(--accent); }
.toast-info .toast-icon { color: var(--accent); }

/* Status */
.status-msg { text-align: center; padding: 40px; color: var(--text-muted); }

/* ============ Mobile ============ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: -300px; height: 100%;
    transition: transform var(--dur-slow) var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(300px); }
  .menu-toggle {
    display: flex !important; position: fixed; top: 10px; left: 10px; z-index: 101;
    width: 38px; height: 38px; align-items: center; justify-content: center;
    background: var(--bg-secondary); color: var(--text-secondary);
    border: 1px solid var(--border-color); border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
  }
  .menu-toggle:hover { color: var(--accent); }
  .toolbar { padding-left: 56px; }
  .toolbar-right { gap: 6px; }
  .search-box { width: 130px; }
}
@media (min-width: 769px) { .menu-toggle { display: none; } }
