/* Seu Lóza · celular primeiro (revisão 10/11). Carregado por último: regras que valem para TODAS as telas no celular e em
   tela de toque. Antes, cada janela tinha a sua correção (só 6); agora a regra é uma só.
   C1 · campos com letra de 16 px (o iPhone não dá zoom sozinho ao tocar para digitar)
   C2 · alvos de toque de 44 px no mínimo
   C3 · janelas abrem de baixo, com a altura certa (dvh) e os botões empilhados, acima da barra do Safari */

/* ---------- C1 · campos sem zoom no iPhone ---------- */
@media (max-width: 900px), (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]), select, textarea,
  .input, .select, .composer textarea, .field input { font-size: 16px !important; }
}

/* ---------- C2 · alvos de toque ---------- */
@media (pointer: coarse) {
  .btn, .btn-sm { min-height: 44px; }
  .btn-sm { padding-inline: 14px; }
  .icon-btn { min-width: 44px; min-height: 44px; }
  .segmented button { height: 40px; }
  .chip, .us-chip, .us-chk, .tabs > button, [role="tab"], .nav-item, .filters button, .fb-big-sm { min-height: 44px; }
  .nav-item { padding-block: 10px; }
  .wa-rail button { width: 44px; min-height: 44px; }
  .qo-msg__x { width: 44px; height: 44px; }
  .wa-etqc { height: 32px; }
  button.wa-etqc { height: 32px; position: relative; overflow: visible; }   /* 27/11: os 32 px valem (o css do WhatsApp carrega depois) e o ::after leva o toque a 44 px; o nome corta no span */
  button.wa-etqc::after { content: ""; position: absolute; inset: -6px -3px; }
  /* links e botões pequenos dentro de texto ganham área de toque sem mudar o desenho */
  .wr-retry, .link-btn { position: relative; }
  .wr-retry::after, .link-btn::after { content: ""; position: absolute; inset: -10px -6px; }
}

