:root {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --text: #2c2c2e;
  --text-secondary: #6e6e73;
  --divider: #d2d2d7;
  --accent: #0071e3;
  --accent-soft: rgba(0, 113, 227, 0.08);
  --brand-coral: #ee5a52;
  --radius: 18px;
  --max-width: 780px;
  --content-width: 860px;
  --aside-width: 320px;
  --grid-gap: 48px;
  --page-width: calc(var(--content-width) + var(--grid-gap) + var(--aside-width));
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; overflow-y: scroll; scrollbar-gutter: stable; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 17px;
}

a { color: inherit; text-decoration: none; }

/* ---------- Nav ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(251, 251, 253, 0.8);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--divider);
}
.nav-inner {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.brand-accent { color: inherit; }
.nav-links { display: flex; gap: 24px; font-size: 14px; color: var(--text-secondary); }
.nav-links a { transition: color 0.2s ease; }
.nav-links a:hover, .nav-links a.active { color: var(--text); }

/* ---------- Layout ---------- */
main { padding: 24px 0 96px; min-height: 60vh; }

/* Grid 2 cột: nội dung bài viết lệch trái + cột dọc dự trữ (quảng cáo / widget sau này) */
.page-grid {
  max-width: var(--page-width);
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: minmax(0, var(--content-width)) var(--aside-width);
  gap: var(--grid-gap);
  align-items: start;
}
.page-main { min-width: 0; }
.page-aside {
  position: sticky;
  top: 88px;
  min-height: 1px;
}
@media (max-width: 1020px) {
  .page-grid { grid-template-columns: 1fr; }
  .page-aside { display: none; }
}

.footer {
  text-align: center;
  color: var(--text-secondary);
  font-size: 12px;
  padding: 32px 20px 48px;
}

/* ---------- Hero ---------- */
.hero { padding: 40px 0 56px; }
.hero h1 {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 12px;
}
.hero p { font-size: 19px; color: var(--text-secondary); margin: 0; max-width: 520px; }

/* ---------- Section ---------- */
.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  margin: 8px 0 16px;
}

/* ---------- Post card / list ---------- */
.post-list { display: flex; flex-direction: column; gap: 20px; }
.post-card {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--divider);
  overflow: hidden;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.post-card:hover { transform: translateY(-2px); box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 12px 28px rgba(0,0,0,0.08); }
.post-card-thumb {
  width: 220px;
  flex-shrink: 0;
  overflow: hidden;
  background: var(--bg);
}
.post-card-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-card-body { padding: 20px; flex: 1; min-width: 0; }

@media (max-width: 560px) {
  .post-card { flex-direction: column; }
  .post-card-thumb { width: 100%; aspect-ratio: 16 / 9; }
  /* Trên điện thoại chỉ giữ ảnh + tiêu đề + ngày đăng cho gọn, ẩn tóm tắt và nhãn danh mục */
  .post-card p,
  .post-card .tag { display: none; }
}
.post-card .tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 100px;
  margin-bottom: 10px;
}
.post-card h2 { font-size: 21px; font-weight: 600; margin: 0 0 6px; letter-spacing: -0.01em; }
.post-card time { display: block; margin: 0 0 10px; font-size: 12px; color: var(--text-secondary); }
.post-card p { margin: 0 0 12px; color: var(--text-secondary); font-size: 15px; }
.post-card .tag { margin-bottom: 0; }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 32px;
  flex-wrap: wrap;
}
.page-btn {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  border: 1px solid var(--divider);
  background: var(--bg-card);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.page-btn:hover { color: var(--text); border-color: var(--text-secondary); }
.page-btn.active { background: var(--text); color: #fff; border-color: var(--text); cursor: default; }
.page-btn.page-nav { font-weight: 500; padding: 0 14px; }
.page-btn.disabled { opacity: 0.4; pointer-events: none; }
.page-ellipsis { color: var(--text-secondary); padding: 0 2px; font-size: 14px; }

.empty {
  color: var(--text-secondary);
  font-size: 15px;
  padding: 40px 0;
  text-align: center;
}

/* ---------- Category chips on homepage ---------- */
.chip-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
@media (max-width: 560px) { .chip-grid { grid-template-columns: 1fr; } }
.chip-card {
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 22px;
  background: var(--bg-card);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.chip-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.06); }
.chip-card h3 { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.chip-card .subs { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-card .subs span {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--divider);
  padding: 3px 10px;
  border-radius: 100px;
}

/* ---------- Single post ---------- */
.post-header { padding: 8px 0 32px; border-bottom: 1px solid var(--divider); margin-bottom: 32px; }
.post-header .tag { font-size: 12px; font-weight: 600; color: var(--accent); }
.post-header h1 { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; margin: 10px 0; }
.post-header time { color: var(--text-secondary); font-size: 14px; }
.post-meta-row { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); font-size: 14px; }
.post-meta-dot { opacity: 0.6; }
.post-reading-time { color: var(--text-secondary); }

.post-toc {
  margin: 0 0 32px;
  padding: 16px 20px;
  border: 1px solid var(--divider);
  border-radius: 14px;
  background: var(--bg-card);
}
.post-toc-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--text-secondary); margin-bottom: 10px; }
.post-toc ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.post-toc a { color: var(--accent); font-size: 14px; }
.post-toc a:hover { text-decoration: underline; }
.post-toc .toc-depth-3 { padding-left: 18px; }

