/* ═══════════════════════════════════════════════════════
   模板大全工具站 v2 - 全面移动端适配
   ═══════════════════════════════════════════════════════ */

:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-50: #f5f3ff;
  --accent: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 6px rgba(0,0,0,.06), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.04);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --max-width: 1280px;
  --header-h: 56px;
  --nav-h: 44px;
}

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

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; transition: color .15s; }
a:hover { color: var(--primary-hover); }

img { max-width: 100%; height: auto; }

/* ══════════════════════════════════
   HEADER
   ══════════════════════════════════ */

.site-header {
  background: var(--card-bg);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  height: var(--header-h);
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.5px;
}
.site-logo:hover { text-decoration: none; color: var(--text); }
.site-logo .logo-icon { font-size: 28px; }

/* 汉堡菜单按钮 - 仅移动端 */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.menu-toggle:hover { background: var(--border-light); }

/* PC端隐藏移动端导航 */

/* ── 导航条 ── */
.nav-wrap {
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}

.nav-scroll {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.nav-scroll::-webkit-scrollbar { display: none; }

.nav-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all .15s;
  font-weight: 500;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  cursor: pointer;
}
.nav-item:hover {
  color: var(--primary);
  background: var(--primary-50);
  text-decoration: none;
  border-bottom-color: var(--primary);
}
.nav-item.active {
  color: var(--primary);
  font-weight: 600;
  border-bottom-color: var(--primary);
  background: var(--primary-50);
}

/* ══════════════════════════════════
   BREADCRUMB
   ══════════════════════════════════ */

.breadcrumb {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 20px 0;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
}
.breadcrumb a { color: var(--text-secondary); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb span.sep { margin: 0 4px; color: var(--text-muted); }

/* ══════════════════════════════════
   MAIN CONTAINER
   ══════════════════════════════════ */

.main-container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 20px;
}

/* ── 页面标题区 ── */
.page-header {
  margin-bottom: 4px;
}
.page-header h1 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1.3;
}
.page-header p {
  font-size: 15px;
  color: var(--text-secondary);
  margin-top: 6px;
}

/* ── 统计条 ── */
.stats-bar {
  display: flex;
  gap: 20px;
  margin: 16px 0;
  flex-wrap: wrap;
}
.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  background: var(--card-bg);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.stat-item strong { color: var(--primary); font-weight: 700; }

/* ── 搜索框 ── */
.search-box {
  margin: 16px 0 20px;
  position: relative;
}
.search-box input {
  width: 100%;
  padding: 12px 16px 12px 44px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  outline: none;
  transition: all .2s;
  background: var(--card-bg);
}
.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.search-box input::placeholder { color: var(--text-muted); }
.search-box .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

/* ══════════════════════════════════
   首页 - 分类卡片网格
   ══════════════════════════════════ */

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 8px;
}

.category-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  transition: all .2s;
  position: relative;
  overflow: hidden;
}
.category-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  opacity: 0;
  transition: opacity .2s;
}
.category-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
  transform: translateY(-2px);
  text-decoration: none;
}
.category-card:hover::before { opacity: 1; }

.card-icon {
  font-size: 36px;
  margin-bottom: 14px;
  line-height: 1;
}
.card-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.card-desc {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}
.card-count {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-light);
  padding: 3px 10px;
  border-radius: 12px;
}
.card-arrow {
  color: var(--text-muted);
  font-size: 16px;
  transition: transform .2s;
}
.category-card:hover .card-arrow { transform: translateX(3px); color: var(--primary); }

/* ══════════════════════════════════
   分类页 - 模板列表
   ══════════════════════════════════ */

