/**
 * AMOSH System - Mobile-First CSS
 * Fase 3 da refatoração de responsividade
 * Criado em: 29/11/2025
 *
 * Abordagem Mobile-First:
 * - Estilos base são para mobile (< 576px)
 * - Usamos min-width para expandir para telas maiores
 * - Breakpoints Bootstrap 5: SM(576) MD(768) LG(992) XL(1200) XXL(1400)
 */

/* ===== CORREÇÃO CRÍTICA: OVERFLOW HORIZONTAL (iOS + Android) ===== */

/* Previne scroll horizontal em toda a página */
html {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    /* Android Chrome fix */
    -webkit-overflow-scrolling: touch;
}

body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    position: relative;
    /* Previne pull-to-refresh indesejado no Android Chrome */
    overscroll-behavior-y: contain;
    /* Android text rendering */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Wrapper principal do CMS */
#kt_wrapper,
.wrapper {
    max-width: 100vw !important;
    overflow-x: hidden !important;
}

/* Content area */
#kt_content,
.content {
    max-width: 100% !important;
    overflow-x: hidden !important;
}

/* Container principal - FORÇA 100% no mobile */
@media screen and (max-width: 991px) {
    .container,
    .container-fluid {
        max-width: 100% !important;
        width: 100% !important;
        padding-left: 12px !important;
        padding-right: 12px !important;
        overflow-x: hidden !important;
    }

    /* Flex containers */
    .d-flex.flex-column.flex-root,
    .d-flex.flex-row.flex-column-fluid.page,
    .d-flex.flex-column.flex-row-fluid.wrapper,
    .d-flex.flex-column-fluid {
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* Row do Bootstrap */
    .row {
        margin-left: -6px !important;
        margin-right: -6px !important;
    }

    .row > * {
        padding-left: 6px !important;
        padding-right: 6px !important;
    }

    /* Cards do Metronic */
    .card {
        max-width: 100% !important;
    }

    .card-body {
        max-width: 100% !important;
        overflow-x: auto;
    }

    /* Tabelas responsivas */
    .table-responsive,
    .table-responsive-sm,
    .table-responsive-md {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    table {
        max-width: 100%;
    }
}

/* ===== BASE MOBILE STYLES (< 576px) ===== */

/* Reset para Mobile-First */
*,
*::before,
*::after {
    box-sizing: border-box;
}

/* Body com Safe Areas iOS */
body {
    font-size: var(--fs-base);
    line-height: 1.5;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

/* ===== TIPOGRAFIA FLUIDA ===== */

/* Headings com tipografia fluida */
h1, .h1 {
    font-size: var(--fs-xxl);
    line-height: 1.2;
    margin-bottom: var(--space-md);
}

h2, .h2 {
    font-size: var(--fs-xl);
    line-height: 1.25;
    margin-bottom: var(--space-sm);
}

h3, .h3 {
    font-size: var(--fs-lg);
    line-height: 1.3;
    margin-bottom: var(--space-sm);
}

h4, .h4,
h5, .h5,
h6, .h6 {
    font-size: var(--fs-base);
    line-height: 1.4;
    margin-bottom: var(--space-xs);
}

p {
    font-size: var(--fs-base);
    margin-bottom: var(--space-sm);
}

small, .small {
    font-size: var(--fs-sm);
}

.text-xs {
    font-size: var(--fs-xs);
}

/* ===== LAYOUT MOBILE ===== */

/*
 * NOTA: NÃO sobrescrever .card, .card-body do Bootstrap/Metronic!
 * Os estilos globais de cards são do framework.
 * Use classes específicas como .amosh-card para novos componentes.
 */

/* Cards AMOSH específicos (não afeta Bootstrap) */
.amosh-card {
    width: 100%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-md);
}

.amosh-card .amosh-card-body {
    padding: var(--space-sm);
}

.amosh-card .amosh-card-header,
.amosh-card .amosh-card-footer {
    padding: var(--space-sm);
}

/* ===== FORMULÁRIOS MOBILE ===== */

/* Inputs com touch targets */
.form-control,
.custom-select,
select,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="date"],
input[type="search"],
textarea {
    width: 100%;
    min-height: var(--touch-min);
    padding: var(--touch-padding);
    font-size: var(--fs-base);
    border-radius: var(--radius-sm);
    transition: var(--transition-base);
}

/* Botões Mobile */
.btn {
    min-height: var(--touch-min);
    padding: var(--touch-padding) var(--space-md);
    font-size: var(--fs-base);
    border-radius: var(--radius-sm);
    transition: var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
}

/* Botões full-width no mobile */
.btn-block-mobile {
    width: 100%;
}

/* ===== TABELAS RESPONSIVAS ===== */

/* Tabela scroll horizontal no mobile */
.table-responsive-mobile {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ===== NAVEGAÇÃO MOBILE ===== */

/* Menu mobile */
.nav-mobile {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.nav-mobile .nav-link {
    min-height: var(--touch-min);
    padding: var(--touch-padding);
    display: flex;
    align-items: center;
}

/* ===== GRID MOBILE-FIRST ===== */

/* Grid utilitário */
.grid {
    display: grid;
    gap: var(--space-sm);
    grid-template-columns: 1fr;
}

.grid-2 {
    grid-template-columns: repeat(2, 1fr);
}

/* Flex utilities mobile */
.flex-col-mobile {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

/* ===== MODAIS MOBILE ===== */

/* Modal responsivo no mobile - NÃO full-screen para melhor UX */
.modal-dialog {
    margin: 10px;
    max-width: calc(100% - 20px);
    min-height: auto;
}

.modal-content {
    border-radius: 8px;
    min-height: auto;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

/* ===== SAFE AREAS (iPhone X+) ===== */

/* Containers com safe areas */
.safe-container {
    padding-left: max(var(--space-sm), var(--safe-left));
    padding-right: max(var(--space-sm), var(--safe-right));
}

/* Footer fixo com safe area */
.fixed-bottom-safe {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding-bottom: calc(var(--space-sm) + var(--safe-bottom));
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

/* Header fixo com safe area */
.fixed-top-safe {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    padding-top: calc(var(--space-sm) + var(--safe-top));
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

/* ===== CONTAINER QUERIES (Cards Responsivos) ===== */

/* Container query wrapper */
.card-container {
    container-type: inline-size;
    container-name: card;
}

/* Card responsivo baseado no container */
@container card (min-width: 300px) {
    .card-container .card-body {
        padding: var(--space-md);
    }

    .card-container .card-title {
        font-size: var(--fs-lg);
    }
}

@container card (min-width: 500px) {
    .card-container .card-body {
        padding: var(--space-lg);
    }

    .card-container .card-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-md);
    }
}

/* Widget container query */
.widget-container {
    container-type: inline-size;
    container-name: widget;
}

@container widget (min-width: 250px) {
    .widget-container .widget-content {
        display: flex;
        align-items: center;
        gap: var(--space-sm);
    }
}

@container widget (min-width: 400px) {
    .widget-container .widget-content {
        gap: var(--space-md);
    }

    .widget-container .widget-title {
        font-size: var(--fs-lg);
    }
}

/* =====================================================
   BREAKPOINT: SM (576px+) - Mobile Grande
   ===================================================== */
@media screen and (min-width: 576px) {
    /* Container */
    .container {
        max-width: 540px;
    }

    /* Grid 2 colunas */
    .grid-sm-2 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Botão normal (não full-width) */
    .btn-block-mobile {
        width: auto;
    }

    /* Cards lado a lado */
    .card-group-sm {
        display: flex;
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .card-group-sm .card {
        flex: 1 1 calc(50% - var(--space-sm));
    }
}

/* =====================================================
   BREAKPOINT: MD (768px+) - Tablet
   ===================================================== */
@media screen and (min-width: 768px) {
    /* Container */
    .container {
        max-width: 720px;
        padding-left: var(--space-md);
        padding-right: var(--space-md);
    }

    /* Card body maior - somente para .amosh-card */
    .amosh-card .amosh-card-body {
        padding: var(--space-md);
    }

    /* Grid 3 colunas */
    .grid-md-3 {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Flex row no tablet */
    .flex-col-mobile {
        flex-direction: row;
        flex-wrap: wrap;
    }

    /* Modal não full-screen */
    .modal-dialog {
        margin: var(--space-lg) auto;
        max-width: 500px;
        min-height: auto;
    }

    .modal-content {
        border-radius: var(--radius-lg);
        min-height: auto;
    }

    /* Modal grande - .modal-lg está na mesma div que .modal-dialog */
    .modal-dialog.modal-lg {
        max-width: 800px;
    }

    /* Navigation horizontal */
    .nav-mobile {
        flex-direction: row;
        gap: var(--space-md);
    }

    /* Hide on tablet+ */
    .hide-md-up {
        display: none !important;
    }
}

/* =====================================================
   BREAKPOINT: LG (992px+) - Laptop
   ===================================================== */
@media screen and (min-width: 992px) {
    /* Container */
    .container {
        max-width: 960px;
    }

    /* Grid 4 colunas */
    .grid-lg-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Tipografia maior - somente para .amosh-card */
    .amosh-card .amosh-card-title {
        font-size: var(--fs-lg);
    }

    /* Sidebar visível */
    .sidebar-lg {
        display: block;
        width: 250px;
    }

    /* Hide on desktop */
    .hide-lg-up {
        display: none !important;
    }

    /* Show only on desktop */
    .show-lg-up {
        display: block !important;
    }
}

/* =====================================================
   BREAKPOINT: XL (1200px+) - Desktop
   ===================================================== */
@media screen and (min-width: 1200px) {
    /* Container */
    .container {
        max-width: 1140px;
    }

    /* Container padding maior */
    .container,
    .container-fluid {
        padding-left: var(--space-lg);
        padding-right: var(--space-lg);
    }

    /* Card body ainda maior - somente para .amosh-card */
    .amosh-card .amosh-card-body {
        padding: var(--space-lg);
    }

    /* Grid gaps maiores */
    .grid {
        gap: var(--space-md);
    }
}

/* =====================================================
   BREAKPOINT: XXL (1400px+) - Desktop Grande
   ===================================================== */
@media screen and (min-width: 1400px) {
    /* Container */
    .container {
        max-width: 1320px;
    }

    /* Espaçamentos ainda maiores - somente para .amosh-card */
    .amosh-card .amosh-card-body {
        padding: var(--space-xl);
    }
}

/* ===== UTILITIES RESPONSIVAS ===== */

/* Spacing responsivo */
.p-responsive {
    padding: var(--space-sm);
}

.m-responsive {
    margin: var(--space-sm);
}

.gap-responsive {
    gap: var(--space-sm);
}

@media screen and (min-width: 768px) {
    .p-responsive {
        padding: var(--space-md);
    }

    .m-responsive {
        margin: var(--space-md);
    }

    .gap-responsive {
        gap: var(--space-md);
    }
}

@media screen and (min-width: 1200px) {
    .p-responsive {
        padding: var(--space-lg);
    }

    .m-responsive {
        margin: var(--space-lg);
    }

    .gap-responsive {
        gap: var(--space-lg);
    }
}

/* ===== DASHBOARD WIDGETS ===== */

/* Widget responsivo com container queries */
.dashboard-widget {
    container-type: inline-size;
    container-name: dashboard-widget;
}

/* Base mobile */
.dashboard-widget .widget-icon {
    width: 40px;
    height: 40px;
    font-size: var(--fs-lg);
}

.dashboard-widget .widget-value {
    font-size: var(--fs-xl);
    font-weight: 700;
}

.dashboard-widget .widget-label {
    font-size: var(--fs-sm);
    color: #6c757d;
}

@container dashboard-widget (min-width: 200px) {
    .dashboard-widget .widget-icon {
        width: 50px;
        height: 50px;
    }

    .dashboard-widget .widget-content {
        display: flex;
        align-items: center;
        gap: var(--space-md);
    }
}

@container dashboard-widget (min-width: 300px) {
    .dashboard-widget .widget-icon {
        width: 60px;
        height: 60px;
        font-size: var(--fs-xl);
    }

    .dashboard-widget .widget-value {
        font-size: var(--fs-xxl);
    }
}

/* ===== CALENDÁRIO RESPONSIVO ===== */

/* Calendário base mobile */
.fc-header-toolbar.fc-toolbar {
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.fc-toolbar-title {
    font-size: var(--fs-lg) !important;
}

@media screen and (min-width: 768px) {
    .fc-header-toolbar.fc-toolbar {
        flex-wrap: nowrap;
    }

    .fc-toolbar-title {
        font-size: var(--fs-xl) !important;
    }
}

/* ===== TABELA SCROLL ===== */

/* Altura responsiva para tabelas */
.table-scroll {
    height: var(--height-card-md);
    max-height: 460px;
    overflow-y: auto;
}

@media screen and (min-width: 768px) {
    .table-scroll {
        height: var(--height-card-lg);
        max-height: 500px;
    }
}

/* ===== CHARTS RESPONSIVOS ===== */

.chart-container {
    container-type: inline-size;
    container-name: chart;
}

.chart-height {
    width: 100%;
    height: var(--height-card-sm);
    max-height: 300px;
}

@container chart (min-width: 400px) {
    .chart-height {
        height: var(--height-card-md);
        max-height: 400px;
    }
}

@container chart (min-width: 600px) {
    .chart-height {
        height: var(--height-card-lg);
        max-height: 500px;
    }
}

/* ===== ANIMAÇÕES RESPONSIVAS ===== */

/* Reduz animações em mobile para performance */
@media screen and (max-width: 767.98px) {
    *,
    *::before,
    *::after {
        animation-duration: 0.1s !important;
        transition-duration: 0.1s !important;
    }
}

/* Respeita preferência do usuário */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== DASHBOARD CARDS RESPONSIVOS ===== */

/* Base Mobile - Cards do Dashboard */
.card.card-custom.card-stretch {
    margin-bottom: var(--space-sm);
}

/* Card header responsivo */
.card.card-custom .card-header {
    padding: var(--space-sm);
    flex-wrap: wrap;
    gap: var(--space-xs);
}

.card.card-custom .card-header .card-title {
    font-size: var(--fs-base);
    margin-bottom: 0;
}

/* Card body responsivo */
.card.card-custom .card-body {
    padding: var(--space-sm);
}

/* Card footer responsivo */
.card.card-custom .card-footer {
    padding: var(--space-sm);
}

/* Lista de membros/itens no mobile */
.card.card-custom .d-flex.align-items-center.mb-10 {
    margin-bottom: var(--space-sm) !important;
    padding: var(--space-xs);
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--radius-sm);
}

/* Symbol/Avatar menor no mobile */
.card.card-custom .symbol.symbol-40 {
    width: 36px !important;
    height: 36px !important;
}

.card.card-custom .symbol.symbol-40 .symbol-label {
    width: 36px !important;
    height: 36px !important;
}

/* Timeline responsiva */
.card.card-custom .timeline.timeline-6 .timeline-item .timeline-label {
    width: 80px;
    font-size: var(--fs-sm);
}

/* Altura máxima para cards de lista no mobile */
.card.card-custom.card-custom-size-board {
    height: auto !important;
    min-height: 350px;
    max-height: none !important;
}

.card.card-custom.card-custom-size-board .card-body {
    min-height: 300px;
    max-height: 350px;
    overflow-y: auto;
}

/* FullCalendar específico - precisa de altura definida para renderizar */
#bord-calender .card.card-custom.card-custom-size-board {
    min-height: 400px;
}

#bord-calender .card.card-custom.card-custom-size-board .card-body {
    min-height: 350px;
    max-height: 400px;
    overflow: visible;
}

/* Containers com scroll para listas (Dashboard cards) */
.celulas-wrap {
    height: 390px;
    overflow-y: auto;
}

.celulas-wrap1 {
    height: 455px;
    overflow-y: auto;
}

/* Container do calendário precisa de altura para FullCalendar */
#calendar {
    min-height: 300px;
}

/* FullCalendar listMonth view - garantir visibilidade */
.fc-list {
    min-height: 280px;
}

.fc-list-table {
    min-height: 250px;
}

/* Ajuste para a lista vazia do FullCalendar */
.fc .fc-list-empty {
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Breakpoint MD (768px+) */
@media screen and (min-width: 768px) {
    .card.card-custom.card-stretch {
        margin-bottom: var(--space-md);
    }

    .card.card-custom .card-header {
        padding: 1rem 1.5rem;
    }

    .card.card-custom .card-header .card-title {
        font-size: var(--fs-lg);
    }

    .card.card-custom .card-body {
        padding: 1rem 1.5rem;
    }

    .card.card-custom .d-flex.align-items-center.mb-10 {
        margin-bottom: 1rem !important;
        padding: 0;
        background: transparent;
        border-radius: 0;
    }

    .card.card-custom .symbol.symbol-40 {
        width: 40px !important;
        height: 40px !important;
    }

    .card.card-custom .symbol.symbol-40 .symbol-label {
        width: 40px !important;
        height: 40px !important;
    }

    .card.card-custom .timeline.timeline-6 .timeline-item .timeline-label {
        width: 100px;
        font-size: var(--fs-base);
    }

    .card.card-custom.card-custom-size-board {
        height: 50vh !important;
    }

    .card.card-custom.card-custom-size-board .card-body {
        max-height: none;
    }
}

/* Breakpoint LG (992px+) */
@media screen and (min-width: 992px) {
    .card.card-custom .card-header {
        padding: 1.5rem 2rem;
    }

    .card.card-custom .card-body {
        padding: 1.5rem 2rem;
    }
}

/* =====================================================
   DISPOSITIVOS ANDROID POPULARES - BREAKPOINTS ESPECÍFICOS
   ===================================================== */

/*
 * Dispositivos Android mais comuns (viewport widths):
 * - Samsung Galaxy S23/S24: 360px - 384px
 * - Samsung Galaxy S24 Ultra: 384px
 * - Samsung Galaxy A series: 360px - 412px
 * - Xiaomi/Redmi: 360px - 393px
 * - Motorola: 360px - 412px
 * - Google Pixel: 393px - 412px
 * - OnePlus: 360px - 412px
 */

/* Android Small (360px) - Galaxy A, Moto G, Xiaomi Redmi */
@media screen and (min-width: 360px) and (max-width: 375px) {
    .container,
    .container-fluid {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .card-body {
        padding: 12px !important;
    }

    /* Tipografia otimizada para telas pequenas Android */
    h1, .h1 { font-size: 1.5rem; }
    h2, .h2 { font-size: 1.3rem; }
    h3, .h3 { font-size: 1.15rem; }

    /* Botões touch-friendly */
    .btn {
        min-height: 44px;
        padding: 10px 16px;
    }

    .btn-sm {
        min-height: 44px;
        padding: 10px 14px;
    }

    /* Forms */
    .form-control,
    select {
        height: 44px;
        font-size: 16px;
    }
}

/* Android Medium (376px - 412px) - Galaxy S series, Pixel, OnePlus */
@media screen and (min-width: 376px) and (max-width: 412px) {
    .container,
    .container-fluid {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    .card-body {
        padding: 14px !important;
    }

    /* Tipografia */
    h1, .h1 { font-size: 1.6rem; }
    h2, .h2 { font-size: 1.35rem; }
    h3, .h3 { font-size: 1.2rem; }

    /* Botões */
    .btn {
        min-height: 46px;
        padding: 11px 18px;
    }

    /* Forms */
    .form-control,
    select {
        height: 46px;
    }

    /* Stats cards em grid 2x2 */
    .row.mb-4 {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .row.mb-4 > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }
}

/* Android Large (413px - 480px) - Tablets pequenos, Galaxy Tab */
@media screen and (min-width: 413px) and (max-width: 480px) {
    .container,
    .container-fluid {
        padding-left: 14px !important;
        padding-right: 14px !important;
    }

    .card-body {
        padding: 16px !important;
    }

    /* Tipografia */
    h1, .h1 { font-size: 1.7rem; }
    h2, .h2 { font-size: 1.4rem; }

    /* Botões */
    .btn {
        min-height: 48px;
    }

    /* Forms */
    .form-control,
    select {
        height: 48px;
    }
}

/* =====================================================
   CORREÇÕES ESPECÍFICAS PARA ANDROID CHROME/WEBVIEW
   ===================================================== */

/* Android Chrome - fix para inputs */
@supports (-webkit-touch-callout: none) or (not (-webkit-overflow-scrolling: touch)) {
    /* Previne zoom em inputs no Android */
    input, select, textarea {
        font-size: 16px !important;
        transform: scale(1);
    }

    /* Fix para select dropdown no Android */
    select {
        -webkit-appearance: none;
        -moz-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 36px;
    }
}

/* Android WebView específico */
@media screen and (-webkit-min-device-pixel-ratio: 1.5) {
    /* Alta densidade de pixels - Android comum */
    .btn-icon,
    .btn-action {
        min-width: 44px;
        min-height: 44px;
    }

    /* Avatares nítidos */
    .avatar-circle,
    .symbol-label {
        image-rendering: -webkit-optimize-contrast;
    }
}

@media screen and (-webkit-min-device-pixel-ratio: 2.5) {
    /* Densidade muito alta - Samsung S series, Pixel */
    .btn-icon,
    .btn-action {
        min-width: 48px;
        min-height: 48px;
    }
}

@media screen and (-webkit-min-device-pixel-ratio: 3) {
    /* Densidade ultra alta - Samsung S24 Ultra */
    .btn-icon,
    .btn-action {
        min-width: 48px;
        min-height: 48px;
    }

    /* Touch targets maiores */
    .nav-link,
    .dropdown-item,
    .list-group-item {
        min-height: 48px;
        padding-top: 12px;
        padding-bottom: 12px;
    }
}

/* =====================================================
   SAFE AREAS - iOS E ANDROID (com notch/punch hole)
   ===================================================== */

/* Safe areas para dispositivos com notch/punch hole */
@supports (padding: max(0px)) {
    /* Header */
    .header-mobile,
    #kt_header_mobile {
        padding-top: max(8px, env(safe-area-inset-top));
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    /* Footer/Navigation bottom */
    .footer,
    .fixed-bottom,
    .pagination-container {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    /* Modais */
    .modal-dialog {
        margin-top: max(20px, env(safe-area-inset-top));
        margin-bottom: max(20px, env(safe-area-inset-bottom));
    }

    /* Toasts */
    .toast-notification,
    .toast-amosh {
        top: max(20px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
    }

    /* Aside menu */
    .aside,
    #kt_aside {
        padding-top: max(0px, env(safe-area-inset-top));
        padding-bottom: max(0px, env(safe-area-inset-bottom));
    }
}

/* =====================================================
   ORIENTAÇÃO LANDSCAPE - iOS E ANDROID
   ===================================================== */

@media screen and (orientation: landscape) and (max-height: 500px) {
    /* Reduz padding em landscape */
    .container,
    .container-fluid {
        padding-left: 8px !important;
        padding-right: 8px !important;
    }

    .card-body {
        padding: 10px !important;
    }

    /* Header menor */
    .header-mobile,
    #kt_header_mobile {
        height: 50px;
    }

    /* Esconde elementos não essenciais */
    .page-header p,
    .stat-card p {
        display: none;
    }

    /* Cards em linha */
    .row.mb-4 {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto;
        gap: 8px;
    }

    .row.mb-4 > [class*="col-"] {
        flex: 0 0 auto;
        width: auto !important;
        min-width: 120px;
    }

    /* Modais menores */
    .modal-dialog {
        margin: 4px auto;
        max-height: calc(100vh - 8px);
    }

    .modal-content {
        max-height: calc(100vh - 16px);
    }
}

/* =====================================================
   TOUCH FEEDBACK - iOS E ANDROID
   ===================================================== */

/* Feedback visual ao tocar (substituição do hover) */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects em touch devices */
    .btn:hover,
    .card:hover,
    .nav-link:hover {
        transform: none;
        box-shadow: inherit;
    }

    /* Active state para touch */
    .btn:active {
        transform: scale(0.98);
        opacity: 0.9;
    }

    .card:active {
        transform: scale(0.995);
    }

    .nav-link:active,
    .dropdown-item:active {
        background-color: rgba(71, 18, 107, 0.1);
    }

    /* Touch ripple effect (Android-like) */
    .btn,
    .nav-link,
    .list-group-item {
        position: relative;
        overflow: hidden;
    }

    .btn::after,
    .nav-link::after {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 50%;
        transform: translate(-50%, -50%);
        transition: width 0.3s, height 0.3s;
    }

    .btn:active::after,
    .nav-link:active::after {
        width: 200%;
        height: 200%;
    }
}

/* =====================================================
   LAYOUT GLOBAL - Container e Margens Otimizadas
   ===================================================== */

/* Container principal - aproveita melhor as margens */
#main.container-fluid {
    padding-left: 25px !important;
    padding-right: 25px !important;
    max-width: 100% !important;
}

/* Tablet e Desktop */
@media screen and (min-width: 992px) {
    #main.container-fluid {
        padding-left: 30px !important;
        padding-right: 30px !important;
    }
}

/* Desktop grande */
@media screen and (min-width: 1400px) {
    #main.container-fluid {
        padding-left: 40px !important;
        padding-right: 40px !important;
    }
}

/* Mobile */
@media screen and (max-width: 991px) {
    #main.container-fluid {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
}

/* =====================================================
   MÓDULO: DASHBOARD - Responsividade iOS + Android
   ===================================================== */

/* Dashboard - Layout Mobile Base */
@media screen and (max-width: 767.98px) {
    /* Dashboard main row */
    #main > .row,
    .dashboard-row {
        margin-left: -8px !important;
        margin-right: -8px !important;
    }

    #main > .row > [class*="col-"],
    .dashboard-row > [class*="col-"] {
        padding-left: 8px !important;
        padding-right: 8px !important;
        margin-bottom: 12px !important;
    }

    /* Força cards em coluna única no mobile */
    #main > .row > [class*="col-lg-"],
    .dashboard-row > [class*="col-lg-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Blocos do Dashboard */
    #bord-members .card,
    #board-birthdays .card,
    #bord-calender .card {
        margin-bottom: 12px !important;
    }

    /* Título dos cards do Dashboard */
    .card-header .card-title h3,
    .card-header h3.card-title {
        font-size: 1rem !important;
        margin-bottom: 0;
    }

    /* Lista de membros recentes */
    #bord-members .d-flex.align-items-center.mb-10 {
        margin-bottom: 10px !important;
        padding: 8px;
        background: linear-gradient(135deg, rgba(71, 18, 107, 0.02) 0%, rgba(71, 18, 107, 0.05) 100%);
        border-radius: 8px;
        border: 1px solid rgba(71, 18, 107, 0.08);
    }

    /* Avatar na lista de membros */
    #bord-members .symbol.symbol-40,
    #board-birthdays .symbol.symbol-40 {
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0;
    }

    #bord-members .symbol-label,
    #board-birthdays .symbol-label {
        width: 40px !important;
        height: 40px !important;
    }

    /* Nome do membro */
    #bord-members .font-size-lg,
    #board-birthdays .font-size-lg {
        font-size: 0.95rem !important;
        line-height: 1.3;
        word-break: break-word;
    }

    /* Data/hora */
    #bord-members .text-muted,
    #board-birthdays .text-muted {
        font-size: 0.8rem !important;
    }

    /* Botão de editar membro */
    #bord-members .btn.btn-sm.btn-icon,
    #board-birthdays .btn.btn-sm.btn-icon {
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Aniversariantes de hoje */
    #board-birthdays .card-body {
        max-height: 300px;
        overflow-y: auto;
    }

    /* Calendário - Container */
    #bord-calender .card-body {
        padding: 10px !important;
    }

    #calendar {
        min-height: 280px;
    }

    /* FullCalendar - Toolbar */
    .fc .fc-toolbar {
        flex-direction: column !important;
        gap: 8px;
    }

    .fc .fc-toolbar-title {
        font-size: 1rem !important;
        text-align: center;
    }

    .fc .fc-button {
        padding: 8px 12px !important;
        font-size: 0.85rem !important;
        min-height: 40px;
    }

    .fc .fc-button-group {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* FullCalendar - Lista de eventos */
    .fc-list-event {
        padding: 8px !important;
    }

    .fc-list-event-title {
        font-size: 0.9rem !important;
    }

    .fc-list-event-time {
        font-size: 0.8rem !important;
    }

    /* Modal de evento do calendário */
    #editEvent .modal-dialog,
    #detailsEvent .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    #editEvent .modal-body .row > .col-6 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 16px;
    }

    #editEvent .form-group {
        margin-bottom: 12px !important;
    }

    #editEvent .form-group label {
        font-size: 0.9rem;
        margin-bottom: 4px;
    }

    #editEvent .form-control,
    #editEvent select,
    #editEvent textarea {
        font-size: 16px !important;
        min-height: 44px;
    }

    #editEvent .modal-footer {
        flex-direction: column;
        gap: 8px;
    }

    #editEvent .modal-footer .btn {
        width: 100%;
        min-height: 48px;
    }
}

