/* ============================
   CSS Variables & Reset
   ============================ */
:root {
  --bg-primary: #f8f9fc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-header: rgba(255,255,255,0.85);
  --text-primary: #1a1d26;
  --text-secondary: #5a6178;
  --text-muted: #8b92a8;
  --border-color: #e8eaf0;
  --border-light: #f0f1f5;
  --accent: #4f6ef7;
  --accent-light: #eef1fe;
  --accent-hover: #3d5ce5;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-width: 240px;
  --header-height: 64px;
  --transition: 0.2s ease;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
}

[data-theme="dark"] {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d28;
  --bg-card: #1e2130;
  --bg-sidebar: #161824;
  --bg-header: rgba(15,17,23,0.9);
  --text-primary: #e4e6ee;
  --text-secondary: #9499b0;
  --text-muted: #6b7194;
  --border-color: #2a2d3e;
  --border-light: #222534;
  --accent: #6b8aff;
  --accent-light: #1c2444;
  --accent-hover: #8aa2ff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

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

html {
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 16px);
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
}

ul { list-style: none; }

/* ============================
   Header
   ============================ */
.site-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-header);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  z-index: 100;
  transition: background var(--transition);
}

.header-inner {
  max-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
}

.logo-link {
  flex-shrink: 0;
}

.site-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* Search */
.search-box {
  flex: 1;
  max-width: 480px;
  position: relative;
  margin: 0 auto;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 40px;
  padding: 0 36px 0 42px;
  border: 1px solid var(--border-color);
  border-radius: 20px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

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

.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-muted);
  font-size: 1.1rem;
  transition: background var(--transition);
}

.search-clear.visible { display: flex; }
.search-clear:hover { background: var(--border-color); }

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  transition: background var(--transition), color var(--transition);
}

.theme-toggle:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.theme-toggle svg { width: 18px; height: 18px; }
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

.mobile-menu-btn {
  display: none;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
}

.mobile-menu-btn svg { width: 20px; height: 20px; }

/* ============================
   Sidebar
   ============================ */
.sidebar {
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  z-index: 90;
  padding: 16px 0;
  transition: transform 0.3s ease, background var(--transition);
}

.sidebar-header {
  display: none;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 8px;
  justify-content: space-between;
  align-items: center;
}

.sidebar-close {
  font-size: 1.4rem;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.sidebar-close:hover { background: var(--border-color); }

.nav-list {
  padding: 0 8px;
}

.nav-item {
  margin-bottom: 2px;
}

.nav-item a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  color: var(--text-secondary);
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-left: 3px solid transparent;
}

.nav-item a:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-left-color: rgba(79,110,247,0.3);
}

.nav-item a.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(79,110,247,0.08);
}

.nav-item .nav-icon {
  font-size: 1.15rem;
  flex-shrink: 0;
  width: 24px;
  text-align: center;
}

.nav-item .nav-count {
  margin-left: auto;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--border-light);
  color: var(--text-muted);
  font-weight: 600;
  min-width: 26px;
  text-align: center;
}

.nav-item a.active .nav-count {
  background: var(--accent);
  color: #fff;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  margin-top: 12px;
}

.admin-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: all var(--transition);
}

.admin-link:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 85;
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

/* ============================
   Main Content
   ============================ */
.main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  padding: 24px 32px 80px;
  min-height: calc(100vh - var(--header-height));
}

.stats-bar {
  padding: 8px 0 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: right;
}

/* Category Section */
.category-section {
  margin-bottom: 36px;
}

.category-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  padding-bottom: 12px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--border-light);
  display: flex;
  align-items: center;
  gap: 8px;
}

.category-title .cat-icon {
  font-size: 1.15rem;
}

/* Card Grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

/* Site Card */
.site-card {
  display: flex;
  gap: 14px;
  padding: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  transition: all 0.25s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.site-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-md);
  opacity: 0;
  transition: opacity 0.25s ease;
  background: linear-gradient(135deg, var(--accent-light) 0%, transparent 60%);
}

.site-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.site-card:hover::before {
  opacity: 1;
}

.card-logo {
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-logo img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.card-logo .logo-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border-radius: var(--radius-sm);
}

.card-info {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-url {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* No results */
.no-results {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-muted);
}

.no-results svg {
  margin-bottom: 16px;
  opacity: 0.4;
}

.no-results p {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-secondary);
}

.no-results span {
  font-size: 0.85rem;
}

/* ============================
   Footer
   ============================ */
.site-footer {
  margin-left: var(--sidebar-width);
  padding: 24px 32px;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
}

/* ============================
   Floating Action Buttons
   ============================ */
.fab-group {
  position: fixed;
  bottom: 32px;
  right: 28px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 80;
}

.fab {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.25s ease;
}

.fab:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

#fab-top {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: all 0.25s ease;
}

#fab-top.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

#fab-top.visible:hover {
  transform: translateY(-2px);
}

.fab-popup {
  display: none;
  position: absolute;
  bottom: 100px;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  text-align: center;
  min-width: 180px;
  animation: fadeInUp 0.2s ease;
}

.fab-popup.visible { display: block; }

.fab-popup::after {
  content: '';
  position: absolute;
  bottom: -8px;
  right: 16px;
  width: 14px;
  height: 14px;
  background: var(--bg-card);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  transform: rotate(45deg);
}

.fab-popup p {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 10px;
}

.qr-img {
  width: 150px;
  height: 150px;
  border-radius: 8px;
  object-fit: contain;
}

/* ============================
   Animations
   ============================ */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.site-card {
  animation: fadeInUp 0.35s ease both;
}

.category-section:nth-child(1) .site-card { animation-delay: 0s; }
.category-section:nth-child(2) .site-card { animation-delay: 0.02s; }
.category-section:nth-child(3) .site-card { animation-delay: 0.04s; }

/* ============================
   Responsive
   ============================ */
@media (max-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  }
}

@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    top: 0;
    padding-top: 0;
    z-index: 110;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-header {
    display: flex;
  }

  .sidebar-overlay.visible {
    display: block;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .main-content {
    margin-left: 0;
    padding: 16px 16px 80px;
  }

  .site-footer {
    margin-left: 0;
  }

  .card-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .search-box {
    max-width: 300px;
  }

  .site-title {
    font-size: 1.05rem;
  }
}

@media (max-width: 480px) {
  .header-inner {
    padding: 0 12px;
    gap: 8px;
  }

  .search-box {
    max-width: none;
    flex: 1;
  }

  .site-title {
    display: none;
  }
}