.sub-section {
  margin-top: 28px;
}
.sub-section-title {
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.sub-section-title .count-badge {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  background: var(--border-light);
  padding: 2px 10px;
  border-radius: 10px;
}

.template-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.template-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  transition: all .15s;
  gap: 12px;
}
.template-item:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--primary);
  text-decoration: none;
  transform: translateX(2px);
}
.tpl-info { flex: 1; min-width: 0; }
.tpl-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}
.tpl-title .status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tpl-title .status-dot.ready { background: var(--success); }
.tpl-title .status-dot.pending { background: var(--warning); }
.tpl-desc {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tpl-arrow {
  color: var(--text-muted);
  font-size: 18px;
  flex-shrink: 0;
  transition: all .15s;
}
.template-item:hover .tpl-arrow { color: var(--primary); transform: translateX(2px); }

/* ══════════════════════════════════
   模板详情页
   ══════════════════════════════════ */

.detail-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  margin-top: 20px;
  align-items: start;
}

.detail-main {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
}
.detail-main h1 {
  font-size: 24px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -.3px;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0 16px;
}
.tag {
  background: var(--primary-light);
  color: var(--primary);
  padding: 3px 12px;
  border-radius: 14px;
  font-size: 12px;
  font-weight: 500;
}

.detail-desc {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 20px;
}

/* 下载按钮组 */
.download-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0;
  padding: 18px;
  background: linear-gradient(135deg, var(--primary-50), #f0fdf4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.download-bar .dl-label {
  width: 100%;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  transition: all .15s;
  box-shadow: var(--shadow-sm);
}
.download-btn:hover {
  opacity: .9;
  text-decoration: none;
  color: #fff;
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.download-btn.word { background: #2b579a; }
.download-btn.pdf { background: #d32f2f; }
.download-btn.md { background: #1e293b; }
.download-btn.disabled {
  background: #cbd5e1;
  cursor: not-allowed;
  pointer-events: none;
  box-shadow: none;
}

/* 模板内容区 */
.template-content {
  margin-top: 24px;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
  font-size: 15px;
  line-height: 1.9;
}
.template-content h1 { font-size: 22px; margin: 24px 0 12px; font-weight: 700; }
.template-content h2 { font-size: 18px; margin: 20px 0 10px; font-weight: 700; }
.template-content h3 { font-size: 16px; margin: 16px 0 8px; font-weight: 600; }
.template-content p { margin-bottom: 12px; }
.template-content ul, .template-content ol { margin: 8px 0 16px 24px; }
.template-content li { margin-bottom: 4px; }
.template-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 14px;
}
.template-content th, .template-content td {
  border: 1px solid var(--border);
  padding: 10px 14px;
  text-align: left;
}
.template-content th {
  background: var(--primary-light);
  font-weight: 600;
  color: var(--text);
}
.template-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}
.template-content strong { color: var(--text); }

/* 空内容 */
.empty-content {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-secondary);
}
.empty-content .empty-icon { font-size: 52px; margin-bottom: 16px; }
.empty-content p { font-size: 15px; }

/* ── 右侧边栏 ── */
.detail-sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: calc(var(--header-h) + var(--nav-h) + 20px);
}

