/* Ajustes para telemóvel e tablet (ecrãs tácteis). Carregado depois de theme.css.
   Só atua em ecrãs com ponteiro grosso (dedo) ou estreitos: no computador com rato nada muda.
   Regras: alvos de toque com pelo menos 44 px, texto legível, nada tapado pelo teclado nem pelos avisos. */

@media (pointer: coarse) {
  /* Botões e campos: altura mínima de toque (o padding é o mesmo, só cresce a caixa). */
  .btn { min-height: 44px; }
  .btn-sm { min-height: 40px; --bs-btn-padding-y: .45rem; --bs-btn-font-size: .85rem; display: inline-flex; align-items: center; justify-content: center; }
  .btn-link.btn-sm { min-width: 44px; }
  .form-control, .form-select { min-height: 44px; font-size: 16px; } /* 16 px evita o zoom automático do iPhone ao focar */
  .form-control-sm, .form-select-sm { min-height: 40px; font-size: 15px; }
  textarea.form-control { min-height: 88px; }
  .input-group-text { min-height: 44px; }
  .btn-close { width: 44px; height: 44px; padding: 0; background-size: 14px; }
  .modal-header { padding-top: .5rem; padding-bottom: .5rem; }

  /* Caixas de seleção e rádios: maiores e com a linha toda clicável. */
  .form-check-input { width: 1.35em; height: 1.35em; }
  .form-check-input[type=radio], .form-check-input[type=checkbox] { margin-top: .15em; }
  .form-switch .form-check-input { width: 2.6em; height: 1.4em; }
  .form-check { min-height: 32px; display: flex; align-items: center; gap: .5rem; padding-left: 0; }
  .form-check .form-check-input { float: none; margin-left: 0; flex: none; }
  .form-switch { padding-left: 0; }
  .list-group-item:has(> .form-check-input) { min-height: 48px; }
  .btn-group > .btn, .btn-group > label.btn { min-height: 44px; }

  /* Rótulos dos campos: a fonte mono pequena lê-se mal no telemóvel. */
  .form-label { font-size: .74rem; letter-spacing: .8px; }

  /* Barra de topo: botões com 44 px. */
  .topbar .tb-btn { width: 44px; height: 44px; }
  .net-pill { height: 36px; min-width: 40px; justify-content: center; }

  /* Menu lateral: secções e ligações com altura de toque. */
  #sidebar .nav-link, #sidebar a.nav-link, #sidebar .menu-sec, #sidebar button { min-height: 44px; }
  #sidebar input { min-height: 44px; }

  /* Ligações soltas que fazem de botão (Limpar assinatura, chips de email). */
  .chip .x, .chips .x, [data-chip-x], .chip button { min-width: 32px; min-height: 32px; display: inline-flex; align-items: center; justify-content: center; }
  .at-thumbs [data-fdel] { min-width: 32px; min-height: 32px; font-size: 1.1rem; }

  /* Botões só com ícone (editar, eliminar, adiar...): quadrados de toque. */
  .btn-sm { min-width: 44px; }
  /* Visto do lembrete: o quadrado continua pequeno à vista, mas a área de toque cresce. */
  .lb-item .chk { position: relative; }
  .lb-item .chk::after { content: ""; position: absolute; inset: -11px; }
  /* Ligações de texto que são ações (Esqueci-me de registar, Todos, Histórico): mais área de toque. */
  .card-header a.small, [data-addfix], .page-head .crumbs a { display: inline-block; padding: .6rem 0; }

  /* A assinatura precisa de espaço para o dedo. */
  .sign-pad { height: 220px; }

  /* Tabelas com botões na última coluna: botões de ícone com 44 px. */
  .table .actions .btn, td.actions .btn { min-width: 44px; }
}

