/**
 * All of the CSS for your public-facing functionality should be
 * included in this file.
 */

/* Position classes for the widget */
.dfiw-position-bottom-right {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 10000 !important;
}

.dfiw-position-bottom-left {
    position: fixed !important;
    bottom: 20px !important;
    left: 20px !important;
    z-index: 10000 !important;
}

.dfiw-position-top-right {
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 10000 !important;
}

.dfiw-position-top-left {
    position: fixed !important;
    top: 20px !important;
    left: 20px !important;
    z-index: 10000 !important;
}

/* Mobile overrides for positions */
@media (max-width: 767px) {
    .dfiw-position-top-left,
    .dfiw-position-top-right,
    .dfiw-position-bottom-left,
    .dfiw-position-bottom-right {
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 0 !important;
    }
    
    /* Only when minimized, allow it to be positioned properly */
    #flightWidget.minimized.dfiw-position-bottom-right,
    #flightWidget.minimized.dfiw-position-bottom-left,
    #flightWidget.minimized.dfiw-position-top-right,
    #flightWidget.minimized.dfiw-position-top-left {
        width: auto !important;
        max-width: auto !important;
        left: auto !important;
        right: 10px !important;
        bottom: 10px !important;
    }
}

/* Widget styling */
#flightWidget {
    max-width: 100%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    overflow: auto; /* Changed from hidden to auto to allow scrolling */
    background-color: white;
    transition: all 0.3s ease;
    max-height: 95vh; /* Limit height to 95% of viewport height */
    width: 100%;
}

/* Desktop specific styles */
@media (min-width: 768px) {
    #flightWidget {
        max-width: 450px;  /* Limit width on desktop */
        width: 450px;
    }
}

#flightWidget.hidden {
    opacity: 0;
    transform: scale(0);
    width: 0;
    height: 0;
    overflow: hidden;
}

/* When minimized, the widget should be completely removed from normal document flow */
#flightWidget.minimized {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: auto !important;
    height: auto !important;
    max-width: 300px;
    min-width: 0 !important;
    min-height: 0 !important;
    z-index: 1100;
    background: transparent !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
    transform: none !important;
    display: block !important;
    /* Remove card styling */
    border-radius: 0 !important;
}

#flightWidget.minimized .card-body,
#flightWidget.minimized #widgetContent {
    display: none !important;
}

/* Ensure content is ALWAYS visible when maximized */
#flightWidget:not(.minimized) #widgetContent {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    max-height: none !important;
    overflow: visible !important;
}

#flightWidget.minimized .card-header {
    border-radius: 8px;
    cursor: pointer;
    padding: 0 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    margin: 0;
    width: 170px; /* Width for "Flight Information" */
    background-color: #0d6efd !important;
    color: white !important;
    display: flex;
    justify-content: center; /* Center content horizontally */
    align-items: center;
    font-size: 14px;
    font-weight: normal;
    line-height: 40px;
    height: 40px;
    border: none !important;
    /* Ensure no extra space or borders */
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

#flightWidget.minimized #maximizeBtn {
    border: none !important;
    padding: 0;
    margin-left: 8px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    outline: none;
    color: white !important;
    font-size: 0.85rem;
}

#flightWidget.minimized #maximizeBtn:hover {
    background: rgba(255,255,255,0.2) !important;
    border-radius: 4px;
}

/* Airport cards inside the widget have white header with blue text */
#flightWidget .airport-card .card-header {
    background-color: white !important;
    color: #0d6efd !important;
    border-bottom: 1px solid #cfe2ff !important;
    transition: all 0.3s ease;
}

/* Main widget header - blue background with white text */
#flightWidget > .card-header,
#flightWidget .card-header:not(.airport-card .card-header) {
    background-color: #0d6efd !important;
    color: white !important;
    border-bottom: 1px solid #0b5ed7 !important;
    text-align: center !important;
}

.card-body {
    background-color: white !important;
    color: #0d6efd !important;
    max-height: calc(95vh - 48px); /* 95% of viewport height minus header height */
    overflow-y: auto; /* Enable vertical scrolling */
    padding-bottom: 20px; /* Add some padding at the bottom */
}

