/* BA Documentation Framework - Print-friendly stylesheet */

:root {
  --primary: #1a5276;
  --secondary: #2c3e50;
  --accent: #3498db;
  --text: #2c3e50;
  --bg: #ffffff;
  --border: #bdc3c7;
  --header-bg: #ecf0f1;
  --table-stripe: #f8f9fa;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  max-width: 210mm;
  margin: 0 auto;
  padding: 20mm;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* --- Logo Header --- */
.logo-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 20px;
}

.logo-header .logo {
  height: 50px;
  width: auto;
}

.logo-header .logo-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-header .logo-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-header .logo-placeholder {
  height: 50px;
  width: 120px;
  background: var(--header-bg);
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: #999;
  border-radius: 4px;
}

/* --- Table of Contents --- */
.toc {
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px 30px;
  margin: 20px 0 30px;
  page-break-inside: avoid;
}

.toc h2 {
  font-size: 18px;
  color: var(--primary);
  margin-bottom: 15px;
  border-bottom: none;
  padding-bottom: 0;
}

.toc ul {
  list-style: none;
  padding: 0;
}

.toc ul li {
  padding: 6px 0;
  border-bottom: 1px dotted #ddd;
}

.toc ul li:last-child {
  border-bottom: none;
}

.toc ul li a {
  color: var(--text);
  text-decoration: none;
  display: flex;
  justify-content: space-between;
}

.toc ul li a:hover {
  color: var(--accent);
}

.toc ul ul {
  padding-left: 20px;
  margin-top: 4px;
}

.toc ul ul li {
  font-size: 13px;
  border-bottom: none;
  padding: 3px 0;
}

/* --- Cover Page --- */
.cover {
  text-align: center;
  padding: 60px 0;
  border-bottom: 3px solid var(--primary);
  margin-bottom: 40px;
  page-break-after: always;
}

.cover h1 {
  font-size: 28px;
  color: var(--primary);
  margin-bottom: 10px;
}

.cover .subtitle {
  font-size: 18px;
  color: var(--secondary);
  margin-bottom: 30px;
}

.cover .meta-table {
  margin: 30px auto;
  border-collapse: collapse;
  width: 60%;
}

.cover .meta-table td {
  padding: 8px 16px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.cover .meta-table td:first-child {
  background: var(--header-bg);
  font-weight: 600;
  width: 40%;
}

/* --- Headings --- */
h1 { font-size: 24px; color: var(--primary); margin: 30px 0 15px; border-bottom: 2px solid var(--primary); padding-bottom: 8px; }
h2 { font-size: 20px; color: var(--primary); margin: 25px 0 12px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
h3 { font-size: 16px; color: var(--secondary); margin: 20px 0 10px; }
h4 { font-size: 14px; color: var(--secondary); margin: 15px 0 8px; }

/* --- Tables --- */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

th, td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

th {
  background: var(--primary);
  color: white;
  font-weight: 600;
}

tr:nth-child(even) { background: var(--table-stripe); }

/* --- Code --- */
pre {
  background: #f4f4f4;
  border: 1px solid #ddd;
  border-left: 4px solid var(--accent);
  padding: 12px;
  margin: 12px 0;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.5;
}

code {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 12px;
}

p code, li code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid #ddd;
}

/* --- Lists --- */
ul, ol {
  margin: 10px 0;
  padding-left: 24px;
}

li { margin: 4px 0; }

/* --- Diagrams --- */
.diagram {
  text-align: center;
  margin: 20px 0;
  page-break-inside: avoid;
}

.diagram img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.diagram .caption {
  font-size: 12px;
  color: #666;
  margin-top: 6px;
  font-style: italic;
}

/* --- Sections --- */
.section {
  page-break-inside: avoid;
  margin-bottom: 20px;
}

/* --- Content Centering --- */
h1, h2, h3, h4, p, ul, ol, blockquote, pre, table, .toc, .diagram, .cover, .logo-header, .back-link, .module-badge {
  width: 100%;
}

/* --- Blockquotes --- */
blockquote {
  border-left: 4px solid var(--accent);
  padding: 10px 16px;
  margin: 12px 0;
  background: #f8f9fa;
  color: #555;
}

/* --- Horizontal Rule --- */
hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* --- Requirement ID Badge --- */
.req-id {
  background: #e8f4fd;
  color: #1a5276;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 12px;
}

/* --- Traceability Table --- */
.trace-table td:first-child {
  white-space: nowrap;
}

@media print {
  .trace-table {
    font-size: 10px;
    page-break-inside: auto;
  }
  .trace-table th, .trace-table td {
    padding: 4px 5px;
  }
  .trace-table td {
    word-break: break-word;
  }
}

/* --- Print Styles --- */
@media print {
  *, *::before, *::after { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; color-adjust: exact !important; }
  body { padding: 0; max-width: none; font-size: 12px; }

  /* Headings: avoid orphaned at bottom, keep attached to next content */
  h1, h2, h3, h4 { page-break-after: avoid; orphans: 3; widows: 3; }
  h1:first-of-type { page-break-before: avoid; }

  /* Prevent big blank gaps: only break before h2 when there's enough content above */
  h2 { page-break-before: auto; }

  /* Keep heading + diagram together on same page */
  h3 + .diagram, h4 + .diagram, h2 + .diagram, p + .diagram { page-break-before: avoid !important; }
  .diagram { page-break-inside: auto !important; margin: 8px 0 !important; }
  .diagram img { max-height: 220mm; max-width: 80%; }
  table { page-break-inside: avoid; }
  pre { white-space: pre-wrap; word-wrap: break-word; }
  .toc { page-break-inside: avoid; }
  .logo-header { page-break-inside: avoid; }

  /* Reduce spacing to fit more content per page */
  h1 { margin: 15px 0 10px; }
  h2 { margin: 12px 0 8px; }
  h3 { margin: 10px 0 6px; }
  .section { margin-bottom: 10px; }
}

@page {
  size: A4;
  margin: 20mm;
}
