/* Base responsiva dos módulos autorizados do SmartNFe.
   O recurso só é incluído nas páginas autorizadas. A classe confirma o escopo no cliente.
   Acima de 1024px a composição de computador permanece intacta; o clássico não é alterado. */
@media (max-width: 1024px) {
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) { padding: 12px; min-width: 0; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) :is(form, .ui-g, .ui-panel, .ui-panel-content, .ui-tabs, .ui-tabs-panel, .ui-fieldset, .ui-fieldset-content) { min-width: 0; max-width: 100%; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .fieldSetPrincipal { padding: 12px 8px; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-fieldset > .ui-fieldset-legend { max-width: 100%; white-space: normal; overflow-wrap: anywhere; box-sizing: border-box; }

    /* Menus: manter todos os comandos existentes e permitir alcançar os últimos itens. */
    html.sf-pilot-modern.sf-responsive-initial body .layout-menu { max-width: calc(100vw - 24px); }
    html.sf-pilot-modern.sf-responsive-initial body .layout-menu .ultima-menu li > a { min-height: 44px; white-space: normal; overflow-wrap: anywhere; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body .topbar .topbar-items { max-width: calc(100vw - 24px); max-height: calc(100vh - 96px); max-height: calc(100dvh - 96px); overflow-y: auto; }
    html.sf-pilot-modern.sf-responsive-initial body .topbar .ui-selectonemenu { max-width: 100%; min-width: 0; }

    /* Barra de ações e seus filtros: quebrar a linha, preservando a ordem e os menus filhos. */
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-menubar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: 100%; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-menubar > .ui-menu-list { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-menubar > .ui-menu-list > .ui-menuitem { float: none; max-width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-menubar .ui-menubar-options { float: none !important; max-width: 100%; margin-left: auto; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-menubar .ui-button-text { white-space: normal; overflow-wrap: anywhere; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-button { min-height: 40px; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-button-icon-only { min-width: 40px; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .sf-responsive-grid { display: block; width: 100%; max-width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .sf-responsive-grid > tbody { display: block; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .sf-responsive-grid > tbody > tr { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .sf-responsive-grid > tbody > tr > td { display: block; flex: 1 1 200px; min-width: 0; max-width: 100%; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .sf-responsive-toolbar-grid > tbody > tr > td { flex: 0 1 auto; padding: 4px; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-grid .ui-spacer { display: none; }

    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-section { width: 100%; min-width: 0; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboardTecnico body .sf-responsive-field { width: 50%; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboardTecnico body .sf-responsive-field.ui-md-12 { width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboardTecnico body [id$="outputPanelVisualizaCoraCode"] { min-width: 0 !important; max-width: 100%; box-sizing: border-box; }

    /* Formulários: duas colunas no tablet para campos que antes ficavam muito estreitos. */
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-form .sf-responsive-field { width: 50%; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-form .sf-responsive-field.ui-md-12 { width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field :is(.ui-autocomplete, .ui-calendar, .ui-inputnumber, .ui-password, .ui-selectonemenu, .ui-selectcheckboxmenu) { max-width: 100%; min-width: 0; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field .md-inputfield { min-width: 0; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field :is(.ui-selectbooleanbutton, .ui-selectonebutton .ui-button, .ui-selectmanybutton .ui-button) .ui-button-text { white-space: normal; line-height: 1.4; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field .ui-selectbooleanbutton { height: auto !important; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field .ui-selectonemenu-label { overflow: hidden; text-overflow: ellipsis; }

    /* Abas não encolhem seus títulos; a navegação horizontal fica dentro da própria faixa. */
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-tabs .ui-tabs-nav { display: flex; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; max-width: 100%; -webkit-overflow-scrolling: touch; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-tabs .ui-tabs-nav > li { flex: 0 0 auto; float: none; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-tabs .ui-tabs-nav > li > a { min-height: 44px; white-space: nowrap; box-sizing: border-box; }

    /* Tabelas editáveis e cabeçalhos personalizados mantêm sua estrutura. Rolagem localizada. */
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-datatable { max-width: 100%; min-width: 0; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-datatable-tablewrapper { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-datatable-scrollable-body { max-width: 100%; overflow-x: auto; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-datatable .ui-paginator { white-space: normal; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-datatable .ui-paginator-current { display: block; white-space: normal; margin: 8px 0; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content, .ui-dialog) .ui-datatable .ui-paginator :is(.ui-paginator-first, .ui-paginator-prev, .ui-paginator-next, .ui-paginator-last, .ui-paginator-page) { min-width: 36px; min-height: 36px; line-height: 36px; padding: 0 6px; box-sizing: border-box; }

    /* Painel de busca da Filial e do Perfil continua fora do menubar para receber digitação. */
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-config-search { width: 100% !important; max-width: 520px; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-config-search > .md-inputfield { min-width: 0; }
    html.sf-pilot-modern.sf-responsive-initial body #buscaConfiguracaoFilial { height: 44px !important; font-size: 16px; }
    html.sf-pilot-modern.sf-responsive-initial body .botaoBuscaConfigFilial { height: 44px !important; width: 44px !important; flex: 0 0 44px; }
    html.sf-pilot-modern.sf-responsive-initial body #buscaConfiguracaoFilialResultados { max-width: calc(100vw - 48px); max-height: 55vh; max-height: 55dvh; overflow: auto; text-align: left; }

    /* Diálogos: não forçar display, preservando o estado aberto/fechado do PrimeFaces. */
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog { max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog:is(.dialogoSistema, .dialogoSistema2) { top: 8px !important; height: auto !important; max-height: calc(100vh - 16px) !important; max-height: calc(100dvh - 16px) !important; overflow: hidden !important; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog .ui-dialog-titlebar { padding: 12px; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog .ui-dialog-title { max-width: calc(100% - 40px); white-space: normal; overflow-wrap: anywhere; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog .ui-dialog-titlebar-close { min-width: 36px; min-height: 36px; display: flex; align-items: center; justify-content: center; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog .ui-dialog-content { max-height: calc(100vh - 136px) !important; max-height: calc(100dvh - 136px) !important; overflow: auto !important; padding: 12px; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog .ui-dialog-footer { padding: 10px 12px; white-space: normal; }

    /* Dashboard: indicadores e gráficos ganham espaço sem mudar valores ou consultas. */
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard:not(.sf-pilot-dashboardTecnico) body .sf-responsive-metric,
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard:not(.sf-pilot-dashboardTecnico) body .sf-responsive-chart { width: 50%; min-width: 0; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period { margin-top: 0 !important; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period > .ui-md-3 { display: none; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period > .ui-md-6 { width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period .sf-responsive-grid { width: 50%; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period .sf-responsive-grid > tbody > tr > td { flex: 1 1 auto; padding: 4px; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period .ui-inputgroup { display: flex; flex-wrap: wrap; min-width: 0; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period .ui-inputgroup > .ui-outputlabel { width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period .ui-calendar { min-width: 0; flex: 1; }
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period .ui-calendar input { width: 100%; min-height: 44px; font-size: 16px; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-chart .ui-chart { max-width: 100%; }
}
@media (max-width: 767px) {
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) { padding: 8px; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-form .sf-responsive-field,
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboardTecnico body .sf-responsive-field { width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field :is(input.ui-inputfield, textarea.ui-inputfield) { font-size: 16px; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field :is(.ui-inputtext, .ui-inputnumber-input, .ui-autocomplete-input, .ui-inputmask) { min-height: 44px; box-sizing: border-box; }
    html.sf-pilot-modern.sf-responsive-initial body .sf-responsive-field .md-inputfield > label { max-width: 100%; white-space: normal; line-height: 1.3; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .sf-responsive-grid > tbody > tr > td { flex-basis: 100%; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .sf-responsive-toolbar-grid > tbody > tr > td { flex-basis: auto; }
    html.sf-pilot-modern.sf-responsive-initial body :is(.layout-main, .sf-responsive-standalone-content) .ui-menubar .ui-menubar-options { width: 100%; margin-left: 0; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog .sf-responsive-field { width: 100%; }
}
@media (max-width: 640px) {
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-responsive-metric,
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-responsive-chart,
    html.sf-pilot-modern.sf-responsive-initial.sf-pilot-dashboard body .sf-pilot-period .sf-responsive-grid { width: 100%; }
    html.sf-pilot-modern.sf-responsive-initial body .ui-dialog { width: calc(100vw - 16px) !important; }
    html.sf-pilot-modern.sf-responsive-initial body .topbar .topbar-items { right: 8px; }
}
