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

:root {
  --primary-color: #4a90d9;
  --primary-hover: #357abd;
  --secondary-color: #6c757d;
  --bg-color: #f5f7fa;
  --card-bg: #ffffff;
  --text-color: #333333;
  --text-secondary: #666666;
  --border-color: #e1e4e8;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--card-bg);
  padding: 16px 24px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* Login Banner */
.login-banner {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.login-banner-text {
  font-size: 14px;
}

.login-banner-btn {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.login-banner-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.login-banner-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.login-banner-close:hover {
  color: white;
}

.logo {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--primary-color);
}

.header-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.user-section {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.user-name {
  font-size: 14px;
  color: var(--text-color);
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-sm {
  padding: 4px 8px;
  font-size: 12px;
}

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--secondary-color);
  color: white;
}

.btn-secondary:hover {
  background: #5a6268;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-color);
}

.btn-outline:hover {
  background: var(--bg-color);
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-color);
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:hover {
  background: var(--bg-color);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

/* Layout */
.layout {
  display: flex;
  height: calc(100vh - 70px);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 220px;
  background: var(--card-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.category-list {
  list-style: none;
  padding: 8px 0;
  overflow-y: auto;
  flex: 1;
}

.category-list-item {
  padding: 12px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
}

.category-list-item:hover {
  background: var(--bg-color);
  color: var(--primary-color);
}

.category-list-item.active {
  background: rgba(74, 144, 217, 0.1);
  color: var(--primary-color);
  border-left-color: var(--primary-color);
}

.category-list-item .category-name {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-list-item .site-count {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-color);
  padding: 2px 8px;
  border-radius: 10px;
}

.category-list-item.active .site-count {
  background: rgba(74, 144, 217, 0.2);
  color: var(--primary-color);
}

/* Sub Category List */
.sub-category-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sub-category-item {
  padding: 10px 20px 10px 36px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  font-size: 13px;
  color: var(--text-secondary);
}

.sub-category-item:hover {
  background: var(--bg-color);
  color: var(--primary-color);
}

.sub-category-item.active {
  background: rgba(74, 144, 217, 0.08);
  color: var(--primary-color);
  border-left-color: var(--primary-color);
}

.sub-category-item .category-name {
  font-size: 13px;
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sub-category-item .category-name::before {
  content: '└ ';
  color: var(--border-color);
}

.sub-category-item .site-count {
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-color);
  padding: 2px 6px;
  border-radius: 8px;
}

.sub-category-item.active .site-count {
  background: rgba(74, 144, 217, 0.15);
  color: var(--primary-color);
}

/* Sub category drag and drop */
.sub-category-item.drop-target {
  position: relative;
}

.sub-category-item.drop-over {
  background: rgba(74, 144, 217, 0.15) !important;
  color: var(--primary-color) !important;
  border-left-color: var(--primary-color) !important;
}

/* 拖放目标样式 */
.category-list-item.drop-target {
  position: relative;
}

.category-list-item.drop-target::after {
  content: '拖拽到此处';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-color);
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.category-list-item.drop-target:hover::after {
  opacity: 1;
}

.category-list-item.drop-over {
  background: rgba(74, 144, 217, 0.15) !important;
  color: var(--primary-color) !important;
  border-left-color: var(--primary-color) !important;
}

.category-list-item.drop-over::after {
  opacity: 1;
  color: var(--primary-color);
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  background: var(--bg-color);
}

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

.category-section-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--primary-color);
  color: var(--text-color);
}

.category-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-color);
  display: inline-block;
  cursor: pointer;
  user-select: none;
}

.category-title:hover {
  color: var(--primary-color);
}

.category-title.drop-target {
  position: relative;
}

.category-title.drop-target::after {
  content: '拖拽到此处移动分类';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-color);
  padding: 4px 8px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.2s;
}

.category-title.drop-target:hover::after {
  opacity: 1;
}

.category-title.drop-over {
  color: var(--primary-color);
  border-bottom-color: var(--primary-hover);
  background: rgba(74, 144, 217, 0.1);
  border-radius: 4px;
  padding: 4px 8px;
}

.category-title.drop-over::after {
  opacity: 1;
  color: var(--primary-color);
}

.collapse-icon {
  display: inline-block;
  font-size: 0.75rem;
  margin-right: 6px;
  transition: transform 0.2s;
}

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