/* Dashboard - Android Específico */
@media screen and (min-width: 360px) and (max-width: 412px) {
    /* Grid 2 colunas para widgets no Android */
    .dashboard-stats-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .dashboard-stats-row > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
    }

    /* Cards compactos para Android */
    .dashboard-stats-row .card-body {
        padding: 12px !important;
    }

    .dashboard-stats-row .card-title {
        font-size: 0.85rem !important;
    }

    .dashboard-stats-row .display-4 {
        font-size: 1.5rem !important;
    }
}

/* Dashboard - Tablet */
@media screen and (min-width: 768px) and (max-width: 991px) {
    #main > .row > [class*="col-lg-6"] {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    #main > .row > [class*="col-lg-12"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* =====================================================
   MÓDULO: MEMBROS (Person) - Responsividade iOS + Android
   ===================================================== */

/* Membros Lista - Mobile Base */
@media screen and (max-width: 767.98px) {
    /* Filtros em grid */
    #main .card-body > .row.form-group {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    #main .card-body > .row.form-group > [class*="col-lg-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Inputs de busca */
    #main .input-icon input,
    #main .form-control.picker,
    #main select.form-control {
        font-size: 16px !important;
        min-height: 48px;
        padding: 12px;
    }

    /* Input icon */
    #main .input-icon span {
        top: 50%;
        transform: translateY(-50%);
        right: 12px;
    }

    /* Botões de ação (Novo, Limpar, Buscar, Imprimir) */
    #main .d-flex.justify-content-between {
        flex-direction: column !important;
        gap: 12px;
    }

    #main .d-flex.justify-content-end {
        flex-wrap: wrap;
        gap: 8px;
    }

    #main .d-flex.justify-content-end .btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 100px;
        min-height: 48px;
        margin: 0 !important;
    }

    /* Botão Novo Membro - full width */
    #main a.btn.btn-success[href="Create"] {
        width: 100%;
        min-height: 48px;
        margin-bottom: 8px;
    }

    /* Tabela de membros */
    #main table {
        font-size: 0.85rem;
    }

    #main table thead {
        display: none;
    }

    #main table tbody tr {
        display: block;
        margin-bottom: 12px;
        padding: 12px;
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        border: 1px solid #eee;
    }

    #main table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid #f0f0f0;
    }

    #main table tbody td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        gap: 8px;
        padding-top: 12px;
    }

    #main table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #666;
        font-size: 0.8rem;
        text-transform: uppercase;
    }

    /* Botões de ação na tabela */
    #main table .btn.btn-sm.btn-icon {
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Bootstrap Select */
    .bootstrap-select {
        width: 100% !important;
    }

    .bootstrap-select .dropdown-toggle {
        min-height: 48px !important;
        padding: 12px !important;
        font-size: 16px !important;
    }

    .bootstrap-select .dropdown-menu {
        max-height: 50vh !important;
    }

    .bootstrap-select .dropdown-menu .dropdown-item {
        padding: 12px 16px !important;
        min-height: 44px;
    }
}

