/* ==========================================================================
   MarkdownHub - Markdown to PDF Stylesheet
   Professional Document Layout & Print Styles
   ========================================================================== */

/* Top Settings Bar for PDF Controls */
.pdf-settings-bar {
  background-color: #F0F1F4;
  border: 1px solid #DCDFE4;
  border-radius: 8px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.pdf-setting-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.pdf-setting-label {
  font-weight: 500;
  color: #374151;
  font-size: 0.82rem;
}

.pdf-select {
  background-color: #FFFFFF;
  border: 1px solid #D1D5DB;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 0.82rem;
  color: #374151;
  outline: none;
  cursor: pointer;
}

[data-theme="dark"] .pdf-settings-bar {
  background-color: #26262B;
  border-color: #37373C;
}

[data-theme="dark"] .pdf-setting-label {
  color: #D1D5DB;
}

[data-theme="dark"] .pdf-select {
  background-color: #2F2F35;
  border-color: #424248;
  color: #F3F4F6;
}

/* Screen Document Desk Preview */
.pdf-sheet-preview {
  background-color: #F3F4F6;
  padding: 24px;
  display: flex;
  justify-content: center;
  overflow-y: auto;
  height: 100%;
}

[data-theme="dark"] .pdf-sheet-preview {
  background-color: #24242A;
}

/* Professional Report Document Sheet (Screen Preview) */
.pdf-sheet {
  background-color: #FFFFFF !important;
  color: #000000 !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  width: 100%;
  max-width: 794px; /* A4 width at 96 DPI */
  min-height: 1123px; /* A4 height at 96 DPI for screen preview */
  padding: 42px;
  box-sizing: border-box;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Noto Sans Arabic", "Amiri", "Scheherazade", "Geeza Pro", "Simplified Arabic", Tahoma, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
}

.pdf-sheet.landscape {
  max-width: 1123px;
  min-height: 794px;
}

.pdf-sheet.margins-compact {
  padding: 24px;
}

.pdf-sheet.margins-wide {
  padding: 56px;
}

/* Ensure pure black text and professional document typography in all themes */
.pdf-sheet,
.pdf-sheet * {
  color: #000000 !important;
}

.pdf-sheet h1,
.pdf-sheet h2,
.pdf-sheet h3,
.pdf-sheet h4,
.pdf-sheet h5,
.pdf-sheet h6 {
  color: #000000 !important;
  font-weight: 700;
  line-height: 1.25;
  margin-top: 1.1em;
  margin-bottom: 0.4em;
}

.pdf-sheet h1:first-child,
.pdf-sheet h2:first-child,
.pdf-sheet h3:first-child {
  margin-top: 0 !important;
}

.pdf-sheet h1 {
  font-size: 1.35rem; /* ~19pt */
  border-bottom: 1.5px solid #D1D5DB;
  padding-bottom: 0.25em;
  margin-bottom: 0.5em;
}

.pdf-sheet h2 {
  font-size: 1.15rem; /* ~14.5pt */
  border-bottom: 1px solid #E5E7EB;
  padding-bottom: 0.2em;
  margin-bottom: 0.45em;
}

.pdf-sheet h3 {
  font-size: 1rem; /* ~12.5pt */
  margin-bottom: 0.35em;
}

.pdf-sheet h4 {
  font-size: 0.92rem;
  margin-bottom: 0.3em;
}

.pdf-sheet h5,
.pdf-sheet h6 {
  font-size: 0.88rem;
  margin-bottom: 0.25em;
}

.pdf-sheet p {
  color: #000000 !important;
  margin: 0 0 0.65em 0;
  line-height: 1.45;
}

.pdf-sheet ul,
.pdf-sheet ol {
  color: #000000 !important;
  margin: 0 0 0.65em 0;
  padding-left: 1.6em;
}

.pdf-sheet li {
  color: #000000 !important;
  margin-bottom: 0.2em;
  line-height: 1.45;
}

.pdf-sheet li > ul,
.pdf-sheet li > ol {
  margin-top: 0.2em;
  margin-bottom: 0.2em;
}

.pdf-sheet blockquote {
  border-left: 3.5px solid #9CA3AF;
  padding: 5px 12px;
  margin: 0.8em 0 1em 0;
  color: #1F2937 !important;
  background-color: #F9FAFB;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.pdf-sheet blockquote p {
  color: #1F2937 !important;
  margin: 0 0 0.3em 0;
}

.pdf-sheet blockquote p:last-child {
  margin-bottom: 0;
}

.pdf-sheet code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.88rem;
  background-color: #F3F4F6 !important;
  color: #000000 !important;
  padding: 1.5px 4.5px;
  border-radius: 3px;
  border: 1px solid #E5E7EB;
}

.pdf-sheet pre {
  background-color: #F8F9FA !important;
  border: 1px solid #D1D5DB;
  border-radius: 4px;
  padding: 8px 12px;
  overflow-x: auto;
  margin: 0.8em 0 1em 0;
  white-space: pre-wrap;
  word-break: break-all;
}