/* Site Card */
.site-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.site-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.site-card.dragging {
  opacity: 0.5;
  transform: scale(0.95);
  cursor: move;
}

.site-card[draggable="true"] {
  cursor: grab;
}

.site-card[draggable="true"]:active {
  cursor: grabbing;
}

.site-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  object-fit: contain;
  background: var(--bg-color);
  padding: 4px;
}

.site-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  max-width: 15em;
}

/* Context Menu */
.context-menu {
  position: fixed;
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: var(--shadow-hover);
  padding: 8px 0;
  min-width: 120px;
  z-index: 1000;
  display: none;
}

.context-menu.show {
  display: block;
}

.context-menu-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-color);
  transition: background 0.2s;
}

.context-menu-item:hover {
  background: var(--bg-color);
}

.context-menu-divider {
  border-top: 1px solid var(--border-color);
  margin: 4px 0;
}

.context-menu-item-danger {
  color: #e53935;
}

.context-menu-item-danger:hover {
  background: rgba(229, 57, 53, 0.1);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--card-bg);
  border-radius: 12px;
  width: 90%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text-color);
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

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

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

.form-group input,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 14px;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary-color);
}

/* Loading */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}

.loading.show {
  display: flex;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 1.1rem;
  margin-bottom: 20px;
}

/* Responsive */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
  }

  .header-actions {
    width: 100%;
    justify-content: center;
  }

  .btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  .layout {
    flex-direction: column;
    height: auto;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    max-height: 200px;
  }

  .category-list {
    display: flex;
    flex-wrap: wrap;
    padding: 8px;
    gap: 8px;
  }

  .category-list-item {
    padding: 8px 12px;
    border-left: none;
    border-radius: 6px;
    background: var(--bg-color);
  }

  .category-list-item.active {
    border-left: none;
    background: var(--primary-color);
    color: white;
  }

  .category-list-item.active .site-count {
    background: rgba(255, 255, 255, 0.2);
    color: white;
  }

  .main-content {
    padding: 16px;
  }

  .sites-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .site-card {
    padding: 12px 8px;
  }

  .site-icon {
    width: 40px;
    height: 40px;
  }

  .site-name {
    font-size: 12px;
  }
}

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

@media (min-width: 1200px) {
  .sites-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

/* Toast 提示窗 */
.toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 14px 20px;
  box-shadow: var(--shadow-hover);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: 400px;
  animation: toastSlideIn 0.3s ease;
  pointer-events: auto;
  border-left: 4px solid var(--primary-color);
}

.toast.toast-exit {
  animation: toastSlideOut 0.3s ease forwards;
}

.toast-success {
  border-left-color: #4caf50;
}

.toast-error {
  border-left-color: #e53935;
}

.toast-warning {
  border-left-color: #ff9800;
}

.toast-info {
  border-left-color: var(--primary-color);
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.toast-success .toast-icon {
  color: #4caf50;
}

.toast-error .toast-icon {
  color: #e53935;
}

.toast-warning .toast-icon {
  color: #ff9800;
}

.toast-info .toast-icon {
  color: var(--primary-color);
}

.toast-message {
  flex: 1;
  font-size: 14px;
  color: var(--text-color);
  line-height: 1.5;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.toast-close:hover {
  background: var(--bg-color);
  color: var(--text-color);
}

@keyframes toastSlideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes toastSlideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* Auth Modal 额外样式 */
.auth-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
  font-size: 14px;
  color: var(--text-secondary);
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  text-decoration: underline;
}

.btn-link:hover {
  color: var(--primary-hover);
}

.form-hint {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* 确认对话框 */
.confirm-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2500;
}

.confirm-modal.show {
  display: flex;
}

.confirm-modal-content {
  background: var(--card-bg);
  border-radius: 12px;
  width: 90%;
  max-width: 360px;
  box-shadow: var(--shadow-hover);
  animation: confirmModalIn 0.2s ease;
}

@keyframes confirmModalIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.confirm-modal-body {
  padding: 24px 20px;
  text-align: center;
}

.confirm-modal-body p {
  font-size: 15px;
  color: var(--text-color);
  line-height: 1.6;
  margin: 0;
  white-space: pre-line;
}

.confirm-modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: center;
  gap: 12px;
}

.confirm-modal-footer .btn {
  min-width: 80px;
}
