/* === A4 Print Layout === */
@page {
    size: A4;
    margin: 20mm 18mm 25mm 18mm;
}

@media print {
    body { padding: 0; margin: 0; max-width: 170mm; }
    .no-print { display: none !important; }
    .page-break { page-break-before: always; }
    .avoid-break { page-break-inside: avoid; }
    a { color: inherit; text-decoration: none; }
    .toc a { color: #1a1a2e; }
}

/* === Base Styles === */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 11pt;
    line-height: 1.7;
    color: #1a1a2e;
    max-width: 960px;
    margin: 0 auto;
    padding: 40px 48px;
    background: white;
}

/* === Typography === */
h1 {
    font-size: 22pt;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 8pt;
    line-height: 1.2;
}

h2 {
    font-size: 15pt;
    font-weight: 600;
    color: #1e293b;
    margin-top: 24pt;
    margin-bottom: 10pt;
    padding-bottom: 4pt;
    border-bottom: 2px solid #e2e8f0;
}

h3 {
    font-size: 12pt;
    font-weight: 600;
    color: #334155;
    margin-top: 16pt;
    margin-bottom: 8pt;
}

h4 {
    font-size: 10.5pt;
    font-weight: 600;
    color: #475569;
    margin-top: 12pt;
    margin-bottom: 6pt;
}

p { margin-bottom: 8pt; }

