/* ==========================================================================
   ERP — Camada de usabilidade (desktop + celular)
   --------------------------------------------------------------------------
   Carregado depois do tema. Só acrescenta: alvos de toque, foco visível,
   estados de botão (carregando/desabilitado), campos legíveis no celular,
   modais e tabelas responsivos. Não altera cores nem o layout desktop.
   ========================================================================== */

/* ---- Foco visível por teclado (acessibilidade e Tab/Enter) --------------- */
:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 3px solid color-mix(in srgb, var(--erp-primary, #2563eb) 45%, transparent);
    outline-offset: 2px;
}
.btn:focus-visible { box-shadow: 0 0 0 4px color-mix(in srgb, var(--erp-primary, #2563eb) 30%, transparent); }

/* ---- Feedback de clique -------------------------------------------------- */
.btn { transition: transform .08s ease, box-shadow .15s ease, background-color .15s ease; -webkit-tap-highlight-color: transparent; }
.btn:active:not(:disabled):not(.disabled) { transform: translateY(1px) scale(.99); }

/* ---- Botão carregando (aplicado por form-ux.js) -------------------------- */
.btn.is-loading { position: relative; pointer-events: none; opacity: .85; }
.btn.is-loading::after {
    content: ""; display: inline-block; width: 1em; height: 1em; margin-left: .55em;
    vertical-align: -0.15em; border: 2px solid currentColor; border-right-color: transparent;
    border-radius: 50%; animation: erp-spin .7s linear infinite;
}
@keyframes erp-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
    .btn, .btn.is-loading::after { transition: none; animation-duration: 1.6s; }
}

/* ---- Botões desabilitados: deixa claro que não clicam -------------------- */
.btn[disabled], .btn.disabled, fieldset[disabled] .btn { cursor: not-allowed; opacity: .55; }

/* ---- Tabelas que não têm wrapper responsivo (envolvidas por form-ux.js) -- */
.erp-table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ==========================================================================
   Celular / tablet / telas de toque
   ========================================================================== */
@media (max-width: 991px), (pointer: coarse) {

    /* Campos: 44px de altura e 16px de fonte (evita o zoom automático do iPhone) */
    .form-control,
    .input-group-addon,
    .select2-container--default .select2-selection--single,
    .select2-container--default .select2-selection--multiple {
        min-height: 44px;
        font-size: 16px;
    }
    .form-control { padding-top: 9px; padding-bottom: 9px; }
    .select2-container--default .select2-selection--single { display: flex; align-items: center; }
    .select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 1.4; width: 100%; }
    .select2-container--default .select2-selection--single .select2-selection__arrow { height: 100%; }
    textarea.form-control { min-height: 88px; }

    /* Botões: alvo mínimo de toque (44px; compactos 38px) */
    .btn { min-height: 44px; padding-top: 10px; padding-bottom: 10px; }
    .btn-sm, .btn-xs, .btn-group-sm > .btn, .btn-group-xs > .btn { min-height: 38px; padding: 8px 12px; font-size: 14px; }
    .btn-lg { min-height: 52px; }
    .btn-group > .btn, .input-group-btn > .btn { min-height: 44px; }

    /* Menus de ação (dropdown "Ações" das tabelas) com itens tocáveis */
    .dropdown-menu > li > a { padding: 12px 18px; font-size: 15px; }

    /* Caixas de seleção e rádios maiores (iCheck e nativos) */
    .icheckbox_square-blue, .iradio_square-blue { transform: scale(1.2); transform-origin: left center; margin-right: 4px; }
    input[type="checkbox"]:not([class*="icheck"]), input[type="radio"]:not([class*="icheck"]) { width: 20px; height: 20px; }

    /* Labels e ajuda mais legíveis */
    label { font-size: 14px; }
    .help-block, small.text-muted { font-size: 13px; }

    /* Campos empilhados: tira o risco de colunas muito estreitas */
    .form-group { margin-bottom: 14px; }

    /* Botões de ação de formulário: largura total e empilhados */
    .box-footer .btn, .modal-footer .btn { min-width: 120px; }
    .modal-footer { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
    .modal-footer .btn { margin: 0; flex: 1 1 140px; }

    /* Modais ocupam a tela inteira no celular (mais espaço para digitar) */
    .modal-dialog { margin: 0; width: 100%; max-width: 100%; }
    .modal-content { border-radius: 0; min-height: 100vh; }
    .modal.fade .modal-dialog { transition: transform .2s ease-out; }

    /* Tabelas rolam na horizontal em vez de estourar a tela */
    .table-responsive { border: 0; }
    .content { padding-left: 10px; padding-right: 10px; }

    /* Cabeçalho "x" de fechar do modal maior */
    .modal-header .close { font-size: 32px; padding: 6px 12px; margin-top: -8px; opacity: .7; }

    /* SweetAlert / toastr com botões tocáveis */
    .swal-button { min-height: 44px; padding: 10px 22px; }
    #toast-container > div { width: auto; max-width: 92vw; }
}

/* Telas bem pequenas: botões de ação em coluna */
@media (max-width: 575px) {
    .box-footer .btn, form .text-right > .btn { width: 100%; margin: 4px 0; }
    .content-header > h1 { font-size: 20px; }
    #mass_delete_bar .btn { width: 100%; margin: 6px 0 0; white-space: normal; }
}

/* Barra de ações fixa no rodapé em formulários longos (use a classe .erp-sticky-actions) */
.erp-sticky-actions {
    position: sticky; bottom: 0; z-index: 20; padding: 10px 0;
    background: var(--erp-surface, #fff); border-top: 1px solid var(--erp-border, #e5e8ef);
    box-shadow: 0 -6px 16px rgba(15, 23, 42, .06);
}
