/* ============================================================
   X-GORB Baike - Frontend Stylesheet
   Encyclopedia System
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --color-primary: #1a73e8;
  --color-primary-dark: #1557b0;
  --color-primary-light: #e8f0fe;
  --color-primary-hover: #1669d3;
  --color-secondary: #5f6368;
  --color-bg: #ffffff;
  --color-bg-secondary: #f8f9fa;
  --color-bg-tertiary: #f1f3f4;
  --color-text: #202124;
  --color-text-secondary: #5f6368;
  --color-text-muted: #80868b;
  --color-border: #dadce0;
  --color-border-light: #e8eaed;
  --color-success: #0f9d58;
  --color-warning: #f4b400;
  --color-danger: #db4437;
  --color-info: #4285f4;
  --color-white: #ffffff;
  --color-black: #000000;
  --color-shadow: rgba(0, 0, 0, 0.1);
  --color-shadow-dark: rgba(0, 0, 0, 0.15);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
  --font-family-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "Consolas", monospace;
  --header-height: 64px;
  --sidebar-width: 260px;
  --max-width: 1200px;
  --border-radius: 8px;
  --border-radius-sm: 4px;
  --border-radius-lg: 12px;
  --transition: 0.2s ease;
  --transition-slow: 0.3s ease;
}

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

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

body {
  font-family: var(--font-family);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text);
  background-color: var(--color-bg-secondary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

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

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

ul, ol {
  list-style: none;
}

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

h1, h2, h3, h4, h5, h6 {
  line-height: 1.3;
  font-weight: 600;
  color: var(--color-text);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.1rem; }
h5 { font-size: 1rem; }
h6 { font-size: 0.9rem; }

/* ============================================================
   HEADER / NAVBAR
   ============================================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 2px 4px var(--color-shadow);
  height: var(--header-height);
}

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

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

.header-logo a {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: var(--color-text);
}

.header-logo img {
  height: 36px;
  width: auto;
}

.header-logo span {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-primary);
}

.header-logo-sub {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-left: 4px;
}

/* Header Search */
.header-search {
  flex: 1;
  max-width: 540px;
  position: relative;
}

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

.header-search input {
  width: 100%;
  height: 40px;
  padding: 0 44px 0 16px;
  border: 2px solid var(--color-border);
  border-radius: 24px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--color-bg-secondary);
}

.header-search input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
  background: var(--color-white);
}

.header-search button {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.header-search button:hover {
  background: var(--color-primary-dark);
}

.header-search button svg {
  width: 18px;
  height: 18px;
}

/* Header Nav */
.header-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-nav a {
  padding: 8px 12px;
  border-radius: var(--border-radius);
  color: var(--color-text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
}

.header-nav a:hover {
  background: var(--color-bg-secondary);
  color: var(--color-primary);
  text-decoration: none;
}

.header-nav a.active {
  color: var(--color-primary);
  background: var(--color-primary-light);
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  gap: 4px;
  width: 28px;
  padding: 4px;
  cursor: pointer;
}

.mobile-menu-toggle span {
  display: block;
  height: 2px;
  background: var(--color-text);
  border-radius: 2px;
  transition: transform var(--transition), opacity var(--transition);
}

/* ============================================================
   HOMEPAGE SEARCH (Large Centered)
   ============================================================ */
.homepage-search {
  text-align: center;
  padding: 80px 20px 60px;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-white) 50%, #e8f5e9 100%);
}

.homepage-search h1 {
  font-size: 2.5rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--color-text);
}

.homepage-search p {
  font-size: 1.1rem;
  color: var(--color-text-secondary);
  margin-bottom: 32px;
}

.homepage-search .search-wrapper {
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}

.homepage-search .search-wrapper input {
  width: 100%;
  height: 52px;
  padding: 0 56px 0 24px;
  border: 2px solid var(--color-border);
  border-radius: 28px;
  font-size: 1.1rem;
  outline: none;
  transition: all var(--transition);
  background: var(--color-white);
  box-shadow: 0 2px 8px var(--color-shadow);
}

.homepage-search .search-wrapper input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 4px 16px var(--color-shadow-dark);
}

.homepage-search .search-wrapper button {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}

.homepage-search .search-wrapper button:hover {
  background: var(--color-primary-dark);
}

.homepage-search .search-wrapper button svg {
  width: 22px;
  height: 22px;
}