.post-body { font-size: 17px; color: #3a3a3c; }
.post-body h2 { font-size: 24px; margin-top: 40px; letter-spacing: -0.01em; scroll-margin-top: 90px; }
.post-body h3 { font-size: 20px; margin-top: 32px; scroll-margin-top: 90px; }
.post-body p { margin: 18px 0; }
.post-body img { max-width: 100%; border-radius: 12px; display: block; }
.post-figure { margin: 28px 0; }
.post-figure img { width: 100%; }
.post-figure figcaption { text-align: center; font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.post-body code { background: var(--accent-soft); padding: 2px 6px; border-radius: 6px; font-size: 0.9em; }
.post-body pre { background: #1d1d1f; color: #f5f5f7; padding: 18px; border-radius: 12px; overflow-x: auto; }
.post-body pre code { background: none; padding: 0; color: inherit; }
.post-body blockquote { margin: 20px 0; padding: 4px 20px; border-left: 3px solid var(--accent); color: var(--text-secondary); }
.post-body a { color: var(--accent); }
.post-body ul, .post-body ol { padding-left: 22px; }

/* ---------- Admin ---------- */
/* Dùng đúng quy tắc canh lề với .page-grid ngoài trang công khai để đồng bộ tuyệt đối */
/* Lưu ý: khai báo đủ padding-top/bottom ở đây vì shorthand này sẽ ghi đè hoàn toàn padding của thẻ main */
.admin-shell { max-width: var(--page-width); margin: 0 auto; padding: 40px 20px 96px; }

.admin-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 28px;
}
.admin-topbar-left { display: flex; align-items: center; gap: 14px; }
.admin-topbar h1 { font-size: 20px; margin: 0; font-weight: 600; }
.admin-back {
  font-size: 13px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.15s ease;
}
.admin-back:hover { color: var(--text); }
.admin-divider { width: 1px; height: 18px; background: var(--divider); }

.admin-layout {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) { .admin-layout { grid-template-columns: 1fr; } }
.admin-layout-single { grid-template-columns: 1fr; }

.admin-topbar-right { display: flex; align-items: center; gap: 10px; }
.new-post-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 100px;
  background: var(--accent);
  color: #fff;
  transition: opacity 0.15s ease;
}
.new-post-btn:hover { opacity: 0.85; color: #fff; }

.card {
  background: var(--bg-card);
  border: 1px solid var(--divider);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03), 0 10px 28px rgba(0,0,0,0.035);
}
.card h2 { font-size: 16px; margin: 0; font-weight: 600; }

.editor-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.editor-status { font-size: 12px; color: var(--text-secondary); }

.editor-label-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ghost-btn {
  background: transparent;
  color: var(--accent);
  border: none;
  padding: 4px 6px;
  font-size: 13px;
  font-weight: 600;
}
.ghost-btn:hover { opacity: 0.7; }

.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 8px;
  padding: 4px;
  flex-wrap: wrap;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: 12px 12px 0 0;
  border-bottom: none;
}
.tb-group { display: flex; align-items: center; gap: 2px; }
.tb-sep { width: 1px; height: 22px; background: var(--divider); margin: 0 6px; flex-shrink: 0; }
.tb-spacer { flex: 1 1 auto; min-width: 8px; }
.tb-dropdown { position: relative; }

.toolbar-btn {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.toolbar-btn:hover { opacity: 1; background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.tb-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 220px;
  width: max-content;
  background: var(--bg-card);
  border: 1px solid var(--divider);
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.09);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
/* Quan trọng: thuộc tính [hidden] phải thắng display:flex ở trên, nếu không menu sẽ
   không bao giờ ẩn đi dù JS đã set hidden = true (đây là nguyên nhân 2 menu bị chồng nhau). */
.tb-menu[hidden] { display: none; }
.tb-menu button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 10px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  border-radius: 7px;
  white-space: nowrap;
}
.tb-menu button:hover { background: var(--accent-soft); color: var(--accent); }

.editor-dropzone { border-top-left-radius: 0; border-top-right-radius: 0; }
.editor-dropzone textarea { border-top-left-radius: 0; border-top-right-radius: 0; }