/* Membros - Editar/Criar - Mobile Base */
@media screen and (max-width: 991px) {
    /* Profile aside - escondido por padrão no mobile */
    #kt_profile_aside {
        display: none;
    }

    #kt_profile_aside.offcanvas-mobile-on {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 280px !important;
        height: 100vh;
        z-index: 1050;
        background: #fff;
        box-shadow: 0 0 30px rgba(0,0,0,0.2);
        overflow-y: auto;
    }

    .offcanvas-mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
    }

    /* Conteúdo principal ocupa toda largura */
    .flex-row-fluid {
        margin-left: 0 !important;
        width: 100% !important;
    }

    /* Card de edição */
    .flex-row-fluid .card-body {
        padding: 12px !important;
    }

    /* Tabs de navegação mobile */
    .navi.navi-bold.navi-hover {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .navi-link {
        min-height: 48px;
        padding: 12px 16px !important;
    }

    /* Perfil do membro */
    .symbol.symbol-60,
    .symbol.symbol-xxl-100 {
        width: 60px !important;
        height: 60px !important;
    }

    .font-size-h5 {
        font-size: 1.1rem !important;
    }

    /* Formulário de edição */
    .tab-item .form-group {
        margin-bottom: 16px !important;
    }

    .tab-item .row > [class*="col-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 8px;
    }

    /* Inputs do formulário */
    .tab-item .form-control,
    .tab-item select,
    .tab-item textarea {
        font-size: 16px !important;
        min-height: 48px;
    }

    /* Botões WhatsApp e Download */
    .btn-whats,
    .btn.btn-info.btn-icon {
        min-width: 48px;
        min-height: 48px;
    }
}

