/* ================================================================
   SINGLE POST — Complete Styles
   ================================================================ */

/* Reading progress bar */
#reading-progress {
  position: fixed;
  top: 0; left: 0;
  height: 3px; width: 0;
  background: linear-gradient(90deg, var(--primary), #0077cc);
  z-index: 9999;
  transition: width .1s linear;
  pointer-events: none;
}

/* Breadcrumb bar */
.single-breadcrumb-bar { background: var(--bg-alt); border-bottom: 1px solid var(--border); padding: 10px 0; }
.single-bc-inner { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.single-reading-time { display: flex; align-items: center; gap: 5px; font-size: .78rem; color: var(--muted); white-space: nowrap; }

/* Outer wrapper */
.single-wrap { padding: 36px 0 60px; }
@media (min-width:768px) { .single-wrap { padding: 48px 0 80px; } }

/* Layout */
/* Layout 2 cột — dùng minmax(0,1fr) để tránh overflow lệch */
.single-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 36px;
  align-items: start;
  width: 100%;
}
@media (min-width:900px)  { .single-layout { grid-template-columns: minmax(0,1fr) 300px; gap: 44px; } }
@media (min-width:1100px) { .single-layout { grid-template-columns: minmax(0,1fr) 320px; } }

/* Quan trọng: cả 2 cột phải có min-width:0 */
.single-main    { min-width: 0; overflow: visible; }
.single-sidebar { min-width: 0; }

/* Article */
.single-article { min-width: 0; }

/* Category badges */
.single-cats { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }

/* Title */
.single-title { font-size: clamp(1.4rem, 4vw, 2.2rem); line-height: 1.3; color: var(--bg-dark); margin-bottom: 18px; word-break: break-word; }