.editor-dropzone {
  position: relative;
  border-radius: 12px;
  transition: outline-color 0.15s ease;
  outline: 2px dashed transparent;
  outline-offset: 2px;
}
.editor-dropzone textarea { min-height: 300px; }
.editor-dropzone.drag-active { outline-color: var(--accent); }
.dropzone-overlay {
  display: none;
  position: absolute;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: 12px;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  pointer-events: none;
}
.editor-dropzone.drag-active .dropzone-overlay { display: flex; }

.preview-pane {
  min-height: 300px;
  max-height: 520px;
  overflow-y: auto;
  border: 1px solid var(--divider);
  border-radius: 12px;
  padding: 16px 18px;
  background: var(--bg-card);
}
.preview-pane p:first-child { margin-top: 0; }

.editor-hint { font-size: 12px; color: var(--text-secondary); margin: 8px 0 0; }

.thumb-strip { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.thumb-chip {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--divider);
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  line-height: 1;
  border: none;
}
.thumb-spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--divider);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.editor-publish-row { margin-top: 4px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { display: none; }
.switch-track {
  display: inline-block; /* để track luôn có kích thước 38x22 riêng, không phụ thuộc việc .switch có thật sự là flex hay không */
  width: 38px;
  height: 22px;
  border-radius: 100px;
  background: var(--divider);
  position: relative;
  vertical-align: middle;
  transition: background 0.15s ease;
  flex-shrink: 0;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(16px); }
.switch-label { font-size: 14px; color: var(--text); }
/* Bug cũ: khi công tắc nằm trong .field, rule ".field label {display:block}" có thể ghi đè
   mất layout ngang của .switch, khiến switch-track co gần về 0 và nút tròn (switch-thumb)
   đè lên chữ nhãn (vd. che mất chữ "Xu" trong "Xuất bản ngay"). Ép !important ở đây để
   .switch luôn giữ đúng layout ngang bất kể rule nào khác có thể áp lên sau này. */
.field .switch { display: inline-flex !important; margin-bottom: 0; }

.save-bar {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--divider);
}
.save-bar button { flex: 1; }
.save-bar button[type="submit"] { flex: 2; }

.sidebar-card { position: sticky; top: 88px; }
.admin-subtabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: 100px;
  padding: 3px;
  margin-bottom: 18px;
}
.subtab {
  flex: 1;
  background: transparent;
  color: var(--text-secondary);
  border: none;
  border-radius: 100px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.subtab.active { background: var(--bg-card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.count-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 100px;
}
.subtab.active .count-badge { background: var(--accent); color: #fff; }

.filter-pills { display: flex; gap: 6px; margin-bottom: 14px; }
.pill-btn {
  background: var(--bg);
  border: 1px solid var(--divider);
  color: var(--text-secondary);
  border-radius: 100px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
}
.pill-btn.active { background: var(--text); color: #fff; border-color: var(--text); }

.admin-post-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--divider);
  font-size: 14px;
}
.admin-post-item:last-child { border-bottom: none; }
.admin-post-thumb {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--divider);
}
.admin-post-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.admin-post-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 11px;
}
.admin-post-info { min-width: 0; flex: 1; }
.admin-post-title-row { display: flex; align-items: center; gap: 8px; }
.admin-post-title-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.admin-post-item .meta { color: var(--text-secondary); font-size: 12px; margin-top: 3px; }
.admin-post-item .actions { display: flex; gap: 8px; flex-shrink: 0; }
.admin-post-item .actions button, .admin-post-item .actions a { padding: 6px 12px; font-size: 12px; }

.cat-block { margin-bottom: 14px; }
.cat-block-head { display: flex; justify-content: space-between; align-items: center; }
.cat-block-head strong { font-size: 14px; }
.cat-block-head button { padding: 4px 10px; font-size: 11px; }
.cat-block-subs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.sub-pill { cursor: pointer; }
.muted-hint { color: var(--text-secondary); font-size: 12px; }
.divider-line { border: none; border-top: 1px solid var(--divider); margin: 18px 0; }

.login-box {
  max-width: 360px;
  margin: 15vh auto;
  padding: 36px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--divider);
  text-align: center;
}
.login-box h1 { font-size: 22px; margin-bottom: 6px; }
.login-box p { color: var(--text-secondary); font-size: 14px; margin-bottom: 24px; }

input, textarea, select {
  font-family: var(--font);
  font-size: 15px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--divider);
  background: var(--bg-card);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

button, .btn, a.secondary, a.danger, a.success {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 100px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  transition: opacity 0.15s ease;
  display: inline-block;
  text-align: center;
}
button:hover, .btn:hover, a.secondary:hover, a.danger:hover, a.success:hover { opacity: 0.85; color: inherit; }
.secondary { background: var(--bg-card); color: var(--text); border: 1px solid var(--divider); }
.danger { background: #ff3b30; }
.success { background: #34c759; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.pill { display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 100px; background: var(--accent-soft); color: var(--accent); margin-right: 6px; }
.pill.draft { background: #f5f5f7; color: var(--text-secondary); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: 100px;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; }
