/* ====== CSS Variables ====== */
:root {
  --primary: #409eff;
  --primary-dark: #337ecc;
  --primary-light: #ecf5ff;
  --bg: #f5f5fb;
  --bg-white: #ffffff;
  --text: #333333;
  --text-secondary: #666666;
  --text-muted: #999999;
  --border: #e5e7eb;
  --sidebar-width: 240px;
  --header-height: 60px;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 16px rgba(64,158,255,0.15);
  --transition: all 0.3s ease;
}

/* ====== Reset ====== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
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.6;
  overflow-x: hidden;
}
a { color: var(--primary); text-decoration: none; transition: var(--transition); }
a:hover { color: var(--primary-dark); }
img { max-width: 100%; height: auto; }
button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* ====== App Layout ====== */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}
.main-area {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: var(--transition);
}
.main-area.full-width {
  margin-left: 0;
}
.main-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* ====== Sidebar ====== */
.site-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  overflow-y: auto;
}
.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
.sidebar-logo i { color: var(--primary); font-size: 22px; }
.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  font-size: 14px;
  transition: var(--transition);
  border-left: 3px solid transparent;
}
.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
  font-weight: 600;
}
.nav-item i { width: 20px; text-align: center; font-size: 15px; }
.nav-divider {
  padding: 16px 20px 6px;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.sidebar-ads {
  padding: 12px;
  border-top: 1px solid var(--border);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 99;
}

/* ====== Header ====== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: var(--header-height);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.header-left { display: flex; align-items: center; gap: 12px; }
.sidebar-toggle {
  display: none;
  font-size: 20px;
  color: var(--text-secondary);
  padding: 8px;
}
.site-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
}
.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--primary), #667eea);
  border-radius: 8px;
  color: white;
  font-size: 16px;
}
.header-search { flex: 1; max-width: 500px; }
.search-form { width: 100%; }
.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0 4px 0 16px;
  transition: var(--transition);
}
.search-input-wrap:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(64,158,255,0.15);
}
.search-icon { color: var(--text-muted); font-size: 14px; }
.search-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 12px;
  outline: none;
  font-size: 14px;
}
.search-btn {
  padding: 6px 16px;
  background: var(--primary);
  color: white;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}
.search-btn:hover { background: var(--primary-dark); }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-link {
  font-size: 22px;
  color: var(--text-secondary);
  transition: var(--transition);
}
.header-link:hover { color: var(--primary); transform: scale(1.1); }

/* ====== Hero ====== */
.home-hero {
  text-align: center;
  padding: 48px 20px 36px;
  background: linear-gradient(135deg, #667eea 0%, var(--primary) 100%);
  border-radius: 16px;
  margin-bottom: 32px;
  color: white;
}
.hero-title { font-size: 32px; font-weight: 800; margin-bottom: 12px; }
.hero-desc { font-size: 16px; opacity: 0.9; }

/* ====== Sections ====== */
.tool-section { margin-bottom: 36px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}
.section-title i { color: var(--primary); }
.section-more {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.section-more:hover { color: var(--primary); }

/* ====== Tool Grid ====== */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.tool-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px;
  background: var(--bg-white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: var(--transition);
  color: var(--text);
}
.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary);
  color: var(--text);
}
.tool-card-icon {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tool-card-icon img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}
.tool-icon-fallback {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-light);
  border-radius: 10px;
  color: var(--primary);
  font-size: 18px;
}
.tool-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  line-height: 1.3;
}
.tool-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tool-card-cat {
  display: inline-block;
  margin-top: 6px;
  padding: 2px 8px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 4px;
  font-size: 11px;
}

/* ====== Tool Detail ====== */
.tool-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.tool-detail-title {
  display: flex;
  align-items: center;
  gap: 16px;
}
.tool-detail-icon {
  width: 56px;
  height: 56px;
  object-fit: contain;
}
.tool-detail-title h1 {
  font-size: 24px;
  font-weight: 700;
}
.tool-detail-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}
.tool-detail-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}
.meta-cat a {
  padding: 4px 12px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 20px;
  font-size: 13px;
}
.meta-views {
  font-size: 13px;
  color: var(--text-muted);
}
.tool-detail-layout {
  display: flex;
  gap: 24px;
}
.tool-detail-main { flex: 1; min-width: 0; }
.tool-detail-sidebar {
  flex-shrink: 0;
  width: 300px;
}
.tool-detail-body {
  background: var(--bg-white);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
}

