:root {
  --bg-main: #f1f5f9;
  --bg-surface: #ffffff;
  --border-color: #cbd5e1;
  --border-strong: #94a3b8;
  --text-primary: #0f172a;
  --text-secondary: #334155;
  --text-muted: #64748b;
  --brand-primary: #1e293b;
  --brand-accent: #2563eb;
  --table-header-bg: #1e293b;
  --code-bg: #f8fafc;
  --toc-active: #2563eb;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; scroll-padding-top: 70px; overflow-x: clip; }
body {
  background: var(--bg-main);
  color: var(--text-primary);
  font-family: "Times New Roman", Times, serif;
  line-height: 1.7;
  font-size: 14px;
  overflow-x: clip;
}
/* header */
header {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg-surface);
  border-bottom: 2px solid #cbd5e1;
  padding: 12px 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px;
}
header h1 { font-size: 15px; font-weight: 800; color: var(--brand-primary); letter-spacing: -0.02em; }
.doc-meta {
  font-size: 11px; color: var(--text-secondary);
  background: var(--code-bg); border: 1px solid var(--border-color);
  padding: 3px 8px; border-radius: 4px;
  font-family: ui-monospace, monospace; font-weight: 700;
}
.btn-pdf {
  background: var(--brand-primary); color: #fff; border: none;
  padding: 7px 14px; border-radius: 6px; font-size: 12px; font-weight: 700; cursor: pointer;
}
.btn-pdf:hover { background: #0f172a; }
.btn-toc {
  display: none; background: #fff; border: 1px solid var(--border-color);
  padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 700; cursor: pointer;
}
/* layout */
.layout {
  max-width: 1400px; margin: 0 auto; padding: 20px 16px;
  display: flex; gap: 22px; align-items: flex-start;
}
aside.toc {
  position: sticky; top: 70px;
  width: 300px; flex-shrink: 0;
  background: var(--bg-surface); border: 1px solid var(--border-color);
  border-radius: 8px; padding: 16px 14px; max-height: calc(100vh - 80px); overflow-y: auto;
}
aside.toc h3 { font-size: 12px; letter-spacing: 0.08em; color: var(--text-muted); margin-bottom: 10px; }
.toc a {
  display: block; text-decoration: none; color: var(--text-secondary);
  font-size: 12.5px; padding: 5px 8px; border-radius: 4px; border-left: 3px solid transparent;
  margin-bottom: 1px; line-height: 1.4;
}
.toc a:hover { background: #f1f5f9; color: var(--brand-primary); }
.toc a.active { background: #eff6ff; color: var(--toc-active); border-left-color: var(--toc-active); font-weight: 700; }
.toc .toc-bab { font-weight: 700; color: var(--brand-primary); margin-top: 10px; font-size: 12px; }
.toc .toc-sub { padding-left: 18px; font-size: 11.5px; }
main { flex: 1; min-width: 0; }
section {
  background: var(--bg-surface); border-radius: 8px; padding: 26px 22px;
  margin-bottom: 22px; border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
h2 { font-size: 17px; font-weight: 800; color: var(--brand-primary); border-bottom: 2px solid var(--brand-primary); padding-bottom: 7px; margin-bottom: 12px; }
h3 { font-size: 14px; font-weight: 800; color: var(--brand-primary); margin: 20px 0 8px 0; }
h4 { font-size: 13px; font-weight: 700; color: var(--brand-primary); margin: 14px 0 6px 0; }
p, ul, ol { color: var(--text-secondary); margin-bottom: 10px; font-size: 13.5px; }
ul, ol { padding-left: 20px; }
li { margin-bottom: 4px; }
.note-box {
  background: #f8fafc; border: 1px solid var(--border-color); border-left: 4px solid var(--brand-primary);
  padding: 12px 14px; margin: 14px 0; font-size: 12.5px;
}
.note-box b { color: var(--brand-primary); }
.mermaid-wrapper {
  position: relative; background: #ffffff; border: 1px solid var(--border-strong);
  border-radius: 6px; margin: 14px 0; padding: 38px 12px 12px 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04); overflow-x: auto;
}
.copy-btn {
  position: absolute; top: 8px; right: 8px; background: #334155; color: #fff;
  border: none; padding: 4px 10px; border-radius: 4px; font-size: 11px; font-weight: 700; cursor: pointer;
}
.copy-btn:hover { background: #0f172a; }
.mermaid { display: flex; justify-content: center; }
.mermaid svg { max-width: 100%; height: auto; }
.mermaid text { font-family: "Times New Roman", Times, serif !important; font-size: 12px !important; }
table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 12px 0 16px 0; background: #fff; }
th, td { border: 1px solid var(--border-color); padding: 7px 10px; text-align: left; vertical-align: top; }
th { background: var(--table-header-bg); color: #fff; font-weight: 700; font-size: 11.5px; }
tr:nth-child(even) { background: #f8fafc; }
code { font-family: ui-monospace, monospace; background: var(--code-bg); border: 1px solid #e2e8f0; padding: 1px 5px; border-radius: 3px; font-size: 11.5px; color: #0f172a; }
pre { background: #0f172a; color: #f8fafc; padding: 14px; border-radius: 6px; font-size: 11.5px; overflow-x: auto; font-family: ui-monospace, monospace; margin: 12px 0; line-height: 1.6; }
.step-card { border: 1px solid var(--border-color); border-left: 4px solid var(--brand-accent); border-radius: 4px; padding: 12px 14px; margin-bottom: 10px; background: #fff; }
.step-card h4 { font-size: 12.5px; color: var(--brand-primary); margin-bottom: 4px; }
footer { text-align: center; padding: 20px; font-size: 11px; color: var(--text-muted); border-top: 1px solid var(--border-color); margin-top: 20px; }
/* tooltip */
.relation-tooltip {
  display: none; position: absolute; background: var(--brand-primary); color: white;
  padding: 6px 10px; border-radius: 4px; font-size: 11px; font-weight: 600; z-index: 1000;
  pointer-events: none; white-space: nowrap; box-shadow: 0 4px 6px rgba(0,0,0,0.15); transform: translate(-50%, -10px);
}
.relation-tooltip::after {
  content: ''; position: absolute; top: 100%; left: 50%; margin-left: -5px;
  border-width: 5px; border-style: solid; border-color: var(--brand-primary) transparent transparent transparent;
}
.mermaid svg path.relationshipLine { transition: stroke 0.15s; }
.mermaid svg path.relationshipLine.is-active { stroke: #2563eb !important; stroke-width: 2.5px !important; }
/* cover */
.cover { text-align: center; padding: 30px 20px 24px 20px; border-bottom: 3px double var(--brand-primary); margin-bottom: 0; }
.cover h1 { font-size: 20px; font-weight: 900; color: var(--brand-primary); line-height: 1.3; margin-bottom: 6px; }
.cover .subtitle { font-size: 13px; color: var(--text-secondary); }
.cover .meta-row { display: flex; justify-content: center; gap: 16px; flex-wrap: wrap; margin-top: 14px; font-size: 11px; color: var(--text-muted); }
@media (max-width: 980px) {
  .layout { flex-direction: column; }
  aside.toc { position: relative; top: 0; width: 100%; max-height: none; }
  .btn-toc { display: inline-block; }
  aside.toc.collapsed { display: none; }
}
/* Modal PDF Warning */
.modal-backdrop {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); z-index: 999; align-items: center; justify-content: center;
}
.modal-backdrop.active { display: flex; }
.modal-box {
  background: #fff; width: 90%; max-width: 560px; border-radius: 10px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.2); overflow: hidden; font-family: "Times New Roman", Times, serif;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-color); background: #f8fafc; }
.modal-header h3 { margin: 0; font-size: 14px; }
.modal-body { padding: 18px 20px; max-height: 70vh; overflow-y: auto; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; line-height: 1; color: var(--text-muted); }
.modal-close:hover { color: var(--text-primary); }
.btn-primary { background: var(--brand-primary); color: #fff; border: none; border-radius: 6px; font-weight: 700; cursor: pointer; font-family: "Times New Roman", Times, serif; }
.btn-primary:hover { background: #0f172a; }

@media print {
  header, .copy-btn, #tooltip, .btn-pdf, .btn-toc, .modal-backdrop { display: none !important; }
  body { background: #fff; }
  .layout { display: block; padding: 0; }
  aside.toc { display: block !important; position: static; width: 100%; border: 2px solid #000; page-break-after: always; max-height: none; }
  section { break-inside: avoid; box-shadow: none; border: 1px solid #cbd5e1; }
  pre { white-space: pre-wrap; }
}