/* Global Responsive Fixes - Prevents Squashing on All Devices */

/* Base HTML and Body */
html {
    overflow-x: hidden !important;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    position: relative;
    margin: 0;
    padding: 0;
}

/* App Container */
.app {
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: relative;
    margin: 0;
    padding: 0;
}

/* Header Fixes */
.header {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.header-top {
    width: 100%;
    box-sizing: border-box;
}

/* Main Content */
.main {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Prevent All Elements from Overflowing (except tables) */
*:not(table):not(.table-container):not(.table) {
    max-width: 100%;
}

/* Ensure tables can scroll horizontally but container respects viewport */
.table-container {
    box-sizing: border-box;
    max-width: 100vw;
    overflow-x: auto;
}

table {
    box-sizing: border-box;
    width: 100%;
}

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

/* Text Wrapping */
p, h1, h2, h3, h4, h5, h6, span, div, label, button, a {
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

/* Long URLs */
a {
    word-break: break-all;
}

/* Mobile Specific Fixes */
@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
    
    body {
        font-size: 14px;
    }
    
    .main {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    
    /* Ensure buttons don't get squashed */
    .btn {
        white-space: nowrap;
        overflow: visible;
        text-overflow: clip;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Ensure inputs don't overflow */
    input, select, textarea {
        width: 100% !important;
        box-sizing: border-box !important;
        max-width: 100% !important;
    }
    
    /* Ensure cards don't overflow */
    .card, .stat-card {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    
    /* Ensure modals fit on screen */
    .modal {
        width: 95vw !important;
        max-width: 95vw !important;
        margin: 0.5rem auto !important;
        box-sizing: border-box;
    }
    
    /* Fix header overflow */
    .header-top {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .user-menu {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    /* Ensure grids don't overflow */
    .dashboard-grid,
    .stats-grid,
    .client-stats {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Fix invoice content */
    .invoice-content {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
        padding: 15px !important;
    }
    
    /* Fix chat container */
    .chat-container,
    .whatsapp-messaging {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }
    
    /* Fix search containers */
    .search-container {
        width: 100%;
        flex-wrap: wrap;
    }
    
    .search-input-wrapper {
        width: 100%;
        min-width: 0;
    }
    
    /* Ensure all flex containers wrap */
    .flex,
    .search-container,
    .user-menu {
        flex-wrap: wrap;
    }
    
    /* Fix any fixed widths */
    [style*="width"] {
        max-width: 100% !important;
    }
    
    /* Ensure containers respect viewport */
    .container,
    .main,
    .header,
    .header-top {
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box;
    }
}

/* Very Small Devices */
@media (max-width: 320px) {
    html {
        font-size: 12px;
    }
    
    body {
        font-size: 12px;
    }
    
    .main {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    .logo img {
        max-width: 100px;
        height: auto;
    }
    
    .btn {
        font-size: 0.75rem;
        padding: 0.5rem 0.875rem;
    }
    
    .modal {
        width: 98vw !important;
        max-width: 98vw !important;
        padding: 1rem !important;
    }
    
    .header-top {
        padding: 0.5rem 0.75rem !important;
    }
    
    .user-menu {
        font-size: 0.75rem;
    }
    
    .user-menu .btn {
        font-size: 0.6875rem;
        padding: 0.375rem 0.625rem;
    }
}

/* Quick Actions buttons - MUST BE LAST - highest priority override */
@media (max-width: 480px) {
    /* Quick Actions buttons - REBUILT: side-by-side on mobile - ABSOLUTE LAST */
    /* Using maximum specificity and !important to override ALL button styles */
    body div.card > div.card-body.quick-actions-buttons {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
        gap: 0.5rem !important;
        width: 100% !important;
        align-items: stretch !important;
    }
    
    body div.card > div.card-body.quick-actions-buttons > button.btn,
    body div.card > div.card-body.quick-actions-buttons > button.btn-primary,
    body div.card > div.card-body.quick-actions-buttons > button.btn-secondary,
    body div.card > div.card-body.quick-actions-buttons > button.btn-success,
    body div.card > div.card-body.quick-actions-buttons > button.btn-outline {
        display: inline-flex !important;
        flex: 1 1 calc(50% - 0.25rem) !important;
        flex-basis: calc(50% - 0.25rem) !important;
        flex-grow: 1 !important;
        flex-shrink: 1 !important;
        min-width: 0 !important;
        width: calc(50% - 0.25rem) !important;
        max-width: calc(50% - 0.25rem) !important;
        padding: 0.5rem 0.75rem !important;
        font-size: 0.8125rem !important;
        min-height: 38px !important;
        max-height: none !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        box-sizing: border-box !important;
    }
}

