html, body { margin:0; padding:0; width:100%; height:100%; font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;}
#map { width:100%; height:100%; }

/* Modal styling */
.modal { position: fixed; inset:0; background: rgba(0,0,0,0.75); backdrop-filter: blur(4px); display:flex; align-items:center; justify-content:center; z-index:9999; padding:16px; animation:fadeIn 0.2s ease-out;}
@keyframes fadeIn { from{opacity:0;} to{opacity:1;} }
@keyframes slideUp { from{opacity:0; transform: translateY(20px);} to{opacity:1; transform:translateY(0);} }
.modal-content { background: linear-gradient(135deg,#1a1a2e 0%,#16213e 100%); color:#e8e8e8; padding:0; border-radius:16px; max-width:700px; width:100%; max-height:90vh; overflow:hidden; position:relative; box-shadow:0 20px 60px rgba(0,0,0,0.5); animation:slideUp 0.3s ease-out;}
.modal-header { background:linear-gradient(135deg,#0f3460 0%,#16213e 100%); padding:20px 24px; border-bottom:2px solid rgba(255,255,255,0.1); display:flex; justify-content:space-between; align-items:center;}
#modal-title, #stats-modal-title { margin:0; font-size:1.5rem; font-weight:600; color:#fff; flex:1;}
#modal-close, #settings-close, #stats-close { cursor:pointer; font-size:32px; color:#e8e8e8; background:rgba(255,255,255,0.1); border-radius:50%; width:40px; height:40px; display:flex; align-items:center; justify-content:center; transition:all 0.2s ease; border:none; line-height:1; flex-shrink:0; margin-left:16px;}
#modal-close:hover, #settings-close:hover, #stats-close:hover { background:rgba(255,255,255,0.2); transform:rotate(90deg); }
#modal-body, #settings-body, #stats-body { padding:24px; overflow-y:auto; max-height:calc(90vh - 100px);}
#modal-body h3, #stats-body h3 { margin-top:0; margin-bottom:12px; font-size:1.3rem; font-weight:600; padding-bottom:8px; border-bottom:2px solid #000; }
#modal-body p, #stats-body p { margin:12px 0; line-height:1.6;}
#modal-body strong, #stats-body strong { color:#FFFFFF; font-weight:600;}
#modal-body small { color:#b0b0b0; font-size:0.85rem; display:block; margin:8px 0;}
#modal-body em { color:#9e9e9e; font-style:italic;}
.alert-section { background:rgba(255,255,255,0.05); padding:20px; border-radius:12px; margin-bottom:20px; border-left:4px solid #000;}
.alert-section:last-child { margin-bottom:0;}

/* Last updated timestamp under the menu */
#last-updated {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
    background: rgba(31,41,55,0.85);
    color: #cbd5e1;
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.4);
    pointer-events: none;
    white-space: nowrap;
    display: none;
}

@media (max-width:640px) {
  .modal { padding:8px; align-items:flex-end; }
  .modal-content { max-height:85vh; border-bottom-left-radius:0; border-bottom-right-radius:0;}
  .modal-header { padding:16px 20px; }
  #modal-title, #stats-modal-title { font-size:1.25rem; }
  #modal-close, #settings-close, #stats-close { width:36px; height:36px; font-size:28px; }
  #modal-body, #settings-body, #stats-body { padding:20px; max-height:calc(85vh - 80px);}
  #modal-body h3, #stats-body h3 { font-size:1.15rem;}
  .alert-section { padding:16px; }
  #last-updated { top: 80px; font-size: 11px; padding: 3px 10px; }
}
::-webkit-scrollbar { width:8px; }
::-webkit-scrollbar-track { background: rgba(255,255,255,0.05);}
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius:4px;}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3);}

