/* ─── Import Fonts ──────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

/* ─── CSS Reset & Variables ─────────────────────────────────────── */
:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --bg-body: #f8f9fa;
  --bg-white: #ffffff;
  --bg-card: #ffffff;
  --bg-hover: #f1f3f5;
  --border-light: #e9ecef;
  --border-medium: #dee2e6;
  --border-subtle: rgba(0, 0, 0, 0.05);
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #868e96;
  --text-faint: #adb5bd;
  --accent: #228be6;
  --accent-light: #e7f5ff;
  --accent-glow: rgba(34, 139, 230, 0.15);
  --green-check: #40c057;
  --green-bg: #ebfbee;
  --green: #34d399;
  --blue: #60a5fa;
  --purple: #a78bfa;
  --amber: #fbbf24;
  --red: #f87171;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.06), 0 4px 6px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --transition: 0.2s ease;
}

[data-theme="dark"] {
  --bg-body: #0f111a;
  --bg-white: #1a1d27;
  --bg-card: #1e212b;
  --bg-hover: #2a2d39;
  --border-light: #2a2d39;
  --border-medium: #3b3f51;
  --border-subtle: rgba(255, 255, 255, 0.06);
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --accent: #818cf8;
  --accent-light: #1e3a8a;
  --accent-glow: rgba(129, 140, 248, 0.15);
  --green-bg: #064e3b;
  --green-check: #10b981;
}

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

html {
  font-family: var(--font-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.5;
}

/* ─── Scrollbar ─────────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #ced4da;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #adb5bd;
}

/* ─── Site Header ───────────────────────────────────────────────── */
.site-header {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}

.header-left {
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
}

.logo-text h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.header-center {
  flex: 1;
  max-width: 420px;
}

.search-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  pointer-events: none;
}

#search-input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  padding: 0 14px 0 36px;
  font-size: 13px;
  font-family: var(--font-main);
  color: var(--text-primary);
  background: var(--bg-body);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

#search-input::placeholder {
  color: var(--text-faint);
}

#search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 139, 230, 0.1);
  background: var(--bg-white);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.header-tabs {
  display: flex;
  align-items: center;
  background: var(--bg-body);
  border-radius: var(--radius-full);
  padding: 3px;
  border: 1px solid var(--border-light);
}

.header-tab {
  padding: 5px 14px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-main);
  transition: all var(--transition);
  white-space: nowrap;
}

.header-tab.active {
  background: var(--bg-white);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.header-tab:hover:not(.active) {
  color: var(--text-secondary);
}

.admin-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  transition: all var(--transition);
  text-decoration: none;
}

.admin-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* ─── Category Tabs ─────────────────────────────────────────────── */
.category-tabs {
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 60px;
  z-index: 90;
}

.tabs-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 46px;
  overflow-x: auto;
}

.tabs-inner::-webkit-scrollbar {
  display: none;
}

.cat-tab {
  padding: 6px 16px;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font-main);
  transition: all var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.cat-tab:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.cat-tab.active {
  background: var(--text-primary);
  color: var(--bg-white);
  font-weight: 600;
}

/* ─── Main Content ──────────────────────────────────────────────── */
.main-content {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px;
}

/* ─── Section ───────────────────────────────────────────────────── */
.section {
  margin-bottom: 36px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

.section-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-icon {
  font-size: 18px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.section-count {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-body);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-light);
}

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

.section-fav {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition);
  background: none;
  border: none;
  font-family: var(--font-main);
}

.section-fav:hover {
  color: var(--accent);
}

/* ─── Card Grid ─────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

@media (max-width: 1024px) {
  .card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .card-grid {
    grid-template-columns: 1fr;
  }
}

/* ─── Resource Card ─────────────────────────────────────────────── */
.resource-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  animation: cardFadeIn 0.3s ease both;
}

.resource-card:hover {
  border-color: var(--border-medium);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
  flex: 1;
}

.card-check {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
  border: 2px solid var(--border-medium);
  background: transparent;
  padding: 0;
}

.card-check:hover {
  border-color: var(--green-check);
}

