/* Site CSS for Photogrammetry Post-Processing App Generated Maps */

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
}

/* Map container */
#map {
    height: 100vh;
    width: 100%;
    z-index: 1;
}

/* Map title overlay */
.map-title {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(45, 45, 45, 0.9);
    color: white;
    padding: 12px 24px;
    border-radius: 6px;
    font-size: 18px;
    font-weight: 600;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* 3D Model Viewer Link styling */
.model-viewer-link {
    position: absolute;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 120, 212, 0.9);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    user-select: none;
    transition: all 0.2s ease;
}

.model-viewer-link:hover {
    background: rgba(0, 120, 212, 1);
    box-shadow: 0 4px 15px rgba(0, 120, 212, 0.4);
}

.model-viewer-link:active {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* DEM legend styling */
.dem-legend {
    position: absolute;
    bottom: 100px;
    left: 20px;
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 10px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    max-width: 200px;
    backdrop-filter: blur(5px);
}

.dem-legend img {
    width: 100%;
    height: auto;
    border-radius: 3px;
    margin-bottom: 5px;
}

.legend-title {
    text-align: center;
    font-weight: 600;
    font-size: 12px;
    color: #333;
    margin-top: 5px;
}

/* Stack multiple legends */
#dtm-legend {
    bottom: 200px; /* Adjust if DSM legend exists */
}

#dsm-legend + #dtm-legend {
    bottom: 170px; /* Closer stacking when both exist */
}

/* Attribution styling */
.attribution {
    position: absolute;
    bottom: 5px;
    right: 10px;
    background: rgba(255, 255, 255, 0.8);
    padding: 4px 8px;
    font-size: 11px;
    color: #666;
    border-radius: 3px;
    z-index: 1000;
}

.attribution a {
    color: #0078d4;
    text-decoration: none;
}

.attribution a:hover {
    text-decoration: underline;
}

/* Feature popup styling */
.feature-popup {
    max-width: 300px;
    font-size: 13px;
    line-height: 1.4;
}

.feature-popup strong {
    color: #333;
    font-weight: 600;
}

