:root {
    --primary-color: #008080; /* Teal */
    --secondary-color: #FFA500; /* Orange */
    --dark-teal: #1a3b42;
    --light-teal: #268171;
    --bg-white: rgba(255, 255, 255, 0.95);
    --text-color: #333;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-color);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* --- Header Styling --- */
#header2 {
    background: linear-gradient(135deg, var(--dark-teal), var(--light-teal));
    color: white;
    padding: 0 20px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    z-index: 2000;
}

.header-title {
    font-weight: bold;
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

#real-time {
    font-size: 0.9rem;
    margin-right: 15px;
    opacity: 0.9;
    display: none;
}
@media (min-width: 768px) { #real-time { display: block; } }

.btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: background 0.3s;
}
.btn:hover { background: rgba(255,255,255,0.4); }
.btn-primary { background: var(--secondary-color); color: #000; font-weight: bold; }
.btn-active { background: #ff4500; color: white; border: 2px solid white; }

/* --- Map Container --- */
#map-container {
    flex: 1;
    position: relative;
    display: flex;
}

#map {
    flex: 1;
    z-index: 1;
}

/* --- Improved Sidebar/Navbar (MOVED RIGHT) --- */
#navbar {
    position: absolute;
    top: 10px;
    left: 60px; /* Offset to clear zoom controls */
    z-index: 1000;
    background: var(--bg-white);
    padding: 10px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-width: 250px;
    max-height: 80vh;
    overflow-y: auto;
}

details > summary {
    font-weight: bold;
    cursor: pointer;
    margin-bottom: 5px;
    color: var(--dark-teal);
}

.control-group {
    border-top: 1px solid #eee;
    margin-top: 10px;
    padding-top: 10px;
}
.control-group h5 { margin: 0 0 8px 0; color: #555; font-size: 0.95rem; }

.layer-item {
    display: flex;
    align-items: center;
    margin-bottom: 5px;
    font-size: 0.9rem;
}
.layer-item input { margin-right: 8px; }

/* --- Playback Controls --- */
.playback-controls { display: flex; gap: 2px; justify-content: space-between; margin-bottom: 5px; }
.playback-controls button {
    flex: 1;
    padding: 4px;
    font-size: 0.75rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}
.playback-controls button:hover { opacity: 0.9; }

/* --- Loading Screen --- */
#loading-screen {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: #ffffff;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: opacity 1s ease-out;
}
.hidden { opacity: 0; pointer-events: none; }

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px; height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px 0;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.progress-container { width: 200px; height: 6px; background: #eee; border-radius: 3px; overflow: hidden; }
.progress-bar { width: 0%; height: 100%; background: var(--secondary-color); animation: load 3s ease-out forwards; }
@keyframes load { 0% { width: 0; } 100% { width: 100%; } }

/* --- POPUP STYLES --- */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    padding: 0;
    overflow: hidden;
}

.leaflet-popup-content {
    margin: 0;
    width: 320px !important;
}

.popup-container {
    display: flex;
    flex-direction: column;
}

.popup-header {
    background: var(--primary-color);
    color: white;
    padding: 12px 15px;
    font-size: 1.1rem;
    font-weight: bold;
    border-bottom: 4px solid var(--secondary-color);
}

.popup-scroll-container {
    max-height: 250px;
    overflow-y: auto;
    padding: 0;
    background: #fff;
}

.popup-section-title {
    background: #f4f4f4;
    padding: 8px 15px;
    font-size: 0.9rem;
    font-weight: bold;
    color: var(--dark-teal);
    border-bottom: 1px solid #ddd;
    border-top: 1px solid #ddd;
    position: sticky;
    top: 0;
}

