/* ===== Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --secondary: #10b981;
  --bg: #f9fafb;
  --bg-card: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --transition: .2s ease;
  --max-w: 1200px;
}

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;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }

/* ===== Layout ===== */
.container { max-width: var(--max-w); width: 100%; margin: 0 auto; padding: 0 24px; }

/* ===== Navbar ===== */
.navbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}
.logo:hover { color: var(--primary); }
.logo-icon { font-size: 1.5rem; }
.nav-links {
  display: flex;
  gap: 4px;
  list-style: none;
}
.nav-links a {
  display: block;
  padding: 6px 14px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: .95rem;
  transition: var(--transition);
}
.nav-links a:hover, .nav-links a.active {
  background: #eff6ff;
  color: var(--primary);
}
.nav-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
}

/* ===== Main ===== */
.main-content { flex: 1; padding: 32px 0 24px; }

/* ===== Card ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-body { padding: 20px; }

/* ===== Grid ===== */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.sidebar-layout { display: grid; grid-template-columns: 1fr 300px; gap: 28px; align-items: start; }

/* tablet: 768-1024 */
@media (max-width: 1024px) and (min-width: 769px) {
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .sidebar-layout { grid-template-columns: 1fr 260px; }
}

/* ===== Hero ===== */
.hero {
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 50%, #06b6d4 100%);
  color: #fff;
  padding: 60px 16px;
  text-align: center;
  margin-bottom: 32px;
}
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.8rem); margin-bottom: 12px; }
.hero p { font-size: 1.1rem; opacity: .85; margin-bottom: 24px; }
.hero-btns { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 22px;
  border-radius: 6px;
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: var(--transition);
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-outline { background: transparent; border: 2px solid var(--primary); color: var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-white { background: #fff; color: var(--primary); }
.btn-white:hover { background: #f0f9ff; }
.btn-sm { padding: 6px 14px; font-size: .85rem; }
.btn-full { width: 100%; justify-content: center; }

/* ===== Article Card ===== */
.article-card { display: block; }
.article-card .card-body { display: flex; flex-direction: column; gap: 8px; }
.article-meta { display: flex; align-items: center; gap: 12px; font-size: .8rem; color: var(--text-muted); flex-wrap: wrap; }
.tag {
  display: inline-block;
  padding: 2px 10px;
  background: #eff6ff;
  color: var(--primary);
  border-radius: 20px;
  font-size: .78rem;
}
.article-title { font-size: 1.1rem; font-weight: 600; color: var(--text); line-height: 1.4; }
.article-summary { font-size: .9rem; color: var(--text-muted); line-height: 1.5; }

/* ===== Article Detail ===== */
.article-detail { max-width: 800px; }
.article-header { margin-bottom: 24px; }
.article-header h1 { font-size: clamp(1.4rem, 3vw, 2rem); margin-bottom: 12px; line-height: 1.3; }
.article-content { line-height: 1.8; font-size: 1rem; }
.article-content h2 { font-size: 1.4rem; margin: 28px 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--border); }
.article-content h3 { font-size: 1.2rem; margin: 20px 0 8px; }
.article-content p { margin-bottom: 16px; }
.article-content pre {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 16px 0;
  font-size: .9rem;
}
.article-content code {
  background: #f1f5f9;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: .9em;
  color: #e11d48;
}
.article-content pre code { background: none; color: inherit; padding: 0; }
.article-content blockquote {
  border-left: 4px solid var(--primary);
  padding: 8px 16px;
  margin: 16px 0;
  background: #f0f9ff;
  color: var(--text-muted);
}
.article-content ul, .article-content ol { margin: 12px 0 12px 24px; }
.article-content li { margin-bottom: 6px; }
.article-content img { max-width: 100%; border-radius: 6px; }
.article-content a { text-decoration: underline; }
.article-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.article-content th, .article-content td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.article-content th { background: var(--bg); }

/* ===== Comments ===== */
.comment-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.comment-item:last-child { border-bottom: none; }
.comment-header { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.comment-username { font-weight: 600; font-size: .9rem; }
.comment-time { font-size: .78rem; color: var(--text-muted); }
.comment-content { font-size: .9rem; line-height: 1.6; }

/* ===== Form ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: 6px; color: var(--text); }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .95rem;
  color: var(--text);
  background: #fff;
  transition: border-color var(--transition);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
textarea.form-control { resize: vertical; min-height: 100px; }

/* ===== Tools ===== */
.tool-card { cursor: pointer; }
.tool-icon { font-size: 2rem; margin-bottom: 10px; }
.result-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 16px;
  margin-top: 16px;
  font-family: 'Courier New', monospace;
  font-size: .88rem;
  white-space: pre-wrap;
  word-break: break-all;
}
.result-box.success { border-color: var(--secondary); background: #f0fdf4; }
.result-box.error { border-color: #f87171; background: #fff5f5; }

/* ===== Project ===== */
.project-card .tags { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 4px; }
.project-links { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* ===== Pagination ===== */
.pagination { display: flex; justify-content: center; gap: 6px; margin-top: 28px; flex-wrap: wrap; }
.page-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: .9rem;
  color: var(--text-muted);
  background: #fff;
  transition: var(--transition);
}
.page-btn:hover, .page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===== Search ===== */
.search-bar { display: flex; gap: 8px; margin-bottom: 20px; }
.search-bar input { flex: 1; }

/* ===== Section ===== */
.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-title::before { content: attr(data-icon); font-size: 1.2rem; }

/* ===== Sidebar ===== */
.sidebar-card { margin-bottom: 16px; }
.sidebar-card .card-body { padding: 16px; }
.sidebar-title { font-weight: 600; margin-bottom: 12px; font-size: .95rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-size: .8rem; }
.category-list { list-style: none; }
.category-list li { padding: 6px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.category-list li:last-child { border-bottom: none; }

/* ===== Ad ===== */
.ad-container { margin: 16px auto 0; min-height: 90px; }

/* ===== Footer ===== */
.footer {
  background: var(--text);
  color: rgba(255,255,255,.7);
  padding: 24px 0;
  margin-top: auto;
}
.footer-inner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.footer-links { display: flex; gap: 16px; }
.footer-links a { color: rgba(255,255,255,.6); font-size: .85rem; }
.footer-links a:hover { color: #fff; }
.footer-copy { font-size: .85rem; }

/* ===== Loading / Toast ===== */
.loading { text-align: center; padding: 40px; color: var(--text-muted); font-size: 1.1rem; }
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1f2937;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: .9rem;
  z-index: 999;
  transform: translateY(0);
  animation: slideIn .3s ease;
}
.toast.success { background: var(--secondary); }
.toast.error { background: #ef4444; }
@keyframes slideIn { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card { text-align: center; padding: 20px; }
.stat-number { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-label { font-size: .85rem; color: var(--text-muted); margin-top: 4px; }

/* ===== Empty ===== */
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-icon { font-size: 3rem; margin-bottom: 12px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .container { padding: 0 16px; }
  .nav-toggle { display: block; }
  .nav-links {
    display: none;
    flex-direction: column;
    position: absolute;
    top: 60px;
    left: 0; right: 0;
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 8px 16px 16px;
    box-shadow: var(--shadow-md);
    z-index: 99;
  }
  .nav-links.open { display: flex; }
  .navbar { position: relative; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .sidebar-layout { grid-template-columns: 1fr; }
  .hero { padding: 40px 16px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .footer-inner { flex-direction: column; text-align: center; }
}
@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.6rem; }
  .card-body { padding: 14px; }
}

/* ===== Admin ===== */
.admin-layout { display: grid; grid-template-columns: 220px 1fr; gap: 0; min-height: calc(100vh - 60px); }
.admin-sidebar {
  background: #1e293b;
  color: #cbd5e1;
  padding: 20px 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
}
.admin-sidebar-logo { padding: 0 20px 20px; font-weight: 700; color: #fff; font-size: 1.05rem; border-bottom: 1px solid #334155; margin-bottom: 10px; }
.admin-nav-item {
  display: block;
  padding: 10px 20px;
  color: #94a3b8;
  font-size: .9rem;
  cursor: pointer;
  transition: var(--transition);
  border-left: 3px solid transparent;
}
.admin-nav-item:hover, .admin-nav-item.active { background: #0f172a; color: #fff; border-left-color: var(--primary); }
.admin-main { padding: 28px 32px; background: var(--bg); }
.admin-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.admin-title { font-size: 1.4rem; font-weight: 700; }
.admin-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 28px; }
.admin-stat-card { background: #fff; border-radius: var(--radius); padding: 20px; border: 1px solid var(--border); }
.admin-stat-num { font-size: 2rem; font-weight: 700; color: var(--primary); }
.admin-stat-label { font-size: .85rem; color: var(--text-muted); margin-top: 4px; }
.admin-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.admin-table th { background: #f8fafc; padding: 12px 16px; text-align: left; font-size: .85rem; color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); }
.admin-table td { padding: 12px 16px; font-size: .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: #f9fafb; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: .75rem; font-weight: 500; }
.badge-green { background: #dcfce7; color: #16a34a; }
.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-red { background: #fee2e2; color: #dc2626; }
.editor-toolbar { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 12px; background: #f8fafc; border: 1px solid var(--border); border-bottom: none; border-radius: 6px 6px 0 0; }
.editor-btn { padding: 4px 10px; background: #fff; border: 1px solid var(--border); border-radius: 4px; font-size: .82rem; cursor: pointer; color: var(--text); transition: var(--transition); }
.editor-btn:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.editor-area { border-radius: 0 0 6px 6px !important; border-radius: 0 !important; min-height: 320px; font-family: 'Courier New', monospace; font-size: .9rem; line-height: 1.7; }
.editor-preview { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 20px; min-height: 320px; }
.login-box { max-width: 420px; margin: 80px auto; }
.login-box .card-body { padding: 40px; }
.login-title { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: 28px; }
@media (max-width: 768px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar { position: static; height: auto; }
  .admin-main { padding: 16px; }
  .admin-stats { grid-template-columns: repeat(2, 1fr); }
}
