/* ===== CSS Variables ===== */
:root {
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);

  --bg: #f0f2f8;
  --bg-gradient-1: rgba(99, 102, 241, 0.08);
  --bg-gradient-2: rgba(139, 92, 246, 0.06);
  --surface: rgba(255, 255, 255, 0.72);
  --surface-hover: rgba(255, 255, 255, 0.88);
  --sidebar-bg: rgba(255, 255, 255, 0.65);
  --border: rgba(255, 255, 255, 0.6);
  --border-subtle: rgba(0, 0, 0, 0.06);
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: rgba(99, 102, 241, 0.12);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-hover: 0 12px 40px rgba(99, 102, 241, 0.15);
  --glass-blur: blur(20px);
  --card-bg: rgba(255, 255, 255, 0.75);
  --input-bg: rgba(255, 255, 255, 0.8);
  --nav-active: rgba(99, 102, 241, 0.14);
  --scrollbar: rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-gradient-1: rgba(99, 102, 241, 0.12);
  --bg-gradient-2: rgba(139, 92, 246, 0.08);
  --surface: rgba(30, 32, 44, 0.75);
  --surface-hover: rgba(38, 40, 54, 0.9);
  --sidebar-bg: rgba(22, 24, 34, 0.82);
  --border: rgba(255, 255, 255, 0.08);
  --border-subtle: rgba(255, 255, 255, 0.06);
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, 0.15);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-hover: 0 12px 40px rgba(99, 102, 241, 0.2);
  --card-bg: rgba(30, 32, 44, 0.7);
  --input-bg: rgba(22, 24, 34, 0.8);
  --nav-active: rgba(129, 140, 248, 0.18);
  --scrollbar: rgba(255, 255, 255, 0.12);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 10% 10%, var(--bg-gradient-1), transparent),
    radial-gradient(ellipse 60% 50% at 90% 80%, var(--bg-gradient-2), transparent);
  pointer-events: none;
  z-index: 0;
}

img {
  display: block;
  max-width: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ===== Layout ===== */
.app {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.brand-icon {
  flex-shrink: 0;
  border-radius: 10px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

.sidebar-nav::-webkit-scrollbar {
  width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition);
  margin-bottom: 2px;
  text-align: left;
}

.nav-item:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.nav-item.active {
  background: var(--nav-active);
  color: var(--accent);
  font-weight: 600;
}

.nav-item .nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.nav-item .nav-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--border-subtle);
  padding: 1px 7px;
  border-radius: 20px;
}

.nav-item.active .nav-count {
  background: var(--accent-soft);
  color: var(--accent);
}

.sidebar-overlay {
  display: none;
}

/* ===== Main ===== */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-height);
  padding: 0 24px;
  background: var(--surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border-subtle);
}

.menu-btn {
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.lang-select {
  height: 36px;
  padding: 0 28px 0 12px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  outline: none;
  cursor: pointer;
  transition: all var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.lang-select:hover,
.lang-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.search-wrap {
  flex: 1;
  position: relative;
  max-width: 480px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 42px;
  padding: 0 40px 0 42px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--input-bg);
  backdrop-filter: blur(8px);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: all var(--transition);
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.search-clear {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.search-clear:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: block !important; }
[data-theme="light"] .icon-sun { display: none; }

/* ===== Content ===== */
.content {
  flex: 1;
  padding: 28px 24px 16px;
}

.content-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 20px;
}

.category-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.site-count {
  font-size: 13px;
  color: var(--text-muted);
}

/* ===== Site Grid ===== */
.site-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.site-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  background: var(--card-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: all var(--transition);
  animation: cardIn 0.4s cubic-bezier(0.4, 0, 0.2, 1) both;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.site-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--accent-soft), transparent 60%);
  opacity: 0;
  transition: opacity var(--transition);
}

.site-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
  border-color: var(--accent);
}

.site-card:hover::before {
  opacity: 1;
}

.site-card:active {
  transform: translateY(-1px);
}

@keyframes cardIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.site-favicon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  object-fit: contain;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  flex-shrink: 0;
  position: relative;
  z-index: 1;
  padding: 4px;
}

.site-info {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.site-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.site-desc {
  font-size: 13px;
  color: var(--text-secondary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 6px;
}

.site-url {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-card:hover .site-name {
  color: var(--accent);
}

/* ===== Empty State ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.6;
}

.empty-state p {
  font-size: 15px;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 20px 24px 28px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .app {
    flex-direction: column;
  }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
  }

  .sidebar-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px 12px;
    overflow: visible;
  }

  .nav-item {
    width: auto;
    margin-bottom: 0;
    padding: 8px 12px;
    font-size: 13px;
  }

  .nav-item .nav-count {
    display: none;
  }

  .main {
    margin-left: 0;
  }

  .topbar {
    padding: 0 16px;
  }

  .content {
    padding: 20px 16px 12px;
  }

  .site-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .brand-subtitle {
    display: none;
  }

  .search-wrap {
    max-width: none;
  }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
