/* Programação de Entrega (PCP). Compacta como a Notas dos Fornecedores:
   KPI baixo em faixa, explicação atrás de "Ajuda". Cor sempre com texto ou
   ícone: vermelho = atrasada, âmbar = antiga / a revisar, verde = entregue,
   azul = ação e seleção. */
.pge-shell { --pge-ink: #16233a; --pge-muted: #53647a; --pge-soft: #64748b; --pge-line: #e0e5ed;
  --pge-good: #1f9d55; --pge-warn: #c98a09; --pge-danger: #d33c3c; --pge-info: #1769d2;
  max-width: 1800px; margin: 0 auto; color: var(--pge-ink); min-width: 0; }

.pge-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 16px; margin-bottom: 8px; }
.pge-head h2 { margin: 2px 0; font-size: 1.35rem; font-weight: 700; color: var(--pge-ink); }
.pge-eyebrow { display: block; font-size: .61rem; letter-spacing: .1em; font-weight: 800; color: #a43b40; margin-bottom: 3px; }
.pge-intro { font-size: .76rem; color: var(--pge-muted); margin: 3px 0; }
.pge-head-dir { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: .74rem; color: var(--pge-muted); }
.pge-head:has(.pge-ajuda[open]) > div:first-child { flex-basis: 100%; }
.pge-ajuda { font-size: .76rem; }
.pge-ajuda summary { cursor: pointer; color: var(--pge-info); padding: 2px 0; }
.pge-ajuda ul { margin: 6px 0 4px; padding-left: 18px; max-width: 110ch; color: #34435a; }
.pge-ajuda li { margin-bottom: 4px; }
.pge-ajuda p { margin: 4px 0; max-width: 110ch; color: var(--pge-muted); }

.pge-aviso { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 6px; margin-bottom: 6px; font-size: .76rem;
  border: 1px solid var(--pge-line); background: #fff; }
.pge-aviso > div { flex: 1 1 0; min-width: 0; }
.pge-aviso.warn { background: #fdf6ea; border-color: #f0dcb4; color: #6d4a10; }
.pge-aviso.danger { background: #fbeeee; border-color: #f0c9c8; color: #7c2725; }

.pge-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-bottom: 10px; }
.pge-kpi { position: relative; display: flex; flex-direction: column; gap: 4px; justify-content: flex-start;
  background: #fff; border: 1px solid var(--pge-line); border-radius: 9px; padding: 10px 12px 10px 16px; min-width: 0; overflow-wrap: anywhere; }
.pge-kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: #adb5bd; }
.pge-kpi.good::before { background: var(--pge-good); }
.pge-kpi.warn::before { background: var(--pge-warn); }
.pge-kpi.danger::before { background: var(--pge-danger); }
.pge-kpi > span { color: var(--pge-muted); font-size: .69rem; line-height: 1.35; }
.pge-kpi strong { font-size: clamp(1rem, 1.35vw, 1.35rem); font-weight: 750; line-height: 1.25; font-variant-numeric: tabular-nums; }
.pge-kpi small { color: var(--pge-soft); font-size: .68rem; line-height: 1.25; }

.pge-card { background: #fff; border: 1px solid var(--pge-line); border-radius: 8px; margin-bottom: 8px; min-width: 0; }
.pge-card-head { display: flex; justify-content: space-between; align-items: center; gap: 4px 12px; flex-wrap: wrap; padding: 8px 12px; border-bottom: 1px solid #eef1f5; }
.pge-card-head h3 { font-size: .9rem; margin: 0; color: var(--pge-ink); }
.pge-card-head small { display: block; font-size: .7rem; color: var(--pge-soft); }
.pge-count { font-size: .72rem; color: var(--pge-muted); white-space: nowrap; }

.pge-pend { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 4px 10px; padding: 7px 12px; border-bottom: 1px solid #f1f3f7; font-size: .76rem; }
.pge-pend:last-child { border-bottom: 0; }
.pge-pend > i { font-size: .95rem; }
.pge-pend > i.danger { color: var(--pge-danger); }
.pge-pend > i.warn { color: var(--pge-warn); }
.pge-pend small { display: block; color: var(--pge-soft); font-size: .68rem; }
.pge-ok { padding: 8px 12px; font-size: .76rem; color: #1f7a45; }

.pge-btn { height: 28px; border: 1px solid var(--pge-info); background: #fff; color: var(--pge-info); border-radius: 6px; padding: 0 .6rem;
  font-size: .72rem; font-weight: 700; white-space: nowrap; }
.pge-btn:hover { background: #eef5ff; }
.pge-btn.sec { border-color: #cbd3df; color: #26344b; }
.pge-btn.sec:hover { background: #f1f5fa; }
.pge-btn:disabled { opacity: .55; cursor: default; }

.pge-filtros { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 10px; padding: 8px 12px; }
.pge-filtro label { display: block; font-size: .65rem; font-weight: 700; color: var(--pge-muted); margin-bottom: 2px; }
.pge-filtro select, .pge-filtro input { height: 31px; font-size: .76rem; border: 1px solid #cbd3df; border-radius: 6px; padding: 0 .5rem; color: var(--pge-ink); background: #fff; max-width: 280px; }
.pge-filtro select { padding-right: 2rem; }
.pge-filtro { min-width: 0; }
.pge-btn:focus-visible, .pge-op:focus-visible, .pge-metrica button:focus-visible, .pge-tbl th.ord:focus-visible { outline: 2px solid var(--pge-info); outline-offset: 2px; }
.pge-filtro.busca { flex: 1 1 200px; }
.pge-filtro.busca input { width: 100%; max-width: none; }
.pge-colecoes { position: relative; width: 240px; max-width: 100%; }
.pge-colecoes summary { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 31px;
  padding: 0 10px; background: #fff; border: 1px solid #cbd3df; border-radius: 6px; color: var(--pge-ink); font-size: .76rem; cursor: pointer; list-style: none; }
.pge-colecoes summary::-webkit-details-marker { display: none; }
.pge-colecoes summary::after { content: '▾'; flex-shrink: 0; }
.pge-colecoes summary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pge-colecoes[open] summary { border-color: var(--pge-info); }
.pge-colecoes summary:focus-visible { outline: 2px solid var(--pge-info); outline-offset: 2px; }
.pge-colecoes-menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; width: max-content; min-width: 100%; max-width: calc(100dvw - 64px);
  padding: 6px; border: 1px solid #cbd3df; border-radius: 7px; background: #fff; box-shadow: 0 6px 22px #16233a26; }
.pge-colecoes-menu > button { width: 100%; padding: 5px 7px; border: 0; border-bottom: 1px solid var(--pge-line); background: #fff; color: var(--pge-info); font-size: .7rem; text-align: left; }
.pge-colecoes-opcoes { max-height: min(260px, 45dvh); overflow: auto; overscroll-behavior: contain; padding-top: 4px; }
.pge-colecoes-opcoes label { display: flex; align-items: center; gap: 8px; padding: 7px; margin: 0; cursor: pointer; font-size: .75rem; font-weight: 400; color: var(--pge-ink); }
.pge-colecoes-opcoes label:hover, .pge-colecoes-opcoes label:focus-within { background: #eef5ff; border-radius: 4px; }
.pge-colecoes-opcoes input[type="checkbox"] { flex: 0 0 15px; width: 15px; height: 15px; padding: 0; margin: 0; accent-color: var(--pge-info); }
.pge-colecoes-opcoes small { color: var(--pge-muted); }
.pge-metrica { display: inline-flex; border: 1px solid #cbd3df; border-radius: 6px; overflow: hidden; }
.pge-metrica button { height: 29px; border: 0; background: #fff; color: #26344b; font-size: .72rem; padding: 0 .65rem; }
.pge-metrica button.ativo { background: var(--pge-info); color: #fff; font-weight: 700; }
.pge-ativos { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 8px; }
.pge-chip { display: inline-flex; align-items: center; gap: 6px; background: #eef5ff; border: 1px solid #cfe0f7; border-radius: 6px;
  padding: 3px 8px; font-size: .72rem; color: #26344b; }
.pge-chip button { border: 1px solid var(--pge-info); background: #fff; color: var(--pge-info); border-radius: 5px; font-size: .66rem; font-weight: 700; padding: 1px 6px; }

.pge-tbl-wrap { overflow: auto; max-width: 100%; scrollbar-width: thin; }
#pgeMatCard .pge-tbl-wrap { max-height: max(320px, calc(100dvh - 160px)); }
.pge-tbl thead th { position: sticky; top: 0; z-index: 2; }
.pge-mat td:first-child, .pge-mat th:first-child { position: sticky; left: 0; z-index: 1; background: #fff; border-right: 1px solid var(--pge-line); }
.pge-mat th:first-child { z-index: 3; background: #f7f9fc; }
.pge-mat tfoot td { position: sticky; bottom: 0; z-index: 2; }
.pge-mat tfoot td:first-child { z-index: 3; background: #f7f9fc; }
.pge-mat tbody tr:nth-child(even) td { background-color: #fafbfd; }
.pge-mat td:last-child, .pge-mat th:last-child { background: #f1f5f9; border-left: 1px solid var(--pge-line); }
.pge-mat tbody tr:hover td { background-color: #f0f6ff; }
.pge-mat td.cel:hover { box-shadow: inset 0 0 0 1px #86afe9; }
.pge-tbl { width: 100%; border-collapse: collapse; font-size: .76rem; }
.pge-tbl th { background: #f7f9fc; color: var(--pge-muted); font-size: .64rem; text-transform: uppercase; letter-spacing: .03em; font-weight: 700;
  padding: 6px 8px; border-bottom: 1px solid #e5e9ef; text-align: left; white-space: nowrap; }
.pge-tbl th.ord { cursor: pointer; user-select: none; }
.pge-tbl th.ord:hover { color: var(--pge-ink); }
.pge-tbl th .bi { font-size: .6rem; margin-left: 2px; }
.pge-tbl td { padding: 6px 8px; border-bottom: 1px solid #f0f2f6; vertical-align: top; white-space: nowrap; }
.pge-tbl th.num, .pge-tbl td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pge-tbl tfoot td { font-weight: 700; background: #fafbfd; border-top: 1px solid #e5e9ef; }
.pge-neg { color: #c92a2a; }
.pge-zero { color: #b3bccb; }
.pge-sub { display: block; font-size: .66rem; color: var(--pge-soft); font-weight: 400; }

/* matriz fabricante × semana */
.pge-mat { min-width: 980px; }
.pge-mat td.cel { cursor: pointer; }
.pge-mat td.cel:hover { background: #f3f8ff; }
.pge-mat td.cel.sel, .pge-mat th.sel { background: #e3efff; }
.pge-mat td.cel:focus-visible { outline: 2px solid var(--pge-info); outline-offset: -2px; }
.pge-mat td.atraso b { color: #c92a2a; }
.pge-mat td.antiga b { color: #8a5a00; }
.pge-mat th.atual { color: var(--pge-ink); }
.pge-mat td.fab { min-width: 165px; max-width: 210px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }

/* detalhe por OP */
.pge-ops { min-width: 1330px; table-layout: fixed; }
.pge-ops th:nth-child(1) { width: 60px; }
.pge-ops th:nth-child(2) { width: 240px; }
.pge-ops th:nth-child(3) { width: 125px; }
.pge-ops th:nth-child(4) { width: 95px; }
.pge-ops th:nth-child(5) { width: 140px; }
.pge-ops th:nth-child(6) { width: 140px; }
.pge-ops th:nth-child(7), .pge-ops th:nth-child(8) { width: 80px; }
.pge-ops th:nth-child(9) { width: 74px; }
.pge-ops th:nth-child(10) { width: 100px; }
.pge-ops th:nth-child(11) { width: 100px; }
.pge-ops td { white-space: normal; overflow-wrap: anywhere; }
.pge-ops .pge-acoes { flex-direction: column; align-items: stretch; }
.pge-ops .pge-sub { line-height: 1.35; margin-top: 3px; }
.pge-ops .pge-prod .pge-sub { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.pge-ops .pge-tag { white-space: normal; }
.pge-ops th:first-child, .pge-ops td:first-child { position: sticky; left: 0; background: #fff; z-index: 1; border-right: 1px solid var(--pge-line); }
.pge-ops th:first-child { z-index: 3; background: #f7f9fc; }
.pge-ops tbody tr:hover td { background-color: #f6f9fd; }
.pge-op { border: 0; background: none; color: var(--pge-info); font-weight: 700; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
.pge-prod { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.pge-prod b { font-weight: 600; }
.pge-colecao { display: block; font-size: .65rem; color: #44536a; margin-top: 3px; line-height: 1.3; }
.pge-lista-filtros { padding: 6px 12px; border-bottom: 1px solid var(--pge-line); background: #fafbfd; }
.pge-lista-filtros .pge-filtro { display: flex; align-items: center; gap: 8px; }
.pge-lista-filtros select { max-width: 300px; }
.pge-produto-foto { display: flex; align-items: center; gap: 8px; }
.pge-produto-foto > div { min-width: 0; }
.pge-foto { flex: 0 0 48px; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center;
  background: #fff; border: 1px solid var(--pge-line); border-radius: 5px; color: var(--pge-muted); text-align: center; font-size: .6rem; line-height: 1.2; }
.pge-foto img { width: 100%; height: 100%; object-fit: contain; border-radius: 5px; }
.pge-foto-abrir { cursor: zoom-in; padding: 0; }
.pge-foto-abrir:hover { border-color: var(--pge-info); }
.pge-foto-abrir:focus-visible { outline: 2px solid var(--pge-info); outline-offset: 2px; }
.pge-foto-overlay .pge-dialog { width: min(900px, 100%); }
.pge-foto-view { margin: 0; text-align: center; }
.pge-foto-view img { display: block; width: 100%; height: min(65dvh, 650px); object-fit: contain; background: #fff; border-radius: 6px; }
.pge-foto-view figcaption { padding-top: 8px; font-size: .8rem; }
.pge-lista-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px 12px; }
.pge-exportar { display: flex; flex-wrap: wrap; gap: 6px; }
.pge-export-status { font-size: .7rem; color: var(--pge-muted); }
.pge-export-status:empty { display: none; }
.pge-btn:disabled { opacity: .6; cursor: wait; }
.pge-tag { display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 1px 8px; font-size: .68rem; font-weight: 700; white-space: nowrap; }
.pge-tag.danger { background: #fdecec; color: #a61e1e; }
.pge-tag.warn { background: #fdf3df; color: #7a5200; }
.pge-tag.good { background: #e6f6ec; color: #1a6d3d; }
.pge-tag.info { background: #eaf2fd; color: #1d5bb0; }
.pge-tag.neutro { background: #eef1f5; color: #44536a; }
.pge-acoes { display: flex; gap: 4px; }

.pge-vazio { padding: 18px 12px; text-align: center; color: var(--pge-muted); font-size: .76rem; }
.pge-vazio b { display: block; color: var(--pge-ink); font-size: .84rem; margin-bottom: 2px; }
.pge-vazio.good b { color: #1f7a45; }
.pge-carregando { padding: 36px; text-align: center; color: var(--pge-muted); font-size: .8rem; }
.pge-recarregando { opacity: .45; pointer-events: none; transition: opacity .15s; }
.pge-mais { padding: 8px 12px; text-align: center; }

/* Consulta em camadas: quadro → OPs selecionadas → OP completa. */
.pge-overlay { position: fixed; inset: 0; background: rgba(22, 35, 58, .48); display: flex; align-items: center; justify-content: center; padding: 24px; }
.pge-dialog { background: #f4f6f9; border: 1px solid #d9e1ec; border-radius: 12px; box-shadow: 0 18px 70px #16233a40; width: min(1560px, 100%); max-height: calc(100dvh - 48px); display: flex; flex-direction: column; min-width: 0; }
.pge-dialog-head { flex-shrink: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; background: #fff; border-bottom: 1px solid var(--pge-line); border-radius: 12px 12px 0 0; }
.pge-dialog-head > div { min-width: 0; }
.pge-dialog-head h3 { font-size: 1rem; margin: 0; font-weight: 750; overflow-wrap: anywhere; }
.pge-dialog-body { padding: 14px; overflow: auto; min-height: 0; overscroll-behavior: contain; }
.pge-lista-detalhe { margin: 0; }
.pge-lista-detalhe .pge-tbl-wrap { max-height: calc(100dvh - 290px); }
.pge-scroll-hint { display: none; padding: 6px 12px; color: var(--pge-muted); font-size: .68rem; background: #f7f9fc; border-top: 1px solid var(--pge-line); }
.pge-op-detalhe .ftop { max-width: none; }
@media (max-width: 1100px) and (min-width: 601px) {
  .pge-kpi { padding: 8px 8px 8px 12px; }
  .pge-kpi > span { min-height: 2.7em; }
  .pge-filtro select { max-width: 240px; }
}
@media (max-width: 1320px) {
  .pge-scroll-hint { display: block; }
}

@media (max-width: 600px) {
  .pge-colecoes { width: 100%; }
  .pge-lista-tools { justify-content: flex-start; }
  .pge-lista-detalhe .pge-card-head { align-items: flex-start; flex-direction: column; }
  .pge-head h2 { font-size: 1.15rem; }
  .pge-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pge-kpi { grid-template-columns: minmax(0, 1fr); }
  .pge-kpi strong { font-size: 1rem; }
  .pge-pend small { display: none; }
  .pge-filtro, .pge-filtro select { width: 100%; max-width: none; }
  .pge-pend { grid-template-columns: auto 1fr; }
  .pge-pend .pge-btn { grid-column: 2; justify-self: start; }
  .pge-kpi:last-child { grid-column: 1 / -1; }
  .pge-head-dir { gap: 6px; }
  .pge-overlay { padding: 8px; }
  .pge-dialog { max-height: calc(100dvh - 16px); border-radius: 9px; }
  .pge-dialog-head { align-items: flex-start; padding: 10px; flex-direction: column; gap: 8px; }
  .pge-dialog-head h3 { font-size: .88rem; }
  .pge-dialog-head .pge-btn { height: 32px; }
  .pge-dialog-body { padding: 8px; }
  .pge-lista-detalhe .pge-tbl-wrap { max-height: calc(100dvh - 305px); }
  .pge-mat td.fab { min-width: 120px; max-width: 135px; }
}
@media print {
  body.ftec-imprimindo .pge-shell > :not(.pge-overlay),
  body.ftec-imprimindo .pge-overlay:not(:has(.pge-op-detalhe)),
  body.ftec-imprimindo .pge-dialog-head { display: none !important; }
  body.ftec-imprimindo .pge-overlay, body.ftec-imprimindo .pge-dialog,
  body.ftec-imprimindo .pge-dialog-body { position: static; display: block; background: none; padding: 0; margin: 0; border: 0; box-shadow: none; width: auto; max-height: none; overflow: visible; }
}
