/* ===========================================================
   BiblioCPS - Folha de estilos dedicada aos relatorios.
   Mantida separada de 4-base.css para nao se misturar com o
   tema do app. Todas as classes comecam com .report-* ou
   .label-* para evitar colisao.
   =========================================================== */

/* ---------- Variaveis (fallback inline) ----------------------- */
:root {
    --rep-ink: #182230;
    --rep-text: #20242a;
    --rep-muted: #667085;
    --rep-line: #d7dce2;
    --rep-line-soft: #e6ebf1;
    --rep-bg: #ffffff;
    --rep-bg-alt: #f7f9fb;
    --rep-bg-zebra: #fbfcfd;
    --rep-bg-head: #f2f5f8;
    --rep-brand: #1f4e79;
    --rep-brand-soft: #eef3f8;
    --rep-accent: #b62f21;
    --rep-success: #027a48;
    --rep-warn: #b54708;
}

/* ---------- Casca do relatorio -------------------------------- */
.report-shell {
    margin: 0;
    padding: 28px 32px;
    border: 1px solid var(--rep-line);
    border-radius: 4px;
    background: var(--rep-bg);
    color: var(--rep-text);
    font: 13px/1.5 "Segoe UI", Arial, Helvetica, sans-serif;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.04);
}

/* ---------- Cabecalho institucional --------------------------- */
.report-header {
    display: table;
    width: 100%;
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 3px solid var(--rep-brand);
}
.report-header > .report-id {
    display: table-cell;
    vertical-align: bottom;
    padding-right: 16px;
}
.report-header > .report-meta {
    display: table-cell;
    vertical-align: bottom;
    width: 32%;
    min-width: 220px;
    padding-left: 12px;
    text-align: right;
    color: var(--rep-muted);
    font-size: 11px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}