/* Leaflet control customization */
.leaflet-control-layers {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.leaflet-control-layers-expanded {
    min-width: 180px;
}

.leaflet-control-zoom {
    border: none;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.leaflet-control-zoom a {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #333;
    font-weight: 600;
    font-size: 16px;
}

.leaflet-control-zoom a:hover {
    background: rgba(255, 255, 255, 1);
    color: #0078d4;
}

/* Measure tool styling */
.leaflet-control-measure {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* High specificity override for measure tool icon */
.leaflet-control-measure .leaflet-control-measure-toggle,
.leaflet-control-measure a.leaflet-control-measure-toggle {
    background-image: url('../icons/ruler.svg') !important;
    background-size: 16px 16px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    width: 26px !important;
    height: 26px !important;
}

/* Fullscreen control styling */
.leaflet-control-fullscreen {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* Locate control styling */
.leaflet-control-locate {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* Geocoder styling */
.leaflet-control-geocoder {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.leaflet-control-geocoder-form input {
    border: 1px solid #ddd;
    border-radius: 3px;
    padding: 4px 8px;
    font-size: 13px;
}

/* Mini map styling */
.leaflet-control-minimap {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* Drawing/editing tools styling */
.leaflet-pm-toolbar {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

/* Loading indicator */
.map-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 6px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    font-size: 14px;
    color: #333;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0078d4;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Error message styling */
.map-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255, 255, 255, 0.95);
    padding: 20px;
    border-radius: 6px;
    border-left: 4px solid #dc3545;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 2000;
    max-width: 400px;
    text-align: center;
}

.map-error h3 {
    color: #dc3545;
    margin-bottom: 10px;
    font-size: 16px;
}

.map-error p {
    color: #666;
    font-size: 14px;
    line-height: 1.4;
}

/* Responsive design */
@media (max-width: 768px) {
    .map-title {
        top: 10px;
        font-size: 16px;
        padding: 8px 16px;
        max-width: calc(100% - 40px);
    }
    
    .model-viewer-link {
        top: 60px;
        font-size: 12px;
        padding: 8px 16px;
        max-width: calc(80% - 40px);
    }
    
    .dem-legend {
        bottom: 80px;
        left: 10px;
        max-width: 150px;
        padding: 8px;
    }
    
    #dtm-legend {
        bottom: 150px;
    }
    
    #dsm-legend + #dtm-legend {
        bottom: 130px;
    }
    
    .leaflet-control-layers-expanded {
        min-width: 150px;
    }
    
    .feature-popup {
        max-width: 250px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .map-title {
        font-size: 14px;
        padding: 6px 12px;
    }
    
    .model-viewer-link {
        top: 50px;
        font-size: 11px;
        padding: 6px 12px;
        max-width: calc(90% - 20px);
    }
    
    .dem-legend {
        max-width: 120px;
        padding: 6px;
    }
    
    .legend-title {
        font-size: 11px;
    }
}

/* Print styles */
@media print {
    .leaflet-control-container {
        display: none;
    }
    
    .attribution {
        display: block !important;
        position: fixed;
        bottom: 0;
        right: 0;
        background: white;
        border: 1px solid #ccc;
        padding: 5px;
    }
}

/* Custom icon overrides for plugins - High specificity to override plugin defaults */

/* Leaflet Measure Tool - Custom Ruler Icon */
.leaflet-control-measure .leaflet-control-measure-toggle,
.leaflet-control-measure a.leaflet-control-measure-toggle,
.leaflet-control-container .leaflet-control-measure .leaflet-control-measure-toggle {
    background-image: url('../icons/ruler.svg') !important;
    background-size: 16px 16px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    width: 26px !important;
    height: 26px !important;
}

/* Better File Layer - Custom Import Icon */
/* Target the actual file input element created by BetterFileLayer */
.leaflet-control-betterfilelayer,
.leaflet-control-betterfilelayer a,
.leaflet-control-betterfilelayer button,
.leaflet-control-betterfilelayer input[type="file"],
.leaflet-control-betterfilelayer input,
.leaflet-control-container .leaflet-control-betterfilelayer,
.leaflet-control-container .leaflet-control-betterfilelayer input,
div.leaflet-control-betterfilelayer,
div.leaflet-control-betterfilelayer input,
input[type="file"].leaflet-control-betterfilelayer,
input.leaflet-control-betterfilelayer {
    background-image: url('../icons/file-import.svg') !important;
    background-size: 16px 16px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    width: 26px !important;
    height: 26px !important;
    text-indent: -9999px !important;
    text-align: center !important;
    line-height: 26px !important;
    overflow: hidden !important;
    color: transparent !important;
    font-size: 0 !important;
    border: none !important;
    cursor: pointer !important;
}

/* Hide file input text and style the wrapper */
input[type="file"]::-webkit-file-upload-button {
    background-image: url('../icons/file-import.svg') !important;
    background-size: 16px 16px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    width: 26px !important;
    height: 26px !important;
    border: none !important;
    color: transparent !important;
    font-size: 0 !important;
    text-indent: -9999px !important;
    cursor: pointer !important;
}

/* File layer control styling to match other controls */
.leaflet-control-betterfilelayer,
div.leaflet-control-betterfilelayer {
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    border-radius: 6px !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2) !important;
    padding: 0 !important;
    margin: 0 !important;
}

.leaflet-control-betterfilelayer a,
.leaflet-control-betterfilelayer button,
div.leaflet-control-betterfilelayer a,
div.leaflet-control-betterfilelayer button {
    background-color: rgba(255, 255, 255, 0.95) !important;
    color: transparent !important;
    font-weight: 600;
    border: none !important;
    border-radius: 6px !important;
    display: block !important;
    text-decoration: none !important;
    cursor: pointer !important;
}

.leaflet-control-betterfilelayer a:hover,
.leaflet-control-betterfilelayer button:hover,
div.leaflet-control-betterfilelayer a:hover,
div.leaflet-control-betterfilelayer button:hover {
    background-color: rgba(255, 255, 255, 1) !important;
    color: transparent !important;
}

/* File input styling - hide the actual input and style the wrapper */
.leaflet-control-betterfilelayer input[type="file"] {
    position: absolute !important;
    opacity: 0 !important;
    width: 26px !important;
    height: 26px !important;
    cursor: pointer !important;
}

/* Alternative selectors that might be used by BetterFileLayer */
.leaflet-bar .leaflet-control-betterfilelayer,
.leaflet-bar .leaflet-control-betterfilelayer a,
a.leaflet-control-betterfilelayer,
button.leaflet-control-betterfilelayer,
.file-control,
.file-control a,
.file-control button {
    background-image: url('../icons/file-import.svg') !important;
    background-size: 16px 16px !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    width: 26px !important;
    height: 26px !important;
    text-indent: -9999px !important;
    color: transparent !important;
}

/* ===== PHOTO LAYER STYLES ===== */

/* Using default Leaflet markers for photos - no custom styling needed */
/* This prevents CSS conflicts with Leaflet's positioning system */

/* Photo popup styling */
.photo-popup {
    max-width: 400px !important;
    padding: 0 !important;
}

.photo-popup .leaflet-popup-content {
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 8px !important;
    overflow: hidden !important;
}

.photo-popup-header {
    background: #2c3e50;
    color: white;
    padding: 10px 15px;
    font-weight: 600;
    font-size: 14px;
    border-radius: 8px 8px 0 0;
}

.photo-popup-image {
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.photo-popup-image:hover {
    opacity: 0.9;
}

.photo-popup-metadata {
    padding: 15px;
    background: white;
    border-radius: 0 0 8px 8px;
}

.photo-metadata-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 12px;
}

.photo-metadata-label {
    font-weight: 600;
    color: #555;
    margin-right: 10px;
}

.photo-metadata-value {
    color: #333;
    text-align: right;
}

.photo-popup-actions {
    padding: 10px 15px;
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    text-align: center;
}

.photo-popup-btn {
    display: inline-block;
    padding: 6px 12px;
    background: #007bff;
    color: white !important;
    text-decoration: none;
    border-radius: 4px;
    font-size: 12px;
    margin: 0 5px;
    transition: background-color 0.2s ease;
    border: none;
    cursor: pointer;
}

.photo-popup-btn:hover {
    background: #0056b3;
    color: white !important;
    text-decoration: none;
}

/* Ensure anchor tags with photo-popup-btn class have white text */
a.photo-popup-btn,
a.photo-popup-btn:link,
a.photo-popup-btn:visited {
    color: white !important;
    text-decoration: none !important;
}

a.photo-popup-btn:hover {
    color: white !important;
    text-decoration: none !important;
}

/* Mobile responsive photo popup */
@media (max-width: 768px) {
    .photo-popup {
        max-width: 280px !important;
    }
    
    .photo-popup-image {
        max-height: 200px;
    }
    
    .photo-metadata-row {
        font-size: 11px;
        margin-bottom: 3px;
    }
    
    .photo-popup-header {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .photo-popup-metadata {
        padding: 12px;
    }
}

@media (max-width: 480px) {
    .photo-popup {
        max-width: 240px !important;
    }
    
    .photo-popup-image {
        max-height: 160px;
    }
    
    .photo-marker-icon {
        background-size: 20px 20px !important;
        width: 28px !important;
        height: 28px !important;
    }
    
    .photo-marker-icon.zoom-small {
        background-size: 14px 14px !important;
        width: 20px !important;
        height: 20px !important;
    }
    
    .photo-marker-icon.zoom-large {
        background-size: 24px 24px !important;
        width: 32px !important;
        height: 32px !important;
    }
}

/* Animation for photo markers appearing */
@keyframes photoMarkerAppear {
    0% {
        opacity: 0;
        transform: scale(0.5) rotate(var(--rotation, 0deg));
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(var(--rotation, 0deg));
    }
}

.photo-marker-animate {
    animation: photoMarkerAppear 0.3s ease-out;
}

/* Clustered photo markers */
.photo-cluster-marker {
    background: rgba(52, 152, 219, 0.9) !important;
    color: white !important;
    font-weight: 600 !important;
    text-align: center !important;
    line-height: 32px !important;
    border-radius: 50% !important;
    border: 2px solid white !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    font-size: 14px !important;
}

.photo-cluster-marker:hover {
    background: rgba(41, 128, 185, 1) !important;
    transform: scale(1.1) !important;
}

/* ===== PHOTO MODAL STYLES ===== */

/* Modal overlay */
.photo-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.photo-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.photo-modal-content {
    position: relative;
    width: 90%;
    height: 90%;
    max-width: 1200px;
    max-height: 800px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease forwards;
}

@keyframes modalSlideIn {
    from {
        transform: scale(0.9) translateY(20px);
        opacity: 0;
    }
    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* Modal header */
.photo-modal-header {
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 12px 12px 0 0;
}

.photo-modal-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    flex: 1;
}

.photo-modal-controls {
    display: flex;
    gap: 8px;
}

.photo-modal-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0;
}

.photo-modal-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.photo-modal-btn:active {
    transform: translateY(0);
}

.photo-modal-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* Modal body */
.photo-modal-body {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.photo-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.modal-photo {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: transform 0.1s ease;
    transform-origin: center center;
    cursor: default;
    user-select: none;
}

.modal-photo.draggable {
    cursor: grab;
}

.modal-photo.dragging {
    cursor: grabbing;
}

.photo-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.photo-loading .loading-spinner {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: white;
}

.photo-loading p {
    margin: 0;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

/* Modal metadata footer */
.photo-modal-metadata {
    background: #f8f9fa;
    border-top: 1px solid #dee2e6;
    padding: 20px;
    border-radius: 0 0 12px 12px;
    max-height: 200px;
    overflow-y: auto;
}

.photo-metadata-content {
    max-width: 100%;
}

.photo-metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.metadata-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metadata-label {
    font-size: 12px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.metadata-value {
    font-size: 14px;
    color: #333;
    font-weight: 500;
}

/* Mobile responsive modal */
@media (max-width: 768px) {
    .photo-modal-content {
        width: 95%;
        height: 95%;
        max-height: none;
    }
    
    .photo-modal-header {
        padding: 12px 15px;
    }
    
    .photo-modal-title {
        font-size: 14px;
    }
    
    .photo-modal-btn {
        width: 28px;
        height: 28px;
    }
    
    .photo-modal-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .photo-modal-metadata {
        padding: 15px;
        max-height: 150px;
    }
    
    .photo-metadata-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .metadata-item {
        gap: 2px;
    }
    
    .metadata-label {
        font-size: 11px;
    }
    
    .metadata-value {
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .photo-modal-content {
        width: 98%;
        height: 98%;
        border-radius: 8px;
    }
    
    .photo-modal-header {
        padding: 10px 12px;
        border-radius: 8px 8px 0 0;
    }
    
    .photo-modal-title {
        font-size: 13px;
    }
    
    .photo-modal-controls {
        gap: 6px;
    }
    
    .photo-modal-btn {
        width: 26px;
        height: 26px;
    }
    
    .photo-modal-metadata {
        padding: 12px;
        max-height: 120px;
        border-radius: 0 0 8px 8px;
    }
}

/* Touch gestures for mobile */
@media (pointer: coarse) {
    .modal-photo {
        touch-action: pan-x pan-y;
    }
    
    .photo-modal-btn {
        min-height: 44px;
        min-width: 44px;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .photo-modal {
        background: rgba(0, 0, 0, 0.95);
    }
    
    .photo-modal-header {
        background: #000;
        border-bottom: 2px solid #fff;
    }
    
    .photo-modal-btn {
        border: 2px solid #fff;
        background: #000;
    }
    
    .photo-modal-metadata {
        background: #fff;
        border-top: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .photo-modal,
    .photo-modal-content,
    .modal-photo,
    .photo-modal-btn {
        animation: none;
        transition: none;
    }
}

/* Print styles for modal */
@media print {
    .photo-modal {
        position: static;
        background: white;
        width: 100%;
        height: auto;
    }
    
    .photo-modal-content {
        max-width: none;
        max-height: none;
        box-shadow: none;
        border: 1px solid #000;
    }
    
    .photo-modal-header {
        background: #000;
        color: white;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    
    .photo-modal-controls {
        display: none;
    }
    
    .modal-photo {
        max-width: 100%;
        height: auto;
    }
}