/* Mobile adjustments for card body and content */
@media (max-width: 767px) {
    .card-body {
        max-height: calc(85vh - 48px); /* Smaller max-height on mobile to ensure controls are visible */
        padding: 15px 12px; /* Smaller padding on mobile */
    }
    
    /* Smaller buttons on mobile */
    .btn {
        padding: 0.375rem 0.5rem;
        font-size: 0.875rem;
    }
    
    /* Make headers and labels smaller on mobile */
    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.25rem;
    }
    
    /* Reduce spacing between form elements on mobile */
    .mb-3 {
        margin-bottom: 0.75rem !important;
    }
}

.form-control, .form-select {
    background-color: white !important;
    color: #0d6efd !important;
    border-color: #cfe2ff !important;
}

/* Remove Bootstrap's default dropdown arrow and use browser default */
.form-select {
    background-image: none !important;
    appearance: auto !important;
}

.form-control:focus, .form-select:focus {
    border-color: #0d6efd !important;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25) !important;
}

/* Mobile-specific form improvements */
@media (max-width: 767px) {
    /* Larger touch targets for mobile */
    .form-control, .form-select, .btn {
        height: 44px; /* Larger height for better touch targets */
        font-size: 16px !important; /* iOS prevents zoom on input focus if font is 16px or larger */
    }
    
    /* Improve the detect location button styling for mobile */
    #detect-location-btn {
        height: auto !important;
        padding: 10px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        font-weight: 500 !important;
    }
    
    /* Make form elements stack better on mobile */
    #flightForm .d-flex {
        flex-direction: column !important;
    }
    
    /* Ensure form controls have proper spacing on mobile */
    .form-control, .form-select {
        margin-bottom: 8px !important;
    }
    
    /* Adjust card header for better mobile display */
    .card-header {
        padding: 12px 15px !important;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}

#minimizedButton {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1100;
}

#minimizedButton .btn {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

#minimizedButton .btn i {
    font-size: 1.5rem;
}

/* Mobile-specific minimized widget styling */
@media (max-width: 767px) {
    /* Larger touch-friendly minimized header for mobile */
    #flightWidget.minimized .card-header {
        width: auto !important; /* Allow it to size to content */
        min-width: 190px; /* Ensure enough width for the text and buttons */
        line-height: 45px !important; /* Taller for easier touch */
        height: 45px !important;
    }
    
    /* Larger touch-friendly maximize button */
    #flightWidget.minimized #maximizeBtn {
        width: 30px !important;
        height: 30px !important;
        margin-left: 10px !important;
    }
    
    /* Add an indicator to show the widget can be swiped */
    #flightWidget:not(.minimized) .card-header::after {
        content: "";
        position: absolute;
        top: 50%;
        right: 10px;
        transform: translateY(-50%);
        width: 30px;
        height: 3px;
        background-color: rgba(255, 255, 255, 0.4);
        border-radius: 3px;
    }
    
    /* Focus indicators for better mobile UX */
    #flightWidget.mobile-device .form-control:focus,
    #flightWidget.mobile-device .form-select:focus,
    #flightWidget.mobile-device .btn:focus {
        outline: 2px solid #0d6efd !important;
        outline-offset: 2px !important;
    }
}

.fas.fa-drone-alt:before {
    content: "\f085";
}

/* Custom loader styles */
.loader {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
    margin-right: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Result styling */
#output {
    font-size: 0.9rem;
    line-height: 1.5;
    color: #0d6efd !important;
}

#output strong {
    color: #0d6efd !important;
    font-weight: 600;
}

/* Mobile adjustments for results display */
@media (max-width: 767px) {
    #output {
        font-size: 0.85rem;
    }
    
    /* Stack elements in results section for better mobile viewing */
    #output .d-flex {
        flex-direction: column;
    }
    
    #output .ms-4 {
        margin-left: 0.5rem !important;
    }
    
    /* Adjust airport cards for better mobile display */
    #flightWidget .airport-card .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    #flightWidget .airport-card .card-header .badge {
        margin-top: 0.5rem;
    }
    
    /* Make sure NOTAM containers don't overflow */
    .notam-container {
        max-height: 150px !important;
    }
}

/* Alert styling */
.alert-info {
    background-color: white !important;
    border-color: #cfe2ff !important;
    color: #0d6efd !important;
}

/* Form validation styling */
.is-invalid {
    border-color: var(--bs-danger) !important;
}

