/*
 * Responsividade transversal do GestaoEmpresa.
 *
 * Esta folha é carregada pelos layouts público e administrativo. As páginas
 * continuam livres para ter estilos próprios, mas estas regras garantem uma
 * base consistente em telemóveis, tablets, monitores grandes e dispositivos
 * com safe-area (iPhone/iPad).
 */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: clamp(15px, calc(14px + .25vw), 18px);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    min-width: 320px;
    max-width: 100%;
    overflow-x: hidden;
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

img,
picture,
video,
canvas,
svg,
iframe {
    max-width: 100%;
}

img,
picture,
video,
canvas,
svg {
    height: auto;
}

button,
a,
input,
select,
textarea,
[role="button"] {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

button,
.btn,
a.btn,
input[type="submit"],
input[type="button"] {
    min-height: 44px;
}

input,
select,
textarea {
    max-width: 100%;
}

textarea {
    min-height: 110px;
    resize: vertical;
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
a,
button,
label,
small,
strong,
span,
th,
td {
    overflow-wrap: anywhere;
}

/* Containers não podem criar uma largura mínima que force scroll horizontal. */
.container,
.container-fluid,
.row,
main,
section,
article,
form,
fieldset,
.card,
.panel {
    min-width: 0;
    max-width: 100%;
}

/*
 * Wrappers de tabelas e GridView. A tabela mantém a legibilidade e o utilizador
 * pode deslocá-la horizontalmente apenas dentro do seu próprio painel.
 */
.table-responsive,
.table-wrap,
.tablebox,
.table-area,
.table-container,
.gridviewer,
.grid-view,
.gridview,
.dataTables_wrapper,
.rh-table-wrap,
.ponto-table-wrap,
.scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.table-responsive > table,
.table-wrap > table,
.tablebox > table,
.table-area > table,
.table-container > table,
.gridviewer > table,
.grid-view > table,
.gridview > table,
.dataTables_wrapper table,
.rh-table-wrap > table,
.ponto-table-wrap > table {
    min-width: 640px;
    width: 100%;
}

table {
    max-width: 100%;
}

th,
td {
    max-width: 32rem;
    vertical-align: top;
}

/* Grelhas e barras de filtros colapsam sem produzir colunas ilegíveis. */
.form-grid,
.form-row,
.filters,
.toolbar,
.actions,
.form-actions,
.button-row,
.modal-actions,
.public-nav-actions {
    min-width: 0;
    max-width: 100%;
}

.form-grid > *,
.form-row > *,
.filters > *,
.toolbar > *,
.actions > *,
.form-actions > *,
.button-row > *,
.modal-actions > * {
    min-width: 0;
    max-width: 100%;
}

/* O cabeçalho público mantém os acessos e as redes separados em telas estreitas. */
.topbar-account-socials,
.topbar-socials,
.public-nav-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .45rem;
}

.topbar-account-socials {
    min-width: 0;
    max-width: 100%;
}

.topbar-account-link {
    white-space: normal;
    text-align: center;
}

.public-main-nav,
.public-main-nav .navbar-brand,
.public-main-nav .navbar-collapse,
.public-nav-links,
.public-nav-actions {
    min-width: 0;
}

.public-main-nav .navbar-brand img {
    width: clamp(78px, 8vw, 125px);
    height: auto;
}

.public-nav-actions {
    justify-content: flex-end;
}

.public-nav-actions > a {
    max-width: 100%;
    text-align: center;
    white-space: normal;
}

/* Imagens grandes não podem empurrar o conteúdo do carrossel para fora. */
.carousel-shell,
.header-carousel,
.header-carousel-item,
.carousel-caption,
.carousel-caption-inner {
    min-width: 0;
    max-width: 100%;
}

.carousel-caption-inner {
    width: min(100%, 960px);
}

/* Modais e iframes cabem na altura útil do telefone, incluindo orientação horizontal. */
.modal-dialog {
    width: min(calc(100% - 1rem), 1140px);
    max-width: calc(100% - 1rem);
    margin: .5rem auto;
}

.modal-content {
    max-height: calc(100dvh - 1rem);
    overflow: hidden;
}

.modal-body {
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.modal iframe {
    width: 100%;
    max-width: 100%;
    min-height: min(70dvh, 720px);
}

/* Evita zoom automático do Safari ao focar campos e preserva a leitura. */
@media (max-width: 767.98px) {
    input,
    select,
    textarea {
        font-size: max(16px, 1rem);
    }

    .container,
    .container-fluid {
        padding-left: max(12px, env(safe-area-inset-left, 0px));
        padding-right: max(12px, env(safe-area-inset-right, 0px));
    }

    .row {
        --bs-gutter-x: 1rem;
    }

    .form-grid,
    .form-row,
    .filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .public-main-nav {
        padding-left: max(10px, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(10px, env(safe-area-inset-right, 0px)) !important;
    }

    .public-nav-actions {
        align-items: stretch;
    }

    .public-nav-actions > a {
        flex: 1 1 10rem;
    }

    .carousel-caption-inner {
        padding: clamp(12px, 4vw, 24px) !important;
    }

    .carousel-caption h1,
    .header-carousel h1 {
        font-size: clamp(1.9rem, 7vw, 3.5rem) !important;
        line-height: 1.08;
    }

    .carousel-caption p {
        font-size: clamp(1rem, 3.5vw, 1.25rem) !important;
        line-height: 1.45;
    }

    .carousel-caption .btn {
        width: 100%;
        margin-right: 0 !important;
        margin-left: 0 !important;
    }
}

@media (max-width: 575.98px) {
    h1 {
        font-size: clamp(1.55rem, 8vw, 2.25rem);
    }

    h2 {
        font-size: clamp(1.3rem, 6vw, 1.9rem);
    }

    .form-grid,
    .form-row,
    .filters {
        grid-template-columns: minmax(0, 1fr);
    }

    .form-actions,
    .button-row,
    .modal-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .form-actions > .btn,
    .button-row > .btn,
    .modal-actions > .btn,
    .form-actions > button,
    .button-row > button,
    .modal-actions > button {
        width: 100%;
    }

    .modal-dialog {
        width: calc(100% - .5rem);
        max-width: calc(100% - .5rem);
        margin: .25rem auto;
    }

    .modal-content {
        max-height: calc(100dvh - .5rem);
        border-radius: .75rem;
    }

    .table-responsive > table,
    .table-wrap > table,
    .tablebox > table,
    .table-area > table,
    .table-container > table,
    .gridviewer > table,
    .grid-view > table,
    .gridview > table,
    .dataTables_wrapper table,
    .rh-table-wrap > table,
    .ponto-table-wrap > table {
        min-width: 560px;
    }
}

@media (pointer: coarse) {
    button,
    .btn,
    a.btn,
    input[type="submit"],
    input[type="button"],
    .topbar-account-link,
    .topbar-social-btn,
    .nav-link {
        min-height: 48px;
    }

    .topbar-social-btn {
        min-width: 48px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

@media print {
    .topbar,
    .navbar-toggler,
    .public-nav-actions,
    .soft-chat-fallback,
    #softAreaChatButton,
    .modal {
        display: none !important;
    }

    body {
        overflow: visible;
        padding: 0;
    }
}
