/* --- DEFAULT DESKTOP/LARGE SCREEN LAYOUT --- */
@media (min-width: 1025px) {
    DIV.bg_bottom {
        display: flex;
        flex-direction: row;
        align-items: flex-start;
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;
    }
    
    DIV.content_left {
        flex: 0 0 auto;
        margin-bottom: 0 !important;
        padding-bottom: 10px !important;
    }
    
    DIV.content_right {
        flex: 1;
        margin-top: 0 !important;
        margin-bottom: 0 !important;
        padding-bottom: 0 !important;
    }
    
    DIV.cruise_detail_content_top {
        margin-bottom: 0 !important;
        padding-bottom: 10px !important;
    }
    DIV.content_right > DIV.cruise_detail_content_top {
        transform: none !important;
        width: auto !important;
        max-width: none !important;
    }
}

/* --- MOBILE PORTRAIT LAYOUT (NO SCALING/TRANSFORM) --- */
@media (max-width: 768px) and (orientation: portrait) {
    
    /* CRITICAL: Prevent horizontal overflow on parent containers */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    #wrapper {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }
    
    #content {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }
    
    /* 1. Overall Structure */
    .bg_bottom {
        display: flex;
        flex-direction: column;
        padding: 0 !important;
        margin: 0 !important;
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }
    
    DIV.content_left {
        width: 100% !important;
        max-width: 100% !important;
        float: none !important;
        padding: 10px !important;
        box-sizing: border-box !important;
        order: 2;
    }
    
    DIV.content_right {
        width: 100% !important;
        max-width: 100vw !important;
        padding: 0 !important;
        margin: 0 !important; 
        overflow-x: hidden !important;
        order: 1 !important;
        box-sizing: border-box !important;
    }

    /* 2. Disable Scaling on the main content block */
    DIV.content_right > DIV.cruise_detail_content_top {
        transform: none !important;
        width: 100% !important; 
        max-width: 100% !important;
        margin: 0 !important;
        padding: 10px !important;
        position: static !important;
        overflow-x: hidden !important;
        box-sizing: border-box !important;
    }

    /* 3. CRITICAL FIX: All corner spans that might extend beyond viewport */
    .corner_top_left,
    .corner_top_right,
    .corner_bottom_left,
    .corner_bottom_right {
        display: none !important;
    }

    /* 4. FIX: Corner tab right container - Allow wrapping */
    DIV.corner_tab_right {
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        box-sizing: border-box !important;
        padding: 0 !important;
        margin: 0 !important;
        position: relative !important;
    }

    /* 5. FIX: Tabs all in one horizontal line on portrait - SIMPLIFIED STYLING */
    DIV.cruise_detail_tab_sub {
        overflow: visible !important;
        white-space: normal !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 5px 2px !important;
        box-sizing: border-box !important;
        margin: 0 !important;
    }

    DIV.cruise_detail_tab_sub ul {
        display: flex !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        justify-content: space-between !important;
        gap: 2px !important;
    }
    
    DIV.cruise_detail_tab_sub li {
        flex: 1 1 0 !important;
        margin: 0 !important; 
        padding: 0 !important;
        display: flex !important;
        min-width: 0 !important;
        height: auto !important;
        min-height: 37px !important;
        /* Default grey tab appearance (inactive) */
        background: linear-gradient(to bottom, #d4d4d4 0%, #b8b8b8 50%, #a0a0a0 100%) !important;
        border-radius: 4px 4px 0 0 !important;
        border: 1px solid #888 !important;
        border-bottom: none !important;
        overflow: hidden !important;
    }
    
    /* Active/selected tab - green color (using JavaScript class) */
    DIV.cruise_detail_tab_sub li.tab_index_select {
        background: linear-gradient(to bottom, #99d14e 0%, #85c226 50%, #72a821 100%) !important;
        border: 1px solid #5a8c1a !important;
        border-bottom: none !important;
    }
    
    /* Ensure unselected tabs stay grey */
    DIV.cruise_detail_tab_sub li.tab_index_unselect {
        background: linear-gradient(to bottom, #d4d4d4 0%, #b8b8b8 50%, #a0a0a0 100%) !important;
        border: 1px solid #888 !important;
        border-bottom: none !important;
    }
    
    /* CRITICAL FIX: Hide the decorative left/mid/right spans on mobile */
    DIV.cruise_detail_tab_sub li .cruise_detail_tab_left,
    DIV.cruise_detail_tab_sub li .cruise_detail_tab_left_first,
    DIV.cruise_detail_tab_sub li .cruise_detail_tab_right,
    DIV.cruise_detail_tab_sub li .cruise_detail_tab_right_first {
        display: none !important;
    }

    /* Style the middle span as the full tab */
    DIV.cruise_detail_tab_sub li .cruise_detail_tab_mid,
    DIV.cruise_detail_tab_sub li .cruise_detail_tab_mid_first {
        padding: 6px 4px !important;
        font-size: 8.5px !important;
        line-height: 1.2 !important;
        white-space: normal !important;
        word-wrap: break-word !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        flex: 1 !important;
        min-height: 25px !important;
        width: 100% !important;
        background: transparent !important;
        font-weight: 500 !important;
        color: #626262 !important;
    }

    /* Active tab text - white color for green background */
    DIV.cruise_detail_tab_sub li.tab_index_select .cruise_detail_tab_mid,
    DIV.cruise_detail_tab_sub li.tab_index_select .cruise_detail_tab_mid_first {
        color: #fff !important;
        font-weight: bold !important;
    }
    
    /* Unselected tab text - grey color */
    DIV.cruise_detail_tab_sub li.tab_index_unselect .cruise_detail_tab_mid,
    DIV.cruise_detail_tab_sub li.tab_index_unselect .cruise_detail_tab_mid_first {
        color: #626262 !important;
        font-weight: 500 !important;
    }

    /* 6. FIX: Content Cut-Off */
    DIV.cruise_detail_content_top * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Adjust specific nested layout elements */
    DIV.cruise_detail_content_top .tab1_view_left,
    DIV.cruise_detail_content_top .tab1_view_right,
    DIV.cruise_detail_content_top .cruise_detail_summary_right {
        float: none !important;
        width: 100% !important;
        padding: 10px !important;
        margin: 0 !important;
        clear: both !important;
    }

    /* All tab content divs */
    DIV.cruise_detail_tab,
    DIV.cruise_detail_tab2,
    DIV.cruise_detail_tab5,
    DIV.cruise_detail_tab6 {
        width: 100% !important;
        max-width: 100% !important;
        padding: 10px !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* Ensure images reflow */
    DIV.cruise_detail_content_top img {
        height: auto !important;
        max-width: 100% !important;
        width: auto !important;
    }
    
    /* Tables */
    DIV.cruise_detail_content_top table,
    DIV.cruise_detail_content_top .td_table {
        width: 100% !important;
        max-width: 100% !important;
        table-layout: auto !important;
        overflow-x: auto !important;
        display: block !important;
    }
    
    /* Breadcrumbs */
    DIV.cruise_detail_content_top .breadcrumbs {
        font-size: 11px !important;
        padding: 10px !important;
        white-space: normal !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Description images container */
    .cruise_detail_description_img {
        width: 100% !important;
        max-width: 100% !important;
        padding: 5px !important;
        box-sizing: border-box !important;
    }

    /* Tab view container */
    .cruise_detail_tab1_view {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: hidden !important;
    }
}

/* --- MOBILE LANDSCAPE LAYOUT --- */
@media (max-width: 1024px) and (orientation: landscape) {
    html, body {
        overflow-x: hidden !important;
    }
    
    #wrapper, #content {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    .bg_bottom {
        flex-direction: column;
        overflow-x: hidden !important;
    }
    
    .corner_top_left,
    .corner_top_right,
    .corner_bottom_left,
    .corner_bottom_right {
        display: none !important;
    }
    
    DIV.corner_tab_right {
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }

    DIV.cruise_detail_tab_sub {
        overflow: visible !important;
    }

    DIV.cruise_detail_tab_sub ul {
        flex-wrap: wrap !important;
        gap: 5px !important;
    }

    DIV.cruise_detail_tab_sub li {
        flex: 0 1 auto !important;
        max-width: 32% !important;
    }
    
    DIV.content_right {
        width: 100% !important;
        transform: none !important;
        overflow-x: hidden !important;
    }
    
    DIV.content_right > DIV.cruise_detail_content_top {
        transform: none !important;
        width: 100% !important;
        overflow-x: hidden !important;
    }
    
    DIV.content_right > DIV.cruise_detail_content_top * {
        max-width: 100% !important;
    }
}

/* --- GLOBAL CLEANUP --- */
DIV#content, DIV#wrapper, DIV.cruise_detail_content_top {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
}
.bg_bottom_left, .bg_bottom_right {
    display: none !important;
}
DIV.content_right, DIV.cruise_detail_content_top {
    opacity: 1 !important;
    visibility: visible !important;
}