/* Telemóvel (até 575 px). */
@media (max-width: 575.98px) {
  /* Os avisos aparecem em cima, para não taparem os botões do rodapé das janelas (Guardar, Terminar...). */
  .toast-stack { top: calc(env(safe-area-inset-top, 0px) + 64px); bottom: auto; left: .75rem; right: .75rem; }
  .toast-stack .toast-x { width: 100%; max-width: none; }

  /* O botão do assistente não deve tapar o fim do conteúdo nem as ações. */
  #view { padding-bottom: 84px; }
  .ai-fab { width: 48px; height: 48px; right: .9rem; bottom: calc(env(safe-area-inset-bottom, 0px) + .9rem); }
  .modal.show ~ .ai-fab, body.modal-open .ai-fab { display: none; }

  /* Rodapé das janelas: botões a toda a largura, com o principal à direita (à mão do polegar). */
  .modal-footer { flex-wrap: nowrap; gap: .5rem; position: sticky; bottom: 0; background: inherit; z-index: 2; }
  .modal-footer > .btn { flex: 1 1 0; margin: 0; }
  .modal-footer > .btn.me-auto { flex: 0 1 auto; }
  .modal-fullscreen-sm-down .modal-footer { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + .75rem); }

  /* Botões grandes do serviço em curso (Pausar, Máquinas, Terminar) em três colunas: ícone por cima do texto. */
  .col-4 > .at-big { flex-direction: column; gap: .1rem; font-size: .85rem; padding-left: .25rem; padding-right: .25rem; min-height: 64px; }
  .col-4 > .at-big .bi { font-size: 1.25rem; }
  .col-4 > .at-big .small { font-size: .85rem; }

  /* Pesquisa geral espremida na barra de topo: só a lupa (o campo abre ao tocar). */
  .topbar #gsearch { min-width: 0; }
}

/* Tablet (sala de stock, coordenação no terreno): botões das janelas maiores. */
@media (pointer: coarse) and (min-width: 768px) {
  .modal-footer > .btn { min-height: 52px; min-width: 140px; font-size: 1rem; }
}

/* Sala de stock (modo tablet): as janelas (Retirar peças, Repor, PIN) ficam fora de .stk-tab, por isso os botões
   grandes .bigb precisam do mesmo estilo dentro de .stk-pin. */
.stk-pin .bigb { border: 1px solid rgba(0, 158, 229, .55); background: rgba(0, 158, 229, .12); color: #e6edf3; font-size: 1.05rem; padding: .8rem 1.4rem; min-height: 60px; min-width: 150px; border-radius: 2px; display: inline-flex; align-items: center; justify-content: center; gap: .5rem; font-weight: 500; flex: 1 1 0; }
.stk-pin .bigb:active { transform: scale(.98); }
.stk-pin .bigb i { font-size: 1.3rem; }
.stk-pin .bigb.pri { background: linear-gradient(135deg, #00b4ff, #0079b0); border-color: #00b4ff; color: #fff; box-shadow: 0 8px 22px rgba(0, 158, 229, .35); }
.stk-pin .bigb.ok { background: linear-gradient(135deg, #2e9d6a, #1d7a50); border-color: #3fbf86; color: #fff; }
.stk-pin .bigb.bad { background: linear-gradient(135deg, #d0453b, #9e2a22); border-color: #ff7a6e; color: #fff; }
.stk-pin .modal-footer { gap: .75rem; flex-wrap: nowrap; }

/* Portal do cliente no telemóvel: tabelas em cartões (portal.js põe .pc-cards e o nome da coluna em data-label). */
@media (max-width: 575.98px) {
  .pc-cards { overflow: visible; }
  .pc-cards .table, .pc-cards .table > tbody, .pc-cards .table > tbody > tr { display: block; width: 100%; }
  .pc-cards .table > thead { display: none; }
  .pc-cards .table > tbody > tr { padding: .7rem 1rem; border-bottom: 1px solid rgba(0, 0, 0, .08); }
  .pc-cards .table > tbody > tr > td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; width: 100%; padding: .2rem 0; border: 0; text-align: right; background: transparent; box-shadow: none; }
  .pc-cards .table > tbody > tr > td[data-label]::before { content: attr(data-label); flex: none; text-align: left; font-family: var(--mono); font-size: .68rem; letter-spacing: 1px; text-transform: uppercase; color: #6b7785; }
  .pc-cards .table > tbody > tr > td:first-child { display: block; text-align: left; font-size: 1.02rem; padding-bottom: .35rem; }
  .pc-cards .table > tbody > tr > td:first-child::before { display: none; }
  .pc-cards .table > tbody > tr > td.actions, .pc-cards .table > tbody > tr > td:last-child:has(.btn) { justify-content: flex-end; flex-wrap: wrap; padding-top: .5rem; }
  .pc-cards .table > tbody > tr > td.actions::before, .pc-cards .table > tbody > tr > td:last-child:has(.btn)::before { display: none; }
  .pc-cards .table > tbody > tr > td:empty { display: none; }
}