.pdf-sheet pre code {
  background: none !important;
  border: none !important;
  padding: 0;
  color: #000000 !important;
  font-size: 0.84rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.pdf-sheet table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.8em 0 1em 0;
  font-size: 0.88rem;
  color: #000000 !important;
  border: 1px solid #D1D5DB;
}

.pdf-sheet th,
.pdf-sheet td {
  border: 1px solid #D1D5DB;
  padding: 6px 10px;
  text-align: left;
  color: #000000 !important;
  vertical-align: top;
}

.pdf-sheet th {
  background-color: #F3F4F6 !important;
  font-weight: 600;
  color: #000000 !important;
}

.pdf-sheet tr:nth-child(even) td {
  background-color: #FAFAFA !important;
}

.pdf-sheet hr {
  border: none;
  border-top: 1px solid #D1D5DB;
  margin: 1.1em 0;
}

.pdf-sheet img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-sm);
}

.pdf-sheet a {
  color: #000000 !important;
  text-decoration: underline;
}

/* Bidirectional (RTL) & Arabic Support */
.pdf-sheet[dir="rtl"],
.pdf-sheet.is-rtl {
  direction: rtl;
  text-align: right;
}

.pdf-sheet.is-rtl ul,
.pdf-sheet.is-rtl ol,
.pdf-sheet[dir="rtl"] ul,
.pdf-sheet[dir="rtl"] ol {
  padding-left: 0;
  padding-right: 1.6em;
}

.pdf-sheet.is-rtl blockquote,
.pdf-sheet[dir="rtl"] blockquote {
  border-left: none;
  border-right: 3.5px solid #9CA3AF;
  padding: 5px 12px 5px 8px;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}

.pdf-sheet.is-rtl th,
.pdf-sheet.is-rtl td,
.pdf-sheet[dir="rtl"] th,
.pdf-sheet[dir="rtl"] td {
  text-align: right;
}

/* Keep code blocks LTR even in RTL Arabic documents */
.pdf-sheet pre,
.pdf-sheet code,
.pdf-sheet.is-rtl pre,
.pdf-sheet.is-rtl code,
.pdf-sheet[dir="rtl"] pre,
.pdf-sheet[dir="rtl"] code {
  direction: ltr !important;
  text-align: left !important;
  unicode-bidi: isolate !important;
}

/* ==========================================================================
   Page Print Fallback Styles (@media print)
   (Applied if user uses native Ctrl+P / Cmd+P directly on the main window)
   ========================================================================== */
@page {
  size: A4 portrait;
  margin: 18mm;
}