.card-check.checked {
  background: var(--green-check);
  border-color: var(--green-check);
}

.card-check svg {
  width: 12px;
  height: 12px;
  opacity: 0;
  transition: opacity var(--transition);
}

.card-check.checked svg {
  opacity: 1;
}

.card-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

.card-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.02em;
}

/* ─── Tag Colors by category ────────────────────────────────────── */
.tag-dsa {
  background: #fff4e6;
  color: #e8590c;
}

.tag-java {
  background: #e7f5ff;
  color: #1971c2;
}

.tag-javascript {
  background: #fff9db;
  color: #e67700;
}

.tag-system-design {
  background: #f3f0ff;
  color: #7048e8;
}

.tag-default {
  background: #f1f3f5;
  color: #495057;
}

/* Difficulty tags */
.tag-beginner {
  background: #ebfbee;
  color: #2b8a3e;
}

.tag-intermediate {
  background: #fff4e6;
  color: #e8590c;
}

.tag-advanced {
  background: #ffe3e3;
  color: #c92a2a;
}

/* ─── Card Animations ───────────────────────────────────────────── */
@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.resource-card:nth-child(1) {
  animation-delay: 0ms;
}

.resource-card:nth-child(2) {
  animation-delay: 30ms;
}

.resource-card:nth-child(3) {
  animation-delay: 60ms;
}

.resource-card:nth-child(4) {
  animation-delay: 90ms;
}

.resource-card:nth-child(5) {
  animation-delay: 120ms;
}

.resource-card:nth-child(6) {
  animation-delay: 150ms;
}

/* ─── Empty State ───────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  max-width: 1320px;
  margin: 0 auto;
}

.empty-state.hidden {
  display: none;
}

.empty-icon {
  font-size: 56px;
  display: block;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-state p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.btn-clear {
  padding: 8px 20px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-medium);
  background: var(--bg-white);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font-main);
  transition: all var(--transition);
}

.btn-clear:hover {
  background: var(--bg-hover);
  border-color: var(--text-faint);
}

/* ─── Nested Subcategory Label ──────────────────────────────────── */
.nested-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
  margin-top: 16px;
  padding-left: 4px;
}

.nested-label:first-child {
  margin-top: 0;
}

/* ─── Responsive Header ────────────────────────────────────────── */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 16px;
    gap: 12px;
  }

  .header-center {
    max-width: none;
    flex: 1;
  }

  .header-tabs {
    display: none;
  }

  .logo-subtitle {
    display: none;
  }

  .tabs-inner {
    padding: 0 16px;
  }

  .main-content {
    padding: 16px;
  }
}

@media (max-width: 480px) {
  .logo-text h1 {
    font-size: 14px;
  }

  .admin-link {
    display: none;
  }
}

/* ─── Back to Resources Button ────────────────────────────────────── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-medium);
  padding: 8px 16px;
  border-radius: var(--radius-full);
  font-family: var(--font-main);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 24px;
}

.btn-back:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--text-faint);
  transform: translateX(-2px);
}

/* ─── Resource Viewer ────────────────────────────────────────────── */
.resource-viewer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* ─── Article Layout & TOC (Mini Tree) ─────────────────────────── */
.article-layout {
  display: flex;
  gap: 40px;
  align-items: flex-start;
}

.article-content-col {
  flex: 1;
  min-width: 0;
}

.article-toc-col {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  padding-left: 24px;
  border-left: 1px solid var(--border-medium);
}

.toc-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 16px;
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toc-h3 {
  padding-left: 12px;
}

.toc-link {
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color var(--transition);
  display: block;
  position: relative;
}

.toc-link:hover {
  color: var(--text-primary);
}

.toc-link.active {
  color: var(--accent);
  font-weight: 600;
}

/* Add custom scrollbar for TOC */
.article-toc-col::-webkit-scrollbar {
  width: 4px;
}

.article-toc-col::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 4px;
}

@media (max-width: 900px) {
  .article-layout {
    flex-direction: column;
  }

  .article-toc-col {
    display: none;
  }
}