/* ---------- C3 · janelas no celular ---------- */
@media (max-width: 640px) {
  .modal {
    left: 0; right: 0; top: auto; bottom: 0; width: 100% !important; max-width: 100%;
    max-height: calc(100dvh - 12px); border-radius: var(--r-xl) var(--r-xl) 0 0; border-bottom: 0;
    transform: translateY(32px); opacity: 0;
  }
  .modal.on { transform: none; opacity: 1; }
  .modal__head { padding: 14px 14px 12px 16px; }
  .modal__body { padding: 14px 16px 18px; overscroll-behavior: contain; }
  .modal__foot { flex-wrap: wrap; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .modal__foot .spacer { display: none; }
  /* botões empilhados: o principal embaixo, perto do polegar; textos longos quebram em vez de sumir */
  .modal__foot > .btn { flex: 1 1 100%; min-height: 48px; justify-content: center; white-space: normal; height: auto; padding-block: 10px; }
  .modal__foot > .btn-ghost, .modal__foot > .btn-quiet { order: -1; }
  .modal__foot > :not(.btn) { flex-basis: 100%; }
  /* O15 (revisão do comercial 10/11): nas janelas em passos (orçamento, Nova OS) o "Voltar" é um botão pequeno ao lado do
     "Continuar", numa linha só (antes ocupava uma linha inteira: 148 px de botões numa tela de 750) */
  .oq-wiz .modal__foot, .nx-modal .modal__foot { flex-wrap: wrap; align-items: center; }
  .oq-wiz .modal__foot > #oq-back, .nx-modal .modal__foot > #nx-back { flex: 0 0 auto; order: 2; min-height: 44px; padding-inline: 12px; }
  .oq-wiz .modal__foot > #oq-fbtns, .nx-modal .modal__foot > #nx-fbtns { flex: 1 1 0; order: 3; min-width: 0; display: flex; gap: 8px; }
  .oq-wiz .modal__foot > #oq-fbtns > .btn, .nx-modal .modal__foot > #nx-fbtns > .btn { flex: 1 1 auto; min-height: 44px; }
  .oq-wiz .modal__foot > #oq-back[style*="hidden"], .nx-modal .modal__foot > #nx-back[style*="hidden"] { display: none; }
  .nx-modal:not(.oq-wiz) .modal__foot > .btn:not(#nx-back) { flex: 1 1 0; order: 3; min-height: 44px; }
  .drawer { width: 100% !important; max-width: 100%; }
  .drawer__foot { flex-wrap: wrap; }
  .drawer__foot > .btn { flex: 1 1 auto; min-height: 48px; justify-content: center; }
}

/* ---------- T1 · letra maior no celular (mínimo de 13 px; texto corrido 14 px) ---------- */
@media (max-width: 900px) {
  :root { --fs-2xs: 12.5px; --fs-xs: 13px; --fs-sm: 14px; }
}
/* ---------- C14 · efeitos pesados desligados no celular (grão animado, luzes com desfoque, animação de entrada) ---------- */
@media (max-width: 900px), (prefers-reduced-motion: reduce) {
  .grain { display: none !important; }
  .page.enter { animation: none !important; }
  .spot::before, .spot::after { display: none !important; }
  .toast, .rd-faixa, .modal-conf { backdrop-filter: none !important; }
}

/* ---------- C4 · números do topo numa faixa compacta (a lista de trabalho aparece logo) ---------- */
@media (max-width: 640px) {
  .crm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 8px; margin-bottom: 12px; }
  .crm-stats .mini { padding: 9px 11px; gap: 8px; min-height: 0; }
  .crm-stats .mini__ic { display: none; }
  .crm-stats .mini b { font-size: var(--fs-md); }
  .crm-stats .mini small { font-size: var(--fs-2xs); }
  .crm-stats .mini span.muted, .crm-stats .mini > div > span { font-size: var(--fs-2xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------- C6 · filtros numa linha que rola para o lado ---------- */
@media (max-width: 640px) {
  .ox-filt__chips { flex-wrap: nowrap !important; overflow-x: auto; scrollbar-width: none; margin-inline: -14px; padding: 2px 14px 6px; overscroll-behavior-x: contain; }
  .ox-filt__chips::-webkit-scrollbar { display: none; }
  .ox-filt__chips > * { flex: none; }
  /* a linha que rola não pode esticar o cartão (grade com coluna mínima 0) */
  .ox-fbar, .oq-fbar { grid-template-columns: minmax(0, 1fr); }
  .ox-fbar > *, .oq-fbar > *, .ox-fbar__r2, .ox-filt, .ox-fbar .ox-filt { min-width: 0; max-width: 100%; }
  /* "Mais situações" abre por cima, preso embaixo da tela (a linha rolável cortaria o menu) */
  .ox-more__m { position: fixed !important; left: 12px; right: 12px; top: auto !important; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); min-width: 0 !important; max-height: 60dvh; overflow: auto; z-index: 420; }
}

/* ---------- C13 · Leitor QR: um botão só no celular (o grande do cartão; o da barra de baixo continua) ---------- */
@media (max-width: 768px) {
  .qrp-ler-topo, #qo-top { display: none !important; }
}

/* ---------- C11 · em tela de toque, o que só aparecia com o mouse fica sempre à vista ---------- */
@media (hover: none) {
  .os-foto__del { opacity: 1 !important; width: 40px; height: 40px; }
  .nx-sec .nx-sec__plus, .ox-art__zoom, .iac-img__zoom, .qf-nb, .iaa-graf__b { opacity: 1 !important; }
}

/* ---------- C8 · conversa do WhatsApp em tela cheia no celular (sem as barras de cima e de baixo) ---------- */
@media (max-width: 760px) {
  #wa.wr-app.chat-open { position: fixed; inset: 0; z-index: 350; height: auto !important; min-height: 0; margin: 0; border-radius: 0; border: 0;
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); background: var(--bg); }
  html:has(#wa.wr-app.chat-open) .qo-tabbar, html:has(#wa.wr-app.chat-open) .rd-semnet { display: none !important; }
  html:has(#wa.wr-app.chat-open) body { overflow: hidden; }
  /* a .page (z-index 1) prendia a conversa embaixo da barra de cima: com a conversa aberta, a barra sai e a página não
     segura mais a camada */
  html:has(#wa.wr-app.chat-open) .topbar { display: none !important; }
  html:has(#wa.wr-app.chat-open) .page { z-index: auto; }
}

/* ---------- C12 · OS no celular: "Ir para…" no lugar das 10 abas e uma faixa de ações ---------- */
.oa-tabsel { display: none; }
@media (max-width: 640px) {
  .oa-tabsel { display: block; position: sticky; top: 0; z-index: 8; margin: 0 -16px 14px; padding: 8px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
  .oa-tabsel .select { width: 100%; min-height: 46px; font-weight: 600; }
  .oa-tabs { display: none !important; }
  .ox-hero__acts { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 100%; }
  .ox-hero__acts > .btn { width: 100%; justify-content: center; white-space: normal; height: auto; min-height: 44px; padding-block: 8px; text-align: center; }
  .ox-hero__acts > .btn:first-child { grid-column: 1 / -1; }
}

/* ---------- C5 · listas em tabela viram um cartão por linha no celular (OS, Orçamentos, Funil, Clientes, itens) ---------- */
@media (max-width: 640px) {
  table.tbl-cards, table.tbl-cards tbody, table.tbl-cards tr, table.tbl-cards td { display: block; width: 100%; }
  table.tbl-cards { min-width: 0 !important; border-collapse: separate; }
  table.tbl-cards thead { display: none; }
  .table-wrap:has(> table.tbl-cards), .nx-tblw:has(> table.tbl-cards) { overflow: visible; border: 0; background: none; }
  .card:has(table.tbl-cards) { background: none; border: 0; box-shadow: none; padding: 0; }
  table.tbl-cards tr { margin: 0 0 10px; padding: 10px 12px; border: 1px solid var(--line-2); border-radius: var(--r-md); background: linear-gradient(180deg, var(--s2), var(--s1)); }
  table.tbl-cards td { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 4px 0 !important; border: 0 !important; text-align: right !important; min-width: 0; white-space: normal !important; }
  table.tbl-cards td::before { content: attr(data-label); flex: none; max-width: 42%; text-align: left; color: var(--tx-3); font-size: var(--fs-2xs); text-transform: uppercase; letter-spacing: .04em; }
  table.tbl-cards td[data-label=""]::before, table.tbl-cards td:not([data-label])::before { display: none; }
  /* a 1ª coluna (número / nome) é o título do cartão */
  table.tbl-cards td:first-child { display: block; text-align: left !important; font-size: var(--fs-md); padding-bottom: 6px !important; border-bottom: 1px solid var(--line) !important; margin-bottom: 4px; }
  table.tbl-cards td:first-child::before { display: none; }
  table.tbl-cards td > * { min-width: 0; }
  table.tbl-cards tr td[colspan] { display: block; text-align: left !important; }
  table.tbl-cards tr td[colspan]::before { display: none; }
}
