/**
 * Responsive Utilities
 * SNEC IMS - Additional responsive styles for all pages
 */

/* ==================== GLOBAL RESPONSIVE UTILITIES ==================== */

/* Ensure viewport meta tag is respected */
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    overflow-x: hidden;
}

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

/* Images responsive by default */
img {
    max-width: 100%;
    height: auto;
}

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

/* Prevent horizontal scroll */
* {
    box-sizing: border-box;
}

/* Force all containers to respect max-width */
.container,
.container-fluid,
.content-area,
.main-content {
    max-width: 100%;
    overflow-x: hidden;
}

/* ==================== HEADER RESPONSIVE ENHANCEMENTS ==================== */

@media (max-width: 768px) {
    /* Use column layout instead of wrap to prevent overlap - HIGH SPECIFICITY */
    header.header,
    .header,
    div.header {
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        min-height: auto !important;
        padding: 10px 15px !important;
        gap: 0 !important;
        align-items: stretch !important;
        display: flex !important;
    }
    
    header.header .header-left,
    .header .header-left,
    div.header .header-left {
        flex: 0 0 auto !important;
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 0 !important;
        margin-top: 0 !important;
        padding-bottom: 0 !important;
        padding-top: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 10px !important;
        box-sizing: border-box !important;
        order: 1 !important;
        position: relative !important;
        z-index: 1 !important;
    }
    
    .header-logo {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        max-width: calc(100% - 50px) !important;
        overflow: hidden !important;
    }
    
    .header-logo-img {
        max-width: 100% !important;
        height: auto !important;
        object-fit: contain !important;
    }
    
    .mobile-menu-toggle {
        flex-shrink: 0 !important;
        flex-grow: 0 !important;
        width: 40px !important;
        min-width: 40px !important;
        max-width: 40px !important;
        margin-right: 0 !important;
        padding: 8px !important;
        box-sizing: border-box !important;
    }
    
    header.header .user-profile,
    .header .user-profile,
    div.header .user-profile {
        order: 2 !important;
        width: 100% !important;
        flex: 0 0 auto !important;
        max-width: 100% !important;
        justify-content: flex-end !important;
        align-items: center !important;
        margin-top: 20px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 0 !important;
        padding-top: 15px !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        padding-bottom: 0 !important;
        border-top: 2px solid rgba(255, 255, 255, 0.3) !important;
        gap: 8px !important;
        clear: both !important;
        box-sizing: border-box !important;
        display: flex !important;
        position: relative !important;
        z-index: 2 !important;
    }
    
    /* Prevent any inline style overrides */
    .user-profile[style] {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        width: 100% !important;
        margin-top: 12px !important;
        padding-top: 12px !important;
    }
    
    .profile-menu-wrapper {
        flex-shrink: 0 !important;
        position: relative !important;
        z-index: 10 !important;
    }
    
    .logout-btn {
        flex-shrink: 0 !important;
    }
    
    /* Ensure profile dropdown doesn't overlap */
    #userDropdown {
        position: absolute !important;
        right: 0 !important;
        left: auto !important;
        top: calc(100% + 10px) !important;
        z-index: 1001 !important;
    }
    
    /* Hide user name in profile button on mobile */
    .profile-menu-btn .user-name,
    .user-profile .user-name {
        display: none !important;
    }
    
    .profile-menu-btn {
        padding: 6px 10px !important;
        gap: 6px !important;
        font-size: 12px !important;
    }
    
    .profile-menu-btn .user-avatar {
        width: 28px !important;
        height: 28px !important;
    }
    
    .logout-btn {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
    
    /* Make logout button icon-only on very small screens */
    @media (max-width: 480px) {
        .logout-btn span {
            display: none !important;
        }
        
        .logout-btn {
            min-width: 36px;
            padding: 6px !important;
            justify-content: center;
        }
        
        .profile-menu-btn {
            padding: 5px 8px !important;
        }
    }
}

/* ==================== CONTENT AREA RESPONSIVE ==================== */

