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

:root {
  --bg: #f9f8f6;
  --bg-sidebar: #f2f0ec;
  --surface: #ffffff;
  --border: rgba(0,0,0,.045);
  --border-strong: rgba(0,0,0,.07);
  --text: #1c1c1e;
  --text-secondary: #6b6b70;
  --text-tertiary: #aeaeb2;
  --accent: #0d7b6b;
  --accent-hover: #096354;
  --accent-light: #edf7f4;
  --accent-border: #c0e5db;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.03);
  --shadow-md: 0 2px 8px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.03);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.03);
  --radius: 14px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ── */
.app { display: flex; min-height: 100vh; }

/* ── Sidebar ── */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-sidebar);
  padding: 24px 0 20px;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border-strong);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.sidebar-logo {
  font-size: 17px; font-weight: 700;
  padding: 0 20px 20px; letter-spacing: .02em;
  color: var(--text); display: flex; align-items: center; gap: 8px;
}
.sidebar-logo::before {
  content: ''; display: inline-block; width: 7px; height: 7px;
  border-radius: 50%; background: var(--accent); flex-shrink: 0;
}

.sidebar-divider {
  height: 1px; background: var(--border); margin: 6px 16px 7px;
}

.sidebar-nav { flex: 1; padding: 0 10px; }

.sidebar-item {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px; margin-bottom: 1px;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 13px; color: var(--text-secondary);
  transition: background .2s var(--ease), color .2s var(--ease); user-select: none;
  position: relative; text-decoration: none;
}
.sidebar-item:hover { background: rgba(0,0,0,.04); color: var(--text); }
.sidebar-item.active {
  background: var(--accent-light); color: var(--accent); font-weight: 600;
}
.sidebar-item.active::before {
  content: ''; position: absolute; left: -10px; top: 5px; bottom: 5px;
  width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}

.sidebar-item .count {
  display: none;
}

.sidebar-sub {
  padding-left: 20px;
}
.sidebar-sub .count { font-size: 10px; }

.sidebar-item-all {
  font-weight: 600; color: var(--text); margin-bottom: 2px;
}
.sidebar-item-all:hover { background: rgba(0,0,0,.04); }

/* ── Sidebar toggle ── */
.sidebar-toggle {
  width: 14px; height: 14px; flex-shrink: 0;
  color: var(--text-tertiary); margin-left: auto;
  transition: transform .3s var(--ease);
}
.sidebar-toggle.expanded { transform: rotate(90deg); }

.sidebar-children {
  overflow: hidden; max-height: 0;
  transition: max-height .25s ease;
}
.sidebar-children.expanded {
  max-height: 500px;
}

/* ── Sidebar subnav (mobile subcategory tabs) ── */
.sidebar-subnav {
  display: none;
  /* desktop: hidden */
}

/* ── Sidebar subnav items (shared) ── */
.subnav-item {
  white-space: nowrap; cursor: pointer; user-select: none;
  font-size: 12px; font-weight: 500; padding: 6px 0 4px;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: color .2s var(--ease), border-color .2s var(--ease);
  flex-shrink: 0;
}
.subnav-item:hover { color: var(--text); }
.subnav-item.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Main ── */
.main {
  flex: 1; min-width: 0;
  padding: 28px 32px 60px;
}

/* ── Header ── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; margin-bottom: 24px;
}
.header h1 { display: none; }  /* logo in sidebar */

.search-wrap { position: relative; width: 320px; }
.search-wrap svg {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-tertiary); pointer-events: none;
}
.search-input {
  width: 100%; padding: 9px 14px 9px 36px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit;
  background: var(--surface); color: var(--text); outline: none;
  transition: border-color .25s var(--ease), box-shadow .25s var(--ease);
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13,123,107,.15);
}

.current-category {
  font-size: 13px; color: var(--text-secondary);
  display: flex; align-items: center; gap: 6px;
}
.current-category span { color: var(--text); font-weight: 600; }

/* ── Tags ── */
.tags-wrap {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 28px;
  padding-bottom: 20px; border-bottom: 1px solid var(--border);
}
.tag-chip {
  padding: 4px 12px; border-radius: 100px;
  cursor: pointer; font-size: 12px; font-family: inherit;
  background: var(--surface); color: var(--text-secondary); border: 1px solid var(--border);
  transition: background .2s var(--ease), color .2s var(--ease), border-color .2s var(--ease); white-space: nowrap; font-weight: 500;
}
.tag-chip:hover { border-color: var(--accent-border); color: var(--accent); }
.tag-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.tag-chip-toggle {
  background: var(--accent-light); color: var(--accent);
  border-color: var(--accent-border); font-weight: 600;
}
.tag-chip-toggle:hover {
  background: var(--accent); color: #fff;
  border-color: var(--accent);
}