/* ============================================================
   SEARCH AUTOCOMPLETE DROPDOWN
   ============================================================ */
.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  box-shadow: 0 8px 24px var(--color-shadow-dark);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1001;
  display: none;
}

.search-dropdown.active {
  display: block;
}

.search-dropdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--color-border-light);
}

.search-dropdown-item:last-child {
  border-bottom: none;
}

.search-dropdown-item:hover,
.search-dropdown-item.active {
  background: var(--color-primary-light);
}

.search-dropdown-item .search-item-thumb {
  width: 48px;
  height: 48px;
  border-radius: var(--border-radius-sm);
  object-fit: cover;
  background: var(--color-bg-tertiary);
  flex-shrink: 0;
}

.search-dropdown-item .search-item-thumb-placeholder {
  width: 48px;
  height: 48px;
  border-radius: var(--border-radius-sm);
  background: var(--color-bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--color-text-muted);
}

.search-dropdown-item .search-item-info {
  flex: 1;
  min-width: 0;
}

.search-dropdown-item .search-item-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-dropdown-item .search-item-summary {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.search-dropdown-item .search-item-category {
  font-size: 0.75rem;
  color: var(--color-primary);
  background: var(--color-primary-light);
  padding: 2px 8px;
  border-radius: 12px;
  flex-shrink: 0;
}

.search-dropdown-empty {
  padding: 20px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.search-dropdown-loading {
  padding: 20px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ============================================================
   MAIN CONTENT AREA
   ============================================================ */
.main-content {
  flex: 1;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 20px;
  width: 100%;
}

/* ============================================================
   BREADCRUMB
   ============================================================ */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 0 16px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.breadcrumb a {
  color: var(--color-text-secondary);
}

.breadcrumb a:hover {
  color: var(--color-primary);
}

.breadcrumb .separator {
  color: var(--color-text-muted);
  margin: 0 4px;
  user-select: none;
}

.breadcrumb .current {
  color: var(--color-text);
  font-weight: 500;
}

/* ============================================================
   CATEGORY GRID
   ============================================================ */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.category-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 24px 16px;
  text-align: center;
  transition: transform var(--transition), box-shadow var(--transition);
  cursor: pointer;
}

.category-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px var(--color-shadow-dark);
  border-color: var(--color-primary);
}

.category-card .category-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  color: var(--color-primary);
}

.category-card .category-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 4px;
}

.category-card .category-count {
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* ============================================================
   ENTRY CARDS
   ============================================================ */
.entry-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.entry-card {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}

.entry-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px var(--color-shadow-dark);
}

.entry-card .entry-card-thumb {
  width: 100%;
  height: 180px;
  object-fit: cover;
  background: var(--color-bg-tertiary);
}

.entry-card .entry-card-thumb-placeholder {
  width: 100%;
  height: 180px;
  background: linear-gradient(135deg, var(--color-primary-light), var(--color-bg-tertiary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: var(--color-primary);
}

.entry-card .entry-card-body {
  padding: 16px;
}

.entry-card .entry-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.entry-card .entry-card-title a {
  color: var(--color-text);
}

.entry-card .entry-card-title a:hover {
  color: var(--color-primary);
}

.entry-card .entry-card-summary {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.5;
}

.entry-card .entry-card-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--color-text-muted);
}

.entry-card .entry-card-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.entry-card .entry-card-meta .entry-category-tag {
  background: var(--color-primary-light);
  color: var(--color-primary);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
}

/* ============================================================
   ENTRY DETAIL PAGE
   ============================================================ */
.entry-detail {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  align-items: start;
}

.entry-detail-main {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 32px;
  min-width: 0;
}

.entry-detail-sidebar {
  position: sticky;
  top: calc(var(--header-height) + 24px);
}

/* Entry Header */
.entry-header {
  margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--color-border-light);
}

