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

:root {
  --bg: #1a1a2e;
  --bg-panel: #16213e;
  --bg-card: #0f3460;
  --bg-hover: #1a4a7a;
  --text: #e0e0e0;
  --text-dim: #888;
  --accent: #e94560;
  --accent-hover: #ff6b81;
  --border: #2a2a4a;
  --safe: #4caf50;
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

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

#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  height: 56px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { display: flex; align-items: center; gap: 12px; }

#topbar h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1px;
}

.breadcrumb { color: var(--text-dim); font-size: 13px; }

#search-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  width: 240px;
  outline: none;
}
#search-input:focus { border-color: var(--accent); }

.user-info { font-size: 13px; color: var(--text-dim); }

.btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.15s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--accent); }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--accent); border-color: var(--accent); color: white; }
.btn-danger:hover { background: var(--accent-hover); }

#main { display: flex; flex: 1; overflow: hidden; }

#sidebar {
  width: 280px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h3 { font-size: 13px; text-transform: uppercase; color: var(--text-dim); letter-spacing: 1px; }

#tree-container { padding: 8px 0; flex: 1; overflow-y: auto; }

.tree-node { user-select: none; }
.tree-node-label {
  display: flex;
  align-items: center;
  padding: 4px 14px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.1s;
}
.tree-node-label:hover { background: var(--bg-hover); }
.tree-node-label.active { background: var(--bg-card); color: var(--accent); }
.tree-toggle { display: inline-block; width: 16px; text-align: center; color: var(--text-dim); font-size: 10px; }
.tree-icon { margin-right: 6px; font-size: 14px; }
.tree-badge {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--safe);
  margin-left: 6px;
}
.tree-children { padding-left: 16px; }
.tree-children.collapsed { display: none; }

#content { flex: 1; overflow-y: auto; padding: 16px; }

.dir-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.dir-header-left { display: flex; align-items: center; gap: 12px; }
.dir-header-right { display: flex; align-items: center; gap: 12px; }
#current-dir { font-size: 16px; font-weight: 600; word-break: break-all; }

.tag-control {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-dim);
}
.tag-control input { cursor: pointer; accent-color: var(--safe); }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.gallery-item {
  position: relative;
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.gallery-item:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.4); }

.gallery-thumb {
  width: 100%;
  height: 160px;
  object-fit: cover;
  display: block;
  background: var(--bg);
}

.gallery-video-thumb {
  width: 100%;
  height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  font-size: 48px;
}

.gallery-name {
  padding: 6px 8px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gallery-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  color: var(--accent);
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
}
.gallery-delete:hover { background: var(--accent); color: white; opacity: 1; }

.gallery-share {
  position: absolute;
  top: 4px;
  right: 32px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 2px 6px;
  cursor: pointer;
  font-size: 9px;
  color: var(--text-dim);
  font-weight: 600;
  letter-spacing: 0.5px;
  transition: all 0.15s;
}
.gallery-share:hover { background: rgba(0,0,0,0.8); color: var(--text); }
.gallery-share.active {
  background: var(--safe);
  color: white;
  border-color: var(--safe);
}
.gallery-share.active:hover { opacity: 0.85; }

.gallery-select {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 4px;
  background: rgba(0,0,0,0.4);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
}
.gallery-item.selected .gallery-select {
  background: var(--accent);
  border-color: var(--accent);
}
.gallery-item.selected .gallery-select::after {
  content: "\2713";
}
.gallery-item.selected {
  outline: 3px solid var(--accent);
  outline-offset: -3px;
}
.select-mode .gallery-select { display: flex; }
.select-mode .gallery-delete { display: none; }

.gallery-type-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.search-results { margin-bottom: 16px; }
.search-results h3 { font-size: 14px; color: var(--text-dim); margin-bottom: 8px; }

.lightbox {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}
.lightbox.visible {
  display: flex;
}
.lightbox-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.92);
}
.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 85vh;
  z-index: 1;
}
.lightbox-content img, .lightbox-content video {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 4px;
}
.lightbox-close {
  position: absolute;
  top: 16px; right: 20px;
  background: none;
  border: none;
  color: white;
  font-size: 36px;
  cursor: pointer;
  z-index: 2;
  opacity: 0.7;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-prev, .lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: white;
  font-size: 48px;
  cursor: pointer;
  z-index: 2;
  opacity: 0.5;
  padding: 16px;
}
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }
.lightbox-prev:hover, .lightbox-next:hover { opacity: 1; }
.lightbox-info {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-dim);
  font-size: 13px;
  z-index: 2;
  text-align: center;
  background: rgba(0,0,0,0.6);
  padding: 6px 16px;
  border-radius: 4px;
}

.lightbox-delete {
  position: absolute;
  top: 16px;
  right: 70px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  z-index: 2;
  opacity: 0.8;
}
.lightbox-delete:hover { opacity: 1; background: var(--accent-hover); }

.lightbox-share {
  position: absolute;
  top: 16px;
  right: 165px;
  background: rgba(0,0,0,0.6);
  color: var(--text-dim);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: var(--radius);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
  z-index: 2;
  opacity: 0.8;
}
.lightbox-share:hover { opacity: 1; color: var(--text); }
.lightbox-share.active {
  background: var(--safe);
  color: white;
  border-color: var(--safe);
  opacity: 0.9;
}

.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
}
.modal.visible {
  display: flex;
}
.modal-backdrop {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
}
.modal-content {
  position: relative;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  max-width: 400px;
  z-index: 1;
}
.modal-content h3 { margin-bottom: 12px; color: var(--accent); }
.delete-filename { font-weight: 600; margin-bottom: 8px; word-break: break-all; }
.delete-warning { color: var(--text-dim); font-size: 14px; margin-bottom: 20px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 768px) {
  #sidebar { width: 200px; }
  #search-input { width: 140px; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .gallery-thumb, .gallery-video-thumb { height: 120px; }
}