/* ===================================================================
   SIMPLIFIED MOBILE FIX FOR GEOVEIL V2
   Inspired by V1's working approach
   Fixes: Close button visibility, tabs visibility, plot positioning
   =================================================================== */

/* =========================
   CLOSE BUTTON - ALWAYS VISIBLE
   ========================= */
.close {
    position: absolute !important;
    color: #333 !important;
    background-color: transparent !important;
    width: 25px;
    height: 25px;
    line-height: 23px;
    text-align: center;
    border-radius: 0;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    z-index: 999999 !important;
    border: 2px solid #333 !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    box-shadow: none;
    top: 15px;
    right: 15px;
    transition: all 0.2s ease;
}

.close:hover,
.close:active {
    transform: none;
    background-color: #f0f0f0 !important;
}

/* =========================
   MODAL
   ========================= */
.modal {
    display: none;
    position: fixed;
    top: 80px;
    left: 0;
    width: 100%;
    height: calc(100% - 80px);
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 100000;
    overflow-y: auto;
    padding: 15px;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    position: relative;
    background-color: #fff;
    margin: 10px auto;
    padding: 15px;
    padding-top: 55px;
    border: 1px solid #888;
    width: 95%;
    max-width: 800px;
    border-radius: 12px;
    max-height: none;
    overflow-y: visible;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* =========================
   TABS - SIMPLE AND VISIBLE
   ========================= */
.tab-container {
    width: 100%;
    display: flex;
    flex-direction: column;
}

.tab-header {
    display: flex !important;
    gap: 5px;
    margin-top: 70px;
    border-bottom: 2px solid #e0e0e0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    visibility: visible !important;
    opacity: 1 !important;
}

.tab-link {
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-weight: 500;
    color: #666;
    transition: all 0.3s;
    display: flex !important;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
    visibility: visible !important;
    opacity: 1 !important;
    min-height: 44px;
}

.tab-link:hover {
    color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.tab-link.active {
    color: #667eea !important;
    border-bottom-color: #667eea !important;
    font-weight: 600;
    background: rgba(102, 126, 234, 0.08) !important;
}

.tab-link i {
    font-size: 18px;
}

.tab-content {
    display: none;
    padding: 0 !important;
}

.tab-content.active {
    display: block !important;
}

/* =========================
   PLOT - NO SHIFTING OR CLIPPING
   ========================= */
#plotDiv {
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
    min-height: 400px;
    margin: 0 0 0 -60px !important;
    padding: 0 !important;
}

/* Ensure plotly container doesn't shift */
.js-plotly-plot {
    margin: 0 !important;
}

/* =========================
   TABLES
   ========================= */
.table-container {
    max-height: 400px;
    overflow: auto;
    position: relative;
    border: 1px solid #ddd;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
}

.table-container table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table-container thead th {
    background-color: #007bff;
    color: #ffffff;
    padding: 12px 8px;
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.table-container tbody td {
    padding: 10px 8px;
    border-bottom: 1px solid #e0e0e0;
    text-align: center;
    font-size: 12px;
}

.table-container tbody tr:nth-child(even) {
    background-color: #f8f9fa;
}

.table-container tbody tr:hover {
    background-color: #e7f3ff;
}

/* =========================
   MODAL LOADER
   ========================= */
.modal-loader {
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal-loader.hidden {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    display: none !important;
}

/* =========================
   MOBILE SPECIFIC (<= 768px)
   ========================= */
@media (max-width: 768px) {
    .modal {
        padding: 10px;
        top: 70px;
        height: calc(100% - 70px);
    }
    
    .modal-content {
        width: 96%;
        padding: 12px;
        padding-top: 0px;
    }
    
    .close {
        top: 12px;
        right: 12px;
        width: 25px;
        height: 25px;
        line-height: 23px;
        font-size: 16px;
    }
    
    .tab-header {
        gap: 3px;
        margin-bottom: 15px;
    }
    
    .tab-link {
        padding: 10px 12px;
        font-size: 14px;
        min-height: 44px;
    }
    
    .tab-link i {
        font-size: 16px;
    }
    
    .tab-link span {
        font-size: 13px;
    }
    
    .table-container {
        max-height: 350px;
    }
    
    .table-container table {
        font-size: 11px;
    }
    
    .table-container thead th {
        padding: 10px 6px;
        font-size: 11px;
    }
    
    .table-container tbody td {
        padding: 8px 6px;
        font-size: 11px;
    }
    
    #plotDiv {
        min-height: 350px;
    }
}

/* =========================
   SMALL MOBILE (<= 480px)
   ========================= */
@media (max-width: 480px) {
    .modal {
        padding: 8px;
    }
    
    .modal-content {
        width: 98%;
        padding: 10px;
        padding-top: 50px;
    }
    
    .close {
        top: 120px;
        right: 10px;
        width: 25px;
        height: 25px;
        line-height: 23px;
        font-size: 16px;
    }
    
    .tab-header {
        gap: 2px;
    }
    
    .tab-link {
        padding: 8px 10px;
        font-size: 13px;
        min-height: 42px;
        gap: 6px;
    }
    
    .tab-link i {
        font-size: 15px;
    }
    
    /* Keep text visible even on small screens */
    .tab-link span {
        display: inline-block;
        font-size: 12px;
    }
    
    .table-container {
        max-height: 300px;
    }
    
    #plotDiv {
        min-height: 300px;
    }
}

/* =========================
   DESKTOP (> 768px)
   ========================= */
@media (min-width: 769px) {
    .modal {
        top: 0;
        height: 100%;
        padding: 20px;
    }
    
    .modal-content {
        width: 70%;
        max-width: 800px;
        margin: 150px auto 20px auto;
        padding: 20px;
        padding-top: 60px;
        max-height: calc(100vh - 120px);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    
    .close {
        top: 15px;
        right: 15px;
        width: 25px;
        height: 25px;
        line-height: 23px;
        font-size: 18px;
        position: absolute;
    }
}

/* =========================
   PREVENT BODY SCROLL
   ========================= */
body.modal-open {
    overflow: hidden;
}

/* =========================
   PLOTLY MODEBAR FIX
   ========================= */
@media (max-width: 600px) {
    .js-plotly-plot .modebar {
        left: 5px !important;
        right: auto !important;
    }
}