/* SGCB no celular (PWA, etapa 2).
 *
 * Só vale em telas de até 640 px; o layout de computador não muda.
 * Carregado depois do design system; os seletores usam #sgcb para
 * prevalecer sobre os utilitários das páginas.
 */
@media (max-width: 640px) {
  /* Campos com 16 px: o iPhone não dá zoom automático ao tocar. */
  #sgcb input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="hidden"]),
  #sgcb select,
  #sgcb textarea {
    font-size: 16px;
  }

  /* Alvos de toque com pelo menos 44 px de altura. */
  #sgcb .button,
  #sgcb main button:not(.icon-action),
  #sgcb main input[type="submit"] {
    min-height: 44px;
  }

  #sgcb .icon-action {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

  #sgcb .back-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
  }

  /* Cabeçalho da página em coluna: título à esquerda, ações abaixo. */
  #sgcb .page-head {
    align-items: stretch;
  }

  /* Grupos de ações empilhados, com largura total. */
  #sgcb main .actions:not(td .actions):not(.table-actions) {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    margin-left: 0;
  }

  #sgcb main .actions:not(td .actions):not(.table-actions) > :is(.button, a.button, button) {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  /* Indicadores numéricos em duas colunas. */
  #sgcb :is(.summary-grid, .kpi-grid, .ws-kpis, .sgcb-stat-grid, .sgcb-summary-grid) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  #sgcb :is(.summary-grid article strong, .kpi-value, .ws-kpi-value, .sgcb-stat-value) {
    font-size: 22px;
    overflow-wrap: anywhere;
  }

  /* Cartões de módulos do primeiro acesso com títulos proporcionais. */
  #sgcb .module-card strong {
    font-size: 20px;
    line-height: 1.25;
  }

  /* Tabelas simples viram cartões (marcadas por sgcb_mobile.js). */
  #sgcb table.sgcb-tabela-empilhavel {
    display: block;
    width: 100%;
    min-width: 0 !important;
    border: 0;
    background: transparent;
  }

  #sgcb table.sgcb-tabela-empilhavel thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
  }

  #sgcb table.sgcb-tabela-empilhavel :is(tbody, tfoot) {
    display: grid;
    gap: 10px;
    padding: 10px 0;
  }

  #sgcb table.sgcb-tabela-empilhavel tr {
    display: block;
    min-width: 0;
    padding: 6px 12px;
    border: 1px solid var(--sgcb-border);
    border-radius: 10px;
    background: var(--sgcb-surface);
  }

  #sgcb table.sgcb-tabela-empilhavel tfoot tr {
    background: var(--sgcb-canvas-subtle);
    font-weight: 600;
  }

  #sgcb table.sgcb-tabela-empilhavel td,
  #sgcb table.sgcb-tabela-empilhavel tbody th,
  #sgcb table.sgcb-tabela-empilhavel tfoot th {
    display: block;
    width: auto;
    padding: 8px 0;
    border: 0;
    border-bottom: 1px solid var(--sgcb-border-subtle);
    text-align: left;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  /* Rótulo em linha própria: células com vários elementos (nome + código) não se misturam. */
  #sgcb table.sgcb-tabela-empilhavel :is(td, th)::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--sgcb-ink-soft);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
  }

  #sgcb table.sgcb-tabela-empilhavel :is(td, th):not([data-label])::before {
    content: none;
  }

  #sgcb table.sgcb-tabela-empilhavel tr > :last-child {
    border-bottom: 0;
  }

  #sgcb table.sgcb-tabela-empilhavel .table-actions {
    flex-wrap: wrap;
  }

  /* Listas em modo cartões não podem herdar a largura mínima da tabela. */
  #sgcb .sgcb-list-view-cards table[data-list-view-table] {
    min-width: 0 !important;
  }

  /* A área de rolagem lateral deixa de ser necessária. */
  #sgcb :is(.table-wrap, .u-overflow-x-auto):has(> table.sgcb-tabela-empilhavel) {
    overflow-x: visible;
    border: 0;
    box-shadow: none;
    background: transparent;
  }
}