.sidebar-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.sidebar-section h3 {
  font-size: 14px;
  font-weight: 700;
  padding: 14px 18px;
  background: var(--border-light);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-section .sidebar-body { padding: 6px 0; }

.sidebar-link {
  display: block;
  padding: 10px 18px;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border-light);
  transition: all .1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-link:hover {
  color: var(--primary);
  background: var(--primary-50);
  text-decoration: none;
}
.sidebar-link:last-child { border-bottom: none; }

.sidebar-empty {
  padding: 16px 18px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ══════════════════════════════════
   FOOTER
   ══════════════════════════════════ */

.site-footer {
  text-align: center;
  padding: 40px 20px;
  margin-top: 48px;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}
.footer-main {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.footer-sub {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
}
.footer-warn {
  margin-top: 12px;
  font-size: 12px;
  color: var(--warning);
  background: #fffbeb;
  display: inline-block;
  padding: 4px 14px;
  border-radius: 14px;
}

/* ══════════════════════════════════
   移动端 - 768px 以下
   ══════════════════════════════════ */

@media (max-width: 768px) {
  :root {
    --header-h: 50px;
  }

  .menu-toggle { display: block; }

  .nav-wrap {
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
  }
  .nav-wrap.open {
    max-height: 600px;
    overflow-y: auto;
    border-top: 1px solid var(--border);
  }

  .nav-scroll {
    overflow-x: visible;
    padding: 0;
  }

  .nav-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    min-width: auto;
    padding: 0;
  }

  .nav-item {
    padding: 12px 8px;
    font-size: 13px;
    text-align: center;
    border: none;
    border-bottom: 1px dashed var(--border);
    border-right: 1px dashed var(--border);
    border-radius: 0;
    justify-content: center;
  }
  .nav-item:nth-child(3n) {
    border-right: none;
  }
  .nav-item:nth-last-child(-n+2) {
    border-bottom: none;
  }
  .nav-item:hover, .nav-item.active {
    background: var(--primary-50);
    border-bottom-color: var(--border);
    border-right-color: var(--border);
  }

  .main-container { padding: 16px; }

  .page-header h1 { font-size: 22px; }

  /* 首页卡片 - 手机双列 */
  .category-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .category-card {
    padding: 16px 14px;
    border-radius: var(--radius);
  }
  .card-icon { font-size: 28px; margin-bottom: 10px; }
  .card-title { font-size: 14px; }
  .card-desc { font-size: 12px; -webkit-line-clamp: 1; }
  .card-footer { margin-top: 10px; padding-top: 8px; }
  .card-count { font-size: 11px; padding: 2px 8px; }

  /* 详情页 - 单列 */
  .detail-layout {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .detail-main { padding: 20px 16px; border-radius: var(--radius); }
  .detail-main h1 { font-size: 20px; }

  .detail-sidebar {
    position: static;
  }

  .download-bar {
    padding: 14px;
    gap: 8px;
  }
  .download-btn {
    padding: 10px 14px;
    font-size: 12px;
    flex: 1;
    justify-content: center;
    min-width: 0;
  }

  .template-content {
    padding: 18px 14px;
    font-size: 14px;
    overflow-x: auto;
  }
  .template-content table { font-size: 13px; }
  .template-content th, .template-content td { padding: 8px 10px; }

  .template-item { padding: 12px 14px; }
  .tpl-title { font-size: 14px; }

  .breadcrumb { font-size: 12px; padding: 10px 16px 0; }

  .stats-bar { gap: 8px; }
  .stat-item { padding: 4px 10px; font-size: 12px; }

  .sub-section-title { font-size: 16px; }
}

/* ══════════════════════════════════
   极小屏幕 - 375px 以下
   ══════════════════════════════════ */

@media (max-width: 375px) {
  .category-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .category-card {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 14px;
  }
  .card-icon { font-size: 32px; margin-bottom: 0; flex-shrink: 0; }
  .card-body { flex: 1; min-width: 0; }
  .card-title { font-size: 15px; }
  .card-desc { display: none; }
  .card-footer { display: none; }
}

/* ══════════════════════════════════
   平板 - 769px ~ 1024px
   ══════════════════════════════════ */

@media (min-width: 769px) and (max-width: 1024px) {
  .category-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .detail-layout {
    grid-template-columns: 1fr 260px;
  }
}

/* ══════════════════════════════════
   打印样式
   ══════════════════════════════════ */

@media print {
  .site-header, .nav-wrap, .breadcrumb,
  .search-box, .detail-sidebar, .site-footer,
  .download-bar { display: none !important; }

  .detail-layout { grid-template-columns: 1fr !important; }
  .detail-main {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  .template-content {
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
  }

  body { background: #fff; }
}

/* ══════════════════════════════════
   动画
   ══════════════════════════════════ */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.category-card, .template-item, .detail-main, .sidebar-section {
  animation: fadeIn .3s ease;
}

/* ══════════════════════════════════
   回到顶部
   ══════════════════════════════════ */

.back-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  opacity: 0;
  transform: translateY(10px);
  transition: all .2s;
  z-index: 50;
  border: none;
}
.back-to-top:hover { background: var(--primary-hover); }
.back-to-top.visible { opacity: 1; transform: translateY(0); }
