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

:root {
  --color-bg: #f8f9fb;
  --color-surface: #ffffff;
  --color-border: #e2e6ed;
  --color-border-light: #f0f2f5;
  --color-text: #1a1f36;
  --color-text-secondary: #525f7f;
  --color-text-muted: #8792a2;
  --color-primary: #3d7c2a;
  --color-primary-hover: #2e6320;
  --color-primary-light: #e8f5e3;
  --color-primary-bg: #d4edcc;
  --color-success: #0cce6b;
  --color-warning: #f5a623;
  --color-danger: #e25950;
  --color-info: #3ecf8e;
  --color-code-bg: #f4f5f7;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --header-height: 64px;
  --max-width: 1200px;
  --content-width: 800px;
}

html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

/* ===== Internal Banner ===== */
.internal-banner {
  background: var(--color-danger);
  color: #fff;
  text-align: center;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ===== Header ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #1a2332;
  height: var(--header-height);
}
.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 24px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #ffffff;
  white-space: nowrap;
  flex-shrink: 0;
}
.logo:hover { text-decoration: none; color: var(--color-primary-light); }
.logo svg { color: #ffffff; }

.header-search {
  position: relative;
  flex: 1;
  max-width: 480px;
}
.header-search .search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.5);
  pointer-events: none;
}
.header-search input {
  width: 100%;
  padding: 8px 40px 8px 40px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  background: #253347;
  color: #ffffff;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.header-search input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}
.header-search input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(61, 124, 42, 0.3);
  background: #2d3e54;
}
.search-shortcut {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.5);
  font-family: inherit;
  pointer-events: none;
}

/* ===== Search Dropdown ===== */
.search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
}
.search-dropdown.hidden { display: none; }
.search-result {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border-light);
  cursor: pointer;
  transition: background 0.1s;
}
.search-result:hover, .search-result.active { background: var(--color-primary-light); }
.search-result:last-child { border-bottom: none; }
.search-result-title { font-weight: 600; font-size: 0.9rem; color: var(--color-text); }
.search-result-category { font-size: 0.78rem; color: var(--color-text-muted); margin-top: 2px; }
.search-result-snippet { font-size: 0.82rem; color: var(--color-text-secondary); margin-top: 4px; }
.search-result-snippet mark { background: var(--color-primary-bg); color: var(--color-primary); border-radius: 2px; padding: 0 2px; }
.search-no-results { padding: 24px 16px; text-align: center; color: var(--color-text-muted); font-size: 0.9rem; }

/* ===== Main Content ===== */
#app { flex: 1; max-width: var(--max-width); margin: 0 auto; padding: 32px 24px; width: 100%; }

/* ===== Home Page ===== */
.home-hero {
  text-align: center;
  padding: 48px 24px;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, #fff 100%);
  border-radius: var(--radius-lg);
  margin-bottom: 40px;
  border: 1px solid var(--color-border-light);
}
.home-hero h1 { font-size: 2rem; font-weight: 800; margin-bottom: 8px; }
.home-hero p { font-size: 1.1rem; color: var(--color-text-secondary); max-width: 520px; margin: 0 auto 24px; }
.home-search {
  max-width: 520px;
  margin: 0 auto;
  position: relative;
}
.home-search .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}
.home-search input {
  width: 100%;
  padding: 14px 20px 14px 48px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: 1rem;
  box-shadow: var(--shadow-sm);
  background: var(--color-surface);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.home-search input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light), var(--shadow-sm);
}
.home-search .search-dropdown {
  text-align: left;
}

/* Home page tabs */
.home-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--color-border-light);
}
.home-tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.15s, border-color 0.15s;
}
.home-tab:hover {
  color: var(--color-text);
}
.home-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.categories-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 48px;
}
.category-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 24px;
  transition: box-shadow 0.15s, border-color 0.15s, transform 0.15s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.category-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
  transform: translateY(-2px);
  text-decoration: none;
}
.category-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary);
  margin-bottom: 4px;
}
.category-card h3 { font-size: 1rem; font-weight: 700; color: var(--color-text); }
.category-card p { font-size: 0.85rem; color: var(--color-text-secondary); line-height: 1.5; }
.category-card .article-count { font-size: 0.78rem; color: var(--color-text-muted); margin-top: auto; padding-top: 8px; }

/* ===== Category Page ===== */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 24px;
}
.breadcrumb a { color: var(--color-text-secondary); }
.breadcrumb a:hover { color: var(--color-primary); }
.breadcrumb .separator { color: var(--color-border); }