.invalid-feedback {
    display: block;
    color: var(--bs-danger) !important;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.form-control.valid-input + .invalid-feedback,
.form-select.valid-input + .invalid-feedback {
    display: none;
}

/* Form labels and text */
.form-label, .form-check-label, .form-text {
    color: #0d6efd !important;
    font-weight: 500;
}

/* Mobile-optimized submit button */
@media (max-width: 767px) {
    /* Make submit button more prominent on mobile */
    #flightForm button[type="submit"] {
        background-color: #0d6efd !important;
        color: white !important;
        font-weight: 600 !important;
        height: 48px !important; /* Taller button for easier touch */
        width: 100% !important; /* Full width button on mobile */
        margin-top: 1rem !important;
        font-size: 1rem !important;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2) !important;
    }
    
    /* Add a sticky footer with the submit button when scrolled down on mobile */
    #flightForm.scrolled button[type="submit"] {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1050 !important;
        border-radius: 0 !important;
        margin: 0 !important;
    }
}

/* Location description styling */
#location-description {
    color: #0d6efd !important;
    font-weight: 500;
}

/* Location status container styling */
#location-status {
    transition: all 0.3s ease;
}

/* Mobile-specific location detection styling */
@media (max-width: 767px) {
    #location-status .alert {
        padding: 8px 10px !important;
        margin-bottom: 8px !important;
        font-size: 0.85rem !important;
    }
    
    /* Animated pulse effect for GPS detection button on mobile */
    #detect-location-btn.pulsing {
        animation: pulse-animation 2s infinite;
    }
    
    @keyframes pulse-animation {
        0% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0.4); }
        70% { box-shadow: 0 0 0 10px rgba(13, 110, 253, 0); }
        100% { box-shadow: 0 0 0 0 rgba(13, 110, 253, 0); }
    }
    
    /* Highlight GPS fields on mobile when location is detected */
    .location-detected .form-control[readonly] {
        background-color: rgba(13, 110, 253, 0.05) !important;
        border-color: rgba(13, 110, 253, 0.3) !important;
    }
}

/* Custom airport distance badge */
.badge.distance-badge {
    background-color: rgba(13, 110, 253, 0.1) !important;
    color: #0d6efd !important;
    font-weight: 600;
    border: 1px solid rgba(13, 110, 253, 0.2);
}

/* Satellite image styles */
.satellite-img-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-top: 1px solid rgba(0,0,0,0.125);
    border-bottom: 1px solid rgba(0,0,0,0.125);
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f8f9fa;
    min-height: 150px; /* Ensures a minimum height even if image fails to load */
}

.satellite-img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    transition: transform 0.3s ease;
    display: block; /* Ensures proper image display */
}

.satellite-img:hover {
    transform: scale(1.05);
}

/* Mobile-specific image adjustments */
@media (max-width: 767px) {
    .satellite-img-container {
        min-height: 120px;  /* Smaller on mobile */
    }
    
    .satellite-img {
        height: 150px;
        max-width: 100%;
        margin: 0 auto;
        
        /* Fix for Safari mobile */
        -webkit-transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        -webkit-perspective: 1000;
    }
}

/* Mobile optimizations for NOTAM display */
@media (max-width: 767px) {
    
    /* Better spacing for NOTAM content on mobile */
    .notam-container {
        padding: 0 !important;
    }
    
    /* Make NOTAM display more compact on mobile */
    .notam-container .alert {
        padding: 8px !important;
        margin-bottom: 8px !important;
    }
    
    /* Stack NOTAM header on mobile */
    .notam-container .alert .d-flex {
        flex-direction: column !important;
        align-items: flex-start !important;
    }
    
    .notam-container .alert .d-flex small {
        margin-top: 3px;
        font-size: 0.75rem !important;
    }
    
    /* Add touch-friendly scrolling indicator for image containers */
    .satellite-img-container::after {
        content: '';
        position: absolute;
        bottom: 10px;
        right: 10px;
        width: 30px;
        height: 30px;
        background-color: rgba(255, 255, 255, 0.7);
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        pointer-events: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%230d6efd' viewBox='0 0 16 16'%3E%3Cpath d='M8 0a8 8 0 1 1 0 16A8 8 0 0 1 8 0zM4.5 7.5a.5.5 0 0 0 0 1h5.793l-2.147 2.146a.5.5 0 0 0 .708.708l3-3a.5.5 0 0 0 0-.708l-3-3a.5.5 0 1 0-.708.708L10.293 7.5H4.5z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: center;
        background-size: 16px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    }
}