body {
    margin: 0;
    padding: 0;
    overflow: auto;
}

/* Default to 5 columns (20%) for most screens (TVs, Desktops, Tablets in Landscape) */
.col-md-custom {
    flex: 0 0 20% !important;
    max-width: 20% !important;
    width: 20% !important;
}

/* Force 1 column on mobile devices (phones in portrait/landscape up to 767.98px max width) */
/* This breakpoint ensures that tablets and larger screens will maintain the multi-column layout */
@media (max-width: 767.98px) {
    html,
    body {
        height: auto !important;
        overflow-y: auto !important;
        overscroll-behavior-y: auto;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
    }

    /* Dash root container uses inline fixed-height styles; override on mobile. */
    .container-fluid {
        height: auto !important;
        max-height: none !important;
        overflow-y: visible !important;
    }

    .header-main-title {
        display: none !important;
    }

    #bloco-sync {
        display: none !important;
    }

    .mobile-title-update-row {
        margin-top: 0.2rem;
        margin-bottom: 0.5rem;
    }

    .mobile-title-update-inner {
        position: relative;
        width: 100%;
        min-height: 68px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0.2rem 7.2rem 0.2rem 0.4rem;
    }

    .mobile-header-title {
        font-size: 1.7rem !important;
        line-height: 1.05;
        text-align: center;
        width: 100%;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mobile-last-update {
        position: absolute;
        right: 0.25rem;
        top: 50%;
        transform: translateY(-50%);
        text-align: right;
        white-space: nowrap;
    }

    #output-ultimo-recebimento-mobile {
        font-size: 1.05rem !important;
    }

    .col-md-custom {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        /* Ensure normal height and scrolling on mobile */
        height: auto !important;
        min-height: 350px;
        margin-bottom: 20px !important;
    }

    #conteudo-dinamico {
        overflow-y: visible !important;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        /* Force block display to stack items nicely if flex causes issues, optional but safe */
        display: block !important; 
    }

    /* Tabs need auto height on mobile because labels can wrap to 2 lines. */
    #tabs-principal {
        height: auto !important;
        min-height: 44px;
    }

    #tabs-principal > div {
        height: auto !important;
    }

    .tabs-principal {
        position: relative;
        z-index: 2;
        background: #F8FAFC;
    }

    /* Keep tab labels centered and readable when text wraps on small screens */
    #tabs-principal .tab {
        height: auto !important;
        min-height: 44px;
        padding: 6px 6px !important;
        font-size: 0.72rem !important;
        line-height: 1.1;
        white-space: normal !important;
        text-align: center;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    /* Monitor card plant name: larger font and proper wrap only on mobile */
    .monitor-plant-title {
        font-size: 1.05rem !important;
        min-height: 2.4em !important;
        line-height: 1.2 !important;
        margin-bottom: 0.25rem !important;
        white-space: normal !important;
        word-break: break-word;
        overflow: hidden;
    }

    /* Current production number inside Plotly indicator gauge on mobile */
    .monitor-gauge-graph .indicatorlayer .number,
    .monitor-gauge-graph .trace.indicator .number {
        font-size: 20px !important;
    }
}

@media (min-width: 1600px) {
    .tab-ajustada-tv .card-body {
        padding: 0.75rem 1rem !important;
    }

    .tab-ajustada-tv h2 {
        font-size: 1.25rem !important;
    }

    #grafico-mensal-barras,
    #grafico-heatmap {
        height: 50vh !important;
        min-height: 340px !important;
    }

    .tab-ajustada-tv .Select-control {
        min-height: 34px !important;
        height: 34px !important;
    }

    .tab-ajustada-tv .Select-placeholder,
    .tab-ajustada-tv .Select-value-label {
        line-height: 34px !important;
        font-size: 0.9rem !important;
    }

    .tab-ajustada-tv .btn {
        font-size: 0.85rem !important;
        padding-top: 0.3rem !important;
        padding-bottom: 0.3rem !important;
    }
}