.category-header { margin-bottom: 32px; }
.category-header h1 { font-size: 1.75rem; font-weight: 800; margin-bottom: 4px; }
.category-header p { color: var(--color-text-secondary); font-size: 1rem; }

.subcategory-section { margin-bottom: 24px; }
.subcategory-section:last-child { margin-bottom: 0; }
.subcategory-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-secondary);
  padding: 6px 4px;
  border: none;
  border-bottom: 1px solid var(--color-border);
  background: none;
  cursor: pointer;
  width: 100%;
  margin-bottom: 4px;
  transition: color 0.15s;
}
.subcategory-toggle:hover { color: var(--color-text); }
.subcategory-toggle .chevron {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}
.subcategory-section.collapsed .subcategory-toggle .chevron { transform: rotate(-90deg); }
.subcategory-toggle .subcategory-count {
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-left: 4px;
}
.subcategory-body {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.25s ease;
}
.subcategory-section.collapsed .subcategory-body { grid-template-rows: 0fr; }
.subcategory-body-inner { overflow: hidden; }

.article-content details {
  margin: 12px 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
}
.article-content details summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: color 0.15s;
}
.article-content details summary::-webkit-details-marker { display: none; }
.article-content details summary::before {
  content: '▶';
  font-size: 0.65rem;
  transition: transform 0.2s ease;
}
.article-content details[open] summary::before { transform: rotate(90deg); }
.article-content details summary:hover { color: var(--color-text); }
.article-content details > :not(summary) { padding: 0 16px 12px; }
.article-content details img { margin-top: 4px; border-radius: var(--radius-sm); }

.article-list { display: flex; flex-direction: column; gap: 2px; }
.article-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: background 0.1s, border-color 0.15s;
  color: var(--color-text);
}
.article-list-item:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  text-decoration: none;
}
.article-list-item svg { flex-shrink: 0; color: var(--color-text-muted); }
.article-list-item:hover svg { color: var(--color-primary); }
.article-list-item-content { flex: 1; }
.article-list-item-title { font-weight: 600; font-size: 0.95rem; }
.article-list-item-desc { font-size: 0.82rem; color: var(--color-text-secondary); margin-top: 2px; }

/* ===== Article Page ===== */
.article-layout {
  display: grid;
  grid-template-columns: 1fr 260px;
  gap: 40px;
  align-items: start;
}
@media (max-width: 900px) {
  .article-layout { grid-template-columns: 1fr; }
  .article-sidebar { display: none; }
}

.article-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 40px;
}
.article-content h1 { font-size: 1.75rem; font-weight: 800; margin-bottom: 8px; line-height: 1.3; }
.article-content h2 { scroll-margin-top: calc(var(--header-height) + 24px); }
.article-meta { font-size: 0.82rem; color: var(--color-text-muted); margin-bottom: 28px; padding-bottom: 20px; border-bottom: 1px solid var(--color-border-light); }
.article-meta span + span::before { content: ' \00b7 '; margin: 0 6px; }
.article-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.article-tag {
  font-size: 0.72rem;
  background: var(--color-primary-light);
  color: var(--color-primary);
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 500;
}

/* Article body typography */
.article-body h2 { font-size: 1.35rem; font-weight: 700; margin: 32px 0 12px; padding-top: 16px; border-top: 1px solid var(--color-border-light); }
.article-body h2:first-child { margin-top: 0; padding-top: 0; border-top: none; }
.article-body h3 { font-size: 1.1rem; font-weight: 600; margin: 24px 0 8px; }
.article-body p { margin: 0 0 16px; }
.article-body ul, .article-body ol { margin: 0 0 16px; padding-left: 24px; }
.article-body li { margin-bottom: 6px; }
.article-body li > ul, .article-body li > ol { margin-top: 6px; margin-bottom: 0; }
.article-body code {
  background: var(--color-code-bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.88em;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.article-body pre {
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 16px;
  overflow-x: auto;
  margin: 0 0 16px;
}
.article-body pre code { background: none; padding: 0; }
.article-body blockquote {
  border-left: 4px solid var(--color-primary);
  background: var(--color-primary-light);
  padding: 12px 16px;
  margin: 0 0 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--color-text-secondary);
}
.article-body blockquote p:last-child { margin-bottom: 0; }
.article-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 16px;
  font-size: 0.9rem;
}
.article-body th, .article-body td {
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
}
.article-body th { background: var(--color-bg); font-weight: 600; }
.article-body img, .article-body .image-placeholder {
  max-width: 100%;
  border-radius: var(--radius-sm);
  margin: 8px 0 16px;
}
.article-body img:not(.image-placeholder) {
  cursor: zoom-in;
}

