/**
 * Print stylesheet for tier analysis PDF export.
 * Uses browser's native print-to-PDF functionality.
 *
 * Note: .print-only is hidden on screen via app.css, shown here in print.
 */

@media print {
    /* Show print-only elements (hidden on screen via app.css) */
    .print-only {
        display: inline !important;
        visibility: visible !important;
    }
    /* ========================================
       HIDE NON-ESSENTIAL ELEMENTS
       ======================================== */

    /* Navigation and layout chrome */
    nav,
    aside,
    footer,
    .navbar,
    .sidebar,
    .no-print {
        display: none !important;
    }

    /* Interactive form elements */
    button[type="submit"],
    button[type="button"]:not(.print-trigger),
    .btn-primary,
    .btn-ghost,
    select,
    input[type="checkbox"],
    input[type="number"],
    input[type="text"],
    textarea,
    .dropdown {
        display: none !important;
    }

    /* Hide workflow visualization entirely - use multiple selectors for robustness */
    #tier-sse-workflow,
    #reanalyze-workflow,
    [sse-swap="workflow-progress"],
    .border.border-white\/10.bg-slate-900\/80,
    div:has(> .px-4.py-3.bg-slate-800\/50):has([x-data*="nodes"]) {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
    }

    /* Hide empty states - project tier list "No tiers yet" box */
    .empty-state,
    [class*="empty-state"],
    div.border.border-base-300\/60.bg-base-200.p-8.text-center {
        display: none !important;
        visibility: hidden !important;
        height: 0 !important;
        max-height: 0 !important;
        overflow: hidden !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Ensure AI-generated tier suggestions container is visible.
       Note: #tier-suggestions is now OUTSIDE the .no-print wrapper,
       so it will print correctly without needing specificity overrides. */
    #tier-suggestions,
    #tier-sse-tiers {
        display: block !important;
        visibility: visible !important;
    }

    /* Hide reanalysis progress/loading states */
    #reanalyze-progress,
    #reanalyze-error,
    #tier-sse-progress,
    #tier-sse-error,
    .htmx-request,
    .loading {
        display: none !important;
    }

    /* Hide empty SSE swap targets (only hide when empty, not when they have content) */
    [hx-ext="sse"] > div:empty,
    [sse-swap]:empty {
        display: none !important;
    }

    /* Ensure SSE content areas with content are visible in print */
    #tier-sse-tiers:not(:empty),
    #tier-sse-summary:not(:empty),
    #tier-sse-portfolio:not(:empty) {
        display: block !important;
    }

    /* Ensure reanalysis area content is visible but hide its SSE machinery */
    #tier-analysis-area {
        display: block !important;
    }
    #tier-analysis-area [hx-ext="sse"] {
        display: none !important;
    }

    /* ========================================
       LAYOUT ADJUSTMENTS
       ======================================== */

    /* Reset body styling for print */
    body {
        background: white !important;
        color: black !important;
        font-size: 11pt !important;
        line-height: 1.4 !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    /* Remove max-height constraints */
    .tier-analysis-container,
    .max-h-screen,
    .overflow-auto,
    .overflow-y-auto {
        max-height: none !important;
        overflow: visible !important;
    }

    /* Make content fill page width */
    .container,
    .max-w-7xl,
    .max-w-6xl,
    .max-w-4xl {
        max-width: 100% !important;
        padding: 0 !important;
    }

    /* Reset flex containers for print flow */
    .flex-1,
    .flex.min-h-screen {
        display: block !important;
    }

    /* ========================================
       CARD STYLING FOR PRINT
       ======================================== */

    .card,
    .bg-base-200,
    .bg-base-300,
    .bg-slate-800,
    .bg-slate-900 {
        background: white !important;
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        color: black !important;
    }

    /* Ensure text visibility */
    .text-base-content,
    .text-slate-200,
    .text-slate-300,
    .text-slate-400,
    .text-white,
    .text-gray-400 {
        color: #333 !important;
    }

    .text-muted,
    .text-soft {
        color: #666 !important;
    }

    /* ========================================
       PRESERVE SEMANTIC COLORS
       ======================================== */

    /* Success/healthy indicators */
    .text-emerald-400,
    .text-emerald-500,
    .text-green-400,
    .text-green-500,
    .bg-emerald-500\/10,
    .bg-green-500\/10 {
        color: #059669 !important;
        background: #d1fae5 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Warning indicators */
    .text-amber-400,
    .text-amber-500,
    .text-yellow-400,
    .text-yellow-500,
    .bg-amber-500\/10,
    .bg-yellow-500\/10 {
        color: #d97706 !important;
        background: #fef3c7 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Danger/risk indicators */
    .text-red-400,
    .text-red-500,
    .bg-red-500\/10 {
        color: #dc2626 !important;
        background: #fee2e2 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Info/opportunity indicators */
    .text-sky-400,
    .text-sky-500,
    .text-blue-400,
    .text-blue-500,
    .bg-sky-500\/10,
    .bg-blue-500\/10 {
        color: #0284c7 !important;
        background: #e0f2fe !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* ========================================
       PAGE BREAK CONTROL
       ======================================== */

    /* Prevent breaking inside important blocks */
    .tier-card,
    .insight-card,
    .key-insight,
    table,
    tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Force breaks before major sections */
    .business-summary-card,
    .portfolio-analysis-card {
        page-break-before: always !important;
        break-before: page !important;
    }

    /* ========================================
       TABLE STYLING
       ======================================== */

    table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    th,
    td {
        border: 1px solid #ddd !important;
        padding: 8px !important;
        text-align: left !important;
    }

    th {
        background: #f5f5f5 !important;
        font-weight: 600 !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* ========================================
       TIER CARD DISPLAY VALUES
       ======================================== */

    /* print-only elements are shown via the rule at top of file */
    .print-only-block {
        display: block !important;
        visibility: visible !important;
    }

    /* ========================================
       PRINT HEADER (optional)
       ======================================== */

    .print-header {
        display: block !important;
        text-align: center;
        margin-bottom: 20px;
        padding-bottom: 10px;
        border-bottom: 2px solid #333;
    }

    .print-header h1 {
        font-size: 18pt !important;
        margin: 0 0 5px 0 !important;
    }

    .print-header .print-date {
        font-size: 10pt !important;
        color: #666 !important;
    }

    /* ========================================
       LINK HANDLING
       ======================================== */

    a {
        color: #333 !important;
        text-decoration: underline !important;
    }

    /* Show URL after links (optional - can remove if too noisy) */
    /*
    a[href^="http"]:after {
        content: " (" attr(href) ")";
        font-size: 8pt;
        color: #666;
    }
    */
}
