/* ============================================
   WebStack-Nav
   融合 WebStack-Hugo 布局 + Simple-Nav-Page 功能
   ============================================ */

:root {
  --theme: #f1404b;
  --theme-light: rgba(241,64,75,0.08);
  --sidebar-bg: #f0f2f4;
  --sidebar-width: 220px;
  --sidebar-mini: 0px;
  --card-bg: #ffffff;
  --bg: #f5f6f8;
  --text: #333;
  --text-light: #666;
  --text-muted: #999;
  --border: #e8e8e8;
  --shadow: 0 1px 4px rgba(0,0,0,0.06);
  --shadow-hover: 0 8px 25px rgba(0,0,0,0.1);
  --radius: 10px;
  --header-h: 74px;
}

/* Dark theme */
body.dark {
  --theme: #ff6b6b;
  --theme-light: rgba(255,107,107,0.1);
  --sidebar-bg: #1a1a2e;
  --card-bg: #16213e;
  --bg: #0f0f23;
  --text: #e0e0e0;
  --text-light: #aaa;
  --text-muted: #666;
  --border: #2a2a4a;
  --shadow: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-hover: 0 8px 25px rgba(0,0,0,0.4);
}

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

html { scroll-behavior: smooth; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

a { text-decoration: none; color: inherit; }
img { max-width: 100%; }
ul { list-style: none; }

/* ===== Background ===== */
#bgLayer {
  position: fixed; inset: 0;
  background-size: cover; background-position: center;
  z-index: -2; transition: background-image 0.8s;
}
#bgOverlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: -1;
  transition: background 0.3s;
}
body.dark #bgOverlay { background: rgba(0,0,0,0.6); }

/* ===== Page Layout ===== */
.page-container { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  height: 100vh;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  z-index: 100;
  border-right: 1px solid var(--border);
  transition: transform 0.3s, background 0.3s;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: var(--sidebar-width);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.logo-icon { font-size: 28px; }
.logo-text { font-size: 18px; font-weight: 700; white-space: nowrap; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: var(--text-light);
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}
.nav-item:hover {
  background: var(--theme-light);
  color: var(--theme);
  border-left-color: var(--theme);
}
.nav-item.active {
  color: var(--theme);
  background: var(--theme-light);
  border-left-color: var(--theme);
  font-weight: 600;
}
.nav-item .nav-icon { margin-right: 10px; font-size: 16px; width: 20px; text-align: center; }
.nav-item .nav-count {
  margin-left: auto;
  font-size: 11px;
  background: var(--theme);
  color: #fff;
  padding: 1px 8px;
  border-radius: 10px;
}

.sidebar-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.sidebar-icon-btn:hover { background: var(--theme-light); }

/* ===== Sidebar Toggle ===== */
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 99;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  cursor: pointer;
  font-size: 20px;
}

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left 0.3s;
}

/* ===== Header Banner ===== */
.header-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  padding: 50px 30px 30px;
  text-align: center;
}
.header-title { font-size: 28px; font-weight: 700; margin-bottom: 6px; }
.header-desc { font-size: 14px; opacity: 0.8; margin-bottom: 20px; }