/* Menu & Legend styles */
.menu-container{
    position:absolute;top:12px;left:50%;transform:translateX(-50%);z-index:1000;
    background:rgba(31,41,55,.95);padding:8px 12px;border-radius:12px;
    box-shadow:0 4px 20px rgba(0,0,0,.5);border:1px solid rgba(255,255,255,.15);
    display:flex;align-items:center;gap:8px;
    max-width:95vw;overflow-x:auto;white-space:nowrap;scrollbar-width:none;
    overflow:visible !important;
}
.menu-container::-webkit-scrollbar{display:none}

.logo-section{display:flex;align-items:center;padding-right:12px;border-right:1px solid rgba(255,255,255,.2);margin-right:8px;flex-shrink:0;}
.logo-text{font-size:16px;font-weight:700;color:#fff;letter-spacing:-.4px;}

.menu-item{
    display:inline-flex;align-items:center;
    flex-shrink:0;margin-right:8px;
}
.menu-item:last-child{margin-right:0;}

.dropbtn{
    background:rgba(255,255,255,.1);border:1px solid rgba(255,255,255,.2);
    color:#E5E7EB;padding:8px 14px;border-radius:8px;cursor:pointer;
    font-size:13px;font-weight:600;display:flex;align-items:center;gap:6px;
    transition:all .3s;white-space:nowrap;min-height:38px;
}
.dropbtn:hover{background:rgba(255,255,255,.18);border-color:rgba(255,255,255,.35);transform:translateY(-1px)}
.dropbtn.active{color:#fff;font-weight:700;background:rgba(59,130,246,.3);border-color:#60A5FA}
.dropbtn i{font-size:12px;transition:transform .2s}
.dropdown.active .dropbtn i{transform:rotate(180deg)}

.dropdown{position:relative;display:inline-block;}
.dropdown-content{
    display:none;position:absolute;top:100%;left:0;
    width:max-content;min-width:200px;max-width:320px;
    background:rgba(31,41,55,.98);border:1px solid rgba(255,255,255,.15);
    border-radius:8px;overflow:visible;box-shadow:0 6px 20px rgba(0,0,0,.5);
    z-index:3000;
    margin-top:4px;
    pointer-events:auto;max-height:400px;overflow-y:auto;
}
.dropdown.active .dropdown-content{display:block;}
.dropdown-content button{
    width:100%;text-align:left;padding:12px 16px;background:none;border:none;
    color:#E5E7EB;font-size:13px;cursor:pointer;transition:background .2s;
    white-space:nowrap;display:block;
    border-bottom:1px solid rgba(255,255,255,.08);
}
.dropdown-content button:last-child{border-bottom:none;}
.dropdown-content button:hover{background:rgba(255,255,255,.1)}
.dropdown-content button.active{color:#fff;background:rgba(59,130,246,.4);font-weight:600}

.hamburger{cursor:pointer;font-size:20px;color:#fff;padding:8px;z-index:1001;display:none;}
.hamburger i{font-size:20px;}

.mobile-menu{
    display:none;position:absolute;top:58px;left:50%;transform:translateX(-50%);
    background:rgba(31,41,55,.98);border-radius:10px;padding:8px 0;
    box-shadow:0 6px 20px rgba(0,0,0,.5);z-index:1000;
    width:calc(100vw - 40px);max-width:400px;max-height:70vh;overflow-y:auto;
    border:1px solid rgba(255,255,255,.15);
}
.mobile-menu button{
    width:100%;text-align:left;padding:10px 16px;background:none;border:none;
    color:#E5E7EB;font-size:13px;cursor:pointer;transition:background .2s;
    white-space:nowrap;
}
.mobile-menu button:hover{background:rgba(255,255,255,.1)}
.mobile-menu button.active{color:#fff;background:rgba(59,130,246,.4);font-weight:600}

.legend-container{
    position:absolute;bottom:0;left:0;right:0;z-index:1000;
    background:rgba(31,41,55,.95);box-shadow:0 -2px 20px rgba(0,0,0,.5);
    border-top:1px solid rgba(255,255,255,.15);
    padding:10px 16px;width:100%;box-sizing:border-box;
}
.legend-title{
    text-align:center;color:#fff;font-weight:600;margin-bottom:6px;font-size:12px;
}
.legend-gradient{
    height:14px;background:linear-gradient(to right,
        #FAFAFA 0%, #88FF88 5.88%, #22FF22 11.76%, #00DD00 17.65%, 
        #00AA00 23.53%, #007700 29.41%, #003366 35.29%, #0055AA 41.18%, 
        #2288EE 47.06%, #55BBFF 52.94%, #00FFFF 58.82%, #AA77DD 64.71%, 
        #7733AA 70.59%, #770000 76.47%, #BB0000 82.35%, #FF3300 88.24%, 
        #FF7700 94.12%, #AA8800 97.06%, #FFFF00 99.41%, #FFDDDD 100%
    );
    border-radius:4px;border:1px solid rgba(255,255,255,.2);margin:0 4px;
}
.legend-values{
    display:flex;justify-content:space-between;margin-top:4px;color:#E5E7EB;
    font-size:10px;line-height:1;
}
.legend-values span{flex:1;text-align:center;}

.legend-items{
    display:flex;flex-wrap:wrap;gap:12px 16px;
    justify-content:center;align-items:center;
    row-gap:8px;
}
.legend-item{
    display:flex;align-items:center;gap:8px;flex-shrink:0;
}
.legend-color{
    width:24px;height:16px;border-radius:3px;
    border:1px solid rgba(255,255,255,.3);flex-shrink:0;
}
.legend-label{
    font-size:11px;color:#E5E7EB;white-space:nowrap;
}

/* Settings modal styles */
#settings-modal .modal-content {
  max-width: 420px;
}
#settings-modal .modal-body {
  padding: 20px;
  overflow-y: auto;
  max-height: 70vh;
}
.style-radio-group {
  margin-bottom: 24px;
}
.style-radio-group label {
  display: block;
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.style-radio-group label:hover {
  background: rgba(255,255,255,0.08);
}
.style-radio-group input[type="radio"]:checked + span {
  font-weight: 600;
  color: #60A5FA;
}

/* Mobile responsiveness for menu */
@media (max-width: 1180px) and (orientation: landscape),
       (max-width: 1024px) {
    .hamburger { display: block !important; }
    #wmsMenuContainer { display: none !important; }
}

@media (min-width: 1181px) and (orientation: landscape) {
    .hamburger { display: none !important; }
    .mobile-menu { display: none !important; }
}

/* Legend toggle button & panel */
.legend-toggle-btn {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 1100;
    background: rgba(31,41,55,0.95);
    color: #e5e7eb;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(0,0,0,0.5);
    transition: all 0.2s ease;
}

.legend-toggle-btn:hover {
    background: rgba(55,65,81,0.98);
    transform: scale(1.08);
}

.legend-toggle-btn.active {
    background: rgba(59,130,246,0.4);
    border-color: #60a5fa;
}

#legendPanel {
    position: absolute;
    bottom: 78px;
    left: 16px;
    z-index: 1050;
    background: rgba(31,41,55,0.96);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 12px;
    padding: 14px 16px;
    min-width: 220px;
    max-width: 340px;
    max-height: 66vh;
    overflow-y: auto;
    box-shadow: 0 8px 30px rgba(0,0,0,0.55);
    display: none;
    color: #e5e7eb;
    font-size: 13px;
}

#legendPanel.show {
    display: block;
}

.legend-panel-title {
    font-weight: 600;
    color: #fff;
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.12);
    font-size: 1.05rem;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
}

.legend-color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.25);
    flex-shrink: 0;
}

.legend-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Optional: Make geolocate button more visible / styled */
.maplibregl-ctrl-geolocate {
    background-color: rgba(31,41,55,0.95) !important;
    border: 1px solid rgba(255,255,255,0.25) !important;
    border-radius: 50% !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4) !important;
    width: 40px !important;
    height: 40px !important;
}

.maplibregl-ctrl-geolocate:hover {
    background-color: rgba(55,65,81,0.98) !important;
}

.maplibregl-ctrl-geolocate .maplibregl-ctrl-icon {
    filter: brightness(1.2);
}