:root {
    --bg: #eff4fa;
    --panel: #ffffff;
    --panel-soft: #f7fbff;
    --text: #172534;
    --muted: #61758a;
    --line: #dbe5ef;
    --primary: #0c5ea5;
    --primary-2: #2f89df;
    --shadow: 0 8px 22px rgba(22, 37, 52, 0.06);
    --radius: 18px;
    --radius-sm: 14px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body {
    margin: 0;
    background: linear-gradient(180deg, #f7fbff 0%, var(--bg) 100%);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 16px;
}
.hero {
    display: block;
    padding: 22px 24px;
    border-radius: 22px;
    background: linear-gradient(135deg, #0b4e8a 0%, #156dc0 55%, #4097ec 100%);
    color: #fff;
    box-shadow: var(--shadow);
}
.eyebrow {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,.14);
    margin-bottom: 10px;
}
.hero h1 { margin: 0 0 8px; font-size: 28px; line-height: 1.1; }
.hero p { margin: 0; max-width: 980px; line-height: 1.45; color: rgba(255,255,255,.95); }
.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.block { margin-top: 12px; padding: 12px; }
.slim-block { padding-top: 12px; }
.filters { margin-top: 14px; padding: 14px; }
.filters-grid {
    display: grid;
    grid-template-columns: 170px minmax(230px,1.2fr) 120px minmax(220px,1fr) 160px 160px 150px;
    gap: 10px;
    align-items: end;
}
.field label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
}
.field select,
.field button,
.toolbar-link {
    width: 100%;
    min-height: 40px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    padding: 9px 11px;
    font-size: 13px;
}
.field button,
.toolbar-link {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border: none;
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}
.secondary-action {
    background: #ffffff !important;
    color: var(--primary) !important;
    border: 1px solid #9ec3e7 !important;
}
.secondary-action:hover,
.toolbar-link:hover,
.field button:hover { filter: brightness(.98); }
.meta { margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.error {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid #efc7c7;
    background: #fff4f4;
    color: #a22020;
    font-size: 13px;
}
.cards { display: grid; gap: 10px; }
.cards-summary {
    margin-top: 14px;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
}
.components-grid { grid-template-columns: repeat(5, minmax(160px, 1fr)); }
.demais-cards-grid { grid-template-columns: repeat(4, minmax(180px, 1fr)); margin-top: 8px; }
.card {
    position: relative;
    overflow: hidden;
    padding: 10px 11px 10px 13px;
    border-radius: 11px;
    background: linear-gradient(180deg, #ffffff, var(--panel-soft));
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
}
.card::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    background: linear-gradient(180deg, var(--primary), var(--primary-2));
    opacity: .8;
}
.card .title {
    font-size: 11px;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 6px;
    line-height: 1.2;
}
.card .value {
    font-size: clamp(17px, 1.45cqw, 22px);
    font-weight: 800;
    line-height: 1.08;
    white-space: nowrap;
}
.card .value-muted {
    font-size: 17px;
    color: var(--muted);
    line-height: 1.25;
}
.card .sub { margin-top: 5px; font-size: 10px; color: var(--muted); line-height: 1.25; }
.metric-card {
    min-height: 98px;
    container-type: inline-size;
}
@container (max-width: 220px) {
    .metric-card .value { font-size: 20px; }
}
@container (max-width: 185px) {
    .metric-card .value { font-size: 18px; }
}
.component-card, .demais-card {
    min-height: 104px;
    container-type: inline-size;
}
.component-meta {
    margin-top: 7px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px 5px;
    font-size: 9px;
    color: var(--muted);
}
.component-meta span {
    display: inline-flex;
    gap: 3px;
    padding: 2px 5px;
    border-radius: 999px;
    background: #edf6ff;
    border: 1px solid var(--line);
}
@container (max-width: 190px) {
    .component-card .value,
    .demais-card .value { font-size: 17px; }
    .component-meta { font-size: 8px; }
}
.block-head { margin-bottom: 10px; }
.section-title { margin: 0 0 4px; font-size: 17px; }
.table-subtitle { margin-top: 16px; }
.section-desc { margin: 0 0 10px; font-size: 12px; color: var(--muted); line-height: 1.45; }
.section-grid {
    display: grid;
    grid-template-columns: 1.08fr .92fr;
    gap: 12px;
    margin-top: 14px;
}
.section-grid-equal { grid-template-columns: 1fr 1fr; }
.charts-three-grid { grid-template-columns: repeat(3, minmax(260px, 1fr)); }
.section-grid.parcelas-wide { grid-template-columns: minmax(0, 1fr); }
.parcelas-wide .canvas-wrap { height: 300px; }
.production-panel { margin-top: 14px; padding: 14px; min-width: 0; }
.production-panel p { font-size: 12px; line-height: 1.5; }
.production-status { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; font-size: 12px; }
.production-status progress { width: 180px; max-width: 100%; accent-color: #1976c9; }
.production-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 12px 0; font-size: 12px; }
.production-controls select { padding: 8px; max-width: 100%; }
.production-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 12px 0; }
.production-summary > div { display: flex; flex-direction: column; gap: 6px; border-left: 3px solid #a76316; padding: 8px; background: #fff9eb; font-size: 12px; }
.production-summary strong { font-size: 18px; }
.production-table-wrap { overflow-x: auto; margin: 12px 0; }
.production-table-wrap table { width: 100%; min-width: 620px; }
.production-table-wrap td { white-space: normal; overflow-wrap: anywhere; }
.production-alert { background: #fffbf1; }
.production-off-page { display: none; }
.production-table-wrap td.production-cns { white-space: nowrap; font-variant-numeric: tabular-nums; }
.production-pagination { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 12px; color: var(--muted); }
.production-pagination[hidden] { display: none; }
.production-page-actions { display: flex; align-items: center; gap: 8px; }
.production-page-actions select { padding: 6px; border: 1px solid var(--line); border-radius: 4px; background: white; }
.production-page-actions button { width: 32px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: white; color: #1976c9; font-size: 24px; cursor: pointer; }
.production-page-actions button:disabled { opacity: .4; cursor: default; }
.production-page-actions button:hover:not(:disabled) { background: #edf5fc; }
.production-page-actions button:focus-visible { outline: 2px solid #1976c9; outline-offset: 2px; }
#productionPageNumber { min-width: 52px; text-align: center; font-variant-numeric: tabular-nums; }
#productionWarnings { color: #9b303a; }
@media (max-width: 600px) {
    .production-summary { grid-template-columns: 1fr; gap: 5px; }
    .parcelas-wide .canvas-wrap { height: 250px; }
}
.inner-grid { margin-top: 12px; }
.chart-panel, .table-panel { padding: 14px; }
.compact-panel { padding: 12px; }
.canvas-wrap { position: relative; height: 260px; }
.canvas-wrap.mini { height: 170px; }
.mini-charts-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(240px, 1fr));
    gap: 12px;
}
.mini-demais-grid { margin-top: 12px; }
.mini-chart-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 12px;
    background: linear-gradient(180deg, #ffffff, var(--panel-soft));
}
.mini-chart-head {
    display: flex;
    gap: 10px;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 8px;
}
.mini-chart-head h3 { margin: 0; font-size: 14px; line-height: 1.2; }
.mini-chart-head span { color: var(--muted); font-size: 12px; font-weight: 700; }
.table-wrap { overflow: auto; }
.table-gap { margin-top: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 920px; }
th, td {
    padding: 9px 8px;
    border-bottom: 1px solid #e8eef5;
    font-size: 12px;
    text-align: left;
    vertical-align: top;
}
th { position: sticky; top: 0; background: #fbfdff; z-index: 1; }
.muted { color: var(--muted); font-size: 11px; }
.subsection-head h3 {
    margin: 0 0 3px;
    font-size: 14px;
}
.subsection-head p {
    margin: 0 0 8px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}
.subsection-head-spaced { margin-top: 16px; }
.diagnostic-panel {
    border-color: #cbd9e7;
    background: linear-gradient(180deg, #ffffff, #f8fbff);
}
.diagnostic-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}
.diagnostic-card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 13px;
    background: #fff;
}
.diagnostic-card span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    margin-bottom: 8px;
}
.diagnostic-card strong {
    display: block;
    font-size: 22px;
    line-height: 1.1;
}
.diagnostic-card small {
    display: block;
    margin-top: 8px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.35;
}
.diagnostic-card.loss {
    border-color: #f0b9b9;
    background: #fff7f7;
}
.diagnostic-card.loss strong { color: #ad1f1f; }
.diagnostic-card.gain {
    border-color: #a8d5bc;
    background: #f4fff8;
}
.diagnostic-card.gain strong { color: #0f7a3b; }
.diagnostic-card.neutral strong { color: var(--text); }
.diagnostic-table-wrap { max-height: 340px; }
.diagnostic-table .movement-loss td { background: #fff8f8; }
.diagnostic-table .movement-gain td { background: #f6fff9; }
.variation-badge {
    display: inline-flex;
    min-width: 58px;
    justify-content: center;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 800;
}
.variation-badge.loss {
    background: #f9dede;
    color: #9f1d1d;
}
.variation-badge.gain {
    background: #dff5e8;
    color: #0d6b35;
}
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }
.mini-tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 7px;
    border-radius: 999px;
    background: #edf6ff;
    border: 1px solid var(--line);
    font-size: 11px;
}
.empty-box {
    padding: 14px;
    border-radius: 14px;
    border: 1px dashed var(--line);
    background: #fbfdff;
    color: var(--muted);
    font-size: 12px;
}
.footer-note { margin: 14px 0 18px; color: var(--muted); font-size: 11px; }
.report-cover {
    display: none;
    margin-top: 14px;
    padding: 18px 20px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: linear-gradient(135deg, #0b4e8a, #2f89df);
    color: #fff;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-end;
}
.report-cover h2 {
    margin: 6px 0;
    font-size: 22px;
}
.report-cover p { margin: 0; color: rgba(255,255,255,.92); }
.report-stamp {
    min-width: 170px;
    text-align: right;
    font-size: 12px;
}
.report-stamp span {
    display: block;
    color: rgba(255,255,255,.78);
    margin-bottom: 4px;
}
.report-stamp strong { font-size: 15px; }
canvas { width: 100% !important; height: 100% !important; }
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(239, 244, 250, 0.84);
    backdrop-filter: blur(5px);
}
.loading-overlay.is-active { display: flex; }
.loading-dialog {
    width: min(520px, 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 18px 50px rgba(22, 37, 52, 0.18);
    padding: 18px;
}
.loading-topline {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
}
.loading-title {
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
}
.loading-step {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}
.loading-percent {
    min-width: 54px;
    text-align: right;
    font-size: 22px;
    line-height: 1;
    font-weight: 800;
    color: var(--primary);
}
.loading-bar {
    position: relative;
    overflow: hidden;
    height: 10px;
    margin-top: 16px;
    border-radius: 999px;
    background: #dce9f5;
}
.loading-bar-fill {
    width: 0%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--primary), var(--primary-2));
    transition: width .35s ease;
}
.loading-bar-fill::after {
    content: "";
    display: block;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.55), transparent);
    animation: loading-shine 1.2s linear infinite;
}
.loading-detail {
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.45;
}
.loading-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
    color: #7a8da1;
    font-size: 11px;
}
.loading-overlay.is-waiting .loading-bar-fill {
    width: 100% !important;
    animation: loading-pulse 1.4s ease-in-out infinite;
}
.is-loading-page {
    cursor: progress;
}

@keyframes loading-shine {
    from { transform: translateX(-100%); }
    to { transform: translateX(100%); }
}

@keyframes loading-pulse {
    0%, 100% { opacity: .72; }
    50% { opacity: 1; }
}

@media (max-width: 1250px) {
    .filters-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
    .cards-summary { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
    .components-grid { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
    .diagnostic-summary { grid-template-columns: repeat(2, minmax(180px, 1fr)); }
    .demais-cards-grid, .mini-charts-grid { grid-template-columns: repeat(2, minmax(190px, 1fr)); }
}

@media print {
    @page {
        size: A4 landscape;
        margin: 7mm;
    }
    html { font-size: 11px; }
    body {
        background: #fff !important;
        color: #111827;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .container {
        max-width: none;
        padding: 0;
    }
    .hero,
    .filters,
    .footer-note,
    .loading-overlay { display: none !important; }
    .report-cover { display: flex; }
    .report-cover {
        margin-top: 0;
        padding: 10px 12px;
        border-radius: 12px;
    }
    .report-cover .eyebrow {
        font-size: 9px;
        padding: 3px 6px;
        margin-bottom: 4px;
    }
    .report-cover h2 {
        margin: 3px 0;
        font-size: 16px;
    }
    .report-cover p,
    .report-stamp { font-size: 10px; }
    .report-stamp strong { font-size: 12px; }
    .panel,
    .card,
    .mini-chart-card {
        box-shadow: none;
    }
    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    .chart-panel,
    .mini-chart-card,
    .table-panel {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    .components-panel {
        break-inside: auto;
        page-break-inside: auto;
    }
    .diagnostic-panel,
    .cards-summary,
    .components-grid,
    .demais-cards-grid {
        break-inside: auto;
        page-break-inside: auto;
        align-items: start;
    }
    .block,
    .section-grid,
    .cards-summary { margin-top: 8px; }
    .cards-summary {
        grid-template-columns: repeat(5, 1fr);
        gap: 5px;
    }
    .components-grid,
    .demais-cards-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 5px;
    }
    .charts-three-grid { grid-template-columns: repeat(3, 1fr); }
    .section-grid.parcelas-wide { grid-template-columns: minmax(0, 1fr); }
    .parcelas-wide .canvas-wrap { height: 160px; }
    .production-panel { break-inside: auto !important; page-break-inside: auto !important; }
    .production-controls, .production-status progress { display: none !important; }
    .production-pagination { display: none !important; }
    .production-off-page { display: table-row !important; }
    .production-table-wrap td.production-cns { font-size: 7px; }
    .production-summary { grid-template-columns: repeat(3, 1fr); break-inside: avoid; }
    .production-table-wrap { overflow: visible !important; max-height: none !important; height: auto !important; }
    .production-table-wrap table { min-width: 0; table-layout: fixed; }
    .production-panel .canvas-wrap { height: 160px; break-inside: avoid; }
    .production-table-wrap tr { break-inside: avoid; page-break-inside: avoid; }
    .section-grid-equal { grid-template-columns: repeat(2, 1fr); }
    .mini-charts-grid { grid-template-columns: repeat(3, 1fr); }
    .chart-panel,
    .table-panel,
    .block { padding: 7px; }
    .panel { border-radius: 10px; }
    .card {
        overflow: visible;
        padding: 5px 6px 5px 8px;
        border-radius: 8px;
        height: auto;
        min-height: 58px !important;
        display: flex;
        flex-direction: column;
    }
    .card::before { width: 2px; }
    .card .title {
        font-size: 7.5px;
        margin-bottom: 2px;
        line-height: 1.15;
        min-height: 17px;
        max-height: 17px;
        overflow: hidden;
    }
    .card .value {
        font-size: 12px;
        line-height: 1.05;
        margin-top: 0;
    }
    .card .sub {
        font-size: 7.2px;
        margin-top: 2px;
        line-height: 1.15;
        min-height: 16px;
        max-height: 16px;
        overflow: hidden;
    }
    .metric-card,
    .component-card,
    .demais-card {
        height: 70px;
        min-height: 70px !important;
        max-height: 70px;
    }
    .metric-card {
        height: 52px;
        min-height: 52px !important;
        max-height: 52px;
    }
    .component-meta {
        margin-top: 3px;
        gap: 2px 3px;
        font-size: 6.6px;
        min-height: 22px;
        max-height: 22px;
        overflow: hidden;
        align-content: flex-start;
    }
    .component-meta span {
        padding: 1px 3px;
        line-height: 1.15;
        white-space: normal;
    }
    .block-head { margin-bottom: 5px; }
    .section-title {
        font-size: 12px;
        margin-bottom: 2px;
    }
    .section-desc {
        font-size: 9px;
        margin-bottom: 5px;
        line-height: 1.25;
    }
    .canvas-wrap { height: 165px; }
    .canvas-wrap.mini { height: 105px; }
    .diagnostic-summary {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
        margin-bottom: 6px;
    }
    .diagnostic-card {
        padding: 7px;
        border-radius: 9px;
    }
    .diagnostic-card span {
        font-size: 9px;
        margin-bottom: 4px;
    }
    .diagnostic-card strong {
        font-size: 15px;
    }
    .diagnostic-card small {
        margin-top: 4px;
        font-size: 8px;
        line-height: 1.2;
    }
    .diagnostic-table-wrap { max-height: none; }
    table { min-width: 0; }
    thead { display: table-header-group; }
    tr {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    th, td { font-size: 8px; padding: 4px; }
    .variation-badge {
        min-width: 42px;
        padding: 2px 5px;
        font-size: 8px;
    }
    .mini-chart-card { padding: 7px; border-radius: 9px; }
    .mini-chart-head { margin-bottom: 4px; }
    .mini-chart-head h3 { font-size: 10px; }
    .mini-chart-head span { font-size: 9px; }
}

@media (max-width: 900px) {
    .container { padding: 12px; }
    .hero { padding: 18px; }
    .hero h1 { font-size: 22px; }
    .filters-grid,
    .cards-summary,
    .diagnostic-summary,
    .components-grid,
    .demais-cards-grid,
    .section-grid,
    .charts-three-grid,
    .mini-charts-grid { grid-template-columns: 1fr; }
    .canvas-wrap { height: 240px; }
    .canvas-wrap.mini { height: 180px; }
}

.source-notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 12px 0 16px;
    padding: 12px 14px;
    border: 1px solid #dce3eb;
    border-radius: 6px;
    background: #f8fafc;
    color: #536174;
    font-size: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}
.source-notice-icon {
    flex: 0 0 17px;
    width: 17px;
    height: 17px;
    margin-top: 1px;
    border: 1px solid #8594a6;
    border-radius: 50%;
    text-align: center;
    font: 600 12px/16px Georgia, serif;
    color: #64748b;
}
.source-notice-content { min-width: 0; }
.source-notice-content strong { color: #354358; font-size: 12px; font-weight: 600; }
.source-notice-content p { margin: 3px 0 0; }
@media print {
    .source-notice { break-inside: avoid; page-break-inside: avoid; background: #fff; }
}