@media (max-width: 768px) {
    /* Ensure content doesn't overflow */
    .content-area,
    #home-section,
    section.content-area {
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 10px !important;
        margin: 0 !important;
    }
    
    .main-content {
        padding: 10px !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Stack all columns on mobile - force Bootstrap columns to stack */
    .row > [class*="col-"],
    .row-sm > [class*="col-"] {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 20px;
    }
    
    /* Remove negative margins on mobile for better spacing */
    .row,
    .row-sm {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    .row > [class*="col-"],
    .row-sm > [class*="col-"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* Force col-lg-8 and col-lg-4 to stack */
    .col-lg-8,
    .col-lg-4,
    .col-lg-6,
    .col-lg-12 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    
    /* Force col-md-* to stack */
    .col-md-6,
    .col-md-4,
    .col-md-3,
    .col-md-8,
    .col-md-12 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* ==================== CARDS RESPONSIVE ==================== */

@media (max-width: 768px) {
    .card {
        margin-bottom: 15px;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Card headers stack on mobile */
    .card-header,
    div[style*="display: flex"][style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
    
    .card-header > div,
    div[style*="display: flex"] > div {
        width: 100% !important;
        margin-bottom: 10px !important;
    }
    
    .card-header > div:last-child {
        margin-bottom: 0 !important;
    }
    
    /* Card content with flex */
    .card-body div[style*="display: flex"] {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    /* Card title sections */
    .card-body > div[style*="margin-bottom"] {
        margin-bottom: 20px !important;
    }
}

/* ==================== FORMS RESPONSIVE ==================== */

@media (max-width: 768px) {
    /* Form groups stack */
    .form-group,
    .mb-3 {
        margin-bottom: 15px;
    }
    
    /* Form labels */
    .form-label,
    label {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    /* Input groups */
    .input-group {
        flex-direction: column;
    }
    
    .input-group > * {
        width: 100% !important;
        margin-bottom: 10px;
    }
}

/* ==================== BUTTONS RESPONSIVE ==================== */

@media (max-width: 768px) {
    /* Button groups stack */
    .btn-group,
    .d-flex.justify-content-end,
    .d-flex.justify-content-between,
    div[style*="display: flex"][style*="justify-content"],
    div[style*="display:flex"][style*="justify-content"] {
        flex-direction: column !important;
        width: 100% !important;
        gap: 10px !important;
    }
    
    .btn-group .btn,
    .d-flex .btn,
    div[style*="display: flex"] .btn,
    div[style*="display:flex"] .btn {
        width: 100% !important;
        margin-bottom: 10px !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
    }
    
    .btn-group .btn:last-child,
    .d-flex .btn:last-child {
        margin-bottom: 0 !important;
    }
    
    /* Override inline button styles */
    .btn[style*="width"],
    a.btn[style*="width"] {
        width: 100% !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
    }
    
    /* Action button containers */
    .az-content-header-right,
    .form-group .d-flex {
        flex-direction: column !important;
        width: 100% !important;
    }
    
    .az-content-header-right .btn,
    .form-group .d-flex .btn {
        width: 100% !important;
        margin-bottom: 10px !important;
    }
    
    /* Button with inline flex styles */
    a[style*="display: flex"][style*="align-items"],
    button[style*="display: flex"][style*="align-items"] {
        width: 100% !important;
        justify-content: center !important;
    }
}

/* ==================== TABLES RESPONSIVE ==================== */

@media (max-width: 768px) {
    /* Make all tables scrollable - keep structure */
    .table-responsive,
    div[style*="overflow-x: auto"],
    div[style*="overflow-x:auto"] {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        -ms-overflow-style: -ms-autohiding-scrollbar;
    }
    
    .table-responsive table,
    .table,
    table {
        width: 100% !important;
        min-width: 600px;
        display: table !important;
    }
    
    .table-responsive thead,
    .table-responsive tbody,
    .table-responsive tr {
        display: table-row !important;
    }
    
    .table-responsive th,
    .table-responsive td {
        display: table-cell !important;
        white-space: nowrap;
        padding: 8px 6px !important;
        font-size: 12px !important;
    }
    
    /* Make table headers smaller on mobile */
    .table thead th {
        font-size: 11px !important;
        padding: 8px 6px !important;
    }
    
    .table tbody td {
        font-size: 12px !important;
        padding: 8px 6px !important;
    }
}

/* ==================== GRID LAYOUTS RESPONSIVE ==================== */

@media (max-width: 768px) {
    /* All grid layouts become single column */
    [class*="grid"],
    [style*="display: grid"],
    [style*="display:grid"],
    div[style*="display: grid"],
    div[style*="display:grid"] {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }
    
    /* Specific grid overrides - more specific selectors */
    div[style*="grid-template-columns: repeat(auto-fill, minmax(400px, 1fr))"],
    div[style*="grid-template-columns:repeat(auto-fill, minmax(400px, 1fr))"],
    [style*="grid-template-columns: repeat(auto-fill"] {
        grid-template-columns: 1fr !important;
        min-width: 0 !important;
    }
    
    div[style*="grid-template-columns: 1fr 1fr"],
    div[style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"],
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: repeat(2"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Card content grids */
    .card [style*="grid-template-columns: 1fr 1fr"],
    .card [style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
}

/* ==================== TEXT RESPONSIVE ==================== */

@media (max-width: 768px) {
    h1, h1[style*="font-size"] { font-size: 24px !important; }
    h2, h2[style*="font-size"] { font-size: 22px !important; }
    h3, h3[style*="font-size"] { font-size: 20px !important; }
    h4, h4[style*="font-size"] { font-size: 18px !important; }
    h5, h5[style*="font-size"] { font-size: 16px !important; }
    h6, h6[style*="font-size"] { font-size: 15px !important; }
    
    .az-dashboard-title,
    h2.az-dashboard-title {
        font-size: 20px !important;
    }
    
    /* Override inline font sizes */
    [style*="font-size: 28px"],
    [style*="font-size:28px"] {
        font-size: 22px !important;
    }
    
    [style*="font-size: 20px"],
    [style*="font-size:20px"] {
        font-size: 18px !important;
    }
    
    [style*="font-size: 18px"],
    [style*="font-size:18px"] {
        font-size: 16px !important;
    }
}

@media (max-width: 480px) {
    h1, h1[style*="font-size"] { font-size: 22px !important; }
    h2, h2[style*="font-size"] { font-size: 20px !important; }
    h3, h3[style*="font-size"] { font-size: 18px !important; }
    h4, h4[style*="font-size"] { font-size: 16px !important; }
    h5, h5[style*="font-size"] { font-size: 15px !important; }
    h6, h6[style*="font-size"] { font-size: 14px !important; }
    
    .az-dashboard-title,
    h2.az-dashboard-title {
        font-size: 18px !important;
    }
    
    [style*="font-size: 28px"],
    [style*="font-size:28px"] {
        font-size: 20px !important;
    }
    
    [style*="font-size: 20px"],
    [style*="font-size:20px"] {
        font-size: 17px !important;
    }
    
    [style*="font-size: 18px"],
    [style*="font-size:18px"] {
        font-size: 15px !important;
    }
}

/* ==================== UTILITY CLASSES ==================== */

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }
}

/* Full width on mobile */
@media (max-width: 768px) {
    .mobile-full-width {
        width: 100% !important;
        max-width: 100% !important;
    }
}