/* Membros - Android Específico */
@media screen and (min-width: 360px) and (max-width: 412px) {
    /* Filtros em 2 colunas onde faz sentido */
    #main .card-body > .row.form-group {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Duas colunas para status e tipo */
    #main .card-body > .row.form-group > .col-lg-4:nth-child(4),
    #main .card-body > .row.form-group > .col-lg-4:nth-child(5) {
        grid-column: span 1;
    }
}

/* =====================================================
   MÓDULO: IGREJAS (Church) - Responsividade iOS + Android
   ===================================================== */

/* Igrejas Lista - Mobile Base */
@media screen and (max-width: 767.98px) {
    /* Input group de data */
    .input-group.date {
        flex-direction: column;
        gap: 8px;
    }

    .input-group.date input {
        width: 100% !important;
        border-radius: 6px !important;
    }

    .input-group.date .input-group-prepend {
        display: none;
    }

    /* Botões de período (7, 30, 60, 90 dias) */
    .col-12.mt-2 {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .col-12.mt-2 .btn-sm {
        flex: 1 1 calc(25% - 6px);
        min-width: 60px;
        min-height: 40px;
        padding: 8px !important;
        font-size: 0.8rem !important;
    }

    /* Botões de ação */
    .d-flex.justify-content-end {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }

    .d-flex.justify-content-end .btn {
        flex: 1 1 calc(33% - 6px);
        min-height: 48px;
        margin: 0 !important;
    }

    /* Tabela de igrejas */
    #main table tbody td .btn.btn-sm.btn-icon {
        margin: 0 !important;
        min-width: 40px;
        min-height: 40px;
    }
}

/* Igrejas - Editar - Mobile Base */
@media screen and (max-width: 991px) {
    /* Link de auto cadastro */
    .form-group .input-group {
        flex-wrap: nowrap;
    }

    .form-group .input-group input {
        font-size: 0.85rem;
        padding: 10px;
    }

    .form-group .input-group-append {
        min-width: 48px;
    }

    /* Recorrência e outras tabs */
    .tab-item .card {
        margin-bottom: 12px;
    }

    .tab-item .card-body {
        padding: 12px;
    }
}

/* =====================================================
   MÓDULO: RELATÓRIOS (Reports) - Responsividade iOS + Android
   ===================================================== */

/* Relatórios - Mobile Base */
@media screen and (max-width: 767.98px) {
    /* Container de filtros */
    #filters.row {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    #filters.row > [class*="col-lg-"] {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    /* Labels */
    #filters label {
        font-size: 0.9rem;
        font-weight: 500;
        margin-bottom: 6px;
        display: block;
    }

    /* Input group de período */
    #filters .input-group.date {
        flex-direction: column;
        gap: 8px;
    }

    #filters .input-group.date input {
        width: 100% !important;
        border-radius: 6px !important;
        min-height: 48px;
        font-size: 16px !important;
    }

    #filters .input-group.date .input-group-append {
        display: none;
    }

    /* Selects */
    #filters select.form-control,
    #filters .bootstrap-select .dropdown-toggle {
        min-height: 48px;
        font-size: 16px !important;
    }

    /* Botões de ação */
    #filters .d-flex.justify-content-end {
        flex-direction: column;
        gap: 8px;
        padding-top: 8px;
    }

    #filters .d-flex.justify-content-end .btn {
        width: 100%;
        min-height: 52px;
        font-size: 1rem;
    }

    #filters .btn.btn-success {
        order: -1; /* Gerar Relatório primeiro */
    }
}

/* Relatórios - Tabela de Resultados Mobile */
@media screen and (max-width: 767.98px) {
    /* Wrapper para scroll horizontal */
    .table-responsive {
        margin: 0 -12px;
        padding: 0 12px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Indicador de scroll */
    .table-responsive::after {
        content: '→ Deslize para ver mais';
        display: block;
        text-align: center;
        font-size: 0.75rem;
        color: #999;
        padding: 8px;
    }

    /* Tabela mínima */
    .table-responsive table {
        min-width: 600px;
    }

    /* Células compactas */
    .table-responsive th,
    .table-responsive td {
        padding: 10px 8px;
        font-size: 0.85rem;
        white-space: nowrap;
    }

    /* Header fixo */
    .table-responsive thead th {
        position: sticky;
        top: 0;
        background: #f5f5f5;
        z-index: 10;
    }

    /* Valores numéricos */
    .table-responsive td[data-type="currency"],
    .table-responsive td[data-type="number"] {
        text-align: right;
        font-variant-numeric: tabular-nums;
    }
}

/* Relatórios - Android Específico */
@media screen and (min-width: 360px) and (max-width: 412px) {
    /* Grid 2 colunas para alguns filtros */
    #filters.row {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
    }

    /* Período lado a lado */
    #filters .input-group.date {
        flex-direction: row;
        gap: 4px;
    }

    #filters .input-group.date input {
        flex: 1;
        min-width: 0;
    }
}

/* =====================================================
   COMPONENTES GLOBAIS - Tabelas Responsivas
   ===================================================== */

/* Tabela responsiva com cards no mobile */
@media screen and (max-width: 767.98px) {
    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards tbody tr {
        display: block;
        margin-bottom: 12px;
        padding: 14px;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
        border: 1px solid rgba(71, 18, 107, 0.08);
    }

    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid #f0f0f0;
    }

    .table-mobile-cards tbody td:last-child {
        border-bottom: none;
    }

    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #47126b;
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }

    /* Coluna de ações */
    .table-mobile-cards tbody td.actions-cell {
        justify-content: center;
        gap: 8px;
        padding-top: 12px;
        margin-top: 8px;
        border-top: 1px solid #eee;
    }

    .table-mobile-cards tbody td.actions-cell::before {
        display: none;
    }
}

/* =====================================================
   COMPONENTES GLOBAIS - Paginação Responsiva
   ===================================================== */

@media screen and (max-width: 767.98px) {
    /* Paginação */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
    }

    .page-link {
        min-width: 40px;
        min-height: 40px;
        padding: 8px 12px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Esconde páginas intermediárias no mobile */
    .pagination .page-item:not(:first-child):not(:last-child):not(.active):not(:nth-child(2)):not(:nth-last-child(2)) {
        display: none;
    }

    /* Info de paginação */
    .dataTables_info,
    .pagination-info {
        font-size: 0.85rem;
        text-align: center;
        padding: 8px 0;
    }

    /* Select de itens por página */
    .dataTables_length select,
    .items-per-page select {
        min-height: 40px;
        padding: 8px 12px;
    }
}

/* =====================================================
   COMPONENTES GLOBAIS - Modais Responsivos iOS + Android
   ===================================================== */

@media screen and (max-width: 767.98px) {
    /* Modal base */
    .modal-dialog {
        margin: 8px !important;
        max-width: calc(100% - 16px) !important;
        max-height: calc(100vh - 16px);
    }

    .modal-content {
        border-radius: 12px;
        max-height: calc(100vh - 32px);
        overflow: hidden;
    }

    /* Modal header */
    .modal-header {
        padding: 14px 16px;
        border-bottom: 1px solid #eee;
    }

    .modal-title {
        font-size: 1.1rem;
    }

    .modal-header .close {
        min-width: 44px;
        min-height: 44px;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Modal body */
    .modal-body {
        padding: 16px;
        overflow-y: auto;
        max-height: calc(100vh - 180px);
        -webkit-overflow-scrolling: touch;
    }

    /* Modal footer */
    .modal-footer {
        padding: 12px 16px;
        border-top: 1px solid #eee;
        flex-wrap: wrap;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1 1 calc(50% - 4px);
        min-height: 48px;
    }

    /* Modal XL no mobile vira tela cheia */
    .modal-xl .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        height: 100vh;
        max-height: 100vh;
    }

    .modal-xl .modal-content {
        border-radius: 0;
        height: 100%;
        max-height: 100%;
    }

    .modal-xl .modal-body {
        max-height: calc(100vh - 130px);
    }
}

/* Modal - Safe Areas iOS */
@supports (padding: max(0px)) {
    @media screen and (max-width: 767.98px) {
        .modal-content {
            padding-top: max(0px, env(safe-area-inset-top));
            padding-bottom: max(0px, env(safe-area-inset-bottom));
        }

        .modal-xl .modal-content {
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* =====================================================
   COMPONENTES GLOBAIS - Toast/Alertas Responsivos
   ===================================================== */

@media screen and (max-width: 767.98px) {
    /* Toastr ajustes */
    #toast-container {
        top: auto !important;
        bottom: 16px !important;
        left: 16px !important;
        right: 16px !important;
    }

    #toast-container > .toast {
        width: 100% !important;
        max-width: none !important;
        margin-bottom: 8px;
        border-radius: 10px;
    }

    #toast-container > .toast .toast-message {
        font-size: 0.95rem;
    }
}

/* Toast - Safe Areas */
@supports (padding: max(0px)) {
    @media screen and (max-width: 767.98px) {
        #toast-container {
            bottom: max(16px, env(safe-area-inset-bottom)) !important;
            left: max(16px, env(safe-area-inset-left)) !important;
            right: max(16px, env(safe-area-inset-right)) !important;
        }
    }
}

/* =====================================================
   COMPONENTES GLOBAIS - Dropdown Responsivo
   ===================================================== */