/* ── Cards grid ── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px; margin-bottom: 24px;
}

.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 22px 24px 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: transform .3s var(--ease), box-shadow .3s var(--ease);
  cursor: pointer;
  display: flex; flex-direction: column;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}
.card:active { transform: scale(.985); }

@keyframes cardIn {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
.card.enter { animation: cardIn .45s var(--ease) both; }

.card-title {
  font-size: 16px; font-weight: 600; margin-bottom: 10px;
  color: var(--text); text-decoration: none; display: inline-block;
  transition: color .2s var(--ease);
  height: 22px; line-height: 22px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 100%;
}
.card-title:hover { color: var(--accent); }
.card-title::after {
  content: ''; display: block; width: 0; height: 1.5px;
  background: var(--accent); border-radius: 2px;
  transition: width .25s var(--ease);
}
.card-title:hover::after { width: 100%; }

.card-desc {
  font-size: 13px; color: var(--text-secondary);
  line-height: 1.5; height: 20px; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis;
  margin-bottom: 12px;
}

.card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; min-height: 22px; align-content: flex-start; }
.card-tag {
  padding: 2px 10px; border-radius: 6px; font-size: 11px; font-weight: 500;
  background: var(--bg); color: var(--text-tertiary);
}

.card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: auto; }
.card-category {
  font-size: 11px; font-weight: 600; letter-spacing: .03em;
  padding: 3px 10px; border-radius: 6px;
  background: var(--accent-light); color: var(--accent);
}
.card-link {
  width: 32px; height: 32px; border-radius: 50%;
  color: var(--text-tertiary); text-decoration: none;
  display: flex; align-items: center; justify-content: center;
  transition: background .2s var(--ease), color .2s var(--ease); flex-shrink: 0;
}
.card-link svg { width: 15px; height: 15px; }
.card-link:hover {
  color: #fff; background: var(--accent);
}
.card-link:hover svg { transform: translateX(1px); }

/* ── Footer ── */
.footer { font-size: 13px; color: var(--text-tertiary); font-weight: 500; }

/* ── States ── */
.state-msg {
  grid-column: 1 / -1;
  display: flex; flex-direction: column; align-items: center;
  padding: 60px 20px; text-align: center; gap: 12px;
}
.state-msg svg { width: 36px; height: 36px; color: var(--text-tertiary); }
.state-msg p { font-size: 14px; color: var(--text-secondary); max-width: 300px; }

/* ── Skeleton ── */
@keyframes shimmer {
  0% { background-position: -400px 0; }
  100% { background-position: 400px 0; }
}
.skeleton {
  background: var(--surface); border-radius: var(--radius);
  padding: 20px 22px; border: 1px solid var(--border);
}
.skeleton-line {
  height: 12px; border-radius: 6px; margin-bottom: 10px;
  background: linear-gradient(90deg, #e8e7e5 25%, #d8d6d2 50%, #e8e7e5 75%);
  background-size: 800px 100%;
  animation: shimmer 1.8s infinite linear;
}
.skeleton-line:first-child { width: 55%; height: 16px; }
.skeleton-line:nth-child(2) { width: 88%; }
.skeleton-line:nth-child(3) { width: 35%; height: 20px; margin-top: 14px; }

/* ── Responsive ── */
@media (max-width: 860px) {
  .app { flex-direction: column; }

  .sidebar {
    width: 100%; height: auto; position: fixed; top: 0; left: 0; right: 0; z-index: 20;
    padding: 0; flex-direction: row; align-items: stretch;
    background: rgba(242,240,236,.92);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border-right: none; border-bottom: 1px solid var(--border-strong);
    overflow: visible;
  }
  .sidebar-logo {
    font-size: 14px; font-weight: 700; color: var(--text);
    padding: 10px 14px; flex-shrink: 0; display: flex; align-items: center; gap: 6px;
    border-right: 1px solid var(--border);
  }
  .sidebar-logo::before {
    content: ''; display: inline-block; width: 6px; height: 6px;
    border-radius: 50%; background: var(--accent); flex-shrink: 0;
  }

  .sidebar-nav {
    display: flex; gap: 4px; padding: 10px 16px;
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar { display: none; }

  .sidebar-item {
    white-space: nowrap; padding: 5px 12px; font-size: 12px;
    border-radius: 100px; flex-shrink: 0; gap: 0;
    background: transparent; border: 1px solid transparent;
  }
  .sidebar-item:hover { background: rgba(0,0,0,.04); border-color: var(--border); }
  .sidebar-item.active {
    background: var(--accent); color: #fff; font-weight: 500;
    border-color: var(--accent);
  }
  .sidebar-item.active::before { display: none; }
  .sidebar-item.active:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

  .sidebar-divider { display: none; }
  .sidebar-sub { padding-left: 0; }
  .sidebar-item .count { display: none; }
  .sidebar-toggle { display: none; }
  .sidebar-children { display: none; }

  /* Mobile subcategory tabs (fixed below main nav) */
  .sidebar-subnav {
    display: flex; gap: 16px; padding: 0 16px;
    overflow-x: auto; flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    position: fixed; top: 56px; left: 0; right: 0; z-index: 15;
    background: var(--bg-sidebar);
    border-bottom: 1px solid rgba(0,0,0,.04);
  }
  .sidebar-subnav::-webkit-scrollbar { display: none; }
  .sidebar-subnav:empty { display: none; }

  .subnav-item {
    font-size: 12px; padding: 8px 0 6px;
  }

  .main { padding: 110px 14px 40px; }

  .header {
    flex-direction: row; align-items: center; gap: 10px;
    margin-bottom: 14px;
  }
  .current-category { display: none; }
  .search-wrap { width: 100%; }
  .search-input { padding: 8px 12px 8px 32px; font-size: 13px; }
  .search-wrap svg { left: 10px; width: 14px; height: 14px; }

  .tags-wrap {
    padding-bottom: 12px; margin-bottom: 14px; gap: 4px;
  }
  .tag-chip { padding: 3px 10px; font-size: 11px; }

  .grid { grid-template-columns: 1fr; gap: 12px; }

  .card { padding: 18px 20px 16px; }
  .card.enter { animation-duration: .35s; }
  .card-title { font-size: 15px; height: 20px; line-height: 20px; }
  .card-desc { font-size: 12px; height: 20px; }

  .state-msg { padding: 40px 16px; }

  .footer { font-size: 12px; }
}
