:root {
  --level10-color: #ff0000;
  --level9-color:  #ff4500;
  --level8-color:  #ffa500;
  --level7-color:  #ffdf00;
  --level6-color:  #008000;
  --level5-color:  #32cd32;
  --level4-color:  #90ee90;
  --level3-color:  #2a52be;
  --level2-color:  #1e90ff;
  --level1-color:  #73c2fb;
}

/* Toàn màn hình map */
html, body {
  height: 100%;
  width: 100%;
}

#map {
  position: absolute;
  top: 60px;   /* Desktop: nằm ngay dưới thanh nav chuẩn */
  left: 0;
  right: 0;
  bottom: 0;
  transition: top 0.3s ease; /* Hiệu ứng mượt khi đổi kích thước */
}

/* --- CHỈNH SỬA: Ô tìm kiếm --- */
.custom-control-search {
  margin: 10px;
  /* Desktop: Giảm từ 300px xuống 260px cho gọn */
  width: 200px; 
  height: 40px;
  font-size: 15px;
  padding: 0 11px 0 13px;
  text-overflow: ellipsis;
  border: 1px solid transparent;
  border-radius: 2px;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  box-sizing: border-box;
}

/* Chú thích & bộ lọc */
.legend-control-container {
  margin: 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.legend-toggle-button {
  width: auto; /* Để auto để nút co giãn theo nội dung */
  min-width: 40px;
  height: 40px;
  padding: 0 10px;
  background-color: #fff;
  border: none;
  border-radius: 2px;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  box-sizing: border-box;
}

.custom-control-legend {
  width: 100%;
  box-sizing: border-box;
  margin-top: 5px;
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  border-radius: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s ease-out, padding 0.4s ease-out;
  padding: 0 12px;
}

.custom-control-legend.is-open {
  max-height: 80vh;
  padding: 8px 12px;
  overflow-y: auto;
}

.legend-title {
  font-weight: bold;
  margin-bottom: 8px;
  font-size: 14px;
  text-align: center;
  line-height: 1.2;
}

.legend-subtitle {
  font-weight: normal;
  font-size: 13px;
}

.legend-item {
  display: flex;
  align-items: center;
  margin-bottom: 5px;
  font-size: 12px;
}

.legend-item input {
  margin-right: 8px;
}

.legend-item i {
  width: 18px;
  height: 18px;
  margin-right: 8px;
  border: 1px solid #ccc;
  flex-shrink: 0;
}

.legend-separator {
  border-top: 1px solid #ccc;
  margin: 8px 0;
}

/* Popup map */
.gm-style-iw-c {
  padding: 12px !important;
  border-radius: 0 !important;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15) !important;
}
.gm-style-iw-d { overflow: auto !important; }
.gm-style-iw-t::after { display: none !important; }

/* Banner loading */
.loading-banner {
  position: absolute;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.95);
  padding: 6px 10px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
  font-size: 13px;
  z-index: 1500;
}

/* Footer nhỏ trên map */
.map-footer {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  background-color: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 8px 15px;
  border-radius: 5px;
  font-size: 13px;
  white-space: nowrap;
  z-index: 1005;
  pointer-events: none;
}

/* ===== RESPONSIVE CHO MOBILE (SỬA LỖI CHE MENU) ===== */
@media screen and (max-width: 992px) {
  /* Tablet/Mobile lớn: Giảm chiều rộng search box để chừa chỗ cho Legend */
  .custom-control-search { 
    width: 200px; 
  }

  /* Đẩy bản đồ xuống thấp hơn vì Header mobile cao */
  #map {
      top: 150px; 
  }
  
  /* Đẩy thông báo loading xuống theo */
  .loading-banner {
      top: 10px; 
  }
  
  .legend-control-container {
      margin: 5px;
  }
}

@media screen and (max-width: 600px) {
  .map-footer {
    font-size: 11px;
    padding: 6px 10px;
    white-space: normal; 
    width: 90%;
    text-align: center;
  }
  
  /* --- KHẮC PHỤC LỖI QUAN TRỌNG TẠI ĐÂY --- */
  .custom-control-search {
      /* Bỏ dòng calc(100vw - 20px) cũ đi */
      /* Đặt chiều rộng cố định nhỏ hơn để không đâm vào nút Legend bên phải */
      width: 170px; 
      margin: 10px 5px;
  }
  
  /* Thu nhỏ chữ trong nút tìm kiếm trên mobile */
  .custom-control-search {
      font-size: 13px;
      padding: 0 8px;
  }
}