:root {
  --bg-deep: #1a1b1e;
  --bg-surface: #25262b;
  --bg-elevated: #2c2e33;
  --accent: #4a9eff;
  --text-primary: #e1e1e3;
  --text-secondary: #909296;
  --text-disabled: #5c5f66;
  --border-light: rgba(255, 255, 255, 0.06);
  --glass-bg: rgba(26, 27, 30, 0.8);
  --glass-card: rgba(255, 255, 255, 0.04);
  --glass-card-hover: rgba(255, 255, 255, 0.08);
}

html, body {
  background-color: var(--bg-deep);
}

body {
  margin: 0;
  padding: 0;
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

#header h1 {
  font-size: 20px;
  font-weight: 600;
  white-space: nowrap;
  margin: 0;
  letter-spacing: -0.3px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex: 1;
  justify-content: flex-end;
}

.search-container {
  position: relative;
  display: flex;
  align-items: center;
}

#search-input {
  width: 280px;
  padding: 10px 36px 10px 16px;
  border: 1px solid var(--border-light);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-primary);
  font-size: 14px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

#search-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.05);
  width: 340px;
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.15), inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

#search-input::placeholder {
  color: var(--text-secondary);
}

#search-clear {
  position: absolute;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#search-clear:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
}

#ebook-count {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
  padding: 6px 12px;
  border-radius: 20px;
  white-space: nowrap;
  border: 1px solid var(--border-light);
}

#refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

#refresh-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}

#refresh-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#refresh-btn.refreshing svg {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

#recent-section {
  padding: 20px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0;
}

#clear-recents {
  background: transparent;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: 6px;
  transition: all 0.2s;
  font-weight: 500;
}

#clear-recents:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.15);
}

#recent-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.recent-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px;
  background: var(--glass-card);
  border: 1px solid var(--border-light);
  border-radius: 12px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-primary);
  transition: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  box-sizing: border-box;
  position: relative;
}

.recent-item.pinned {
  border-left: 3px solid var(--accent);
  background: rgba(74, 158, 255, 0.03);
}

.recent-item:hover {
  background: var(--glass-card-hover);
  border-color: rgba(255, 255, 255, 0.15);
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

.recent-icon {
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: rgba(74, 158, 255, 0.1);
  border-radius: 8px;
}

.recent-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding-right: 24px;
}

.recent-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.recent-meta {
  font-size: 11px;
  color: var(--text-secondary);
}

.recent-pin-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  z-index: 2;
}

.recent-pin-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.recent-item.pinned .recent-pin-btn {
  color: var(--accent);
}

.recent-item.pinned .recent-pin-btn:hover {
  background: rgba(74, 158, 255, 0.1);
}

#tree-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  position: relative;
  overflow: hidden;
}

#tree-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

#tree-viewport::-webkit-scrollbar {
  width: 10px;
}
#tree-viewport::-webkit-scrollbar-track {
  background: transparent;
}
#tree-viewport::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid var(--bg-deep);
  border-radius: 10px;
}
#tree-viewport::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

#tree-content {
  position: relative;
}

#top-spacer, #bottom-spacer {
  height: 0;
}

#visible-rows {
  position: relative;
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(26, 27, 30, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  opacity: 1;
  transition: opacity 0.3s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-text {
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  background: var(--bg-elevated);
  padding: 10px 24px;
  border-radius: 20px;
  border: 1px solid var(--border-light);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.tree-row {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 24px 0 0;
  cursor: pointer;
  transition: background 0.2s ease;
  user-select: none;
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  box-sizing: border-box;
}

.tree-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.tree-row.folder-row.expanded {
  background: rgba(255, 255, 255, 0.02);
}

.tree-row.loading {
  opacity: 0.6;
}

.row-indent {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 100%;
}

.indent-unit {
  width: 24px;
  height: 100%;
  display: inline-flex;
  border-right: 1px solid rgba(255, 255, 255, 0.03);
}

.folder-toggle {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-disabled);
  flex-shrink: 0;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1), color 0.2s;
  margin: 0 4px 0 12px;
  border-radius: 6px;
}

.tree-row:hover .folder-toggle:not(.empty) {
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.05);
}

.folder-toggle.expanded {
  transform: rotate(90deg);
}

.folder-toggle.empty {
  visibility: hidden;
}

.row-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
}

.folder-icon {
  color: var(--accent);
  opacity: 0.8;
}

.ebook-icon {
  color: var(--accent);
  opacity: 0.9;
}

.ebook-icon.icon-pdf { color: #e74c3c; opacity: 1; }
.ebook-icon.icon-epub { color: #2ecc71; opacity: 1; }
.ebook-icon.icon-mobi { color: #f39c12; opacity: 1; }
.ebook-icon.icon-comic { color: #e67e22; opacity: 1; }
.ebook-icon.icon-fb2 { color: #9b59b6; opacity: 1; }
.ebook-icon.icon-xps { color: #3498db; opacity: 1; }
.ebook-icon.icon-html { color: #e44d26; opacity: 1; }
.ebook-icon.icon-md { color: #42a5f5; opacity: 1; }

.row-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
}

.folder-row .row-content {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.row-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.2px;
}

.row-name.search-match {
  color: var(--accent);
}

.search-highlight {
  background: rgba(74, 158, 255, 0.25);
  color: #fff;
  border-radius: 3px;
  padding: 0 2px;
  box-shadow: 0 0 0 1px rgba(74, 158, 255, 0.3);
}

.row-counts {
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
  flex-shrink: 0;
  font-weight: 500;
}

.row-meta {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.tree-row.ebook-row .row-name {
  color: var(--text-primary);
}

.tree-row.ebook-row:hover .row-name {
  color: #fff;
}

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

.empty-state h3 {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 14px;
}

.search-results-info {
  padding: 12px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.search-results-info span {
  font-size: 13px;
  color: var(--text-secondary);
}
#exit-search {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
#exit-search:hover {
  background: rgba(255, 255, 255, 0.1);
}

@media (max-width: 600px) {
  #header {
    flex-direction: column;
    align-items: stretch;
    padding: 16px;
    gap: 12px;
  }
  
  .header-right {
    justify-content: space-between;
  }
  
  #search-input {
    width: 100%;
  }
  
  #search-input:focus {
    width: 100%;
  }
  
  #recent-list {
    grid-template-columns: 1fr;
  }
}
