/*
 * Responsive foundation
 * Regras estruturais compartilhadas. A identidade visual continua pertencendo
 * aos estilos de cada modulo; este arquivo impede overflow e controles cortados.
 */

html {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
    color-scheme: dark;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
}

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

:where(main, header, footer, nav, section, article, aside, form, fieldset, div) {
    min-width: 0;
}

:where(img, video, canvas, iframe, svg) { max-width: 100%; }
:where(img, video) { height: auto; }
:where(iframe) { display: block; border: 0; }

:where(input, select, textarea, button) {
    max-width: 100%;
    font: inherit;
}

:where(button, a, input, select, textarea, [role="button"]) {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(111, 225, 255, .14);
}

:where(button, [role="button"]):not(:disabled) { cursor: pointer; }
:where(textarea) { resize: vertical; }

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid rgba(111, 225, 255, .92);
    outline-offset: 3px;
}

:where(h1, h2, h3, h4, p, a, button, label, td, th) {
    overflow-wrap: anywhere;
}

:where(h1, h2, h3) { text-wrap: balance; }
:where(p) { text-wrap: pretty; }
:where(h1, h2, h3, h4, [id]) { scroll-margin-block-start: 96px; }
:where(td, th, [class*="stat"], [class*="metric"]) { font-variant-numeric: tabular-nums; }

:where([hidden]) { display: none !important; }

:where(.table-responsive, .table-wrapper, .table-wrap, .admin-table-wrap, .responsive-table) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

:where(.modal, .dialog-overlay, .popup-overlay, [class*="-modal-overlay"]) {
    overscroll-behavior: contain;
}

:where(.modal-card, .dialog, [class*="-dialog"], [class*="-modal-card"]) {
    max-width: calc(100vw - 24px);
}

@media (max-width: 1024px) {
    :root { --responsive-gutter: clamp(14px, 2.4vw, 24px); }

    :where(.admin-main, .admin-content, .dashboard-content, .main-content, .page-content) {
        max-width: 100%;
        min-width: 0;
    }

    :where(.actions, .page-actions, .header-actions, .toolbar-actions, .panel-actions) {
        flex-wrap: wrap;
    }
}

/* Notebooks: reduz altura ociosa e preserva mais conteudo acima da dobra. */
@media (min-width: 769px) and (max-width: 1440px) {
    .community-index .topbar {
        width: min(1180px, calc(100% - 24px));
        height: 74px;
    }

    .community-index .app-main {
        width: min(1120px, calc(100% - 24px));
        margin-top: 8px;
    }

    .community-index .home-feature-carousel {
        --home-carousel-height: clamp(330px, 34vw, 440px);
        margin-top: 20px;
    }
}

@media (min-width: 769px) and (max-height: 760px) {
    .community-index .home-feature-carousel {
        --home-carousel-height: clamp(300px, 32vw, 400px);
    }
}

@media (max-width: 768px) {
    :root {
        --responsive-gutter: clamp(10px, 3.2vw, 18px);
        --responsive-touch: 44px;
    }

    body { min-height: 100dvh; }

    html { scroll-padding-block-end: calc(96px + env(safe-area-inset-bottom)); }

    :where(.page-shell, .content-shell, .admin-main, .dashboard-main, .main-content) {
        max-width: 100%;
    }

    :where(.modal, .dialog-overlay, .popup-overlay, [class*="-modal-overlay"]) {
        padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom));
    }

    :where(.modal-card, .dialog, [class*="-dialog"], [class*="-modal-card"]) {
        width: min(100%, 640px);
        max-width: 100%;
        max-height: calc(100dvh - max(16px, calc(env(safe-area-inset-top) + env(safe-area-inset-bottom))));
        margin-inline: auto;
    }

    :where(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
        width: 100%;
        min-width: 0;
        font-size: max(16px, 1em);
    }

    :where(button, [role="button"], .btn, .action-btn) { min-height: var(--responsive-touch); }

    :where(.actions, .page-actions, .header-actions, .toolbar-actions, .panel-actions, .dialog-actions) {
        gap: 8px;
    }

    :where(.actions, .page-actions, .header-actions, .toolbar-actions, .panel-actions, .dialog-actions) > :where(button, .btn, .action-btn, a) {
        flex: 1 1 auto;
    }

    :where(table) { max-width: none; }

    :where(.bottom-nav, .mobile-nav, .ecosystem-nav) {
        max-width: calc(100vw - 12px);
        margin-inline: auto;
        padding-bottom: env(safe-area-inset-bottom);
    }

    .community-index .topbar,
    .community-index .app-main {
        width: auto;
        max-width: none;
        margin-inline: max(10px, env(safe-area-inset-left)) max(10px, env(safe-area-inset-right));
    }

    .community-index .topbar {
        grid-template-columns: minmax(0, 1fr) auto auto;
    }

    .community-index .brand { min-width: 0; }

    .community-index .app-nav {
        right: max(6px, env(safe-area-inset-right));
        left: max(6px, env(safe-area-inset-left));
        width: auto;
        max-width: 760px;
    }

    .community-index .app-nav > .nav-item { min-width: 0; }
}

/* Portal publico: sete destinos e tres controles no cabecalho precisam de uma
   faixa intermediaria propria, antes do breakpoint de celulares pequenos. */
@media (max-width: 620px) {
    .community-index .topbar {
        grid-template-columns: auto minmax(0, 1fr) auto;
        column-gap: 8px;
        width: auto;
    }

    .community-index .brand span,
    .community-index .user-chip-copy { display: none; }

    .community-index .brand img {
        width: 40px;
        height: 46px;
    }

    .community-index .language-picker {
        justify-self: end;
        min-width: 0;
        padding-inline: 7px;
    }

    .community-index .user-chip {
        width: 44px;
        min-width: 44px;
        height: 44px;
        justify-content: center;
        padding: 3px;
    }

    .community-index .app-nav {
        grid-template-columns: repeat(7, minmax(0, 1fr));
        width: auto;
        padding-inline: 4px;
        overflow: visible;
    }

    .community-index .app-nav > .nav-item {
        width: 100%;
        min-width: 0;
        padding-inline: 0;
    }
}

@media (max-width: 380px) {
    .community-index .app-nav .nav-item > span:last-child { display: none; }
    .community-index .app-nav { min-height: 64px; }
}

@media (max-width: 480px) {
    :root { --responsive-gutter: 10px; }

    :where(.stats-grid, .metric-grid, .summary-grid) > * { min-width: 0; }

    :where(.actions, .page-actions, .header-actions, .toolbar-actions, .panel-actions, .dialog-actions).stack-mobile > * {
        flex-basis: 100%;
        width: 100%;
    }

    :where(.modal-card, .dialog, [class*="-dialog"], [class*="-modal-card"]) {
        border-radius: min(20px, 5vw);
    }

    .community-index .topbar {
        margin-inline: max(8px, env(safe-area-inset-left)) max(8px, env(safe-area-inset-right));
    }

    .community-index .language-picker { min-height: 42px; }
    .community-index .user-chip { flex: 0 0 44px; }
}

@media (orientation: landscape) and (max-height: 540px) {
    :where(.modal, .dialog-overlay, .popup-overlay, [class*="-modal-overlay"]) {
        align-items: flex-start;
    }

    :where(.modal-card, .dialog, [class*="-dialog"], [class*="-modal-card"]) {
        max-height: calc(100dvh - 12px);
    }
}

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

@media (hover: hover) and (pointer: fine) {
    html { scrollbar-gutter: stable; }
}
