.layout-wrapper {
    display: flex;
    height: 100dvh; /* Fixes iOS Safari address bar overlap */
    min-height: -webkit-fill-available;
    overflow: hidden;
    gap: 0;
}

@media (min-width: 1024px) {
    .layout-wrapper {
        padding: 1rem;
        gap: 1rem;
    }
}

.sidebar {
    display: none;
    width: var(--sidebar-width);
    flex-direction: column;
    padding: 1.5rem;
    z-index: 10;
}

@media (min-width: 1024px) {
    .sidebar {
        display: flex;
        position: sticky;
        top: 1rem;
        height: calc(100vh - 2rem);
        border-radius: var(--radius-xl);
    }
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    border-radius: 0;
    padding-bottom: 10rem; /* Increased space for mobile nav + safe area */
}

@media (min-width: 1024px) {
    .main-content {
        border-radius: var(--radius-xl);
        padding: 2.5rem;
        /* Dashboard cards content padding check */
        padding-bottom: 5rem;
    }
}

.mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    padding: 0.75rem 1rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    z-index: 99;
    /* High z-index to stay above content */
    justify-content: space-around;
    align-items: center;
    transition: transform 0.3s ease;
}

.dark .mobile-nav {
    background: rgba(15, 23, 42, 0.8);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}

@media (min-width: 1024px) {
    .mobile-nav {
        display: none;
    }
}

.mobile-nav-container {
    margin: 0 0.5rem 0.5rem 0.5rem;
    border-radius: var(--radius-xl);
    padding: 0.5rem;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
}

/* Modal Open Scroll Lock */
body.is-modal-open {
    overflow: hidden !important;
    height: 100vh;
}

body.is-modal-open .main-content {
    overflow: hidden !important;
}

/* ==========================================================================
   Print Styles (Global)
   ========================================================================== */
@media print {
    @page {
        margin: 1.5cm;
    }
    
    html, body {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        background: white !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    /* Ocultar elementos de navegação e UI desnecessária */
    nav, aside, header, footer,
    .sidebar, .mobile-nav, .mobile-nav-container,
    [class*="sidebar"], [class*="menu"],
    .no-print {
        display: none !important;
    }

    /* Expandir conteúdo principal - Force block and auto height to allow page breaks */
    main, .main-content, .layout-wrapper, body > div.flex-1, .main-wrapper {
        display: block !important;
        height: auto !important;
        min-height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        position: static !important;
    }

    .page-container {
        padding: 0 !important;
        margin: 0 !important;
        box-shadow: none !important;
        border: none !important;
    }

    .print-break-inside-avoid {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .glass-panel {
        background: white !important;
        backdrop-filter: none !important;
        border: none !important;
        box-shadow: none !important;
    }
}

/* ==========================================================================
   A4 Paper Screen Simulation
   ========================================================================== */
.a4-paper {
    width: 21cm;
    min-height: 29.7cm;
    padding: 2cm;
    margin: 2rem auto;
    background: white;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    border-radius: 4px;
    box-sizing: border-box;
    position: relative;
    color: #1a202c !important; /* Force darker color for print fidelity */
}

/* Responsive A4 */
@media screen and (max-width: 21.5cm) {
    .a4-paper {
        width: 100%;
        margin: 0;
        padding: 1.5rem;
        min-height: auto;
        border-radius: 0;
        box-shadow: none;
    }
}

@media print {
    .a4-paper {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        min-height: auto !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }
}