/* ====== Tool Common Styles ====== */
.tool-container { width: 100%; }
.tool-row { margin-bottom: 16px; }
.tool-label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.tool-input, .tool-textarea, .tool-select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: var(--transition);
  background: var(--bg-white);
}
.tool-input:focus, .tool-textarea:focus, .tool-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(64,158,255,0.15);
}
.tool-textarea { min-height: 150px; resize: vertical; font-family: 'Courier New', monospace; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: var(--bg); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--primary); color: var(--primary); }
.btn-success { background: #67c23a; color: white; }
.btn-danger { background: #f56c6c; color: white; }
.btn-group { display: flex; flex-wrap: wrap; gap: 8px; }
.result-box {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-family: 'Courier New', monospace;
  font-size: 14px;
  word-break: break-all;
  white-space: pre-wrap;
  min-height: 60px;
}
.tool-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}
.tool-tab {
  padding: 10px 20px;
  font-size: 14px;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
  cursor: pointer;
}
.tool-tab:hover { color: var(--primary); }
.tool-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tool-tab-panel { display: none; }
.tool-tab-panel.active { display: block; }

/* ====== Ads ====== */
.ad-container { text-align: center; }
.ad-item { display: block; margin: 8px 0; }
.ad-item img { max-width: 100%; border-radius: var(--radius); }
.ad-text { padding: 12px; background: #fffbe6; border: 1px solid #ffe58f; border-radius: var(--radius); }
.home-ads-top, .tool-ads-top { margin-bottom: 20px; }

/* ====== Footer ====== */
.site-footer {
  padding: 24px;
  text-align: center;
  border-top: 1px solid var(--border);
  background: var(--bg-white);
  margin-top: auto;
}
.footer-content { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 16px; }
.footer-text { font-size: 14px; color: var(--text-muted); }
.footer-link { font-size: 14px; color: var(--text-secondary); display: flex; align-items: center; gap: 4px; }
.footer-link:hover { color: var(--primary); }
.footer-icp { font-size: 12px; color: var(--text-muted); }
.footer-copy { font-size: 12px; color: var(--text-muted); }
.footer-ads { margin-bottom: 16px; }

/* ====== Empty State ====== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state i { font-size: 48px; margin-bottom: 16px; display: block; opacity: 0.4; }
.empty-state p { font-size: 16px; }

/* ====== Category Page ====== */
.category-page { }
.category-page .section-title { margin-bottom: 20px; }

/* ====== Search Results ====== */
.search-results .section-title { margin-bottom: 20px; }

/* ====== Admin Styles ====== */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 220px;
  background: #1f2937;
  color: #e5e7eb;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.admin-sidebar-header {
  padding: 20px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.admin-sidebar-header i { color: var(--primary); }
.admin-nav { flex: 1; padding: 12px 0; }
.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: #9ca3af;
  font-size: 14px;
  transition: var(--transition);
}
.admin-nav-item:hover { background: rgba(255,255,255,0.05); color: white; }
.admin-nav-item.active { background: rgba(64,158,255,0.15); color: var(--primary); }
.admin-nav-item i { width: 18px; text-align: center; }
.admin-nav-section { padding: 16px 20px 6px; font-size: 11px; color: #6b7280; text-transform: uppercase; letter-spacing: 1px; }
.admin-main { flex: 1; display: flex; flex-direction: column; }
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: white;
  border-bottom: 1px solid var(--border);
}
.admin-header-title { font-size: 16px; font-weight: 600; }
.admin-user { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text-secondary); }
.admin-content { flex: 1; padding: 24px; background: var(--bg); }

/* Admin cards & tables */
.admin-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.admin-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.admin-card-title { font-size: 16px; font-weight: 600; }
.admin-card-body { padding: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}
.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.green { background: #d1fae5; color: #059669; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }
.stat-icon.orange { background: #fed7aa; color: #ea580c; }
.stat-value { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--text-muted); }

/* Admin table */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.admin-table tr:hover td { background: #fafafa; }
.admin-table .actions { display: flex; gap: 8px; }
.admin-table .actions a, .admin-table .actions button {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 4px;
}
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.badge-success { background: #d1fae5; color: #059669; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-info { background: #dbeafe; color: #2563eb; }

/* Admin form */
.admin-form .form-group { margin-bottom: 16px; }
.admin-form label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}
.admin-form input[type="text"],
.admin-form input[type="email"],
.admin-form input[type="password"],
.admin-form input[type="number"],
.admin-form input[type="datetime-local"],
.admin-form input[type="url"],
.admin-form textarea,
.admin-form select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  transition: var(--transition);
}
.admin-form input:focus, .admin-form textarea:focus, .admin-form select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(64,158,255,0.15);
}
.admin-form .form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.admin-form .form-actions { display: flex; gap: 10px; padding-top: 16px; }

/* Admin pagination */
.pagination { display: flex; gap: 4px; justify-content: center; padding: 16px 0; }
.pagination a, .pagination span {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}
.pagination a:hover { border-color: var(--primary); color: var(--primary); }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }

/* Login page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea, var(--primary));
}
.login-card {
  width: 400px;
  background: white;
  border-radius: 16px;
  padding: 40px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.login-card h1 {
  text-align: center;
  margin-bottom: 8px;
  font-size: 24px;
}
.login-card .login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 14px;
}
.login-card .form-group { margin-bottom: 20px; }
.login-card label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.login-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
}
.login-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(64,158,255,0.15);
}
.login-card .btn { width: 100%; justify-content: center; padding: 12px; font-size: 16px; }
.login-error {
  background: #fee2e2;
  color: #dc2626;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
  text-align: center;
}
.alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; }
.alert-success { background: #d1fae5; color: #059669; }
.alert-error { background: #fee2e2; color: #dc2626; }

/* ====== Responsive ====== */
@media (max-width: 1024px) {
  .tool-detail-sidebar { display: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .site-sidebar {
    transform: translateX(-100%);
  }
  .site-sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open { display: block; }
  .main-area { margin-left: 0 !important; }
  .sidebar-toggle { display: block; }
  .main-content { padding: 16px; }
  .hero-title { font-size: 24px; }
  .hero-desc { font-size: 14px; }
  .tool-grid { grid-template-columns: 1fr; }
  .tool-detail-title h1 { font-size: 18px; }
  .admin-sidebar { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .login-card { width: 90%; padding: 24px; }
}

/* ====== Language Switcher ====== */
.lang-switcher {
  position: relative;
  margin-right: 12px;
}

.lang-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: var(--transition);
}

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

.lang-dropdown {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 100px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: var(--transition);
  z-index: 1000;
}

.lang-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-option {
  display: block;
  padding: 8px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  transition: var(--transition);
}

.lang-option:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.lang-option.active {
  color: var(--primary);
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ====== Friend Links ====== */
.friend-links {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.friend-links a {
  display: inline-block;
  margin: 4px 12px 4px 0;
  font-size: 13px;
  text-decoration: none;
  transition: var(--transition);
  opacity: 0.85;
}
.friend-links a:hover {
  opacity: 1;
  text-decoration: underline;
}
