/* =====================================
   Neurosurgery Digest — Complete Stylesheet
   Dark theme · RTL-first · Responsive
   ===================================== */

/* ── Variables ────────────────────── */
:root {
  --bg: #0b1120;
  --bg-card: #131c31;
  --bg-hover: #1a2744;
  --bg-sidebar: #0f172a;
  --border: #1e293b;
  --border-light: #334155;

  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-dim: rgba(99,102,241,0.12);

  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);

  --font: 'Vazirmatn', system-ui, -apple-system, sans-serif;
}

/* ── Reset ─────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.8;
  direction: rtl;
  text-align: right;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
img { max-width: 100%; }

/* ── Header ────────────────────────── */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 1.25rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.logo-icon { font-size: 2rem; }
.site-name {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.site-subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

/* ── Container ─────────────────────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem;
}

/* ── Page Layout (post/article) ─────── */
.page-layout {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
}
.page-content {
  flex: 1;
  min-width: 0;
}
.page-sidebar {
  width: 280px;
  flex-shrink: 0;
  position: sticky;
  top: 90px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
}

/* ── Back button ───────────────────── */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  transition: 0.2s;
}
.back-link:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

/* ── Post Card (index page) ─────────── */
.posts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin-top: 2rem;
}
.post-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: 0.25s ease;
}
.post-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-3px);
  box-shadow: 0 8px 30px rgba(99,102,241,0.08);
}
.post-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.post-date {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.post-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent-hover);
  border: 1px solid rgba(99,102,241,0.2);
}
.post-card-title {
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.5;
  margin-bottom: 0.75rem;
}
.post-card-title a {
  color: var(--text);
}
.post-card-title a:hover {
  color: var(--accent);
  text-decoration: none;
}
.post-card-summary {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.post-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Search & Filter ────────────────── */
.search-section {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}
.search-input {
  flex: 1;
  min-width: 250px;
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-family: var(--font);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  transition: 0.2s;
}
.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.search-input::placeholder { color: var(--text-muted); }
.filter-select {
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-family: var(--font);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  min-width: 180px;
}
.filter-select:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Article Content (inside digest) ── */
.article-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 1.5rem;
  transition: 0.2s;
}
.article-card:hover { border-color: var(--border-light); }
.article-card h2 {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text);
  line-height: 1.5;
}
.article-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  padding: 0.6rem 1rem;
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
}
.article-meta .badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent-hover);
}
.article-card h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--accent);
  margin: 1.25rem 0 0.5rem;
}
.article-card ul {
  list-style: none;
  padding: 0;
  margin: 0 0 0.5rem;
}
.article-card ul li {
  position: relative;
  padding-right: 1.25rem;
  margin-bottom: 0.4rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.7;
}
.article-card ul li::before {
  content: '▸';
  position: absolute;
  right: 0;
  color: var(--accent);
  opacity: 0.6;
}
.article-card p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.8;
  margin-bottom: 0.5rem;
  text-align: justify;
}
.single-article-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--accent);
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  transition: 0.2s;
}
.single-article-link:hover {
  background: var(--accent-dim);
  text-decoration: none;
}

/* ── Tip Box ───────────────────────── */
.tip-box {
  background: var(--accent-dim);
  border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--radius-lg);
  padding: 1.5rem 2rem;
  margin: 2rem 0;
}
.tip-box strong {
  color: var(--accent-hover);
  font-size: 1rem;
}
.tip-box p { color: var(--text-secondary) !important; margin-bottom: 0.5rem !important; }
.tip-box ul { margin: 0.5rem 0; }
.tip-box ul li::before { content: '💡' !important; }

/* ── TOC Sidebar ────────────────────── */
.toc-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.toc-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}
.toc-list {
  list-style: none;
}
.toc-list li {
  margin-bottom: 0.35rem;
}
.toc-list a {
  display: block;
  padding: 0.35rem 0.5rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
  border-radius: 6px;
  border-right: 2px solid transparent;
  transition: 0.2s;
  line-height: 1.5;
}
.toc-list a:hover {
  background: var(--accent-dim);
  color: var(--text);
  border-right-color: var(--accent);
  text-decoration: none;
}
.toc-list a.active {
  background: var(--accent-dim);
  color: var(--accent-hover);
  border-right-color: var(--accent);
}

/* ── Single Article Page ─────────────── */
.article-page {
  max-width: 800px;
  margin: 0 auto;
}
.article-page .article-meta {
  font-size: 0.9rem;
  padding: 0.75rem 1.25rem;
}
.article-page .article-meta .badge {
  font-size: 0.75rem;
  padding: 0.3rem 0.75rem;
}
.article-page h1 {
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.5;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.article-body {
  margin-top: 2rem;
}
.article-body h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  margin: 2rem 0 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--accent-dim);
}
.article-body h3 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 1.5rem 0 0.5rem;
}
.article-body p {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 2;
  margin-bottom: 1rem;
  text-align: justify;
}
.article-body ul {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 1rem;
}
.article-body ul li {
  position: relative;
  padding-right: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  line-height: 1.8;
}
.article-body ul li::before {
  content: '▸';
  position: absolute;
  right: 0;
  color: var(--accent);
  opacity: 0.6;
}
.article-nav {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}
.article-nav a {
  font-size: 0.9rem;
  padding: 0.5rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: 0.2s;
}
.article-nav a:hover {
  background: var(--accent-dim);
  border-color: var(--accent);
  text-decoration: none;
}

/* ── Digest Intro ──────────────────── */
.digest-intro {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-right: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.5rem 2rem;
  margin-bottom: 2rem;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 2;
}

/* ── Footer ────────────────────────── */
.site-footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 2rem;
  margin-top: 4rem;
  text-align: center;
}
.footer-inner {
  max-width: 1400px;
  margin: 0 auto;
}
.copyright {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.25rem;
}
.credit {
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
}

/* ── Loading ────────────────────────── */
.loading {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-box {
  text-align: center;
  padding: 4rem 2rem;
}
.error-box p {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-bottom: 1.5rem;
}

/* ── No Results ─────────────────────── */
.no-results {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
  font-size: 1rem;
}

/* ── Responsive ─────────────────────── */
@media (max-width: 1024px) {
  .posts-grid { grid-template-columns: repeat(2, 1fr); }
  .page-layout { flex-direction: column; }
  .page-sidebar {
    width: 100%;
    position: static;
    max-height: none;
    order: -1;
  }
  .toc-card { max-height: 250px; overflow-y: auto; }
}
@media (max-width: 768px) {
  .container { padding: 1rem; }
  .site-header { padding: 1rem; }
  .site-name { font-size: 1.2rem; }
  .header-inner { flex-wrap: wrap; }
  .posts-grid { grid-template-columns: 1fr; gap: 1rem; }
  .article-card { padding: 1.25rem; }
  .article-card h2 { font-size: 1.15rem; }
  .digest-intro { padding: 1rem 1.25rem; }
  .tip-box { padding: 1rem 1.25rem; }
  .search-section { flex-direction: column; }
  .search-input { min-width: 100%; }
  .filter-select { width: 100%; }
  .article-page h1 { font-size: 1.35rem; }
  .article-nav { flex-direction: column; text-align: center; }
}