:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #2f5d50;
  --primary-dark: #244a40;
  --primary-soft: #e7f0ed;
  --danger: #c0392b;
  --danger-soft: #fbeceb;
  --warn: #b7791f;
  --warn-soft: #fdf3dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  font-size: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button { font-family: inherit; }
a { color: var(--primary-dark); }

/* ---------------------------------------------------------------------- */
/* Login / pending screens                                                */
/* ---------------------------------------------------------------------- */
.login-screen, .pending-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}

.login-card h1 { font-size: 20px; margin: 0 0 8px; }
.login-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}

/* ---------------------------------------------------------------------- */
/* App shell                                                              */
/* ---------------------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 20px; }

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.brand-title { font-weight: 700; font-size: 14.5px; }
.brand-sub { font-size: 12px; color: var(--text-muted); }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav-icon { font-size: 15px; width: 18px; text-align: center; }
.nav-divider { height: 1px; background: var(--border); margin: 10px 4px; }
.sidebar-footer { font-size: 11.5px; color: var(--text-muted); padding: 10px 8px 0; }

.content { flex: 1; padding: 28px 36px 60px; max-width: 1180px; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-title { font-size: 21px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--text-muted); font-size: 13.5px; margin: 0; max-width: 640px; }
.header-actions { display: flex; gap: 10px; flex-shrink: 0; }

/* ---------------------------------------------------------------------- */
/* Buttons / forms                                                        */
/* ---------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { background: var(--bg); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn-danger:hover { background: #f6d9d6; }
.btn-warn { color: var(--warn); border-color: var(--warn-soft); background: var(--warn-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field input[type=text], .field input[type=url], .field input[type=search], .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  background: var(--panel);
  color: var(--text);
}
.field textarea { resize: vertical; }
.field-hint { font-size: 11.5px; color: var(--text-muted); margin-top: 4px; }

/* ---------------------------------------------------------------------- */
/* Panels / cards                                                         */
/* ---------------------------------------------------------------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Search + tag filter row on list views */
.list-toolbar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; align-items: center; }
.list-toolbar input[type=search] { flex: 1; min-width: 220px; }
.tag-chip-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tag-chip {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-muted);
}
.tag-chip:hover { background: var(--bg); }
.tag-chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 600; }

/* Article card grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.article-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.article-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.1);
}
.article-card:has(.pill-category-qaqc) { border-left-color: var(--primary); }
.article-card:has(.pill-category-guideline) { border-left-color: var(--warn); }
.article-card-title { font-weight: 700; font-size: 15px; margin: 0; }
.article-card-summary { font-size: 13px; color: var(--text-muted); margin: 0; flex: 1; }
.article-card-tags { display: flex; gap: 5px; flex-wrap: wrap; }
.pill {
  display: inline-block;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 11px;
}
.pill-category-qaqc { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.pill-category-guideline { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.pill-draft { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.pill-owner { background: #fdf0d5; color: #8a5a00; font-weight: 700; margin-left: 6px; }

/* ---------------------------------------------------------------------- */
/* Article detail                                                         */
/* ---------------------------------------------------------------------- */
.article-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }
.article-source-link { font-size: 12px; color: var(--text-muted); }

.article-body {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 32px;
  max-width: 820px;
  line-height: 1.7;
  font-size: 15px;
  position: relative;
}
.article-body h1, .article-body h2, .article-body h3 { line-height: 1.3; }
.article-body h1 { font-size: 24px; margin-top: 8px; }
.article-body h2 {
  margin-top: 36px;
  font-size: 19px;
  color: var(--primary-dark);
  border-bottom: 2px solid var(--primary-soft);
  padding-bottom: 8px;
}
.article-body h3 { margin-top: 24px; font-size: 16px; }
.article-body p { margin: 12px 0; }
.article-body ul, .article-body ol { padding-left: 24px; }
.article-body li { margin: 5px 0; }
.article-body table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.article-body th, .article-body td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.article-body th { background: var(--bg); }
.article-body img { max-width: 100%; border-radius: 8px; margin: 6px 0; box-shadow: var(--shadow); }
.article-body blockquote {
  margin: 16px 0;
  padding: 12px 16px;
  border-left: 3px solid var(--primary);
  background: var(--primary-soft);
  color: var(--text);
  border-radius: 0 8px 8px 0;
}
.article-body code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.article-body pre { background: var(--bg); padding: 12px; border-radius: 8px; overflow-x: auto; }