@media screen and (max-width: 767.98px) {
    /* Dropdown menu */
    .dropdown-menu {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        top: auto !important;
        transform: none !important;
        max-height: 60vh;
        overflow-y: auto;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
        padding: 8px 0 16px;
        margin: 0;
    }

    .dropdown-menu::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: #ddd;
        border-radius: 2px;
        margin: 8px auto 16px;
    }

    .dropdown-item {
        padding: 14px 20px;
        min-height: 48px;
        display: flex;
        align-items: center;
    }

    .dropdown-item i {
        margin-right: 12px;
        font-size: 1.2rem;
    }

    /* Backdrop para dropdown */
    .dropdown.show::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: 999;
    }
}

/* Dropdown - Safe Areas */
@supports (padding: max(0px)) {
    @media screen and (max-width: 767.98px) {
        .dropdown-menu {
            padding-bottom: max(16px, env(safe-area-inset-bottom));
        }
    }
}

/* =====================================================
   LANDSCAPE MODE - Todos os módulos
   ===================================================== */

@media screen and (orientation: landscape) and (max-height: 500px) {
    /* Dashboard compacto */
    #bord-members .card-body,
    #board-birthdays .card-body {
        max-height: 200px;
        overflow-y: auto;
    }

    #bord-members .d-flex.align-items-center.mb-10 {
        margin-bottom: 6px !important;
        padding: 6px;
    }

    /* Calendário compacto */
    #calendar {
        min-height: 200px;
    }

    .fc .fc-toolbar-title {
        font-size: 0.9rem !important;
    }

    /* Membros - formulário compacto */
    .tab-item .form-group {
        margin-bottom: 8px !important;
    }

    .tab-item .form-control,
    .tab-item select {
        min-height: 40px;
    }

    /* Modais menores */
    .modal-dialog {
        margin: 4px auto !important;
    }

    .modal-body {
        max-height: calc(100vh - 120px);
        padding: 12px;
    }

    .modal-header,
    .modal-footer {
        padding: 8px 12px;
    }
}

/* =====================================================
   MÓDULO: CARTEIRINHAS - Responsividade COMPLETA iOS + Android
   ===================================================== */

/* ===== CARTEIRINHAS - Base Mobile (até 767px) ===== */
@media screen and (max-width: 767.98px) {

    /* === CONTAINER E LAYOUT GERAL === */
    #gerarApp,
    #configApp,
    #atualizaApp {
        padding: 0 12px !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    /* === PAGE HEADER === */
    #gerarApp .page-header,
    #configApp .page-header,
    #atualizaApp .page-header {
        margin-bottom: 16px !important;
    }

    #gerarApp .page-header .d-flex,
    #configApp .page-header .d-flex,
    #atualizaApp .page-header .d-flex {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px;
    }

    #gerarApp .page-header h2,
    #configApp .page-header h2,
    #atualizaApp .page-header h2 {
        font-size: 1.25rem !important;
        margin-bottom: 4px !important;
        word-break: break-word;
    }

    #gerarApp .page-header p,
    #configApp .page-header p,
    #atualizaApp .page-header p {
        font-size: 0.85rem !important;
        line-height: 1.4;
    }

    /* Botão Configurações - full width */
    #gerarApp .page-header .btn,
    #atualizaApp .page-header .btn {
        width: 100% !important;
        min-height: 48px;
        justify-content: center;
    }

    /* === STATS CARDS (Gerar Carteirinhas) === */
    #gerarApp .row.mb-4 {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    #gerarApp .row.mb-4 > .col-md-3 {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin-bottom: 0 !important;
    }

    #gerarApp .stat-card {
        padding: 14px 12px !important;
        min-height: 80px;
        border-radius: 10px !important;
    }

    #gerarApp .stat-details h3 {
        font-size: 1.75rem !important;
    }

    #gerarApp .stat-details p {
        font-size: 0.7rem !important;
        line-height: 1.2;
    }

    /* === CARD DE FILTROS === */
    #gerarApp .card.shadow-sm.mb-4 .card-body,
    #atualizaApp .card.shadow-sm.mb-4 .card-body {
        padding: 14px !important;
    }

    #gerarApp .card.shadow-sm.mb-4 .row,
    #atualizaApp .card.shadow-sm.mb-4 .row {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    #gerarApp .card.shadow-sm.mb-4 .row > [class*="col-"],
    #atualizaApp .card.shadow-sm.mb-4 .row > [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin-bottom: 0 !important;
    }

    /* Search box */
    #gerarApp .search-box input,
    #atualizaApp .search-box input {
        font-size: 16px !important;
        min-height: 48px !important;
        padding: 12px 12px 12px 44px !important;
    }

    #gerarApp .search-box i,
    #atualizaApp .search-box i {
        left: 14px !important;
        font-size: 16px;
    }

    /* Select de status */
    #gerarApp select.form-control,
    #atualizaApp select.form-control {
        font-size: 16px !important;
        min-height: 48px !important;
        padding: 12px !important;
    }

    /* Botões de ação - em grid 2 colunas */
    #gerarApp .card.shadow-sm.mb-4 .row > .col-md-4.text-right,
    #atualizaApp .card.shadow-sm.mb-4 .row > .col-md-4.text-right {
        text-align: center !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    #gerarApp .card.shadow-sm.mb-4 .btn,
    #atualizaApp .card.shadow-sm.mb-4 .btn {
        width: 100% !important;
        min-height: 48px !important;
        font-size: 0.85rem !important;
        padding: 10px 8px !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px;
    }

    #gerarApp .card.shadow-sm.mb-4 .btn i,
    #atualizaApp .card.shadow-sm.mb-4 .btn i {
        font-size: 1rem;
    }

    /* === TABELA DE MEMBROS === */
    #gerarApp .modern-table,
    #atualizaApp .modern-table {
        display: block !important;
    }

    #gerarApp .modern-table thead,
    #atualizaApp .modern-table thead {
        display: none !important;
    }

    #gerarApp .modern-table tbody,
    #atualizaApp .modern-table tbody {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        padding: 12px !important;
    }

    #gerarApp .modern-table tbody tr,
    #atualizaApp .modern-table tbody tr {
        display: flex !important;
        flex-direction: column !important;
        background: #fff !important;
        border-radius: 12px !important;
        padding: 14px !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06) !important;
        border: 1px solid rgba(71, 18, 107, 0.08) !important;
        position: relative;
    }

    #gerarApp .modern-table tbody tr.selected-row,
    #atualizaApp .modern-table tbody tr.selected-row {
        border-color: #47126B !important;
        background: rgba(71, 18, 107, 0.03) !important;
    }

    #gerarApp .modern-table tbody td,
    #atualizaApp .modern-table tbody td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 6px 0 !important;
        border: none !important;
        border-bottom: 1px solid #f0f0f0 !important;
        font-size: 0.9rem !important;
    }

    #gerarApp .modern-table tbody td:last-child,
    #atualizaApp .modern-table tbody td:last-child {
        border-bottom: none !important;
        padding-top: 12px !important;
        justify-content: center !important;
        gap: 12px !important;
    }

    /* Checkbox na primeira coluna - posição absoluta */
    #gerarApp .modern-table tbody td:first-child,
    #atualizaApp .modern-table tbody td:first-child {
        position: absolute !important;
        top: 14px !important;
        right: 14px !important;
        padding: 0 !important;
        border: none !important;
        width: auto !important;
    }

    /* Nome do membro */
    #gerarApp .modern-table .member-name,
    #atualizaApp .modern-table .member-name {
        flex-direction: row !important;
        gap: 10px !important;
        width: 100% !important;
        padding-right: 40px !important; /* Espaço para checkbox */
    }

    #gerarApp .modern-table .member-name span,
    #atualizaApp .modern-table .member-name span {
        font-weight: 600 !important;
        font-size: 1rem !important;
        color: #3F4254 !important;
    }

    #gerarApp .modern-table .avatar-circle,
    #atualizaApp .modern-table .avatar-circle {
        width: 44px !important;
        height: 44px !important;
        flex-shrink: 0;
    }

    /* Labels para as colunas no mobile */
    #gerarApp .modern-table tbody td:nth-child(3)::before,
    #atualizaApp .modern-table tbody td:nth-child(3)::before {
        content: 'CPF:';
        font-weight: 600;
        color: #47126B;
        font-size: 0.75rem;
        text-transform: uppercase;
    }

    #gerarApp .modern-table tbody td:nth-child(4)::before,
    #atualizaApp .modern-table tbody td:nth-child(4)::before {
        content: 'Nascimento:';
        font-weight: 600;
        color: #47126B;
        font-size: 0.75rem;
        text-transform: uppercase;
    }

    #gerarApp .modern-table tbody td:nth-child(5)::before,
    #atualizaApp .modern-table tbody td:nth-child(5)::before {
        content: 'Validade:';
        font-weight: 600;
        color: #47126B;
        font-size: 0.75rem;
        text-transform: uppercase;
    }

    /* Status badge */
    #gerarApp .status-badge,
    #atualizaApp .status-badge {
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
    }

    /* Botões de ação na tabela */
    #gerarApp .btn-action,
    #atualizaApp .btn-action {
        min-width: 48px !important;
        min-height: 48px !important;
        width: 48px !important;
        height: 48px !important;
        border-radius: 12px !important;
    }

    #gerarApp .btn-action i,
    #atualizaApp .btn-action i {
        font-size: 1.1rem !important;
    }

    /* === PAGINAÇÃO === */
    #gerarApp .pagination-container,
    #atualizaApp .pagination-container {
        flex-direction: column !important;
        gap: 12px !important;
        padding: 14px !important;
    }

    #gerarApp .pagination-info,
    #atualizaApp .pagination-info {
        text-align: center !important;
        font-size: 0.85rem !important;
    }

    #gerarApp .pagination-controls,
    #atualizaApp .pagination-controls {
        flex-direction: column !important;
        gap: 12px !important;
        width: 100% !important;
    }

    #gerarApp .items-per-page,
    #atualizaApp .items-per-page {
        justify-content: center !important;
    }

    #gerarApp .pagination-buttons,
    #atualizaApp .pagination-buttons {
        justify-content: center !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    #gerarApp .pagination-buttons .btn,
    #atualizaApp .pagination-buttons .btn {
        min-width: 44px !important;
        min-height: 44px !important;
    }

    /* === CONFIG - Templates === */
    #configApp .card-header h3 {
        font-size: 1.15rem !important;
    }

    #configApp .card-body {
        padding: 14px !important;
    }

    /* Templates grid */
    #configApp .row.mb-4 .row {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 10px !important;
    }

    #configApp .row.mb-4 .row .col-md-3 {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .card {
        margin-bottom: 0 !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .card-body {
        padding: 12px 10px !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .fa-3x {
        font-size: 1.75rem !important;
    }

    #configApp .row.mb-4 .row .col-md-3 h5 {
        font-size: 0.85rem !important;
        margin-bottom: 0 !important;
    }

    /* Cores - em coluna */
    #configApp h4 {
        font-size: 1rem !important;
        margin-bottom: 12px !important;
    }

    #configApp .row.mb-4 > .col-md-12 > .row {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    #configApp .row.mb-4 > .col-md-12 > .row > .col-md-4 {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
    }

    #configApp input[type="color"] {
        height: 50px !important;
        width: 100% !important;
        border-radius: 8px !important;
    }

    /* Nav Tabs */
    #configApp .nav-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 0 !important;
        padding-bottom: 2px !important;
        margin-bottom: 16px !important;
    }

    #configApp .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    #configApp .nav-tabs .nav-item {
        flex: 0 0 auto !important;
    }

    #configApp .nav-tabs .nav-link {
        font-size: 0.85rem !important;
        padding: 12px 16px !important;
        white-space: nowrap !important;
        min-height: 48px !important;
    }

    /* Tab Content - Preview e Config lado a lado viram empilhados */
    #configApp .tab-content .row {
        flex-direction: column !important;
    }

    #configApp .tab-content .row .col-md-6 {
        width: 100% !important;
        max-width: 100% !important;
        padding: 0 !important;
        margin-bottom: 20px !important;
    }

    /* Preview da Carteirinha - Container wrapper */
    #configApp .tab-content .row .col-md-6:first-child {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        overflow: visible !important;
    }

    /* Preview da Carteirinha - Tamanho fixo proporcional que cabe na tela */
    #configApp .carteirinha-preview,
    #configApp .carteirinha-preview-moderna {
        width: calc(100vw - 56px) !important;
        max-width: 340px !important;
        min-width: 280px !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        aspect-ratio: 85.6 / 53.98 !important;
        transform: none !important;
        transform-origin: center center !important;
        margin: 0 auto 16px !important;
        flex-shrink: 0 !important;
        overflow: hidden !important;
        padding: 8px !important;
    }

    /* Ajusta fontes internas do preview para caber na tela menor */
    #configApp .carteirinha-preview-moderna .card-header-preview-center {
        padding: 6px 12px 0 12px !important;
    }

    #configApp .carteirinha-preview-moderna .card-header-preview-center > div:first-child {
        font-size: clamp(12px, 4vw, 18px) !important;
        margin-bottom: 0 !important;
    }

    #configApp .carteirinha-preview-moderna .card-header-preview-center > div:last-child {
        font-size: clamp(6px, 2vw, 8px) !important;
    }

    /* Área do membro principal */
    #configApp .carteirinha-preview-moderna .card-body-preview {
        padding: 0 12px 2px 12px !important;
    }

    #configApp .carteirinha-preview-moderna .membro-principal-preview {
        margin-bottom: 4px !important;
        gap: 8px !important;
    }

    #configApp .carteirinha-preview-moderna .foto-preview {
        width: 45px !important;
        height: 45px !important;
        min-width: 45px !important;
    }

    #configApp .carteirinha-preview-moderna .membro-principal-preview > div:last-child > div:first-child {
        font-size: clamp(10px, 3.5vw, 14px) !important;
        max-height: 18px !important;
    }

    #configApp .carteirinha-preview-moderna .membro-principal-preview > div:last-child > div:last-child {
        font-size: clamp(8px, 2.5vw, 10px) !important;
    }

    /* Grid de informações - mantém 4 colunas mas com fontes menores */
    #configApp .carteirinha-preview-moderna .card-body-preview > div[style*="grid"] {
        gap: 2px !important;
    }

    #configApp .carteirinha-preview-moderna .card-body-preview > div[style*="grid"] > div {
        padding: 2px 3px !important;
        border-radius: 3px !important;
    }

    #configApp .carteirinha-preview-moderna .card-body-preview > div[style*="grid"] > div > div:first-child {
        font-size: clamp(5px, 1.8vw, 7px) !important;
        margin-bottom: 0 !important;
    }

    #configApp .carteirinha-preview-moderna .card-body-preview > div[style*="grid"] > div > div:last-child {
        font-size: clamp(7px, 2.2vw, 9px) !important;
    }

    /* Footer do preview */
    #configApp .carteirinha-preview-moderna .card-footer-preview {
        padding: 3px 12px !important;
    }

    #configApp .carteirinha-preview-moderna .card-footer-preview .info-label-preview {
        font-size: clamp(6px, 2vw, 8px) !important;
    }

    #configApp .carteirinha-preview-moderna .card-footer-preview > div:first-child > div:last-child {
        font-size: clamp(7px, 2.2vw, 9px) !important;
        margin-top: 1px !important;
    }

    #configApp .carteirinha-preview-moderna .card-footer-preview > div:last-child {
        font-size: clamp(5px, 1.5vw, 7px) !important;
        max-width: 45% !important;
    }

    /* Verso da carteirinha - mesmo tratamento */
    #configApp .carteirinha-preview-moderna .verso-content {
        padding: 8px !important;
    }

    #configApp .carteirinha-preview-moderna .verso-header {
        margin-bottom: 4px !important;
    }

    #configApp .carteirinha-preview-moderna .verso-logo {
        width: 40px !important;
        height: 40px !important;
    }

    #configApp .carteirinha-preview-moderna .verso-logo i {
        font-size: 20px !important;
    }

    #configApp .carteirinha-preview-moderna .verso-info h4 {
        font-size: clamp(10px, 3vw, 14px) !important;
        margin: 2px 0 !important;
    }

    #configApp .carteirinha-preview-moderna .verso-info p {
        font-size: clamp(7px, 2vw, 9px) !important;
        margin: 2px 0 !important;
    }

    /* Formulários */
    #configApp .form-group {
        margin-bottom: 14px !important;
    }

    #configApp .form-group label {
        font-size: 0.9rem !important;
        margin-bottom: 6px !important;
        display: block !important;
    }

    #configApp .form-control {
        font-size: 16px !important;
        min-height: 48px !important;
        padding: 12px 14px !important;
    }

    #configApp textarea.form-control {
        min-height: 100px !important;
    }

    /* Checkboxes com touch target */
    #configApp .form-group label:has(input[type="checkbox"]),
    #configApp .form-group > label > input[type="checkbox"] {
        min-height: 44px;
        display: flex;
        align-items: center;
        gap: 10px;
    }

    #configApp input[type="checkbox"] {
        width: 22px !important;
        height: 22px !important;
        margin-right: 10px !important;
    }

    /* Botão Salvar */
    #configApp .row.mt-5 {
        margin-top: 20px !important;
    }

    #configApp .row.mt-5 .btn {
        width: 100% !important;
        min-height: 52px !important;
        font-size: 1rem !important;
    }

    /* === MODAL DE PREVIEW === */
    #previewModal .modal-dialog {
        margin: 8px !important;
        max-width: calc(100% - 16px) !important;
    }

    #previewModal .modal-body {
        padding: 12px !important;
    }

    #previewModal .modal-body > div {
        flex-direction: column !important;
        gap: 16px !important;
    }

    #previewModal .carteirinha-preview-moderna {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        aspect-ratio: 85.6 / 53.98 !important;
        transform: none !important;
    }

    #previewModal .modal-footer {
        flex-direction: column !important;
        gap: 8px !important;
    }

    #previewModal .modal-footer .btn {
        width: 100% !important;
        min-height: 48px !important;
    }

    /* === TOASTS E MODAIS CUSTOMIZADOS === */
    .toast-amosh {
        right: 12px !important;
        left: 12px !important;
        width: calc(100vw - 24px) !important;
        max-width: none !important;
    }

    .confirm-dialog,
    .alert-dialog {
        width: calc(100% - 24px) !important;
        max-width: none !important;
        margin: 12px !important;
    }

    .confirm-header,
    .alert-icon-wrapper {
        padding: 20px 16px !important;
    }

    .confirm-body {
        padding: 16px !important;
    }

    .confirm-footer {
        padding: 16px !important;
        flex-direction: column !important;
        gap: 8px !important;
    }

    .confirm-footer .btn {
        width: 100% !important;
        min-height: 48px !important;
    }

    /* PDF Loading */
    .pdf-loading-container {
        padding: 20px !important;
        width: calc(100% - 32px) !important;
        max-width: none !important;
    }
}

