/* ===================================================================
   MOBILE LAYOUT FIXES FOR GEOVEIL V1
   Fixes: Tab visibility, modal overflow, plot clipping, VADASE overlaps
   =================================================================== */

/* Modal Styles - FIXED MOBILE LAYOUT */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 10000;
    justify-content: center;
    align-items: flex-start;
    padding: 10px;
    padding-top: 50px; /* Space for close button */
    transition: opacity 0.5s;
}

.modal-content {
    background-color: #fff;
    margin: 0 auto;
    padding: 15px;
    padding-top: 50px; /* Space for close button */
    border: 1px solid #888;
    width: 95%;
    max-width: 800px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border-radius: 12px;
    overflow-y: auto;
    max-height: calc(100vh - 60px);
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 10001;
}

.close {
    position: fixed;
    top: 15px;
    right: 15px;
    color: #fff;
    background-color: #f00;
    width: 36px;
    height: 36px;
    line-height: 36px;
    text-align: center;
    padding: 0;
    border-radius: 50%;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10003;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.close:hover,
.close:active {
    background-color: #d00;
}

/* Tab System - IMPROVED MOBILE VISIBILITY */
.tab-container {
    width: 100%;
    position: relative;
    margin-bottom: 15px;
}

.tab-header {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    border-bottom: 2px solid #e8e8e8;
    padding-bottom: 0;
    justify-content: space-around;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.tab-link {
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    color: #555;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex: 1 1 auto;
    min-width: fit-content;
    white-space: nowrap;
}

.tab-link i {
    font-size: 18px;
    flex-shrink: 0;
}

.tab-link span {
    display: inline-block;
}

.tab-link:hover,
.tab-link:active {
    color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.tab-link.active {
    color: #667eea;
    border-bottom-color: #667eea;
    font-weight: 600;
    background: rgba(102, 126, 234, 0.08);
}

.tab-content {
    display: none;
    padding: 10px 0;
}

.tab-content.active {
    display: block;
}

.tab-content h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #2c3e50;
}

/* Plot Div - PREVENT CLIPPING */
#plotDiv {
    width: 100%;
    height: auto;
    min-height: 400px;
    display: flex;
    justify-content: center;
    overflow: visible;
    margin: 10px 0;
}

/* Map Container */
#map {
    height: 600px;
    width: 100%;
    z-index: 1;
}

/* Table Container Styles */
.table-container {
    max-height: 400px;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    border: 1px solid #e8e8e8;
    border-radius: 6px;
    margin-bottom: 15px;
    touch-action: pan-x pan-y;
}

.table-container table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    text-align: left;
    margin-bottom: 0;
}

.table-container thead th {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #ffffff;
    padding: 10px 8px;
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.table-container tbody td {
    padding: 10px 8px;
    border-bottom: 1px solid #f0f0f0;
    text-align: center;
    font-size: 11px;
    color: #444;
}

.table-container tbody tr:nth-child(even) {
    background-color: #fafafa;
}

.table-container tbody tr:hover,
.table-container tbody tr:active {
    background-color: #f0f4ff;
}

/* VADASE Tab Styles - FIXED OVERLAPPING */
.vadase-info-box {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    border: 1px solid #667eea30;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 15px;
}

.vadase-description {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
    color: #555;
}

.vadase-description i {
    color: #667eea;
    margin-right: 5px;
    vertical-align: middle;
}

#vadasePlotDiv {
    min-height: 400px;
    margin: 15px 0;
    background: white;
    border-radius: 8px;
    padding: 10px;
    overflow: visible;
}

.vadase-summary-box {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
    padding: 15px;
    background: #F8F9FA;
    border-radius: 8px;
    border: 1px solid #E0E0E0;
}

.summary-section {
    background: white;
    padding: 12px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}

.summary-section h5 {
    margin: 0 0 12px 0;
    font-size: 13px;
    color: #333;
    display: flex;
    align-items: center;
    gap: 6px;
    padding-bottom: 8px;
    border-bottom: 2px solid #667eea;
}

.summary-section h5 i {
    color: #667eea;
    font-size: 16px;
}

.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.summary-item {
    display: flex;
    flex-direction: column;
    padding: 8px;
    background: #F8F9FA;
    border-radius: 4px;
}

.summary-label {
    font-size: 10px;
    color: #999;
    margin-bottom: 4px;
    font-weight: 500;
    text-transform: uppercase;
}

.summary-value {
    font-size: 13px;
    font-weight: bold;
    color: #667eea;
    word-break: break-word;
}

.summary-item-bw {
    position: relative;
}

.bw-indicator {
    margin-top: 6px;
    height: 3px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    border-radius: 2px;
    transition: width 0.3s ease;
    min-width: 20px;
}

/* Date Picker Container */
.date-picker-container {
    width: auto;
    margin: 10px;
    font-weight: bold;
    color: rgb(86, 37, 210);
    text-align: center;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.date-picker-container label {
    color: rgb(86, 37, 210);
    white-space: nowrap;
    font-size: 14px;
}

#dateSelector {
    font-size: 14px;
    padding: 6px 10px;
    border: 1px solid rgb(86, 37, 210);
    color: rgb(86, 37, 210);
    border-radius: 4px;
    min-width: 140px;
}