.popup-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.popup-table th, .popup-table td {
    padding: 8px 15px;
    border-bottom: 1px solid #eee;
    text-align: left;
    vertical-align: top;
}
.popup-table th { background-color: #fcfcfc; color: #666; width: 40%; font-weight: 600; }
.popup-table tr:last-child td { border-bottom: none; }
.popup-table img { 
    max-width: 100%; 
    height: auto; 
    border-radius: 4px; 
    border: 1px solid #ddd; 
    margin-top: 5px; 
    display: block;
    cursor: pointer; /* Indicates clickable */
    transition: transform 0.2s;
}
.popup-table img:hover {
    transform: scale(1.02);
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* PDF Button Style */
.pdf-btn {
    width: 100%;
    padding: 10px;
    background-color: var(--dark-teal);
    color: white;
    border: none;
    font-weight: bold;
    cursor: pointer;
    text-align: center;
    border-top: 1px solid #eee;
    transition: background 0.3s;
}
.pdf-btn:hover { background-color: var(--primary-color); }
.pdf-btn:disabled { background-color: #ccc; cursor: not-allowed; }

/* --- Properties Table (Bottom Right) --- */
#propertiesContainer {
    position: absolute;
    bottom: 30px;
    right: 10px;
    z-index: 1000;
    background: white;
    padding: 10px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-width: 300px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8rem;
}
#propertiesTable { width: 100%; border-collapse: collapse; }
#propertiesTable th, #propertiesTable td { border: 1px solid #ddd; padding: 4px; }
#propertiesTable th { background: #f2f2f2; }

/* --- Legend (Moved Upward) --- */
.legend {
    background: white;
    border-radius: 5px;
    padding: 10px;
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    max-height: 300px;
    overflow-y: auto;
    min-width: 150px;
    margin-bottom: 160px !important; 
}
.legend-toggle {
    background: none;
    border: none;
    font-weight: bold;
    cursor: pointer;
    width: 100%;
    text-align: left;
    padding: 0;
    margin-bottom: 5px;
    border-bottom: 1px solid #eee;
}
.legend-item { display: flex; align-items: center; margin-bottom: 5px; font-size: 12px; }
.legend-swatch { width: 14px; height: 14px; border-radius: 3px; margin-right: 8px; border: 1px solid #ccc; }
.legend-logo { width: 18px; height: 18px; margin-right: 8px; object-fit: contain; }
.legend-text span { font-size: 10px; color: #777; }
.legend-content.hidden { display: none; }

/* --- Error Notification Styles (Top) --- */
#errorOverride {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 20px;
    border-radius: 5px;
    z-index: 3000;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    text-align: center;
    display: none;
}
#errorOverride.error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}
#errorOverride.warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}
#errorOverride button { margin-left: 10px; padding: 5px 10px; cursor: pointer; border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 3px; opacity: 0.7; }
#errorOverride button:hover { opacity: 1; }

/* --- Pulse Animation --- */
@keyframes pulse-expand {
    0% { transform: scale(0.5); opacity: 1.5; }
    100% { transform: scale(1.1); opacity: 0; }
}

.pulse-layer {
    transform-box: fill-box;
    transform-origin: center;
    animation: pulse-expand 2s infinite ease-out;
}

/* --- IMAGE MODAL (ZOOM) --- */
.image-modal {
    display: none; 
    position: fixed; 
    z-index: 99999; 
    padding-top: 60px; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.9); 
}

.modal-content {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    border-radius: 5px;
    animation: zoomIn 0.3s;
}

@keyframes zoomIn {
    from {transform:scale(0)} 
    to {transform:scale(1)}
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    transition: 0.3s;
    cursor: pointer;
}
.close-modal:hover,
.close-modal:focus {
    color: #bbb;
    text-decoration: none;
    cursor: pointer;
}

#caption {
    margin: auto;
    display: block;
    width: 80%;
    max-width: 700px;
    text-align: center;
    color: #ccc;
    padding: 10px 0;
    height: 150px;
}
/* --- NEW: Flashing Animation for MGB-HIGH --- */
@keyframes flash-warning {
    0% { fill-opacity: 0.4; stroke-opacity: 1; }
    50% { fill-opacity: 0.1; stroke-opacity: 0.4; }
    100% { fill-opacity: 0.4; stroke-opacity: 1; }
}

.flashing-high {
    animation: flash-warning 3s infinite ease-in-out;
}