/* ===== CARTEIRINHAS - Samsung S24 Ultra e Android similares (360-420px) ===== */
@media screen and (min-width: 360px) and (max-width: 420px) {

    #gerarApp,
    #configApp,
    #atualizaApp {
        padding: 0 10px !important;
    }

    /* Stats em 2x2 mais compacto */
    #gerarApp .row.mb-4 {
        gap: 8px !important;
    }

    #gerarApp .stat-card {
        padding: 12px 10px !important;
    }

    #gerarApp .stat-details h3 {
        font-size: 1.5rem !important;
    }

    #gerarApp .stat-details p {
        font-size: 0.65rem !important;
    }

    /* Page header mais compacto */
    #gerarApp .page-header h2,
    #configApp .page-header h2 {
        font-size: 1.15rem !important;
    }

    /* Templates em 2x2 */
    #configApp .row.mb-4 .row {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .card-body {
        padding: 10px 8px !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .fa-3x {
        font-size: 1.5rem !important;
    }

    #configApp .row.mb-4 .row .col-md-3 h5 {
        font-size: 0.8rem !important;
    }

    /* Nav tabs mais compactas */
    #configApp .nav-tabs .nav-link {
        font-size: 0.8rem !important;
        padding: 10px 12px !important;
    }

    #configApp .nav-tabs .nav-link i {
        margin-right: 4px !important;
    }

    /* Cards de membros mais compactos */
    #gerarApp .modern-table tbody tr {
        padding: 12px !important;
    }

    #gerarApp .modern-table .member-name span {
        font-size: 0.95rem !important;
    }

    #gerarApp .modern-table tbody td {
        font-size: 0.85rem !important;
    }
}

/* ===== CARTEIRINHAS - iPhone SE e telas pequenas (até 375px) ===== */
@media screen and (max-width: 375px) {

    #gerarApp,
    #configApp,
    #atualizaApp {
        padding: 0 8px !important;
    }

    /* Stats em coluna única */
    #gerarApp .row.mb-4 {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    #gerarApp .stat-card {
        flex-direction: row !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 12px !important;
    }

    #gerarApp .stat-details {
        flex-direction: row !important;
        align-items: center !important;
        gap: 8px !important;
    }

    #gerarApp .stat-details h3 {
        font-size: 1.5rem !important;
        margin: 0 !important;
    }

    #gerarApp .stat-details p {
        font-size: 0.75rem !important;
        margin: 0 !important;
    }

    /* Page header */
    #gerarApp .page-header h2,
    #configApp .page-header h2 {
        font-size: 1.1rem !important;
    }

    #gerarApp .page-header p {
        font-size: 0.8rem !important;
    }

    /* Botões de ação em coluna */
    #gerarApp .card.shadow-sm.mb-4 .row > .col-md-4.text-right {
        grid-template-columns: 1fr !important;
    }

    /* Templates em coluna única */
    #configApp .row.mb-4 .row {
        grid-template-columns: 1fr !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .card-body {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 12px !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .fa-3x {
        font-size: 1.5rem !important;
        margin-bottom: 0 !important;
    }

    #configApp .row.mb-4 .row .col-md-3 h5 {
        margin: 0 !important;
    }

    /* Nav tabs - só texto */
    #configApp .nav-tabs .nav-link i {
        display: none !important;
    }

    #configApp .nav-tabs .nav-link {
        font-size: 0.75rem !important;
        padding: 10px !important;
    }
}

