/* Nível 8 — composição interna para desktop
   Complementa desktop-wide.css: não altera a versão mobile e reorganiza
   somente páginas marcadas como candidatas à composição ampla. */

@media (min-width: 1180px) {
  body.n8-refined .app-main,
  body.n8-refined .main-content {
    min-width: 0;
    align-items: start;
  }

  body.n8-refined .card,
  body.n8-refined .panel,
  body.n8-refined .result-section,
  body.n8-refined .results-panel {
    min-width: 0;
  }

  /* Grades internas: deixam de manter apenas duas colunas quando há espaço. */
  body.n8-adaptive-grids .input-grid {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)) !important;
  }

  body.n8-adaptive-grids .result-grid,
  body.n8-adaptive-grids .results-grid {
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)) !important;
  }

  body.n8-adaptive-grids .form-grid {
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)) !important;
  }

  /* Formulário / consulta à esquerda e tabela / histórico à direita. */
  body.n8-sidebar-wide .app-main,
  body.n8-sidebar-wide .main-content {
    display: grid !important;
    grid-template-columns: minmax(320px, 0.38fr) minmax(0, 1.62fr) !important;
    gap: 1.4rem !important;
    align-items: start !important;
  }

  body.n8-sidebar-wide .app-main > :nth-child(n+2),
  body.n8-sidebar-wide .main-content > :nth-child(n+2) {
    min-width: 0;
  }

  /* Duas áreas principais equivalentes: entradas e resultados. */
  body.n8-split .app-main,
  body.n8-split .main-content {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 1.4rem !important;
    align-items: start !important;
  }

  /* Três cards funcionais lado a lado em monitores grandes. */
  body.n8-three .app-main,
  body.n8-three .main-content {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 1.25rem !important;
    align-items: stretch !important;
  }

  body.n8-three .app-main > .card,
  body.n8-three .main-content > .card {
    height: 100%;
  }

  /* Três cards de entrada e um resultado amplo. */
  body.n8-three-plus-result .app-main,
  body.n8-three-plus-result .main-content {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 1.25rem !important;
    align-items: start !important;
  }

  body.n8-three-plus-result .app-main > .result-card,
  body.n8-three-plus-result .main-content > .result-card,
  body.n8-three-plus-result .app-main > .result-section,
  body.n8-three-plus-result .main-content > .result-section,
  body.n8-three-plus-result.n8-result-last .app-main > :last-child,
  body.n8-three-plus-result.n8-result-last .main-content > :last-child {
    grid-column: 1 / -1 !important;
  }

  /* Quatro grupos de entrada em 2x2 + resultados ocupando a largura total. */
  body.n8-four-plus-result .app-main,
  body.n8-four-plus-result .main-content {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 1.25rem !important;
    align-items: start !important;
  }

  body.n8-four-plus-result .app-main > .result-card,
  body.n8-four-plus-result .main-content > .result-card,
  body.n8-four-plus-result .app-main > .result-section,
  body.n8-four-plus-result .main-content > .result-section,
  body.n8-four-plus-result.n8-result-last .app-main > :last-child,
  body.n8-four-plus-result.n8-result-last .main-content > :last-child {
    grid-column: 1 / -1 !important;
  }

  /* Máquinas móveis: dois grupos de dados, resultados e ação em largura total. */
  body.n8-machine .app-main,
  body.n8-machine .main-content {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 1.25rem !important;
    align-items: start !important;
  }

  body.n8-machine .app-main > :nth-child(n+3),
  body.n8-machine .main-content > :nth-child(n+3) {
    grid-column: 1 / -1 !important;
  }

  body.n8-machine .app-main > .btn,
  body.n8-machine .main-content > .btn {
    width: min(420px, 100%) !important;
    justify-self: end;
  }

  /* Curto-circuito: quatro blocos de entrada em 2x2 e resultados abaixo. */
  body.n8-short-circuit .app-main {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 1.25rem !important;
    align-items: start !important;
  }

  body.n8-short-circuit .app-main > .result-section {
    grid-column: 1 / -1 !important;
  }

  body.n8-short-circuit .result-grid {
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)) !important;
  }

  /* Gantt: tarefa recebe mais espaço, métricas e ações ficam compactas. */
  body.n8-gantt .app-main {
    display: grid !important;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.8fr) minmax(240px, 0.55fr) !important;
    gap: 1.25rem !important;
    align-items: start !important;
  }

  /* Falhas de inversores: consulta lateral + diagnóstico. */
  body.n8-faults .app-main {
    display: grid !important;
    grid-template-columns: minmax(320px, 0.42fr) minmax(0, 1.58fr) !important;
    gap: 1.4rem !important;
    align-items: start !important;
  }

  body.n8-faults .app-main > :first-child {
    grid-row: 1 / span 2;
  }

  body.n8-faults .fault-result,
  body.n8-faults .no-results {
    grid-column: 2;
  }

  /* Tabelas e áreas roláveis nunca devem estourar o card em layouts largos. */
  body.n8-refined :is(.table-wrap, .table-container, .table-responsive, .results-table, .history-table) {
    max-width: 100%;
    overflow-x: auto;
  }
}

/* Em notebooks menores, reduzimos a agressividade das composições de 3 colunas. */
@media (min-width: 1024px) and (max-width: 1379px) {
  body.n8-three .app-main,
  body.n8-three .main-content,
  body.n8-three-plus-result .app-main,
  body.n8-three-plus-result .main-content {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  body.n8-three .app-main > :last-child,
  body.n8-three .main-content > :last-child,
  body.n8-three-plus-result .app-main > .result-card,
  body.n8-three-plus-result .main-content > .result-card,
  body.n8-three-plus-result .app-main > .result-section,
  body.n8-three-plus-result .main-content > .result-section,
  body.n8-three-plus-result.n8-result-last .app-main > :last-child,
  body.n8-three-plus-result.n8-result-last .main-content > :last-child {
    grid-column: 1 / -1 !important;
  }

  body.n8-gantt .app-main {
    grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr) !important;
  }

  body.n8-gantt .app-main > :last-child {
    grid-column: 1 / -1;
  }
}