/* ===== Search ===== */
.search-area {
  max-width: 640px;
  margin: 0 auto;
}
.search-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.search-tab {
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 13px;
  cursor: pointer;
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.7);
  transition: all 0.2s;
  user-select: none;
}
.search-tab:hover, .search-tab.active {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.search-box {
  display: flex;
  align-items: center;
  background: #fff;
  border-radius: 28px;
  overflow: visible;
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.engine-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  border: none;
  background: transparent;
  color: #666;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  border-radius: 28px 0 0 28px;
  transition: background 0.2s;
}
.engine-btn:hover { background: #f5f5f5; }
.engine-arrow { font-size: 10px; color: #999; }

.search-divider {
  width: 1px;
  height: 24px;
  background: #ddd;
  flex-shrink: 0;
}

.search-box input {
  flex: 1;
  border: none;
  padding: 12px 8px;
  font-size: 15px;
  outline: none;
  min-width: 0;
}

.search-clear {
  border: none;
  background: none;
  color: #999;
  cursor: pointer;
  padding: 8px;
  font-size: 14px;
}
.search-go {
  border: none;
  background: transparent;
  color: var(--theme);
  cursor: pointer;
  padding: 12px 18px;
  font-size: 18px;
  border-radius: 0 28px 28px 0;
  transition: background 0.2s;
}
.search-go:hover { background: #fff5f5; }

/* ===== Engine Panel ===== */
.engine-panel {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.15);
  padding: 10px;
  z-index: 10;
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.engine-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #555;
  transition: all 0.2s;
}
.engine-option:hover { background: #f5f5f5; }
.engine-option.active { background: var(--theme-light); color: var(--theme); font-weight: 600; }

/* ===== Content Area ===== */
.content-area {
  flex: 1;
  padding: 20px 30px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ===== Category Section ===== */
.cat-section {
  margin-bottom: 28px;
}
.cat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}
.cat-header .cat-icon { font-size: 20px; }
.cat-header h2 { font-size: 18px; font-weight: 600; }
.cat-header .cat-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Links Grid ===== */
.links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.link-card {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: all 0.3s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.link-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-2px);
}

.link-icon-wrap {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 12px;
  flex-shrink: 0;
  overflow: hidden;
}
.link-icon-wrap img {
  width: 22px;
  height: 22px;
}

.link-info {
  flex: 1;
  min-width: 0;
}
.link-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link-desc {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.link-go {
  opacity: 0;
  margin-left: 8px;
  color: var(--text-muted);
  transition: all 0.3s;
  flex-shrink: 0;
}
.link-card:hover .link-go { opacity: 1; color: var(--theme); }

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 20px;
  font-size: 13px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.footer a { color: var(--theme); }

/* ===== Back to Top ===== */
.back-top-btn {
  position: fixed;
  bottom: 30px;
  right: 30px;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--theme);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
  z-index: 50;
}
.back-top-btn.visible { opacity: 1; visibility: visible; }
.back-top-btn:hover { transform: translateY(-3px); }

/* ===== Net Badge ===== */
.net-badge {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--theme-light);
  color: var(--theme);
  margin-left: 4px;
}

/* ===== Empty State ===== */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 10px; }

/* ===== Mobile Overlay ===== */
.mobile-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}
.mobile-overlay.show { display: block; }

/* ============================================
   Multi-level Category Tree
   ============================================ */

/* Child nav item in sidebar - indented with smaller font */
.nav-item.nav-child {
  padding-left: 40px;
  font-size: 13px;
}
.nav-item.nav-child .nav-icon {
  font-size: 14px;
  width: 18px;
}
.nav-item.nav-child .nav-count {
  font-size: 10px;
  padding: 1px 6px;
}

/* Sub-section for child categories */
.sub-section {
  background: var(--theme-light);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
body.dark .sub-section {
  background: rgba(255,255,255,0.04);
}

.sub-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.sub-section-header .sub-icon {
  font-size: 16px;
}
.sub-section-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.sub-section-header .sub-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
}

/* Collapse indicator for parent nav items */
.nav-expand-icon {
  margin-left: auto;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}
.nav-item.expanded .nav-expand-icon {
  transform: rotate(90deg);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: flex; }
  .main-content { margin-left: 0; }
  .header-banner { padding: 40px 16px 24px; }
  .header-title { font-size: 22px; }
  .content-area { padding: 16px; }
  .links-grid { grid-template-columns: 1fr; }
  .engine-panel { grid-template-columns: repeat(3, 1fr); }
  .nav-item.nav-child { padding-left: 28px; font-size: 12px; }
  .sub-section { padding: 10px 12px; }

}
@media (max-width: 480px) {
  .engine-panel { grid-template-columns: repeat(2, 1fr); }
  .search-box input { font-size: 14px; }
}
