/* Print / "PDF로 저장" — a clean document: title, one meta line, the rendered body. Screen styles are untouched. */
@media print {
  @page { margin: 18mm 16mm; }

  html, body { background: #fff !important; color: #000 !important; }
  body { margin: 0; font-size: 11pt; }

  /* ---- App chrome ---- */
  .sidebar, .topbar, .workspace-navigation, .mobile-menu, .demo-banner, .sample-notice, .storage-chip,
  #toast, #modal-root, .modal-overlay, .search-overlay, .search-dialog, .quick-capture, .source-drawer,
  .floating-outline, .format-bar, .slash-popover, .block-menu, .editor-tool-popover, .write-backdrop,
  .block-handle, .live-append, textarea.live-edit, .live-edit-holder > textarea, .drag-message, .errorbar {
    display: none !important;
  }

  /* Layout: drop the sidebar column and side panels, let the page flow at full width. */
  .shell { display: block !important; min-height: 0 !important; }
  .main { margin: 0 !important; width: auto !important; min-width: 0 !important; }
  .content, .document-page .content { padding: 0 !important; margin: 0 !important; max-width: none !important; }
  .editor-layout { display: block !important; }

  /* Document page: keep only the title, the print header and the rendered body. */
  .content:has(.body-preview) > :not(.editor-layout),
  .editor-layout:has(.body-preview) > :not(.editor-main),
  .editor-main:has(.body-preview) > :not(.body-preview):not(.print-header):not(#note-title) {
    display: none !important;
  }

  /* The header printNote() injects (hidden on screen via the hidden attribute). */
  .print-header { display: block !important; max-width: 170mm; margin: 0 auto 7mm; padding-bottom: 3mm; border-bottom: .6pt solid #999; break-after: avoid; }
  .print-header h1 { margin: 0 0 1.5mm; font-size: 20pt; line-height: 1.3; font-weight: 700; color: #000; letter-spacing: -.2pt; }
  .print-header p { margin: 0; font-size: 9pt; color: #555; }

  /* Plain Ctrl+P without printNote(): the title input stands in as the heading. */
  #note-title { display: none !important; }
  .editor-main:not(:has(.print-header)) > #note-title {
    display: block !important; width: 100% !important; max-width: 170mm !important; margin: 0 auto 6mm !important; padding: 0 0 3mm !important;
    border: 0 !important; border-bottom: .6pt solid #999 !important; border-radius: 0 !important; background: none !important;
    font-size: 20pt !important; font-weight: 700 !important; color: #000 !important; height: auto !important;
  }

  /* ---- Body ---- */
  .body-preview {
    max-width: 170mm !important; width: 100% !important; margin: 0 auto !important; padding: 0 !important;
    font-family: "Noto Serif KR", "Nanum Myeongjo", "Batang", Georgia, serif;
    font-size: 11pt !important; line-height: 1.7 !important; color: #000 !important;
    word-break: keep-all; overflow-wrap: anywhere;
    orphans: 3; widows: 3;
  }
  .body-preview * { cursor: auto !important; }
  .body-preview [data-src] { outline: none !important; box-shadow: none !important; }
  .body-preview p, .body-preview li { color: #000; }
  .body-preview h1, .body-preview h2, .body-preview h3, .body-preview h4, .body-preview h5, .body-preview h6 {
    color: #000 !important; break-after: avoid; page-break-after: avoid; break-inside: avoid;
    font-family: "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  }
  .body-preview h1 { font-size: 17pt; }
  .body-preview h2 { font-size: 14.5pt; margin-top: 1.4em; }
  .body-preview h3 { font-size: 12.5pt; }
  .body-preview h4, .body-preview h5, .body-preview h6 { font-size: 11pt; }

  /* Links: external URL after the text, but not for citation marks or autolinks that already show the URL. */
  .body-preview a { color: #000 !important; text-decoration: underline; text-decoration-thickness: .4pt; }
  .body-preview a[href^="http"]:not(.md-autolink)::after { content: " (" attr(href) ")"; font-size: 8.5pt; color: #444; word-break: break-all; text-decoration: none; }
  .body-preview .md-cite a::after, .body-preview .md-link-card a::after, .body-preview .fn-ref a::after { content: none !important; }
  .body-preview .md-autolink { text-decoration: none; }
  .body-preview .wiki-link { border: 0 !important; background: none !important; padding: 0 !important; color: #000 !important; font: inherit; text-decoration: underline dotted; }

  /* Blocks that should not split across pages. */
  .body-preview .markdown-callout, .body-preview blockquote, .body-preview .code-block, .body-preview pre,
  .body-preview .markdown-table-scroll, .body-preview table, .body-preview figure, .body-preview img,
  .body-preview .md-embed, .body-preview .md-link-card, .body-preview .slide-card, .body-preview .inline-attachment {
    break-inside: avoid; page-break-inside: avoid;
  }

  /* Callouts and highlights keep their soft background. */
  .body-preview .markdown-callout, .body-preview blockquote, .body-preview .markdown-dig, .body-preview mark,
  .body-preview .code-block, .body-preview .code-block-bar, .body-preview th, .body-preview code, .body-preview h2 {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .body-preview .markdown-callout { box-shadow: none !important; }
  .body-preview details.markdown-callout > summary::marker, .body-preview details.markdown-callout > summary::-webkit-details-marker { display: none; content: ""; }

  /* Code wraps instead of scrolling. */
  .body-preview .code-block { overflow: visible !important; border: .6pt solid #bbb !important; }
  .body-preview .code-block-bar button { display: none !important; }
  .body-preview pre, .body-preview .code-block pre {
    white-space: pre-wrap !important; overflow: visible !important; word-break: break-all;
    font-size: 9pt !important; line-height: 1.55 !important;
  }

  /* Tables: full width with borders. */
  .body-preview .markdown-table-scroll { overflow: visible !important; border: 0 !important; border-radius: 0 !important; max-width: none !important; }
  .body-preview table { width: 100% !important; border-collapse: collapse !important; font-size: 9.5pt !important; }
  .body-preview th, .body-preview td { min-width: 0 !important; border: .6pt solid #888 !important; padding: 1.5mm 2.5mm !important; color: #000 !important; }
  .body-preview thead { display: table-header-group; }
  .body-preview tr { break-inside: avoid; }

  /* Images fit the column. */
  .body-preview img, .body-preview video, .body-preview canvas { max-width: 100% !important; height: auto; }
  .body-preview .md-embed-video, .body-preview iframe { display: none !important; }

  /* Slide decks: one slide per page width, notes as plain text, no tools. */
  .body-preview .inline-deck { border: 0 !important; background: none !important; padding: 0 !important; margin: 1.2em 0 !important; }
  .body-preview .inline-deck .slide-toolbar, .body-preview .inline-deck .slide-card-actions,
  .body-preview .inline-deck .slide-pad-actions, .body-preview .inline-deck .slide-pad-open,
  .body-preview .inline-deck button, .body-preview .inline-deck .slide-note:placeholder-shown { display: none !important; }
  .body-preview .inline-deck .slide-card { width: 100%; margin: 0 0 6mm !important; padding: 0 !important; border: 0 !important; }
  .body-preview .inline-deck .slide-stage { width: 100% !important; border: .6pt solid #bbb !important; border-radius: 0 !important; }
  .body-preview .inline-deck .slide-stage img { width: 100% !important; height: auto !important; display: block; }
  .body-preview .inline-deck .slide-note {
    display: block; width: 100% !important; border: 0 !important; background: none !important; resize: none;
    padding: 1mm 0 0 !important; font: inherit !important; font-size: 10pt !important; color: #000 !important; overflow: visible;
  }

  /* Footnotes at the end. */
  .body-preview .footnotes { margin-top: 8mm !important; padding-top: 3mm !important; border-top: .6pt solid #999 !important; font-size: 9pt !important; color: #000 !important; break-inside: auto; }
  .body-preview .footnotes .fn-back { display: none !important; }
  .body-preview .fn-ref a { text-decoration: none; }

  hr, .body-preview .markdown-divider { border: 0; border-top: .6pt solid #999; }
}
