/* ui/reports.css */
/* Styles for grouped reports, analysis, charts, and print styles */

:root {
    --bg-card: #ffffff;
    --text-primary: #0b1220;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --accent: #06b6d4;
    --secondary-bg: #f1f5f9;
    --accent-hover: #0891b2;
}

/* Results Section Structure */
#results-section {
    margin-top: 24px;
}

#results-section h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 16px 0;
}

#results-section h3 {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 12px 0;
}

#results-section h4 {
    font-size: 16px;
    font-weight: 600;
    margin: 12px 0 8px 0;
}

/* Collapsible Content and Toggle Button */
.section-header-with-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.section-header-with-toggle h2 {
    margin: 0;
}

.toggle-btn {
    background: var(--accent);
    color: white;
    font-size: 13px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
}

.toggle-btn::before {
    content: "▼";
    transition: transform 0.3s ease;
}

.toggle-btn.expanded::before {
    transform: rotate(180deg);
}

.collapsible-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.4s ease;
}

.collapsible-content.expanded {
    max-height: 10000px;
}


/* Grouped Report Table Styles */
.grouped-report-table .detail-row {
    background: white;
}

.grouped-report-table .subtotal-row {
    background: #f8fafc;
    font-weight: 500;
}

.grouped-report-table .project-subtotal-separator {
    border-top: 2px solid var(--border-color);
}

.grouped-report-table tfoot {
    background: #f1f5f9;
    font-weight: 600;
    border-top: 3px solid var(--accent);
}

/* Main Charts (Grouped Report) */
#report-charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.chart-wrapper {
    background: white;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.chart-wrapper h4 {
    margin: 0 0 12px 0;
    text-align: center;
}

/* Analysis Section Styles */
.analysis-grid-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(450px, 1fr));
    gap: 20px;
    margin-top: 10px;
}

/* 3 small charts side-by-side */
.analysis-3-column-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); /* Force smaller min width to fit 3 */
    gap: 15px;
    margin-top: 10px;
    margin-bottom: 20px;
}

.analysis-chart-section {
    background: var(--bg-card);
    padding: 16px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    height: fit-content; 
}

/* Specific styling for small charts in 3-column layout */
.analysis-3-column-row .analysis-chart-section {
    padding: 10px;
}

.analysis-3-column-row .analysis-chart-section h4 {
    font-size: 14px;
    margin: 0 0 8px 0;
}

.analysis-3-column-row .analysis-summary-card .stat-value {
    font-size: 14px;
}

.analysis-stats-grid {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.analysis-summary-card {
    flex: 1;
    background: var(--secondary-bg);
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
}

.analysis-summary-card .stat-label {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 2px;
    text-transform: uppercase;
}

.analysis-summary-card .stat-value {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.analysis-chart-section .chart-wrapper {
    height: 300px; 
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0; 
    border: none; 
    background: none;
}

.analysis-3-column-row .chart-wrapper {
    height: 300px;
}

/* PRINT STYLES */

@media print {
    @page {
        size: A4 portrait;
        margin: 15mm;
    }

    body {
        background: white;
        padding: 0;
        font-size: 10pt;
    }

    .container {
        max-width: 100%;
    }

    /* Hide UI elements */
    .card:first-of-type,
    .tabs,
    .tab-content,
    .footer-note,
    .toolbar,
    button,
    #print-btn, 
    .table-controls,
    .control-row,
    .filter-input-wrapper,
    .column-filter-input,
    header p,
    #loading-overlay,
    .section-header-with-toggle { 
        display: none !important;
    }

    /* Show only results */
    #results-section {
        display: block !important;
    }

    header h1 {
        font-size: 18pt;
        margin-bottom: 10mm;
        text-align: center;
        page-break-after: avoid;
    }

    .card {
        box-shadow: none;
        border: none;
        padding: 0;
        margin-bottom: 8mm;
        page-break-inside: avoid;
    }

    h2, h3, h4 {
        page-break-after: avoid;
        margin-top: 5mm;
    }

    h2 {
        font-size: 14pt;
        border-bottom: 1pt solid #000;
        padding-bottom: 2mm;
    }

    h3 {
        font-size: 12pt;
        font-weight: 700; 
    }

    h4 {
        font-size: 11pt;
    }

    .table-scroll {
        max-height: none;
        overflow: visible;
        border: none;
    }

    table {
        page-break-inside: auto;
        font-size: 9pt;
        border-collapse: collapse;
        border: 1pt solid #000; 
    }

    /* General table cell definitions for clean look */
    th,
    td {
        padding: 1.5mm 3mm; 
        text-align: left;
        border-bottom: none; 
    }

    th {
        position: static;
        background: #e9ecef !important; 
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: normal;
        color: #000;
        font-size: 8.5pt;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    /* Hide Analysis and Interactive Table sections during print */
    #analysis-container,
    .card:has(#analysis-container),
    section:has(#processed-table-container),
    .card:has(#processed-table-container),
    #results-section > section:first-child,
    #results-section > section:nth-child(3), 
    .card:has(h3:contains("İxrac")) {
        display: none !important;
    }

    /* Ensure only grouped report is visible */
    section:has(#grouped-report-container) {
        display: block !important;
        margin-top: 0;
        padding-top: 0;
    }
    
    #grouped-report-container > div {
        margin-bottom: 0 !important;
    }


    /* Totals Summary block */
    .totals-summary {
        background: #f8f8f8 !important;
        border: 1pt solid #000;
        padding: 3mm;
        margin-bottom: 5mm;
        page-break-inside: avoid;
    }

    .totals-summary h4 {
        margin-top: 0;
        font-size: 10pt;
    }


    /* Charts layout (small and side by side) */
    #report-charts-container {
        display: flex !important;
        flex-direction: row;
        gap: 5mm;
        margin: 10mm 0;
        page-break-inside: avoid;
        max-height: 85mm;
    }

    .chart-wrapper {
        flex: 1;
        min-width: 45%;
        max-width: 50%;
        display: block !important;
        page-break-inside: avoid;
        border: 1pt solid #ccc;
        padding: 3mm;
        height: 75mm;
    }

    .chart-wrapper h4 {
        margin: 0 0 2mm 0;
        font-size: 9pt;
        text-align: center;
    }

    .chart-wrapper canvas {
        max-width: 100%;
        max-height: 60mm !important; 
        width: auto !important;
        height: 60mm !important;
    }

    /* Grouped Report Table specific borders and styling */
    .grouped-report-table {
        border: 1pt solid #000; 
    }

    .grouped-report-table th,
    .grouped-report-table td {
        border: 0.5pt solid #666; /* Internal lines */
    }

    .grouped-report-table .subtotal-row {
        background: #f0f0f0; 
    }

    .grouped-report-table .project-subtotal-separator {
        border-top: 1.5pt solid #000;
        font-weight: bold;
    }
    
    .grouped-report-table .project-subtotal-label {
        text-align: right;
    }

    .grouped-report-table tfoot {
        border-top: 2pt solid #000;
        font-weight: bold;
        font-size: 10pt;
    }

    .grouped-report-table tfoot td {
        border: 1pt solid #000 !important;
        background: #e9ecef !important;
    }
    
    /* Ensure amount columns are correctly aligned */
    .grouped-report-table td:nth-child(3),
    .grouped-report-table tfoot td:nth-child(3) {
        text-align: right !important;
    }

    /* Page numbers */
    @page {
        @bottom-right {
            content: counter(page) " / " counter(pages);
            font-size: 8pt;
            color: #444;
        }
    }
}