/* === Title Page === */
.title-page {
    text-align: center;
    padding: 60pt 0 40pt;
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.title-page .series-label {
    font-size: 10pt;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #1a9c8d;
    margin-bottom: 16pt;
}

.title-page h1 {
    font-size: 28pt;
    margin-bottom: 12pt;
}

.title-page .subtitle {
    font-size: 13pt;
    color: #64748b;
    font-weight: 400;
    max-width: 560px;
    margin-bottom: 40pt;
}

.title-page .meta {
    font-size: 9pt;
    color: #94a3b8;
}

/* === Table of Contents === */
.toc {
    padding: 16pt 20pt;
    background: #f8fafc;
    border-radius: 8pt;
    margin: 20pt 0;
}

.toc h2 {
    font-size: 12pt;
    margin-top: 0;
    border: none;
    padding-bottom: 8pt;
}

.toc ol {
    list-style: none;
    counter-reset: toc;
    padding: 0;
}

.toc > ol > li {
    counter-increment: toc;
    margin-bottom: 4pt;
}

.toc > ol > li::before {
    content: counter(toc) ". ";
    font-weight: 600;
    color: #1a9c8d;
}

.toc a {
    color: #334155;
    text-decoration: none;
}

.toc a:hover { color: #1a9c8d; }

.toc .sub-items {
    padding-left: 20pt;
    list-style: none;
}

.toc .sub-items li {
    font-size: 9.5pt;
    color: #64748b;
    margin-bottom: 2pt;
}

.toc .toc-part-label {
    font-weight: 600;
    font-size: 10pt;
    color: #1a9c8d;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 12pt;
    margin-bottom: 4pt;
    padding-top: 8pt;
    border-top: 1px solid #e2e8f0;
}

.toc .toc-part-label:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* === Part Dividers === */
.part-divider {
    text-align: center;
    padding: 40pt 0 20pt;
}

.part-divider .part-label {
    font-size: 10pt;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 3px;
    color: #1a9c8d;
    margin-bottom: 8pt;
}

.part-divider h2 {
    border: none;
    font-size: 18pt;
    margin-top: 0;
}

.part-divider p {
    color: #64748b;
    font-size: 10.5pt;
}

/* === Info Boxes === */
.info-box {
    background: #f0f9ff;
    border-left: 4px solid #1a9c8d;
    padding: 12pt 16pt;
    border-radius: 0 6pt 6pt 0;
    margin: 12pt 0;
    font-size: 10pt;
}

.info-box.warning {
    background: #fffbeb;
    border-left-color: #f59e0b;
}

.info-box.tip {
    background: #f0fdf4;
    border-left-color: #22c55e;
}

.info-box.critical {
    background: #fef2f2;
    border-left-color: #ef4444;
}

.info-box-title {
    font-weight: 600;
    margin-bottom: 4pt;
}

/* === Glossary / Definition Box === */
.glossary {
    background: #fafafa;
    border: 1px solid #e2e8f0;
    border-radius: 8pt;
    padding: 16pt;
    margin: 16pt 0;
}

.glossary h3 {
    margin-top: 0;
    font-size: 11pt;
}

.glossary dl {
    margin: 0;
}

.glossary dt {
    font-weight: 600;
    color: #1e293b;
    margin-top: 8pt;
}

.glossary dd {
    margin-left: 0;
    padding-left: 16pt;
    color: #475569;
    font-size: 10pt;
}

/* === Figures === */
figure {
    margin: 16pt 0;
    text-align: center;
    page-break-inside: avoid;
}

figure img {
    max-width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 6pt;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

figcaption {
    font-size: 9pt;
    color: #64748b;
    font-style: italic;
    margin-top: 6pt;
}

/* === Tables === */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 12pt 0;
    font-size: 10pt;
    page-break-inside: avoid;
}

th, td {
    padding: 8pt 10pt;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

th {
    background: #f8fafc;
    font-weight: 600;
    color: #334155;
    font-size: 9.5pt;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* === Code / Formulas === */
code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9pt;
    background: #f1f5f9;
    padding: 1pt 4pt;
    border-radius: 3pt;
    color: #0f172a;
}

pre {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9pt;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6pt;
    padding: 12pt 16pt;
    overflow-x: auto;
    margin: 10pt 0;
    line-height: 1.6;
}

.formula-box {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8pt;
    padding: 16pt 20pt;
    margin: 14pt 0;
    text-align: center;
    page-break-inside: avoid;
}

.formula-box .formula {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11pt;
    color: #1e293b;
    margin: 8pt 0;
}

.formula-box .formula-label {
    font-size: 9pt;
    color: #64748b;
    margin-top: 6pt;
}

/* === Example Walkthrough === */
.example-box {
    background: #fefce8;
    border: 1px solid #fde68a;
    border-radius: 8pt;
    padding: 16pt;
    margin: 14pt 0;
    page-break-inside: avoid;
}

.example-box h4 {
    color: #92400e;
    margin-top: 0;
}

.example-box .calculation {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9.5pt;
    background: white;
    border-radius: 4pt;
    padding: 10pt;
    margin: 8pt 0;
}

/* === UI Mockup Boxes === */
.ui-box {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 10pt;
    padding: 20pt;
    margin: 14pt 0;
    page-break-inside: avoid;
}

.ui-box .ui-label {
    font-size: 9pt;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #94a3b8;
    font-weight: 600;
    margin-bottom: 6pt;
}

.ui-box .ui-field {
    display: flex;
    align-items: center;
    gap: 10pt;
    margin-bottom: 8pt;
}

.ui-box .ui-field-name {
    font-weight: 600;
    min-width: 120pt;
    color: #334155;
}

.ui-box .ui-field-value {
    background: white;
    border: 1px solid #cbd5e1;
    border-radius: 4pt;
    padding: 4pt 10pt;
    flex: 1;
    color: #475569;
    font-size: 10pt;
}

/* === Step-by-Step === */
.step {
    display: flex;
    gap: 12pt;
    margin: 12pt 0;
    padding: 12pt;
    background: #fafafa;
    border-radius: 8pt;
    page-break-inside: avoid;
}

.step-number {
    flex-shrink: 0;
    width: 28pt;
    height: 28pt;
    background: #1a9c8d;
    color: white;
    font-weight: 700;
    font-size: 12pt;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step-content {
    flex: 1;
}

.step-content p:last-child { margin-bottom: 0; }

/* === Comparison Table (Method Summary) === */
.method-comparison {
    border: 2px solid #e2e8f0;
    border-radius: 8pt;
    overflow: hidden;
    margin: 16pt 0;
}

.method-comparison th {
    background: #1e293b;
    color: white;
    text-transform: none;
    font-size: 10pt;
}

.method-comparison td {
    vertical-align: top;
}

.method-comparison .rank-best { color: #16a34a; font-weight: 600; }
.method-comparison .rank-good { color: #2563eb; font-weight: 600; }
.method-comparison .rank-ok { color: #d97706; font-weight: 600; }
.method-comparison .rank-caution { color: #dc2626; font-weight: 600; }

/* === References (APA 6) === */
.references {
    margin-top: 30pt;
}

.references h2 {
    border-bottom: 2px solid #334155;
}

.references p {
    padding-left: 36pt;
    text-indent: -36pt;
    margin-bottom: 6pt;
    font-size: 9.5pt;
    line-height: 1.5;
}

/* === Utility === */
.text-muted { color: #94a3b8; }
.text-primary { color: #1a9c8d; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.mt-1 { margin-top: 8pt; }
.mt-2 { margin-top: 16pt; }
.mb-1 { margin-bottom: 8pt; }
.mb-2 { margin-bottom: 16pt; }

ul, ol { margin-bottom: 8pt; padding-left: 20pt; }
li { margin-bottom: 4pt; }

/* === Print Button (screen only) === */
.print-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #1a9c8d;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    z-index: 100;
}

.print-btn:hover { background: #2d8a9e; }

/* === Decision Tree Diagram (Auto-Segment specific) === */
.tree-diagram {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 10pt;
    padding: 24pt 16pt;
    margin: 16pt 0;
    page-break-inside: avoid;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9pt;
    text-align: center;
}

.tree-diagram .tree-node {
    display: inline-block;
    border: 2px solid #1a9c8d;
    border-radius: 8pt;
    padding: 8pt 14pt;
    margin: 4pt;
    background: white;
}

.tree-diagram .tree-node.leaf {
    border-color: #22c55e;
    background: #f0fdf4;
}

.tree-diagram .tree-node .node-label {
    font-weight: 600;
    color: #1e293b;
}

.tree-diagram .tree-node .node-value {
    color: #64748b;
    font-size: 8.5pt;
}

.tree-diagram .tree-edge {
    color: #94a3b8;
    font-size: 9pt;
}

/* === Tree Diagram Layout Helpers (moved out of inline styles) === */
.tree-diagram .tree-root-row {
    margin-bottom: 12pt;
}

.tree-diagram .tree-branch-row {
    display: flex;
    justify-content: center;
    gap: 60pt;
    margin-bottom: 6pt;
}

.tree-diagram .tree-level-row {
    display: flex;
    justify-content: center;
    gap: 40pt;
}

.tree-diagram .tree-branch-row-inner {
    display: flex;
    justify-content: center;
    gap: 30pt;
    margin-top: 8pt;
}

.tree-diagram .tree-branch-row-inner .tree-edge {
    font-size: 8pt;
}

.tree-diagram .tree-leaf-row {
    display: flex;
    justify-content: center;
    gap: 10pt;
    margin-top: 6pt;
}

.tree-diagram .node-label.node-seg-1 { color: #2563eb; }
.tree-diagram .node-label.node-seg-2 { color: #0f766e; }
.tree-diagram .node-label.node-seg-3 { color: #db7a17; }

.tree-diagram .tree-caption {
    margin-top: 14pt;
    font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 9pt;
    color: #64748b;
    font-style: italic;
}

/* === Document Footer === */
.doc-footer {
    text-align: center;
    margin-top: 40pt;
    padding-top: 20pt;
    border-top: 1px solid #e2e8f0;
}

.doc-footer p {
    font-size: 9pt;
}

/* === Matrix Mockup (segment comparison matrix) === */
.matrix-mock {
    margin: 14pt 0;
    page-break-inside: avoid;
    overflow-x: auto;
}

.matrix-mock table {
    margin: 0;
    font-size: 9pt;
}

.matrix-mock th,
.matrix-mock td {
    padding: 5pt 8pt;
    vertical-align: top;
}

.matrix-mock .matrix-section-row td {
    background: #f1f5f9;
    font-weight: 600;
    color: #334155;
    text-transform: uppercase;
    font-size: 8.5pt;
    letter-spacing: 0.5px;
}

.matrix-mock .matrix-row-label {
    background: #f8fafc;
    font-weight: 600;
    color: #334155;
    text-transform: none;
    letter-spacing: 0;
    font-size: 9pt;
    white-space: nowrap;
}

.matrix-mock .matrix-imp {
    display: block;
    font-weight: 400;
    color: #64748b;
    font-size: 8pt;
}

.matrix-mock .matrix-seg-head {
    background: #1e293b;
    color: white;
    text-transform: none;
    letter-spacing: 0;
    font-size: 9pt;
}

.matrix-mock .matrix-seg-meta {
    display: block;
    font-weight: 400;
    font-size: 8pt;
    color: #cbd5e1;
}

.matrix-mock .matrix-sub {
    display: block;
    color: #64748b;
    font-size: 8pt;
}

.matrix-mock .matrix-chip {
    display: inline-block;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 4pt;
    padding: 1pt 5pt;
    margin: 1pt 2pt 1pt 0;
    font-family: 'JetBrains Mono', monospace;
    font-size: 8pt;
    color: #334155;
}