/* Image lightbox */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  cursor: zoom-out;
  padding: 24px;
}
.lightbox-overlay img {
  max-width: 95vw;
  max-height: 92vh;
  border-radius: var(--radius-md);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}
.image-placeholder {
  background: var(--color-bg);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-md);
  padding: 32px 24px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.85rem;
}
.image-placeholder svg { margin-bottom: 8px; opacity: 0.4; }

/* Callout boxes */
.article-body .callout,
.article-content > .callout {
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 0 0 16px;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 10px;
}
.article-body .callout-icon,
.article-content > .callout .callout-icon { flex-shrink: 0; }
.callout-info { background: #e8f4fd; border-left: 4px solid #3498db; }
.callout-warning { background: #fef9e7; border-left: 4px solid var(--color-warning); }
.callout-danger { background: #fde8e7; border-left: 4px solid var(--color-danger); }
.callout-tip { background: #e8fdf0; border-left: 4px solid var(--color-success); }

/* Sidebar */
.article-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 24px);
}
.sidebar-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}
.sidebar-section h4 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
  margin-bottom: 12px;
  font-weight: 600;
}
.toc-list { list-style: none; }
.toc-list li { margin-bottom: 6px; }
.toc-list a {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  display: block;
  padding: 4px 0;
  border-left: 2px solid transparent;
  padding-left: 10px;
  transition: color 0.1s, border-color 0.1s;
}
.toc-list a:hover, .toc-list a.active {
  color: var(--color-primary);
  border-left-color: var(--color-primary);
  text-decoration: none;
}
.related-list { list-style: none; }
.related-list li { margin-bottom: 8px; }
.related-list a { font-size: 0.85rem; color: var(--color-text-secondary); }
.related-list a:hover { color: var(--color-primary); }

/* ===== Footer ===== */
.footer {
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  padding: 24px;
  text-align: center;
  font-size: 0.82rem;
  color: var(--color-text-muted);
}
.footer-inner { max-width: var(--max-width); margin: 0 auto; }
.footer-meta { margin-top: 4px; }

/* ===== Loading ===== */
.loading {
  display: flex;
  justify-content: center;
  padding: 48px;
}
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Search Results Page ===== */
.search-page h1 { font-size: 1.5rem; margin-bottom: 24px; }
.search-results-count { color: var(--color-text-muted); font-size: 0.9rem; margin-bottom: 16px; }

/* ===== Status Badges & Dropdown ===== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 99px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
.status-badge--needs-review {
  background: #fef3e2;
  color: #b45309;
  border: 1px solid #fcd9a0;
}
.status-badge--reviewed {
  background: #e6f9ed;
  color: #0f6b31;
  border: 1px solid #a3e4ba;
}
.status-badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-badge--needs-review .status-badge-dot { background: #d97706; }
.status-badge--reviewed .status-badge-dot { background: #16a34a; }

/* Status dropdown on article page */
.status-dropdown-wrapper {
  position: relative;
  display: inline-block;
}
.status-dropdown-trigger {
  cursor: pointer;
  transition: opacity 0.15s;
  user-select: none;
}
.status-dropdown-trigger:hover { opacity: 0.85; }
.status-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 50;
  min-width: 180px;
  overflow: hidden;
}
.status-dropdown-menu.hidden { display: none; }
.status-dropdown-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.1s;
  color: var(--color-text);
}
.status-dropdown-option:hover { background: var(--color-bg); }
.status-dropdown-option.active { background: var(--color-primary-light); font-weight: 600; }
.status-dropdown-option .status-badge-dot { width: 8px; height: 8px; }
.status-dropdown-option .option-dot-needs-review { background: #d97706; }
.status-dropdown-option .option-dot-reviewed { background: #16a34a; }
.status-dropdown-option .checkmark { margin-left: auto; color: var(--color-primary); font-size: 0.9rem; }

/* Status in article list items */
.article-list-item .status-badge { margin-left: auto; flex-shrink: 0; }

/* Status in article header */
.article-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.article-status-label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-weight: 500;
}


/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .header-inner { padding: 0 16px; }
  .header-search { max-width: 100%; }
  .logo span { display: none; }
  #app { padding: 20px 16px; }
  .home-hero { padding: 32px 16px; }
  .home-hero h1 { font-size: 1.5rem; }
  .categories-grid { grid-template-columns: 1fr; }
  .article-content { padding: 24px; }
}
