/* ============================================================
   AI THỰC CHIẾN · Tạ Quang Thuận · Master Theme v3.1
   Print-ready · A4 · Vietnamese-optimized
   ============================================================ */

/* ─────────────────────────────────────────────────────────────
   PRINT LAYOUT — chuẩn book chuyên nghiệp (O'Reilly/Pearson style)
   Khổ giấy A4: 210 × 297 mm
   Lề: top 22mm · right 18mm · bottom 22mm · left 22mm
   → Vùng nội dung: ~170 × 253 mm (sweet spot, đọc thoải mái)
   → "Vạch mờ" 18-22mm mỗi bên = an toàn máy in, không cảm giác ép.
   ───────────────────────────────────────────────────────────── */
@page {
  size: A4;
  margin: 22mm 18mm 22mm 22mm;
  @bottom-center {
    content: "AI Thực Chiến · Tạ Quang Thuận · Trang " counter(page);
    font-size: 9pt; color: #888;
  }
  @top-right {
    content: string(chap-title);
    font-size: 9pt; color: #888;
  }
}
@page :first { @top-right { content: ""; } @bottom-center { content: ""; } }

/* Khi xem trên màn hình → đồng bộ padding với print để preview chuẩn */
@media screen {
  body {
    padding: 22mm 18mm 22mm 22mm;
    max-width: 210mm; margin: 0 auto;
    box-shadow: 0 0 12px rgba(0,0,0,0.1);
  }
}

/* Khi in/save PDF → body KHÔNG padding, @page đã quản lề */
@media print {
  .no-print { display: none !important; }
  body { padding: 0; margin: 0; max-width: none; box-shadow: none; }
  /* Đảm bảo nội dung KHÔNG dính sát mép trên trang mới */
  h1, h2, h3 { padding-top: 4pt !important; }
  table, pre, .callout, .diagram { margin-top: 12pt !important; }
  /* Mỗi row trong table tránh bị cắt giữa chừng */
  tr { page-break-inside: avoid; }
}

* { box-sizing: border-box; }
html { font-size: 11pt; }
body {
  font-family: 'Segoe UI', 'Inter', 'Helvetica Neue', Arial, sans-serif;
  color: #1a1a1a; line-height: 1.65;
  background: #fff;
}

