
/* ============================================
   MOBILE RESPONSIVE IMPROVEMENTS
   ============================================ */

/* Prevent horizontal scrolling on all devices */
* {
    box-sizing: border-box;
}

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

/* Ensure portal screen and main content don't overflow */
.portal-screen,
.portal-layout,
.main-content {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Mobile-first table improvements */
@media (max-width: 768px) {
    /* Make all tables responsive with horizontal scroll */
    .table-container,
    .table-scroll-container {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 20px;
    }

    table {
        min-width: 600px;
        font-size: 13px;
    }

    table th,
    table td {
        padding: 10px 8px;
        white-space: nowrap;
    }
    
    /* Geographic Distribution specific tables */
    .geo-table-card {
        max-width: 100%;
        overflow: hidden;
    }
    
    #geoTable {
        min-width: 700px;
    }
    
    #dqReasonsTable,
    #returnsReasonsTable {
        min-width: 900px;
    }
    
    /* Ensure geo content doesn't overflow */
    .geo-content,
    .geo-content-full {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .geo-table-full {
        max-width: 100%;
    }

    /* Reduce padding on cards and containers */
    .tab-content-area {
        padding: 16px !important;
    }

    .section-card {
        padding: 16px !important;
        margin-bottom: 16px;
    }

    /* Stack filter groups vertically */
    .global-filters {
        flex-direction: column;
        gap: 16px;
        padding: 16px;
        align-items: stretch;
    }

    .filter-group {
        width: 100%;
    }

    .filter-group select,
    .filter-group input {
        width: 100%;
    }

    /* Time filter buttons */
    #timeFilter {
        flex-wrap: wrap;
        gap: 8px;
    }

    .filter-btn {
        flex: 1 1 calc(50% - 4px);
        min-width: calc(50% - 4px);
        font-size: 12px;
        padding: 8px 12px;
    }

    /* Header adjustments */
    .content-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 12px 16px !important;
    }

    .header-left,
    .header-right {
        width: 100%;
    }

    .header-right {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    /* Stats grids */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    /* Modal improvements */
    .modal-content {
        width: 95%;
        max-width: 95%;
        margin: 20px auto;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 16px;
    }

    /* Button adjustments */
    .btn-large {
        font-size: 14px;
        padding: 12px 20px;
    }

    .btn-small {
        font-size: 11px;
        padding: 6px 10px;
    }

    /* Form inputs */
    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 13px;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 14px;
        padding: 10px;
    }
}

/* Extra small devices (phones, less than 480px) */
@media (max-width: 480px) {
    /* Further reduce font sizes */
    body {
        font-size: 14px;
    }

    h1 {
        font-size: 20px !important;
    }

    h2 {
        font-size: 18px !important;
    }

    h3 {
        font-size: 16px !important;
    }

    /* Smaller table text */
    table {
        font-size: 12px;
        min-width: 500px;
    }

    table th,
    table td {
        padding: 8px 6px;
    }

    /* Stack stats vertically */
    .accounting-stats {
        grid-template-columns: 1fr !important;
    }

    /* Smaller padding everywhere */
    .tab-content-area {
        padding: 12px !important;
    }

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

    .global-filters {
        padding: 12px;
    }

    /* Filter buttons - one per row on very small screens */
    .filter-btn {
        flex: 1 1 100%;
        min-width: 100%;
    }

    /* Login card adjustments */
    .login-card {
        padding: 24px;
    }

    .login-card h1 {
        font-size: 24px;
    }

    /* Reduce modal padding */
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 12px;
    }

    /* Sidebar full width on mobile */
    .sidebar {
        width: 260px;
    }
}

/* Landscape mobile (480px to 768px) */
@media (min-width: 480px) and (max-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .filter-btn {
        flex: 1 1 calc(33.333% - 6px);
        min-width: calc(33.333% - 6px);
    }
}

