/* ==================== Reset & Base ==================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-hover: #f0f2f5;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 16px rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-sm: 6px;
  --sidebar-width: 220px;
  --header-height: 64px;
  --transition: 0.2s ease;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==================== Header ==================== */
.header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 16px;
}
.logo {
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--primary);
}
.search-box {
  flex: 1;
  max-width: 480px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 10px 16px 10px 40px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 14px;
  background: var(--bg);
  transition: var(--transition);
  outline: none;
}
.search-box input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
  pointer-events: none;
}
.header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ==================== Buttons ==================== */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn:hover {
  background: var(--surface-hover);
  border-color: #d1d5db;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-small {
  padding: 4px 10px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition);
}
.btn-small:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ==================== App Layout ==================== */
.app-container {
  display: flex;
  margin-top: var(--header-height);
  min-height: calc(100vh - var(--header-height));
}

/* ==================== Sidebar ==================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 50;
}
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.sidebar-header h3 {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.category-list {
  display: flex;
  flex-direction: column;
}
.category-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  color: var(--text);
  border-left: 3px solid transparent;
}
.category-item:hover {
  background: var(--surface-hover);
}
.category-item.active {
  background: var(--primary-light);
  border-left-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.category-item .cat-icon {
  font-size: 16px;
  width: 24px;
  text-align: center;
}
.category-item .cat-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg);
  padding: 1px 7px;
  border-radius: 10px;
}

/* ==================== Main Content ==================== */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
  max-width: 1200px;
}
.content-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.content-header h2 {
  font-size: 22px;
  font-weight: 700;
}
.count-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
}

/* ==================== Tool Grid ==================== */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.tool-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}
.tool-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  border-color: var(--primary);
}
.tool-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tool-card-title a {
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-card-title a:hover {
  color: var(--primary);
  text-decoration: underline;
}
.tool-card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  flex: 1;
}
.tool-card-url {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0.7;
}

/* ==================== Empty State ==================== */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}
.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.empty-state p {
  font-size: 15px;
}

/* ==================== Modal ==================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.active {
  display: flex;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
}
.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body {
  padding: 20px 24px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ==================== Form ==================== */
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.form-group textarea {
  resize: vertical;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.5;
}

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1f2937;
  color: #fff;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 300;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ==================== Responsive ==================== */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .sidebar.open {
    display: block;
    width: 100%;
    z-index: 150;
  }
  .main-content {
    margin-left: 0;
    padding: 16px;
  }
  .header-inner {
    padding: 0 12px;
    gap: 8px;
  }
  .logo {
    font-size: 16px;
  }
  .search-box {
    max-width: none;
  }
  .header-actions .btn {
    padding: 6px 10px;
    font-size: 12px;
  }
  .tool-grid {
    grid-template-columns: 1fr;
  }
}

/* ==================== Scrollbar ==================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
