/* Ajustes finais, carregados por último para consolidar o comportamento responsivo. */
@media (min-width: 1024px) {
    .history-toolbar { justify-content: flex-end; }
}

@media (min-width: 1280px) {
    /* As páginas ficam dentro de #page-content; use toda a área útil e
       preserve apenas o respiro lateral do próprio portal-main. */
    .portal-main #page-content > section.mx-auto.max-w-7xl { max-width: none; width: 100%; margin-inline: 0; }
    .portal-main #page-content > section.portal-home-shell { max-width: none; width: 100%; margin-inline: 0; }
    .portal-main #page-content > section.mx-auto.max-w-5xl { max-width: min(100%, 84rem); }
}

@media (min-width: 1536px) {
    .portal-main { padding-left: 2rem !important; padding-right: 2rem !important; }
    .portal-main #page-content > section.mx-auto.max-w-5xl { max-width: min(100%, 94rem); }
}

@media (min-width: 1800px) {
    .portal-main { padding-left: 2.5rem !important; padding-right: 2.5rem !important; }
}

@media (max-width: 1023px) {
    .admin-shell-card,
    .portal-responsive-main-card { max-width: 100%; }

    .dashboard-filter-primary-grid,
    .history-filter-primary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 768px) {
    .portal-main {
        padding-left: 0.9rem !important;
        padding-right: 0.9rem !important;
        padding-top: 4.75rem !important;
    }

    .portal-mobile-toggle {
        top: 0.85rem;
        left: 0.85rem;
        height: 3rem;
        width: 3rem;
        border-radius: 1rem;
    }

    .portal-responsive-main-card {
        padding: 1rem !important;
        border-radius: 1.5rem !important;
    }

    .portal-responsive-hero { gap: 0.85rem; }

    .portal-responsive-hero > span:first-child {
        height: 3rem !important;
        width: 3rem !important;
        border-radius: 1rem !important;
    }

    .portal-responsive-hero > span:first-child i { font-size: 1.35rem !important; }

    .portal-responsive-hero-copy h1:not(.portal-page-title),
    .portal-responsive-hero-copy h2 {
        font-size: 1.75rem !important;
        line-height: 1.1 !important;
    }

    .portal-responsive-hero-copy p[class*='leading-7'] { line-height: 1.55 !important; }
    .portal-responsive-upload-head { flex-direction: column; align-items: flex-start; }

    .portal-responsive-upload-head label,
    .portal-responsive-upload-head a,
    .portal-responsive-upload-head button {
        width: 100%;
        justify-content: center;
    }

    .portal-responsive-sidepanel { gap: 0.85rem !important; }
    .portal-responsive-frame-shell { min-height: calc(100svh - 5.4rem); }
}

@media (max-width: 480px) {
    .portal-main {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        padding-top: 4.35rem !important;
        padding-bottom: 1rem !important;
    }

    .portal-mobile-toggle {
        top: 0.75rem;
        left: 0.75rem;
        height: 2.75rem;
        width: 2.75rem;
    }

    .portal-mobile-toggle .bi { font-size: 1.55rem !important; }
    .portal-responsive-main-card { padding: 0.9rem !important; border-radius: 1.35rem !important; }
    .portal-responsive-hero { gap: 0.75rem; margin-bottom: 1.25rem !important; }

    .portal-responsive-hero-copy h1:not(.portal-page-title),
    .portal-responsive-hero-copy h2 { font-size: 1.55rem !important; }

    .portal-responsive-hero-copy p[class*='leading-7'],
    .portal-responsive-hero-copy p[class*='leading-6'] { font-size: 0.92rem !important; }

    .portal-responsive-stats { grid-template-columns: 1fr; }
    #flash-messages { left: 0.75rem; right: 0.75rem; top: 0.75rem; }
    #flash-messages > * { width: 100%; }
    .portal-responsive-frame-shell { min-height: calc(100svh - 4.8rem); }
}

@media (max-width: 900px) and (orientation: landscape) {
    .portal-main { padding-top: 1rem !important; }
    .portal-mobile-toggle { top: 0.6rem; left: 0.6rem; }
}

@media (max-width: 767px) {
    .admin-shell-card,
    .dashboard-panel,
    .portal-responsive-main-card { padding: var(--ui-space-4) !important; }

    .admin-shell-card h1 { font-size: var(--ui-text-xl); }

    .admin-section-nav,
    .emissor-tabs-list {
        gap: var(--ui-space-2);
        max-width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding: var(--ui-space-2);
    }

    .emissor-page .emissor-tabs-list { display: none; }
    .emissor-mobile-module-select-wrap { display: block; }

    .admin-section-link,
    .emissor-tab-link,
    .dashboard-filter-actions > *,
    .history-filter-primary-actions > * {
        min-height: 2.75rem;
    }

    .dashboard-filter-primary-grid,
    .history-filter-primary-grid,
    .dashboard-overview-grid,
    .portal-responsive-stats { grid-template-columns: minmax(0, 1fr); }

    .dashboard-filter-actions,
    .history-filter-primary-actions { width: 100%; justify-content: stretch; }

    .dashboard-filter-actions > *,
    .history-filter-primary-actions > * { flex: 1 1 100%; width: 100%; }

    .dashboard-more-filters-dialog,
    .history-more-filters-dialog {
        width: min(100%, calc(100% - 1rem));
        max-height: calc(100dvh - 1rem);
    }
}

@media (max-width: 639px) {
    .admin-metric-grid,
    .dashboard-metrics-grid { grid-template-columns: minmax(0, 1fr); }

    .portal-responsive-actions > *,
    .portal-sienge-actions > a { width: 100%; }

    .portal-responsive-hero-copy h1:not(.portal-page-title),
    .portal-responsive-hero-copy h2 { font-size: clamp(1.5rem, 8vw, 2rem) !important; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* Ajustes compactos da sidebar por altura da viewport. */
@media (max-height: 820px) {
    .sidebar-footer {
        margin-top: 0.4rem;
        padding-top: 0.45rem;
    }

    .sidebar-footer .portal-user-card {
        min-height: 3.2rem;
        padding: 0.45rem 0.65rem;
    }

    .sidebar-footer .portal-theme-toggle {
        min-height: 2.8rem;
        padding: 0.4rem 0.6rem;
    }

    .sidebar-footer .sidebar-logout-link {
        min-height: 2.8rem;
        height: 2.8rem;
        width: 2.8rem;
        padding: 0;
    }

    html.sidebar-collapsed .sidebar-footer,
    body.sidebar-collapsed .sidebar-footer {
        margin-top: 0.6rem;
        padding-top: 0.65rem;
    }

    html.sidebar-collapsed .portal-user-card,
    body.sidebar-collapsed .portal-user-card,
    html.sidebar-collapsed .portal-theme-toggle,
    body.sidebar-collapsed .portal-theme-toggle,
    html.sidebar-collapsed .sidebar-logout-link,
    body.sidebar-collapsed .sidebar-logout-link {
        width: 2.75rem;
        min-width: 2.75rem;
        min-height: 2.75rem;
        margin-inline: auto;
    }

    html.sidebar-collapsed .portal-user-card .h-10.w-10,
    body.sidebar-collapsed .portal-user-card .h-10.w-10,
    html.sidebar-collapsed .portal-theme-toggle .h-10.w-10,
    body.sidebar-collapsed .portal-theme-toggle .h-10.w-10 {
        height: 2.2rem;
        width: 2.2rem;
    }

    html.sidebar-collapsed .sidebar-footer-actions,
    body.sidebar-collapsed .sidebar-footer-actions {
        gap: 0.35rem;
        margin-top: 0.35rem;
    }
}