/* Tablet (768px to 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .global-filters {
        gap: 20px;
    }

    table {
        font-size: 14px;
    }
}

/* ============================================
   USER AVATAR & FLYOUT MENU
   ============================================ */

/* User Avatar Container */
.user-avatar-container {
    position: relative;
    display: none;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f3f4f6;
    border: 2px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    padding: 0;
}

.user-avatar:hover {
    background: #e5e7eb;
    border-color: #059669;
}

.user-avatar svg {
    color: #6b7280;
}

/* User Flyout Menu */
.user-flyout {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    width: 280px;
    padding: 16px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    z-index: 1100;
    border: 1px solid #e5e7eb;
}

.user-flyout.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.user-flyout-header {
    display: flex;
    align-items: flex-start !important;
    justify-content: flex-start !important;
    gap: 12px;
    margin-bottom: 12px;
    text-align: left !important;
}

.user-avatar-large {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #f3f4f6;
    border: 2px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.user-avatar-large svg {
    color: #6b7280;
}

.user-info {
    flex: 1;
    min-width: 0;
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 0;
    text-align: left !important;
}

.user-name {
    font-weight: 600;
    font-size: 15px;
    color: #1f2937;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left !important;
    align-self: flex-start !important;
    margin: 0;
    padding: 0;
    width: 100%;
}

.user-email {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left !important;
    align-self: flex-start !important;
    margin-bottom: 0;
    padding: 0;
    width: 100%;
}

.user-role {
    font-size: 13px;
    color: #6b7280;
    margin-top: 4px;
    text-align: left !important;
    align-self: flex-start !important;
    margin-bottom: 0;
    padding: 0;
    width: 100%;
}

.user-role.admin {
    color: #059669;
    font-weight: 600;
}

.user-flyout-divider {
    height: 1px;
    background: #e5e7eb;
    margin: 12px 0;
}

.user-flyout-logout {
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    font-weight: 500;
    color: #dc2626;
    cursor: pointer;
    transition: all 0.2s ease;
}

.user-flyout-logout:hover {
    background: #fef2f2;
    border-color: #dc2626;
}

.user-flyout-logout svg {
    flex-shrink: 0;
}

/* Sidebar User Info (Desktop) */
.sidebar-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin-bottom: 12px;
}

.sidebar-user-avatar {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-user-avatar svg {
    color: rgba(255, 255, 255, 0.8);
}

.sidebar-user-details {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-user-name {
    font-size: 14px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
}

.sidebar-user-role.admin {
    color: #10b981;
}

/* Hide sidebar user info on mobile (use mobile header flyout instead) */
@media (max-width: 768px) {
    .sidebar-user-info {
        display: none;
    }
}

/* Show avatar on small screens only */
@media (max-width: 768px) {
    .user-avatar-container {
        display: block !important;
    }
    
    /* On portal pages, hide regular nav links on small screens */
    .portal-page .navbar .nav-links {
        display: none !important;
    }
    
    .nav-content {
        position: relative;
    }
}

/* Adjust flyout position on very small screens */
@media (max-width: 480px) {
    .user-flyout {
        width: calc(100vw - 32px);
        max-width: 280px;
        right: -8px;
    }
}

/* Fix specific components that cause horizontal scroll */
@media (max-width: 768px) {
    /* Ensure graphs don't overflow */
    .line-graph-container,
    .chart-container {
        max-width: 100%;
        overflow: hidden;
    }

    /* Replacement cards */
    .replacement-item {
        max-width: 100%;
    }

    .replacement-card-header {
        flex-direction: column;
        gap: 12px;
        padding: 12px !important;
    }

    .replacement-card-header > div {
        width: 100%;
        flex-direction: column;
        gap: 8px;
    }

    .replacement-card-header > div > div {
        width: 100%;
    }

    /* Case actions */
    .case-actions {
        display: flex;
        gap: 4px;
        flex-wrap: wrap;
    }

    .case-actions button {
        flex: 1;
        min-width: 70px;
    }

    /* Drilldown table improvements */
    .drilldown-modal .table-container {
        overflow-x: auto;
    }

    /* Campaign table */
    #campaignTable {
        min-width: 600px;
    }

    /* Tracker bar chart */
    .chart-bars {
        padding: 0 8px;
        gap: 6px;
    }

    .bar-column {
        min-width: 50px;
    }

    /* Sentiment selector */
    .sentiment-selector {
        display: flex;
        gap: 4px;
        justify-content: center;
    }

    .sentiment-btn {
        font-size: 16px;
        padding: 4px;
    }

    /* Recording button */
    .btn-recording {
        padding: 6px;
    }
}

/* ============================================
   MOBILE HEADER - Fixed hamburger menu and logo
   ============================================ */

/* Mobile header for portal pages - only visible on small screens */
.mobile-portal-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    z-index: 1003;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

@media (max-width: 768px) {
    /* Show mobile header on portal pages only */
    body:has(.portal-layout) .mobile-portal-header,
    body:has(.media-portal-screen) .mobile-portal-header {
        display: flex;
    }
    
    /* Add top padding to portal content for mobile header */
    body:has(.portal-layout) .portal-layout,
    body:has(.media-portal-screen) .media-portal-screen {
        padding-top: 60px;
    }
    
    /* Adjust demo banner for mobile header */
    body:has(.portal-layout) #demoBanner,
    body:has(.media-portal-screen) #demoBanner {
        top: 60px !important;
    }
}

