/* Regras compartilhadas de celular; desktop mantém o layout de cada tela. */
@media (max-width: 980px) {
  html { scroll-padding-top: 64px; }
  body { min-height: 100dvh; }
  .side-main, .container-fluid, .row > *, .card-body, .pa-box, .cn-box { min-width: 0; }
  .side-main > .container-fluid { padding: 12px !important; }
  .top-bar { padding-top: env(safe-area-inset-top); }
  .side-main { margin-left: 0; }
  .btn-menu { display: inline-flex !important; }
  .side-bar { transform: translateX(-100%); visibility: hidden; width: 260px; max-width: calc(100vw - 44px); height: 100dvh; }
  body.menu-aberto .side-bar { transform: translateX(0); visibility: visible; z-index: 1001; }
  body.menu-aberto .veu { display: block; }
  .nav-itens { padding-bottom: max(16px,env(safe-area-inset-bottom)); }
  .btn, button.nav-tab, .up-tab, .block-item, .svc-opt, summary { min-height: 44px; }
  .btn-close { min-width: 44px; min-height: 44px; box-sizing: border-box; }
  input:not([type=checkbox]):not([type=radio]), select, textarea { font-size: 16px !important; max-width: 100%; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; flex-shrink: 0; }
  .form-check { padding-block: 6px; }
  .input-group { max-width: 100%; }
  .modal-dialog { margin: 8px; max-width: calc(100vw - 16px); }
  .modal-content { max-height: calc(100dvh - 16px); }
  .modal-header, .modal-body, .modal-footer { padding: 12px; }
  .modal-body { overflow-y: auto; overscroll-behavior: contain; }
  .modal-footer { flex-wrap: wrap; padding-bottom: max(12px,env(safe-area-inset-bottom)); }
  .modal-footer > .btn { flex: 1 1 130px; white-space: normal; }
  pre { max-width: 100%; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
  .card-header, .pa-cab, .hist-entry-head, .overview-legend, .overview-map-toolbar { flex-wrap: wrap; }
  .pa-cab .pa-hint { margin-left: 0; flex-basis: 100%; }
  .pa-dn-leg { min-width: 0; width: 100%; }
  .pa-dn-nome, .cf-tag, .mpf-nota, .cl-hero-nome { overflow-wrap: anywhere; white-space: normal; min-width: 0; max-width: 100%; }
  .mon-tabs { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); overflow: visible; padding-bottom: 0; }
  .mon-tab { min-width: 0; padding: 10px !important; }
  .mon-tab small { white-space: normal !important; }
  .mon-subs { grid-template-columns: 1fr; }
  .mon-subs .mon-tab small { display: none; }
  .mobile-editor-workspace, .client-workspace { height: auto !important; }
  .client-workspace > .block-sidebar { width: 100% !important; height: auto !important; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .client-workspace > .block-sidebar > div:first-child { grid-column: 1/-1; }
  .client-workspace > .col { flex-basis: 100%; height: auto !important; overflow: visible !important; min-width: 0; }
  .mobile-editor-workspace > .block-sidebar { width: 100% !important; height: auto; max-height: 260px; overflow: auto; }
  .mobile-editor-workspace > .col { flex-basis: 100%; height: auto !important; overflow: visible !important; min-width: 0; }
  .mobile-editor-workspace #panel-empty { min-height: 120px; }
  #pn-eventos .ev-ctrls, #pn-eventos .ev-range { flex-wrap: wrap; max-width: 100%; }
  .up-cart { left: 8px; right: 8px; bottom: max(8px,env(safe-area-inset-bottom)); max-height: 40dvh; overflow-y: auto; }
  body:has(.up-cart:not(.d-none)) .side-main { padding-bottom: 42dvh; }
  .mpd { width: 100vw !important; max-width: 100vw !important; height: 100dvh !important; }
  .mpd .grid { grid-template-columns: 1fr !important; }
  #mp-mapa { height: 65dvh; min-height: 320px; }
  .mobile-table-scroll, .table-responsive:has(table:not(.tbl-cartao)) {
    max-width: 100%; min-width: 0; overflow-x: auto !important; overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }
  .mobile-wide-table { min-width: 580px; }
  .mobile-table-scroll:focus-visible { outline: 2px solid var(--accent,#324681); outline-offset: -2px; }
  /* Mapas/diagramas mantêm os rótulos legíveis e rolam dentro do próprio quadro. */
  .overview-map-scroll { max-width: 100%; overflow-x: auto; }
  .login-card { margin: 12px; padding: 24px 18px; }
}
@media (min-width: 981px) {
  .mobile-table-scroll { display: contents; }
}

@media (max-width:980px) {
  .up-head, .up-head-right { flex-wrap: wrap; min-width: 0; }
  .up-traf { white-space: normal; max-width: 100%; }
  .cf-tag-font { display: inline-block; }
}
@media (max-width:980px) {
  .btn-group-sm > .svc-opt { min-height: 44px; }
  .top-bar { overflow-x: auto; }
  .cs-fluxo { max-width: 100%; min-width: 0; }
}
@media (max-width:980px) {
  .overview-legend { min-width: 0; max-width: 100%; }
  .overview-legend span { white-space: normal; overflow-wrap: anywhere; max-width: 100%; min-width: 0; }
  #sg-postura .d-flex.text-center { flex-wrap: wrap; gap: 12px !important; max-width: 100%; margin-left: 0 !important; }
}

@media (max-width:980px) {
  .vx-abas { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .vx-abas a { padding:10px; }
  .mpd-tabs.mon-tabs { padding:12px; margin:0; }
}

@media (max-width:980px) {
  /* Seis ações em uma linha comprimiam os rótulos de prepend no celular. */
  .vx-tela .svc-row > .btn-group {
    grid-auto-flow: row;
    grid-auto-columns: auto;
    grid-template-columns: repeat(3,minmax(0,1fr));
    width: 100%; max-width: 100%; gap: 6px;
  }
  .vx-tela .svc-row > .btn-group > .svc-opt {
    min-height: 48px; padding: 6px;
    line-height: 1.3; white-space: normal; overflow-wrap: anywhere;
  }
}

@media (max-width:480px) {
  /* Rótulo e ícone precisam caber mesmo com texto ampliado no telefone. */
  .vx-tela .svc-row > .btn-group {
    grid-template-columns: repeat(auto-fit,minmax(min(100%,120px),1fr)); gap: 8px;
  }
  .vx-tela .svc-row > .btn-group > .svc-opt {
    width: 100%; max-width: 100%; box-sizing: border-box;
    min-height: 52px; padding: 8px; flex-wrap: wrap; text-align: center;
  }
  .vx-tela .svc-row > .btn-group > .svc-opt:nth-child(3):last-child { grid-column: 1 / -1; }
}
