/* ============================================
   MagicMenu Print Styles
   ============================================
   Optimized for recipe cards and shopping lists
   Target: Letter (8.5" x 11") and A4 paper
   ============================================ */

@media print {
    /* Reset and Base Styles */
    * {
        background: transparent !important;
        color: #000 !important;
        box-shadow: none !important;
        text-shadow: none !important;
    }
    
    body {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 12pt;
        line-height: 1.5;
        color: #000;
        background: #fff;
        margin: 0;
        padding: 0;
    }
    
    /* Typography Scale for Print */
    h1 {
        font-size: 16pt;
        margin-bottom: 6pt;
        page-break-after: avoid;
    }

    h2 {
        font-size: 14pt;
        margin-top: 10pt;
        margin-bottom: 4pt;
        page-break-after: avoid;
    }

    h3 {
        font-size: 12pt;
        margin-top: 8pt;
        margin-bottom: 4pt;
        page-break-after: avoid;
    }

    h4, h5, h6 {
        font-size: 10pt;
        font-weight: bold;
        page-break-after: avoid;
    }

    p, li {
        font-size: 9pt;
        margin-bottom: 3pt;
    }
    
    /* Hide Non-Essential Elements */
    .navbar,
    .nav,
    .navigation,
    .sidebar,
    .footer,
    footer,
    .btn,
    .button,
    .alert,
    .badge,
    .breadcrumb,
    .pagination,
    .no-print,
    .toast,
    .modal,
    .dropdown,
    .form-control,
    .form-select,
    button,
    input[type="submit"],
    input[type="button"],
    [role="navigation"],
    [aria-label*="navigation"],
    .bi-printer,
    .bi-arrow-left,
    .htmx-indicator,
    .progress,
    .custom-item-form,
    .item-actions,
    #toast-container {
        display: none !important;
    }
    
    /* Links - Show URL for external links */
    a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        font-style: italic;
    }
    
    /* Internal links - just underline */
    a {
        text-decoration: underline;
        color: #000 !important;
    }
    
    /* Page Layout */
    .container,
    .container-fluid {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    
    /* ============================================
       Recipe Print Styles
       ============================================ */
    
    /* Recipe Header */
    .recipe-header {
        border-bottom: 3pt solid #000;
        padding-bottom: 12pt;
        margin-bottom: 18pt;
    }
    
    .recipe-title {
        font-size: 24pt;
        font-weight: bold;
        margin-bottom: 8pt;
    }
    
    .recipe-meta {
        font-size: 10pt;
        color: #333;
        display: flex;
        gap: 2em;
        flex-wrap: wrap;
    }
    
    .recipe-meta-item {
        white-space: nowrap;
    }
    
    /* Nutrition Facts Box */
    .nutrition-facts {
        border: 2pt solid #000;
        padding: 8pt;
        margin: 12pt 0;
        page-break-inside: avoid;
        max-width: 300pt;
    }
    
    .nutrition-facts h3 {
        font-size: 14pt;
        margin: 0 0 6pt 0;
        border-bottom: 1pt solid #000;
        padding-bottom: 4pt;
    }
    
    .nutrition-fact {
        display: flex;
        justify-content: space-between;
        padding: 2pt 0;
        border-bottom: 0.5pt solid #ccc;
    }
    
    .nutrition-fact:last-child {
        border-bottom: none;
    }
    
    /* Ingredients Section */
    .ingredients-section {
        page-break-inside: avoid;
        margin-bottom: 18pt;
    }
    
    .ingredient-group {
        margin-bottom: 12pt;
    }
    
    .ingredient-item {
        margin-bottom: 4pt;
        padding-left: 18pt;
        position: relative;
    }
    
    .ingredient-item::before {
        content: "□";
        position: absolute;
        left: 0;
        font-size: 14pt;
        line-height: 1;
    }
    
    /* Instructions Section */
    .instructions-section {
        page-break-inside: avoid;
    }
    
    .instruction-step {
        margin-bottom: 12pt;
        padding-left: 24pt;
        position: relative;
        page-break-inside: avoid;
    }
    
    .instruction-step-number {
        position: absolute;
        left: 0;
        font-weight: bold;
        font-size: 14pt;
    }
    
    /* Recipe Notes */
    .recipe-notes {
        border: 1pt solid #666;
        padding: 8pt;
        margin-top: 18pt;
        font-style: italic;
        page-break-inside: avoid;
    }
    
    /* ============================================
       Shopping List Print Styles
       Two-column compact layout organized by section
       ============================================ */

    /* Shopping List Header */
    .shopping-list-header {
        border-bottom: 2pt solid #000;
        padding-bottom: 6pt;
        margin-bottom: 10pt;
    }

    .shopping-list-title {
        font-size: 16pt;
        font-weight: bold;
    }

    .shopping-list-meta {
        font-size: 9pt;
        color: #333;
        margin-top: 2pt;
    }

    /* Shopping Sections - compact layout */
    .shopping-section {
        margin-bottom: 10pt;
        page-break-inside: avoid;
    }

    .section-header {
        font-size: 11pt;
        font-weight: bold;
        border-bottom: 1pt solid #000;
        padding: 2pt 0 2pt 0;
        margin-bottom: 4pt;
        background: none !important;
        cursor: default !important;
    }

    /* Hide collapse indicators and section icons in print */
    .section-header i:last-child,
    .section-header .section-icon {
        display: none !important;
    }

    /* Hide badge counts in print */
    .section-header .badge {
        display: none !important;
    }

    /* Always show items when printing */
    .section-items {
        display: block !important;
    }

    /* Two-column layout for shopping items */
    .section-items {
        column-count: 2;
        column-gap: 16pt;
        column-rule: 1pt solid #ddd;
    }

    /* Shopping Items - compact */
    .shopping-item {
        padding: 1pt 0;
        display: flex;
        align-items: center;
        page-break-inside: avoid;
        break-inside: avoid;
        border-bottom: none;
        font-size: 9pt;
        line-height: 1.3;
    }

    .shopping-item:last-child {
        border-bottom: none;
    }

    .item-checkbox {
        width: 8pt;
        height: 8pt;
        border: 1pt solid #000;
        margin-right: 4pt;
        flex-shrink: 0;
        -webkit-appearance: none;
        appearance: none;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .item-checkbox:checked {
        background: #000 !important;
        position: relative;
    }

    .item-checkbox:checked::after {
        content: "✓";
        position: absolute;
        color: #fff;
        font-size: 6pt;
        top: -1pt;
        left: 0pt;
    }

    .item-details {
        flex: 1;
        display: flex;
        align-items: baseline;
        gap: 4pt;
    }

    .item-name {
        font-weight: normal;
        font-size: 9pt;
        margin-bottom: 0;
    }

    .item-quantity {
        font-size: 8pt;
        color: #666;
    }

    /* Menu Details Shopping List - Grouped by section */
    .shopping-list-grouped {
        display: block;
    }

    .shopping-section-group {
        margin-bottom: 8pt;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .section-header-print {
        font-size: 10pt !important;
        font-weight: bold !important;
        margin: 0 0 3pt 0 !important;
        padding: 0 0 2pt 0 !important;
        border-bottom: 1pt solid #000 !important;
    }

    /* Two-column grid for items within each section */
    .section-items-print {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 1pt 12pt;
        padding: 0 !important;
        margin: 0 !important;
        align-items: start;
    }

    .section-items-print .list-group-item {
        padding: 1pt 0 !important;
        font-size: 8pt !important;
        line-height: 1.3 !important;
        break-inside: avoid;
        page-break-inside: avoid;
        border: none !important;
        margin: 0 !important;
        align-self: start;
    }

    .section-items-print .list-group-item .d-flex {
        gap: 3pt !important;
        align-items: flex-start !important;
    }

    /* Hide the actual checkbox and use a custom square */
    .section-items-print .list-group-item .form-check-input {
        display: none !important;
    }

    /* Add a custom checkbox square before each item */
    .section-items-print .list-group-item .d-flex::before {
        content: "";
        display: inline-block;
        width: 8pt;
        height: 8pt;
        min-width: 8pt;
        min-height: 8pt;
        max-width: 8pt;
        max-height: 8pt;
        border: 1pt solid #000;
        margin-right: 4pt;
        margin-top: 1pt;
        flex-shrink: 0;
        box-sizing: border-box;
    }

    /* Hide badges in print */
    .no-print {
        display: none !important;
    }

    /* ============================================
       Menu Details Page - Compact Layout
       ============================================ */

    /* Page header - compact */
    .d-flex.justify-content-between.align-items-center.mb-4 h1 {
        font-size: 14pt !important;
        margin-bottom: 0 !important;
    }

    /* Menu info card - compact */
    .card.mb-4 .card-body {
        padding: 6pt !important;
    }

    .card.mb-4 .card-body p {
        font-size: 8pt !important;
        margin-bottom: 2pt !important;
        line-height: 1.3 !important;
    }

    .card.mb-4 .card-body strong {
        font-size: 8pt !important;
    }

    /* AI Summary - compact */
    .card.mb-4 .card-body .mt-3 h5 {
        font-size: 9pt !important;
        margin-bottom: 3pt !important;
    }

    .card.mb-4 .card-body .mt-3 pre {
        font-size: 7pt !important;
        line-height: 1.2 !important;
        padding: 4pt !important;
        margin: 0 !important;
    }

    /* Card headers - compact */
    .card-header {
        padding: 4pt 8pt !important;
    }

    .card-header h3 {
        font-size: 10pt !important;
        margin: 0 !important;
    }

    /* Weekly menu table - compact */
    .table-responsive {
        margin: 0 !important;
    }

    .table {
        font-size: 8pt !important;
        margin-bottom: 0 !important;
    }

    .table th {
        font-size: 8pt !important;
        padding: 3pt 4pt !important;
        font-weight: bold;
    }

    .table td {
        font-size: 7pt !important;
        padding: 3pt 4pt !important;
        vertical-align: top;
    }

    .table td strong {
        font-size: 7pt !important;
    }

    /* Recipe links in table */
    .table td a {
        font-size: 7pt !important;
        text-decoration: none !important;
    }

    .table td a strong {
        font-size: 7pt !important;
    }

    /* Recipe meta info in table - smaller */
    .table td .small,
    .table td .text-muted {
        font-size: 6pt !important;
        line-height: 1.2 !important;
    }

    /* Hide icons in table to save space */
    .table td .bi {
        display: none !important;
    }

    /* Compact meal entries */
    .table td .mb-2 {
        margin-bottom: 2pt !important;
    }

    /* ============================================
       Shopping List - Page Break
       ============================================ */

    /* Force shopping list to start on new page */
    .shopping-list-card {
        page-break-before: always !important;
        break-before: page !important;
        margin-top: 0 !important;
    }

    /* ============================================
       Menu Calendar Print Styles
       ============================================ */

    .menu-calendar {
        page-break-before: auto;
    }

    .menu-day-column {
        border: 1pt solid #000;
        padding: 4pt;
        margin-bottom: 6pt;
        page-break-inside: avoid;
    }

    .menu-day-header {
        font-size: 10pt;
        font-weight: bold;
        border-bottom: 1pt solid #000;
        padding-bottom: 2pt;
        margin-bottom: 4pt;
    }

    .meal-card {
        border: 0.5pt solid #666;
        padding: 3pt;
        margin-bottom: 3pt;
        page-break-inside: avoid;
    }

    .meal-card-header {
        font-weight: bold;
        margin-bottom: 2pt;
        font-size: 8pt;
    }
    
    /* ============================================
       Page Breaks and Orphan Control
       ============================================ */
    
    /* Avoid breaking inside critical elements */
    .recipe-header,
    .ingredients-section,
    .nutrition-facts,
    .shopping-section,
    .menu-day-column {
        page-break-inside: avoid;
    }
    
    /* Keep headings with content */
    h1, h2, h3, h4, h5, h6 {
        page-break-after: avoid;
    }
    
    /* Avoid orphaned list items */
    ul, ol {
        page-break-inside: avoid;
    }
    
    li {
        page-break-inside: avoid;
        orphans: 2;
        widows: 2;
    }
    
    /* Start new page for each major section */
    .recipe-container {
        page-break-before: auto;
        page-break-after: auto;
    }
    
    /* ============================================
       Print Visibility Utilities
       ============================================ */

    /* Hide elements marked with print-hide */
    .print-hide {
        display: none !important;
    }

    /* Show elements marked with print-show */
    .print-show {
        display: block !important;
    }

    /* ============================================
       Recipe Print Styles (from menu details)
       ============================================ */

    .recipes-print-section {
        page-break-before: always !important;
        break-before: page !important;
    }

    .recipes-print-header {
        margin-bottom: 12pt;
        border-bottom: 2pt solid #000;
        padding-bottom: 6pt;
    }

    .recipes-print-header h2 {
        font-size: 14pt !important;
        margin: 0 !important;
    }

    .recipes-print-header .bi {
        display: none !important;
    }

    .recipe-print-card {
        border: 1pt solid #000;
        padding: 8pt;
        margin-bottom: 12pt;
        page-break-before: always;
        break-before: page;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Don't page break before the first recipe */
    .recipe-print-card:first-of-type {
        page-break-before: auto;
        break-before: auto;
    }

    .recipe-print-header-bar {
        border-bottom: 1pt solid #666;
        padding-bottom: 4pt;
        margin-bottom: 6pt;
        display: flex;
        justify-content: space-between;
        align-items: baseline;
    }

    .recipe-print-title {
        font-size: 12pt !important;
        font-weight: bold;
        margin: 0 !important;
    }

    .recipe-print-meta {
        font-size: 8pt;
        color: #666;
        font-style: italic;
    }

    .recipe-print-info {
        display: flex;
        gap: 12pt;
        font-size: 8pt;
        margin-bottom: 8pt;
        padding: 4pt;
        background-color: #f5f5f5 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .recipe-print-info span {
        white-space: nowrap;
    }

    .recipe-print-content {
        display: grid;
        grid-template-columns: 1fr 2fr;
        gap: 12pt;
    }

    .recipe-print-ingredients h4,
    .recipe-print-instructions h4 {
        font-size: 10pt !important;
        font-weight: bold;
        margin: 0 0 4pt 0 !important;
        border-bottom: 0.5pt solid #ccc;
        padding-bottom: 2pt;
    }

    .recipe-print-ingredients ul {
        margin: 0;
        padding-left: 14pt;
        font-size: 8pt;
        line-height: 1.4;
    }

    .recipe-print-ingredients li {
        margin-bottom: 2pt;
    }

    .recipe-print-instructions ol {
        margin: 0;
        padding-left: 16pt;
        font-size: 8pt;
        line-height: 1.4;
    }

    .recipe-print-instructions li {
        margin-bottom: 4pt;
    }

    .recipe-print-description {
        margin-top: 6pt;
        padding-top: 4pt;
        border-top: 0.5pt solid #ccc;
        font-size: 8pt;
        font-style: italic;
    }

    .recipe-print-description p {
        margin: 0;
    }

    /* ============================================
       Recipe Tips Print Styles
       ============================================ */

    .recipe-print-tips {
        margin-top: 8pt;
        padding-top: 6pt;
        border-top: 0.5pt solid #ccc;
        page-break-inside: avoid;
    }

    .recipe-print-tips h4 {
        font-size: 9pt !important;
        font-weight: bold;
        margin: 0 0 4pt 0 !important;
    }

    .recipe-print-tips p {
        font-size: 8pt;
        line-height: 1.4;
        margin: 0;
    }

    .recipe-print-tips.print-hide {
        display: none !important;
    }

    /* ============================================
       Print-Specific Utilities
       ============================================ */

    /* Force background printing for important elements */
    .print-bg-light {
        background-color: #f0f0f0 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    .print-border {
        border: 1pt solid #000 !important;
    }

    /* Page numbers - browser will add these */
    @page {
        margin: 0.5in;
        size: letter portrait;
    }

    /* First page can have different margins */
    @page :first {
        margin-top: 0.5in;
    }
}