.mobile-portal-header .hamburger-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
}

.mobile-portal-header .mobile-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    text-decoration: none;
}

.mobile-portal-header .mobile-logo .logo-icon-svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.mobile-portal-header .mobile-logo .mobile-logo-text {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-portal-header .mobile-logo .logo-text {
    font-family: 'Playfair Display', serif;
    font-size: 18px;
    font-weight: 700;
}

.mobile-portal-header .mobile-logo .portal-name-mobile {
    font-size: 11px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.7);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   NAVBAR POSITIONING - MOBILE & DESKTOP
   Fixed positioning for home page and non-portal pages
   Note: Navbar is hidden on portal pages via portal.css/media-portal.css
   ============================================ */

/* Mobile: Fixed navbar at top */
@media (max-width: 768px) {
    .navbar {
        padding: 12px 16px;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
        width: 100% !important;
    }

    .navbar-brand {
        font-size: 18px;
    }

    .nav-links {
        display: none;
    }

    .sidebar-toggle {
        display: block !important;
    }

    /* Add top padding to body to account for fixed navbar */
    /* Note: This padding is overridden on portal pages where navbar is hidden */
    body {
        padding-top: 60px !important;
    }
    
    /* Reset body padding on portal pages (navbar is hidden) */
    body:has(.portal-layout),
    body:has(.media-portal-screen) {
        padding-top: 0 !important;
    }
}

/* Desktop: ALSO use fixed navbar for reliability */
@media (min-width: 769px) {
    /* Add body padding on desktop for fixed navbar */
    /* Note: This padding is overridden on portal pages where navbar is hidden */
    body {
        padding-top: 70px !important;
    }
    
    /* Reset body padding on portal pages (navbar is hidden) */
    body:has(.portal-layout),
    body:has(.media-portal-screen) {
        padding-top: 0 !important;
    }

    /* Use FIXED positioning on desktop too (more reliable than sticky) */
    .navbar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
        width: 100% !important;
    }
}

/* Utility classes for mobile */
.hide-mobile {
    display: none !important;
}

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

    .hide-desktop {
        display: none !important;
    }
}