.entry-header h1 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.entry-header .entry-meta-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.entry-header .entry-views,
.entry-header .entry-date {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Entry Thumbnail */
.entry-thumbnail {
  margin-bottom: 24px;
  border-radius: var(--border-radius);
  overflow: hidden;
}

.entry-thumbnail img {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
}

.entry-thumbnail .entry-thumbnail-caption {
  padding: 8px 12px;
  background: var(--color-bg-tertiary);
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  text-align: center;
}

/* ============================================================
   INFO BOX (Baidu Baike style)
   ============================================================ */
.info-box {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  overflow: hidden;
  margin-bottom: 20px;
}

.info-box-title {
  background: var(--color-primary);
  color: var(--color-white);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
}

.info-box-image {
  padding: 16px;
  text-align: center;
}

.info-box-image img {
  max-width: 100%;
  border-radius: var(--border-radius-sm);
  margin: 0 auto;
}

.info-box-image .info-box-image-caption {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 6px;
}

.info-box table {
  width: 100%;
  border-collapse: collapse;
}

.info-box table tr {
  border-bottom: 1px solid var(--color-border-light);
}

.info-box table tr:last-child {
  border-bottom: none;
}

.info-box table tr:nth-child(even) {
  background: var(--color-bg-secondary);
}

.info-box table td {
  padding: 8px 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  vertical-align: top;
}

.info-box table td.field-name {
  color: var(--color-text-muted);
  font-weight: 500;
  white-space: nowrap;
  width: 1%;
  background: var(--color-bg-tertiary);
  font-size: 0.82rem;
  min-width: 72px;
}

.info-box table td.field-value {
  color: var(--color-text);
}

/* ============================================================
   TOC (Table of Contents)
   ============================================================ */
.toc {
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  padding: 16px;
  margin-bottom: 20px;
  position: sticky;
  top: calc(var(--header-height) + 24px);
}

.toc-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-primary);
  color: var(--color-text);
}

.toc-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.toc-list li {
  padding: 0;
  margin: 0;
}

.toc-list li a {
  display: block;
  padding: 6px 12px;
  font-size: 0.85rem;
  color: var(--color-text-secondary);
  border-radius: var(--border-radius-sm);
  transition: all var(--transition);
  border-left: 2px solid transparent;
}

.toc-list li a:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  text-decoration: none;
  border-left-color: var(--color-primary);
}

.toc-list li a.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
  font-weight: 600;
  border-left-color: var(--color-primary);
}

.toc-list .toc-h2 {
  padding-left: 0;
}

.toc-list .toc-h3 {
  padding-left: 16px;
}

.toc-list .toc-h4 {
  padding-left: 32px;
}

/* ============================================================
   CONTENT AREA TYPOGRAPHY
   ============================================================ */
.content-area {
  font-size: 1rem;
  line-height: 1.8;
  color: var(--color-text);
}

.content-area h2 {
  font-size: 1.5rem;
  margin: 32px 0 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--color-primary);
}

.content-area h3 {
  font-size: 1.25rem;
  margin: 24px 0 12px;
}

.content-area h4 {
  font-size: 1.1rem;
  margin: 20px 0 10px;
}

.content-area p {
  margin-bottom: 16px;
  text-align: justify;
}

.content-area ul,
.content-area ol {
  margin: 12px 0 16px 24px;
}

.content-area ul {
  list-style: disc;
}

.content-area ol {
  list-style: decimal;
}

.content-area li {
  margin-bottom: 6px;
}

.content-area blockquote {
  margin: 16px 0;
  padding: 12px 20px;
  border-left: 4px solid var(--color-primary);
  background: var(--color-primary-light);
  color: var(--color-text-secondary);
  border-radius: 0 var(--border-radius-sm) var(--border-radius-sm) 0;
}

.content-area img {
  max-width: 100%;
  height: auto;
  border-radius: var(--border-radius);
  margin: 16px auto;
}

.content-area figure {
  margin: 20px 0;
  text-align: center;
}

.content-area figure figcaption {
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-top: 8px;
}

.content-area table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.9rem;
}

.content-area table th,
.content-area table td {
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  text-align: left;
}

.content-area table th {
  background: var(--color-primary-light);
  font-weight: 600;
  color: var(--color-text);
}

.content-area table tr:nth-child(even) td {
  background: var(--color-bg-secondary);
}

.content-area table tr:hover td {
  background: var(--color-primary-light);
}

.content-area code {
  background: var(--color-bg-tertiary);
  padding: 2px 6px;
  border-radius: var(--border-radius-sm);
  font-family: var(--font-family-mono);
  font-size: 0.9em;
  color: var(--color-primary-dark);
}

.content-area pre {
  background: var(--color-bg-tertiary);
  padding: 16px;
  border-radius: var(--border-radius);
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid var(--color-border-light);
}

