/* === Rice Bran Wiki — Stylesheet === */

:root {
  --primary: #2d6a4f;
  --primary-light: #40916c;
  --bg: #f8faf8;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-secondary: #555;
  --border: #e0e5e0;
  --accent: #d4a017;
  --warning: #e67e22;
  --danger: #c0392b;
  --sidebar-width: 260px;
}

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

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

/* === Top Navigation === */
.top-nav {
  background: var(--primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.top-nav .logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
  text-decoration: none;
}
.nav-links { display: flex; gap: 8px; }
.nav-links a {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background 0.2s;
}
.nav-links a:hover { background: rgba(255,255,255,0.15); }

/* === Layout === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  gap: 32px;
  padding: 24px;
  min-height: calc(100vh - 56px - 60px);
}
.container.home-layout { display: block; }

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  position: sticky;
  top: 80px;
  align-self: flex-start;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.sidebar-section {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.sidebar-section h3 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.meta-item { font-size: 0.85rem; margin-bottom: 4px; color: var(--text-secondary); }
.meta-item span { font-weight: 600; color: var(--text); }

/* === Content === */
.content {
  flex: 1;
  min-width: 0;
}
.content.full-width { max-width: 900px; margin: 0 auto; }

.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.breadcrumb a { color: var(--primary); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

/* === Hero === */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 48px 32px;
  border-radius: 12px;
  margin-bottom: 32px;
  text-align: center;
}
.hero h1 { font-size: 2rem; margin-bottom: 8px; }
.hero p { opacity: 0.9; margin-bottom: 24px; }
.quick-links { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.quick-card {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 10px;
  padding: 20px;
  width: 220px;
  color: white;
  text-decoration: none;
  text-align: left;
  transition: transform 0.2s, background 0.2s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.quick-card:hover { transform: translateY(-3px); background: rgba(255,255,255,0.25); }
.quick-card .icon { font-size: 1.5rem; }
.quick-card strong { font-size: 1.05rem; }
.quick-card small { font-size: 0.75rem; opacity: 0.8; line-height: 1.4; }

/* === Typography === */
h1 { font-size: 1.8rem; margin: 32px 0 16px; color: var(--primary); border-bottom: 2px solid var(--border); padding-bottom: 8px; }
h2 { font-size: 1.4rem; margin: 28px 0 12px; color: var(--primary); }
h3 { font-size: 1.15rem; margin: 20px 0 8px; }
p { margin-bottom: 12px; }
hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.wiki-link { color: var(--primary); font-weight: 500; }
.wiki-link::before { content: "📄 "; font-size: 0.8rem; }
.raw-link { color: var(--accent); font-weight: 500; }
.raw-link::before { content: "📋 "; font-size: 0.8rem; }
.broken-link { color: var(--danger); text-decoration: line-through; cursor: help; }

code {
  background: #f0f4f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
  font-family: "JetBrains Mono", "Fira Code", monospace;
}
pre {
  background: #1a1a2e;
  color: #a8d8a8;
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 16px 0;
}
pre code { background: none; padding: 0; }

blockquote {
  border-left: 4px solid var(--accent);
  background: #fefdf5;
  padding: 12px 16px;
  margin: 16px 0;
  border-radius: 0 8px 8px 0;
}
blockquote strong { color: var(--warning); }

/* === Tables === */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 16px 0;
  font-size: 0.9rem;
}
th {
  background: var(--primary);
  color: white;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
}
td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
tr:nth-child(even) { background: #f5f8f5; }
tr:hover { background: #edf2ed; }

/* === Lists === */
ul, ol { margin: 8px 0 16px 24px; }
li { margin-bottom: 4px; }

/* === Tags === */
.tag {
  display: inline-block;
  background: #e8f5e9;
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  text-decoration: none;
  margin: 2px;
  transition: background 0.2s;
}
.tag:hover { background: #c8e6c9; }
.tag-list { margin-top: 8px; }

/* === Listing === */
.listing { display: flex; flex-direction: column; gap: 12px; }
.listing-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: box-shadow 0.2s, transform 0.2s;
  display: block;
}
.listing-item:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  transform: translateY(-2px);
  text-decoration: none;
}
.listing-item h3 { color: var(--primary); margin-top: 0; }
.excerpt { color: var(--text-secondary); font-size: 0.9rem; }

/* === Search Hero === */
.search-hero {
  background: linear-gradient(135deg, #1a3a2a 0%, #2d6a4f 40%, #40916c 100%);
  padding: 48px 24px 40px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.search-hero::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 70%, rgba(255,255,255,0.05) 0%, transparent 50%),
              radial-gradient(circle at 70% 30%, rgba(255,255,255,0.03) 0%, transparent 40%);
  pointer-events: none;
}
.search-hero-inner { max-width: 720px; margin: 0 auto; position: relative; z-index: 1; }
.search-hero h1 {
  color: #fff;
  font-size: 2.2rem;
  margin: 0 0 8px;
  border: none;
  padding: 0;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.search-subtitle { color: rgba(255,255,255,0.7); font-size: 1rem; margin: 0 0 28px; }
.search-box-wrapper {
  position: relative;
  margin-bottom: 20px;
}
.search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.3rem;
  z-index: 2;
  pointer-events: none;
}
.search-input-lg {
  width: 100%;
  padding: 18px 24px 18px 56px;
  font-size: 1.15rem;
  border: none;
  border-radius: 16px;
  outline: none;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.15);
  transition: all 0.25s;
}
.search-input-lg:focus {
  box-shadow: 0 6px 32px rgba(0,0,0,0.25), 0 0 0 4px rgba(255,255,255,0.2);
  transform: translateY(-1px);
}
.search-input-lg::placeholder { color: #aaa; }

.search-tags {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
  color: rgba(255,255,255,0.6);
  font-size: 0.85rem;
}
.search-tags a {
  color: rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.12);
  padding: 5px 14px;
  border-radius: 20px;
  text-decoration: none;
  font-size: 0.82rem;
  transition: all 0.2s;
  backdrop-filter: blur(4px);
}
.search-tags a:hover {
  background: rgba(255,255,255,0.25);
  color: #fff;
}

/* === Search Results Grid === */
.search-results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.search-card {
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  transition: all 0.25s;
  position: relative;
}
.search-card:hover {
  box-shadow: 0 8px 30px rgba(0,0,0,0.1);
  border-color: var(--primary-light);
  transform: translateY(-3px);
}
.search-card.relevance-high { border-left: 4px solid var(--primary); }
.search-card.relevance-medium { border-left: 4px solid var(--accent); }
.search-card.relevance-normal { border-left: 4px solid var(--border); }
.search-card:hover .search-card-title { color: #1a5c3a; }

.search-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.type-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.type-entity { background: #e3f2fd; color: #1565c0; }
.type-concept { background: #f3e5f5; color: #7b1fa2; }
.type-topic { background: #e8f5e9; color: #2e7d32; }

.rank-badge {
  font-size: 0.7rem;
  color: var(--text-secondary);
  background: #f5f5f5;
  padding: 2px 8px;
  border-radius: 10px;
}

.search-card-title {
  color: var(--primary);
  font-size: 1.05rem;
  margin: 0 0 10px;
  font-weight: 700;
  line-height: 1.4;
  transition: color 0.2s;
}

.search-card-snippet {
  font-size: 0.82rem;
  color: #666;
  line-height: 1.65;
  margin-bottom: 12px;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.search-card-snippet mark {
  background: linear-gradient(180deg, transparent 60%, #ffe082 60%);
  padding: 1px 3px;
  border-radius: 2px;
  color: #333;
  font-weight: 500;
}

.search-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid #f0f0f0;
  padding-top: 10px;
}

.score-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4caf50;
  flex-shrink: 0;
  position: relative;
}
.score-dot::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
  top: 2px;
  left: 2px;
}

/* === Search Status & Hints === */
#search-status { min-height: 0; }
.search-error-card {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 16px 20px;
  border-radius: 12px;
  text-align: center;
  font-size: 0.95rem;
  margin: 24px 0;
}
.search-hint {
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 20px 0;
}
.result-count {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin: 0 0 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* === No Results === */
.no-results-card {
  text-align: center;
  padding: 60px 20px;
  background: var(--card-bg);
  border-radius: 16px;
  border: 1px solid var(--border);
}
.no-results-icon { font-size: 4rem; margin-bottom: 16px; opacity: 0.6; }
.no-results-card h2 { font-size: 1.3rem; color: var(--text); margin-bottom: 8px; border: none; }
.no-results-card h2 span { color: var(--primary); }
.no-results-card p { color: var(--text-secondary); margin-bottom: 20px; }
.no-results-tags {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.no-results-tags a {
  color: var(--primary);
  background: #e8f5e9;
  padding: 6px 16px;
  border-radius: 20px;
  text-decoration: none;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.no-results-tags a:hover {
  background: var(--primary);
  color: #fff;
}

/* === Responsive search === */
@media (max-width: 768px) {
  .search-hero { padding: 32px 16px 28px; }
  .search-hero h1 { font-size: 1.5rem; }
  .search-input-lg { padding: 14px 18px 14px 44px; font-size: 1rem; }
  .search-icon { left: 14px; font-size: 1.1rem; }
  .search-results-grid { grid-template-columns: 1fr; }
}

/* === Footer === */
footer {
  text-align: center;
  padding: 18px;
  color: var(--text-secondary);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  background: var(--card-bg);
}

/* === TOC === */
#toc { font-size: 0.82rem; }
#toc a { display: block; padding: 2px 0; color: var(--text-secondary); text-decoration: none; }
#toc a:hover { color: var(--primary); }

/* === Responsive === */
@media (max-width: 768px) {
  .container { flex-direction: column; padding: 16px; }
  .sidebar { width: 100%; position: static; }
  .quick-links { flex-direction: column; align-items: center; }
  .quick-card { width: 100%; max-width: 320px; }
  h1 { font-size: 1.4rem; }
  table { font-size: 0.8rem; }
}
