/* Custom Animations */
@keyframes float {
    0%, 100% {
        transform: translateY(0) translateX(0);
    }
    50% {
        transform: translateY(-20px) translateX(10px);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.animate-float {
    animation: float 8s ease-in-out infinite;
}

.animation-delay-2000 {
    animation-delay: 2s;
}

/* Custom Responsive Styles */

/* Sidebar Container */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    max-width: 85vw;
    z-index: 1070;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
    padding: 0;
    background-color: #1e40af;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

/* Prevent Bootstrap modal from affecting sidebar */
.modal-open .sidebar {
    width: 280px !important;
    transform: translateX(-100%) !important;
}

.modal-open .sidebar.show {
    transform: translateX(0) !important;
    width: 280px !important;
}

.sidebar.show {
    transform: translateX(0);
}

/* Sidebar Overlay */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1065;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    backdrop-filter: blur(2px);
}

.sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
}

/* Main Content Area */
.main-content {
    transition: margin-left 0.3s ease-in-out;
    width: 100%;
    min-height: 100vh;
    background-color: #f8fafc;
    position: relative;
    padding: 1rem;
}

/* Ensure desktop offset even if other rules conflict */
body.layout-has-sidebar .main-content,
body.layout-admin .email-content, /* admin pages that use email-content without main-content wrapper */
body.layout-admin .container-fluid > .row > .col { /* fallback for admin email pages */
    margin-left: 0 !important; /* rely on grid for email pages */
    width: auto !important;
}

/* Email module sidebar should not inherit app .sidebar (fixed) styles */
.email-sidebar {
    position: relative !important;
    transform: none !important;
    width: 280px;
    max-width: 85vw;
    z-index: 1;
    min-height: 100%;
}
.email-sidebar .nav-link.active {
    background: rgba(13,110,253,.1);
    font-weight: 600;
}

/* Ensure grid columns don’t wrap and size correctly on admin email pages */
@media (min-width: 768px) {
    body.layout-admin .container-fluid > .row.g-0 { flex-wrap: nowrap; }
    body.layout-admin .container-fluid > .row.g-0 > .col-auto { flex: 0 0 280px; max-width: 280px; }
    body.layout-admin .container-fluid > .row.g-0 > .col.email-content { flex: 1 1 auto; max-width: calc(100% - 280px); }
}
@media (max-width: 767.98px) {
    /* On mobile, allow wrapping and make the email sidebar full width so content is visible first */
    body.layout-admin .container-fluid > .row.g-0 { flex-wrap: wrap; }
    .email-sidebar { width: 100%; max-width: 100%; }
}

@media (max-width: 991.98px) {
    body.layout-has-sidebar .main-content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

@media (min-width: 992px) {
    /* Admin layout (topnav, no sidebar) */
    body.layout-admin .main-content {
        margin-left: 0;
        width: 100%;
    }
    /* Non-admin layout (sidebar visible) */
    body.layout-has-sidebar .main-content {
        margin-left: 280px;
        width: calc(100% - 280px);
    }
}

@media (max-width: 991.98px) {
    .main-content {
        margin-left: 0;
        width: 100%;
        padding-top: 5rem; /* Add padding for mobile header */
    }
}

/* Mobile Menu Toggle Button */
#mobileMenuToggle {
    display: flex;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 1080;
    background: #1a56db;
    border: none;
    border-radius: 0.375rem;
    width: 2.5rem;
    height: 2.5rem;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transition: all 0.2s ease-in-out;
    cursor: pointer;
}

/* Ensure mobile menu toggle stays in position when modal is open */
.modal-open #mobileMenuToggle {
    position: fixed !important;
    top: 1rem !important;
    left: 1rem !important;
    z-index: 1080 !important;
}

#mobileMenuToggle:hover {
    background: #1e4bb6;
    transform: scale(1.05);
}

#mobileMenuToggle i {
    font-size: 1.25rem;
    color: white;
    transition: transform 0.2s ease-in-out;
}

@media (max-width: 991.98px) {
    /* Ensure mobile menu toggle is visible on mobile */
    #mobileMenuToggle {
        display: flex;
    }
    
    /* Adjust main content for mobile */
    .main-content {
        margin-left: 0 !important;
        width: 100%;
        padding: 1rem;
        padding-top: 5rem;
    }
    
    /* Ensure body doesn't scroll when menu is open */
    body.sidebar-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }
}

@media (min-width: 992px) {
    /* Hide mobile menu toggle on desktop */
    #mobileMenuToggle {
        display: none !important;
    }
    
    /* Show sidebar on desktop */
    .sidebar {
        transform: translateX(0);
        width: 280px;
        position: fixed; /* Keep sidebar fixed */
        z-index: 1000;
    }
    
    /* Push main content to the right only when sidebar layout is active */
    body.layout-has-sidebar .main-content {
        /* Increase left margin to add comfortable spacing from the sidebar */
        margin-left: 320px;
        width: calc(100% - 320px);
        padding: 1.5rem;
    }
    
    /* Admin layout keeps full width */
    body.layout-admin .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1.5rem;
    }
    
    .sidebar-overlay {
        display: none !important;
    }
}

/* Overlay for mobile when sidebar is open */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1039;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    /* Prevent overlay from intercepting taps unless visible */
    pointer-events: none;
}

.sidebar-overlay.show {
    display: block;
    opacity: 1;
    /* Allow clicks only when shown */
    pointer-events: auto;
}

/* Responsive Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Form Controls */
.form-control, .form-select {
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    line-height: 1.5;
    border-radius: 0.375rem;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* Cards */
.card {
    border: 1px solid rgba(0, 0, 0, 0.05);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 1.5rem;
    background-color: #fff;
}

.card-header {
    background-color: #fff;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

.card-body {
    padding: 1.25rem;
}

/* Alerts */
.alert {
    border-radius: 0.5rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    border: 1px solid transparent;
}

/* Navigation */
.nav-tabs .nav-link {
    border: none;
    color: #6b7280;
    font-weight: 500;
    padding: 0.75rem 1rem;
    border-bottom: 2px solid transparent;
}

.nav-tabs .nav-link.active {
    color: #4f46e5;
    border-bottom-color: #4f46e5;
    background-color: transparent;
}

/* Responsive Images */
.img-fluid {
    max-width: 100%;
    height: auto;
}

/* Utility Classes */
.rounded-lg {
    border-radius: 0.5rem;
}

.shadow-sm {
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Print Styles */
@media print {
    .no-print, .sidebar, .mobile-menu-toggle {
        display: none !important;
    }
    
    body {
        background: white !important;
        color: black !important;
        font-size: 12pt;
    }
    
    .container {
        width: 100%;
        max-width: 100%;
        padding: 0;
    }
    
    .card {
        border: 1px solid #e5e7eb;
        box-shadow: none;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a202c;
        color: #e2e8f0;
    }
    
    .card, .modal-content {
        background-color: #2d3748;
        border-color: #4a5568;
    }
    
    .card-header, .modal-header, .modal-footer {
        border-color: #4a5568;
    }
    
    .form-control, .form-select, .form-check-input {
        background-color: #2d3748;
        border-color: #4a5568;
        color: #e2e8f0;
    }
    
    .form-control:focus, .form-select:focus {
        background-color: #2d3748;
        color: #e2e8f0;
    }
    
    .table {
        color: #e2e8f0;
    }
    
    .table th, .table td {
        border-color: #4a5568;
    }
    
    .table thead th {
        background-color: #2d3748;
        border-color: #4a5568;
    }
}