.content-area pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: var(--color-text);
}

.content-area hr {
  border: none;
  border-top: 1px solid var(--color-border-light);
  margin: 24px 0;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px 0;
  flex-wrap: wrap;
}

.pagination a,
.pagination span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius-sm);
  font-size: 0.9rem;
  color: var(--color-text-secondary);
  background: var(--color-white);
  transition: all var(--transition);
}

.pagination a:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary);
  text-decoration: none;
}

.pagination .current {
  background: var(--color-primary);
  color: var(--color-white);
  border-color: var(--color-primary);
  font-weight: 600;
}

.pagination .disabled {
  color: var(--color-text-muted);
  cursor: not-allowed;
  opacity: 0.5;
}

.pagination .ellipsis {
  border: none;
  background: none;
  cursor: default;
}

/* ============================================================
   FOOTER
   ============================================================ */
.footer {
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
  padding: 32px 20px 20px;
  margin-top: auto;
}

.footer-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 24px;
}

.footer-col h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--color-text);
}

.footer-col ul li {
  margin-bottom: 6px;
}

.footer-col ul li a {
  font-size: 0.85rem;
  color: var(--color-text-secondary);
}

.footer-col ul li a:hover {
  color: var(--color-primary);
}

.footer-bottom {
  max-width: var(--max-width);
  margin: 24px auto 0;
  padding-top: 16px;
  border-top: 1px solid var(--color-border-light);
  text-align: center;
  font-size: 0.8rem;
  color: var(--color-text-muted);
}

/* ============================================================
   ALERT MESSAGES
   ============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--border-radius);
  margin-bottom: 16px;
  font-size: 0.9rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.alert-success {
  background: #e6f4ea;
  color: #1e7e34;
  border: 1px solid #c3e6cb;
}

.alert-warning {
  background: #fef7e0;
  color: #b06000;
  border: 1px solid #ffeeba;
}

.alert-danger {
  background: #fce8e6;
  color: #c5221f;
  border: 1px solid #f5c6cb;
}

.alert-info {
  background: #e8f0fe;
  color: #1967d2;
  border: 1px solid #c6dafc;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--border-radius);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}

.btn:hover {
  text-decoration: none;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-white);
  border-color: var(--color-primary);
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  border-color: var(--color-primary-dark);
}

.btn-secondary {
  background: var(--color-bg-tertiary);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-border);
}

.btn-outline {
  background: transparent;
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.btn-outline:hover {
  background: var(--color-primary);
  color: var(--color-white);
}

.btn-danger {
  background: var(--color-danger);
  color: var(--color-white);
  border-color: var(--color-danger);
}

.btn-danger:hover {
  background: #c23321;
}

.btn-sm {
  padding: 4px 12px;
  font-size: 0.8rem;
}

.btn-lg {
  padding: 12px 28px;
  font-size: 1rem;
}

.btn-block {
  display: flex;
  width: 100%;
}

/* ============================================================
   FORMS (Frontend)
   ============================================================ */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-text);
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--color-white);
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