/* ===================================================================
   MOBILE-SPECIFIC LAYOUTS (< 600px)
   =================================================================== */
@media (max-width: 600px) {
    .modal {
        padding: 5px;
        padding-top: 45px;
        align-items: flex-start;
    }

    .modal-content {
        width: 98%;
        max-width: 100%;
        padding: 12px;
        padding-top: 45px;
        max-height: calc(100vh - 50px);
        margin: 0;
        border-radius: 8px;
    }

    .close {
        top: 8px;
        right: 8px;
        width: 32px;
        height: 32px;
        line-height: 32px;
        font-size: 20px;
    }

    /* Tab System - Better Mobile Layout */
    .tab-header {
        gap: 4px;
        margin-bottom: 10px;
        padding-bottom: 0;
        border-bottom: 1px solid #e8e8e8;
    }

    .tab-link {
        padding: 10px 8px;
        font-size: 11px;
        gap: 4px;
        flex: 1 1 auto;
        min-width: 70px;
        border-radius: 6px 6px 0 0;
    }

    .tab-link i {
        font-size: 16px;
    }

    .tab-link span {
        display: none;
    }

    .tab-link[data-tab-name]::after {
        content: attr(data-tab-name);
        position: absolute;
        bottom: -18px;
        left: 50%;
        transform: translateX(-50%);
        font-size: 8px;
        font-weight: 600;
        color: #999;
        white-space: nowrap;
        opacity: 0;
        transition: opacity 0.2s;
    }

    .tab-link.active[data-tab-name]::after {
        opacity: 1;
        color: #667eea;
    }

    .tab-content {
        padding: 5px 0;
        margin-top: 10px;
    }

    .tab-content h3 {
        font-size: 14px;
        margin-bottom: 10px;
    }

    /* Plot Optimization */
    #plotDiv {
        width: 100% !important;
        min-height: 350px;
        overflow: visible;
        margin: 5px 0;
    }

    /* Plotly-specific mobile fixes */
    .js-plotly-plot {
        overflow: visible !important;
    }

    .js-plotly-plot .plotly {
        overflow: visible !important;
    }

    /* Map */
    #map {
        height: 450px;
        min-height: 400px;
    }

    /* Tables */
    .table-container {
        font-size: 10px;
        max-height: 300px;
        margin-bottom: 10px;
    }

    .table-container table {
        font-size: 10px;
    }

    .table-container thead th {
        font-size: 9px;
        padding: 8px 4px;
    }

    .table-container tbody td {
        font-size: 10px;
        padding: 8px 4px;
    }

    /* VADASE Mobile Optimizations */
    .vadase-info-box {
        padding: 10px;
        margin-bottom: 10px;
    }

    .vadase-description {
        font-size: 11px;
        line-height: 1.4;
    }

    #vadasePlotDiv {
        min-height: 300px;
        margin: 10px 0;
        padding: 5px;
    }

    .vadase-summary-box {
        gap: 12px;
        padding: 12px;
        margin-top: 15px;
    }

    .summary-section {
        padding: 10px;
    }

    .summary-section h5 {
        font-size: 12px;
        margin-bottom: 10px;
        padding-bottom: 6px;
    }

    .summary-section h5 i {
        font-size: 14px;
    }

    .summary-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .summary-item {
        padding: 6px;
    }

    .summary-label {
        font-size: 9px;
    }

    .summary-value {
        font-size: 12px;
    }

    .bw-indicator {
        height: 2px;
        margin-top: 4px;
    }

    /* Date Picker */
    .date-picker-container {
        width: 100%;
        padding: 8px;
        gap: 6px;
    }

    .date-picker-container label {
        font-size: 12px;
    }

    #dateSelector {
        font-size: 13px;
        padding: 5px 8px;
        min-width: 120px;
    }
}

/* Extra Small Screens */
@media (max-width: 360px) {
    .tab-link {
        min-width: 60px;
        padding: 8px 6px;
    }

    .tab-link i {
        font-size: 14px;
    }

    .modal-content {
        padding: 10px;
        padding-top: 42px;
    }

    .summary-grid {
        gap: 6px;
    }

    #vadasePlotDiv {
        min-height: 280px;
    }
}

/* Tablet Landscape */
@media (min-width: 601px) and (max-width: 991px) {
    .modal-content {
        width: 85%;
        max-width: 700px;
        padding: 20px;
    }

    #map {
        height: 700px;
    }

    .vadase-summary-box {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 15px;
    }

    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Desktop */
@media (min-width: 992px) {
    .modal-content {
        width: 70%;
        max-width: 900px;
        padding: 25px;
    }

    #map {
        height: 800px;
    }

    .vadase-summary-box {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 20px;
    }

    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .tab-link span {
        display: inline-block;
    }
}

/* Ensure proper z-index layering */
header, section, footer {
    position: relative;
    z-index: 1;
}

header.header-menu {
    z-index: 100;
}

/* Plotly modebar positioning */
.js-plotly-plot .modebar {
    position: absolute !important;
    top: 5px !important;
    right: 5px !important;
    z-index: 9998;
}

#plotDiv, .js-plotly-plot {
    position: relative;
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
    position: fixed;
    width: 100%;
}