/* ===== CARTEIRINHAS - Landscape Mobile ===== */
@media screen and (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {

    /* Header compacto */
    #gerarApp .page-header,
    #configApp .page-header {
        margin-bottom: 10px !important;
    }

    #gerarApp .page-header .d-flex {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
    }

    #gerarApp .page-header h2 {
        font-size: 1rem !important;
    }

    #gerarApp .page-header p {
        display: none !important;
    }

    #gerarApp .page-header .btn {
        width: auto !important;
        min-height: 40px !important;
    }

    /* Stats em linha */
    #gerarApp .row.mb-4 {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
        margin-bottom: 10px !important;
    }

    #gerarApp .stat-card {
        padding: 8px !important;
    }

    #gerarApp .stat-details h3 {
        font-size: 1.25rem !important;
    }

    #gerarApp .stat-details p {
        font-size: 0.6rem !important;
    }

    /* Filtros em linha */
    #gerarApp .card.shadow-sm.mb-4 .row {
        flex-direction: row !important;
        flex-wrap: nowrap !important;
    }

    #gerarApp .card.shadow-sm.mb-4 .row > [class*="col-"] {
        flex: 1 !important;
    }

    #gerarApp .card.shadow-sm.mb-4 .btn {
        min-height: 40px !important;
        font-size: 0.75rem !important;
    }

    /* Config - Preview ao lado */
    #configApp .tab-content .row {
        flex-direction: row !important;
    }

    #configApp .tab-content .row .col-md-6 {
        width: 50% !important;
        padding: 0 8px !important;
    }

    #configApp .carteirinha-preview,
    #configApp .carteirinha-preview-moderna {
        max-height: 200px !important;
    }

    /* Templates em linha */
    #configApp .row.mb-4 .row {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 6px !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .card-body {
        padding: 8px !important;
    }

    #configApp .row.mb-4 .row .col-md-3 .fa-3x {
        font-size: 1.25rem !important;
    }

    #configApp .row.mb-4 .row .col-md-3 h5 {
        font-size: 0.7rem !important;
    }

    /* Nav tabs compactas */
    #configApp .nav-tabs .nav-link {
        padding: 8px 12px !important;
        font-size: 0.75rem !important;
    }
}

/* ===== CARTEIRINHAS - Tablet Portrait (768-991px) ===== */
@media screen and (min-width: 768px) and (max-width: 991px) {

    /* Stats em 2x2 */
    #gerarApp .row.mb-4 > .col-md-3 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    /* Filtros - busca e status lado a lado, botões embaixo */
    #gerarApp .card.shadow-sm.mb-4 .row {
        flex-wrap: wrap !important;
    }

    #gerarApp .card.shadow-sm.mb-4 .row > .col-md-5,
    #gerarApp .card.shadow-sm.mb-4 .row > .col-md-3 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    #gerarApp .card.shadow-sm.mb-4 .row > .col-md-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-top: 12px !important;
    }

    /* Config - Preview e form lado a lado */
    #configApp .tab-content .row .col-md-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }

    /* Templates em 2x2 */
    #configApp .row.mb-4 .row .col-md-3 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
}

/* ===== CARTEIRINHAS - Safe Areas iOS ===== */
@supports (padding: max(0px)) {
    @media screen and (max-width: 767.98px) {
        #gerarApp,
        #configApp,
        #atualizaApp {
            padding-left: max(12px, env(safe-area-inset-left)) !important;
            padding-right: max(12px, env(safe-area-inset-right)) !important;
            padding-bottom: max(16px, env(safe-area-inset-bottom)) !important;
        }

        .toast-amosh {
            top: max(20px, env(safe-area-inset-top)) !important;
        }

        .confirm-overlay,
        .alert-overlay,
        .pdf-loading-overlay {
            padding-top: env(safe-area-inset-top);
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* ===== PRINT STYLES ===== */

@media print {
    /* Remove safe areas para impressão */
    body {
        padding: 0;
    }

    /* Remove sombras e bordas arredondadas - somente para .amosh-card */
    .amosh-card {
        box-shadow: none;
        border: 1px solid #ddd;
        border-radius: 0;
    }

    /* Esconde elementos não imprimíveis */
    .no-print,
    .btn,
    .nav,
    .sidebar {
        display: none !important;
    }

    /* Dashboard - imprime todos os cards */
    #main > .row > [class*="col-lg-"] {
        flex: 0 0 50% !important;
        max-width: 50% !important;
        page-break-inside: avoid;
    }

    /* Tabelas - força visibilidade */
    table thead {
        display: table-header-group !important;
    }

    table tbody tr {
        display: table-row !important;
        page-break-inside: avoid;
    }

    /* Remove backgrounds escuros */
    .card,
    .table-striped tbody tr:nth-of-type(odd) {
        background: #fff !important;
    }

    /* Relatórios - mostra tabela completa */
    .table-responsive {
        overflow: visible !important;
    }

    .table-responsive table {
        min-width: 0 !important;
    }
}


/* ===================================================================
   DASHBOARD - LAYOUT UNIFORME E ORGANIZADO
   ===================================================================
   Refatoração para cards uniformes, alinhados e fluidos
   =================================================================== */

/* ===== CONTAINER PRINCIPAL DO DASHBOARD ===== */
#main > .row {
    display: flex;
    flex-wrap: wrap;
}

/* ===== CARDS DE ESTATÍSTICAS (PRIMEIRA SEÇÃO) ===== */
/* Estilo base para todos os cards do Dashboard */
.card.card-custom.card-stretch {
    height: 100%;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    border: none;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
    background: #fff;
}

.card.card-custom.card-stretch:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    transform: translateY(-2px);
}

/* ===== SEÇÃO INFERIOR (Aniversariantes, Ministérios, Calendário) ===== */
#main > .row:nth-child(2) {
    margin-top: 20px;
}

/* Cards da seção inferior com altura uniforme */
#main > .row:nth-child(2) > [class*="col-lg-"] {
    margin-bottom: 20px;
}

#main > .row:nth-child(2) .card.card-custom {
    min-height: 380px;
    display: flex;
    flex-direction: column;
}

#main > .row:nth-child(2) .card-body {
    flex: 1;
    overflow-y: auto;
    max-height: 300px;
}

/* ===== CARD HEADER PADRONIZADO ===== */
.card.card-custom .card-header {
    padding: 20px 24px 10px;
    background: transparent;
    border-bottom: none;
    min-height: auto;
}

.card.card-custom .card-header h3.card-title {
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin: 0;
}

/* ===== CARD BODY PADRONIZADO ===== */
.card.card-custom .card-body {
    padding: 10px 24px 20px;
    flex: 1;
}

/* ===== CARDS DE ANIVERSARIANTES ===== */
#birthdays .card .card-body {
    padding-top: 0;
}

#birthdays .d-flex.align-items-center {
    padding: 12px 0;
    border-bottom: 1px solid #f5f5f5;
}

#birthdays .d-flex.align-items-center:last-child {
    border-bottom: none;
}

#birthdays .symbol-40 {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

#birthdays .symbol-label {
    background: linear-gradient(135deg, #47126b 0%, #8e44ad 100%);
    color: #fff;
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    width: 44px;
    height: 44px;
}

/* ===== CARDS DE MINISTÉRIOS ===== */
#main .card-body:has(celulas) {
    padding-top: 0;
}

/* ===== CALENDÁRIO ===== */
#schedule .card.card-custom {
    min-height: 380px;
}

#schedule .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 20px;
}

/* Fix para o título do mês no calendário */
#schedule .fc-toolbar-title,
#calendar .fc-toolbar-title {
    font-size: 18px !important;
    font-weight: 600 !important;
    color: #333;
}

/* Botões de navegação do calendário */
#schedule .fc-button-group,
#calendar .fc-button-group {
    display: flex;
    gap: 4px;
}

#schedule .fc-button,
#calendar .fc-button {
    background: #47126b !important;
    border: none !important;
    border-radius: 8px !important;
    padding: 6px 12px !important;
    font-size: 13px !important;
}

#schedule .fc-button:hover,
#calendar .fc-button:hover {
    background: #5a1d82 !important;
}

/* Fix "undefined" - estilo do título */
#schedule .fc-toolbar,
#calendar .fc-toolbar {
    margin-bottom: 15px !important;
}

/* ===== CARDS DE GRÁFICOS (Seção inferior) ===== */
#advanced_data .card,
#main > .row > .col-lg-6:has(members-gender) .card,
#main > .row > .col-lg-6:has(marital-status) .card,
#main > .row > .col-lg-12:has(schooling) .card,
#main > .row > .col-lg-12:has(years-membres) .card,
#main > .row > .col-lg-12:has(members-district) .card,
#main > .row > .col-lg-12:has(dash-jobs) .card {
    min-height: 350px;
}

/* ===== LAYOUT 3 COLUNAS (Aniversariantes/Ministérios/Calendário) ===== */
@media screen and (min-width: 992px) {
    #main > .row:nth-child(2) {
        display: flex;
        flex-wrap: wrap;
    }
    
    /* Primeiro e segundo card (Aniversariantes e Ministérios) = 25% cada */
    #main > .row:nth-child(2) > .col-lg-3 {
        flex: 0 0 25%;
        max-width: 25%;
    }
    
    /* Terceiro card (Calendário) = 50% */
    #main > .row:nth-child(2) > .col-lg-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ===== RESPONSIVIDADE - TABLET (768px - 991px) ===== */
@media screen and (max-width: 991px) {
    /* Seção de Aniversariantes/Ministérios/Calendário */
    #main > .row:nth-child(2) > .col-lg-3,
    #main > .row:nth-child(2) > .col-lg-6 {
        flex: 0 0 100%;
        max-width: 100%;
        margin-bottom: 16px;
    }
    
    #main > .row:nth-child(2) .card.card-custom {
        min-height: auto;
    }
    
    #main > .row:nth-child(2) .card-body {
        max-height: none;
    }
    
    /* Cards de gráficos em coluna única */
    #main > .row > .col-lg-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ===== RESPONSIVIDADE - MOBILE (< 768px) ===== */