/* === Cover === */
.cover {
  position: relative;
  min-height: 245mm;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: center;
  padding: 40pt 0 24pt 0;
  page-break-after: always;
  background: linear-gradient(160deg, #fbfbff 0%, #fff 100%);
}
.cover .brand {
  font-size: 11pt; color: #6c757d;
  letter-spacing: 2pt; text-transform: uppercase;
}
.cover .title {
  font-size: 36pt; font-weight: 800;
  color: #1d3557; letter-spacing: -1pt;
  margin: 18pt 0 8pt 0; line-height: 1.1;
}
.cover .subtitle {
  font-size: 18pt; color: #2a9d8f;
  margin-top: 4pt; font-weight: 600;
}
.cover .tagline {
  font-size: 12pt; color: #555;
  font-style: italic; margin-top: 14pt;
}
.cover .stats {
  display: flex; justify-content: center; gap: 14pt;
  margin: 30pt auto 20pt auto; flex-wrap: wrap;
  max-width: 92%;
}
.cover .stat-card {
  background: #f1f4f9; border-radius: 8pt;
  padding: 14pt 18pt; min-width: 90pt;
}
.cover .stat-card .num {
  font-size: 22pt; font-weight: 800; color: #1d3557;
}
.cover .stat-card .lbl {
  font-size: 9pt; color: #555; text-transform: uppercase;
  letter-spacing: 0.5pt;
}
.cover .audience {
  background: #e8f4f8; border-left: 4px solid #2a9d8f;
  padding: 14pt 18pt; margin: 20pt auto 0 auto;
  max-width: 380pt; text-align: left; border-radius: 4pt;
}
.cover .audience .h {
  font-weight: 700; color: #1d3557;
  margin-bottom: 6pt; font-size: 11pt;
}
.cover .audience p { margin: 3pt 0; font-size: 10pt; }
.cover .meta-bottom {
  margin-top: auto;
  padding-top: 24pt;
  font-size: 10pt; color: #777;
  line-height: 1.6;
}

/* === Headings === */
h1 {
  font-size: 22pt; color: #1d3557;
  margin: 18pt 0 8pt 0; padding-bottom: 8pt;
  border-bottom: 3px solid #1d3557;
  page-break-after: avoid; page-break-inside: avoid;
  string-set: chap-title content();
}
/* Mỗi chương bắt đầu trang mới — chỉ áp dụng class .chapter */
h1.chapter {
  page-break-before: always;
  margin-top: 4pt; padding-top: 8pt;
}
h1.no-break { page-break-before: avoid; }
h2 + table, h2 + pre, h2 + .callout, h2 + .diagram { margin-top: 10pt; }
h3 + table, h3 + pre, h3 + .callout, h3 + .diagram { margin-top: 8pt; }
h2 {
  font-size: 15pt; color: #1d3557;
  margin-top: 22pt; margin-bottom: 6pt; padding-left: 10pt;
  border-left: 5px solid #2a9d8f;
  page-break-after: avoid;
  break-inside: avoid;
}
h3 {
  font-size: 12.5pt; color: #264653;
  margin-top: 16pt; margin-bottom: 4pt;
  page-break-after: avoid;
  break-inside: avoid;
}
h4 {
  font-size: 11pt; color: #1b6e62;
  margin-top: 14pt; margin-bottom: 0;
  padding: 6pt 12pt;
  background: linear-gradient(90deg, #eaf6e8 0%, #f7fbf6 100%);
  border-left: 5px solid #2a9d8f;
  border-radius: 5px 5px 0 0;
  font-weight: 700;
  page-break-after: avoid;
  break-after: avoid;
}
/* h4 + pre liền kề: tạo mini-card prompt mẫu — h4 là header, pre là body */
h4 + pre {
  margin-top: 0 !important;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: none;
}

p, ul, ol { margin: 6pt 0; line-height: 1.6; }
ul, ol { padding-left: 22pt; }
li { margin: 3pt 0; }
strong { color: #1d3557; }
em { color: #555; }
hr { border: none; border-top: 1px dashed #aaa; margin: 16pt 0; }

/* === Code === */
code {
  font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
  background: #f1f4f9; padding: 1pt 5pt; border-radius: 3px;
  font-size: 9.5pt; color: #c1121f; border: 1px solid #e2e7ee;
}
pre {
  background: #f6f8fa; color: #1d3557;
  border: 1px solid #c8d0dd;
  border-left: 5px solid #2a9d8f;
  padding: 14pt 20pt; border-radius: 6px;
  font-size: 9.8pt; line-height: 1.6;
  overflow-x: auto; page-break-inside: avoid;
  margin: 10pt 0 14pt 0;
  font-family: 'JetBrains Mono', 'Consolas', 'Courier New', monospace;
  white-space: pre-wrap; word-wrap: break-word;
  display: block; width: 100%;
  box-shadow: 0 1px 2px rgba(29, 53, 87, 0.04);
}
/* h3 → pre liền kề: kéo sát + tạo mini-card */
h3 + pre { margin-top: 4pt; }
h4 + pre { margin-top: 4pt; }
pre code { background: transparent; color: inherit; padding: 0; border: none; }

/* === Tables — print-friendly (light header, save ink) === */
table {
  border-collapse: collapse; width: 100%;
  margin: 12pt 0; page-break-inside: avoid;
  font-size: 9.8pt;
}
th {
  background: #e8eef5; color: #1d3557;
  padding: 7pt 10pt; text-align: left;
  border: 1px solid #c5cdd9;
  border-bottom: 2px solid #1d3557;
  page-break-after: avoid;
  font-weight: 700;
  line-height: 1.4;
}
td {
  padding: 6pt 10pt; border: 1px solid #d8dde5; vertical-align: top;
  line-height: 1.5;
}
tr:nth-child(even) td { background: #fafbfc; }
table thead { display: table-header-group; }  /* lặp header trên mỗi trang khi tách */

/* === Callouts === */
.callout {
  margin: 12pt 0; padding: 12pt 16pt;
  border-radius: 5px; page-break-inside: avoid;
  font-size: 10pt; line-height: 1.55;
}
.callout .h {
  font-weight: 700; margin-bottom: 4pt;
  font-size: 10.5pt; display: flex; align-items: center; gap: 6pt;
}
.callout p { margin: 3pt 0; }
.callout.info { background: #eaf2fb; border: 1px solid #c8d6ea; border-left: 4px solid #1d3557; }
.callout.info .h { color: #1d3557; }
.callout.tip { background: #eaf6e8; border: 1px solid #c8e0c4; border-left: 4px solid #2a9d8f; }
.callout.tip .h { color: #1b6e62; }
.callout.warn { background: #fff5d6; border: 1px solid #f0deaa; border-left: 4px solid #e9c46a; }
.callout.warn .h { color: #856404; }
.callout.danger { background: #ffe8e8; border: 1px solid #f5c8c8; border-left: 4px solid #c1121f; }
.callout.danger .h { color: #c1121f; }
.callout.example { background: #f4ecff; border: 1px solid #d9c4f5; border-left: 4px solid #7c3aed; }
.callout.example .h { color: #5b21b6; }

/* === TOC === */
.toc { page-break-after: always; padding-top: 4pt; }
.toc h1 { page-break-before: avoid; margin-bottom: 14pt; }
.toc ol { list-style: none; padding: 0; counter-reset: tocitem; }
.toc li {
  counter-increment: tocitem;
  padding: 9pt 0; border-bottom: 1px dotted #ccd;
  display: flex; justify-content: space-between;
  font-size: 11pt; line-height: 1.5;
}
.toc li::before {
  content: "Chương " counter(tocitem) " · ";
  color: #2a9d8f; font-weight: 700; margin-right: 8pt;
  min-width: 75pt;
}
.toc li span:first-of-type { flex: 1; }
.toc li .pg { color: #888; font-weight: 600; margin-left: 12pt; }

/* === Watermark === */
.watermark {
  position: fixed; top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-45deg);
  font-size: 64pt; color: rgba(29, 53, 87, 0.04);
  font-weight: 800; z-index: -1; pointer-events: none;
  white-space: nowrap; letter-spacing: 4pt;
}
@media print {
  .watermark { color: rgba(29, 53, 87, 0.025); font-size: 56pt; }
}

/* === Toolbar (no-print) === */
.toolbar {
  position: fixed; top: 10px; right: 10px;
  background: #1d3557; color: #fff;
  padding: 8px 14px; border-radius: 5px;
  font-size: 11pt; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  z-index: 999;
}
.toolbar button {
  background: #e9c46a; color: #1d3557; border: none;
  padding: 6px 12px; border-radius: 3px;
  font-weight: 700; cursor: pointer; margin-left: 8px;
}

/* === Footer end-of-chapter === */
.chapter-end {
  margin-top: 36pt; padding: 14pt 20pt;
  border-top: 2px solid #1d3557;
  text-align: center; font-size: 10pt; color: #555;
  line-height: 1.65;
  page-break-inside: avoid;
}
.chapter-end .next {
  display: inline-block; background: #e9c46a;
  color: #1d3557; padding: 7pt 16pt; border-radius: 16pt;
  font-weight: 700; margin: 10pt 0;
}
.chapter-end a { color: #1d3557; text-decoration: none; }
.chapter-end a:hover { text-decoration: underline; }

/* === Severity labels === */
.sev-p0 { background: #ffe5e5; padding: 1pt 6pt; border-radius: 3px; color: #c1121f; font-weight: 700; font-size: 9pt; }
.sev-p1 { background: #fff3cd; padding: 1pt 6pt; border-radius: 3px; color: #856404; font-weight: 700; font-size: 9pt; }
.sev-p2 { background: #d1ecf1; padding: 1pt 6pt; border-radius: 3px; color: #0c5460; font-weight: 700; font-size: 9pt; }

/* === Two-col layout === */
.two-col {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12pt;
  margin: 8pt 0; page-break-inside: avoid;
}
.col-card {
  background: #f8f9fa; border-radius: 5px;
  padding: 10pt 12pt; border: 1px solid #e0e3e7;
}
.col-card h4 { margin-top: 0; }

/* === Anti-orphan === */
table, pre, .callout, .col-card, blockquote, .diagram { page-break-inside: avoid; }

/* === Status icons: ✓ green, ✗ red, ⚠ yellow === */
.ok, .yes, .check { color: #16a34a; font-weight: 800; }
.no, .cross { color: #dc2626; font-weight: 800; }
.warn-i { color: #d97706; font-weight: 800; }

/* Auto-color trong table cell khi chứa ký tự đặc biệt */
td:has(> .ok), td:has(> .yes) { color: #16a34a; }
td:has(> .no) { color: #dc2626; }

/* === Diagram Container === */
.diagram {
  margin: 16pt 0; padding: 16pt 14pt;
  background: #fafbfc;
  border: 1px solid #e2e7ee;
  border-radius: 8pt;
  page-break-inside: avoid;
}
.diagram .dtitle {
  text-align: center; font-size: 12pt; font-weight: 800;
  color: #1d3557; letter-spacing: 0.3pt;
  margin-bottom: 14pt; text-transform: uppercase;
}
.diagram .caption {
  font-size: 9.5pt; color: #6c757d;
  margin-top: 12pt; font-style: italic;
  text-align: center;
}
.diagram svg { max-width: 100%; height: auto; display: block; margin: 0 auto; }

/* === 1. DNA FORMULA (4 steps horizontal) === */
.dna-formula {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8pt;
}
.dna-step {
  background: #fff; border-radius: 8pt; padding: 12pt 10pt;
  border-left: 4px solid; display: flex; flex-direction: column;
  position: relative; min-height: 95pt;
}
.dna-step .dna-num {
  position: absolute; top: -8pt; left: 10pt;
  width: 22pt; height: 22pt; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12pt; font-weight: 800; color: #fff;
}
.dna-step .dna-title {
  font-size: 11pt; font-weight: 800; margin-top: 8pt; margin-bottom: 4pt;
}
.dna-step .dna-desc { font-size: 9.5pt; color: #6c757d; margin-bottom: 6pt; }
.dna-step .dna-example {
  font-size: 9pt; font-style: italic;
  padding: 4pt 6pt; border-radius: 4pt;
  margin-top: auto;
}
/* 4 colors */
.dna-step.c1 { background: #eaf2fb; border-color: #1d3557; }
.dna-step.c1 .dna-num { background: #1d3557; }
.dna-step.c1 .dna-title { color: #1d3557; }
.dna-step.c1 .dna-example { background: #d6e3f3; color: #1d3557; }
.dna-step.c2 { background: #eaf6e8; border-color: #2a9d8f; }
.dna-step.c2 .dna-num { background: #2a9d8f; }
.dna-step.c2 .dna-title { color: #1b6e62; }
.dna-step.c2 .dna-example { background: #d2ecd0; color: #1b6e62; }
.dna-step.c3 { background: #fff5d6; border-color: #e9c46a; }
.dna-step.c3 .dna-num { background: #e9c46a; color: #1d3557; }
.dna-step.c3 .dna-title { color: #856404; }
.dna-step.c3 .dna-example { background: #fbe9b6; color: #856404; }
.dna-step.c4 { background: #f4ecff; border-color: #7c3aed; }
.dna-step.c4 .dna-num { background: #7c3aed; }
.dna-step.c4 .dna-title { color: #5b21b6; }
.dna-step.c4 .dna-example { background: #e6d6f8; color: #5b21b6; }

/* === 2. FLOW DECISION (3 boxes with arrows) === */
.flow-decision {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10pt; align-items: center;
}
.flow-box {
  background: #fff; padding: 14pt 12pt;
  border: 2px solid; border-radius: 10pt;
  text-align: center; min-height: 90pt;
  display: flex; flex-direction: column; justify-content: center;
}
.flow-box .flow-title {
  font-size: 12pt; font-weight: 800; margin-bottom: 4pt;
}
.flow-box .flow-sub { font-size: 9.5pt; color: #6c757d; }
.flow-box.q { background: #fff5d6; border-color: #e9c46a; }
.flow-box.q .flow-title { color: #856404; }
.flow-box.a {
  position: relative;
}
.flow-box.a::before {
  content: ""; position: absolute; top: 50%; left: -12pt;
  width: 12pt; height: 2px;
}
.flow-box.left { background: #eaf6e8; border-color: #2a9d8f; }
.flow-box.left .flow-title { color: #1b6e62; }
.flow-box.right { background: #eaf2fb; border-color: #1d3557; }
.flow-box.right .flow-title { color: #1d3557; }
.flow-label {
  display: inline-block; padding: 3pt 8pt; border-radius: 12pt;
  font-size: 9pt; font-weight: 700; margin-bottom: 4pt;
}
.flow-label.no { background: #2a9d8f; color: #fff; }
.flow-label.yes { background: #1d3557; color: #fff; }

/* === 3. SKILL HUB (center + radial nodes) === */
.skill-hub {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10pt;
}
.skill-card {
  background: #fff; padding: 12pt;
  border: 1px solid #e2e7ee; border-radius: 10pt;
  border-top: 4px solid;
  display: flex; gap: 10pt; align-items: flex-start;
}
.skill-icon {
  width: 36pt; height: 36pt; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 18pt; flex-shrink: 0; color: #fff;
}
.skill-content { flex: 1; }
.skill-content .stitle {
  font-size: 11pt; font-weight: 800; margin-bottom: 2pt;
}
.skill-content .sdesc {
  font-size: 9.5pt; color: #6c757d; line-height: 1.4;
}
.skill-card.s1 { border-top-color: #2a9d8f; }
.skill-card.s1 .skill-icon { background: #2a9d8f; }
.skill-card.s1 .stitle { color: #1b6e62; }
.skill-card.s2 { border-top-color: #1d3557; }
.skill-card.s2 .skill-icon { background: #1d3557; }
.skill-card.s2 .stitle { color: #1d3557; }
.skill-card.s3 { border-top-color: #7c3aed; }
.skill-card.s3 .skill-icon { background: #7c3aed; }
.skill-card.s3 .stitle { color: #5b21b6; }
.skill-card.s4 { border-top-color: #e9c46a; }
.skill-card.s4 .skill-icon { background: #e9c46a; color: #1d3557; }
.skill-card.s4 .stitle { color: #856404; }
.skill-card.s5 { border-top-color: #c1121f; }
.skill-card.s5 .skill-icon { background: #c1121f; }
.skill-card.s5 .stitle { color: #c1121f; }
.skill-card.s6 { border-top-color: #0c5460; }
.skill-card.s6 .skill-icon { background: #0c5460; }
.skill-card.s6 .stitle { color: #0c5460; }

/* === 4. WORKFLOW STEPS (numbered timeline) === */
.workflow {
  display: flex; flex-direction: column; gap: 10pt;
  border-left: 3px solid #2a9d8f;
  padding-left: 18pt; margin-left: 10pt;
  position: relative;
}
.workflow-item {
  background: #fff; padding: 12pt 14pt;
  border-radius: 8pt; border: 1px solid #e2e7ee;
  position: relative;
}
.workflow-item::before {
  content: attr(data-step); position: absolute;
  left: -32pt; top: 12pt;
  width: 26pt; height: 26pt; border-radius: 50%;
  background: #2a9d8f; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 11pt;
}
.workflow-item .wtitle {
  font-size: 11pt; font-weight: 700; color: #1d3557;
  margin-bottom: 4pt;
}
.workflow-item .wdesc { font-size: 10pt; color: #6c757d; }

/* === PRINT OPTIMIZATION (book-standard) === */
@media print {
  /* Bảo toàn màu nền nhẹ cho callout, table header, code block khi in PDF */
  body, table, pre, .callout, .col-card, .price-card, th, td,
  .dna-step, .flow-box, .skill-card, .workflow-item, .diagram, .cover {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  /* Bỏ shadow + animation khi in */
  * { box-shadow: none !important; animation: none !important; }
  /* Tránh tách giữa heading và nội dung */
  h1, h2, h3, h4 { page-break-after: avoid; break-after: avoid; }
  /* Tránh phần đoạn văn cuối trang chỉ còn 1-2 dòng */
  p, li { orphans: 3; widows: 3; }
  /* Code/table/callout/diagram không bao giờ tách trang (nếu vừa) */
  pre, table, .callout, .diagram, .col-card,
  .dna-formula, .flow-decision, .skill-hub, .workflow-item, .chapter-end,
  .cover .stats, .cover .audience { page-break-inside: avoid !important; }
  /* Mỗi row table cũng không bị cắt giữa */
  tr { page-break-inside: avoid; }
  /* Tiết kiệm space — bỏ margin top h2 đầu trang */
  h1 + h2, h1 + .callout { margin-top: 8pt; }
  /* Cover không có watermark đè */
  .cover .watermark, section.cover ~ .watermark { display: none; }
  /* TOC + Cover luôn xuống trang sau */
  .cover { page-break-after: always; }
  .toc  { page-break-after: always; }
  /* Chapter-end chốt trang, không bao giờ cô đơn 1 dòng đầu trang sau */
  .chapter-end { page-break-before: avoid; }
}