@media print {
  /* 1. Force pure white background on canvas and reset body layout */
  html, body {
    background: #FFFFFF !important;
    background-color: #FFFFFF !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* 2. Completely remove all website navigation, UI chrome, sidebars, and extra content cards */
  .site-header,
  .site-footer,
  .page-intro,
  .tool-content-card,
  .tool-toolbar,
  .pdf-settings-bar,
  .editor-pane,
  .pane-header,
  .tool-statusbar,
  .editor-toast,
  .mobile-nav-backdrop,
  #tools-dropdown-menu,
  .faq-list,
  .faq-item {
    display: none !important;
    height: 0 !important;
    min-height: 0 !important;
    max-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
  }

  /* 3. Structural rules ensuring all sibling elements outside printable document are hidden */
  body > *:not(.site-main) {
    display: none !important;
  }
  .site-main > .container > *:not(#tool-workspace) {
    display: none !important;
  }
  #tool-workspace > *:not(.panels-container) {
    display: none !important;
  }
  .panels-container > *:not(.preview-pane) {
    display: none !important;
  }
  .preview-pane > *:not(.pdf-sheet-preview) {
    display: none !important;
  }
  .pdf-sheet-preview > *:not(#pdf-sheet) {
    display: none !important;
  }

  /* 4. Flatten all parent containers to eliminate artificial heights, scrollbars, and extra pages */
  .site-main,
  .container,
  #tool-workspace,
  .panels-container,
  .preview-pane,
  .pdf-sheet-preview {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    background: transparent !important;
    background-color: transparent !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    height: auto !important;
    overflow: visible !important;
    float: none !important;
  }

  /* 5. The printable sheet: static document flow, natural pagination, zero artificial heights */
  .pdf-sheet {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 0 !important;
    height: auto !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    border: none !important;
    background: #FFFFFF !important;
    background-color: #FFFFFF !important;
    color: #000000 !important;
    overflow: visible !important;
    box-sizing: border-box !important;
  }

  /* 6. Enforce black text, neutral gray borders, and professional compact document typography for print */
  .pdf-sheet,
  .pdf-sheet * {
    color: #000000 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .pdf-sheet h1,
  .pdf-sheet h2,
  .pdf-sheet h3,
  .pdf-sheet h4,
  .pdf-sheet h5,
  .pdf-sheet h6 {
    color: #000000 !important;
    break-after: avoid;
    page-break-after: avoid;
    margin-top: 1.1em !important;
    margin-bottom: 0.4em !important;
    font-weight: 700 !important;
    line-height: 1.25 !important;
  }

  .pdf-sheet h1:first-child,
  .pdf-sheet h2:first-child,
  .pdf-sheet h3:first-child {
    margin-top: 0 !important;
  }

  .pdf-sheet h1 {
    font-size: 19pt !important;
    border-bottom: 1.5pt solid #D1D5DB !important;
    padding-bottom: 0.25em !important;
    margin-bottom: 0.5em !important;
  }

  .pdf-sheet h2 {
    font-size: 14pt !important;
    border-bottom: 1pt solid #E5E7EB !important;
    padding-bottom: 0.2em !important;
    margin-bottom: 0.45em !important;
  }

  .pdf-sheet h3 {
    font-size: 12pt !important;
    margin-bottom: 0.35em !important;
  }

  .pdf-sheet h4 {
    font-size: 11pt !important;
    margin-bottom: 0.3em !important;
  }

  .pdf-sheet h5,
  .pdf-sheet h6 {
    font-size: 10.5pt !important;
    margin-bottom: 0.25em !important;
  }

  .pdf-sheet p {
    color: #000000 !important;
    font-size: 10.5pt !important;
    line-height: 1.45 !important;
    margin: 0 0 0.65em 0 !important;
    orphans: 3;
    widows: 3;
  }

  .pdf-sheet ul,
  .pdf-sheet ol {
    color: #000000 !important;
    font-size: 10.5pt !important;
    margin: 0 0 0.65em 0 !important;
    padding-left: 1.6em !important;
  }

  .pdf-sheet.is-rtl ul,
  .pdf-sheet.is-rtl ol,
  .pdf-sheet[dir="rtl"] ul,
  .pdf-sheet[dir="rtl"] ol {
    padding-left: 0 !important;
    padding-right: 1.6em !important;
  }

  .pdf-sheet li {
    color: #000000 !important;
    margin-bottom: 0.2em !important;
    line-height: 1.45 !important;
  }

  .pdf-sheet table {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse !important;
    margin: 0.8em 0 1em 0 !important;
    font-size: 9.5pt !important;
    color: #000000 !important;
    border: 1px solid #D1D5DB !important;
    break-inside: auto;
    page-break-inside: auto;
  }

  .pdf-sheet thead {
    display: table-header-group;
  }

  .pdf-sheet tr {
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .pdf-sheet th,
  .pdf-sheet td {
    border: 1px solid #D1D5DB !important;
    padding: 6px 10px !important;
    color: #000000 !important;
    vertical-align: top !important;
    text-align: left;
  }

  .pdf-sheet th {
    background-color: #F3F4F6 !important;
    font-weight: 600 !important;
    color: #000000 !important;
  }

  .pdf-sheet tr:nth-child(even) td {
    background-color: #FAFAFA !important;
  }

  .pdf-sheet.is-rtl th,
  .pdf-sheet.is-rtl td,
  .pdf-sheet[dir="rtl"] th,
  .pdf-sheet[dir="rtl"] td {
    text-align: right !important;
  }

  .pdf-sheet code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !important;
    font-size: 9pt !important;
    color: #000000 !important;
    background-color: #F3F4F6 !important;
    padding: 1.5px 4.5px !important;
    border-radius: 3px !important;
    border: 1px solid #E5E7EB !important;
  }

  .pdf-sheet pre {
    background-color: #F8F9FA !important;
    border: 1px solid #D1D5DB !important;
    border-radius: 4px !important;
    padding: 8px 12px !important;
    margin: 0.8em 0 1em 0 !important;
    overflow-x: visible !important;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    word-break: break-all !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .pdf-sheet pre code {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    color: #000000 !important;
    font-size: 8.8pt !important;
    line-height: 1.4 !important;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
  }

  .pdf-sheet blockquote {
    border-left: 3.5pt solid #9CA3AF !important;
    padding: 5px 12px !important;
    margin: 0.8em 0 1em 0 !important;
    color: #1F2937 !important;
    background-color: #F9FAFB !important;
    border-radius: 0 4px 4px 0 !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .pdf-sheet.is-rtl blockquote,
  .pdf-sheet[dir="rtl"] blockquote {
    border-left: none !important;
    border-right: 3.5pt solid #9CA3AF !important;
    border-radius: 4px 0 0 4px !important;
    padding: 5px 12px 5px 8px !important;
  }

  .pdf-sheet blockquote p {
    color: #1F2937 !important;
    margin: 0 0 0.3em 0 !important;
  }

  .pdf-sheet blockquote p:last-child {
    margin-bottom: 0 !important;
  }

  .pdf-sheet a {
    color: #000000 !important;
    text-decoration: underline !important;
  }

  .pdf-sheet hr {
    border: none !important;
    border-top: 1pt solid #D1D5DB !important;
    margin: 1.1em 0 !important;
  }

  .pdf-sheet img {
    max-width: 100% !important;
    height: auto !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
}
