/* Complementos da Análise de Compras sobre o style.css padrão */
.fornec-busca { position: relative; flex: 1 1 320px; }

.fornec-lista {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    background: white;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 50;
}

.fornec-lista button,
.fornec-lista div {
    display: block;
    width: 100%;
    padding: 10px 14px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    font-size: 13px;
}

.fornec-lista button { cursor: pointer; }
.fornec-lista small { display: block; margin-top: 2px; font-size: 11px; color: var(--text-muted); }
.fornec-lista button:hover,
.fornec-lista button:focus { background: #FFF7EE; }
.fornec-lista div { color: var(--text-muted); }

.selecao {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 30px;
    background: #FFF7EE;
    border-bottom: 1px solid var(--border-color);
}

.selecao .filial-chips { flex: 1 1 300px; max-height: 90px; overflow-y: auto; }
.selecao .filtro { flex: 0 1 340px; }
.selecao .filtro input { padding: 9px 14px; }
.dica { font-size: 12px; color: var(--text-muted); align-self: center; }

.filial-chip { font-family: inherit; }

#page-consulta .table-area { min-height: 0; padding-bottom: 12px; }

#main-table th { user-select: none; }
#main-table th.num { text-align: right; }
#main-table td { white-space: nowrap; }
#main-table th.fixa,
#main-table td.fixa { position: sticky; left: 0; }
#main-table th.fixa { background: var(--primary); z-index: 2; }
#main-table td.fixa {
    background: white;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 700;
    box-shadow: 1px 0 0 var(--border-color);
}

.btn-export:disabled { opacity: 0.45; cursor: not-allowed; }

.so-celular { display: none; }

/* ================================================================ CELULAR
   O navegador aplica sozinho: tela estreita (em pé) ou celular deitado (toque e pouca altura).
   A tabela vira uma lista de cartões; tocar no cartão mostra todas as colunas. */
@media (max-width: 700px), (pointer: coarse) and (max-height: 500px) {
    /* 16px nos campos evita o zoom automático do iPhone ao digitar */
    .field input,
    .search-field input,
    .search-field select { font-size: 16px; }

    #page-login { overflow-y: auto; justify-content: flex-start; }
    .login-wrapper { margin: auto 0; padding: 16px; }
    .login-box { padding: 32px 22px; }

    /* a tela inteira rola; o rodapé fica preso embaixo */
    #page-consulta { overflow-y: auto; }
    #page-consulta > * { flex-shrink: 0; }

    .natan-bar { height: 56px; padding: 0 12px; }
    .bar-left { gap: 4px; font-size: 13px; }
    .bar-right span { display: none; }

    .search-bar { gap: 14px; padding: 14px 12px; }
    .search-bar .search-field { flex: 1 1 100%; }
    .search-bar .search-actions { width: 100%; flex-wrap: wrap; }
    .search-bar .btn-diag { flex: 1 1 100%; padding: 13px; }
    .search-bar .btn-search { flex: 1; padding: 15px; }
    .search-bar .btn-clear { padding: 15px 20px; }
    .filial-chips { gap: 8px; }
    .filial-chip { font-size: 12px; padding: 10px 12px; text-align: left; }
    .fornec-lista button { padding: 13px 14px; }

    .selecao { padding: 10px 12px; }
    .selecao .filial-chips,
    .selecao .filtro { flex: 1 1 100%; }
    .so-celular { display: block; flex: 1 1 100%; }

    .result-info { padding-left: 12px; padding-right: 12px; }

    #page-consulta .table-area { flex: 1 0 auto; overflow: visible; padding: 12px; }
    #page-consulta .table-scroll { flex: none; overflow: visible; border: none; background: none; box-shadow: none; }
    #main-table,
    #main-table tbody { display: block; }
    #main-table thead { display: none; }

    #main-table tr {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px 8px;
        margin-bottom: 10px;
        padding: 14px;
        background: white;
        border: 1px solid var(--border-color);
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
        cursor: pointer;
    }
    #main-table tr::after {
        content: 'Toque para ver todos os dados ▾';
        order: 3;
        grid-column: 1 / -1;
        text-align: center;
        font-size: 11px;
        font-weight: 700;
        color: var(--primary);
    }
    #main-table tr.aberto::after { content: 'Mostrar menos ▴'; }

    #main-table td,
    #main-table td.num {
        display: block;
        order: 1;
        min-width: 0;
        padding: 0;
        border: none;
        text-align: left;
        white-space: normal;
        overflow-wrap: anywhere;
        font-size: 14px;
    }
    #main-table td::before {
        content: attr(data-rotulo);
        display: block;
        font-size: 10px;
        font-weight: 700;
        text-transform: uppercase;
        color: var(--text-muted);
    }
    #main-table td:empty::after { content: '—'; color: #ADB5BD; }
    #main-table td.extra { display: none; order: 2; }
    #main-table tr.aberto td.extra { display: block; }

    #main-table td.fixa {
        position: static;
        grid-column: 1 / -1;
        max-width: none;
        box-shadow: none;
        font-size: 14px;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border-color);
    }
    #main-table td.fixa::before { display: none; }

    #main-table tr.vazia { display: block; cursor: default; }
    #main-table tr.vazia::after { content: none; }
    #main-table tr.vazia td { padding: 30px 8px !important; text-align: center !important; }
    #main-table tr.vazia td::before { display: none; }

    .natan-footer {
        position: sticky;
        bottom: 0;
        z-index: 20;
        height: auto;
        justify-content: space-between;
        gap: 8px;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    }
    .natan-footer .f-stat div { margin-right: 4px; font-size: 10px; }
    .natan-footer .f-stat span { font-size: 17px; }
    .natan-footer .btn-export { padding: 12px 14px; }
}