@media screen and (max-width: 767.98px) {
    /* Cards do Dashboard */
    .card.card-custom.card-stretch {
        border-radius: 10px;
        margin-bottom: 12px;
    }
    
    .card.card-custom .card-header {
        padding: 16px 16px 8px;
    }
    
    .card.card-custom .card-body {
        padding: 8px 16px 16px;
    }
    
    /* Aniversariantes */
    #birthdays .d-flex.align-items-center {
        padding: 10px 0;
    }
    
    #birthdays .symbol-40 {
        width: 38px;
        height: 38px;
    }
    
    #birthdays .symbol-label {
        width: 38px;
        height: 38px;
        font-size: 14px;
    }
    
    /* Calendário compacto */
    #schedule .card.card-custom,
    #schedule .card-body {
        min-height: auto;
    }
    
    #schedule .fc-toolbar-title,
    #calendar .fc-toolbar-title {
        font-size: 15px !important;
    }
}

/* ===== DATA SELECTOR (Seletor de Ano/Mês) ===== */
.card.card-custom.card-stretch.card-bg-transparent {
    background: transparent;
    box-shadow: none;
    border: none;
}

.card.card-custom.card-stretch.card-bg-transparent:hover {
    box-shadow: none;
    transform: none;
}

/* Botões de data mais bonitos */
.btn-date {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}

/* Input de data */
.input-group input.form-control[disabled] {
    background: #fff;
    font-weight: 500;
    color: #333;
}

/* ===== UNIFORMIZAÇÃO DA ALTURA DOS CARDS ===== */
/* Para a seção de estatísticas (5 cards) */
.cards-first-section {
    gap: 16px !important;
}

.cards-first-section .card {
    height: 100%;
    min-height: 180px;
}

/* Para a seção de gráficos */
#main > .row > [class*="col-lg-"]:not(:first-child) {
    margin-top: 0;
    margin-bottom: 20px;
}

/* Garante que cards de gráficos tenham altura mínima */
#main > .row > [class*="col-lg-"] > .card.card-custom.gutter-b {
    min-height: 350px;
    margin-bottom: 0;
}

/* ===== ESPAÇAMENTO E ORGANIZAÇÃO GERAL ===== */
.gutter-b {
    margin-bottom: 0 !important;
}

#main > .row {
    margin-bottom: 20px;
}

#main > .row:last-child {
    margin-bottom: 0;
}

/* ===== SCROLLBAR CUSTOMIZADA PARA CARDS ===== */
.card-body::-webkit-scrollbar {
    width: 6px;
}

.card-body::-webkit-scrollbar-track {
    background: #f5f5f5;
    border-radius: 3px;
}

.card-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.card-body::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* =====================================================
   AMOSH CUSTOMIZAÇÕES (migrado de common.css)
   ===================================================== */

/* Variáveis CSS Amosh */
:root {
    --color-primary: #47126b;
    --color-secondary: #6411ad;
    --color-white: #ffffff;
    --color-background: #fffefb;
    --background-grey: #f2f3f7;
}

/* ===== ESTILOS DE FORMULÁRIO ===== */
input:focus,
select:focus,
textarea:focus,
.dropdown .bootstrap-select .form-control .picker:focus {
    border-color: var(--color-secondary) !important;
}

input.form-control::placeholder,
.bootstrap-select>.dropdown-toggle.bs-placeholder,
.bootstrap-select>.dropdown-toggle.bs-placeholder:hover {
    color: #3f4254 !important;
}

.bootstrap-select>.dropdown-toggle:focus {
    border-color: #997aaf !important;
}

.form-control {
    border-color: #997aaf;
}

/* ===== BOTÕES AMOSH ===== */
.btn.btn-success,
.btn.btn-primary {
    color: var(--color-white);
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn.btn-success:hover,
.btn.btn-primary:hover {
    background-color: var(--color-secondary) !important;
    border-color: var(--color-secondary) !important;
}

.btn.btn-primary:disabled {
    color: var(--color-white);
    background-color: var(--color-secondary) !important;
    border-color: var(--color-secondary);
}

.btn.btn-hover-primary:not(:disabled):not(.disabled).active {
    color: var(--color-white);
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary);
}

.btn.btn-success.focus:not(.btn-text),
.btn.btn-success:focus:not(.btn-text),
.btn.btn-success:hover:not(.btn-text) {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn.btn-light-primary {
    color: #fff !important;
    background-color: #6411ad;
    border-color: transparent;
}

/* ===== PAGINAÇÃO ===== */
.paginate-item-page.current-page,
.datatable.datatable-default>.datatable-pager>.datatable-pager-nav>li>.datatable-pager-link.datatable-pager-link-active {
    color: var(--color-white);
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary);
}

/* ===== MENU LATERAL (ASIDE) ===== */

/* CRÍTICO: Garantir que o aside expandido tenha a largura correta em desktop */
@media screen and (min-width: 992px) {
    /* Aside expandido: largura padrão do framework */
    .aside-fixed .aside {
        width: 265px;
    }

    /* Wrapper deve ter padding-left para não sobrepor o aside */
    .aside-fixed .wrapper {
        padding-left: 265px;
    }

    /* Sidebar minimizado - apenas quando a classe aside-minimize está presente */
    .aside-minimize .aside {
        width: 70px !important;
    }

    .aside-minimize .wrapper {
        padding-left: 70px !important;
    }
}

.svg-icon.menu-icon {
    margin: 0 10px 0 0;
}

.svg-icon.menu-icon>i {
    color: white;
}

.nav-link.active>.svg-icon.menu-icon>i {
    color: #47126b;
}

.aside-menu .menu-nav>.menu-item>.menu-link .menu-icon>i,
.aside-menu .menu-nav>.menu-item .menu-submenu .menu-item>.menu-link .menu-icon>i {
    color: var(--color-primary) !important;
}

.menu-text {
    color: #000 !important;
    font-size: 13px !important;
}

.header .header-menu .menu-nav>.menu-item.menu-item-active>.menu-link {
    background-color: #47126b !important;
}

.menu-item.menu-item-active>.menu-link .menu-text {
    color: #47126b !important;
}

.brand-logo img {
    margin-right: 30px;
}

/* Menu Tutorials */
.menu-tutorials {
    background: linear-gradient(90deg, #a44e8d 0%, #3e017a 100%) !important;
}

.menu-nav>.menu-tutorials.menu-item:not(.menu-item-parent):not(.menu-item-open):not(.menu-item-here):not(.menu-item-active):hover>.menu-link {
    background: transparent !important;
}

.menu-tutorials .menu-text,
.aside-menu .menu-nav>.menu-tutorials.menu-item>.menu-link .menu-icon>i {
    color: white !important;
}

/* Scrollbar do aside */
.aside .aside-menu.ps>.ps__rail-y>.ps__thumb-y,
.aside .aside-menu.ps>.ps__rail-y>.ps__thumb-y:hover {
    background: var(--color-primary);
}

/* ===== SÍMBOLOS E LABELS ===== */
.symbol.symbol-light-success .symbol-label {
    background-color: var(--color-secondary);
    color: var(--color-primary);
}

.svg-icon.svg-icon-primary svg g [fill] {
    fill: var(--color-primary) !important;
}

.switch.switch-success:not(.switch-outline) .input:checked~span:before {
    background-color: var(--color-primary) !important;
}

/* ===== BADGES AMOSH ===== */
.badge-primary {
    color: #ffffff;
    background-color: #47126b;
}

.badge-success {
    color: #ffffff;
    background-color: #6411ad;
}

.badge-light-success {
    color: #50cd89;
    background-color: #e8fff3;
}

.badge-light-secondary {
    color: #7e8299;
    background-color: #f5f8fa;
}

.badge-light-danger {
    color: #f1416c;
    background-color: #fff5f8;
}

/* ===== LABELS AMOSH ===== */
.label.label-primary {
    color: #ffffff;
    background-color: #47126b;
}

.label.label-success {
    color: #ffffff;
    background-color: #6411ad;
}

.label.label-light-primary {
    color: #47126b;
    background-color: #e1f0ff;
}

.label.label-light-success {
    color: #6411ad;
    background-color: #c9f7f5;
}

/* ===== TEXTOS AMOSH ===== */
.text-primary {
    color: #47126b !important;
}

.text-success {
    color: #6411ad !important;
}

.text-muted {
    color: #6411ad !important;
}

.navi-text a {
    color: #3f4254;
}

/* ===== CORES UTILITÁRIAS ===== */
.bg-light-green {
    background: #e9f5db;
}

.text-green {
    color: #718355;
}

.bg-light-blue {
    background: #caf0f8;
}

.text-blue {
    color: #0077b6;
}

.bg-light-purple {
    background: #f2ebfb;
}

.text-yellow {
    color: #ff8100;
}

.font-weight-extra-bold {
    font-weight: 600;
}

.white-space {
    white-space: nowrap;
}

/* ===== TIMELINE ===== */
.timeline {
    height: 300px;
    overflow-y: auto;
    position: relative;
}

.timeline-box {
    position: relative;
}

.timeline-line {
    position: sticky;
    left: 107px;
    top: 0;
    bottom: 0;
    height: auto;
    width: 3px;
    background-color: #ebedf3;
}

.timeline.timeline-6 .timeline-item {
    display: flex;
    align-items: center;
    position: relative;
}

.timeline.timeline-6 .timeline-item .timeline-badge {
    background: white;
    width: 13px;
    height: 13px;
    border-radius: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 0;
    position: absolute;
    left: -7.5px;
    margin-top: 1px;
    margin-left: 0rem;
    padding: 3px !important;
    border: 6px solid #ffffff !important;
}

.font-size-lg.font-weight-normal.pl-3.text-muted.timeline-content {
    padding-left: 20px !important;
    border-left: 3px solid #ebedf3;
    padding-bottom: 1.7rem;
}

.timeline.timeline-6 .timeline-item .timeline-label {
    max-width: 85px;
    min-width: 85px;
    width: auto !important;
    font-size: 1rem !important;
}

/* ===== BOOTSTRAP SELECT ===== */
.bootstrap-select>.dropdown-toggle.btn-light,
.bootstrap-select>.dropdown-toggle.btn-secondary {
    background: #ffffff !important;
    color: #3f4254;
    border-color: var(--color-primary) !important;
    -webkit-box-shadow: none;
    box-shadow: none;
}

.bootstrap-select>.dropdown-toggle.btn-light:focus,
.bootstrap-select>.dropdown-toggle.btn-secondary:focus {
    border-color: var(--color-secondary) !important;
}

.bootstrap-select .dropdown-toggle:focus {
    outline: none !important;
}

/* ===== IMAGENS E TABELAS ===== */
.image-list {
    border-radius: 100% !important;
    width: 35px !important;
    height: 35px !important;
    object-fit: cover;
}

.table td.align-center {
    vertical-align: middle;
}

.scroll.ps>.ps__rail-y>.ps__thumb-y:hover {
    width: 5px;
}
