/**
 * R-30: Print/PDF Export Stylesheet
 * Optimized for A4/Letter paper, professional 1-2 page layout
 */

@media print {
  /* === GLOBAL RESETS === */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }

  body {
    background: white !important;
    color: black !important;
    font-size: 11pt;
    line-height: 1.5;
    margin: 0;
    padding: 0;
  }

  /* === HIDE NON-PRINTABLE ELEMENTS === */
  header,
  [role="banner"],
  nav,
  footer,
  [role="contentinfo"],
  button,
  .tooltip,
  .popover,
  .dropdown,
  .sheet,
  .dialog,
  [role="dialog"],
  .toast,
  .sonner,
  .global-header,
  .sticky-toolbar,
  .root-search-drawer,
  .user-profile-menu,
  .favorite-pills,
  .compare-modal,
  .paywall-modal,
  .offline-banner,
  .keyboard-shortcuts-modal {
    display: none !important;
  }

  /* === SHOW PRINTABLE CONTENT === */
  main,
  article,
  section {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  /* === PAGE SETUP === */
  @page {
    size: A4 portrait;
    margin: 1.5cm 2cm;
  }

  /* === ROOT PAGE LAYOUT === */
  .root-page-print-container {
    display: flex;
    flex-direction: column;
    gap: 12pt;
    width: 100%;
  }

  /* === ROOT HEADER === */
  .print-root-header {
    border-bottom: 2pt solid #000;
    padding-bottom: 8pt;
    margin-bottom: 12pt;
    page-break-after: avoid;
  }

  .print-root-header h1 {
    font-size: 24pt !important;
    font-weight: 700 !important;
    margin: 0 0 4pt 0 !important;
    color: #000 !important;
    direction: rtl;
  }

  .print-root-header .transliteration {
    font-size: 14pt;
    font-style: italic;
    color: #333;
    margin-bottom: 4pt;
  }

  .print-root-header .primary-meaning {
    font-size: 12pt;
    color: #000;
    font-weight: 600;
  }

  /* === PATTERN LEGEND === */
  .pattern-legend {
    border: 1pt solid #ccc;
    padding: 8pt;
    background: #f5f5f5;
    page-break-inside: avoid;
    margin-bottom: 12pt;
  }

  .pattern-legend h2 {
    font-size: 14pt !important;
    margin: 0 0 6pt 0 !important;
    font-weight: 600;
    color: #000;
  }

  .legend-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4pt;
  }

  .legend-item {
    font-size: 9pt;
    padding: 3pt 6pt;
    border: 1pt solid #ddd;
    background: white;
    page-break-inside: avoid;
  }

  .legend-item .binyan-name {
    font-weight: 700;
    font-size: 10pt;
  }

  .legend-item .pattern {
    font-style: italic;
    color: #555;
  }

  /* === MEANING FLOW BAR === */
  .meaning-flow-bar {
    page-break-inside: avoid;
    margin-bottom: 12pt;
  }

  .meaning-flow-bar h2 {
    font-size: 16pt !important;
    margin: 0 0 8pt 0 !important;
    font-weight: 600;
    color: #000;
  }

  .binyan-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100pt, 1fr));
    gap: 6pt;
  }

  .binyan-card {
    border: 1.5pt solid #333;
    padding: 6pt;
    page-break-inside: avoid;
    background: white;
  }

  .binyan-card h3 {
    font-size: 12pt !important;
    margin: 0 0 4pt 0 !important;
    font-weight: 700;
    color: #000;
  }

  .binyan-card .hebrew-form {
    font-size: 14pt !important;
    font-weight: 600;
    margin: 4pt 0;
    direction: rtl;
  }

  .binyan-card .meaning {
    font-size: 10pt;
    font-style: italic;
    color: #333;
    margin-top: 2pt;
  }

  /* === CONJUGATION TABLES === */
  .verb-grid {
    page-break-inside: avoid;
    margin-bottom: 12pt;
  }

  .verb-grid h2 {
    font-size: 16pt !important;
    margin: 0 0 8pt 0 !important;
    font-weight: 600;
    color: #000;
  }

  .conjugation-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 9pt;
    page-break-inside: avoid;
    margin-bottom: 8pt;
  }

  .conjugation-table th,
  .conjugation-table td {
    border: 1pt solid #666;
    padding: 4pt 6pt;
    text-align: center;
  }

  .conjugation-table th {
    background: #e0e0e0;
    font-weight: 700;
    font-size: 10pt;
    color: #000;
  }

  .conjugation-table .hebrew-text {
    font-size: 12pt !important;
    font-weight: 600;
    direction: rtl;
  }

  .conjugation-table .pronoun {
    font-weight: 600;
    background: #f5f5f5;
  }

  /* Sticky pronoun column - make static for print */
  .conjugation-table [data-sticky] {
    position: static !important;
    box-shadow: none !important;
  }

  /* === DERIVED FORMS === */
  .derived-nouns {
    page-break-inside: avoid;
    margin-bottom: 12pt;
  }

  .derived-nouns h2 {
    font-size: 16pt !important;
    margin: 0 0 8pt 0 !important;
    font-weight: 600;
    color: #000;
  }

  .derived-forms-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6pt;
  }

  .derived-form-card {
    border: 1pt solid #999;
    padding: 6pt;
    page-break-inside: avoid;
    background: white;
  }

  .derived-form-card .hebrew-text {
    font-size: 13pt !important;
    font-weight: 600;
    margin-bottom: 3pt;
    direction: rtl;
  }

  .derived-form-card .english-text {
    font-size: 9pt;
    font-style: italic;
    color: #555;
  }

  .derived-form-card .type {
    font-size: 8pt;
    color: #777;
    margin-top: 2pt;
  }

  /* === QR CODE SECTION === */
  .print-qr-code {
    display: flex !important;
    justify-content: flex-end;
    align-items: center;
    margin-top: 16pt;
    padding-top: 8pt;
    border-top: 1pt solid #ccc;
    gap: 8pt;
  }

  .print-qr-code canvas {
    width: 80pt !important;
    height: 80pt !important;
    border: 1pt solid #ccc;
  }

  .print-qr-code .url-text {
    font-size: 8pt;
    color: #666;
    font-family: monospace;
  }

  /* Hide QR code on screen, show in print */
  .print-qr-code {
    display: none;
  }

  @media print {
    .print-qr-code {
      display: flex !important;
    }
  }

  /* === PAGE BREAKS === */
  .page-break-before {
    page-break-before: always;
  }

  .page-break-after {
    page-break-after: always;
  }

  .page-break-inside-avoid {
    page-break-inside: avoid;
  }

  /* Prevent orphans/widows */
  p,
  li,
  .binyan-card,
  .derived-form-card,
  .legend-item {
    orphans: 3;
    widows: 3;
  }

  /* === TYPOGRAPHY === */
  /* Hebrew text */
  [dir="rtl"],
  .hebrew-base,
  .hebrew-form,
  .hebrew-text,
  [lang="he"] {
    font-family: "Frank Ruehl Libre", "Taamey Frank CLM", serif !important;
    direction: rtl;
    font-weight: 600;
  }

  /* English text */
  .latin-base,
  .english-text,
  .text-label {
    font-family: "Inter", "Arial", sans-serif !important;
    direction: ltr;
  }

  /* === COLOR MANAGEMENT === */
  /* Preserve binyan colors for print */
  .binyan-paal {
    color: #C55A00 !important;
  }

  .binyan-piel {
    color: #8B6500 !important;
  }

  .binyan-hifil {
    color: #A65600 !important;
  }

  .binyan-hitpael {
    color: #5A1A8F !important;
  }

  .binyan-nifal {
    color: #007B6E !important;
  }

  .binyan-pual {
    color: #005A99 !important;
  }

  .binyan-hufal {
    color: #1F6B7A !important;
  }

  /* Vowel colors (slightly darker for print) */
  .vowel-a {
    color: #CC0000 !important;
  }

  .vowel-e {
    color: #008855 !important;
  }

  .vowel-i {
    color: #6633CC !important;
  }

  .vowel-o {
    color: #CC5200 !important;
  }

  .vowel-u {
    color: #0055CC !important;
  }

  /* Grayscale mode - apply to body or root container */
  body.print-grayscale,
  .print-grayscale * {
    filter: grayscale(100%) contrast(1.2) !important;
  }

  /* === PERFORMANCE === */
  /* Remove background images (save ink) */
  * {
    background-image: none !important;
  }

  /* Simplify borders */
  * {
    border-radius: 0 !important;
  }

  /* === ACCESSIBILITY === */
  /* Ensure minimum contrast */
  a {
    color: #000 !important;
    text-decoration: underline !important;
  }

  /* Print URLs after links */
  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 8pt;
    color: #666;
  }

  /* Hide icon-only links URLs */
  a[aria-label]:after {
    content: "";
  }
}
