/* ========== 主题变量 ========== */
:root {
  --bg: #f5f5f7;
  --sidebar-bg: #ffffff;
  --card-bg: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #86868b;
  --border: #e8e8ed;
  --accent: #0071e3;
  --accent-light: rgba(0, 113, 227, 0.08);
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(0,0,0,0.08);
  --radius: 14px;
  --radius-sm: 10px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #1c1c1e;
  --sidebar-bg: #2c2c2e;
  --card-bg: #2c2c2e;
  --text: #f5f5f7;
  --text-secondary: #98989d;
  --border: #3a3a3c;
  --accent: #0a84ff;
  --accent-light: rgba(10, 132, 255, 0.15);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.35);
}

/* ========== 基础重置 ========== */
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select { font-family: inherit; }

/* ========== 布局 ========== */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ========== 侧边栏 ========== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), background var(--transition);
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.category-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px;
}

.category-list::-webkit-scrollbar { width: 4px; }
.category-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.category-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 2px;
  user-select: none;
}

.category-item:hover {
  background: var(--accent-light);
  color: var(--text);
}

.category-item.active {
  background: var(--accent-light);
  color: var(--accent);
  font-weight: 500;
}

.category-item .cat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
  flex-shrink: 0;
}

.category-item .cat-count {
  margin-left: auto;
  font-size: 12px;
  opacity: 0.6;
  font-weight: 400;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn-add {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  transition: opacity var(--transition), transform var(--transition);
}

.btn-add:hover { opacity: 0.9; }
.btn-add:active { transform: scale(0.97); }

.btn-add svg { width: 16px; height: 16px; }

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  transition: all var(--transition);
}

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

.theme-toggle svg { width: 15px; height: 15px; }

/* ========== 主内容区 ========== */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-header {
  padding: 20px 32px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.menu-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.menu-toggle:hover { background: var(--accent-light); color: var(--text); }
.menu-toggle svg { width: 20px; height: 20px; }

.search-wrapper {
  flex: 1;
  position: relative;
  max-width: 480px;
}

.search-wrapper svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-secondary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 11px 16px 11px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: all var(--transition);
}

.search-input::placeholder { color: var(--text-secondary); opacity: 0.7; }

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

.sort-select {
  padding: 10px 32px 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  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='%2386868b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: all var(--transition);
}

.sort-select:focus { border-color: var(--accent); }

/* ========== 内容区 ========== */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 8px 32px 40px;
}

.content::-webkit-scrollbar { width: 6px; }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 20px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title:first-child { margin-top: 8px; }

.section-title .count {
  font-weight: 400;
  opacity: 0.6;
  text-transform: none;
  letter-spacing: 0;
}

/* ========== 网址卡片 ========== */
.sites-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.site-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

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

.site-card:active { transform: translateY(0); }

.site-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--accent);
}

.site-icon img {
  width: 28px;
  height: 28px;
  object-fit: contain;
  display: block;
}

.site-icon .favicon-fallback {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  letter-spacing: 0;
}

.site-info {
  flex: 1;
  min-width: 0;
}

.site-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.site-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.site-card .delete-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  opacity: 0;
  transition: all var(--transition);
}

.site-card:hover .delete-btn { opacity: 1; }
.site-card .delete-btn:hover { background: rgba(255,59,48,0.1); color: #ff3b30; }
.site-card .delete-btn svg { width: 12px; height: 12px; }

/* ========== 空状态 ========== */
.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty-state p { font-size: 15px; }
.empty-state .empty-hint { font-size: 13px; margin-top: 6px; opacity: 0.7; }

/* ========== 弹窗 ========== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

.modal-overlay.show { opacity: 1; visibility: visible; }

.modal {
  background: var(--sidebar-bg);
  border-radius: 18px;
  padding: 28px;
  width: 90%;
  max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  transform: translateY(20px) scale(0.96);
  transition: transform var(--transition);
}

.modal-overlay.show .modal { transform: translateY(0) scale(1); }

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: all var(--transition);
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group input::placeholder { color: var(--text-secondary); opacity: 0.5; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 24px;
}

.btn-cancel {
  flex: 1;
  padding: 11px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: var(--card-bg);
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.btn-cancel:hover { color: var(--text); background: var(--accent-light); }

.btn-submit {
  flex: 1;
  padding: 11px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  transition: opacity var(--transition);
}

.btn-submit:hover { opacity: 0.9; }
.btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
  z-index: 2000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }

/* ========== 遮罩（移动端） ========== */
.sidebar-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

.sidebar-mask.show { opacity: 1; visibility: visible; }

/* ========== 响应式 ========== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,0.1);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-mask { display: block; }
  .menu-toggle { display: flex; }

  .main-header { padding: 16px 16px 12px; gap: 10px; }
  .content { padding: 4px 16px 32px; }
  .sites-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .site-card { padding: 14px; }
  .site-icon { width: 36px; height: 36px; }
  .site-icon img { width: 24px; height: 24px; }
  .sort-select { padding: 9px 28px 9px 10px; font-size: 12px; }
}

@media (max-width: 480px) {
  .sites-grid { grid-template-columns: 1fr; }
}