textarea.form-control {
  resize: vertical;
  min-height: 100px;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%235f6368' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }
.text-primary { color: var(--color-primary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.mt-0 { margin-top: 0; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition), visibility var(--transition);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-white);
  border-radius: var(--border-radius-lg);
  padding: 24px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px var(--color-shadow-dark);
  transform: translateY(20px);
  transition: transform var(--transition);
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: var(--color-text-muted);
  transition: background var(--transition);
}

.modal-close:hover {
  background: var(--color-bg-tertiary);
}

.modal-body {
  margin-bottom: 20px;
  font-size: 0.95rem;
  color: var(--color-text-secondary);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ============================================================
   STATUS BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
}

.badge-draft {
  background: #f1f3f4;
  color: #5f6368;
}

.badge-pending {
  background: #fef7e0;
  color: #b06000;
}

.badge-published {
  background: #e6f4ea;
  color: #1e7e34;
}

.badge-rejected {
  background: #fce8e6;
  color: #c5221f;
}

.badge-primary {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

/* ============================================================
   LOADING / SKELETON
   ============================================================ */
.skeleton {
  background: linear-gradient(90deg, var(--color-bg-tertiary) 25%, var(--color-border-light) 50%, var(--color-bg-tertiary) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--border-radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ============================================================
   RESPONSIVE DESIGN
   ============================================================ */
@media (max-width: 1024px) {
  .entry-detail {
    grid-template-columns: 1fr;
  }

  .entry-detail-sidebar {
    position: static;
    order: -1;
  }

  .toc {
    position: static;
  }

  .info-box {
    max-width: 400px;
  }
}

@media (max-width: 768px) {
  :root {
    --header-height: 56px;
  }

  .header-logo span {
    font-size: 1.1rem;
  }

  .header-logo-sub {
    display: none;
  }

  .header-search {
    display: none;
  }

  .header-search.mobile-visible {
    display: block;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    max-width: none;
    padding: 8px 16px;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 2px 8px var(--color-shadow);
    z-index: 1001;
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .header-nav {
    display: none;
    position: absolute;
    top: var(--header-height);
    left: 0;
    right: 0;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    box-shadow: 0 2px 8px var(--color-shadow);
    padding: 12px 16px;
    flex-direction: column;
    z-index: 1001;
  }

  .header-nav.mobile-open {
    display: flex;
  }

  .homepage-search {
    padding: 40px 16px 32px;
  }

  .homepage-search h1 {
    font-size: 1.8rem;
  }

  .category-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
  }

  .entry-cards {
    grid-template-columns: 1fr;
  }

  .entry-detail-main {
    padding: 20px;
  }

  .entry-header h1 {
    font-size: 1.5rem;
  }

  .footer-inner {
    grid-template-columns: 1fr 1fr;
  }

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

@media (max-width: 480px) {
  .homepage-search h1 {
    font-size: 1.5rem;
  }

  .homepage-search .search-wrapper input {
    height: 44px;
    font-size: 1rem;
    padding: 0 48px 0 16px;
  }

  .category-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .entry-detail-main {
    padding: 16px;
  }

  .entry-header h1 {
    font-size: 1.3rem;
  }

  .footer-inner {
    grid-template-columns: 1fr;
  }

  .pagination a,
  .pagination span {
    min-width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }
}

/* ============================================================
   PRINT STYLES
   ============================================================ */
@media print {
  .header,
  .footer,
  .toc,
  .search-dropdown,
  .mobile-menu-toggle,
  .header-nav {
    display: none !important;
  }

  .entry-detail {
    grid-template-columns: 1fr;
  }

  .entry-detail-sidebar {
    position: static;
  }

  body {
    background: white;
    color: black;
  }

  .content-area {
    font-size: 12pt;
  }
}

/* ============================================================
   SMOOTH SCROLL HIGHLIGHT
   ============================================================ */
.content-area h2:target,
.content-area h3:target,
.content-area h4:target {
  animation: target-highlight 2s ease;
}

@keyframes target-highlight {
  0% { background: #fff3cd; }
  100% { background: transparent; }
}

/* ============================================================
   IMAGE LAZY LOADING
   ============================================================ */
img.lazy {
  opacity: 0;
  transition: opacity 0.3s ease;
}

img.lazy.loaded {
  opacity: 1;
}

/* ============================================================
   ENTRY RELATED / TAGS
   ============================================================ */
.entry-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.entry-tag {
  display: inline-block;
  padding: 4px 12px;
  background: var(--color-bg-tertiary);
  border-radius: 16px;
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  transition: all var(--transition);
}

.entry-tag:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  text-decoration: none;
}

/* ============================================================
   RELATED ENTRIES
   ============================================================ */
.related-entries {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--color-border-light);
}

.related-entries h3 {
  margin-bottom: 16px;
}

.related-entries-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.related-entry-item {
  display: flex;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--color-border-light);
  border-radius: var(--border-radius);
  transition: all var(--transition);
}

.related-entry-item:hover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.related-entry-item img {
  width: 60px;
  height: 60px;
  border-radius: var(--border-radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.related-entry-item .related-entry-info {
  flex: 1;
  min-width: 0;
}

.related-entry-item .related-entry-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
}

.related-entry-item .related-entry-summary {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ============================================================
   SCROLL TO TOP
   ============================================================ */
.scroll-to-top {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--color-shadow-dark);
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all var(--transition);
  z-index: 999;
}

.scroll-to-top.visible {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.scroll-to-top:hover {
  background: var(--color-primary-dark);
  transform: translateY(-2px);
}

.scroll-to-top svg {
  width: 20px;
  height: 20px;
}