/* Ensure images and embedded content are responsive */
img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* Fix table overflow with scroll shadows */
@media (max-width: 768px) {
    .table-container {
        background:
            linear-gradient(to right, white 30%, rgba(255, 255, 255, 0)),
            linear-gradient(to right, rgba(255, 255, 255, 0), white 70%) 0 100%,
            radial-gradient(farthest-side at 0% 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)),
            radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0)) 0 100%;
        background-repeat: no-repeat;
        background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
        background-position: 0 0, 100%, 0 0, 100%;
        background-attachment: local, local, scroll, scroll;
    }
    
    /* ============================================
       MEDIA PORTAL - PUBLISHER ITEMS RESPONSIVE
       Fix layout on small screens
       ============================================ */
    
    /* Allow publisher items to wrap on small screens */
    .publisher-item {
        flex-wrap: wrap;
        gap: 12px;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Keep publisher name and badge inline on media portal */
    .publisher-item .publisher-name {
        display: flex !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        gap: 0 !important;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 100%;
        white-space: nowrap;
    }
    
    /* Ensure rank badge stays small and inline within the name */
    .publisher-item .publisher-rank {
        flex-shrink: 0 !important;
        margin-right: 6px !important;
        display: inline-flex !important;
    }
    
    /* Publisher info takes full width on small screens */
    .publisher-info {
        flex: 1 1 100%;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }
    
    /* Publisher ID also should not overflow */
    .publisher-id {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: block;
    }
    
    /* Metrics and revenue/actions stack below on smaller screens */
    .publisher-metrics {
        flex: 1 1 auto;
        min-width: 0;
        text-align: left;
        max-width: 100%;
    }
    
    .publisher-revenue {
        flex: 1 1 auto;
        min-width: 0;
        text-align: left;
        font-size: 16px;
        max-width: 100%;
    }
    
    .publisher-actions {
        flex: 1 1 100%;
        justify-content: flex-start;
        gap: 8px;
        max-width: 100%;
    }
    
    /* Publisher action buttons should be smaller on mobile */
    .publisher-actions .btn-action {
        padding: 6px 12px;
        font-size: 12px;
    }
    
    /* Make chart cards responsive */
    .chart-card {
        padding: 16px !important;
        overflow: hidden;
        max-width: 100% !important;
        box-sizing: border-box !important;
        margin: 0 !important;
    }
    
    /* Ensure publisher list doesn't overflow */
    .publisher-list {
        width: 100%;
        max-width: 100%;
        overflow: hidden;
        box-sizing: border-box;
    }
    
    /* Make KPI grid (Revenue, Signups, etc.) stack in single column */
    .kpi-grid {
        display: grid !important;
        grid-template-columns: 1fr !important;
        gap: 16px;
        max-width: 100%;
    }
    
    /* Ensure KPI cards don't overflow */
    .kpi-card {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Make the two-column layout stack on small screens */
    .charts-row {
        display: grid !important;
        grid-template-columns: 1fr !important;
        max-width: 100%;
        overflow: hidden;
        gap: 24px;
    }
    
    /* Ensure all chart cards stay within bounds */
    .charts-row > * {
        max-width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }
    
    /* ============================================
       MEDIA PORTAL - GEOGRAPHIC DISTRIBUTION TAB
       ============================================ */
    
    /* Stack filter controls vertically on mobile */
    .section-header-row .filter-controls {
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }
    
    .section-header-row .filter-controls select {
        width: 100%;
    }
    
    /* Ensure geo tables have proper scroll indicators */
    .table-scroll-container {
        position: relative;
        margin-bottom: 24px;
    }
    
    /* Add subtle shadow to indicate scrollable content */
    .table-scroll-container::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to right, rgba(255,255,255,0), rgba(0,0,0,0.05));
        pointer-events: none;
    }
    
    /* ============================================
       CLIENT PORTAL - RETURNS TAB RESPONSIVE
       ============================================ */
    
    /* Target the specific two-column layout and force it to stack */
    .returns-two-column-layout {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* NUCLEAR OPTION: Force ALL grid layouts in Returns tab to stack on mobile using attribute selectors */
    #tab-returns > div[style*="display"][style*="grid"] {
        display: block !important;
        grid-template-columns: 1fr !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
    }
    
    /* Target the specific two-column grid container */
    #tab-returns > div[style*="grid-template-columns"][style*="1fr 1fr"] {
        display: block !important;
        grid-template-columns: 1fr !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Force all child portal-section divs to stack */
    #tab-returns > div[style] > .portal-section,
    #tab-returns > div > .portal-section {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 16px !important;
        float: none !important;
    }
    
    /* Ensure portal sections in Returns tab don't overflow */
    #tab-returns .portal-section {
        max-width: 100% !important;
        width: 100% !important;
        min-width: 0 !important;
        overflow: hidden !important;
        box-sizing: border-box !important;
        padding: 16px !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
    
    /* Make sure all divs with inline styles in Returns tab are contained */
    #tab-returns > div[style],
    #tab-returns .portal-section > div,
    #tab-returns div[style] {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Override the gap property too */
    #tab-returns > div[style*="gap"] {
        gap: 16px !important;
    }
    
    /* Cancelation reasons list responsive */
    .cancelation-reasons-list {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .cancelation-reason-item {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* Make replacement cards responsive */
    .replacement-item {
        max-width: 100%;
        overflow: hidden;
    }
    
    .replacement-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
    }
    
    .replacement-card-header > div {
        width: 100%;
        flex-direction: column !important;
        gap: 12px !important;
    }
    
    .replacement-card-header > div > div {
        width: 100%;
    }
    
    /* Stack data points on mobile */
    .replacement-card-content > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr 1fr !important;
    }
    
    /* Stack notes sections on mobile */
    .replacement-card-content > div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Ensure any tables in Returns tab are scrollable */
    #tab-returns .cases-table-wrapper,
    #tab-returns .table-container,
    #tab-returns .table-scroll-container {
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        box-sizing: border-box;
    }
    
    #tab-returns table,
    #tab-returns .data-table,
    #tab-returns .cases-table {
        min-width: 600px;
    }
    
    /* Make DQ/Return report tables scrollable with larger min-width for many columns */
    #tab-returns table[id*="dq"],
    #tab-returns table[id*="DQ"],
    #tab-returns table[id*="return"],
    #tab-returns table[id*="Return"],
    #tab-returns table.drilldown-table {
        min-width: 900px;
    }
    
    /* Add scroll indicator for tables in Returns tab */
    #tab-returns .table-scroll-container,
    #tab-returns .cases-table-wrapper {
        position: relative;
    }
    
    #tab-returns .table-scroll-container::after,
    #tab-returns .cases-table-wrapper::after {
        content: '';
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 30px;
        background: linear-gradient(to right, rgba(255,255,255,0), rgba(0,0,0,0.05));
        pointer-events: none;
    }
    
    /* ============================================
       MEDIA PORTAL - RETURN SUMMARY RESPONSIVE
       ============================================ */
    
    /* Make return summary items responsive */
    .return-summary-item {
        max-width: 100% !important;
        width: 100% !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }
    
    /* Make return summary headers stack on mobile */
    .return-summary-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding: 12px 16px !important;
        overflow: visible !important;
        cursor: pointer !important;
    }
    
    /* Force all child divs in header to stack and wrap */
    .return-summary-header > div {
        width: 100% !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
        overflow: visible !important;
        word-wrap: break-word !important;
        white-space: normal !important;
    }
    
    .return-summary-header > div[style*="flex"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100% !important;
        display: flex !important;
    }
    
    /* Ensure spans and text elements wrap */
    .return-summary-header span {
        white-space: normal !important;
        word-wrap: break-word !important;
        max-width: 100% !important;
    }
    
    /* Make expanded content visible and scrollable */
    .return-summary-content {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 500px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        box-sizing: border-box !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Ensure collapsed state hides content */
    .return-summary-item.collapsed .return-summary-content {
        display: none !important;
    }
    
    /* Make return summary body stack on mobile */
    .return-summary-body {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
        padding: 16px !important;
        box-sizing: border-box !important;
    }
    
    .return-summary-body > div {
        width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        word-wrap: break-word !important;
    }
    
    /* Make return summary notes stack on mobile */
    .return-summary-notes {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
        padding: 12px 16px !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
    }
    
    .return-summary-notes > div {
        flex: none !important;
        width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        word-wrap: break-word !important;
        white-space: normal !important;
    }
    
    .return-summary-notes > div > div {
        width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        word-wrap: break-word !important;
        white-space: normal !important;
    }
    
    /* Make return summary footer stack on mobile */
    .return-summary-footer {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
        padding: 12px 16px !important;
    }
    
    .return-summary-footer span {
        display: block !important;
        white-space: normal !important;
        word-wrap: break-word !important;
    }
    
    /* Collapse icon rotation */
    .collapse-icon {
        flex-shrink: 0 !important;
        transition: transform 0.2s !important;
    }
    
    .return-summary-item.collapsed .collapse-icon {
        transform: rotate(-90deg) !important;
    }
    
    /* ============================================
       CLIENT PORTAL - REPLACEMENT CARDS RESPONSIVE
       ============================================ */
    
    /* Make replacement items responsive */
    .replacement-item {
        max-width: 100% !important;
        width: 100% !important;
        overflow: visible !important;
        box-sizing: border-box !important;
        margin-bottom: 16px !important;
    }
    
    /* Make replacement card headers stack on mobile */
    .replacement-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding: 12px 16px !important;
        overflow: visible !important;
        cursor: pointer !important;
    }
    
    /* Force all child divs in replacement header to stack */
    .replacement-card-header > div {
        width: 100% !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
        overflow: visible !important;
        word-wrap: break-word !important;
        white-space: normal !important;
    }
    
    .replacement-card-header > div[style*="flex"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        width: 100% !important;
        display: flex !important;
    }
    
    /* Ensure spans in replacement header wrap */
    .replacement-card-header span {
        white-space: normal !important;
        word-wrap: break-word !important;
        max-width: 100% !important;
    }
    
    /* Make replacement card content scrollable when visible */
    .replacement-card-content {
        max-width: 100% !important;
        max-height: 500px !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        box-sizing: border-box !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Stack data points in replacement cards */
    .replacement-card-content > div[style*="grid-template-columns"] {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
        padding: 16px !important;
        box-sizing: border-box !important;
    }
    
    .replacement-card-content > div > div {
        width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        word-wrap: break-word !important;
    }
    
    /* Stack notes sections in replacement cards */
    .replacement-card-content > div[style*="grid-template-columns: 1fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 16px !important;
        padding: 12px 16px !important;
        box-sizing: border-box !important;
    }
    
    .replacement-card-content > div[style*="grid-template-columns: 1fr 1fr"] > div {
        flex: none !important;
        width: 100% !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        word-wrap: break-word !important;
        white-space: normal !important;
    }
    
    /* Make replacement footer stack on mobile */
    .replacement-card-footer {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 8px !important;
        padding: 12px 16px !important;
    }
    
    .replacement-card-footer span {
        display: block !important;
        white-space: normal !important;
        word-wrap: break-word !important;
    }
    
    /* Replacement list container */
    .replacements-list {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
    
    /* ============================================
       COLLAPSIBLE SECTIONS RESPONSIVE
       ============================================ */
    
    /* Make collapsible section headers responsive */
    .stats-section-title,
    .section-toggle {
        font-size: 16px !important;
        line-height: 1.4 !important;
        padding: 12px 16px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        flex-wrap: nowrap !important;
        overflow: visible !important;
    }
    
    .stats-section-title .toggle-icon,
    .section-toggle .toggle-icon {
        flex-shrink: 0 !important;
        margin-left: 8px !important;
    }
    
    /* Section header row with filters */
    .section-header-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 12px !important;
        padding: 12px 16px !important;
    }
    
    .section-header-row h2 {
        width: 100% !important;
    }
    
    .filter-controls {
        width: 100% !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .filter-controls select {
        width: 100% !important;
    }
    
    /* Ensure section content is visible when expanded */
    .section-content {
        overflow: visible !important;
        max-width: 100% !important;
    }
    
    /* Collapsible section styling */
    .collapsible-section {
        overflow: visible !important;
        max-width: 100% !important;
    }
    
    /* ============================================
       CLIENT PORTAL HOME TAB - RESPONSIVE CARDS
       ============================================ */
    
    /* Make stat grids responsive - stack on mobile */
    .stats-grid-6,
    .stats-grid-4,
    .dashboard-stats {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }
    
    /* Make stat cards full width on mobile */
    .stat-card,
    .stat-card-highlight {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Make supplier performance two-column layout stack on mobile */
    #tab-home > div[style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }
    
    /* Ensure all portal sections on home tab are responsive */
    #tab-home .portal-section {
        width: 100% !important;
        max-width: 100% !important;
        padding: 16px !important;
        box-sizing: border-box !important;
    }
    
    /* Make supplier ranking items responsive */
    .supplier-ranking-item {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .supplier-info {
        width: 100% !important;
    }
    
    .supplier-stats {
        width: 100% !important;
        justify-content: space-between !important;
    }
    
    /* Make line graph responsive */
    .line-graph-container {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    /* Make accounting overview responsive */
    .accounting-overview {
        padding: 12px !important;
    }
    
    .accounting-stats {
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }
    
    .accounting-stat {
        padding: 12px !important;
    }
    
    /* ============================================
       CLIENT PORTAL - SUPPLIER RANKING RESPONSIVE
       Ensure badge stays inline with name on small screens
       ============================================ */
    
    /* Ensure supplier name and badge stay inline */
    .supplier-ranking-item {
        flex-wrap: nowrap;
        gap: 12px;
    }
    
    /* Keep the supplier name flexbox inline */
    .supplier-name {
        display: flex !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Ensure rank badge stays small and inline */
    .supplier-rank {
        flex-shrink: 0 !important;
        margin-right: 6px !important;
    }
    
    /* Make stats stack vertically on very small screens */
    @media (max-width: 480px) {
        .supplier-stats {
            align-items: flex-start;
            text-align: left;
        }
    }
}

/* Replacement Cards - Mobile Responsive */
@media (max-width: 768px) {
    .replacements-list {
        gap: 10px;
        max-height: calc(100vh - 400px);
        overflow-y: auto;
    }

    .replacement-item {
        font-size: 14px;
    }

    .replacement-card-header {
        padding: 12px 14px !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .replacement-card-header > div:first-child {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
        width: 100%;
    }

    .replacement-card-header > div:last-child {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    /* Metrics row - make it a 2-column grid */
    .replacement-card-header > div:first-child > div:last-child {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
        width: 100%;
    }

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

    /* Stack notes vertically on mobile */
    .replacement-card-content > div:last-child {
        grid-template-columns: 1fr !important;
    }

    /* Reduce data points grid */
    .replacement-card-content > div:first-child {
        padding: 10px !important;
        gap: 8px !important;
    }
}

@media (max-width: 480px) {
    .replacements-list {
        max-height: calc(100vh - 350px);
    }

    .replacement-card-header {
        padding: 10px 12px !important;
        gap: 8px !important;
    }

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

    /* Single column for metrics on very small screens */
    .replacement-card-header > div:first-child > div:last-child {
        grid-template-columns: 1fr !important;
    }

    .replacement-card-content > div:first-child {
        grid-template-columns: 1fr !important;
        padding: 8px !important;
    }
}

/* Pagination - ensure it's always visible and accessible */
.pagination {
    margin-top: 16px;
    padding: 12px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

@media (max-width: 480px) {
    .pagination {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px;
    }

    .pagination-btn {
        padding: 6px 10px;
        font-size: 13px;
    }

    .pagination-info {
        width: 100%;
        text-align: center;
        order: -1;
        margin-bottom: 8px;
    }
}