.report-header .report-eyebrow {
    display: block;
    margin-bottom: 4px;
    color: var(--rep-muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.report-header h4 {
    margin: 0;
    color: var(--rep-ink);
    font-size: 24px;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: -0.005em;
}
.report-header p {
    margin: 6px 0 0;
    color: var(--rep-muted);
    font-size: 13px;
    line-height: 1.4;
}
.report-header .report-meta strong {
    display: block;
    color: var(--rep-ink);
    font-weight: 700;
}
.report-header .report-meta span {
    display: block;
    color: var(--rep-muted);
}
.report-header .report-meta time {
    display: block;
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

/* ---------- Chips de filtros aplicados ----------------------- */
.report-filters {
    display: block;
    margin: 14px 0 0;
    padding: 0;
    list-style: none;
}
.report-filters li {
    display: inline-block;
    margin: 0 6px 6px 0;
    padding: 4px 10px;
    border: 1px solid var(--rep-line);
    border-radius: 12px;
    background: var(--rep-bg-alt);
    font-size: 11px;
    line-height: 1.4;
}
.report-filters li span {
    color: var(--rep-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.report-filters li strong {
    margin-left: 6px;
    color: var(--rep-ink);
    font-weight: 700;
}

/* Texto livre dentro de uma secao */
.report-text {
    margin: 0;
    padding: 10px 14px;
    border: 1px solid var(--rep-line);
    border-top: 0;
    background: var(--rep-bg);
    color: var(--rep-text);
    font-size: 12px;
    line-height: 1.5;
}

/* ---------- KPI summary --------------------------------------- */
.report-summary {
    display: table;
    width: 100%;
    margin: 0 0 22px;
    border-collapse: separate;
    border-spacing: 10px 0;
    table-layout: fixed;
}
.report-summary > div {
    display: table-cell;
    padding: 12px 14px;
    border: 1px solid var(--rep-line);
    border-top: 3px solid var(--rep-brand);
    border-radius: 0 0 3px 3px;
    background: var(--rep-bg-alt);
    vertical-align: top;
}
.report-summary > div:first-child { margin-left: -10px; }
.report-summary span {
    display: block;
    min-height: 14px;
    color: var(--rep-muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.report-summary strong {
    display: block;
    margin-top: 6px;
    color: var(--rep-ink);
    font-size: 18px;
    line-height: 1.2;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ---------- Sections ------------------------------------------ */
.report-section {
    margin-bottom: 22px;
    page-break-inside: avoid;
}
.report-section > header {
    display: table;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #cfd6df;
    border-bottom: 0;
    background: var(--rep-brand-soft);
    box-sizing: border-box;
}
.report-section > header h5 {
    display: table-cell;
    margin: 0;
    color: var(--rep-ink);
    font-size: 13.5px;
    line-height: 20px;
    font-weight: 700;
    vertical-align: middle;
}
.report-count {
    display: table-cell;
    width: 64px;
    min-width: 48px;
    padding: 2px 10px;
    color: var(--rep-brand);
    text-align: right;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
}

/* ---------- Tables -------------------------------------------- */
.report-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.report-table th,
.report-table td {
    padding: 8px 10px;
    border: 1px solid var(--rep-line);
    vertical-align: top;
    word-wrap: break-word;
    line-height: 1.4;
}
.report-table th {
    background: var(--rep-bg-head);
    color: #344054;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.report-table tbody tr:nth-child(even) td { background: var(--rep-bg-zebra); }
.report-table tbody tr:hover td { background: #f0f4f8; }
.report-table td.numeric {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}
.report-table tfoot td {
    background: var(--rep-brand-soft);
    color: var(--rep-ink);
    font-weight: 700;
}
.report-table strong { font-weight: 700; }
.report-table em { font-style: italic; color: var(--rep-muted); }

.report-table-exemplares th:nth-child(1), .report-table-exemplares td:nth-child(1) { width: 8%; white-space: nowrap; }
.report-table-exemplares th:nth-child(2), .report-table-exemplares td:nth-child(2) { width: 7%; white-space: nowrap; }
.report-table-exemplares th:nth-child(3), .report-table-exemplares td:nth-child(3) { width: 10%; }
.report-table-exemplares th:nth-child(4), .report-table-exemplares td:nth-child(4) { width: 52%; }
.report-table-exemplares th:nth-child(5), .report-table-exemplares td:nth-child(5) { width: 23%; }

.report-table-bibliografia th:nth-child(1), .report-table-bibliografia td:nth-child(1) { width: 14%; }
.report-table-bibliografia th:nth-child(2), .report-table-bibliografia td:nth-child(2) { width: 8%; white-space: nowrap; }
.report-table-bibliografia th:nth-child(3), .report-table-bibliografia td:nth-child(3) { width: 10%; }
.report-table-bibliografia th:nth-child(4), .report-table-bibliografia td:nth-child(4) { width: 68%; }

.report-table-compact th, .report-table-compact td { padding: 6px 7px; font-size: 12px; }

/* ---------- Linha de cabecalho de secao embutida no thead ----- */
/* Quando a secao tem apenas uma tabela como conteudo, o titulo e
   embutido como primeira linha do <thead>. Isto torna a renderizacao
   imune a gaps entre titulo e cabecalho de colunas e faz o titulo
   se repetir em cada pagina junto com os cabecalhos de coluna. */

/* Defesa: garante zero margem/padding em containers de tabela.
   border-collapse ja deveria fazer isso, mas explicitar nao machuca. */
.report-table,
.report-table thead,
.report-table tbody,
.report-table tfoot,
.report-table tr {
    margin: 0 !important;
    border-spacing: 0 !important;
}

.report-table .report-section-row > th.report-section-cell {
    padding: 9px 12px;
    background: var(--rep-brand-soft);
    color: var(--rep-ink);
    text-transform: none;
    letter-spacing: 0;
    font-size: 13.5px;
    font-weight: 700;
    line-height: 1.25;
    border-color: #cfd6df;
}
.report-table .report-section-row .report-section-title {
    display: inline-block;
    margin: 0;
    padding: 0;
    color: var(--rep-ink);
    font-size: 13.5px;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0;
}
.report-table .report-section-row .report-count {
    display: inline-block;
    float: right;
    margin: 0;
    padding: 0;
    color: var(--rep-brand);
    text-align: right;
    font-size: 12px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-transform: none;
    letter-spacing: 0;
}

/* ---------- List & empty -------------------------------------- */
.report-list {
    margin: 0;
    padding: 12px 14px 12px 32px;
    border: 1px solid var(--rep-line);
    border-top: 0;
    background: var(--rep-bg);
    columns: 1;
}
.report-list li {
    margin: 0 0 8px;
    padding-left: 4px;
    line-height: 1.45;
    break-inside: avoid;
}
.report-list li:last-child { margin-bottom: 0; }
.report-empty,
.report-empty-cell {
    padding: 22px;
    border: 1px solid var(--rep-line);
    text-align: center;
    color: var(--rep-muted);
    background: var(--rep-bg-alt);
    font-style: italic;
}

/* ---------- Charts (placeholder visual) ----------------------- */
.report-chart {
    margin: 0;
    padding: 12px 14px;
    border: 1px solid var(--rep-line);
    border-top: 0;
    background: var(--rep-bg);
}
.report-chart-canvas {
    display: block;
    width: 100%;
    max-width: 100%;
    height: 280px;
}
.report-chart-legend {
    margin: 10px 0 0;
    padding: 0;
    list-style: none;
    text-align: center;
    font-size: 11px;
    color: var(--rep-muted);
}
.report-chart-legend li {
    display: inline-block;
    margin: 0 8px;
}
.report-chart-legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 5px;
    vertical-align: middle;
    border-radius: 2px;
}

/* ---------- Cabecalho do relatorio de etiquetas --------------- */
/* O header eh visivel em tela para o operador conferir o que vai
   imprimir (modelo, unidade, total de etiquetas/folhas) e fica
   oculto na impressao para nao deslocar as etiquetas da posicao
   exata da folha Pimaco. */
.label-report-header {
    margin-bottom: 14px;
    padding: 18px 18px 14px;
    border: 1px solid var(--rep-line);
    border-bottom: 3px solid var(--rep-brand);
    background: #fff;
    box-sizing: border-box;
}
.label-report .label-report-header + .label-pages > .label-sheet:first-child {
    /* Em tela, o primeiro sheet pode ficar mais perto do header.
       (Em impressao a margem original eh restaurada). */
    margin-top: 0.5cm;
}

/* ---------- Etiquetas Pimaco 6180 (3x10, 30 por folha Carta) -- */
/* Folha Carta retrato 21,59 x 27,94 cm.
   Etiqueta:        6,67 x 2,54 cm
   3 etiquetas x 6,67 + 2 gaps x 0,3175 + 2 margens x 0,4725 = 21,59 cm
   10 etiquetas x 2,54 + 2 margens x 1,27                    = 27,94 cm
   Layout calibrado para impressao em folha Pimaco 6180. */
.label-pages { display: block; }
.label-sheet {
    position: relative;
    display: block;
    width: 21.59cm;
    height: 27.94cm;
    margin: 0.5cm auto 0;
    padding: 0;
    box-sizing: border-box;
    background: #fff;
}
.label-sheet + .label-sheet {
    page-break-before: always;
    break-before: page;
}
.label-card {
    position: absolute;
    overflow: hidden;
    width: 6.66999cm;
    height: 2.54cm;
    margin: 0;
    padding: 0;
    border: 1px dashed #d0d0d0;
    box-sizing: border-box;
    page-break-inside: avoid;
    break-inside: avoid;
    font-family: Arial, Helvetica, sans-serif;
}
.label-tombo {
    position: absolute;
    top: 0.6425in;
    left: 0.04155in;
    width: 0.9in;
    height: 0.16in;
    overflow: hidden;
    text-align: center;
    font-size: 9pt;
    line-height: 0.16in;
    white-space: nowrap;
}
.label-class {
    position: absolute;
    top: 0.175in;
    left: 1.39in;
    width: 1.175in;
    height: 0.64in;
    overflow: hidden;
    text-align: center;
    font-size: 9pt;
    line-height: 1.05;
}
.label-class strong,
.label-class span {
    display: block;
    min-height: 0.14in;
    font-weight: 700;
}
.label-class span { font-weight: 400; }
.label-barcode {
    position: absolute;
    top: 0.2in;
    left: 0.2in;
    width: 0.6125in;
    height: 0.41472in;
    object-fit: fill;
}

/* ---------- Print / PDF do navegador -------------------------- */
@media print {
    /* Margem da pagina A4 com folga para a area nao-imprimivel
       da maioria das impressoras (5-10mm). Sem isso, caracteres
       no extremo direito podem ser comidos pelo cortecome. */
    @page { size: A4 portrait; margin: 1.2cm; }
    #menu, #header, #footer, #title-bar, #filters, #areaTombos { display: none !important; }
    #page, #page > div { margin: 0 !important; padding: 0 !important; }

    .report-shell {
        margin: 0 !important;
        padding: 0 !important;
        border: 0 none !important;
        box-shadow: none !important;
        font-size: 10.5pt !important;
    }
    /* Em impressao, a coluna direita do cabecalho ganha mais largura
       para acomodar nomes longos de unidade sem quebra disforme. */
    .report-header > .report-meta {
        width: 38% !important;
        min-width: 0 !important;
        padding-left: 8px !important;
    }
    .report-header {
        margin-bottom: 12px !important;
        padding-bottom: 10px !important;
        border-bottom: 1.5pt solid #333 !important;
        /* O cabecalho institucional jamais se parte entre paginas */
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }
    .report-header h4 { font-size: 16pt !important; line-height: 1.2 !important; }
    .report-header p,
    .report-header .report-meta { font-size: 9pt !important; }

    /* Chips de filtros aplicados acompanham o cabecalho */
    .report-filters {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .report-summary {
        margin-bottom: 12px !important;
        border-spacing: 6px 0 !important;
        /* KPIs nao podem se separar entre paginas */
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }
    .report-summary > div {
        padding: 7px 9px !important;
        border: 1px solid #bbb !important;
        border-top: 1.5pt solid #555 !important;
        background: #f6f6f6 !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }
    .report-summary span { font-size: 8pt !important; }
    .report-summary strong { font-size: 11pt !important; }

    .report-section {
        margin-bottom: 12px !important;
        page-break-inside: auto !important;
        break-inside: auto !important;
    }
    /* Em modo impressao o cabecalho da secao fica em layout block
       simples (em tela continua display: table). Display: table no
       browser de impressao gera altura de linha com folga e cria
       gap visual indesejado entre o titulo e a tabela. */
    .report-section > header {
        display: block !important;
        position: relative !important;
        margin: 0 !important;
        padding: 4px 8px !important;
        border: 1px solid #bbb !important;
        border-bottom: 0 !important;
        background: #ececec !important;
        line-height: 1.2 !important;
        overflow: hidden !important;
        page-break-after: avoid !important;
        break-after: avoid !important;
    }
    .report-section > header h5 {
        display: inline !important;
        margin: 0 !important;
        padding: 0 !important;
        font-size: 11pt !important;
        line-height: 1.2 !important;
    }
    .report-count {
        display: inline-block !important;
        float: right !important;
        margin: 0 !important;
        padding: 0 !important;
        font-size: 9pt !important;
        line-height: 1.2 !important;
    }
    /* Nao deixar a tabela criar margem antes (defesa redundante) */
    .report-section > .report-table {
        margin-top: 0 !important;
        page-break-before: avoid !important;
        break-before: avoid !important;
    }

    /* Linhas das tabelas nao se partem entre paginas */
    .report-table tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    /* Linha de titulo de secao embutida no thead - print */
    .report-table .report-section-row > th.report-section-cell {
        padding: 5px 8px !important;
        background: #ececec !important;
        font-size: 11pt !important;
        line-height: 1.2 !important;
        border-color: #bbb !important;
    }
    .report-table .report-section-row .report-section-title {
        font-size: 11pt !important;
    }
    .report-table .report-section-row .report-count {
        font-size: 9pt !important;
    }

    .report-table th,
    .report-table td {
        padding: 5px 6px !important;
        font-size: 9pt !important;
        line-height: 1.3 !important;
    }
    /* tfoot como linha normal evita que totais se repitam em cada pagina */
    .report-table tfoot { display: table-row-group !important; }
    .report-table tbody tr:hover td { background: inherit !important; }

    .report-list {
        padding: 6px 9px 6px 26px !important;
        border: 1px solid #bbb !important;
    }
    .report-list li {
        margin-bottom: 4px !important;
        line-height: 1.3 !important;
        page-break-inside: auto !important;
        break-inside: auto !important;
    }

    .report-chart-canvas { height: 220px !important; }

    html,
    body,
    form {
        width: auto !important;
        min-width: 0 !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }
    body,
    header,
    #menu,
    #page > div {
        min-width: 0 !important;
    }
    #page > div {
        width: auto !important;
        background: transparent !important;
        box-shadow: none !important;
        -webkit-box-shadow: none !important;
    }

    /* Etiquetas Pimaco 6180 - folha Carta, sem margens da pagina.
       A folha fisica ja tem o offset correto das etiquetas; cada
       etiqueta e posicionada de forma absoluta dentro da folha para
       evitar arredondamento acumulado de grid/tabela no navegador. */
    .label-report {
        margin: 0 !important;
        width: 21.59cm !important;
        min-width: 21.59cm !important;
    }
    /* Cabecalho e oculto na impressao - as etiquetas precisam das
       coordenadas exatas para alinhar com a folha Pimaco. */
    .label-report-header { display: none !important; }
    /* A posicao fisica fica nas coordenadas absolutas dos cards. */
    .label-report .label-report-header + .label-pages > .label-sheet:first-child {
        margin-top: 0 !important;
    }
    .label-sheet {
        width: 21.59cm !important;
        height: 27.94cm !important;
        margin: 0 !important;
        padding: 0 !important;
        border: 0 none !important;
    }
    .label-report .label-card { border: 0 none !important; }
    .label-card { page-break-inside: avoid; }
}