/* Meta row */
.single-meta { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 14px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.single-meta-author { display: flex; align-items: center; gap: 10px; }
.meta-avatar { width: 36px !important; height: 36px !important; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.meta-author-info { line-height: 1.3; }
.meta-author-name { font-size: .88rem; font-weight: 700; color: var(--bg-dark); display: block; }
.meta-author-name:hover { color: var(--primary); }
.meta-date-row { display: flex; align-items: center; gap: 6px; font-size: .76rem; color: var(--muted); margin-top: 2px; }
.meta-date-row time { display: flex; align-items: center; gap: 4px; }
.meta-updated { color: var(--muted); font-size: .72rem; }
.single-meta-right { display: flex; align-items: center; gap: 8px; }
.share-btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px; border-radius: 100px; font-size: .76rem; font-weight: 600; transition: all var(--transition); text-decoration: none; border: 1px solid var(--border); color: var(--text); }
.share-btn:hover { background: var(--bg-alt); color: var(--primary); }
.share-btn.share-fb { border-color: #1877f2; color: #1877f2; }
.share-btn.share-fb:hover { background: #1877f2; color: #fff; }
.share-btn.share-cmt { color: var(--muted); }

/* Featured image */
.single-thumb { width: 100%; border-radius: 12px; overflow: hidden; margin-bottom: 28px; background: var(--bg-alt); line-height: 0; }
.single-thumb img { width: 100%; height: auto; max-height: 520px; object-fit: cover; display: block; }
.single-thumb-caption { padding: 8px 12px; font-size: .76rem; color: var(--muted); text-align: center; background: var(--bg-alt); line-height: 1.5; }

/* ── ENTRY CONTENT ── */
.entry-content {
  font-size: .96rem;
  line-height: 1.85;
  color: var(--text);
  word-break: break-word;
  overflow-wrap: break-word;
  /* Quan trọng: clip ảnh tràn ngay tại entry-content */
  overflow: hidden;
  /* Đảm bảo chiều rộng không vượt cột */
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.entry-content > * { margin-bottom: 1.2rem; }
.entry-content > *:last-child { margin-bottom: 0; }

.entry-content h2 { font-size: clamp(1.15rem, 3vw, 1.45rem); font-weight: 700; color: var(--bg-dark); margin-top: 2.2rem; margin-bottom: .8rem; padding-bottom: .5rem; border-bottom: 2px solid var(--primary-light); line-height: 1.3; }
.entry-content h2:first-child { margin-top: 0; }
.entry-content h3 { font-size: clamp(1.05rem, 2.5vw, 1.2rem); font-weight: 700; color: var(--bg-dark); margin-top: 1.8rem; margin-bottom: .6rem; padding-left: 12px; border-left: 3px solid var(--primary); line-height: 1.3; }
.entry-content h4 { font-size: 1rem; font-weight: 700; color: var(--bg-dark); margin-top: 1.4rem; margin-bottom: .5rem; }
.entry-content p { margin-bottom: 1.2rem; }
.entry-content a { color: var(--primary); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(0,85,165,.4); transition: text-decoration-color var(--transition), color var(--transition); }
.entry-content a:hover { color: var(--primary-dark); text-decoration-color: var(--primary); }

/* Images */
/* Ảnh trong bài viết: max 800px, giữ tỷ lệ gốc, căn giữa */
.entry-content img {
  display: block;
  width: 100%;              /* mobile: full width */
  max-width: 800px;         /* desktop: tối đa 800px */
  height: auto !important;  /* giữ tỷ lệ chiều cao */
  margin: 1.6rem auto;      /* căn giữa */
  border-radius: var(--radius);
  box-sizing: border-box;
}
/* figure wrapper cũng căn giữa */
.entry-content figure {
  margin: 1.6rem auto;
  max-width: 800px;
  width: 100%;
}
.entry-content figure img { margin: 0 auto; }
/* Ảnh có align thì không áp dụng max-width */
.entry-content .alignleft img  { width: auto; max-width: 50%; margin: 0 20px 16px 0; }
.entry-content .alignright img { width: auto; max-width: 50%; margin: 0 0 16px 20px; }
@media (max-width:640px) {
  .entry-content .alignleft img,
  .entry-content .alignright img { float: none; width: 100%; max-width: 100%; margin: 1rem 0; }
}
.entry-content figure { margin: 1.6rem 0; line-height: 0; }
.entry-content figure img { margin: 0 auto; }
.entry-content figcaption { font-size: .78rem; color: var(--muted); text-align: center; padding: 8px; line-height: 1.5; }

/* Lists */
.entry-content ul, .entry-content ol { padding-left: 1.4rem; margin-bottom: 1.2rem; }
.entry-content ul { list-style: disc; }
.entry-content ol { list-style: decimal; }
.entry-content li { margin-bottom: .45rem; line-height: 1.65; }
.entry-content ul ul, .entry-content ol ol { margin-top: .4rem; margin-bottom: .4rem; }

/* Blockquote */
.entry-content blockquote { border-left: 4px solid var(--primary); background: var(--primary-light); border-radius: 0 var(--radius) var(--radius) 0; padding: 16px 20px; margin: 1.6rem 0; font-style: italic; color: var(--primary-dark); line-height: 1.7; }
.entry-content blockquote p { margin-bottom: 0; color: inherit; }
.entry-content blockquote cite { display: block; font-size: .8rem; font-style: normal; color: var(--muted); margin-top: 8px; }

/* Tables — scrollable mobile */
.entry-content table { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; display: block; margin: 1.6rem 0; border-radius: var(--radius); border: 1px solid var(--border); min-width: 500px; border-collapse: collapse; }
@media (min-width:640px) { .entry-content table { display: table; min-width: 0; } }
.entry-content th { background: var(--primary); color: #fff; padding: 10px 14px; text-align: left; font-size: .88rem; white-space: nowrap; }
.entry-content td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: .88rem; vertical-align: top; }
.entry-content tr:last-child td { border-bottom: none; }
.entry-content tr:nth-child(even) td { background: var(--bg-alt); }

/* Code */
.entry-content code { background: #f1f5f9; color: #e11d48; padding: 2px 6px; border-radius: 4px; font-size: .88em; font-family: monospace; word-break: break-all; }
.entry-content pre { background: #1e1e2e; color: #cdd6f4; padding: 18px 20px; border-radius: var(--radius); overflow-x: auto; font-size: .84em; line-height: 1.6; margin: 1.6rem 0; }
.entry-content pre code { background: none; color: inherit; padding: 0; font-size: 1em; word-break: normal; }

/* Embeds */
.entry-content iframe, .entry-content video { max-width: 100% !important; border-radius: var(--radius); }
.entry-content .wp-block-embed__wrapper { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; }
.entry-content .wp-block-embed__wrapper iframe { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }

/* Gutenberg */
.entry-content .wp-block-image { margin: 1.6rem 0; }
.entry-content .wp-block-image img { margin: 0 auto; max-width: 100%; }
.entry-content .wp-block-separator { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.entry-content .alignleft  { float: left; margin: 0 20px 16px 0; max-width: 50%; }
.entry-content .alignright { float: right; margin: 0 0 16px 20px; max-width: 50%; }
.entry-content .aligncenter { margin-left: auto; margin-right: auto; display: block; }
.entry-content .size-full, .entry-content .size-large { max-width: 100%; height: auto; }
@media (max-width:640px) { .entry-content .alignleft, .entry-content .alignright { float: none; margin: 1rem 0; max-width: 100%; } }
.entry-content::after { content: ''; display: table; clear: both; }

/* Page links */
.page-links { margin: 1.6rem 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: .88rem; }
.page-links span { display: flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius); border: 1px solid var(--border); font-weight: 600; }
.page-links a span { transition: all var(--transition); }
.page-links a span:hover { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Single footer */
.single-footer { display: flex; flex-direction: column; gap: 16px; margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); }
.single-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.single-share-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.share-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.share-btns  { display: flex; flex-wrap: wrap; gap: 8px; }
.share-pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 100px; font-size: .78rem; font-weight: 600; border: 1.5px solid var(--border); transition: all var(--transition); cursor: pointer; background: var(--bg); color: var(--text); text-decoration: none; font-family: inherit; }
.share-pill:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.share-pill-fb   { border-color: #1877f2; color: #1877f2; }
.share-pill-fb:hover   { background: #1877f2; color: #fff; }
.share-pill-zalo { border-color: #0068ff; color: #0068ff; }
.share-pill-zalo:hover { background: #0068ff; color: #fff; }
.share-pill-copy { border-color: var(--border); color: var(--muted); }
.share-pill-copy:hover { border-color: var(--primary); color: var(--primary); }

/* Author box */
.author-box { display: flex; gap: 18px; align-items: flex-start; background: var(--bg-alt); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: 0 12px 12px 0; padding: 22px; margin-top: 32px; }
.author-avatar { width: 64px !important; height: 64px !important; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 3px solid var(--bg); box-shadow: 0 0 0 2px var(--primary); }
.author-info { min-width: 0; }
.author-label { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
.author-name  { font-size: 1rem; font-weight: 700; color: var(--bg-dark); display: block; }
.author-name:hover { color: var(--primary); }
.author-bio   { font-size: .83rem; color: var(--text-light); margin: 6px 0 0; line-height: 1.6; }

/* Post nav */
.post-nav { display: grid; grid-template-columns: 1fr; gap: 12px; margin-top: 28px; }
@media (min-width:580px) { .post-nav { grid-template-columns: 1fr 1fr; } }
.post-nav-item { display: flex; flex-direction: column; gap: 8px; padding: 16px 18px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 12px; text-decoration: none; transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition); min-width: 0; }
.post-nav-item:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); transform: translateY(-2px); }
.post-nav-item.next  { text-align: right; align-items: flex-end; }
.post-nav-dir { font-size: .72rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .05em; display: flex; align-items: center; gap: 4px; }
.post-nav-item.next .post-nav-dir { flex-direction: row-reverse; }
.post-nav-title { font-size: .88rem; font-weight: 600; color: var(--bg-dark); line-height: 1.4; display: flex; align-items: center; gap: 10px; overflow: hidden; }
.post-nav-item.next .post-nav-title { flex-direction: row-reverse; }
.post-nav-thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.icon.flip-x { transform: rotate(180deg); }

/* ── Bài viết liên quan — chuyên nghiệp ── */
.related-section {
  margin-top: 52px;
  padding-top: 36px;
  border-top: 1px solid var(--border);
}
.related-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 22px; flex-wrap: wrap;
}
.related-title h2 {
  font-size: 1rem; font-weight: 800; color: var(--bg-dark); margin: 0;
  display: flex; align-items: center; gap: 10px;
}
.related-title h2::before {
  content: ''; display: inline-block;
  width: 4px; height: 18px;
  background: var(--primary); border-radius: 2px;
}
.related-view-all {
  font-size: .76rem; font-weight: 600; color: var(--primary);
  display: flex; align-items: center; gap: 4px; white-space: nowrap;
  transition: gap var(--transition);
}
.related-view-all:hover { gap: 7px; }

.related-posts-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width:560px) { .related-posts-grid { grid-template-columns: repeat(2,1fr); } }
@media (min-width:900px) { .related-posts-grid { grid-template-columns: repeat(3,1fr); } }

.related-card {
  display: flex; flex-direction: row;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
  text-decoration: none; color: inherit; min-width: 0;
  transition: box-shadow .22s ease, border-color .22s ease, transform .22s ease;
}
.related-card:hover { box-shadow: 0 6px 20px rgba(0,85,165,.1); border-color: var(--primary); transform: translateY(-2px); }

/* Mobile: ảnh trái, chữ phải */
.related-card-thumb { width: 90px; min-width: 90px; height: 90px; overflow: hidden; background: var(--bg-alt); flex-shrink: 0; }

/* Tablet/Desktop: ảnh trên, chữ dưới */
@media (min-width:560px) {
  .related-card { flex-direction: column; }
  .related-card-thumb { width: 100%; height: auto; aspect-ratio: 16/9; min-width: 0; }
}
.related-card-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s ease; }
.related-card:hover .related-card-thumb img { transform: scale(1.06); }
.related-card-placeholder { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; background: var(--primary-light); color: var(--primary); }

.related-card-body { padding: 12px 14px; flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
@media (min-width:560px) { .related-card-body { padding: 14px 16px; } }
.related-cat { font-size: .64rem; font-weight: 700; color: var(--primary); text-transform: uppercase; letter-spacing: .05em; }
.related-card-body h3 {
  font-size: .84rem; font-weight: 700; color: var(--bg-dark);
  line-height: 1.4; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
  transition: color .22s ease;
}
.related-card:hover .related-card-body h3 { color: var(--primary); }
.related-date { font-size: .7rem; color: var(--muted); margin-top: auto; padding-top: 3px; }

/* Comments */
.single-comments { margin-top: 40px; padding-top: 32px; border-top: 1px solid var(--border); }
.single-comments .comments-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 24px; }
.comment-form input, .comment-form textarea { font-size: 1rem !important; }

/* SIDEBAR */
.single-sidebar {
  display: flex;
  flex-direction: column;
  gap: 20px;
  /* Sticky chỉ trên desktop, KHÔNG dùng max-height để tránh lệch */
  position: sticky;
  top: 90px;
  /* Không dùng max-height + overflow-y vì gây layout lệch */
  align-self: start; /* quan trọng — giữ sidebar ở đầu column */
}
@media (max-width:899px) {
  .single-sidebar {
    position: static;
  }
}

.sidebar-author-card { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; }
.sa-avatar { width: 56px !important; height: 56px !important; border-radius: 50%; object-fit: cover; border: 3px solid var(--primary-light); }
.sa-label { font-size: .7rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.sa-name  { font-size: .92rem; font-weight: 700; color: var(--bg-dark); display: block; }
.sa-name:hover { color: var(--primary); }
.sa-bio   { font-size: .78rem; color: var(--muted); line-height: 1.55; margin: 0; }

.sidebar-recent { display: flex; flex-direction: column; gap: 0; }
.sidebar-recent-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.sidebar-recent-item:last-child { border-bottom: none; }
.recent-thumb { flex-shrink: 0; width: 60px; height: 60px; border-radius: 6px; overflow: hidden; display: block; background: var(--bg-alt); }
.recent-thumb img { width: 100%; height: 100%; object-fit: cover; }
.recent-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.recent-title { font-size: .82rem; font-weight: 600; color: var(--bg-dark); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.recent-title:hover { color: var(--primary); }
.recent-date { font-size: .72rem; color: var(--muted); }

.sidebar-cta-card { text-align: center; background: linear-gradient(135deg, #002d6b, var(--primary)) !important; border-color: var(--primary) !important; }
.sidebar-cta-icon { margin-bottom: 10px; }
.sidebar-cta-icon svg { color: rgba(255,255,255,.4); margin: 0 auto; }
.sidebar-cta-card h3 { color: #fff; font-size: .95rem; margin-bottom: 6px; }
.sidebar-cta-card p  { color: rgba(255,255,255,.8); font-size: .8rem; margin-bottom: 16px; }

/* Table of Contents */
.toc-widget { background: var(--bg-alt); }
.toc-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 2px; }
.toc-h3 { padding-left: 14px; }
.toc-link { display: block; padding: 7px 10px; font-size: .82rem; color: var(--text-light); border-radius: 6px; border-left: 2px solid transparent; transition: all var(--transition); text-decoration: none; line-height: 1.4; }
.toc-link:hover { background: var(--bg); color: var(--primary); border-left-color: var(--primary); }
.toc-link.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