/* ------------------------------------------------------------------------ */
/* Highlight (==text==) + callout blockquotes — makes the important bits    */
/* impossible to miss even for someone skimming, per the CEO's requirement  */
/* that even the least-experienced reader picks up the key points fast.    */
/* ------------------------------------------------------------------------ */
.article-body mark, .editor-preview mark {
  background: #fff3a3;
  color: #4a3b00;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 600;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
@media (prefers-color-scheme: dark) {
  .article-body mark, .editor-preview mark { background: #6b5900; color: #ffe9a3; }
}

.article-body blockquote.callout, .editor-preview blockquote.callout {
  border-left-width: 5px;
  font-weight: 600;
  padding: 12px 18px;
}
.callout.callout-warn { background: var(--warn-soft); border-color: var(--warn); color: #6b4f14; }
.callout.callout-danger { background: var(--danger-soft); border-color: var(--danger); color: #7a241a; }
.callout.callout-tip { background: #e8f1fc; border-color: #2f6fb7; color: #1d4a7a; }
.callout.callout-ok { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }

/* Interactive checklist items — rendered from "- [ ] ..." markdown by
   js/checklist.js after marked.parse(). Personal, per-device progress only
   (localStorage), no backend involved. */
.article-body li.checklist-item { list-style: none; margin-left: -22px; }
.article-body li.checklist-item input[type=checkbox] { margin-right: 8px; cursor: pointer; }
.article-body li.checklist-item.checked { color: var(--text-muted); text-decoration: line-through; }

/* Deterrence-only friction: no drag/select affordance on article images. */
.article-body img { -webkit-user-drag: none; user-select: none; }

/* ---------------------------------------------------------------------- */
/* Watermark overlay (deterrent-only — see README.md for real limits)     */
/* ---------------------------------------------------------------------- */
.watermark-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
  display: none;
}
.watermark-overlay.active { display: block; }
.watermark-tile {
  position: absolute;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: rgba(30, 30, 30, 0.07);
  transform: rotate(-28deg);
  user-select: none;
}
@media (prefers-color-scheme: dark) {
  .watermark-tile { color: rgba(255, 255, 255, 0.08); }
}

/* ---------------------------------------------------------------------- */
/* Admin: users                                                           */
/* ---------------------------------------------------------------------- */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}
.user-row-info { display: flex; flex-direction: column; gap: 2px; }
.user-row-email { font-weight: 600; font-size: 13.5px; }
.user-row-sub { font-size: 12px; color: var(--text-muted); }
.user-row-actions { display: flex; gap: 8px; align-items: center; }

.switch { position: relative; display: inline-block; width: 38px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--border); border-radius: 999px; transition: .15s;
}
.switch-slider::before {
  content: ""; position: absolute; height: 16px; width: 16px; left: 2px; bottom: 2px;
  background: #fff; border-radius: 50%; transition: .15s;
}
.switch input:checked + .switch-slider { background: var(--primary); }
.switch input:checked + .switch-slider::before { transform: translateX(18px); }
.switch input:disabled + .switch-slider { opacity: .5; cursor: not-allowed; }

.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; color: var(--text-muted); margin: 22px 0 10px; }
.section-label:first-child { margin-top: 0; }

/* ---------------------------------------------------------------------- */
/* Admin: content editor                                                  */
/* ---------------------------------------------------------------------- */
.editor-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.editor-textarea { width: 100%; min-height: 480px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; line-height: 1.6; }
.editor-preview {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  min-height: 480px;
  max-height: 900px;
  overflow-y: auto;
}
.editor-toolbar { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; align-items: center; }
.editor-fields-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Click-to-manage images in the editor preview (task: replace/xoá ảnh) */
.editor-preview img.editable-image {
  cursor: pointer;
  outline: 2px dashed transparent;
  outline-offset: 3px;
  transition: outline-color .1s;
}
.editor-preview img.editable-image:hover { outline-color: var(--primary); }
.image-menu {
  position: absolute;
  z-index: 500;
  display: flex;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(16, 24, 40, 0.18);
  padding: 6px;
}

.help-box {
  background: var(--warn-soft);
  border: 1px solid #f0dca8;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 12.5px;
  margin-bottom: 16px;
  color: #6b4f14;
}
.help-box summary { cursor: pointer; font-weight: 700; color: var(--warn); }
.help-box[open] summary { margin-bottom: 8px; }
.help-box ol, .help-box ul { margin: 6px 0 0; padding-left: 20px; }

.content-table-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
}
.content-table-title { font-weight: 600; font-size: 13.5px; }
.content-table-meta { font-size: 11.5px; color: var(--text-muted); }

/* Eye-icon publish/draft quick-toggle (article detail header + admin list) */
.btn-icon-toggle { color: var(--primary-dark); border-color: var(--primary-soft); background: var(--primary-soft); }
.btn-icon-toggle:hover { background: #d9ebe4; }
.btn-icon-toggle.is-hidden { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn-icon-toggle.is-hidden:hover { background: #f6d9d6; }

/* ---------------------------------------------------------------------- */
/* Dashboard entry cards                                                  */
/* ---------------------------------------------------------------------- */
.entry-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 20px; }
.entry-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  cursor: pointer;
  text-align: left;
}
.entry-card:hover { border-color: var(--primary); }
.entry-card-icon { font-size: 28px; margin-bottom: 10px; }
.entry-card-title { font-weight: 700; font-size: 16px; margin: 0 0 6px; }
.entry-card-desc { font-size: 13px; color: var(--text-muted); margin: 0; }

/* ---------------------------------------------------------------------- */
/* Print — deliberately unattractive to print/PDF-export article content   */
/* ---------------------------------------------------------------------- */
@media print {
  .sidebar, .header-actions, .list-toolbar, .tag-chip-row { display: none !important; }
  .article-body { border: none; box-shadow: none; }
  .watermark-overlay {
    display: block !important;
    z-index: 99999;
  }
  .watermark-tile { color: rgba(0, 0, 0, 0.18) !important; }
}
